/* * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Web::DOM { // https://dom.spec.whatwg.org/#nodeiterator class NodeIterator : public RefCounted , public Bindings::Wrappable { public: using WrapperType = Bindings::NodeIteratorWrapper; static NonnullRefPtr create(Node& root, unsigned what_to_show, RefPtr); NonnullRefPtr root() { return m_root; } NonnullRefPtr reference_node() { return m_reference; } bool pointer_before_reference_node() const { return m_pointer_before_reference; } unsigned what_to_show() const { return m_what_to_show; } NodeFilter* filter() { return m_filter; } JS::ThrowCompletionOr> next_node(); JS::ThrowCompletionOr> previous_node(); void detach(); private: NodeIterator(Node& root); enum class Direction { Next, Previous, }; JS::ThrowCompletionOr> traverse(Direction); JS::ThrowCompletionOr filter(Node&); // https://dom.spec.whatwg.org/#concept-traversal-root NonnullRefPtr m_root; // https://dom.spec.whatwg.org/#nodeiterator-reference NonnullRefPtr m_reference; // https://dom.spec.whatwg.org/#nodeiterator-pointer-before-reference bool m_pointer_before_reference { true }; // https://dom.spec.whatwg.org/#concept-traversal-whattoshow unsigned m_what_to_show { 0 }; // https://dom.spec.whatwg.org/#concept-traversal-filter RefPtr m_filter; // https://dom.spec.whatwg.org/#concept-traversal-active bool m_active { false }; }; }