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

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

Issue 2147223004: SELECT element: Remove HTMLSelectElement::optionToListIndex(). (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 | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // "0 size()" happens when an attribute "size" is absent or an invalid size 136 // "0 size()" happens when an attribute "size" is absent or an invalid size
137 // attribute is specified. In this case, the display size should be assumed 137 // attribute is specified. In this case, the display size should be assumed
138 // as the default. The default display size is 1 for non-multiple select 138 // as the default. The default display size is 1 for non-multiple select
139 // elements, and 4 for multiple select elements. 139 // elements, and 4 for multiple select elements.
140 // 140 //
141 // Finally, if size() == 0 and non-multiple, the display size can be assumed 141 // Finally, if size() == 0 and non-multiple, the display size can be assumed
142 // as 1. 142 // as 1.
143 if (multiple() || size() > 1) 143 if (multiple() || size() > 1)
144 return false; 144 return false;
145 145
146 int listIndex = optionToListIndex(0); 146 // TODO(tkent): This function is called in CSS selector matching. Using
147 ASSERT(listIndex >= 0); 147 // listItems() might have performance impact.
148 if (listIndex < 0) 148 if (listItems().size() == 0 || !isHTMLOptionElement(listItems()[0]))
149 return false; 149 return false;
150 return !listIndex && toHTMLOptionElement(listItems()[listIndex])->value().is Empty(); 150 return toHTMLOptionElement(listItems()[0])->value().isEmpty();
151 } 151 }
152 152
153 String HTMLSelectElement::validationMessage() const 153 String HTMLSelectElement::validationMessage() const
154 { 154 {
155 if (!willValidate()) 155 if (!willValidate())
156 return String(); 156 return String();
157 if (customError()) 157 if (customError())
158 return customValidationMessage(); 158 return customValidationMessage();
159 if (valueMissing()) 159 if (valueMissing())
160 return locale().queryString(WebLocalizedString::ValidationValueMissingFo rSelect); 160 return locale().queryString(WebLocalizedString::ValidationValueMissingFo rSelect);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 beforeElement = options()->item(before.getAsLong()); 234 beforeElement = options()->item(before.getAsLong());
235 else 235 else
236 beforeElement = nullptr; 236 beforeElement = nullptr;
237 237
238 insertBefore(elementToInsert, beforeElement, exceptionState); 238 insertBefore(elementToInsert, beforeElement, exceptionState);
239 setNeedsValidityCheck(); 239 setNeedsValidityCheck();
240 } 240 }
241 241
242 void HTMLSelectElement::remove(int optionIndex) 242 void HTMLSelectElement::remove(int optionIndex)
243 { 243 {
244 int listIndex = optionToListIndex(optionIndex); 244 if (HTMLOptionElement* option = item(optionIndex))
245 if (listIndex >= 0) 245 option->remove(IGNORE_EXCEPTION);
246 listItems()[listIndex]->remove(IGNORE_EXCEPTION);
247 } 246 }
248 247
249 String HTMLSelectElement::value() const 248 String HTMLSelectElement::value() const
250 { 249 {
251 if (HTMLOptionElement* option = selectedOption()) 250 if (HTMLOptionElement* option = selectedOption())
252 return option->value(); 251 return option->value();
253 return ""; 252 return "";
254 } 253 }
255 254
256 void HTMLSelectElement::setValue(const String &value, bool sendEvents) 255 void HTMLSelectElement::setValue(const String &value, bool sendEvents)
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 if (usesMenuList()) { 1048 if (usesMenuList()) {
1050 // didSelectOption() is O(N) because of HTMLOptionElement::index (). 1049 // didSelectOption() is O(N) because of HTMLOptionElement::index ().
1051 toLayoutMenuList(layoutObject)->didSelectOption(element); 1050 toLayoutMenuList(layoutObject)->didSelectOption(element);
1052 } 1051 }
1053 } 1052 }
1054 } 1053 }
1055 1054
1056 notifyFormStateChanged(); 1055 notifyFormStateChanged();
1057 } 1056 }
1058 1057
1059 int HTMLSelectElement::optionToListIndex(int optionIndex) const
1060 {
1061 const ListItems& items = listItems();
1062 int listSize = static_cast<int>(items.size());
1063 if (optionIndex < 0 || optionIndex >= listSize)
1064 return -1;
1065
1066 int optionIndex2 = -1;
1067 for (int listIndex = 0; listIndex < listSize; ++listIndex) {
1068 if (isHTMLOptionElement(*items[listIndex])) {
1069 ++optionIndex2;
1070 if (optionIndex2 == optionIndex)
1071 return listIndex;
1072 }
1073 }
1074
1075 return -1;
1076 }
1077
1078 void HTMLSelectElement::dispatchFocusEvent(Element* oldFocusedElement, WebFocusT ype type, InputDeviceCapabilities* sourceCapabilities) 1058 void HTMLSelectElement::dispatchFocusEvent(Element* oldFocusedElement, WebFocusT ype type, InputDeviceCapabilities* sourceCapabilities)
1079 { 1059 {
1080 // Save the selection so it can be compared to the new selection when 1060 // Save the selection so it can be compared to the new selection when
1081 // dispatching change events during blur event dispatch. 1061 // dispatching change events during blur event dispatch.
1082 if (usesMenuList()) 1062 if (usesMenuList())
1083 saveLastSelection(); 1063 saveLastSelection();
1084 HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedElement, type, sourceCapabilities); 1064 HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedElement, type, sourceCapabilities);
1085 } 1065 }
1086 1066
1087 void HTMLSelectElement::dispatchBlurEvent(Element* newFocusedElement, WebFocusTy pe type, InputDeviceCapabilities* sourceCapabilities) 1067 void HTMLSelectElement::dispatchBlurEvent(Element* newFocusedElement, WebFocusTy pe type, InputDeviceCapabilities* sourceCapabilities)
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 } 2034 }
2055 2035
2056 void HTMLSelectElement::didMutateSubtree() 2036 void HTMLSelectElement::didMutateSubtree()
2057 { 2037 {
2058 DCHECK(popupIsVisible()); 2038 DCHECK(popupIsVisible());
2059 DCHECK(m_popup); 2039 DCHECK(m_popup);
2060 m_popup->updateFromElement(PopupMenu::ByDOMChange); 2040 m_popup->updateFromElement(PopupMenu::ByDOMChange);
2061 } 2041 }
2062 2042
2063 } // namespace blink 2043 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698