| 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 19 matching lines...) Expand all Loading... |
| 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/FramelessScrollView.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 class Font; | 41 class Font; |
| 41 class GraphicsContext; | 42 class GraphicsContext; |
| 42 class IntRect; | 43 class IntRect; |
| 43 class PlatformKeyboardEvent; | 44 class PlatformKeyboardEvent; |
| 44 class PlatformMouseEvent; | 45 class PlatformMouseEvent; |
| 45 class PlatformGestureEvent; | 46 class PlatformGestureEvent; |
| 46 class PlatformTouchEvent; | 47 class PlatformTouchEvent; |
| 47 class PlatformWheelEvent; | 48 class PlatformWheelEvent; |
| 48 class PopupMenuClient; | 49 class PopupMenuClient; |
| 49 } | |
| 50 | |
| 51 namespace blink { | |
| 52 | |
| 53 typedef unsigned long long TimeStamp; | 50 typedef unsigned long long TimeStamp; |
| 54 | 51 |
| 55 class PopupContent { | 52 class PopupContent { |
| 56 public: | 53 public: |
| 57 virtual void layout() = 0; | 54 virtual void layout() = 0; |
| 58 virtual void setMaxHeight(int) = 0; | 55 virtual void setMaxHeight(int) = 0; |
| 59 virtual void setMaxWidthAndLayout(int) = 0; | 56 virtual void setMaxWidthAndLayout(int) = 0; |
| 60 virtual int popupContentHeight() const = 0; | 57 virtual int popupContentHeight() const = 0; |
| 61 virtual ~PopupContent() { }; | 58 virtual ~PopupContent() { }; |
| 62 }; | 59 }; |
| 63 | 60 |
| 64 // A container for the data for each menu item (e.g. represented by <option> | 61 // A container for the data for each menu item (e.g. represented by <option> |
| 65 // or <optgroup> in a <select> widget) and is used by PopupListBox. | 62 // or <optgroup> in a <select> widget) and is used by PopupListBox. |
| 66 struct PopupItem { | 63 struct PopupItem { |
| 67 enum Type { | 64 enum Type { |
| 68 TypeOption, | 65 TypeOption, |
| 69 TypeGroup, | 66 TypeGroup, |
| 70 TypeSeparator | 67 TypeSeparator |
| 71 }; | 68 }; |
| 72 | 69 |
| 73 PopupItem(const String& label, Type type) | 70 PopupItem(const String& label, Type type) |
| 74 : label(label) | 71 : label(label) |
| 75 , type(type) | 72 , type(type) |
| 76 , yOffset(0) | 73 , yOffset(0) |
| 77 { | 74 { |
| 78 } | 75 } |
| 79 String label; | 76 String label; |
| 80 Type type; | 77 Type type; |
| 81 int yOffset; // y offset of this item, relative to the top of the popup. | 78 int yOffset; // y offset of this item, relative to the top of the popup. |
| 82 blink::TextDirection textDirection; | 79 TextDirection textDirection; |
| 83 bool hasTextDirectionOverride; | 80 bool hasTextDirectionOverride; |
| 84 bool enabled; | 81 bool enabled; |
| 85 bool displayNone; | 82 bool displayNone; |
| 86 }; | 83 }; |
| 87 | 84 |
| 88 // This class uses WebCore code to paint and handle events for a drop-down list | 85 // This class uses WebCore code to paint and handle events for a drop-down list |
| 89 // box ("combobox" on Windows). | 86 // box ("combobox" on Windows). |
| 90 class PopupListBox FINAL : public blink::FramelessScrollView, public PopupConten
t { | 87 class PopupListBox FINAL : public FramelessScrollView, public PopupContent { |
| 91 public: | 88 public: |
| 92 static PassRefPtr<PopupListBox> create(blink::PopupMenuClient* client, bool
deviceSupportsTouch) | 89 static PassRefPtr<PopupListBox> create(PopupMenuClient* client, bool deviceS
upportsTouch) |
| 93 { | 90 { |
| 94 return adoptRef(new PopupListBox(client, deviceSupportsTouch)); | 91 return adoptRef(new PopupListBox(client, deviceSupportsTouch)); |
| 95 } | 92 } |
| 96 | 93 |
| 97 // FramelessScrollView | 94 // FramelessScrollView |
| 98 virtual void paint(blink::GraphicsContext*, const blink::IntRect&) OVERRIDE; | 95 virtual void paint(GraphicsContext*, const IntRect&) OVERRIDE; |
| 99 virtual bool handleMouseDownEvent(const blink::PlatformMouseEvent&) OVERRIDE
; | 96 virtual bool handleMouseDownEvent(const PlatformMouseEvent&) OVERRIDE; |
| 100 virtual bool handleMouseMoveEvent(const blink::PlatformMouseEvent&) OVERRIDE
; | 97 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&) OVERRIDE; |
| 101 virtual bool handleMouseReleaseEvent(const blink::PlatformMouseEvent&) OVERR
IDE; | 98 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) OVERRIDE; |
| 102 virtual bool handleWheelEvent(const blink::PlatformWheelEvent&) OVERRIDE; | 99 virtual bool handleWheelEvent(const PlatformWheelEvent&) OVERRIDE; |
| 103 virtual bool handleKeyEvent(const blink::PlatformKeyboardEvent&) OVERRIDE; | 100 virtual bool handleKeyEvent(const PlatformKeyboardEvent&) OVERRIDE; |
| 104 virtual bool handleTouchEvent(const blink::PlatformTouchEvent&) OVERRIDE; | 101 virtual bool handleTouchEvent(const PlatformTouchEvent&) OVERRIDE; |
| 105 virtual bool handleGestureEvent(const blink::PlatformGestureEvent&) OVERRIDE
; | 102 virtual bool handleGestureEvent(const PlatformGestureEvent&) OVERRIDE; |
| 106 | 103 |
| 107 // ScrollView | 104 // ScrollView |
| 108 virtual blink::HostWindow* hostWindow() const OVERRIDE; | 105 virtual HostWindow* hostWindow() const OVERRIDE; |
| 109 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE; | 106 virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE; |
| 110 | 107 |
| 111 // PopupListBox methods | 108 // PopupListBox methods |
| 112 | 109 |
| 113 // Closes the popup | 110 // Closes the popup |
| 114 void abandon(); | 111 void abandon(); |
| 115 | 112 |
| 116 // Updates our internal list to match the client. | 113 // Updates our internal list to match the client. |
| 117 void updateFromElement(); | 114 void updateFromElement(); |
| 118 | 115 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 const Vector<PopupItem*>& items() const { return m_items; } | 156 const Vector<PopupItem*>& items() const { return m_items; } |
| 160 | 157 |
| 161 virtual int popupContentHeight() const OVERRIDE; | 158 virtual int popupContentHeight() const OVERRIDE; |
| 162 | 159 |
| 163 static const int defaultMaxHeight; | 160 static const int defaultMaxHeight; |
| 164 | 161 |
| 165 private: | 162 private: |
| 166 friend class PopupContainer; | 163 friend class PopupContainer; |
| 167 friend class RefCounted<PopupListBox>; | 164 friend class RefCounted<PopupListBox>; |
| 168 | 165 |
| 169 PopupListBox(blink::PopupMenuClient*, bool deviceSupportsTouch); | 166 PopupListBox(PopupMenuClient*, bool deviceSupportsTouch); |
| 170 | 167 |
| 171 virtual ~PopupListBox() | 168 virtual ~PopupListBox() |
| 172 { | 169 { |
| 173 clear(); | 170 clear(); |
| 174 } | 171 } |
| 175 | 172 |
| 176 // Hides the popup. Other classes should not call this. Use abandon instead. | 173 // Hides the popup. Other classes should not call this. Use abandon instead. |
| 177 void hidePopup(); | 174 void hidePopup(); |
| 178 | 175 |
| 179 // Returns true if the selection can be changed to index. | 176 // Returns true if the selection can be changed to index. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 192 void clearSelection(); | 189 void clearSelection(); |
| 193 | 190 |
| 194 // Scrolls to reveal the given index. | 191 // Scrolls to reveal the given index. |
| 195 void scrollToRevealRow(int index); | 192 void scrollToRevealRow(int index); |
| 196 void scrollToRevealSelection() { scrollToRevealRow(m_selectedIndex); } | 193 void scrollToRevealSelection() { scrollToRevealRow(m_selectedIndex); } |
| 197 | 194 |
| 198 // Invalidates the row at the given index. | 195 // Invalidates the row at the given index. |
| 199 void invalidateRow(int index); | 196 void invalidateRow(int index); |
| 200 | 197 |
| 201 // Get the bounds of a row. | 198 // Get the bounds of a row. |
| 202 blink::IntRect getRowBounds(int index); | 199 IntRect getRowBounds(int index); |
| 203 | 200 |
| 204 // Converts a point to an index of the row the point is over | 201 // Converts a point to an index of the row the point is over |
| 205 int pointToRowIndex(const blink::IntPoint&); | 202 int pointToRowIndex(const IntPoint&); |
| 206 | 203 |
| 207 // Paint an individual row | 204 // Paint an individual row |
| 208 void paintRow(blink::GraphicsContext*, const blink::IntRect&, int rowIndex); | 205 void paintRow(GraphicsContext*, const IntRect&, int rowIndex); |
| 209 | 206 |
| 210 // Test if the given point is within the bounds of the popup window. | 207 // Test if the given point is within the bounds of the popup window. |
| 211 bool isPointInBounds(const blink::IntPoint&); | 208 bool isPointInBounds(const IntPoint&); |
| 212 | 209 |
| 213 // Called when the user presses a text key. Does a prefix-search of the item
s. | 210 // Called when the user presses a text key. Does a prefix-search of the item
s. |
| 214 void typeAheadFind(const blink::PlatformKeyboardEvent&); | 211 void typeAheadFind(const PlatformKeyboardEvent&); |
| 215 | 212 |
| 216 // Returns the font to use for the given row | 213 // Returns the font to use for the given row |
| 217 blink::Font getRowFont(int index); | 214 Font getRowFont(int index); |
| 218 | 215 |
| 219 // Moves the selection down/up one item, taking care of looping back to the | 216 // Moves the selection down/up one item, taking care of looping back to the |
| 220 // first/last element if m_loopSelectionNavigation is true. | 217 // first/last element if m_loopSelectionNavigation is true. |
| 221 void selectPreviousRow(); | 218 void selectPreviousRow(); |
| 222 void selectNextRow(); | 219 void selectNextRow(); |
| 223 | 220 |
| 224 // If the device is a touch screen we increase the height of menu items | 221 // If the device is a touch screen we increase the height of menu items |
| 225 // to make it easier to unambiguously touch them. | 222 // to make it easier to unambiguously touch them. |
| 226 bool m_deviceSupportsTouch; | 223 bool m_deviceSupportsTouch; |
| 227 | 224 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 248 // Our suggested width, not including scrollbar. | 245 // Our suggested width, not including scrollbar. |
| 249 int m_baseWidth; | 246 int m_baseWidth; |
| 250 | 247 |
| 251 // The maximum height we can be without being off-screen. | 248 // The maximum height we can be without being off-screen. |
| 252 int m_maxHeight; | 249 int m_maxHeight; |
| 253 | 250 |
| 254 // A list of the options contained within the <select> | 251 // A list of the options contained within the <select> |
| 255 Vector<PopupItem*> m_items; | 252 Vector<PopupItem*> m_items; |
| 256 | 253 |
| 257 // The <select> PopupMenuClient that opened us. | 254 // The <select> PopupMenuClient that opened us. |
| 258 blink::PopupMenuClient* m_popupClient; | 255 PopupMenuClient* m_popupClient; |
| 259 | 256 |
| 260 // The scrollbar which has mouse capture. Mouse events go straight to this | 257 // The scrollbar which has mouse capture. Mouse events go straight to this |
| 261 // if not null. | 258 // if not null. |
| 262 RefPtr<blink::Scrollbar> m_capturingScrollbar; | 259 RefPtr<Scrollbar> m_capturingScrollbar; |
| 263 | 260 |
| 264 // The last scrollbar that the mouse was over. Used for mouseover highlights
. | 261 // The last scrollbar that the mouse was over. Used for mouseover highlights
. |
| 265 RefPtr<blink::Scrollbar> m_lastScrollbarUnderMouse; | 262 RefPtr<Scrollbar> m_lastScrollbarUnderMouse; |
| 266 | 263 |
| 267 // The string the user has typed so far into the popup. Used for typeAheadFi
nd. | 264 // The string the user has typed so far into the popup. Used for typeAheadFi
nd. |
| 268 String m_typedString; | 265 String m_typedString; |
| 269 | 266 |
| 270 // The char the user has hit repeatedly. Used for typeAheadFind. | 267 // The char the user has hit repeatedly. Used for typeAheadFind. |
| 271 UChar m_repeatingChar; | 268 UChar m_repeatingChar; |
| 272 | 269 |
| 273 // The last time the user hit a key. Used for typeAheadFind. | 270 // The last time the user hit a key. Used for typeAheadFind. |
| 274 TimeStamp m_lastCharTime; | 271 TimeStamp m_lastCharTime; |
| 275 | 272 |
| 276 // If width exeeds screen width, we have to clip it. | 273 // If width exeeds screen width, we have to clip it. |
| 277 int m_maxWindowWidth; | 274 int m_maxWindowWidth; |
| 278 | 275 |
| 279 // To forward last mouse release event. | 276 // To forward last mouse release event. |
| 280 RefPtrWillBePersistent<blink::Element> m_focusedElement; | 277 RefPtrWillBePersistent<Element> m_focusedElement; |
| 281 }; | 278 }; |
| 282 | 279 |
| 283 } // namespace blink | 280 } // namespace blink |
| 284 | 281 |
| 285 #endif | 282 #endif |
| OLD | NEW |