blob: 6cf5d7903f57c1cf680d4e68aaeb885534ab2452 [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * Copyright (c) 2011, Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef PopupContainer_h
32#define PopupContainer_h
33
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010034#include "PopupListBox.h"
Torne (Richard Coles)09380292014-02-21 12:17:33 +000035#include "platform/PopupMenuStyle.h"
Torne (Richard Coles)1e202182013-10-18 15:46:42 +010036#include "platform/geometry/FloatQuad.h"
Torne (Richard Coles)09380292014-02-21 12:17:33 +000037#include "platform/scroll/FramelessScrollView.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010038
39namespace WebCore {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010040class ChromeClient;
41class FrameView;
42class PopupMenuClient;
Torne (Richard Coles)09380292014-02-21 12:17:33 +000043}
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010044
Torne (Richard Coles)09380292014-02-21 12:17:33 +000045namespace blink {
46
47struct WebPopupMenuInfo;
48
49class PopupContainer FINAL : public WebCore::FramelessScrollView {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010050public:
Torne (Richard Coles)09380292014-02-21 12:17:33 +000051 static PassRefPtr<PopupContainer> create(WebCore::PopupMenuClient*, bool deviceSupportsTouch);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010052
53 // Whether a key event should be sent to this popup.
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010054 bool isInterestedInEventForKey(int keyCode);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010055
56 // FramelessScrollView
Torne (Richard Coles)09380292014-02-21 12:17:33 +000057 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect&) OVERRIDE;
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +010058 virtual void hide() OVERRIDE;
Torne (Richard Coles)09380292014-02-21 12:17:33 +000059 virtual bool handleMouseDownEvent(const WebCore::PlatformMouseEvent&) OVERRIDE;
60 virtual bool handleMouseMoveEvent(const WebCore::PlatformMouseEvent&) OVERRIDE;
61 virtual bool handleMouseReleaseEvent(const WebCore::PlatformMouseEvent&) OVERRIDE;
62 virtual bool handleWheelEvent(const WebCore::PlatformWheelEvent&) OVERRIDE;
63 virtual bool handleKeyEvent(const WebCore::PlatformKeyboardEvent&) OVERRIDE;
64 virtual bool handleTouchEvent(const WebCore::PlatformTouchEvent&) OVERRIDE;
65 virtual bool handleGestureEvent(const WebCore::PlatformGestureEvent&) OVERRIDE;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010066
67 // PopupContainer methods
68
69 // Show the popup
Torne (Richard Coles)09380292014-02-21 12:17:33 +000070 void showPopup(WebCore::FrameView*);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010071
72 // Show the popup in the specified rect for the specified frame.
73 // Note: this code was somehow arbitrarily factored-out of the Popup class
74 // so WebViewImpl can create a PopupContainer. This method is used for
75 // displaying auto complete popup menus on Mac Chromium, and for all
76 // popups on other platforms.
Torne (Richard Coles)09380292014-02-21 12:17:33 +000077 void showInRect(const WebCore::FloatQuad& controlPosition, const WebCore::IntSize& controlSize, WebCore::FrameView*, int index);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010078
79 // Hides the popup.
80 void hidePopup();
81
82 // The popup was hidden.
83 void notifyPopupHidden();
84
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010085 PopupListBox* listBox() const { return m_listBox.get(); }
86
87 bool isRTL() const;
88
89 // Gets the index of the item that the user is currently moused-over or
90 // has selected with the keyboard up/down arrows.
91 int selectedIndex() const;
92
93 // Refresh the popup values from the PopupMenuClient.
Torne (Richard Coles)09380292014-02-21 12:17:33 +000094 WebCore::IntRect refresh(const WebCore::IntRect& targetControlRect);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010095
96 // The menu per-item data.
Torne (Richard Coles)09380292014-02-21 12:17:33 +000097 const Vector<PopupItem*>& popupData() const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010098
99 // The height of a row in the menu.
100 int menuItemHeight() const;
101
102 // The size of the font being used.
103 int menuItemFontSize() const;
104
105 // The style of the menu being used.
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000106 WebCore::PopupMenuStyle menuStyle() const;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100107
108 // While hovering popup menu window, we want to show tool tip message.
109 String getSelectedItemToolTip();
110
111 // This is public for testing.
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000112 static WebCore::IntRect layoutAndCalculateWidgetRectInternal(WebCore::IntRect widgetRectInScreen, int targetControlHeight, const WebCore::FloatRect& windowRect, const WebCore::FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const WebCore::IntSize& transformOffset, PopupContent*, bool& needToResizeView);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100113
114private:
115 friend class WTF::RefCounted<PopupContainer>;
116
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000117 PopupContainer(WebCore::PopupMenuClient*, bool deviceSupportsTouch);
118 virtual ~PopupContainer();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100119
120 // Paint the border.
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000121 void paintBorder(WebCore::GraphicsContext*, const WebCore::IntRect&);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100122
123 // Layout and calculate popup widget size and location and returns it as IntRect.
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000124 WebCore::IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const WebCore::IntSize& transformOffset, const WebCore::IntPoint& popupInitialCoordinate);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100125
126 void fitToListBox();
127
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000128 void popupOpened(const WebCore::IntRect& bounds);
129 void getPopupMenuInfo(WebPopupMenuInfo*);
130
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100131 // Returns the ChromeClient of the page this popup is associated with.
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000132 WebCore::ChromeClient& chromeClient();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100133
134 RefPtr<PopupListBox> m_listBox;
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000135 RefPtr<WebCore::FrameView> m_frameView;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100136
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100137 // m_controlPosition contains the transformed position of the
138 // <select>/<input> associated with this popup. m_controlSize is the size
139 // of the <select>/<input> without transform.
Torne (Richard Coles)81a51572013-05-13 16:52:28 +0100140 // The popup menu will be positioned as follows:
Torne (Richard Coles)93ac45c2013-05-29 14:40:20 +0100141 // LTR : If the popup is positioned down it will align with the bottom left
142 // of m_controlPosition (p4)
143 // If the popup is positioned up it will align with the top left of
144 // m_controlPosition (p1)
145 // RTL : If the popup is positioned down it will align with the bottom right
146 // of m_controlPosition (p3)
147 // If the popup is positioned up it will align with the top right of
148 // m_controlPosition (p2)
Torne (Richard Coles)09380292014-02-21 12:17:33 +0000149 WebCore::FloatQuad m_controlPosition;
150 WebCore::IntSize m_controlSize;
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100151
152 // Whether the popup is currently open.
153 bool m_popupOpen;
154};
155
156} // namespace WebCore
157
158#endif