1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

LibWeb: Stub out a basic Selection interface

This patch establishes scaffolding for the Selection API.
This commit is contained in:
Andreas Kling 2021-10-10 19:12:32 +02:00
parent 6782cf5193
commit 5c9ca5c2dc
11 changed files with 269 additions and 1 deletions

View file

@ -0,0 +1,135 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Selection/Selection.h>
namespace Web::Selection {
NonnullRefPtr<Selection> Selection::create()
{
return adopt_ref(*new Selection);
}
DOM::Node* Selection::anchor_node()
{
TODO();
}
unsigned Selection::anchor_offset()
{
TODO();
}
DOM::Node* Selection::focus_node()
{
TODO();
}
unsigned Selection::focus_offset() const
{
TODO();
}
bool Selection::is_collapsed() const
{
TODO();
}
unsigned Selection::range_count() const
{
TODO();
}
String Selection::type() const
{
TODO();
}
NonnullRefPtr<DOM::Range> Selection::get_range_at(unsigned index)
{
(void)index;
TODO();
}
void Selection::add_range(DOM::Range&)
{
TODO();
}
void Selection::remove_range(DOM::Range&)
{
TODO();
}
void Selection::remove_all_ranges()
{
TODO();
}
void Selection::empty()
{
TODO();
}
void Selection::collapse(DOM::Node*, unsigned offset)
{
(void)offset;
TODO();
}
void Selection::set_position(DOM::Node*, unsigned offset)
{
(void)offset;
TODO();
}
void Selection::collapse_to_start()
{
TODO();
}
void Selection::collapse_to_end()
{
TODO();
}
void Selection::extend(DOM::Node&, unsigned offset)
{
(void)offset;
TODO();
}
void Selection::set_base_and_extent(DOM::Node& anchor_node, unsigned anchor_offset, DOM::Node& focus_node, unsigned focus_offset)
{
(void)anchor_node;
(void)anchor_offset;
(void)focus_node;
(void)focus_offset;
TODO();
}
void Selection::select_all_children(DOM::Node&)
{
TODO();
}
void Selection::delete_from_document()
{
TODO();
}
bool Selection::contains_node(DOM::Node&, bool allow_partial_containment) const
{
(void)allow_partial_containment;
TODO();
}
String Selection::to_string() const
{
TODO();
}
}

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <LibWeb/Bindings/Wrappable.h>
namespace Web::Selection {
class Selection
: public RefCounted<Selection>
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::SelectionWrapper;
static NonnullRefPtr<Selection> create();
DOM::Node* anchor_node();
unsigned anchor_offset();
DOM::Node* focus_node();
unsigned focus_offset() const;
bool is_collapsed() const;
unsigned range_count() const;
String type() const;
NonnullRefPtr<DOM::Range> get_range_at(unsigned index);
void add_range(DOM::Range&);
void remove_range(DOM::Range&);
void remove_all_ranges();
void empty();
void collapse(DOM::Node*, unsigned offset);
void set_position(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;
String to_string() const;
};
}

View file

@ -0,0 +1,27 @@
[Exposed=Window]
interface Selection {
readonly attribute Node? anchorNode;
readonly attribute unsigned long anchorOffset;
readonly attribute Node? focusNode;
readonly attribute unsigned long focusOffset;
readonly attribute boolean isCollapsed;
readonly attribute unsigned long rangeCount;
readonly attribute DOMString type;
Range getRangeAt(unsigned long index);
undefined addRange(Range range);
undefined removeRange(Range range);
undefined removeAllRanges();
undefined empty();
undefined collapse(Node? node, optional unsigned long offset = 0);
undefined setPosition(Node? node, optional unsigned long offset = 0);
undefined collapseToStart();
undefined collapseToEnd();
undefined extend(Node node, optional unsigned long offset = 0);
undefined setBaseAndExtent(Node anchorNode, unsigned long anchorOffset, Node focusNode, unsigned long focusOffset);
undefined selectAllChildren(Node node);
[CEReactions] undefined deleteFromDocument();
boolean containsNode(Node node, optional boolean allowPartialContainment = false);
stringifier;
};