From 9b446df7f55f1bb75ebde53d9af63cf866a1f960 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 4 Dec 2024 00:18:06 +0100 Subject: [PATCH] LibWeb: Replace local name checks with simpler `is` in editing API --- Libraries/LibWeb/Editing/Commands.cpp | 9 +++++---- Libraries/LibWeb/Editing/Internal/Algorithms.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp index 2136e3911b7..4348d1ef1d2 100644 --- a/Libraries/LibWeb/Editing/Commands.cpp +++ b/Libraries/LibWeb/Editing/Commands.cpp @@ -15,7 +15,9 @@ #include #include #include +#include #include +#include #include #include @@ -152,9 +154,8 @@ bool command_delete_action(DOM::Document& document, String const&) auto items = Vector>(); GC::Ptr ancestor = node->parent(); while (ancestor) { - auto& ancestor_element = static_cast(*ancestor); - if (ancestor_element.local_name() == HTML::TagNames::li) - items.append(ancestor_element); + if (is(*ancestor)) + items.append(static_cast(*ancestor)); ancestor = ancestor->parent(); } @@ -264,7 +265,7 @@ bool command_delete_action(DOM::Document& document, String const&) if (offset == 0 && is(offset_minus_one_child.ptr())) { auto& child_element = static_cast(*offset_minus_one_child); auto* previous_sibling = child_element.previous_sibling(); - if (child_element.local_name() == HTML::TagNames::hr + if (is(child_element) || (is(child_element) && previous_sibling && (is(*previous_sibling) || !is_inline_node(*previous_sibling)))) { // 1. Call collapse(start node, start offset − 1) on the context object's selection. MUST(selection.collapse(start_node, start_offset - 1)); diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index 0b11a5e3709..b7473b78b6e 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -13,9 +13,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -632,7 +634,7 @@ bool is_allowed_child_of_node(Variant, FlyString> child, Vari if (child_local_name == HTML::TagNames::a) { DOM::Node* ancestor = &parent_html_element; while (ancestor) { - if (is(ancestor) && static_cast(*ancestor).local_name() == HTML::TagNames::a) + if (is(*ancestor)) return false; ancestor = ancestor->parent(); } @@ -940,8 +942,8 @@ bool is_extraneous_line_break(GC::Ref node) return false; // ...except that a br that is the sole child of an li is not extraneous. - auto parent = node->parent(); - if (parent && static_cast(*parent).local_name() == HTML::TagNames::li && parent->child_count() == 1) + GC::Ptr parent = node->parent(); + if (is(parent.ptr()) && parent->child_count() == 1) return false; // FIXME: ...that has no visual effect, in that removing it from the DOM