initial import
[vuplus_webkit] / Source / WebCore / platform / chromium / PopupContainer.h
1 /*
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
34 #include "FramelessScrollView.h"
35 #include "PopupListBox.h"
36 #include "PopupMenuStyle.h"
37
38 namespace WebCore {
39
40 class ChromeClientChromium;
41 class FrameView;
42 class PopupMenuClient;
43
44 class PopupContainer : public FramelessScrollView {
45 public:
46     enum PopupType {
47         Select, // HTML select popup.
48         Suggestion, // Autocomplete/autofill popup.
49     };
50
51     static PassRefPtr<PopupContainer> create(PopupMenuClient*, PopupType,
52                                              const PopupContainerSettings&);
53
54     // Whether a key event should be sent to this popup.
55     virtual bool isInterestedInEventForKey(int keyCode);
56
57     // FramelessScrollView
58     virtual void paint(GraphicsContext*, const IntRect&);
59     virtual void hide();
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&);
67 #endif
68 #if ENABLE(GESTURE_RECOGNIZER)
69     virtual bool handleGestureEvent(const PlatformGestureEvent&);
70 #endif
71
72     // PopupContainer methods
73
74     // Show the popup
75     void showPopup(FrameView*);
76
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);
83
84     // Hides the popup.
85     void hidePopup();
86
87     // The popup was hidden.
88     void notifyPopupHidden();
89
90     // Compute size of widget and children. Return right offset for the popup right alignment.
91     int layoutAndGetRTLOffset();
92
93     PopupListBox* listBox() const { return m_listBox.get(); }
94
95     bool isRTL() const;
96
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;
100
101     // Refresh the popup values from the PopupMenuClient.
102     void refresh(const IntRect& targetControlRect);
103
104     // The menu per-item data.
105     const WTF::Vector<PopupItem*>& popupData() const;
106
107     // The height of a row in the menu.
108     int menuItemHeight() const;
109
110     // The size of the font being used.
111     int menuItemFontSize() const;
112
113     // The style of the menu being used.
114     PopupMenuStyle menuStyle() const;
115
116     PopupType popupType() const { return m_popupType; }
117
118     // While hovering popup menu window, we want to show tool tip message.
119     String getSelectedItemToolTip();
120
121 private:
122     friend class WTF::RefCounted<PopupContainer>;
123
124     PopupContainer(PopupMenuClient*, PopupType, const PopupContainerSettings&);
125     ~PopupContainer();
126
127     // Paint the border.
128     void paintBorder(GraphicsContext*, const IntRect&);
129
130     // Layout and calculate popup widget size and location and returns it as IntRect.
131     IntRect layoutAndCalculateWidgetRect(int targetControlHeight, const IntPoint& popupInitialCoordinate);
132
133     // Returns the ChromeClient of the page this popup is associated with.
134     ChromeClientChromium* chromeClientChromium();
135
136     RefPtr<PopupListBox> m_listBox;
137     RefPtr<FrameView> m_frameView;
138
139     PopupContainerSettings m_settings;
140     PopupType m_popupType;
141     IntRect m_originalFrameRect;
142     // Whether the popup is currently open.
143     bool m_popupOpen;
144 };
145
146 } // namespace WebCore
147
148 #endif