1f10a37f614d0ae6b08006301f8a7a0c22d54660
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / PopupContainer.h
1
2 /*
3  * Copyright (c) 2011, Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
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
14  * distribution.
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.
18  *
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.
30  */
31
32 #ifndef PopupContainer_h
33 #define PopupContainer_h
34
35 #include "platform/PopupMenuStyle.h"
36 #include "platform/geometry/FloatQuad.h"
37 #include "platform/scroll/FramelessScrollView.h"
38 #include "web/PopupListBox.h"
39
40 namespace blink {
41
42 class ChromeClient;
43 class FrameView;
44 class PopupMenuClient;
45 struct WebPopupMenuInfo;
46
47 class PopupContainer FINAL : public FramelessScrollView {
48 public:
49     static PassRefPtr<PopupContainer> create(PopupMenuClient*, bool deviceSupportsTouch);
50
51     // Whether a key event should be sent to this popup.
52     bool isInterestedInEventForKey(int keyCode);
53
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;
64
65     // PopupContainer methods
66
67     // Show the popup
68     void showPopup(FrameView*);
69
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);
76
77     // Hides the popup.
78     void hidePopup();
79
80     // The popup was hidden.
81     void notifyPopupHidden();
82
83     PopupListBox* listBox() const { return m_listBox.get(); }
84
85     bool isRTL() const;
86
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;
90
91     // Refresh the popup values from the PopupMenuClient.
92     IntRect refresh(const IntRect& targetControlRect);
93
94     // The menu per-item data.
95     const Vector<PopupItem*>& popupData() const;
96
97     // The height of a row in the menu.
98     int menuItemHeight() const;
99
100     // The size of the font being used.
101     int menuItemFontSize() const;
102
103     // The style of the menu being used.
104     PopupMenuStyle menuStyle() const;
105
106     // While hovering popup menu window, we want to show tool tip message.
107     String getSelectedItemToolTip();
108
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);
111
112 private:
113     friend class WTF::RefCounted<PopupContainer>;
114
115     PopupContainer(PopupMenuClient*, bool deviceSupportsTouch);
116     virtual ~PopupContainer();
117
118     // Paint the border.
119     void paintBorder(GraphicsContext*, const IntRect&);
120
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);
123
124     void fitToListBox();
125
126     void popupOpened(const IntRect& bounds);
127     void getPopupMenuInfo(WebPopupMenuInfo*);
128
129     // Returns the ChromeClient of the page this popup is associated with.
130     ChromeClient& chromeClient();
131
132     RefPtr<PopupListBox> m_listBox;
133     RefPtr<FrameView> m_frameView;
134
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;
149
150     // Whether the popup is currently open.
151     bool m_popupOpen;
152 };
153
154 } // namespace blink
155
156 #endif