/* * Copyright (c) 2020, the SerenityOS developers. * Copyright (c) 2022, Luke Wilde * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace Web::DOM { class Range final : public AbstractRange { WEB_PLATFORM_OBJECT(Range, AbstractRange); public: static JS::NonnullGCPtr create(Document&); static JS::NonnullGCPtr create(HTML::Window&); static JS::NonnullGCPtr create(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset); static JS::NonnullGCPtr construct_impl(JS::Realm&); virtual ~Range() override; // FIXME: There are a ton of methods missing here. WebIDL::ExceptionOr set_start(Node& node, u32 offset); WebIDL::ExceptionOr set_end(Node& node, u32 offset); WebIDL::ExceptionOr set_start_before(Node& node); WebIDL::ExceptionOr set_start_after(Node& node); WebIDL::ExceptionOr set_end_before(Node& node); WebIDL::ExceptionOr set_end_after(Node& node); WebIDL::ExceptionOr select_node(Node& node); void collapse(bool to_start); WebIDL::ExceptionOr select_node_contents(Node const&); // https://dom.spec.whatwg.org/#dom-range-start_to_start enum HowToCompareBoundaryPoints : u16 { START_TO_START = 0, START_TO_END = 1, END_TO_END = 2, END_TO_START = 3, }; WebIDL::ExceptionOr compare_boundary_points(u16 how, Range const& source_range) const; JS::NonnullGCPtr inverted() const; JS::NonnullGCPtr normalized() const; JS::NonnullGCPtr clone_range() const; JS::NonnullGCPtr common_ancestor_container() const; // https://dom.spec.whatwg.org/#dom-range-detach void detach() const { // The detach() method steps are to do nothing. // Note: Its functionality (disabling a Range object) was removed, but the method itself is preserved for compatibility. } bool intersects_node(Node const&) const; WebIDL::ExceptionOr is_point_in_range(Node const&, u32 offset) const; WebIDL::ExceptionOr compare_point(Node const&, u32 offset) const; WebIDL::ExceptionOr delete_contents(); WebIDL::ExceptionOr> extract_contents(); WebIDL::ExceptionOr> clone_contents(); WebIDL::ExceptionOr insert_node(JS::NonnullGCPtr); WebIDL::ExceptionOr surround_contents(JS::NonnullGCPtr new_parent); String to_string() const; static HashTable& live_ranges(); private: explicit Range(Document&); Range(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset); Node& root(); Node const& root() const; enum class StartOrEnd { Start, End, }; WebIDL::ExceptionOr set_start_or_end(Node& node, u32 offset, StartOrEnd start_or_end); WebIDL::ExceptionOr select(Node& node); WebIDL::ExceptionOr> extract(); WebIDL::ExceptionOr> clone_the_contents(); WebIDL::ExceptionOr insert(JS::NonnullGCPtr); bool contains_node(Node const&) const; bool partially_contains_node(Node const&) const; }; }