| OLD | NEW | 
|---|
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. | 
| 2 // All rights reserved. | 2 // 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 123     { | 123     { | 
| 124         m_baseWidth = width; | 124         m_baseWidth = width; | 
| 125     } | 125     } | 
| 126 | 126 | 
| 127     // Compute size of widget and children. | 127     // Compute size of widget and children. | 
| 128     void layout(); | 128     void layout(); | 
| 129 | 129 | 
| 130     // Returns whether the popup wants to process events for the passed key. | 130     // Returns whether the popup wants to process events for the passed key. | 
| 131     bool isInterestedInEventForKey(int key_code); | 131     bool isInterestedInEventForKey(int key_code); | 
| 132 | 132 | 
|  | 133     // Sets whether the PopupMenuClient should be told to change its text when a | 
|  | 134     // new item is selected (by using the arrow keys).  Default is true. | 
|  | 135     void setTextOnIndexChange(bool value) { m_setTextOnIndexChange = value; } | 
|  | 136 | 
| 133 private: | 137 private: | 
| 134     friend class PopupContainer; | 138     friend class PopupContainer; | 
| 135     friend class RefCounted<PopupListBox>; | 139     friend class RefCounted<PopupListBox>; | 
| 136 | 140 | 
| 137     // A type of List Item | 141     // A type of List Item | 
| 138     enum ListItemType { | 142     enum ListItemType { | 
| 139         TYPE_OPTION, | 143         TYPE_OPTION, | 
| 140         TYPE_GROUP, | 144         TYPE_GROUP, | 
| 141         TYPE_SEPARATOR | 145         TYPE_SEPARATOR | 
| 142     }; | 146     }; | 
| 143 | 147 | 
| 144     // A item (represented by <option> or <optgroup>) in the <select> widget. | 148     // A item (represented by <option> or <optgroup>) in the <select> widget. | 
| 145     struct ListItem { | 149     struct ListItem { | 
| 146         ListItem(const String& label, ListItemType type) | 150         ListItem(const String& label, ListItemType type) | 
| 147             : label(label.copy()), type(type), y(0) {} | 151             : label(label.copy()), type(type), y(0) {} | 
| 148         String label; | 152         String label; | 
| 149         ListItemType type; | 153         ListItemType type; | 
| 150         int y;  // y offset of this item, relative to the top of the popup. | 154         int y;  // y offset of this item, relative to the top of the popup. | 
| 151     }; | 155     }; | 
| 152 | 156 | 
| 153     PopupListBox(PopupMenuClient* client) | 157     PopupListBox(PopupMenuClient* client) | 
| 154         : m_originalIndex(0) | 158         : m_originalIndex(0) | 
| 155         , m_selectedIndex(0) | 159         , m_selectedIndex(0) | 
| 156         , m_acceptOnAbandon(false) | 160         , m_acceptOnAbandon(false) | 
| 157         , m_visibleRows(0) | 161         , m_visibleRows(0) | 
| 158         , m_popupClient(client) | 162         , m_popupClient(client) | 
| 159         , m_repeatingChar(0) | 163         , m_repeatingChar(0) | 
| 160         , m_lastCharTime(0) | 164         , m_lastCharTime(0) | 
|  | 165         , m_setTextOnIndexChange(true) | 
| 161     { | 166     { | 
| 162         setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff); | 167         setScrollbarModes(ScrollbarAlwaysOff, ScrollbarAlwaysOff); | 
| 163     } | 168     } | 
| 164 | 169 | 
| 165     ~PopupListBox() | 170     ~PopupListBox() | 
| 166     { | 171     { | 
| 167         clear(); | 172         clear(); | 
| 168     } | 173     } | 
| 169 | 174 | 
| 170     void disconnectClient() { m_popupClient = 0; } | 175     void disconnectClient() { m_popupClient = 0; } | 
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 244     RefPtr<Scrollbar> m_lastScrollbarUnderMouse; | 249     RefPtr<Scrollbar> m_lastScrollbarUnderMouse; | 
| 245 | 250 | 
| 246     // The string the user has typed so far into the popup. Used for typeAheadFi
      nd. | 251     // The string the user has typed so far into the popup. Used for typeAheadFi
      nd. | 
| 247     String m_typedString; | 252     String m_typedString; | 
| 248 | 253 | 
| 249     // The char the user has hit repeatedly.  Used for typeAheadFind. | 254     // The char the user has hit repeatedly.  Used for typeAheadFind. | 
| 250     UChar m_repeatingChar; | 255     UChar m_repeatingChar; | 
| 251 | 256 | 
| 252     // The last time the user hit a key.  Used for typeAheadFind. | 257     // The last time the user hit a key.  Used for typeAheadFind. | 
| 253     TimeStamp m_lastCharTime; | 258     TimeStamp m_lastCharTime; | 
|  | 259 | 
|  | 260     bool m_setTextOnIndexChange; | 
| 254 }; | 261 }; | 
| 255 | 262 | 
| 256 static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent& 
      e, | 263 static PlatformMouseEvent constructRelativeMouseEvent(const PlatformMouseEvent& 
      e, | 
| 257                                                       FramelessScrollView* paren
      t, | 264                                                       FramelessScrollView* paren
      t, | 
| 258                                                       FramelessScrollView* child
      ) | 265                                                       FramelessScrollView* child
      ) | 
| 259 { | 266 { | 
| 260     IntPoint pos = parent->convertSelfToChild(child, e.pos()); | 267     IntPoint pos = parent->convertSelfToChild(child, e.pos()); | 
| 261 | 268 | 
| 262     // FIXME(beng): This is a horrible hack since PlatformMouseEvent has no sett
      ers for x/y. | 269     // FIXME(beng): This is a horrible hack since PlatformMouseEvent has no sett
      ers for x/y. | 
| 263     //              Need to add setters and get patch back upstream to webkit so
      urce. | 270     //              Need to add setters and get patch back upstream to webkit so
      urce. | 
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 457     IntPoint location = v->contentsToWindow(r.location()); | 464     IntPoint location = v->contentsToWindow(r.location()); | 
| 458 | 465 | 
| 459     // Move it below the select widget. | 466     // Move it below the select widget. | 
| 460     location.move(0, r.height()); | 467     location.move(0, r.height()); | 
| 461 | 468 | 
| 462     IntRect popupRect(location, r.size()); | 469     IntRect popupRect(location, r.size()); | 
| 463     setFrameRect(popupRect); | 470     setFrameRect(popupRect); | 
| 464     showPopup(v); | 471     showPopup(v); | 
| 465 } | 472 } | 
| 466 | 473 | 
|  | 474 void PopupContainer::setTextOnIndexChange(bool value) { | 
|  | 475   listBox()->setTextOnIndexChange(value); | 
|  | 476 } | 
|  | 477 | 
| 467 /////////////////////////////////////////////////////////////////////////////// | 478 /////////////////////////////////////////////////////////////////////////////// | 
| 468 // PopupListBox implementation | 479 // PopupListBox implementation | 
| 469 | 480 | 
| 470 bool PopupListBox::handleMouseDownEvent(const PlatformMouseEvent& event) | 481 bool PopupListBox::handleMouseDownEvent(const PlatformMouseEvent& event) | 
| 471 { | 482 { | 
| 472     Scrollbar* scrollbar = scrollbarUnderMouse(event); | 483     Scrollbar* scrollbar = scrollbarUnderMouse(event); | 
| 473     if (scrollbar) { | 484     if (scrollbar) { | 
| 474         m_capturingScrollbar = scrollbar; | 485         m_capturingScrollbar = scrollbar; | 
| 475         m_capturingScrollbar->mouseDown(event); | 486         m_capturingScrollbar->mouseDown(event); | 
| 476         return true; | 487         return true; | 
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 595         break; | 606         break; | 
| 596     } | 607     } | 
| 597 | 608 | 
| 598     if (m_originalIndex != m_selectedIndex) { | 609     if (m_originalIndex != m_selectedIndex) { | 
| 599         // Keyboard events should update the selection immediately (but we don't | 610         // Keyboard events should update the selection immediately (but we don't | 
| 600         // want to fire the onchange event until the popup is closed, to match | 611         // want to fire the onchange event until the popup is closed, to match | 
| 601         // IE).  We change the original index so we revert to that when the | 612         // IE).  We change the original index so we revert to that when the | 
| 602         // popup is closed. | 613         // popup is closed. | 
| 603         m_acceptOnAbandon = true; | 614         m_acceptOnAbandon = true; | 
| 604         setOriginalIndex(m_selectedIndex); | 615         setOriginalIndex(m_selectedIndex); | 
| 605         m_popupClient->setTextFromItem(m_selectedIndex); | 616         if (m_setTextOnIndexChange) | 
|  | 617           m_popupClient->setTextFromItem(m_selectedIndex); | 
| 606     } | 618     } | 
| 607 | 619 | 
| 608     return true; | 620     return true; | 
| 609 } | 621 } | 
| 610 | 622 | 
| 611 HostWindow* PopupListBox::hostWindow() const | 623 HostWindow* PopupListBox::hostWindow() const | 
| 612 { | 624 { | 
| 613     // Our parent is the root ScrollView, so it is the one that has a | 625     // Our parent is the root ScrollView, so it is the one that has a | 
| 614     // HostWindow.  FrameView::hostWindow() works similarly. | 626     // HostWindow.  FrameView::hostWindow() works similarly. | 
| 615     return parent() ? parent()->hostWindow() : 0; | 627     return parent() ? parent()->hostWindow() : 0; | 
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1058 { | 1070 { | 
| 1059     p.m_popup->listBox()->updateFromElement(); | 1071     p.m_popup->listBox()->updateFromElement(); | 
| 1060 } | 1072 } | 
| 1061 | 1073 | 
| 1062 bool PopupMenu::itemWritingDirectionIsNatural() | 1074 bool PopupMenu::itemWritingDirectionIsNatural() | 
| 1063 { | 1075 { | 
| 1064     return false; | 1076     return false; | 
| 1065 } | 1077 } | 
| 1066 | 1078 | 
| 1067 } // namespace WebCore | 1079 } // namespace WebCore | 
| OLD | NEW | 
|---|