Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLSelectElement.cpp

Issue 2108883003: Improve performance to remove an OPTION from a SELECT element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
4 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * (C) 1999 Antti Koivisto (koivisto@kde.org)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved.
7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
8 * Copyright (C) 2010 Google Inc. All rights reserved. 8 * Copyright (C) 2010 Google Inc. All rights reserved.
9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
10 * 10 *
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 // In conforming HTML code, only <optgroup> and <option> will be found 835 // In conforming HTML code, only <optgroup> and <option> will be found
836 // within a <select>. We call NodeTraversal::nextSkippingChildren so 836 // within a <select>. We call NodeTraversal::nextSkippingChildren so
837 // that we only step into those tags that we choose to. For web-compat, 837 // that we only step into those tags that we choose to. For web-compat,
838 // we should cope with the case where odd tags like a <div> have been 838 // we should cope with the case where odd tags like a <div> have been
839 // added but we handle this because such tags have already been removed 839 // added but we handle this because such tags have already been removed
840 // from the <select>'s subtree at this point. 840 // from the <select>'s subtree at this point.
841 currentElement = ElementTraversal::nextSkippingChildren(*currentElement, this); 841 currentElement = ElementTraversal::nextSkippingChildren(*currentElement, this);
842 } 842 }
843 } 843 }
844 844
845 void HTMLSelectElement::resetToDefaultSelection() 845 void HTMLSelectElement::resetToDefaultSelection(ResetReason reason)
846 { 846 {
847 // https://html.spec.whatwg.org/multipage/forms.html#ask-for-a-reset 847 // https://html.spec.whatwg.org/multipage/forms.html#ask-for-a-reset
848 if (multiple()) 848 if (multiple())
849 return; 849 return;
850 HTMLOptionElement* firstEnabledOption = nullptr; 850 HTMLOptionElement* firstEnabledOption = nullptr;
851 int firstEnabledOptionIndex = -1; 851 int firstEnabledOptionIndex = -1;
852 HTMLOptionElement* lastSelectedOption = nullptr; 852 HTMLOptionElement* lastSelectedOption = nullptr;
853 bool didChange = false; 853 bool didChange = false;
854 int optionIndex = 0; 854 int optionIndex = 0;
855 // We can't use HTMLSelectElement::options here because this function is 855 // We can't use HTMLSelectElement::options here because this function is
856 // called in Node::insertedInto and Node::removedFrom before invalidating 856 // called in Node::insertedInto and Node::removedFrom before invalidating
857 // node collections. 857 // node collections.
858 for (auto& item : listItems()) { 858 for (auto& item : listItems()) {
859 if (!isHTMLOptionElement(item)) 859 if (!isHTMLOptionElement(item))
860 continue; 860 continue;
861 HTMLOptionElement* option = toHTMLOptionElement(item); 861 HTMLOptionElement* option = toHTMLOptionElement(item);
862 if (option->selected()) { 862 if (option->selected()) {
863 if (lastSelectedOption) { 863 if (lastSelectedOption) {
864 lastSelectedOption->setSelectedState(false); 864 lastSelectedOption->setSelectedState(false);
865 didChange = true; 865 didChange = true;
866 } 866 }
867 lastSelectedOption = option; 867 lastSelectedOption = option;
868 } 868 }
869 if (!firstEnabledOption && !option->isDisabledFormControl()) { 869 if (!firstEnabledOption && !option->isDisabledFormControl()) {
870 firstEnabledOption = option; 870 firstEnabledOption = option;
871 firstEnabledOptionIndex = optionIndex; 871 firstEnabledOptionIndex = optionIndex;
872 if (reason == ResetReasonSelectedOptionRemoved) {
873 // There must be no selected OPTIONs.
874 break;
875 }
872 } 876 }
873 ++optionIndex; 877 ++optionIndex;
874 } 878 }
875 if (!lastSelectedOption && m_size <= 1 && firstEnabledOption && !firstEnable dOption->selected()) { 879 if (!lastSelectedOption && m_size <= 1 && firstEnabledOption && !firstEnable dOption->selected()) {
876 selectOption(firstEnabledOption, firstEnabledOptionIndex, 0); 880 selectOption(firstEnabledOption, firstEnabledOptionIndex, 0);
877 lastSelectedOption = firstEnabledOption; 881 lastSelectedOption = firstEnabledOption;
878 didChange = true; 882 didChange = true;
879 } 883 }
880 if (didChange) 884 if (didChange)
881 setNeedsValidityCheck(); 885 setNeedsValidityCheck();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 } else { 983 } else {
980 // No need to reset if we already have a selected option. 984 // No need to reset if we already have a selected option.
981 if (!m_lastOnChangeOption) 985 if (!m_lastOnChangeOption)
982 resetToDefaultSelection(); 986 resetToDefaultSelection();
983 } 987 }
984 } 988 }
985 989
986 void HTMLSelectElement::optionRemoved(const HTMLOptionElement& option) 990 void HTMLSelectElement::optionRemoved(const HTMLOptionElement& option)
987 { 991 {
988 setRecalcListItems(); 992 setRecalcListItems();
989 if (option.selected() || !m_lastOnChangeOption) 993 if (option.selected())
994 resetToDefaultSelection(ResetReasonSelectedOptionRemoved);
995 else if (!m_lastOnChangeOption)
990 resetToDefaultSelection(); 996 resetToDefaultSelection();
991 if (m_lastOnChangeOption == &option) 997 if (m_lastOnChangeOption == &option)
992 m_lastOnChangeOption.clear(); 998 m_lastOnChangeOption.clear();
993 if (m_optionToScrollTo == &option) 999 if (m_optionToScrollTo == &option)
994 m_optionToScrollTo.clear(); 1000 m_optionToScrollTo.clear();
995 if (m_activeSelectionAnchor == &option) 1001 if (m_activeSelectionAnchor == &option)
996 m_activeSelectionAnchor.clear(); 1002 m_activeSelectionAnchor.clear();
997 if (m_activeSelectionEnd == &option) 1003 if (m_activeSelectionEnd == &option)
998 m_activeSelectionEnd.clear(); 1004 m_activeSelectionEnd.clear();
999 if (option.selected()) 1005 if (option.selected())
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 } 2078 }
2073 2079
2074 void HTMLSelectElement::didMutateSubtree() 2080 void HTMLSelectElement::didMutateSubtree()
2075 { 2081 {
2076 DCHECK(popupIsVisible()); 2082 DCHECK(popupIsVisible());
2077 DCHECK(m_popup); 2083 DCHECK(m_popup);
2078 m_popup->updateFromElement(PopupMenu::ByDOMChange); 2084 m_popup->updateFromElement(PopupMenu::ByDOMChange);
2079 } 2085 }
2080 2086
2081 } // namespace blink 2087 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698