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

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

Issue 761463002: Fix listbox selections with only disabled options. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated patch Created 6 years 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 | « LayoutTests/fast/html/crash-on-invalid-selection-index-expected.txt ('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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 { 653 {
654 if (index == m_activeSelectionEndIndex) 654 if (index == m_activeSelectionEndIndex)
655 return; 655 return;
656 m_activeSelectionEndIndex = index; 656 m_activeSelectionEndIndex = index;
657 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( StyleChangeReason::Control)); 657 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( StyleChangeReason::Control));
658 } 658 }
659 659
660 void HTMLSelectElement::updateListBoxSelection(bool deselectOtherOptions, bool s croll) 660 void HTMLSelectElement::updateListBoxSelection(bool deselectOtherOptions, bool s croll)
661 { 661 {
662 ASSERT(renderer() && (renderer()->isListBox() || m_multiple)); 662 ASSERT(renderer() && (renderer()->isListBox() || m_multiple));
663 ASSERT(!listItems().size() || m_activeSelectionAnchorIndex >= 0);
664 663
665 unsigned start = std::min(m_activeSelectionAnchorIndex, m_activeSelectionEnd Index); 664 int start = std::min(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex );
666 unsigned end = std::max(m_activeSelectionAnchorIndex, m_activeSelectionEndIn dex); 665 int end = std::max(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex);
667 666
668 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = listItems() ; 667 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = listItems() ;
669 for (unsigned i = 0; i < items.size(); ++i) { 668 for (int i = 0; i < static_cast<int>(items.size()); ++i) {
670 HTMLElement* element = items[i]; 669 HTMLElement* element = items[i];
671 if (!isHTMLOptionElement(*element) || toHTMLOptionElement(element)->isDi sabledFormControl() || !toHTMLOptionElement(element)->renderer()) 670 if (!isHTMLOptionElement(*element) || toHTMLOptionElement(element)->isDi sabledFormControl() || !toHTMLOptionElement(element)->renderer())
672 continue; 671 continue;
673 672
674 if (i >= start && i <= end) 673 if (i >= start && i <= end)
675 toHTMLOptionElement(element)->setSelectedState(m_activeSelectionStat e); 674 toHTMLOptionElement(element)->setSelectedState(m_activeSelectionStat e);
676 else if (deselectOtherOptions || i >= m_cachedStateForActiveSelection.si ze()) 675 else if (deselectOtherOptions || i >= static_cast<int>(m_cachedStateForA ctiveSelection.size()))
677 toHTMLOptionElement(element)->setSelectedState(false); 676 toHTMLOptionElement(element)->setSelectedState(false);
678 else 677 else
679 toHTMLOptionElement(element)->setSelectedState(m_cachedStateForActiv eSelection[i]); 678 toHTMLOptionElement(element)->setSelectedState(m_cachedStateForActiv eSelection[i]);
680 } 679 }
681 680
682 setNeedsValidityCheck(); 681 setNeedsValidityCheck();
683 if (scroll) 682 if (scroll)
684 scrollToSelection(); 683 scrollToSelection();
685 notifyFormStateChanged(); 684 notifyFormStateChanged();
686 } 685 }
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1774 int focusedIndex = activeSelectionEndListIndex(); 1773 int focusedIndex = activeSelectionEndListIndex();
1775 if (focusedIndex < 0) 1774 if (focusedIndex < 0)
1776 focusedIndex = firstSelectableListIndex(); 1775 focusedIndex = firstSelectableListIndex();
1777 if (focusedIndex < 0) 1776 if (focusedIndex < 0)
1778 return nullptr; 1777 return nullptr;
1779 HTMLElement* focused = listItems()[focusedIndex]; 1778 HTMLElement* focused = listItems()[focusedIndex];
1780 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr ; 1779 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr ;
1781 } 1780 }
1782 1781
1783 } // namespace 1782 } // namespace
OLDNEW
« no previous file with comments | « LayoutTests/fast/html/crash-on-invalid-selection-index-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698