mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb: Clean up some editing-related code
No functional changes.
This commit is contained in:
parent
dd83634121
commit
3931c0336b
Notes:
github-actions[bot]
2025-09-03 22:26:06 +00:00
Author: https://github.com/gmta
Commit: 3931c0336b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6060
3 changed files with 11 additions and 12 deletions
|
@ -1537,7 +1537,8 @@ bool Node::is_editable() const
|
|||
return false;
|
||||
|
||||
// it does not have a contenteditable attribute set to the false state;
|
||||
if (is<HTML::HTMLElement>(this) && static_cast<HTML::HTMLElement const&>(*this).content_editable_state() == HTML::ContentEditableState::False)
|
||||
auto const* html_element = as_if<HTML::HTMLElement>(*this);
|
||||
if (html_element && html_element->content_editable_state() == HTML::ContentEditableState::False)
|
||||
return false;
|
||||
|
||||
// its parent is an editing host or editable;
|
||||
|
@ -1551,7 +1552,7 @@ bool Node::is_editable() const
|
|||
return false;
|
||||
|
||||
// and either it is an HTML element,
|
||||
if (is<HTML::HTMLElement>(this))
|
||||
if (html_element)
|
||||
return true;
|
||||
|
||||
// or it is an svg or math element,
|
||||
|
@ -1566,17 +1567,18 @@ bool Node::is_editable() const
|
|||
bool Node::is_editing_host() const
|
||||
{
|
||||
// NOTE: Both conditions below require this to be an HTML element.
|
||||
if (!is<HTML::HTMLElement>(this))
|
||||
auto const* html_element = as_if<HTML::HTMLElement>(*this);
|
||||
if (!html_element)
|
||||
return false;
|
||||
|
||||
// An editing host is either an HTML element with its contenteditable attribute in the true state or
|
||||
// plaintext-only state,
|
||||
auto state = static_cast<HTML::HTMLElement const&>(*this).content_editable_state();
|
||||
auto state = html_element->content_editable_state();
|
||||
if (state == HTML::ContentEditableState::True || state == HTML::ContentEditableState::PlaintextOnly)
|
||||
return true;
|
||||
|
||||
// or a child HTML element of a Document whose design mode enabled is true.
|
||||
return is<Document>(parent()) && static_cast<Document const&>(*parent()).design_mode_enabled_state();
|
||||
return is<Document>(parent()) && as<Document>(*parent()).design_mode_enabled_state();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#editing-host-of
|
||||
|
|
|
@ -383,7 +383,7 @@ bool command_delete_action(DOM::Document& document, Utf16String const&)
|
|||
// is an hr, or the child is a br whose previousSibling is either a br or not an inline
|
||||
// node:
|
||||
if (offset == 0 && is<DOM::Element>(offset_minus_one_child.ptr())) {
|
||||
auto& child_element = static_cast<DOM::Element&>(*offset_minus_one_child);
|
||||
auto& child_element = as<DOM::Element>(*offset_minus_one_child);
|
||||
auto* previous_sibling = child_element.previous_sibling();
|
||||
if (is<HTML::HTMLHRElement>(child_element)
|
||||
|| (is<HTML::HTMLBRElement>(child_element) && previous_sibling && (is<HTML::HTMLBRElement>(*previous_sibling) || !is_inline_node(*previous_sibling)))) {
|
||||
|
@ -1477,7 +1477,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16String const&
|
|||
// or "div":
|
||||
if (container->is_editable() && is_single_line_container(*container) && is_in_same_editing_host(*container, *node)
|
||||
&& is<DOM::Element>(*container)
|
||||
&& static_cast<DOM::Element&>(*container).local_name().is_one_of(HTML::TagNames::p, HTML::TagNames::div)) {
|
||||
&& as<DOM::Element>(*container).local_name().is_one_of(HTML::TagNames::p, HTML::TagNames::div)) {
|
||||
// 1. Let outer container equal container.
|
||||
auto outer_container = container;
|
||||
|
||||
|
@ -1486,7 +1486,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16String const&
|
|||
auto is_li_dt_or_dd = [](DOM::Element const& node) {
|
||||
return node.local_name().is_one_of(HTML::TagNames::li, HTML::TagNames::dt, HTML::TagNames::dd);
|
||||
};
|
||||
while (!is<DOM::Element>(*outer_container) || !is_li_dt_or_dd(static_cast<DOM::Element&>(*outer_container))) {
|
||||
while (!is<DOM::Element>(*outer_container) || !is_li_dt_or_dd(as<DOM::Element>(*outer_container))) {
|
||||
auto outer_container_parent = outer_container->parent();
|
||||
if (!outer_container_parent->is_editable())
|
||||
break;
|
||||
|
@ -1494,7 +1494,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16String const&
|
|||
}
|
||||
|
||||
// 3. If outer container is a dd or dt or li, set container to outer container.
|
||||
if (is<DOM::Element>(*outer_container) && is_li_dt_or_dd(static_cast<DOM::Element&>(*outer_container)))
|
||||
if (is<DOM::Element>(*outer_container) && is_li_dt_or_dd(as<DOM::Element>(*outer_container)))
|
||||
container = outer_container;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <LibGfx/Color.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||
|
@ -35,9 +34,7 @@
|
|||
#include <LibWeb/HTML/HTMLTableSectionElement.h>
|
||||
#include <LibWeb/HTML/HTMLUListElement.h>
|
||||
#include <LibWeb/Infra/CharacterTypes.h>
|
||||
#include <LibWeb/Layout/BreakNode.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Namespace.h>
|
||||
#include <LibWeb/Painting/TextPaintable.h>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue