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

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

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.h
diff --git a/third_party/WebKit/Source/core/html/forms/OptionList.h b/third_party/WebKit/Source/core/html/forms/OptionList.h
new file mode 100644
index 0000000000000000000000000000000000000000..07a36cf7da558b34f7b15b39bf22eee866f290d2
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/forms/OptionList.h
@@ -0,0 +1,56 @@
+// 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.
+
+#ifndef OptionList_h
+#define OptionList_h
+
+#include "core/CoreExport.h"
+#include "platform/heap/Handle.h"
+
+namespace blink {
+
+class HTMLSelectElement;
+class HTMLOptionElement;
+
+class CORE_EXPORT OptionListIterator final {
+ STACK_ALLOCATED();
+public:
+ explicit OptionListIterator(HTMLSelectElement* select) : m_select(select)
+ {
+ if (m_select)
+ advance(nullptr);
+ }
+ HTMLOptionElement* operator*() { return m_current; }
+ void operator++()
+ {
+ if (m_current)
+ advance(m_current);
+ }
+ bool operator==(const OptionListIterator& other) const { return m_current == other.m_current; }
+ bool operator!=(const OptionListIterator& other) const { return !(*this == other); }
+
+private:
+ void advance(HTMLOptionElement* current);
+
+ Member<HTMLSelectElement> m_select;
+ Member<HTMLOptionElement> m_current; // nullptr means we reached to the end.
+};
+
+// OptionList class is a lightweight version of HTMLOptionsCollection.
+class OptionList final {
+ STACK_ALLOCATED();
+public:
+ explicit OptionList(HTMLSelectElement& select) : m_select(select) {}
+ using Iterator = OptionListIterator;
+ Iterator begin() { return Iterator(m_select); }
+ Iterator end() { return Iterator(nullptr); }
+
+private:
+ Member<HTMLSelectElement> m_select;
+};
+
+} // namespace blink
+
+#endif
+
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.cpp ('k') | third_party/WebKit/Source/core/html/forms/OptionList.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698