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 2258033002: Replace ASSERT()s with DCHECK*() in core/html/*.{cpp,h}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace ASSERT()s with DCHECK*() in core/html/*.{cpp,h}. Created 4 years, 4 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
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 HTMLOptionElement* HTMLSelectElement::activeSelectionEnd() const 214 HTMLOptionElement* HTMLSelectElement::activeSelectionEnd() const
215 { 215 {
216 if (m_activeSelectionEnd) 216 if (m_activeSelectionEnd)
217 return m_activeSelectionEnd.get(); 217 return m_activeSelectionEnd.get();
218 return lastSelectedOption(); 218 return lastSelectedOption();
219 } 219 }
220 220
221 void HTMLSelectElement::add(const HTMLOptionElementOrHTMLOptGroupElement& elemen t, const HTMLElementOrLong& before, ExceptionState& exceptionState) 221 void HTMLSelectElement::add(const HTMLOptionElementOrHTMLOptGroupElement& elemen t, const HTMLElementOrLong& before, ExceptionState& exceptionState)
222 { 222 {
223 HTMLElement* elementToInsert; 223 HTMLElement* elementToInsert;
224 ASSERT(!element.isNull()); 224 DCHECK(!element.isNull());
225 if (element.isHTMLOptionElement()) 225 if (element.isHTMLOptionElement())
226 elementToInsert = element.getAsHTMLOptionElement(); 226 elementToInsert = element.getAsHTMLOptionElement();
227 else 227 else
228 elementToInsert = element.getAsHTMLOptGroupElement(); 228 elementToInsert = element.getAsHTMLOptGroupElement();
229 229
230 HTMLElement* beforeElement; 230 HTMLElement* beforeElement;
231 if (before.isHTMLElement()) 231 if (before.isHTMLElement())
232 beforeElement = before.getAsHTMLElement(); 232 beforeElement = before.getAsHTMLElement();
233 else if (before.isLong()) 233 else if (before.isLong())
234 beforeElement = options()->item(before.getAsLong()); 234 beforeElement = options()->item(before.getAsLong());
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 } 491 }
492 492
493 // Returns the 1st valid OPTION |skip| items from |listIndex| in direction 493 // Returns the 1st valid OPTION |skip| items from |listIndex| in direction
494 // |direction| if there is one. 494 // |direction| if there is one.
495 // Otherwise, it returns the valid OPTION closest to that boundary which is past 495 // Otherwise, it returns the valid OPTION closest to that boundary which is past
496 // |listIndex| if there is one. 496 // |listIndex| if there is one.
497 // Otherwise, it returns nullptr. 497 // Otherwise, it returns nullptr.
498 // Valid means that it is enabled and visible. 498 // Valid means that it is enabled and visible.
499 HTMLOptionElement* HTMLSelectElement::nextValidOption(int listIndex, SkipDirecti on direction, int skip) const 499 HTMLOptionElement* HTMLSelectElement::nextValidOption(int listIndex, SkipDirecti on direction, int skip) const
500 { 500 {
501 ASSERT(direction == SkipBackwards || direction == SkipForwards); 501 DCHECK(direction == SkipBackwards || direction == SkipForwards);
502 const ListItems& listItems = this->listItems(); 502 const ListItems& listItems = this->listItems();
503 HTMLOptionElement* lastGoodOption = nullptr; 503 HTMLOptionElement* lastGoodOption = nullptr;
504 int size = listItems.size(); 504 int size = listItems.size();
505 for (listIndex += direction; listIndex >= 0 && listIndex < size; listIndex + = direction) { 505 for (listIndex += direction; listIndex >= 0 && listIndex < size; listIndex + = direction) {
506 --skip; 506 --skip;
507 HTMLElement* element = listItems[listIndex]; 507 HTMLElement* element = listItems[listIndex];
508 if (!isHTMLOptionElement(*element)) 508 if (!isHTMLOptionElement(*element))
509 continue; 509 continue;
510 if (toHTMLOptionElement(*element).isDisplayNone()) 510 if (toHTMLOptionElement(*element).isDisplayNone())
511 continue; 511 continue;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // If there is no exact one page away valid option, returns startIndex or 559 // If there is no exact one page away valid option, returns startIndex or
560 // the most far index. 560 // the most far index.
561 int startIndex = startOption ? startOption->listIndex() : -1; 561 int startIndex = startOption ? startOption->listIndex() : -1;
562 int edgeIndex = (direction == SkipForwards) ? 0 : (items.size() - 1); 562 int edgeIndex = (direction == SkipForwards) ? 0 : (items.size() - 1);
563 int skipAmount = pageSize + ((direction == SkipForwards) ? startIndex : (edg eIndex - startIndex)); 563 int skipAmount = pageSize + ((direction == SkipForwards) ? startIndex : (edg eIndex - startIndex));
564 return nextValidOption(edgeIndex, direction, skipAmount); 564 return nextValidOption(edgeIndex, direction, skipAmount);
565 } 565 }
566 566
567 void HTMLSelectElement::selectAll() 567 void HTMLSelectElement::selectAll()
568 { 568 {
569 ASSERT(!usesMenuList()); 569 DCHECK(!usesMenuList());
570 if (!layoutObject() || !m_multiple) 570 if (!layoutObject() || !m_multiple)
571 return; 571 return;
572 572
573 // Save the selection so it can be compared to the new selectAll selection 573 // Save the selection so it can be compared to the new selectAll selection
574 // when dispatching change events. 574 // when dispatching change events.
575 saveLastSelection(); 575 saveLastSelection();
576 576
577 m_activeSelectionState = true; 577 m_activeSelectionState = true;
578 setActiveSelectionAnchor(nextSelectableOption(nullptr)); 578 setActiveSelectionAnchor(nextSelectableOption(nullptr));
579 setActiveSelectionEnd(previousSelectableOption(nullptr)); 579 setActiveSelectionEnd(previousSelectableOption(nullptr));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 620 }
621 } 621 }
622 622
623 void HTMLSelectElement::setActiveSelectionEnd(HTMLOptionElement* option) 623 void HTMLSelectElement::setActiveSelectionEnd(HTMLOptionElement* option)
624 { 624 {
625 m_activeSelectionEnd = option; 625 m_activeSelectionEnd = option;
626 } 626 }
627 627
628 void HTMLSelectElement::updateListBoxSelection(bool deselectOtherOptions, bool s croll) 628 void HTMLSelectElement::updateListBoxSelection(bool deselectOtherOptions, bool s croll)
629 { 629 {
630 ASSERT(layoutObject()); 630 DCHECK(layoutObject());
631 ASSERT(layoutObject()->isListBox() || m_multiple); 631 DCHECK(layoutObject()->isListBox() || m_multiple);
632 632
633 int activeSelectionAnchorIndex = m_activeSelectionAnchor ? m_activeSelection Anchor->index() : -1; 633 int activeSelectionAnchorIndex = m_activeSelectionAnchor ? m_activeSelection Anchor->index() : -1;
634 int activeSelectionEndIndex = m_activeSelectionEnd ? m_activeSelectionEnd->i ndex() : -1; 634 int activeSelectionEndIndex = m_activeSelectionEnd ? m_activeSelectionEnd->i ndex() : -1;
635 int start = std::min(activeSelectionAnchorIndex, activeSelectionEndIndex); 635 int start = std::min(activeSelectionAnchorIndex, activeSelectionEndIndex);
636 int end = std::max(activeSelectionAnchorIndex, activeSelectionEndIndex); 636 int end = std::max(activeSelectionAnchorIndex, activeSelectionEndIndex);
637 637
638 int i = 0; 638 int i = 0;
639 for (const auto& option : optionList()) { 639 for (const auto& option : optionList()) {
640 if (option->isDisabledFormControl() || !option->layoutObject()) { 640 if (option->isDisabledFormControl() || !option->layoutObject()) {
641 ++i; 641 ++i;
(...skipping 12 matching lines...) Expand all
654 } 654 }
655 655
656 setNeedsValidityCheck(); 656 setNeedsValidityCheck();
657 if (scroll) 657 if (scroll)
658 scrollToSelection(); 658 scrollToSelection();
659 notifyFormStateChanged(); 659 notifyFormStateChanged();
660 } 660 }
661 661
662 void HTMLSelectElement::listBoxOnChange() 662 void HTMLSelectElement::listBoxOnChange()
663 { 663 {
664 ASSERT(!usesMenuList() || m_multiple); 664 DCHECK(!usesMenuList() || m_multiple);
665 665
666 const ListItems& items = listItems(); 666 const ListItems& items = listItems();
667 667
668 // If the cached selection list is empty, or the size has changed, then fire 668 // If the cached selection list is empty, or the size has changed, then fire
669 // dispatchFormControlChangeEvent, and return early. 669 // dispatchFormControlChangeEvent, and return early.
670 // FIXME: Why? This looks unreasonable. 670 // FIXME: Why? This looks unreasonable.
671 if (m_lastOnChangeSelection.isEmpty() || m_lastOnChangeSelection.size() != i tems.size()) { 671 if (m_lastOnChangeSelection.isEmpty() || m_lastOnChangeSelection.size() != i tems.size()) {
672 dispatchFormControlChangeEvent(); 672 dispatchFormControlChangeEvent();
673 return; 673 return;
674 } 674 }
675 675
676 // Update m_lastOnChangeSelection and fire dispatchFormControlChangeEvent. 676 // Update m_lastOnChangeSelection and fire dispatchFormControlChangeEvent.
677 bool fireOnChange = false; 677 bool fireOnChange = false;
678 for (unsigned i = 0; i < items.size(); ++i) { 678 for (unsigned i = 0; i < items.size(); ++i) {
679 HTMLElement* element = items[i]; 679 HTMLElement* element = items[i];
680 bool selected = isHTMLOptionElement(*element) && toHTMLOptionElement(ele ment)->selected(); 680 bool selected = isHTMLOptionElement(*element) && toHTMLOptionElement(ele ment)->selected();
681 if (selected != m_lastOnChangeSelection[i]) 681 if (selected != m_lastOnChangeSelection[i])
682 fireOnChange = true; 682 fireOnChange = true;
683 m_lastOnChangeSelection[i] = selected; 683 m_lastOnChangeSelection[i] = selected;
684 } 684 }
685 685
686 if (fireOnChange) { 686 if (fireOnChange) {
687 dispatchInputEvent(); 687 dispatchInputEvent();
688 dispatchFormControlChangeEvent(); 688 dispatchFormControlChangeEvent();
689 } 689 }
690 } 690 }
691 691
692 void HTMLSelectElement::dispatchInputAndChangeEventForMenuList() 692 void HTMLSelectElement::dispatchInputAndChangeEventForMenuList()
693 { 693 {
694 ASSERT(usesMenuList()); 694 DCHECK(usesMenuList());
695 695
696 HTMLOptionElement* selectedOption = this->selectedOption(); 696 HTMLOptionElement* selectedOption = this->selectedOption();
697 if (m_lastOnChangeOption.get() != selectedOption) { 697 if (m_lastOnChangeOption.get() != selectedOption) {
698 m_lastOnChangeOption = selectedOption; 698 m_lastOnChangeOption = selectedOption;
699 dispatchInputEvent(); 699 dispatchInputEvent();
700 dispatchFormControlChangeEvent(); 700 dispatchFormControlChangeEvent();
701 } 701 }
702 } 702 }
703 703
704 void HTMLSelectElement::scrollToSelection() 704 void HTMLSelectElement::scrollToSelection()
(...skipping 16 matching lines...) Expand all
721 } 721 }
722 722
723 const HTMLSelectElement::ListItems& HTMLSelectElement::listItems() const 723 const HTMLSelectElement::ListItems& HTMLSelectElement::listItems() const
724 { 724 {
725 if (m_shouldRecalcListItems) { 725 if (m_shouldRecalcListItems) {
726 recalcListItems(); 726 recalcListItems();
727 } else { 727 } else {
728 #if ENABLE(ASSERT) 728 #if ENABLE(ASSERT)
729 HeapVector<Member<HTMLElement>> items = m_listItems; 729 HeapVector<Member<HTMLElement>> items = m_listItems;
730 recalcListItems(); 730 recalcListItems();
731 // TODO(tkent): Add a stream printer for HeapVector. DCHECK requires it.
731 ASSERT(items == m_listItems); 732 ASSERT(items == m_listItems);
732 #endif 733 #endif
733 } 734 }
734 735
735 return m_listItems; 736 return m_listItems;
736 } 737 }
737 738
738 void HTMLSelectElement::invalidateSelectedItems() 739 void HTMLSelectElement::invalidateSelectedItems()
739 { 740 {
740 if (HTMLCollection* collection = cachedCollection<HTMLCollection>(SelectedOp tions)) 741 if (HTMLCollection* collection = cachedCollection<HTMLCollection>(SelectedOp tions))
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 document().postTask(BLINK_FROM_HERE, createSameThreadTask(&HTMLSelectEle ment::scrollToOptionTask, wrapPersistent(this))); 914 document().postTask(BLINK_FROM_HERE, createSameThreadTask(&HTMLSelectEle ment::scrollToOptionTask, wrapPersistent(this)));
914 } 915 }
915 916
916 void HTMLSelectElement::scrollToOptionTask() 917 void HTMLSelectElement::scrollToOptionTask()
917 { 918 {
918 HTMLOptionElement* option = m_optionToScrollTo.release(); 919 HTMLOptionElement* option = m_optionToScrollTo.release();
919 if (!option || !isConnected()) 920 if (!option || !isConnected())
920 return; 921 return;
921 // optionRemoved() makes sure m_optionToScrollTo doesn't have an option with 922 // optionRemoved() makes sure m_optionToScrollTo doesn't have an option with
922 // another owner. 923 // another owner.
923 ASSERT(option->ownerSelectElement() == this); 924 DCHECK_EQ(option->ownerSelectElement(), this);
924 document().updateStyleAndLayoutIgnorePendingStylesheets(); 925 document().updateStyleAndLayoutIgnorePendingStylesheets();
925 if (!layoutObject() || !layoutObject()->isListBox()) 926 if (!layoutObject() || !layoutObject()->isListBox())
926 return; 927 return;
927 LayoutRect bounds = option->boundingBox(); 928 LayoutRect bounds = option->boundingBox();
928 toLayoutListBox(layoutObject())->scrollToRect(bounds); 929 toLayoutListBox(layoutObject())->scrollToRect(bounds);
929 } 930 }
930 931
931 void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, b ool optionIsSelected) 932 void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, b ool optionIsSelected)
932 { 933 {
933 ASSERT(option->ownerSelectElement() == this); 934 DCHECK_EQ(option->ownerSelectElement(), this);
934 if (optionIsSelected) 935 if (optionIsSelected)
935 selectOption(option, multiple() ? 0 : DeselectOtherOptions); 936 selectOption(option, multiple() ? 0 : DeselectOtherOptions);
936 else if (!usesMenuList() || multiple()) 937 else if (!usesMenuList() || multiple())
937 selectOption(nullptr, multiple() ? 0 : DeselectOtherOptions); 938 selectOption(nullptr, multiple() ? 0 : DeselectOtherOptions);
938 else 939 else
939 selectOption(nextSelectableOption(nullptr), DeselectOtherOptions); 940 selectOption(nextSelectableOption(nullptr), DeselectOtherOptions);
940 } 941 }
941 942
942 void HTMLSelectElement::optionInserted(HTMLOptionElement& option, bool optionIsS elected) 943 void HTMLSelectElement::optionInserted(HTMLOptionElement& option, bool optionIsS elected)
943 { 944 {
944 ASSERT(option.ownerSelectElement() == this); 945 DCHECK_EQ(option.ownerSelectElement(), this);
945 setRecalcListItems(); 946 setRecalcListItems();
946 if (optionIsSelected) { 947 if (optionIsSelected) {
947 selectOption(&option, multiple() ? 0 : DeselectOtherOptions); 948 selectOption(&option, multiple() ? 0 : DeselectOtherOptions);
948 } else { 949 } else {
949 // No need to reset if we already have a selected option. 950 // No need to reset if we already have a selected option.
950 if (!m_lastOnChangeOption) 951 if (!m_lastOnChangeOption)
951 resetToDefaultSelection(); 952 resetToDefaultSelection();
952 } 953 }
953 setNeedsValidityCheck(); 954 setNeedsValidityCheck();
954 m_lastOnChangeSelection.clear(); 955 m_lastOnChangeSelection.clear();
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 recalcListItems(); 1127 recalcListItems();
1127 1128
1128 const ListItems& items = listItems(); 1129 const ListItems& items = listItems();
1129 size_t itemsSize = items.size(); 1130 size_t itemsSize = items.size();
1130 if (itemsSize == 0) 1131 if (itemsSize == 0)
1131 return; 1132 return;
1132 1133
1133 selectOption(nullptr, DeselectOtherOptions); 1134 selectOption(nullptr, DeselectOtherOptions);
1134 1135
1135 // The saved state should have at least one value and an index. 1136 // The saved state should have at least one value and an index.
1136 ASSERT(state.valueSize() >= 2); 1137 DCHECK_GE(state.valueSize(), 2u);
1137 if (!multiple()) { 1138 if (!multiple()) {
1138 size_t index = state[1].toUInt(); 1139 size_t index = state[1].toUInt();
1139 if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTMLOpti onElement(items[index])->value() == state[0]) { 1140 if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTMLOpti onElement(items[index])->value() == state[0]) {
1140 toHTMLOptionElement(items[index])->setSelectedState(true); 1141 toHTMLOptionElement(items[index])->setSelectedState(true);
1141 toHTMLOptionElement(items[index])->setDirty(true); 1142 toHTMLOptionElement(items[index])->setDirty(true);
1142 m_lastOnChangeOption = toHTMLOptionElement(items[index]); 1143 m_lastOnChangeOption = toHTMLOptionElement(items[index]);
1143 } else { 1144 } else {
1144 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize); 1145 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize);
1145 if (foundIndex != kNotFound) { 1146 if (foundIndex != kNotFound) {
1146 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); 1147 toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 } 1358 }
1358 1359
1359 if (event->type() == EventTypeNames::blur) { 1360 if (event->type() == EventTypeNames::blur) {
1360 if (popupIsVisible()) 1361 if (popupIsVisible())
1361 hidePopup(); 1362 hidePopup();
1362 } 1363 }
1363 } 1364 }
1364 1365
1365 void HTMLSelectElement::updateSelectedState(HTMLOptionElement* clickedOption, bo ol multi, bool shift) 1366 void HTMLSelectElement::updateSelectedState(HTMLOptionElement* clickedOption, bo ol multi, bool shift)
1366 { 1367 {
1367 ASSERT(clickedOption); 1368 DCHECK(clickedOption);
1368 // Save the selection so it can be compared to the new selection when 1369 // Save the selection so it can be compared to the new selection when
1369 // dispatching change events during mouseup, or after autoscroll finishes. 1370 // dispatching change events during mouseup, or after autoscroll finishes.
1370 saveLastSelection(); 1371 saveLastSelection();
1371 1372
1372 m_activeSelectionState = true; 1373 m_activeSelectionState = true;
1373 1374
1374 bool shiftSelect = m_multiple && shift; 1375 bool shiftSelect = m_multiple && shift;
1375 bool multiSelect = m_multiple && multi && !shift; 1376 bool multiSelect = m_multiple && multi && !shift;
1376 1377
1377 // Keep track of whether an active selection (like during drag selection), 1378 // Keep track of whether an active selection (like during drag selection),
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 } 2024 }
2024 2025
2025 void HTMLSelectElement::didMutateSubtree() 2026 void HTMLSelectElement::didMutateSubtree()
2026 { 2027 {
2027 DCHECK(popupIsVisible()); 2028 DCHECK(popupIsVisible());
2028 DCHECK(m_popup); 2029 DCHECK(m_popup);
2029 m_popup->updateFromElement(PopupMenu::ByDOMChange); 2030 m_popup->updateFromElement(PopupMenu::ByDOMChange);
2030 } 2031 }
2031 2032
2032 } // namespace blink 2033 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698