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

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

Issue 2149763003: SELECT element: Add HTMLSelectElement::selectedListIndex(). (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
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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 } 866 }
867 867
868 return -1; 868 return -1;
869 } 869 }
870 870
871 void HTMLSelectElement::setSelectedIndex(int index) 871 void HTMLSelectElement::setSelectedIndex(int index)
872 { 872 {
873 selectOption(item(index), DeselectOtherOptions | MakeOptionDirty); 873 selectOption(item(index), DeselectOtherOptions | MakeOptionDirty);
874 } 874 }
875 875
876 int HTMLSelectElement::selectedListIndex() const
877 {
878 int index = 0;
879 for (const auto& item : listItems()) {
880 if (isHTMLOptionElement(item) && toHTMLOptionElement(item)->selected())
881 return index;
882 ++index;
883 }
884 return -1;
885 }
886
876 void HTMLSelectElement::setSuggestedOption(HTMLOptionElement* option) 887 void HTMLSelectElement::setSuggestedOption(HTMLOptionElement* option)
877 { 888 {
878 if (m_suggestedOption == option) 889 if (m_suggestedOption == option)
879 return; 890 return;
880 m_suggestedOption = option; 891 m_suggestedOption = option;
881 892
882 if (LayoutObject* layoutObject = this->layoutObject()) { 893 if (LayoutObject* layoutObject = this->layoutObject()) {
883 layoutObject->updateFromElement(); 894 layoutObject->updateFromElement();
884 scrollToOption(option); 895 scrollToOption(option);
885 } 896 }
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 if (HTMLOptionElement* option = optionAtListIndex(--i)) { 1697 if (HTMLOptionElement* option = optionAtListIndex(--i)) {
1687 if (option->selected()) 1698 if (option->selected())
1688 return option; 1699 return option;
1689 } 1700 }
1690 } 1701 }
1691 return nullptr; 1702 return nullptr;
1692 } 1703 }
1693 1704
1694 int HTMLSelectElement::indexOfSelectedOption() const 1705 int HTMLSelectElement::indexOfSelectedOption() const
1695 { 1706 {
1696 return optionToListIndex(selectedIndex()); 1707 return selectedListIndex();
1697 } 1708 }
1698 1709
1699 int HTMLSelectElement::optionCount() const 1710 int HTMLSelectElement::optionCount() const
1700 { 1711 {
1701 return listItems().size(); 1712 return listItems().size();
1702 } 1713 }
1703 1714
1704 String HTMLSelectElement::optionAtIndex(int index) const 1715 String HTMLSelectElement::optionAtIndex(int index) const
1705 { 1716 {
1706 if (HTMLOptionElement* option = optionAtListIndex(index)) { 1717 if (HTMLOptionElement* option = optionAtListIndex(index)) {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 } 2074 }
2064 2075
2065 void HTMLSelectElement::didMutateSubtree() 2076 void HTMLSelectElement::didMutateSubtree()
2066 { 2077 {
2067 DCHECK(popupIsVisible()); 2078 DCHECK(popupIsVisible());
2068 DCHECK(m_popup); 2079 DCHECK(m_popup);
2069 m_popup->updateFromElement(PopupMenu::ByDOMChange); 2080 m_popup->updateFromElement(PopupMenu::ByDOMChange);
2070 } 2081 }
2071 2082
2072 } // namespace blink 2083 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | third_party/WebKit/Source/web/ExternalPopupMenu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698