Changeset 97135 in webkit
- Timestamp:
- Oct 11, 2011 1:45:38 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r97133 r97135 1 2011-10-11 Kent Tamura <tkent@chromium.org> 2 3 Move m_listItems and m_recalcListItems from SelectElementData to HTMLSelectElement 4 https://bugs.webkit.org/show_bug.cgi?id=69812 5 6 Reviewed by Ryosuke Niwa. 7 8 Move SelectElementData::m_recalcListItems, 9 SelectElementData::m_listItems, and related functions of 10 SelectElementData class to HTMLSelectElement. 11 12 Non-const listItems() was removed because it is used only in 13 recalcListItemsInternal() and it can access m_listItems diretly. 14 15 Static recalcListItems() is changed to non-static, and renamed to 16 recalcListItemsInternal() in order to avoid confusion with the 17 existing recalcListItems(). 18 19 No new tests, just a refactoring. 20 21 * dom/SelectElement.cpp: 22 Move checkListItems() and listItems() to HTMLSelectElement. 23 (WebCore::SelectElementData::SelectElementData): 24 Remove Initialization of m_recalcListItems. 25 * dom/SelectElement.h: 26 Move m_recalcListItems, m_listItems, and related functions to HTMLSelectElement. 27 * html/HTMLSelectElement.cpp: 28 (WebCore::HTMLSelectElement::HTMLSelectElement): 29 Initializes m_recalcListItems. 30 (WebCore::HTMLSelectElement::recalcListItems): 31 Rename the static recalcListItems() to recalcListItemsInternal(). 32 (WebCore::HTMLSelectElement::recalcListItemsIfNeeded): 33 Use m_recalcListItems directly. 34 (WebCore::HTMLSelectElement::nextSelectableListIndex): 35 Update a listItems() callsite. 36 (WebCore::HTMLSelectElement::previousSelectableListIndex): ditto. 37 (WebCore::HTMLSelectElement::firstSelectableListIndex): ditto. 38 (WebCore::HTMLSelectElement::lastSelectableListIndex): ditto. 39 (WebCore::HTMLSelectElement::nextSelectableListIndexPageAway): ditto. 40 (WebCore::HTMLSelectElement::saveLastSelection): ditto. 41 (WebCore::HTMLSelectElement::setActiveSelectionAnchorIndex): ditto. 42 (WebCore::HTMLSelectElement::updateListBoxSelection): ditto. 43 (WebCore::HTMLSelectElement::listBoxOnChange): ditto. 44 (WebCore::HTMLSelectElement::checkListItems): 45 Moved from SelectElementData. 46 (WebCore::HTMLSelectElement::listItems): ditto. 47 (WebCore::HTMLSelectElement::setRecalcListItems): 48 Use m_recalcListItems directly. 49 (WebCore::HTMLSelectElement::recalcListItemsInternal): 50 - Make this non-static. 51 - Renamed from recalcListItems() to avoid confilct with another recalcListItems(). 52 - Use m_recalcListItems and m_listItems directly. 53 (WebCore::HTMLSelectElement::selectedIndex): 54 Update a listItems() callsite. 55 (WebCore::HTMLSelectElement::setSelectedIndexInternal): ditto. 56 (WebCore::HTMLSelectElement::optionToListIndex): ditto. 57 (WebCore::HTMLSelectElement::listToOptionIndex): ditto. 58 (WebCore::HTMLSelectElement::deselectItemsWithoutValidation): ditto. 59 (WebCore::HTMLSelectElement::saveFormControlState): 60 Update callsites of listItems() and recalcListItems(). 61 (WebCore::HTMLSelectElement::restoreFormControlState): 62 Update a listItems() callsite. 63 (WebCore::HTMLSelectElement::appendFormData): ditto. 64 (WebCore::HTMLSelectElement::reset): ditto. 65 (WebCore::HTMLSelectElement::menuListDefaultEventHandler): ditto. 66 (WebCore::HTMLSelectElement::updateSelectedState): ditto. 67 (WebCore::HTMLSelectElement::listBoxDefaultEventHandler): ditto. 68 (WebCore::HTMLSelectElement::lastSelectedListIndex): ditto. 69 (WebCore::HTMLSelectElement::typeAheadFind): ditto. 70 (WebCore::HTMLSelectElement::insertedIntoTree): 71 Update a recalcListItems() callsite. 72 (WebCore::HTMLSelectElement::accessKeySetSelectedIndex): 73 Update a listItems() callsite. 74 (WebCore::HTMLSelectElement::length): ditto. 75 * html/HTMLSelectElement.h: 76 Move m_recalcListItems, m_listItems, and related functions from SelectElementData. 77 * html/HTMLSelectElementWin.cpp: 78 (WebCore::HTMLSelectElement::platformHandleKeydownEvent): 79 Update a listItems() callsite. 80 1 81 2011-10-11 Kenichi Ishibashi <bashi@chromium.org> 2 82 -
trunk/Source/WebCore/dom/SelectElement.cpp
r97123 r97135 64 64 , m_multiple(false) 65 65 , m_activeSelectionState(false) 66 , m_recalcListItems(false)67 66 { 68 67 } … … 72 71 } 73 72 74 void SelectElementData::checkListItems(const Element* element) const75 {76 #if !ASSERT_DISABLED77 Vector<Element*> items = m_listItems;78 HTMLSelectElement::recalcListItems(*const_cast<SelectElementData*>(this), element, false);79 ASSERT(items == m_listItems);80 #else81 UNUSED_PARAM(element);82 #endif83 73 } 84 85 Vector<Element*>& SelectElementData::listItems(const Element* element)86 {87 if (m_recalcListItems)88 HTMLSelectElement::recalcListItems(*this, element);89 else90 checkListItems(element);91 92 return m_listItems;93 }94 95 const Vector<Element*>& SelectElementData::listItems(const Element* element) const96 {97 if (m_recalcListItems)98 HTMLSelectElement::recalcListItems(*const_cast<SelectElementData*>(this), element);99 else100 checkListItems(element);101 102 return m_listItems;103 }104 105 } -
trunk/Source/WebCore/dom/SelectElement.h
r97123 r97135 74 74 Vector<bool>& cachedStateForActiveSelection() { return m_cachedStateForActiveSelection; } 75 75 76 bool shouldRecalcListItems() const { return m_recalcListItems; }77 void setShouldRecalcListItems(bool value) { m_recalcListItems = value; }78 79 Vector<Element*>& rawListItems() { return m_listItems; }80 Vector<Element*>& listItems(const Element*);81 const Vector<Element*>& listItems(const Element*) const;82 83 76 UChar repeatingChar() const { return m_repeatingChar; } 84 77 void setRepeatingChar(const UChar& value) { m_repeatingChar = value; } … … 93 86 void checkListItems(const Element*) const; 94 87 95 Vector<Element*> m_listItems;96 88 Vector<bool> m_lastOnChangeSelection; 97 89 Vector<bool> m_cachedStateForActiveSelection; … … 110 102 bool m_multiple; 111 103 bool m_activeSelectionState; 112 bool m_recalcListItems;113 104 }; 114 105 -
trunk/Source/WebCore/html/HTMLSelectElement.cpp
r97123 r97135 77 77 HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) 78 78 : HTMLFormControlElementWithState(tagName, document, form) 79 , m_recalcListItems(false) 79 80 { 80 81 ASSERT(hasTagName(selectTag)); … … 315 316 void HTMLSelectElement::recalcListItems(bool updateSelectedStates) const 316 317 { 317 recalcListItems(const_cast<SelectElementData&>(m_data), this,updateSelectedStates);318 const_cast<HTMLSelectElement*>(this)->recalcListItemsInternal(updateSelectedStates); 318 319 } 319 320 320 321 void HTMLSelectElement::recalcListItemsIfNeeded() 321 322 { 322 if (m_ data.shouldRecalcListItems())323 if (m_recalcListItems) 323 324 recalcListItems(); 324 325 } … … 457 458 int HTMLSelectElement::nextSelectableListIndex(int startIndex) const 458 459 { 459 return nextValidIndex( m_data.listItems(this), startIndex, SkipForwards, 1);460 return nextValidIndex(listItems(), startIndex, SkipForwards, 1); 460 461 } 461 462 … … 463 464 { 464 465 if (startIndex == -1) 465 startIndex = m_data.listItems(this).size();466 return nextValidIndex( m_data.listItems(this), startIndex, SkipBackwards, 1);466 startIndex = listItems().size(); 467 return nextValidIndex(listItems(), startIndex, SkipBackwards, 1); 467 468 } 468 469 469 470 int HTMLSelectElement::firstSelectableListIndex() const 470 471 { 471 const Vector<Element*>& items = m_data.listItems(this);472 const Vector<Element*>& items = listItems(); 472 473 int index = nextValidIndex(items, items.size(), SkipBackwards, INT_MAX); 473 474 if (static_cast<unsigned>(index) == items.size()) … … 478 479 int HTMLSelectElement::lastSelectableListIndex() const 479 480 { 480 return nextValidIndex( m_data.listItems(this), -1, SkipForwards, INT_MAX);481 return nextValidIndex(listItems(), -1, SkipForwards, INT_MAX); 481 482 } 482 483 … … 484 485 int HTMLSelectElement::nextSelectableListIndexPageAway(int startIndex, SkipDirection direction) const 485 486 { 486 const Vector<Element*>& items = m_data.listItems(this);487 const Vector<Element*>& items = listItems(); 487 488 // Can't use data->size() because renderer forces a minimum size. 488 489 int pageSize = 0; … … 527 528 lastOnChangeSelection.clear(); 528 529 529 const Vector<Element*>& items = m_data.listItems(this);530 const Vector<Element*>& items = listItems(); 530 531 for (unsigned i = 0; i < items.size(); ++i) { 531 532 OptionElement* optionElement = toOptionElement(items[i]); … … 543 544 cachedStateForActiveSelection.clear(); 544 545 545 const Vector<Element*>& items = m_data.listItems(this);546 const Vector<Element*>& items = listItems(); 546 547 for (unsigned i = 0; i < items.size(); ++i) { 547 548 OptionElement* optionElement = toOptionElement(items[i]); … … 558 559 { 559 560 ASSERT(renderer() && (renderer()->isListBox() || m_data.multiple())); 560 ASSERT(! m_data.listItems(this).size() || m_data.activeSelectionAnchorIndex() >= 0);561 ASSERT(!listItems().size() || m_data.activeSelectionAnchorIndex() >= 0); 561 562 562 563 unsigned start = min(m_data.activeSelectionAnchorIndex(), m_data.activeSelectionEndIndex()); … … 564 565 Vector<bool>& cachedStateForActiveSelection = m_data.cachedStateForActiveSelection(); 565 566 566 const Vector<Element*>& items = m_data.listItems(this);567 const Vector<Element*>& items = listItems(); 567 568 for (unsigned i = 0; i < items.size(); ++i) { 568 569 OptionElement* optionElement = toOptionElement(items[i]); … … 587 588 588 589 Vector<bool>& lastOnChangeSelection = m_data.lastOnChangeSelection(); 589 const Vector<Element*>& items = m_data.listItems(this);590 const Vector<Element*>& items = listItems(); 590 591 591 592 // If the cached selection list is empty, or the size has changed, then fire … … 641 642 } 642 643 644 void HTMLSelectElement::checkListItems() const 645 { 646 #if !ASSERT_DISABLED 647 Vector<Element*> items = m_listItems; 648 const_cast<HTMLSelectElement*>(this)->recalcListItemsInternal(false); 649 ASSERT(items == m_listItems); 650 #endif 651 } 652 653 const Vector<Element*>& HTMLSelectElement::listItems() const 654 { 655 if (m_recalcListItems) 656 const_cast<HTMLSelectElement*>(this)->recalcListItemsInternal(); 657 else 658 checkListItems(); 659 660 return m_listItems; 661 } 662 643 663 void HTMLSelectElement::setRecalcListItems() 644 664 { 645 m_ data.setShouldRecalcListItems(true);665 m_recalcListItems = true; 646 666 // Manual selection anchor is reset when manipulating the select programmatically. 647 667 m_data.setActiveSelectionAnchorIndex(-1); … … 652 672 } 653 673 654 void HTMLSelectElement::recalcListItems(SelectElementData& data, const Element* element, bool updateSelectedStates) 655 { 656 Vector<Element*>& listItems = data.rawListItems(); 657 listItems.clear(); 658 659 data.setShouldRecalcListItems(false); 674 void HTMLSelectElement::recalcListItemsInternal(bool updateSelectedStates) 675 { 676 m_listItems.clear(); 677 678 m_recalcListItems = false; 660 679 661 680 OptionElement* foundSelected = 0; 662 for (Node* currentNode = element->firstChild(); currentNode;) {681 for (Node* currentNode = this->firstChild(); currentNode;) { 663 682 if (!currentNode->isElementNode()) { 664 currentNode = currentNode->traverseNextSibling( element);683 currentNode = currentNode->traverseNextSibling(this); 665 684 continue; 666 685 } … … 672 691 // (http://www.w3.org/TR/html401/interact/forms.html#h-17.6) 673 692 if (isOptionGroupElement(current)) { 674 listItems.append(current);693 m_listItems.append(current); 675 694 if (current->firstChild()) { 676 695 currentNode = current->firstChild(); … … 680 699 681 700 if (OptionElement* optionElement = toOptionElement(current)) { 682 listItems.append(current);683 684 if (updateSelectedStates && ! data.multiple()) {685 if (!foundSelected && ( data.size() <= 1 || optionElement->selected())) {701 m_listItems.append(current); 702 703 if (updateSelectedStates && !m_data.multiple()) { 704 if (!foundSelected && (m_data.size() <= 1 || optionElement->selected())) { 686 705 foundSelected = optionElement; 687 706 foundSelected->setSelectedState(true); … … 694 713 695 714 if (current->hasTagName(HTMLNames::hrTag)) 696 listItems.append(current);715 m_listItems.append(current); 697 716 698 717 // In conforming HTML code, only <optgroup> and <option> will be found … … 702 721 // handle this because such tags have already been removed from the 703 722 // <select>'s subtree at this point. 704 currentNode = currentNode->traverseNextSibling( element);723 currentNode = currentNode->traverseNextSibling(this); 705 724 } 706 725 } … … 711 730 712 731 // return the number of the first option selected 713 const Vector<Element*>& items = m_data.listItems(this);732 const Vector<Element*>& items = listItems(); 714 733 for (size_t i = 0; i < items.size(); ++i) { 715 734 if (OptionElement* optionElement = toOptionElement(items[i])) { … … 730 749 deselect = true; 731 750 732 const Vector<Element*>& items = m_data.listItems(this);751 const Vector<Element*>& items = listItems(); 733 752 int listIndex = optionToListIndex(optionIndex); 734 753 … … 773 792 int HTMLSelectElement::optionToListIndex(int optionIndex) const 774 793 { 775 const Vector<Element*>& items = m_data.listItems(this);794 const Vector<Element*>& items = listItems(); 776 795 int listSize = static_cast<int>(items.size()); 777 796 if (optionIndex < 0 || optionIndex >= listSize) … … 792 811 int HTMLSelectElement::listToOptionIndex(int listIndex) const 793 812 { 794 const Vector<Element*>& items = m_data.listItems(this);813 const Vector<Element*>& items = listItems(); 795 814 if (listIndex < 0 || listIndex >= static_cast<int>(items.size()) || !isOptionElement(items[listIndex])) 796 815 return -1; … … 827 846 void HTMLSelectElement::deselectItemsWithoutValidation(Element* excludeElement) 828 847 { 829 const Vector<Element*>& items = m_data.listItems(this);848 const Vector<Element*>& items = listItems(); 830 849 for (unsigned i = 0; i < items.size(); ++i) { 831 850 if (items[i] == excludeElement) … … 839 858 bool HTMLSelectElement::saveFormControlState(String& value) const 840 859 { 841 const Vector<Element*>& items = m_data.listItems(this);860 const Vector<Element*>& items = listItems(); 842 861 int length = items.size(); 843 862 … … 856 875 void HTMLSelectElement::restoreFormControlState(const String& state) 857 876 { 858 recalcListItems( m_data, this);859 860 const Vector<Element*>& items = m_data.listItems(this);877 recalcListItems(); 878 879 const Vector<Element*>& items = listItems(); 861 880 int length = items.size(); 862 881 … … 886 905 887 906 bool successful = false; 888 const Vector<Element*>& items = m_data.listItems(this);907 const Vector<Element*>& items = listItems(); 889 908 890 909 for (unsigned i = 0; i < items.size(); ++i) { … … 907 926 OptionElement* selectedOption = 0; 908 927 909 const Vector<Element*>& items = m_data.listItems(this);928 const Vector<Element*>& items = listItems(); 910 929 for (unsigned i = 0; i < items.size(); ++i) { 911 930 OptionElement* optionElement = toOptionElement(items[i]); … … 981 1000 const String& keyIdentifier = static_cast<KeyboardEvent*>(event)->keyIdentifier(); 982 1001 bool handled = true; 983 const Vector<Element*>& listItems = m_data.listItems(this);1002 const Vector<Element*>& listItems = this->listItems(); 984 1003 int listIndex = optionToListIndex(selectedIndex()); 985 1004 … … 1109 1128 bool multiSelect = m_data.multiple() && multi && !shift; 1110 1129 1111 Element* clickedElement = m_data.listItems(this)[listIndex];1130 Element* clickedElement = listItems()[listIndex]; 1112 1131 OptionElement* option = toOptionElement(clickedElement); 1113 1132 if (option) { … … 1149 1168 void HTMLSelectElement::listBoxDefaultEventHandler(Event* event) 1150 1169 { 1151 const Vector<Element*>& listItems = m_data.listItems(this);1170 const Vector<Element*>& listItems = this->listItems(); 1152 1171 1153 1172 if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { … … 1307 1326 unsigned index = 0; 1308 1327 bool found = false; 1309 const Vector<Element*>& items = m_data.listItems(this);1328 const Vector<Element*>& items = listItems(); 1310 1329 for (size_t i = 0; i < items.size(); ++i) { 1311 1330 if (OptionElement* optionElement = toOptionElement(items[i])) { … … 1363 1382 } 1364 1383 1365 const Vector<Element*>& items = m_data.listItems(this);1384 const Vector<Element*>& items = listItems(); 1366 1385 int itemCount = items.size(); 1367 1386 if (itemCount < 1) … … 1401 1420 // items yet - but for innerHTML and related methods, this method is called 1402 1421 // after the whole subtree is constructed. 1403 recalcListItems( m_data, this,true);1422 recalcListItems(true); 1404 1423 HTMLFormControlElementWithState::insertedIntoTree(deep); 1405 1424 } … … 1412 1431 1413 1432 // if this index is already selected, unselect. otherwise update the selected index 1414 const Vector<Element*>& items = m_data.listItems(this);1433 const Vector<Element*>& items = listItems(); 1415 1434 int listIndex = optionToListIndex(index); 1416 1435 if (OptionElement* optionElement = (listIndex >= 0 ? toOptionElement(items[listIndex]) : 0)) { … … 1433 1452 unsigned options = 0; 1434 1453 1435 const Vector<Element*>& items = m_data.listItems(this);1454 const Vector<Element*>& items = listItems(); 1436 1455 for (unsigned i = 0; i < items.size(); ++i) { 1437 1456 if (isOptionElement(items[i])) -
trunk/Source/WebCore/html/HTMLSelectElement.h
r97123 r97135 31 31 #include "HTMLFormControlElement.h" 32 32 #include "SelectElement.h" 33 #include <wtf/Vector.h> 33 34 34 35 namespace WebCore { … … 67 68 void recalcListItemsIfNeeded(); 68 69 69 const Vector<Element*>& listItems() const { return m_data.listItems(this); }70 const Vector<Element*>& listItems() const; 70 71 71 72 virtual void accessKeyAction(bool sendToAnyElement); … … 144 145 bool hasPlaceholderLabelOption() const; 145 146 146 static void recalcListItems(SelectElementData&, const Element*, bool updateSelectedStates = true); 147 void checkListItems() const; 148 void recalcListItemsInternal(bool updateSelectedStates = true); 147 149 void setSelectedIndexInternal(int optionIndex, bool deselect = true, bool fireOnChangeNow = false, bool userDrivenChange = true); 148 150 void deselectItemsWithoutValidation(Element* excludeElement = 0); … … 154 156 void listBoxDefaultEventHandler(Event*); 155 157 void setOptionsChangedOnRenderer(); 156 friend class SelectElementData;157 158 158 159 enum SkipDirection { … … 169 170 SelectElementData m_data; 170 171 CollectionCache m_collectionInfo; 172 Vector<Element*> m_listItems; 173 bool m_recalcListItems; 171 174 }; 172 175 -
trunk/Source/WebCore/html/HTMLSelectElementWin.cpp
r97123 r97135 49 49 int index = selectedIndex(); 50 50 ASSERT(index >= 0); 51 ASSERT(index < m_data.listItems(this).size());51 ASSERT(index < listItems().size()); 52 52 setSelectedIndexInternal(index); 53 53 event->setDefaultHandled();
Note: See TracChangeset
for help on using the changeset viewer.