LibWeb: Refactor "editable" and "editing host" concepts

The DOM spec defines what it means for an element to be an "editing
host", and the Editing spec does the same for the "editable" concept.
Replace our `Node::is_editable()` implementation with these
spec-compliant algorithms.

An editing host is an element that has the properties to make its
contents effectively editable. Editable elements are descendants of an
editing host. Concepts like the inheritable contenteditable attribute
are propagated through the editable algorithm.
This commit is contained in:
Jelle Raaijmakers 2024-12-06 11:41:20 +01:00 committed by Jelle Raaijmakers
parent f88c13a58c
commit 1c55153d43
Notes: github-actions[bot] 2024-12-10 13:55:36 +00:00
22 changed files with 85 additions and 102 deletions

View file

@ -201,7 +201,7 @@ String canonical_space_sequence(u32 length, bool non_breaking_start, bool non_br
void canonicalize_whitespace(GC::Ref<DOM::Node> node, u32 offset, bool fix_collapsed_space)
{
// 1. If node is neither editable nor an editing host, abort these steps.
if (!node->is_editable() || !is_editing_host(node))
if (!node->is_editable_or_editing_host())
return;
// 2. Let start node equal node and let start offset equal offset.
@ -916,20 +916,6 @@ bool is_collapsed_whitespace_node(GC::Ref<DOM::Node> node)
return false;
}
// https://html.spec.whatwg.org/multipage/interaction.html#editing-host
bool is_editing_host(GC::Ref<DOM::Node> node)
{
// An editing host is either an HTML element with its contenteditable attribute in the true
// state or plaintext-only state, or a child HTML element of a Document whose design mode
// enabled is true.
if (!is<HTML::HTMLElement>(*node))
return false;
auto const& html_element = static_cast<HTML::HTMLElement&>(*node);
return html_element.content_editable_state() == HTML::ContentEditableState::True
|| html_element.content_editable_state() == HTML::ContentEditableState::PlaintextOnly
|| node->document().design_mode_enabled_state();
}
// https://w3c.github.io/editing/docs/execCommand/#element-with-inline-contents
bool is_element_with_inline_contents(GC::Ref<DOM::Node> node)
{