OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011, Google Inc. All rights reserved. | 2 * Copyright (c) 2011, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef PopupListBox_h | 31 #ifndef PopupListBox_h |
32 #define PopupListBox_h | 32 #define PopupListBox_h |
33 | 33 |
34 #include "core/dom/Element.h" | 34 #include "core/dom/Element.h" |
35 #include "platform/scroll/FramelessScrollView.h" | 35 #include "platform/scroll/ScrollView.h" |
36 #include "platform/text/TextDirection.h" | 36 #include "platform/text/TextDirection.h" |
37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 class Font; | 41 class Font; |
42 class GraphicsContext; | 42 class GraphicsContext; |
43 class IntRect; | 43 class IntRect; |
44 class PlatformKeyboardEvent; | 44 class PlatformKeyboardEvent; |
45 class PlatformMouseEvent; | 45 class PlatformMouseEvent; |
46 class PlatformGestureEvent; | 46 class PlatformGestureEvent; |
47 class PlatformTouchEvent; | 47 class PlatformTouchEvent; |
48 class PlatformWheelEvent; | 48 class PlatformWheelEvent; |
| 49 class PopupContainer; |
49 class PopupMenuClient; | 50 class PopupMenuClient; |
50 typedef unsigned long long TimeStamp; | 51 typedef unsigned long long TimeStamp; |
51 | 52 |
52 class PopupContent { | 53 class PopupContent { |
53 public: | 54 public: |
54 virtual void layout() = 0; | 55 virtual void layout() = 0; |
55 virtual void setMaxHeight(int) = 0; | 56 virtual void setMaxHeight(int) = 0; |
56 virtual void setMaxWidthAndLayout(int) = 0; | 57 virtual void setMaxWidthAndLayout(int) = 0; |
57 virtual int popupContentHeight() const = 0; | 58 virtual int popupContentHeight() const = 0; |
58 virtual ~PopupContent() { }; | 59 virtual ~PopupContent() { }; |
(...skipping 16 matching lines...) Expand all Loading... |
75 } | 76 } |
76 String label; | 77 String label; |
77 Type type; | 78 Type type; |
78 int yOffset; // y offset of this item, relative to the top of the popup. | 79 int yOffset; // y offset of this item, relative to the top of the popup. |
79 TextDirection textDirection; | 80 TextDirection textDirection; |
80 bool hasTextDirectionOverride; | 81 bool hasTextDirectionOverride; |
81 bool enabled; | 82 bool enabled; |
82 bool displayNone; | 83 bool displayNone; |
83 }; | 84 }; |
84 | 85 |
85 // This class uses WebCore code to paint and handle events for a drop-down list | 86 // This class manages the scrollable content inside a <select> popup. |
86 // box ("combobox" on Windows). | 87 class PopupListBox FINAL : public ScrollView, public PopupContent { |
87 class PopupListBox FINAL : public FramelessScrollView, public PopupContent { | |
88 public: | 88 public: |
89 static PassRefPtr<PopupListBox> create(PopupMenuClient* client, bool deviceS
upportsTouch) | 89 static PassRefPtr<PopupListBox> create(PopupMenuClient* client, bool deviceS
upportsTouch, PopupContainer* container) |
90 { | 90 { |
91 return adoptRef(new PopupListBox(client, deviceSupportsTouch)); | 91 return adoptRef(new PopupListBox(client, deviceSupportsTouch, container)
); |
92 } | 92 } |
93 | 93 |
94 // FramelessScrollView | 94 // Widget |
95 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE; | 95 virtual void invalidateRect(const IntRect&) OVERRIDE; |
96 virtual bool handleMouseDownEvent(const PlatformMouseEvent&) OVERRIDE; | 96 |
97 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&) OVERRIDE; | 97 // ScrollableArea |
98 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) OVERRIDE; | 98 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE; |
99 virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE; | 99 virtual bool isActive() const OVERRIDE; |
100 virtual bool handleKeyEvent(const PlatformKeyboardEvent&) OVERRIDE; | 100 virtual bool scrollbarsCanBeActive() const OVERRIDE; |
101 virtual bool handleTouchEvent(const PlatformTouchEvent&) OVERRIDE; | 101 virtual IntRect scrollableAreaBoundingBox() const OVERRIDE; |
102 virtual bool handleGestureEvent(const PlatformGestureEvent&) OVERRIDE; | |
103 | 102 |
104 // ScrollView | 103 // ScrollView |
| 104 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE; |
105 virtual HostWindow* hostWindow() const OVERRIDE; | 105 virtual HostWindow* hostWindow() const OVERRIDE; |
106 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE; | 106 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE; |
| 107 virtual IntRect windowClipRect(IncludeScrollbarsInRect = ExcludeScrollbars)
const OVERRIDE; |
107 | 108 |
108 // PopupListBox methods | 109 // PopupListBox methods |
109 | 110 |
| 111 virtual bool handleMouseDownEvent(const PlatformMouseEvent&); |
| 112 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&); |
| 113 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&); |
| 114 virtual bool handleWheelEvent(const PlatformWheelEvent&); |
| 115 virtual bool handleKeyEvent(const PlatformKeyboardEvent&); |
| 116 virtual bool handleTouchEvent(const PlatformTouchEvent&); |
| 117 virtual bool handleGestureEvent(const PlatformGestureEvent&); |
| 118 |
110 // Closes the popup | 119 // Closes the popup |
111 void abandon(); | 120 void abandon(); |
112 | 121 |
113 // Updates our internal list to match the client. | 122 // Updates our internal list to match the client. |
114 void updateFromElement(); | 123 void updateFromElement(); |
115 | 124 |
116 // Frees any allocated resources used in a particular popup session. | 125 // Frees any allocated resources used in a particular popup session. |
117 void clear(); | 126 void clear(); |
118 | 127 |
119 // Sets the index of the option that is displayed in the <select> widget in
the page | 128 // Sets the index of the option that is displayed in the <select> widget in
the page |
(...skipping 14 matching lines...) Expand all Loading... |
134 | 143 |
135 void setBaseWidth(int width) { m_baseWidth = std::min(m_maxWindowWidth, widt
h); } | 144 void setBaseWidth(int width) { m_baseWidth = std::min(m_maxWindowWidth, widt
h); } |
136 | 145 |
137 // Computes the size of widget and children. | 146 // Computes the size of widget and children. |
138 virtual void layout() OVERRIDE; | 147 virtual void layout() OVERRIDE; |
139 | 148 |
140 // Returns whether the popup wants to process events for the passed key. | 149 // Returns whether the popup wants to process events for the passed key. |
141 bool isInterestedInEventForKey(int keyCode); | 150 bool isInterestedInEventForKey(int keyCode); |
142 | 151 |
143 // Gets the height of a row. | 152 // Gets the height of a row. |
144 int getRowHeight(int index); | 153 int getRowHeight(int index) const; |
145 | 154 |
146 int getRowBaseWidth(int index); | 155 int getRowBaseWidth(int index); |
147 | 156 |
148 virtual void setMaxHeight(int maxHeight) OVERRIDE { m_maxHeight = maxHeight;
} | 157 virtual void setMaxHeight(int maxHeight) OVERRIDE { m_maxHeight = maxHeight;
} |
149 | 158 |
150 void setMaxWidth(int maxWidth) { m_maxWindowWidth = maxWidth; } | 159 void setMaxWidth(int maxWidth) { m_maxWindowWidth = maxWidth; } |
151 | 160 |
152 virtual void setMaxWidthAndLayout(int) OVERRIDE; | 161 virtual void setMaxWidthAndLayout(int) OVERRIDE; |
153 | 162 |
154 void disconnectClient() { m_popupClient = 0; } | 163 void disconnectClient() { m_popupClient = 0; } |
155 | 164 |
156 const Vector<PopupItem*>& items() const { return m_items; } | 165 const Vector<PopupItem*>& items() const { return m_items; } |
157 | 166 |
158 virtual int popupContentHeight() const OVERRIDE; | 167 virtual int popupContentHeight() const OVERRIDE; |
159 | 168 |
160 static const int defaultMaxHeight; | 169 static const int defaultMaxHeight; |
161 | 170 |
| 171 protected: |
| 172 // ScrollView |
| 173 virtual void paintContents(GraphicsContext*, const IntRect&) OVERRIDE { } |
| 174 virtual void scrollbarExistenceDidChange() OVERRIDE { } |
| 175 |
162 private: | 176 private: |
163 friend class PopupContainer; | 177 friend class PopupContainer; |
164 friend class RefCounted<PopupListBox>; | 178 friend class RefCounted<PopupListBox>; |
165 | 179 |
166 PopupListBox(PopupMenuClient*, bool deviceSupportsTouch); | 180 PopupListBox(PopupMenuClient*, bool deviceSupportsTouch, PopupContainer*); |
167 | 181 virtual ~PopupListBox(); |
168 virtual ~PopupListBox() | |
169 { | |
170 clear(); | |
171 } | |
172 | 182 |
173 // Hides the popup. Other classes should not call this. Use abandon instead. | 183 // Hides the popup. Other classes should not call this. Use abandon instead. |
174 void hidePopup(); | 184 void hidePopup(); |
175 | 185 |
176 // Returns true if the selection can be changed to index. | 186 // Returns true if the selection can be changed to index. |
177 // Disabled items, or labels cannot be selected. | 187 // Disabled items, or labels cannot be selected. |
178 bool isSelectableItem(int index); | 188 bool isSelectableItem(int index); |
179 | 189 |
180 // Select an index in the list, scrolling if necessary. | 190 // Select an index in the list, scrolling if necessary. |
181 void selectIndex(int index); | 191 void selectIndex(int index); |
(...skipping 22 matching lines...) Expand all Loading... |
204 // Paint an individual row | 214 // Paint an individual row |
205 void paintRow(GraphicsContext*, const IntRect&, int rowIndex); | 215 void paintRow(GraphicsContext*, const IntRect&, int rowIndex); |
206 | 216 |
207 // Test if the given point is within the bounds of the popup window. | 217 // Test if the given point is within the bounds of the popup window. |
208 bool isPointInBounds(const IntPoint&); | 218 bool isPointInBounds(const IntPoint&); |
209 | 219 |
210 // Called when the user presses a text key. Does a prefix-search of the item
s. | 220 // Called when the user presses a text key. Does a prefix-search of the item
s. |
211 void typeAheadFind(const PlatformKeyboardEvent&); | 221 void typeAheadFind(const PlatformKeyboardEvent&); |
212 | 222 |
213 // Returns the font to use for the given row | 223 // Returns the font to use for the given row |
214 Font getRowFont(int index); | 224 Font getRowFont(int index) const; |
215 | 225 |
216 // Moves the selection down/up one item, taking care of looping back to the | 226 // Moves the selection down/up one item, taking care of looping back to the |
217 // first/last element if m_loopSelectionNavigation is true. | 227 // first/last element if m_loopSelectionNavigation is true. |
218 void selectPreviousRow(); | 228 void selectPreviousRow(); |
219 void selectNextRow(); | 229 void selectNextRow(); |
220 | 230 |
221 // If the device is a touch screen we increase the height of menu items | 231 // If the device is a touch screen we increase the height of menu items |
222 // to make it easier to unambiguously touch them. | 232 // to make it easier to unambiguously touch them. |
223 bool m_deviceSupportsTouch; | 233 bool m_deviceSupportsTouch; |
224 | 234 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 UChar m_repeatingChar; | 278 UChar m_repeatingChar; |
269 | 279 |
270 // The last time the user hit a key. Used for typeAheadFind. | 280 // The last time the user hit a key. Used for typeAheadFind. |
271 TimeStamp m_lastCharTime; | 281 TimeStamp m_lastCharTime; |
272 | 282 |
273 // If width exeeds screen width, we have to clip it. | 283 // If width exeeds screen width, we have to clip it. |
274 int m_maxWindowWidth; | 284 int m_maxWindowWidth; |
275 | 285 |
276 // To forward last mouse release event. | 286 // To forward last mouse release event. |
277 RefPtrWillBePersistent<Element> m_focusedElement; | 287 RefPtrWillBePersistent<Element> m_focusedElement; |
| 288 |
| 289 PopupContainer* m_container; |
278 }; | 290 }; |
279 | 291 |
280 } // namespace blink | 292 } // namespace blink |
281 | 293 |
282 #endif | 294 #endif |
OLD | NEW |