/* * Copyright (c) 2021-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Web::Selection { class Selection final : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(Selection, Bindings::PlatformObject); public: static JS::NonnullGCPtr create(JS::NonnullGCPtr, JS::NonnullGCPtr); virtual ~Selection() override; enum class Direction { Forwards, Backwards, Directionless, }; JS::GCPtr anchor_node(); unsigned anchor_offset(); JS::GCPtr focus_node(); unsigned focus_offset() const; bool is_collapsed() const; unsigned range_count() const; DeprecatedString type() const; WebIDL::ExceptionOr> get_range_at(unsigned index); void add_range(JS::NonnullGCPtr); WebIDL::ExceptionOr remove_range(JS::NonnullGCPtr); void remove_all_ranges(); void empty(); WebIDL::ExceptionOr collapse(JS::GCPtr, unsigned offset); WebIDL::ExceptionOr set_position(JS::GCPtr, unsigned offset); WebIDL::ExceptionOr collapse_to_start(); WebIDL::ExceptionOr collapse_to_end(); WebIDL::ExceptionOr extend(JS::NonnullGCPtr, unsigned offset); WebIDL::ExceptionOr set_base_and_extent(JS::NonnullGCPtr anchor_node, unsigned anchor_offset, JS::NonnullGCPtr focus_node, unsigned focus_offset); WebIDL::ExceptionOr select_all_children(JS::NonnullGCPtr); WebIDL::ExceptionOr delete_from_document(); bool contains_node(JS::NonnullGCPtr, bool allow_partial_containment) const; DeprecatedString to_deprecated_string() const; // Non-standard convenience accessor for the selection's range. JS::GCPtr range() const; // Non-standard accessor for the selection's document. JS::NonnullGCPtr document() const; private: Selection(JS::NonnullGCPtr, JS::NonnullGCPtr); [[nodiscard]] bool is_empty() const; virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; void set_range(JS::GCPtr); // https://w3c.github.io/selection-api/#dfn-empty JS::GCPtr m_range; JS::NonnullGCPtr m_document; Direction m_direction { Direction::Directionless }; }; }