Changeset 97069 in webkit
- Timestamp:
- Oct 10, 2011 11:01:09 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r97067 r97069 1 2011-10-10 Kent Tamura <tkent@chromium.org> 2 3 Make static functions in HTMLSelectElement.cpp member functions of HTMLSelectElement class 4 https://bugs.webkit.org/show_bug.cgi?id=69755 5 6 Reviewed by Ryosuke Niwa. 7 8 9 No new tests, just a refactoring. 10 11 * html/HTMLSelectElement.cpp: 12 (WebCore::HTMLSelectElement::nextValidIndex): 13 Make this a static member function of HTMLSelectElement. 14 (WebCore::HTMLSelectElement::nextSelectableListIndex): 15 Make this a member function of HTMLSelectElement. 16 (WebCore::HTMLSelectElement::previousSelectableListIndex): ditto. 17 (WebCore::HTMLSelectElement::firstSelectableListIndex): ditto. 18 (WebCore::HTMLSelectElement::lastSelectableListIndex): ditto. 19 (WebCore::HTMLSelectElement::nextSelectableListIndexPageAway): ditto. 20 (WebCore::HTMLSelectElement::selectAll): Update callsite of the above functions. 21 (WebCore::HTMLSelectElement::setSelectedIndexInternal): ditto. 22 (WebCore::HTMLSelectElement::listBoxDefaultEventHandler): ditto. 23 * html/HTMLSelectElement.h: 24 - Add the above function declarations. 25 - Move SkipDirection definition from HTMLSelectElement.cpp. 26 1 27 2011-10-10 Pavel Feldman <pfeldman@google.com> 2 28 -
trunk/Source/WebCore/html/HTMLSelectElement.cpp
r97038 r97069 75 75 static const DOMTimeStamp typeAheadTimeout = 1000; 76 76 77 enum SkipDirection {78 SkipBackwards = -1,79 SkipForwards = 180 };81 82 77 HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) 83 78 : HTMLFormControlElementWithState(tagName, document, form) … … 444 439 // Otherwise, it returns |listIndex|. 445 440 // Valid means that it is enabled and an option element. 446 static intnextValidIndex(const Vector<Element*>& listItems, int listIndex, SkipDirection direction, int skip)441 int HTMLSelectElement::nextValidIndex(const Vector<Element*>& listItems, int listIndex, SkipDirection direction, int skip) 447 442 { 448 443 ASSERT(direction == -1 || direction == 1); … … 460 455 } 461 456 462 static int nextSelectableListIndex(SelectElementData& data, Element* element, int startIndex) 463 { 464 return nextValidIndex( data.listItems(element), startIndex, SkipForwards, 1);465 } 466 467 static int previousSelectableListIndex(SelectElementData& data, Element* element, int startIndex) 457 int HTMLSelectElement::nextSelectableListIndex(int startIndex) const 458 { 459 return nextValidIndex(m_data.listItems(this), startIndex, SkipForwards, 1); 460 } 461 462 int HTMLSelectElement::previousSelectableListIndex(int startIndex) const 468 463 { 469 464 if (startIndex == -1) 470 startIndex = data.listItems(element).size();471 return nextValidIndex( data.listItems(element), startIndex, SkipBackwards, 1);472 } 473 474 static int firstSelectableListIndex(SelectElementData& data, Element* element) 475 { 476 const Vector<Element*>& items = data.listItems(element);465 startIndex = m_data.listItems(this).size(); 466 return nextValidIndex(m_data.listItems(this), startIndex, SkipBackwards, 1); 467 } 468 469 int HTMLSelectElement::firstSelectableListIndex() const 470 { 471 const Vector<Element*>& items = m_data.listItems(this); 477 472 int index = nextValidIndex(items, items.size(), SkipBackwards, INT_MAX); 478 473 if (static_cast<unsigned>(index) == items.size()) … … 481 476 } 482 477 483 static int lastSelectableListIndex(SelectElementData& data, Element* element) 484 { 485 return nextValidIndex( data.listItems(element), -1, SkipForwards, INT_MAX);478 int HTMLSelectElement::lastSelectableListIndex() const 479 { 480 return nextValidIndex(m_data.listItems(this), -1, SkipForwards, INT_MAX); 486 481 } 487 482 488 483 // Returns the index of the next valid item one page away from |startIndex| in direction |direction|. 489 static int nextSelectableListIndexPageAway(SelectElementData& data, Element* element, int startIndex, SkipDirection direction) 490 { 491 const Vector<Element*>& items = data.listItems(element);484 int HTMLSelectElement::nextSelectableListIndexPageAway(int startIndex, SkipDirection direction) const 485 { 486 const Vector<Element*>& items = m_data.listItems(this); 492 487 // Can't use data->size() because renderer forces a minimum size. 493 488 int pageSize = 0; 494 if ( element->renderer()->isListBox())495 pageSize = toRenderListBox( element->renderer())->size() - 1; // -1 so we still show context489 if (renderer()->isListBox()) 490 pageSize = toRenderListBox(renderer())->size() - 1; // -1 so we still show context 496 491 497 492 // One page away, but not outside valid bounds. … … 514 509 515 510 m_data.setActiveSelectionState(true); 516 setActiveSelectionAnchorIndex(nextSelectableListIndex( m_data, this,-1));517 setActiveSelectionEndIndex(previousSelectableListIndex( m_data, this,-1));511 setActiveSelectionAnchorIndex(nextSelectableListIndex(-1)); 512 setActiveSelectionEndIndex(previousSelectableListIndex(-1)); 518 513 519 514 updateListBoxSelection(false); … … 731 726 { 732 727 if (optionIndex == -1 && !deselect && !m_data.multiple()) 733 optionIndex = nextSelectableListIndex( m_data, this,-1);728 optionIndex = nextSelectableListIndex(-1); 734 729 if (!m_data.multiple()) 735 730 deselect = true; … … 1195 1190 handled = true; 1196 1191 if (keyIdentifier == "Down") 1197 endIndex = nextSelectableListIndex( m_data, this,startIndex);1192 endIndex = nextSelectableListIndex(startIndex); 1198 1193 else 1199 endIndex = nextSelectableListIndexPageAway( m_data, this,startIndex, SkipForwards);1194 endIndex = nextSelectableListIndexPageAway(startIndex, SkipForwards); 1200 1195 } else if (keyIdentifier == "Up" || keyIdentifier == "PageUp") { 1201 1196 int startIndex = optionToListIndex(selectedIndex()); 1202 1197 handled = true; 1203 1198 if (keyIdentifier == "Up") 1204 endIndex = previousSelectableListIndex( m_data, this,startIndex);1199 endIndex = previousSelectableListIndex(startIndex); 1205 1200 else 1206 endIndex = nextSelectableListIndexPageAway( m_data, this,startIndex, SkipBackwards);1201 endIndex = nextSelectableListIndexPageAway(startIndex, SkipBackwards); 1207 1202 } 1208 1203 } else { 1209 1204 // Set the end index based on the current end index 1210 1205 if (keyIdentifier == "Down") { 1211 endIndex = nextSelectableListIndex(m_data , this, m_data.activeSelectionEndIndex());1206 endIndex = nextSelectableListIndex(m_data.activeSelectionEndIndex()); 1212 1207 handled = true; 1213 1208 } else if (keyIdentifier == "Up") { 1214 endIndex = previousSelectableListIndex(m_data , this, m_data.activeSelectionEndIndex());1209 endIndex = previousSelectableListIndex(m_data.activeSelectionEndIndex()); 1215 1210 handled = true; 1216 1211 } else if (keyIdentifier == "PageDown") { 1217 endIndex = nextSelectableListIndexPageAway(m_data , this, m_data.activeSelectionEndIndex(), SkipForwards);1212 endIndex = nextSelectableListIndexPageAway(m_data.activeSelectionEndIndex(), SkipForwards); 1218 1213 handled = true; 1219 1214 } else if (keyIdentifier == "PageUp") { 1220 endIndex = nextSelectableListIndexPageAway(m_data , this, m_data.activeSelectionEndIndex(), SkipBackwards);1215 endIndex = nextSelectableListIndexPageAway(m_data.activeSelectionEndIndex(), SkipBackwards); 1221 1216 handled = true; 1222 1217 } 1223 1218 } 1224 1219 if (keyIdentifier == "Home") { 1225 endIndex = firstSelectableListIndex( m_data, this);1220 endIndex = firstSelectableListIndex(); 1226 1221 handled = true; 1227 1222 } else if (keyIdentifier == "End") { 1228 endIndex = lastSelectableListIndex( m_data, this);1223 endIndex = lastSelectableListIndex(); 1229 1224 handled = true; 1230 1225 } -
trunk/Source/WebCore/html/HTMLSelectElement.h
r97038 r97069 156 156 friend class SelectElementData; 157 157 158 enum SkipDirection { 159 SkipBackwards = -1, 160 SkipForwards = 1 161 }; 162 static int nextValidIndex(const Vector<Element*>& listItems, int listIndex, SkipDirection, int skip); 163 int nextSelectableListIndex(int startIndex) const; 164 int previousSelectableListIndex(int startIndex) const; 165 int firstSelectableListIndex() const; 166 int lastSelectableListIndex() const; 167 int nextSelectableListIndexPageAway(int startIndex, SkipDirection) const; 168 158 169 SelectElementData m_data; 159 170 CollectionCache m_collectionInfo;
Note: See TracChangeset
for help on using the changeset viewer.