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

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

Issue 189543012: Update <select> when any of its <option> children has "display: none" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addtional layout test included. Created 6 years, 9 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 , m_lastOnChangeIndex(-1) 69 , m_lastOnChangeIndex(-1)
70 , m_activeSelectionAnchorIndex(-1) 70 , m_activeSelectionAnchorIndex(-1)
71 , m_activeSelectionEndIndex(-1) 71 , m_activeSelectionEndIndex(-1)
72 , m_isProcessingUserDrivenChange(false) 72 , m_isProcessingUserDrivenChange(false)
73 , m_multiple(false) 73 , m_multiple(false)
74 , m_activeSelectionState(false) 74 , m_activeSelectionState(false)
75 , m_shouldRecalcListItems(false) 75 , m_shouldRecalcListItems(false)
76 , m_suggestedIndex(-1) 76 , m_suggestedIndex(-1)
77 { 77 {
78 ScriptWrappable::init(this); 78 ScriptWrappable::init(this);
79 setHasCustomStyleCallbacks();
79 } 80 }
80 81
81 PassRefPtr<HTMLSelectElement> HTMLSelectElement::create(Document& document) 82 PassRefPtr<HTMLSelectElement> HTMLSelectElement::create(Document& document)
82 { 83 {
83 return adoptRef(new HTMLSelectElement(document, 0)); 84 return adoptRef(new HTMLSelectElement(document, 0));
84 } 85 }
85 86
86 PassRefPtr<HTMLSelectElement> HTMLSelectElement::create(Document& document, HTML FormElement* form) 87 PassRefPtr<HTMLSelectElement> HTMLSelectElement::create(Document& document, HTML FormElement* form)
87 { 88 {
88 return adoptRef(new HTMLSelectElement(document, form)); 89 return adoptRef(new HTMLSelectElement(document, form));
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Otherwise, it returns |listIndex|. 502 // Otherwise, it returns |listIndex|.
502 // Valid means that it is enabled and an option element. 503 // Valid means that it is enabled and an option element.
503 int HTMLSelectElement::nextValidIndex(int listIndex, SkipDirection direction, in t skip) const 504 int HTMLSelectElement::nextValidIndex(int listIndex, SkipDirection direction, in t skip) const
504 { 505 {
505 ASSERT(direction == -1 || direction == 1); 506 ASSERT(direction == -1 || direction == 1);
506 const Vector<HTMLElement*>& listItems = this->listItems(); 507 const Vector<HTMLElement*>& listItems = this->listItems();
507 int lastGoodIndex = listIndex; 508 int lastGoodIndex = listIndex;
508 int size = listItems.size(); 509 int size = listItems.size();
509 for (listIndex += direction; listIndex >= 0 && listIndex < size; listIndex + = direction) { 510 for (listIndex += direction; listIndex >= 0 && listIndex < size; listIndex + = direction) {
510 --skip; 511 --skip;
511 if (!listItems[listIndex]->isDisabledFormControl() && isHTMLOptionElemen t(*listItems[listIndex])) { 512 HTMLElement* element = listItems[listIndex];
512 lastGoodIndex = listIndex; 513 if (!isHTMLOptionElement(*element) || toHTMLOptionElement(element)->isDi sabledFormControl() || toHTMLOptionElement(element)->isDisplayNone())
513 if (skip <= 0) 514 continue;
514 break; 515 lastGoodIndex = listIndex;
515 } 516 if (skip <= 0)
517 break;
516 } 518 }
517 return lastGoodIndex; 519 return lastGoodIndex;
518 } 520 }
519 521
520 int HTMLSelectElement::nextSelectableListIndex(int startIndex) const 522 int HTMLSelectElement::nextSelectableListIndex(int startIndex) const
521 { 523 {
522 return nextValidIndex(startIndex, SkipForwards, 1); 524 return nextValidIndex(startIndex, SkipForwards, 1);
523 } 525 }
524 526
525 int HTMLSelectElement::previousSelectableListIndex(int startIndex) const 527 int HTMLSelectElement::previousSelectableListIndex(int startIndex) const
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 { 620 {
619 ASSERT(renderer() && (renderer()->isListBox() || m_multiple)); 621 ASSERT(renderer() && (renderer()->isListBox() || m_multiple));
620 ASSERT(!listItems().size() || m_activeSelectionAnchorIndex >= 0); 622 ASSERT(!listItems().size() || m_activeSelectionAnchorIndex >= 0);
621 623
622 unsigned start = min(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex ); 624 unsigned start = min(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex );
623 unsigned end = max(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex); 625 unsigned end = max(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex);
624 626
625 const Vector<HTMLElement*>& items = listItems(); 627 const Vector<HTMLElement*>& items = listItems();
626 for (unsigned i = 0; i < items.size(); ++i) { 628 for (unsigned i = 0; i < items.size(); ++i) {
627 HTMLElement* element = items[i]; 629 HTMLElement* element = items[i];
628 if (!isHTMLOptionElement(*element) || toHTMLOptionElement(element)->isDi sabledFormControl()) 630 if (!isHTMLOptionElement(*element) || toHTMLOptionElement(element)->isDi sabledFormControl() || toHTMLOptionElement(element)->isDisplayNone())
629 continue; 631 continue;
630 632
631 if (i >= start && i <= end) 633 if (i >= start && i <= end)
632 toHTMLOptionElement(element)->setSelectedState(m_activeSelectionStat e); 634 toHTMLOptionElement(element)->setSelectedState(m_activeSelectionStat e);
633 else if (deselectOtherOptions || i >= m_cachedStateForActiveSelection.si ze()) 635 else if (deselectOtherOptions || i >= m_cachedStateForActiveSelection.si ze())
634 toHTMLOptionElement(element)->setSelectedState(false); 636 toHTMLOptionElement(element)->setSelectedState(false);
635 else 637 else
636 toHTMLOptionElement(element)->setSelectedState(m_cachedStateForActiv eSelection[i]); 638 toHTMLOptionElement(element)->setSelectedState(m_cachedStateForActiv eSelection[i]);
637 } 639 }
638 640
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 { 838 {
837 return m_suggestedIndex; 839 return m_suggestedIndex;
838 } 840 }
839 841
840 void HTMLSelectElement::setSuggestedIndex(int suggestedIndex) 842 void HTMLSelectElement::setSuggestedIndex(int suggestedIndex)
841 { 843 {
842 m_suggestedIndex = suggestedIndex; 844 m_suggestedIndex = suggestedIndex;
843 845
844 if (RenderObject* renderer = this->renderer()) { 846 if (RenderObject* renderer = this->renderer()) {
845 renderer->updateFromElement(); 847 renderer->updateFromElement();
846 if (renderer->isListBox()) 848 if (renderer->isListBox()) {
847 toRenderListBox(renderer)->scrollToRevealElementAtListIndex(suggeste dIndex); 849 RenderListBox* listBox = toRenderListBox(renderer);
850 listBox->scrollToRevealElementAtListIndex(listBox->toRenderListBoxIn dex(suggestedIndex));
keishi 2014/04/11 06:40:13 I don't like to have yet another index. We have op
spartha 2014/04/11 11:19:45 Done.
851 }
848 } 852 }
849 } 853 }
850 854
851 void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, b ool optionIsSelected) 855 void HTMLSelectElement::optionSelectionStateChanged(HTMLOptionElement* option, b ool optionIsSelected)
852 { 856 {
853 ASSERT(option->ownerSelectElement() == this); 857 ASSERT(option->ownerSelectElement() == this);
854 if (optionIsSelected) 858 if (optionIsSelected)
855 selectOption(option->index()); 859 selectOption(option->index());
856 else if (!usesMenuList() || multiple()) 860 else if (!usesMenuList() || multiple())
857 selectOption(-1); 861 selectOption(-1);
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 if (selectNewItem) 1447 if (selectNewItem)
1444 m_activeSelectionState = true; 1448 m_activeSelectionState = true;
1445 // If the anchor is unitialized, or if we're going to deselect all 1449 // If the anchor is unitialized, or if we're going to deselect all
1446 // other options, then set the anchor index equal to the end index. 1450 // other options, then set the anchor index equal to the end index.
1447 bool deselectOthers = !m_multiple || (!toKeyboardEvent(event)->shift Key() && selectNewItem); 1451 bool deselectOthers = !m_multiple || (!toKeyboardEvent(event)->shift Key() && selectNewItem);
1448 if (m_activeSelectionAnchorIndex < 0 || deselectOthers) { 1452 if (m_activeSelectionAnchorIndex < 0 || deselectOthers) {
1449 if (deselectOthers) 1453 if (deselectOthers)
1450 deselectItemsWithoutValidation(); 1454 deselectItemsWithoutValidation();
1451 setActiveSelectionAnchorIndex(m_activeSelectionEndIndex); 1455 setActiveSelectionAnchorIndex(m_activeSelectionEndIndex);
1452 } 1456 }
1453 1457 RenderListBox* listBox = toRenderListBox(renderer());
1454 toRenderListBox(renderer())->scrollToRevealElementAtListIndex(endInd ex); 1458 toRenderListBox(renderer())->scrollToRevealElementAtListIndex(listBo x->toRenderListBoxIndex(endIndex));
keishi 2014/04/11 06:40:13 Ditto.
spartha 2014/04/11 11:19:45 Done.
1455 if (selectNewItem) { 1459 if (selectNewItem) {
1456 updateListBoxSelection(deselectOthers); 1460 updateListBoxSelection(deselectOthers);
1457 listBoxOnChange(); 1461 listBoxOnChange();
1458 } else 1462 } else
1459 scrollToSelection(); 1463 scrollToSelection();
1460 1464
1461 event->setDefaultHandled(); 1465 event->setDefaultHandled();
1462 } 1466 }
1463 } else if (event->type() == EventTypeNames::keypress) { 1467 } else if (event->type() == EventTypeNames::keypress) {
1464 if (!event->isKeyboardEvent()) 1468 if (!event->isKeyboardEvent())
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 bool HTMLSelectElement::isInteractiveContent() const 1621 bool HTMLSelectElement::isInteractiveContent() const
1618 { 1622 {
1619 return true; 1623 return true;
1620 } 1624 }
1621 1625
1622 bool HTMLSelectElement::supportsAutofocus() const 1626 bool HTMLSelectElement::supportsAutofocus() const
1623 { 1627 {
1624 return true; 1628 return true;
1625 } 1629 }
1626 1630
1631 void HTMLSelectElement::updateListOnRenderer()
1632 {
1633 setOptionsChangedOnRenderer();
1634 }
1635
1636 void HTMLSelectElement::didRecalcStyle(StyleRecalcChange)
1637 {
1638 if (RenderObject* renderer = this->renderer())
1639 renderer->updateFromElement();
1640 }
1641
1627 } // namespace 1642 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698