Skip to content

Commit 0cab272

Browse files
committed
LibWeb: Change Editing::editing_host_of_node() to Node::editing_host()
No functional changes.
1 parent 3f5bc02 commit 0cab272

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

Libraries/LibWeb/DOM/Node.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,31 @@ bool Node::is_editing_host() const
15791579
return is<Document>(parent()) && static_cast<Document const&>(*parent()).design_mode_enabled_state();
15801580
}
15811581

1582+
// https://w3c.github.io/editing/docs/execCommand/#editing-host-of
1583+
GC::Ptr<Node> Node::editing_host()
1584+
{
1585+
// node itself, if node is an editing host;
1586+
if (is_editing_host())
1587+
return *this;
1588+
1589+
// or the nearest ancestor of node that is an editing host, if node is editable.
1590+
if (is_editable()) {
1591+
GC::Ptr<Node> result;
1592+
for_each_ancestor([&result](GC::Ref<Node> ancestor) {
1593+
if (ancestor->is_editing_host()) {
1594+
result = ancestor;
1595+
return IterationDecision::Break;
1596+
}
1597+
return IterationDecision::Continue;
1598+
});
1599+
VERIFY(result);
1600+
return result;
1601+
}
1602+
1603+
// The editing host of node is null if node is neither editable nor an editing host;
1604+
return {};
1605+
}
1606+
15821607
void Node::set_layout_node(Badge<Layout::Node>, GC::Ref<Layout::Node> layout_node)
15831608
{
15841609
m_layout_node = layout_node;

Libraries/LibWeb/DOM/Node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ class Node : public EventTarget
184184
bool is_editable() const;
185185
bool is_editing_host() const;
186186
bool is_editable_or_editing_host() const { return is_editable() || is_editing_host(); }
187+
GC::Ptr<Node> editing_host();
187188

188189
virtual bool is_dom_node() const final { return true; }
189190
virtual bool is_html_element() const { return false; }

Libraries/LibWeb/Editing/ExecCommand.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ WebIDL::ExceptionOr<bool> Document::exec_command(FlyString const& command, [[may
5959
//
6060
// NOTE: Because either the start or end node of the range could be inside an editing host that is part of the
6161
// other node's editing host, we can probe both and see if either one is the other's ancestor.
62-
// NOTE: We can reuse Editing::editing_host_of_node() here since query_command_enabled() above already checked
63-
// that both the start and end nodes are either editable or an editing host.
62+
// NOTE: We can reuse ->editing_host() here since query_command_enabled() above already checked that both the
63+
// start and end nodes are either editable or an editing host.
6464
auto range = Editing::active_range(*this);
65-
auto& start_node_editing_host = *Editing::editing_host_of_node(range->start_container());
66-
auto& end_node_editing_host = *Editing::editing_host_of_node(range->end_container());
65+
auto& start_node_editing_host = *range->start_container()->editing_host();
66+
auto& end_node_editing_host = *range->end_container()->editing_host();
6767
affected_editing_host = start_node_editing_host.is_ancestor_of(end_node_editing_host)
6868
? end_node_editing_host
6969
: start_node_editing_host;
@@ -174,15 +174,15 @@ WebIDL::ExceptionOr<bool> Document::query_command_enabled(FlyString const& comma
174174
return false;
175175

176176
// FIXME: the editing host of its start node is not an EditContext editing host,
177-
[[maybe_unused]] auto start_node_editing_host = Editing::editing_host_of_node(start_node);
177+
[[maybe_unused]] auto start_node_editing_host = start_node->editing_host();
178178

179179
// its end node is either editable or an editing host,
180180
auto& end_node = *active_range->end_container();
181181
if (!end_node.is_editable_or_editing_host())
182182
return false;
183183

184184
// FIXME: the editing host of its end node is not an EditContext editing host,
185-
[[maybe_unused]] auto end_node_editing_host = Editing::editing_host_of_node(end_node);
185+
[[maybe_unused]] auto end_node_editing_host = end_node.editing_host();
186186

187187
// and there is some editing host that is an inclusive ancestor of both its start node and its end node.
188188
GC::Ptr<Node> inclusive_ancestor_editing_host;

Libraries/LibWeb/Editing/Internal/Algorithms.cpp

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,31 +1106,6 @@ void delete_the_selection(Selection& selection, bool block_merging, bool strip_w
11061106
restore_states_and_values(document, overrides);
11071107
}
11081108

1109-
// https://w3c.github.io/editing/docs/execCommand/#editing-host-of
1110-
GC::Ptr<DOM::Node> editing_host_of_node(GC::Ref<DOM::Node> node)
1111-
{
1112-
// node itself, if node is an editing host;
1113-
if (node->is_editing_host())
1114-
return node;
1115-
1116-
// or the nearest ancestor of node that is an editing host, if node is editable.
1117-
if (node->is_editable()) {
1118-
GC::Ptr<DOM::Node> result;
1119-
node->for_each_ancestor([&result](GC::Ref<DOM::Node> ancestor) {
1120-
if (ancestor->is_editing_host()) {
1121-
result = ancestor;
1122-
return IterationDecision::Break;
1123-
}
1124-
return IterationDecision::Continue;
1125-
});
1126-
VERIFY(result);
1127-
return result;
1128-
}
1129-
1130-
// The editing host of node is null if node is neither editable nor an editing host;
1131-
return {};
1132-
}
1133-
11341109
// https://w3c.github.io/editing/docs/execCommand/#effective-command-value
11351110
Optional<Utf16String> effective_command_value(GC::Ptr<DOM::Node> node, FlyString const& command)
11361111
{
@@ -1308,7 +1283,7 @@ void fix_disallowed_ancestors_of_node(GC::Ref<DOM::Node> node)
13081283
}
13091284

13101285
// 2. If "p" is not an allowed child of the editing host of node, abort these steps.
1311-
if (!is_allowed_child_of_node(HTML::TagNames::p, GC::Ref { *editing_host_of_node(node) }))
1286+
if (!is_allowed_child_of_node(HTML::TagNames::p, GC::Ref { *node->editing_host() }))
13121287
return;
13131288

13141289
// 3. If node is not a prohibited paragraph child, abort these steps.
@@ -2145,8 +2120,8 @@ bool is_in_same_editing_host(GC::Ref<DOM::Node> node_a, GC::Ref<DOM::Node> node_
21452120
{
21462121
// Two nodes are in the same editing host if the editing host of the first is non-null and the
21472122
// same as the editing host of the second.
2148-
auto editing_host_a = editing_host_of_node(node_a);
2149-
auto editing_host_b = editing_host_of_node(node_b);
2123+
auto editing_host_a = node_a->editing_host();
2124+
auto editing_host_b = node_b->editing_host();
21502125
return editing_host_a && editing_host_a == editing_host_b;
21512126
}
21522127

Libraries/LibWeb/Editing/Internal/Algorithms.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void canonicalize_whitespace(DOM::BoundaryPoint, bool fix_collapsed_space = true
5959
Vector<GC::Ref<DOM::Node>> clear_the_value(FlyString const&, GC::Ref<DOM::Element>);
6060
void delete_the_selection(Selection&, bool block_merging = true, bool strip_wrappers = true,
6161
Selection::Direction direction = Selection::Direction::Forwards);
62-
GC::Ptr<DOM::Node> editing_host_of_node(GC::Ref<DOM::Node>);
6362
Optional<Utf16String> effective_command_value(GC::Ptr<DOM::Node>, FlyString const& command);
6463
DOM::BoundaryPoint first_equivalent_point(DOM::BoundaryPoint);
6564
void fix_disallowed_ancestors_of_node(GC::Ref<DOM::Node>);

Libraries/LibWeb/Page/EventHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ EventResult EventHandler::handle_keydown(UIEvents::KeyCode key, u32 modifiers, u
13191319

13201320
// If the editing host is contenteditable="plaintext-only", we force a line break.
13211321
if (focused_element) {
1322-
if (auto editing_host = Editing::editing_host_of_node(*focused_element); editing_host
1322+
if (auto editing_host = focused_element->editing_host(); editing_host
13231323
&& as<HTML::HTMLElement>(*editing_host).content_editable_state() == HTML::ContentEditableState::PlaintextOnly)
13241324
input_type = UIEvents::InputTypes::insertLineBreak;
13251325
}

0 commit comments

Comments
 (0)