Changeset 40494 in webkit
- Timestamp:
- Feb 2, 2009 3:07:53 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r40493 r40494 1 2009-02-02 Jay Campan <jcampan@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Clean up PopupMenuChromium a little. 6 https://bugs.webkit.org/show_bug.cgi?id=23653 7 8 No functional changes, only code cleanup, thus no tests. 9 10 * platform/chromium/PopupMenuChromium.cpp: 11 (WebCore::): 12 (WebCore::PopupListBox::PopupListBox): 13 (WebCore::PopupContainer::create): 14 (WebCore::PopupContainer::PopupContainer): 15 (WebCore::PopupContainer::showPopup): 16 (WebCore::PopupListBox::handleKeyEvent): 17 (WebCore::PopupListBox::isSelectableItem): 18 (WebCore::PopupListBox::selectNextRow): 19 (WebCore::PopupListBox::selectPreviousRow): 20 (WebCore::PopupMenu::show): 21 * platform/chromium/PopupMenuChromium.h: 22 1 23 2009-02-02 Anders Carlsson <andersca@apple.com> 2 24 -
trunk/WebCore/platform/chromium/PopupMenuChromium.cpp
r40269 r40494 70 70 static const TimeStamp kTypeAheadTimeoutMs = 1000; 71 71 72 // The settings used for the drop down menu. 73 // This is the delegate used if none is provided. 74 static const PopupContainerSettings dropDownSettings = { 75 true, // focusOnShow 76 true, // setTextOnIndexChange 77 true, // acceptOnAbandon 78 false // loopSelectionNavigation 79 }; 80 72 81 // This class uses WebCore code to paint and handle events for a drop-down list 73 82 // box ("combobox" on Windows). … … 126 135 bool isInterestedInEventForKey(int keyCode); 127 136 128 // Sets whether the PopupMenuClient should be told to change its text when a129 // new item is selected (by using the arrow keys). Default is true.130 void setTextOnIndexChange(bool value) { m_setTextOnIndexChange = value; }131 132 // Sets whether we should accept the selected index when the popup is133 // abandonned.134 void setAcceptOnAbandon(bool value) { m_shouldAcceptOnAbandon = value; }135 136 // Sets whether pressing the down/up arrow when the last/first row is137 // selected clears the selection on the first key press and then selects the138 // first/last row on the next key press. If false, the selected row stays139 // the last/first row.140 void setLoopSelectionNavigation(bool value) { m_loopSelectionNavigation = value; }141 142 137 private: 143 138 friend class PopupContainer; … … 160 155 }; 161 156 162 PopupListBox(PopupMenuClient* client) 163 : m_originalIndex(0) 157 PopupListBox(PopupMenuClient* client, const PopupContainerSettings& settings) 158 : m_settings(settings) 159 , m_originalIndex(0) 164 160 , m_selectedIndex(0) 165 , m_shouldAcceptOnAbandon(true)166 161 , m_willAcceptOnAbandon(false) 167 162 , m_visibleRows(0) … … 169 164 , m_repeatingChar(0) 170 165 , m_lastCharTime(0) 171 , m_setTextOnIndexChange(true)172 , m_loopSelectionNavigation(false)173 166 { 174 167 setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff); … … 229 222 void selectNextRow(); 230 223 224 // The settings that specify the behavior for this Popup window. 225 PopupContainerSettings m_settings; 226 231 227 // This is the index of the item marked as "selected" - i.e. displayed in the widget on the 232 228 // page. … … 238 234 int m_selectedIndex; 239 235 240 // Whether we should accept the selectedIndex as chosen when the popup is241 // "abandoned". This value is set through its setter and is useful as242 // select popup menu and form autofill popup menu have different behaviors.243 bool m_shouldAcceptOnAbandon;244 245 236 // True if we should accept the selectedIndex as chosen, even if the popup 246 237 // is "abandoned". This is used for keyboard navigation, where we want the 247 // selection to change immediately, and is only used if 248 // m_shouldAcceptOnAbandonis true.238 // selection to change immediately, and is only used if the settings 239 // acceptOnAbandon field is true. 249 240 bool m_willAcceptOnAbandon; 250 241 … … 278 269 // The last time the user hit a key. Used for typeAheadFind. 279 270 TimeStamp m_lastCharTime; 280 281 bool m_setTextOnIndexChange;282 283 bool m_loopSelectionNavigation;284 271 }; 285 272 … … 317 304 // static 318 305 PassRefPtr<PopupContainer> PopupContainer::create(PopupMenuClient* client, 319 bool focusOnShow)320 { 321 return adoptRef(new PopupContainer(client, focusOnShow));322 } 323 324 PopupContainer::PopupContainer(PopupMenuClient* client, bool focusOnShow)325 : m_listBox(new PopupListBox(client )),326 m_focusOnShow(focusOnShow)306 const PopupContainerSettings& settings) 307 { 308 return adoptRef(new PopupContainer(client, settings)); 309 } 310 311 PopupContainer::PopupContainer(PopupMenuClient* client, const PopupContainerSettings& settings) 312 : m_listBox(new PopupListBox(client, settings)) 313 , m_settings(settings) 327 314 { 328 315 // FrameViews are created with a refcount of 1 so it needs releasing after we … … 358 345 widgetRect.move(0, -(widgetRect.height() + selectHeight)); 359 346 360 chromeClient->popupOpened(this, widgetRect, m_ focusOnShow);347 chromeClient->popupOpened(this, widgetRect, m_settings.focusOnShow); 361 348 } 362 349 … … 494 481 setFrameRect(popupRect); 495 482 showPopup(v); 496 }497 498 void PopupContainer::setTextOnIndexChange(bool value)499 {500 listBox()->setTextOnIndexChange(value);501 }502 503 void PopupContainer::setAcceptOnAbandon(bool value)504 {505 listBox()->setAcceptOnAbandon(value);506 }507 508 void PopupContainer::setLoopSelectionNavigation(bool value)509 {510 listBox()->setLoopSelectionNavigation(value);511 483 } 512 484 … … 659 631 // IE). We change the original index so we revert to that when the 660 632 // popup is closed. 661 if (m_s houldAcceptOnAbandon)633 if (m_settings.acceptOnAbandon) 662 634 m_willAcceptOnAbandon = true; 663 635 664 636 setOriginalIndex(m_selectedIndex); 665 if (m_set TextOnIndexChange)637 if (m_settings.setTextOnIndexChange) 666 638 m_popupClient->setTextFromItem(m_selectedIndex); 667 } else if (!m_setTextOnIndexChange && event.windowsVirtualKeyCode() == VKEY_TAB) { 639 } else if (!m_settings.setTextOnIndexChange && 640 event.windowsVirtualKeyCode() == VKEY_TAB) { 668 641 // TAB is a special case as it should select the current item if any and 669 642 // advance focus. … … 960 933 } 961 934 962 bool PopupListBox::isSelectableItem(int index) { 935 bool PopupListBox::isSelectableItem(int index) 936 { 963 937 return m_items[index]->type == TypeOption && m_popupClient->itemIsEnabled(index); 964 938 } … … 974 948 void PopupListBox::selectNextRow() 975 949 { 976 if (!m_ loopSelectionNavigation || m_selectedIndex != numItems() - 1) {950 if (!m_settings.loopSelectionNavigation || m_selectedIndex != numItems() - 1) { 977 951 adjustSelectedIndex(1); 978 952 return; … … 985 959 void PopupListBox::selectPreviousRow() 986 960 { 987 if (!m_ loopSelectionNavigation || m_selectedIndex > 0) {961 if (!m_settings.loopSelectionNavigation || m_selectedIndex > 0) { 988 962 adjustSelectedIndex(-1); 989 963 return; … … 1157 1131 void PopupMenu::show(const IntRect& r, FrameView* v, int index) 1158 1132 { 1159 p.popup = PopupContainer::create(client(), true);1133 p.popup = PopupContainer::create(client(), dropDownSettings); 1160 1134 p.popup->show(r, v, index); 1161 1135 } -
trunk/WebCore/platform/chromium/PopupMenuChromium.h
r40269 r40494 45 45 // FIXME: Our FramelessScrollView classes should probably implement HostWindow! 46 46 47 // Th isclass holds a PopupListBox (see cpp file). Its sole purpose is to be47 // The PopupContainer class holds a PopupListBox (see cpp file). Its sole purpose is to be 48 48 // able to draw a border around its child. All its paint/event handling is 49 49 // just forwarded to the child listBox (with the appropriate transforms). … … 53 53 // key events to it (through handleKeyEvent). 54 54 55 struct PopupContainerSettings { 56 // Whether the popup should get the focus when displayed. 57 bool focusOnShow; 58 59 // Whether the PopupMenuClient should be told to change its text when a 60 // new item is selected by using the arrow keys. 61 bool setTextOnIndexChange; 62 63 // Whether the selection should be accepted when the popup menu is 64 // closed (through ESC being pressed or the focus going away). 65 // Note that when TAB is pressed, the selection is always accepted 66 // regardless of this setting. 67 bool acceptOnAbandon; 68 69 // Whether the we should move the selection to the first/last item when 70 // the user presses down/up arrow keys and the last/first item is 71 // selected. 72 bool loopSelectionNavigation; 73 }; 74 55 75 class PopupContainer : public FramelessScrollView, public RefCounted<PopupContainer> { 56 76 public: 57 static PassRefPtr<PopupContainer> create(PopupMenuClient*, bool focusOnShow); 77 static PassRefPtr<PopupContainer> create(PopupMenuClient*, 78 const PopupContainerSettings&); 58 79 59 80 // Whether a key event should be sent to this popup. … … 85 106 void layout(); 86 107 87 // Sets whether the PopupMenuClient should be told to change its text when a88 // new item is selected (by using the arrow keys). Default is true.89 void setTextOnIndexChange(bool);90 91 // Sets whether the selection should be accepted when the popup menu is92 // closed (through ESC being pressed or the focus going away). Default93 // is true. Note that when TAB is pressed, the selection is always94 // accepted regardless of this setting.95 void setAcceptOnAbandon(bool);96 97 // Sets whether we should move the selection to the first/last item98 // when the user presses down/up arrow keys and the last/first item is99 // selected. Default is false, causing the first/last item to stay100 // selected.101 void setLoopSelectionNavigation(bool);102 103 108 PopupListBox* listBox() const { return m_listBox.get(); } 104 109 … … 109 114 friend class WTF::RefCounted<PopupContainer>; 110 115 111 PopupContainer(PopupMenuClient*, bool focusOnShow);116 PopupContainer(PopupMenuClient*, const PopupContainerSettings&); 112 117 ~PopupContainer(); 113 118 … … 117 122 RefPtr<PopupListBox> m_listBox; 118 123 119 // Whether the window showing this popup should be focused when shown. 120 bool m_focusOnShow; 124 PopupContainerSettings m_settings; 121 125 }; 122 126
Note: See TracChangeset
for help on using the changeset viewer.