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 "platform/scroll/FramelessScrollView.h"
38 #include "web/PopupListBox.h"
44 class PopupMenuClient;
45 struct WebPopupMenuInfo;
47 class PopupContainer FINAL : public FramelessScrollView {
49 static PassRefPtr<PopupContainer> create(PopupMenuClient*, bool deviceSupportsTouch);
51 // Whether a key event should be sent to this popup.
52 bool isInterestedInEventForKey(int keyCode);
54 // FramelessScrollView
55 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE;
56 virtual void hide() OVERRIDE;
57 virtual bool handleMouseDownEvent(const PlatformMouseEvent&) OVERRIDE;
58 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&) OVERRIDE;
59 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) OVERRIDE;
60 virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE;
61 virtual bool handleKeyEvent(const PlatformKeyboardEvent&) OVERRIDE;
62 virtual bool handleTouchEvent(const PlatformTouchEvent&) OVERRIDE;
63 virtual bool handleGestureEvent(const PlatformGestureEvent&) OVERRIDE;
65 // PopupContainer methods
68 void showPopup(FrameView*);
70 // Show the popup in the specified rect for the specified frame.
71 // Note: this code was somehow arbitrarily factored-out of the Popup class
72 // so WebViewImpl can create a PopupContainer. This method is used for
73 // displaying auto complete popup menus on Mac Chromium, and for all
74 // popups on other platforms.
75 void showInRect(const FloatQuad& controlPosition, const IntSize& controlSize, FrameView*, int index);
80 // The popup was hidden.
81 void notifyPopupHidden();
83 PopupListBox* listBox() const { return m_listBox.get(); }
87 // Gets the index of the item that the user is currently moused-over or
88 // has selected with the keyboard up/down arrows.
89 int selectedIndex() const;
91 // Refresh the popup values from the PopupMenuClient.
92 IntRect refresh(const IntRect& targetControlRect);
94 // The menu per-item data.
95 const Vector<PopupItem*>& popupData() const;
97 // The height of a row in the menu.
98 int menuItemHeight() const;
100 // The size of the font being used.
101 int menuItemFontSize() const;
103 // The style of the menu being used.
104 PopupMenuStyle menuStyle() const;
106 // While hovering popup menu window, we want to show tool tip message.
107 String getSelectedItemToolTip();
109 // This is public for testing.
110 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);
113 friend class WTF::RefCounted<PopupContainer>;
115 PopupContainer(PopupMenuClient*, bool deviceSupportsTouch);
116 virtual ~PopupContainer();
119 void paintBorder(GraphicsContext*, const IntRect&);
121 // Layout and calculate popup widget size and location and returns it as IntRect.
122 IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const IntSize& transformOffset, const IntPoint& popupInitialCoordinate);
126 void popupOpened(const IntRect& bounds);
127 void getPopupMenuInfo(WebPopupMenuInfo*);
129 // Returns the ChromeClient of the page this popup is associated with.
130 ChromeClient& chromeClient();
132 RefPtr<PopupListBox> m_listBox;
133 RefPtr<FrameView> m_frameView;
135 // m_controlPosition contains the transformed position of the
136 // <select>/<input> associated with this popup. m_controlSize is the size
137 // of the <select>/<input> without transform.
138 // The popup menu will be positioned as follows:
139 // LTR : If the popup is positioned down it will align with the bottom left
140 // of m_controlPosition (p4)
141 // If the popup is positioned up it will align with the top left of
142 // m_controlPosition (p1)
143 // RTL : If the popup is positioned down it will align with the bottom right
144 // of m_controlPosition (p3)
145 // If the popup is positioned up it will align with the top right of
146 // m_controlPosition (p2)
147 FloatQuad m_controlPosition;
148 IntSize m_controlSize;
150 // Whether the popup is currently open.