mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb: Change Editing::editing_host_of_node() to Node::editing_host()
No functional changes.
This commit is contained in:
parent
3f5bc023e2
commit
0cab272f7f
|
|
@ -1579,6 +1579,31 @@ bool Node::is_editing_host() const
|
|||
return is<Document>(parent()) && static_cast<Document const&>(*parent()).design_mode_enabled_state();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#editing-host-of
|
||||
GC::Ptr<Node> Node::editing_host()
|
||||
{
|
||||
// node itself, if node is an editing host;
|
||||
if (is_editing_host())
|
||||
return *this;
|
||||
|
||||
// or the nearest ancestor of node that is an editing host, if node is editable.
|
||||
if (is_editable()) {
|
||||
GC::Ptr<Node> result;
|
||||
for_each_ancestor([&result](GC::Ref<Node> ancestor) {
|
||||
if (ancestor->is_editing_host()) {
|
||||
result = ancestor;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
VERIFY(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// The editing host of node is null if node is neither editable nor an editing host;
|
||||
return {};
|
||||
}
|
||||
|
||||
void Node::set_layout_node(Badge<Layout::Node>, GC::Ref<Layout::Node> layout_node)
|
||||
{
|
||||
m_layout_node = layout_node;
|
||||
|
|
|
|||
|
|
@ -184,6 +184,7 @@ public:
|
|||
bool is_editable() const;
|
||||
bool is_editing_host() const;
|
||||
bool is_editable_or_editing_host() const { return is_editable() || is_editing_host(); }
|
||||
GC::Ptr<Node> editing_host();
|
||||
|
||||
virtual bool is_dom_node() const final { return true; }
|
||||
virtual bool is_html_element() const { return false; }
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ WebIDL::ExceptionOr<bool> Document::exec_command(FlyString const& command, [[may
|
|||
//
|
||||
// NOTE: Because either the start or end node of the range could be inside an editing host that is part of the
|
||||
// other node's editing host, we can probe both and see if either one is the other's ancestor.
|
||||
// NOTE: We can reuse Editing::editing_host_of_node() here since query_command_enabled() above already checked
|
||||
// that both the start and end nodes are either editable or an editing host.
|
||||
// NOTE: We can reuse ->editing_host() here since query_command_enabled() above already checked that both the
|
||||
// start and end nodes are either editable or an editing host.
|
||||
auto range = Editing::active_range(*this);
|
||||
auto& start_node_editing_host = *Editing::editing_host_of_node(range->start_container());
|
||||
auto& end_node_editing_host = *Editing::editing_host_of_node(range->end_container());
|
||||
auto& start_node_editing_host = *range->start_container()->editing_host();
|
||||
auto& end_node_editing_host = *range->end_container()->editing_host();
|
||||
affected_editing_host = start_node_editing_host.is_ancestor_of(end_node_editing_host)
|
||||
? end_node_editing_host
|
||||
: start_node_editing_host;
|
||||
|
|
@ -174,7 +174,7 @@ WebIDL::ExceptionOr<bool> Document::query_command_enabled(FlyString const& comma
|
|||
return false;
|
||||
|
||||
// FIXME: the editing host of its start node is not an EditContext editing host,
|
||||
[[maybe_unused]] auto start_node_editing_host = Editing::editing_host_of_node(start_node);
|
||||
[[maybe_unused]] auto start_node_editing_host = start_node->editing_host();
|
||||
|
||||
// its end node is either editable or an editing host,
|
||||
auto& end_node = *active_range->end_container();
|
||||
|
|
@ -182,7 +182,7 @@ WebIDL::ExceptionOr<bool> Document::query_command_enabled(FlyString const& comma
|
|||
return false;
|
||||
|
||||
// FIXME: the editing host of its end node is not an EditContext editing host,
|
||||
[[maybe_unused]] auto end_node_editing_host = Editing::editing_host_of_node(end_node);
|
||||
[[maybe_unused]] auto end_node_editing_host = end_node.editing_host();
|
||||
|
||||
// and there is some editing host that is an inclusive ancestor of both its start node and its end node.
|
||||
GC::Ptr<Node> inclusive_ancestor_editing_host;
|
||||
|
|
|
|||
|
|
@ -1106,31 +1106,6 @@ void delete_the_selection(Selection& selection, bool block_merging, bool strip_w
|
|||
restore_states_and_values(document, overrides);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#editing-host-of
|
||||
GC::Ptr<DOM::Node> editing_host_of_node(GC::Ref<DOM::Node> node)
|
||||
{
|
||||
// node itself, if node is an editing host;
|
||||
if (node->is_editing_host())
|
||||
return node;
|
||||
|
||||
// or the nearest ancestor of node that is an editing host, if node is editable.
|
||||
if (node->is_editable()) {
|
||||
GC::Ptr<DOM::Node> result;
|
||||
node->for_each_ancestor([&result](GC::Ref<DOM::Node> ancestor) {
|
||||
if (ancestor->is_editing_host()) {
|
||||
result = ancestor;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
VERIFY(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// The editing host of node is null if node is neither editable nor an editing host;
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#effective-command-value
|
||||
Optional<Utf16String> effective_command_value(GC::Ptr<DOM::Node> node, FlyString const& command)
|
||||
{
|
||||
|
|
@ -1308,7 +1283,7 @@ void fix_disallowed_ancestors_of_node(GC::Ref<DOM::Node> node)
|
|||
}
|
||||
|
||||
// 2. If "p" is not an allowed child of the editing host of node, abort these steps.
|
||||
if (!is_allowed_child_of_node(HTML::TagNames::p, GC::Ref { *editing_host_of_node(node) }))
|
||||
if (!is_allowed_child_of_node(HTML::TagNames::p, GC::Ref { *node->editing_host() }))
|
||||
return;
|
||||
|
||||
// 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_
|
|||
{
|
||||
// Two nodes are in the same editing host if the editing host of the first is non-null and the
|
||||
// same as the editing host of the second.
|
||||
auto editing_host_a = editing_host_of_node(node_a);
|
||||
auto editing_host_b = editing_host_of_node(node_b);
|
||||
auto editing_host_a = node_a->editing_host();
|
||||
auto editing_host_b = node_b->editing_host();
|
||||
return editing_host_a && editing_host_a == editing_host_b;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ void canonicalize_whitespace(DOM::BoundaryPoint, bool fix_collapsed_space = true
|
|||
Vector<GC::Ref<DOM::Node>> clear_the_value(FlyString const&, GC::Ref<DOM::Element>);
|
||||
void delete_the_selection(Selection&, bool block_merging = true, bool strip_wrappers = true,
|
||||
Selection::Direction direction = Selection::Direction::Forwards);
|
||||
GC::Ptr<DOM::Node> editing_host_of_node(GC::Ref<DOM::Node>);
|
||||
Optional<Utf16String> effective_command_value(GC::Ptr<DOM::Node>, FlyString const& command);
|
||||
DOM::BoundaryPoint first_equivalent_point(DOM::BoundaryPoint);
|
||||
void fix_disallowed_ancestors_of_node(GC::Ref<DOM::Node>);
|
||||
|
|
|
|||
|
|
@ -1319,7 +1319,7 @@ EventResult EventHandler::handle_keydown(UIEvents::KeyCode key, u32 modifiers, u
|
|||
|
||||
// If the editing host is contenteditable="plaintext-only", we force a line break.
|
||||
if (focused_element) {
|
||||
if (auto editing_host = Editing::editing_host_of_node(*focused_element); editing_host
|
||||
if (auto editing_host = focused_element->editing_host(); editing_host
|
||||
&& as<HTML::HTMLElement>(*editing_host).content_editable_state() == HTML::ContentEditableState::PlaintextOnly)
|
||||
input_type = UIEvents::InputTypes::insertLineBreak;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user