2 * Copyright (c) 2011, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef PopupContainer_h
32 #define PopupContainer_h
34 #include "FramelessScrollView.h"
35 #include "PopupListBox.h"
36 #include "PopupMenuStyle.h"
40 class ChromeClientChromium;
42 class PopupMenuClient;
44 class PopupContainer : public FramelessScrollView {
47 Select, // HTML select popup.
48 Suggestion, // Autocomplete/autofill popup.
51 static PassRefPtr<PopupContainer> create(PopupMenuClient*, PopupType,
52 const PopupContainerSettings&);
54 // Whether a key event should be sent to this popup.
55 virtual bool isInterestedInEventForKey(int keyCode);
57 // FramelessScrollView
58 virtual void paint(GraphicsContext*, const IntRect&);
60 virtual bool handleMouseDownEvent(const PlatformMouseEvent&);
61 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&);
62 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&);
63 virtual bool handleWheelEvent(const PlatformWheelEvent&);
64 virtual bool handleKeyEvent(const PlatformKeyboardEvent&);
65 #if ENABLE(TOUCH_EVENTS)
66 virtual bool handleTouchEvent(const PlatformTouchEvent&);
68 #if ENABLE(GESTURE_RECOGNIZER)
69 virtual bool handleGestureEvent(const PlatformGestureEvent&);
72 // PopupContainer methods
75 void showPopup(FrameView*);
77 // Show the popup in the specified rect for the specified frame.
78 // Note: this code was somehow arbitrarily factored-out of the Popup class
79 // so WebViewImpl can create a PopupContainer. This method is used for
80 // displaying auto complete popup menus on Mac Chromium, and for all
81 // popups on other platforms.
82 void showInRect(const IntRect&, FrameView*, int index);
87 // The popup was hidden.
88 void notifyPopupHidden();
90 // Compute size of widget and children. Return right offset for the popup right alignment.
91 int layoutAndGetRTLOffset();
93 PopupListBox* listBox() const { return m_listBox.get(); }
97 // Gets the index of the item that the user is currently moused-over or
98 // has selected with the keyboard up/down arrows.
99 int selectedIndex() const;
101 // Refresh the popup values from the PopupMenuClient.
102 void refresh(const IntRect& targetControlRect);
104 // The menu per-item data.
105 const WTF::Vector<PopupItem*>& popupData() const;
107 // The height of a row in the menu.
108 int menuItemHeight() const;
110 // The size of the font being used.
111 int menuItemFontSize() const;
113 // The style of the menu being used.
114 PopupMenuStyle menuStyle() const;
116 PopupType popupType() const { return m_popupType; }
118 // While hovering popup menu window, we want to show tool tip message.
119 String getSelectedItemToolTip();
122 friend class WTF::RefCounted<PopupContainer>;
124 PopupContainer(PopupMenuClient*, PopupType, const PopupContainerSettings&);
128 void paintBorder(GraphicsContext*, const IntRect&);
130 // Layout and calculate popup widget size and location and returns it as IntRect.
131 IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const IntPoint& popupInitialCoordinate);
133 // Returns the ChromeClient of the page this popup is associated with.
134 ChromeClientChromium* chromeClientChromium();
136 RefPtr<PopupListBox> m_listBox;
137 RefPtr<FrameView> m_frameView;
139 PopupContainerSettings m_settings;
140 PopupType m_popupType;
141 IntRect m_originalFrameRect;
142 // Whether the popup is currently open.
146 } // namespace WebCore