| 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 |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 #ifndef PopupListBox_h | 31 #ifndef PopupListBox_h |
| 31 #define PopupListBox_h | 32 #define PopupListBox_h |
| 32 | 33 |
| 33 #include "core/dom/Node.h" | 34 #include "core/dom/Node.h" |
| 34 #include "core/platform/chromium/FramelessScrollView.h" | 35 #include "core/platform/chromium/FramelessScrollView.h" |
| 35 #include "core/platform/text/TextDirection.h" | 36 #include "core/platform/text/TextDirection.h" |
| 36 #include <wtf/text/WTFString.h> | 37 #include "wtf/text/WTFString.h" |
| 37 | 38 |
| 38 namespace WebCore { | 39 namespace WebCore { |
| 39 | 40 |
| 40 typedef unsigned long long TimeStamp; | 41 typedef unsigned long long TimeStamp; |
| 41 | 42 |
| 42 static const int kLabelToIconPadding = 5; | |
| 43 static const int kLinePaddingHeight = 3; // Padding height put at the top and bo
ttom of each line. | |
| 44 static const int kMaxHeight = 500; | |
| 45 static const int kMaxVisibleRows = 20; | |
| 46 static const int kMinEndOfLinePadding = 2; | |
| 47 static const int kTextToLabelPadding = 10; | |
| 48 static const TimeStamp kTypeAheadTimeoutMs = 1000; | |
| 49 | |
| 50 class Font; | 43 class Font; |
| 51 class GraphicsContext; | 44 class GraphicsContext; |
| 52 class IntRect; | 45 class IntRect; |
| 53 class PlatformKeyboardEvent; | 46 class PlatformKeyboardEvent; |
| 54 class PlatformMouseEvent; | 47 class PlatformMouseEvent; |
| 55 class PlatformGestureEvent; | 48 class PlatformGestureEvent; |
| 56 class PlatformTouchEvent; | 49 class PlatformTouchEvent; |
| 57 class PlatformWheelEvent; | 50 class PlatformWheelEvent; |
| 58 class PopupMenuClient; | 51 class PopupMenuClient; |
| 59 | 52 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // This class uses WebCore code to paint and handle events for a drop-down list | 110 // This class uses WebCore code to paint and handle events for a drop-down list |
| 118 // box ("combobox" on Windows). | 111 // box ("combobox" on Windows). |
| 119 class PopupListBox : public FramelessScrollView, public PopupContent { | 112 class PopupListBox : public FramelessScrollView, public PopupContent { |
| 120 public: | 113 public: |
| 121 static PassRefPtr<PopupListBox> create(PopupMenuClient* client, const PopupC
ontainerSettings& settings) | 114 static PassRefPtr<PopupListBox> create(PopupMenuClient* client, const PopupC
ontainerSettings& settings) |
| 122 { | 115 { |
| 123 return adoptRef(new PopupListBox(client, settings)); | 116 return adoptRef(new PopupListBox(client, settings)); |
| 124 } | 117 } |
| 125 | 118 |
| 126 // FramelessScrollView | 119 // FramelessScrollView |
| 127 virtual void paint(GraphicsContext*, const IntRect&); | 120 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE; |
| 128 virtual bool handleMouseDownEvent(const PlatformMouseEvent&); | 121 virtual bool handleMouseDownEvent(const PlatformMouseEvent&) OVERRIDE; |
| 129 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&); | 122 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&) OVERRIDE; |
| 130 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&); | 123 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) OVERRIDE; |
| 131 virtual bool handleWheelEvent(const PlatformWheelEvent&); | 124 virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE; |
| 132 virtual bool handleKeyEvent(const PlatformKeyboardEvent&); | 125 virtual bool handleKeyEvent(const PlatformKeyboardEvent&) OVERRIDE; |
| 133 virtual bool handleTouchEvent(const PlatformTouchEvent&); | 126 virtual bool handleTouchEvent(const PlatformTouchEvent&) OVERRIDE; |
| 134 virtual bool handleGestureEvent(const PlatformGestureEvent&); | 127 virtual bool handleGestureEvent(const PlatformGestureEvent&) OVERRIDE; |
| 135 | 128 |
| 136 // ScrollView | 129 // ScrollView |
| 137 virtual HostWindow* hostWindow() const; | 130 virtual HostWindow* hostWindow() const OVERRIDE; |
| 138 | 131 |
| 139 // PopupListBox methods | 132 // PopupListBox methods |
| 140 | 133 |
| 141 // Hides the popup. | 134 // Hides the popup. |
| 142 void hidePopup(); | 135 void hidePopup(); |
| 143 | 136 |
| 144 // Updates our internal list to match the client. | 137 // Updates our internal list to match the client. |
| 145 void updateFromElement(); | 138 void updateFromElement(); |
| 146 | 139 |
| 147 // Frees any allocated resources used in a particular popup session. | 140 // Frees any allocated resources used in a particular popup session. |
| 148 void clear(); | 141 void clear(); |
| 149 | 142 |
| 150 // Sets the index of the option that is displayed in the <select> widget in
the page | 143 // Sets the index of the option that is displayed in the <select> widget in
the page |
| 151 void setOriginalIndex(int); | 144 void setOriginalIndex(int); |
| 152 | 145 |
| 153 // Gets the index of the item that the user is currently moused over or has
selected with | 146 // Gets the index of the item that the user is currently moused over or has |
| 154 // the keyboard. This is not the same as the original index, since the user
has not yet | 147 // selected with the keyboard. This is not the same as the original index, |
| 155 // accepted this input. | 148 // since the user has not yet accepted this input. |
| 156 int selectedIndex() const { return m_selectedIndex; } | 149 int selectedIndex() const { return m_selectedIndex; } |
| 157 | 150 |
| 158 // Moves selection down/up the given number of items, scrolling if necessary
. | 151 // Moves selection down/up the given number of items, scrolling if necessary
. |
| 159 // Positive is down. The resulting index will be clamped to the range | 152 // Positive is down. The resulting index will be clamped to the range |
| 160 // [0, numItems), and non-option items will be skipped. | 153 // [0, numItems), and non-option items will be skipped. |
| 161 void adjustSelectedIndex(int delta); | 154 void adjustSelectedIndex(int delta); |
| 162 | 155 |
| 163 // Returns the number of items in the list. | 156 // Returns the number of items in the list. |
| 164 int numItems() const { return static_cast<int>(m_items.size()); } | 157 int numItems() const { return static_cast<int>(m_items.size()); } |
| 165 | 158 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 179 void setMaxWidth(int maxWidth) { m_maxWindowWidth = maxWidth; } | 172 void setMaxWidth(int maxWidth) { m_maxWindowWidth = maxWidth; } |
| 180 | 173 |
| 181 virtual void setMaxWidthAndLayout(int) OVERRIDE; | 174 virtual void setMaxWidthAndLayout(int) OVERRIDE; |
| 182 | 175 |
| 183 void disconnectClient() { m_popupClient = 0; } | 176 void disconnectClient() { m_popupClient = 0; } |
| 184 | 177 |
| 185 const Vector<PopupItem*>& items() const { return m_items; } | 178 const Vector<PopupItem*>& items() const { return m_items; } |
| 186 | 179 |
| 187 virtual int popupContentHeight() const OVERRIDE; | 180 virtual int popupContentHeight() const OVERRIDE; |
| 188 | 181 |
| 182 static const int defaultMaxHeight; |
| 183 |
| 189 private: | 184 private: |
| 190 friend class PopupContainer; | 185 friend class PopupContainer; |
| 191 friend class RefCounted<PopupListBox>; | 186 friend class RefCounted<PopupListBox>; |
| 192 | 187 |
| 193 PopupListBox(PopupMenuClient*, const PopupContainerSettings&); | 188 PopupListBox(PopupMenuClient*, const PopupContainerSettings&); |
| 194 | 189 |
| 195 virtual ~PopupListBox() | 190 virtual ~PopupListBox() |
| 196 { | 191 { |
| 197 clear(); | 192 clear(); |
| 198 } | 193 } |
| 199 | 194 |
| 200 // Closes the popup | 195 // Closes the popup |
| 201 void abandon(); | 196 void abandon(); |
| 202 | 197 |
| 203 // Returns true if the selection can be changed to index. | 198 // Returns true if the selection can be changed to index. |
| 204 // Disabled items, or labels cannot be selected. | 199 // Disabled items, or labels cannot be selected. |
| 205 bool isSelectableItem(int index); | 200 bool isSelectableItem(int index); |
| 206 | 201 |
| 207 // Select an index in the list, scrolling if necessary. | 202 // Select an index in the list, scrolling if necessary. |
| 208 void selectIndex(int index); | 203 void selectIndex(int index); |
| 209 | 204 |
| 210 // Accepts the selected index as the value to be displayed in the <select> w
idget on | 205 // Accepts the selected index as the value to be displayed in the <select> |
| 211 // the web page, and closes the popup. Returns true if index is accepted. | 206 // widget on the web page, and closes the popup. Returns true if index is |
| 207 // accepted. |
| 212 bool acceptIndex(int index); | 208 bool acceptIndex(int index); |
| 213 | 209 |
| 214 // Clears the selection (so no row appears selected). | 210 // Clears the selection (so no row appears selected). |
| 215 void clearSelection(); | 211 void clearSelection(); |
| 216 | 212 |
| 217 // Scrolls to reveal the given index. | 213 // Scrolls to reveal the given index. |
| 218 void scrollToRevealRow(int index); | 214 void scrollToRevealRow(int index); |
| 219 void scrollToRevealSelection() { scrollToRevealRow(m_selectedIndex); } | 215 void scrollToRevealSelection() { scrollToRevealRow(m_selectedIndex); } |
| 220 | 216 |
| 221 // Invalidates the row at the given index. | 217 // Invalidates the row at the given index. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 240 Font getRowFont(int index); | 236 Font getRowFont(int index); |
| 241 | 237 |
| 242 // Moves the selection down/up one item, taking care of looping back to the | 238 // Moves the selection down/up one item, taking care of looping back to the |
| 243 // first/last element if m_loopSelectionNavigation is true. | 239 // first/last element if m_loopSelectionNavigation is true. |
| 244 void selectPreviousRow(); | 240 void selectPreviousRow(); |
| 245 void selectNextRow(); | 241 void selectNextRow(); |
| 246 | 242 |
| 247 // The settings that specify the behavior for this Popup window. | 243 // The settings that specify the behavior for this Popup window. |
| 248 PopupContainerSettings m_settings; | 244 PopupContainerSettings m_settings; |
| 249 | 245 |
| 250 // This is the index of the item marked as "selected" - i.e. displayed in th
e widget on the | 246 // This is the index of the item marked as "selected" - i.e. displayed in |
| 251 // page. | 247 // the widget on the page. |
| 252 int m_originalIndex; | 248 int m_originalIndex; |
| 253 | 249 |
| 254 // This is the index of the item that the user is hovered over or has select
ed using the | 250 // This is the index of the item that the user is hovered over or has |
| 255 // keyboard in the list. They have not confirmed this selection by clicking
or pressing | 251 // selected using the keyboard in the list. They have not confirmed this |
| 256 // enter yet however. | 252 // selection by clicking or pressing enter yet however. |
| 257 int m_selectedIndex; | 253 int m_selectedIndex; |
| 258 | 254 |
| 259 // If >= 0, this is the index we should accept if the popup is "abandoned". | 255 // If >= 0, this is the index we should accept if the popup is "abandoned". |
| 260 // This is used for keyboard navigation, where we want the | 256 // This is used for keyboard navigation, where we want the |
| 261 // selection to change immediately, and is only used if the settings | 257 // selection to change immediately, and is only used if the settings |
| 262 // acceptOnAbandon field is true. | 258 // acceptOnAbandon field is true. |
| 263 int m_acceptedIndexOnAbandon; | 259 int m_acceptedIndexOnAbandon; |
| 264 | 260 |
| 265 // This is the number of rows visible in the popup. The maximum number visib
le at a time is | 261 // This is the number of rows visible in the popup. The maximum number |
| 266 // defined as being kMaxVisibleRows. For a scrolled popup, this can be thoug
ht of as the | 262 // visible at a time is defined as being kMaxVisibleRows. For a scrolled |
| 267 // page size in data units. | 263 // popup, this can be thought of as the page size in data units. |
| 268 int m_visibleRows; | 264 int m_visibleRows; |
| 269 | 265 |
| 270 // Our suggested width, not including scrollbar. | 266 // Our suggested width, not including scrollbar. |
| 271 int m_baseWidth; | 267 int m_baseWidth; |
| 272 | 268 |
| 273 // The maximum height we can be without being off-screen. | 269 // The maximum height we can be without being off-screen. |
| 274 int m_maxHeight; | 270 int m_maxHeight; |
| 275 | 271 |
| 276 // A list of the options contained within the <select> | 272 // A list of the options contained within the <select> |
| 277 Vector<PopupItem*> m_items; | 273 Vector<PopupItem*> m_items; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 293 UChar m_repeatingChar; | 289 UChar m_repeatingChar; |
| 294 | 290 |
| 295 // The last time the user hit a key. Used for typeAheadFind. | 291 // The last time the user hit a key. Used for typeAheadFind. |
| 296 TimeStamp m_lastCharTime; | 292 TimeStamp m_lastCharTime; |
| 297 | 293 |
| 298 // If width exeeds screen width, we have to clip it. | 294 // If width exeeds screen width, we have to clip it. |
| 299 int m_maxWindowWidth; | 295 int m_maxWindowWidth; |
| 300 | 296 |
| 301 // To forward last mouse release event. | 297 // To forward last mouse release event. |
| 302 RefPtr<Node> m_focusedNode; | 298 RefPtr<Node> m_focusedNode; |
| 303 | |
| 304 }; | 299 }; |
| 305 | 300 |
| 306 } // namespace WebCore | 301 } // namespace WebCore |
| 307 | 302 |
| 308 #endif | 303 #endif |
| OLD | NEW |