mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:17:34 +00:00
LibWeb: Implement a large chunk of the Selection API
This patch implements enough of the Selection API specification that we stop hitting unimplemented functions when loading Twitter.
This commit is contained in:
parent
317ab7a04b
commit
e77798f5fd
3 changed files with 270 additions and 54 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::Selection {
|
||||
|
||||
|
@ -14,36 +15,53 @@ class Selection final : public Bindings::PlatformObject {
|
|||
WEB_PLATFORM_OBJECT(Selection, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<Selection> create(JS::Realm&);
|
||||
static JS::NonnullGCPtr<Selection> create(JS::NonnullGCPtr<JS::Realm>, JS::NonnullGCPtr<DOM::Document>);
|
||||
|
||||
virtual ~Selection() override;
|
||||
|
||||
DOM::Node* anchor_node();
|
||||
enum class Direction {
|
||||
Forwards,
|
||||
Backwards,
|
||||
Directionless,
|
||||
};
|
||||
|
||||
JS::GCPtr<DOM::Node> anchor_node();
|
||||
unsigned anchor_offset();
|
||||
DOM::Node* focus_node();
|
||||
JS::GCPtr<DOM::Node> focus_node();
|
||||
unsigned focus_offset() const;
|
||||
bool is_collapsed() const;
|
||||
unsigned range_count() const;
|
||||
String type() const;
|
||||
DOM::Range* get_range_at(unsigned index);
|
||||
void add_range(DOM::Range&);
|
||||
void remove_range(DOM::Range&);
|
||||
WebIDL::ExceptionOr<JS::GCPtr<DOM::Range>> get_range_at(unsigned index);
|
||||
void add_range(JS::NonnullGCPtr<DOM::Range>);
|
||||
WebIDL::ExceptionOr<void> remove_range(JS::NonnullGCPtr<DOM::Range>);
|
||||
void remove_all_ranges();
|
||||
void empty();
|
||||
void collapse(DOM::Node*, unsigned offset);
|
||||
void set_position(DOM::Node*, unsigned offset);
|
||||
void collapse(JS::GCPtr<DOM::Node>, unsigned offset);
|
||||
void set_position(JS::GCPtr<DOM::Node>, unsigned offset);
|
||||
void collapse_to_start();
|
||||
void collapse_to_end();
|
||||
void extend(DOM::Node&, unsigned offset);
|
||||
void set_base_and_extent(DOM::Node& anchor_node, unsigned anchor_offset, DOM::Node& focus_node, unsigned focus_offset);
|
||||
void select_all_children(DOM::Node&);
|
||||
void delete_from_document();
|
||||
bool contains_node(DOM::Node&, bool allow_partial_containment) const;
|
||||
WebIDL::ExceptionOr<void> extend(JS::NonnullGCPtr<DOM::Node>, unsigned offset);
|
||||
void set_base_and_extent(JS::NonnullGCPtr<DOM::Node> anchor_node, unsigned anchor_offset, JS::NonnullGCPtr<DOM::Node> focus_node, unsigned focus_offset);
|
||||
WebIDL::ExceptionOr<void> select_all_children(JS::NonnullGCPtr<DOM::Node>);
|
||||
WebIDL::ExceptionOr<void>
|
||||
delete_from_document();
|
||||
bool contains_node(JS::NonnullGCPtr<DOM::Node>, bool allow_partial_containment) const;
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
explicit Selection(JS::Realm&);
|
||||
Selection(JS::NonnullGCPtr<JS::Realm>, JS::NonnullGCPtr<DOM::Document>);
|
||||
|
||||
[[nodiscard]] bool is_empty() const;
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
// https://w3c.github.io/selection-api/#dfn-empty
|
||||
JS::GCPtr<DOM::Range> m_range;
|
||||
|
||||
JS::NonnullGCPtr<DOM::Document> m_document;
|
||||
Direction m_direction { Direction::Directionless };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue