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

Unified Diff: third_party/WebKit/Source/core/html/forms/OptionList.cpp

Issue 2130653002: SELECT element: Introduce light-weight OPTION iterater. (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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/forms/OptionList.cpp
diff --git a/third_party/WebKit/Source/core/html/forms/OptionList.cpp b/third_party/WebKit/Source/core/html/forms/OptionList.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..06f4f6fe6cef9715d830be5e4e85c81303e910bf
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/forms/OptionList.cpp
@@ -0,0 +1,40 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/forms/OptionList.h"
+
+#include "core/dom/ElementTraversal.h"
+#include "core/html/HTMLOptionElement.h"
+#include "core/html/HTMLSelectElement.h"
+
+namespace blink {
+
+void OptionListIterator::advance(HTMLOptionElement* previous)
+{
+ // This function returns only
+ // - An OPTION child of m_select, or
+ // - An OPTION child of an OPTGROUP child of m_select.
+
+ Element* current;
+ if (previous) {
+ DCHECK_EQ(previous->ownerSelectElement(), m_select);
+ current = ElementTraversal::nextSkippingChildren(*previous, m_select);
+ } else {
+ current = ElementTraversal::firstChild(*m_select);
+ }
+ while (current) {
+ if (isHTMLOptionElement(current)) {
+ m_current = toHTMLOptionElement(current);
+ return;
+ }
+ if (isHTMLOptGroupElement(current) && current->parentNode() == m_select) {
+ if ((m_current = Traversal<HTMLOptionElement>::firstChild(*current)))
+ return;
+ }
+ current = ElementTraversal::nextSkippingChildren(*current, m_select);
+ }
+ m_current = nullptr;
+}
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/html/forms/OptionList.h ('k') | third_party/WebKit/Source/core/html/forms/OptionListTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698