3 * Copyright (c) 2011, Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef PopupContainer_h
33 #define PopupContainer_h
35 #include "platform/PopupMenuStyle.h"
36 #include "platform/geometry/FloatQuad.h"
37 #include "web/PopupListBox.h"
43 class PopupContainerClient;
44 class PopupMenuClient;
45 struct WebPopupMenuInfo;
47 // This class wraps a PopupListBox. It positions the popup, paints the border
48 // around it, and forwards input events.
49 // FIXME(skobes): This class can probably be combined with PopupListBox.
50 class PopupContainer FINAL : public Widget {
52 static PassRefPtr<PopupContainer> create(PopupMenuClient*, bool deviceSupportsTouch);
54 // Whether a key event should be sent to this popup.
55 bool isInterestedInEventForKey(int keyCode);
58 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE;
59 virtual void hide() OVERRIDE;
60 virtual HostWindow* hostWindow() const OVERRIDE;
61 virtual void invalidateRect(const IntRect&) OVERRIDE;
62 virtual IntPoint convertChildToSelf(const Widget* child, const IntPoint&) const OVERRIDE;
63 virtual IntPoint convertSelfToChild(const Widget* child, const IntPoint&) const OVERRIDE;
65 // PopupContainer methods
67 bool handleMouseDownEvent(const PlatformMouseEvent&);
68 bool handleMouseMoveEvent(const PlatformMouseEvent&);
69 bool handleMouseReleaseEvent(const PlatformMouseEvent&);
70 bool handleWheelEvent(const PlatformWheelEvent&);
71 bool handleKeyEvent(const PlatformKeyboardEvent&);
72 bool handleTouchEvent(const PlatformTouchEvent&);
73 bool handleGestureEvent(const PlatformGestureEvent&);
75 PopupContainerClient* client() const { return m_client; }
76 void setClient(PopupContainerClient* client) { m_client = client; }
79 void showPopup(FrameView*);
81 // Show the popup in the specified rect for the specified frame.
82 // Note: this code was somehow arbitrarily factored-out of the Popup class
83 // so WebViewImpl can create a PopupContainer. This method is used for
84 // displaying auto complete popup menus on Mac Chromium, and for all
85 // popups on other platforms.
86 void showInRect(const FloatQuad& controlPosition, const IntSize& controlSize, FrameView*, int index);
91 // The popup was hidden.
92 void notifyPopupHidden();
94 PopupListBox* listBox() const { return m_listBox.get(); }
98 // Gets the index of the item that the user is currently moused-over or
99 // has selected with the keyboard up/down arrows.
100 int selectedIndex() const;
102 // Refresh the popup values from the PopupMenuClient.
103 IntRect refresh(const IntRect& targetControlRect);
105 // The menu per-item data.
106 const Vector<PopupItem*>& popupData() const;
108 // The height of a row in the menu.
109 int menuItemHeight() const;
111 // The size of the font being used.
112 int menuItemFontSize() const;
114 // The style of the menu being used.
115 PopupMenuStyle menuStyle() const;
117 // While hovering popup menu window, we want to show tool tip message.
118 String getSelectedItemToolTip();
120 // This is public for testing.
121 static IntRect layoutAndCalculateWidgetRectInternal(IntRect widgetRectInScreen, int targetControlHeight, const FloatRect& windowRect, const FloatRect& screen, bool isRTL, const int rtlOffset, const int verticalOffset, const IntSize& transformOffset, PopupContent*, bool& needToResizeView);
123 void disconnectClient() { m_listBox->disconnectClient(); }
125 void updateFromElement() { m_listBox->updateFromElement(); }
128 friend class WTF::RefCounted<PopupContainer>;
130 PopupContainer(PopupMenuClient*, bool deviceSupportsTouch);
131 virtual ~PopupContainer();
134 void paintBorder(GraphicsContext*, const IntRect&);
136 // Layout and calculate popup widget size and location and returns it as IntRect.
137 IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const IntSize& transformOffset, const IntPoint& popupInitialCoordinate);
141 void popupOpened(const IntRect& bounds);
142 void getPopupMenuInfo(WebPopupMenuInfo*);
144 // Returns the ChromeClient of the page this popup is associated with.
145 ChromeClient& chromeClient();
147 RefPtr<PopupListBox> m_listBox;
148 RefPtr<FrameView> m_frameView;
150 // m_controlPosition contains the transformed position of the
151 // <select>/<input> associated with this popup. m_controlSize is the size
152 // of the <select>/<input> without transform.
153 // The popup menu will be positioned as follows:
154 // LTR : If the popup is positioned down it will align with the bottom left
155 // of m_controlPosition (p4)
156 // If the popup is positioned up it will align with the top left of
157 // m_controlPosition (p1)
158 // RTL : If the popup is positioned down it will align with the bottom right
159 // of m_controlPosition (p3)
160 // If the popup is positioned up it will align with the top right of
161 // m_controlPosition (p2)
162 FloatQuad m_controlPosition;
163 IntSize m_controlSize;
165 // Whether the popup is currently open.
168 PopupContainerClient* m_client;