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

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

Issue 2103663006: Update a comment and fix a possible crash in HTMLSelectElement::setRecalcListItems. (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 | « no previous file | third_party/WebKit/Source/core/html/HTMLSelectElementTest.cpp » ('j') | 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 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 shouldRecalc = false; 792 shouldRecalc = false;
793 } else if (lastChild() == &subject) { 793 } else if (lastChild() == &subject) {
794 // The subject was appended. This doesn't handle elements in an 794 // The subject was appended. This doesn't handle elements in an
795 // OPTGROUP. 795 // OPTGROUP.
796 DCHECK(m_listItems.size() == 0 || m_listItems.last() != &subject); 796 DCHECK(m_listItems.size() == 0 || m_listItems.last() != &subject);
797 m_listItems.append(&subject); 797 m_listItems.append(&subject);
798 shouldRecalc = false; 798 shouldRecalc = false;
799 } else if (!subject.isDescendantOf(this)) { 799 } else if (!subject.isDescendantOf(this)) {
800 // |subject| was removed from this. This logic works well with 800 // |subject| was removed from this. This logic works well with
801 // SELECT children and OPTGROUP children. 801 // SELECT children and OPTGROUP children.
802 // TODO(tkent): m_listItems.size() is 0 in OOBE-related tests. It 802
803 // should not happen. 803 // m_listItems might be empty, or might not have the OPTION.
804 // 1. Remove an OPTGROUP with OPTION children from a SELECT.
805 // 2. This function is called for the OPTGROUP removal.
806 // 3. m_shouldRecalcListItems becomes true.
807 // 4. recalcListItems() happens. m_listItems has no OPTGROUP and
808 // no its children. m_shouldRecalcListItems becomes false.
809 // 5. This function is called for the removal of an OPTION child
810 // of the OPTGROUP.
804 if (m_listItems.size() > 0) { 811 if (m_listItems.size() > 0) {
805 size_t index; 812 size_t index;
806 // Avoid Vector::find() in typical cases. 813 // Avoid Vector::find() in typical cases.
807 if (m_listItems.first() == &subject) { 814 if (m_listItems.first() == &subject)
808 index = 0; 815 index = 0;
809 } else if (m_listItems.last() == &subject) { 816 else if (m_listItems.last() == &subject)
810 index = m_listItems.size() - 1; 817 index = m_listItems.size() - 1;
811 } else { 818 else
812 index = m_listItems.find(&subject); 819 index = m_listItems.find(&subject);
813 DCHECK_NE(index, WTF::kNotFound); 820 if (index != WTF::kNotFound) {
821 m_listItems.remove(index);
822 shouldRecalc = false;
814 } 823 }
815 m_listItems.remove(index);
816 shouldRecalc = false;
817 } 824 }
818 } 825 }
819 } 826 }
820 m_shouldRecalcListItems = shouldRecalc; 827 m_shouldRecalcListItems = shouldRecalc;
821 828
822 setOptionsChangedOnLayoutObject(); 829 setOptionsChangedOnLayoutObject();
823 if (!inShadowIncludingDocument()) { 830 if (!inShadowIncludingDocument()) {
824 if (HTMLOptionsCollection* collection = cachedCollection<HTMLOptionsColl ection>(SelectOptions)) 831 if (HTMLOptionsCollection* collection = cachedCollection<HTMLOptionsColl ection>(SelectOptions))
825 collection->invalidateCache(); 832 collection->invalidateCache();
826 invalidateSelectedItems(); 833 invalidateSelectedItems();
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 } 2136 }
2130 2137
2131 void HTMLSelectElement::didMutateSubtree() 2138 void HTMLSelectElement::didMutateSubtree()
2132 { 2139 {
2133 DCHECK(popupIsVisible()); 2140 DCHECK(popupIsVisible());
2134 DCHECK(m_popup); 2141 DCHECK(m_popup);
2135 m_popup->updateFromElement(PopupMenu::ByDOMChange); 2142 m_popup->updateFromElement(PopupMenu::ByDOMChange);
2136 } 2143 }
2137 2144
2138 } // namespace blink 2145 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/html/HTMLSelectElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698