/* * 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); GC_DECLARE_ALLOCATOR(Selection); public: [[nodiscard]] static GC::Ref create(GC::Ref, GC::Ref); virtual ~Selection() override; enum class Direction { Forwards, Backwards, Directionless, }; GC::Ptr anchor_node(); unsigned anchor_offset(); GC::Ptr focus_node(); unsigned focus_offset() const; bool is_collapsed() const; unsigned range_count() const; String type() const; String direction() const; WebIDL::ExceptionOr> get_range_at(unsigned index); void add_range(GC::Ref); WebIDL::ExceptionOr remove_range(GC::Ref); void remove_all_ranges(); void empty(); WebIDL::ExceptionOr collapse(GC::Ptr, unsigned offset); WebIDL::ExceptionOr set_position(GC::Ptr, unsigned offset); WebIDL::ExceptionOr collapse_to_start(); WebIDL::ExceptionOr collapse_to_end(); WebIDL::ExceptionOr extend(GC::Ref, unsigned offset); WebIDL::ExceptionOr set_base_and_extent(GC::Ref anchor_node, unsigned anchor_offset, GC::Ref focus_node, unsigned focus_offset); WebIDL::ExceptionOr select_all_children(GC::Ref); WebIDL::ExceptionOr delete_from_document(); bool contains_node(GC::Ref, bool allow_partial_containment) const; String to_string() const; // Non-standard convenience accessor for the selection's range. GC::Ptr range() const; // Non-standard accessor for the selection's document. GC::Ref document() const; // Non-standard GC::Ptr cursor_position() const; // Non-standard void move_offset_to_next_character(bool collapse_selection); void move_offset_to_previous_character(bool collapse_selection); void move_offset_to_next_word(bool collapse_selection); void move_offset_to_previous_word(bool collapse_selection); private: Selection(GC::Ref, GC::Ref); [[nodiscard]] bool is_empty() const; virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; void set_range(GC::Ptr); // https://w3c.github.io/selection-api/#dfn-empty GC::Ptr m_range; GC::Ref m_document; Direction m_direction { Direction::Directionless }; }; }