From 4679dbc9dfe522a0ffc83cf2a74264053899fcbd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 18 Mar 2024 20:06:36 +0100 Subject: [PATCH] LibWeb: Make Element::inline_style() return specific declaration type This removes a bunch of RTTI checks in StyleComputer. --- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 6 +++--- Userland/Libraries/LibWeb/DOM/Element.cpp | 5 ----- Userland/Libraries/LibWeb/DOM/Element.h | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 7e95665eeff..ca9623b4a0d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -742,7 +742,7 @@ void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& e } if (cascade_origin == CascadeOrigin::Author && !pseudo_element.has_value()) { - if (auto const* inline_style = verify_cast(element.inline_style())) { + if (auto const inline_style = element.inline_style()) { for (auto const& property : inline_style->properties()) { if (important != property.important) continue; @@ -769,7 +769,7 @@ static void cascade_custom_properties(DOM::Element& element, Optional(matching_rule.rule->declaration()).custom_properties().size(); if (!pseudo_element.has_value()) { - if (auto const* inline_style = verify_cast(element.inline_style())) + if (auto const inline_style = element.inline_style()) needed_capacity += inline_style->custom_properties().size(); } @@ -782,7 +782,7 @@ static void cascade_custom_properties(DOM::Element& element, Optional(element.inline_style())) { + if (auto const inline_style = element.inline_style()) { for (auto const& it : inline_style->custom_properties()) custom_properties.set(it.key, it.value); } diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 9e46d027813..a6cc5269d7a 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -443,11 +443,6 @@ JS::GCPtr Element::create_layout_node_for_display_type(DOM::Docume return document.heap().allocate_without_realm(document, element, move(style)); } -CSS::CSSStyleDeclaration const* Element::inline_style() const -{ - return m_inline_style.ptr(); -} - void Element::run_attribute_change_steps(FlyString const& local_name, Optional const& old_value, Optional const& value, Optional const& namespace_) { attribute_change_steps(local_name, old_value, value, namespace_); diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index e70eecd04e5..b63c6a5e8d8 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -183,7 +183,7 @@ public: void reset_animated_css_properties(); - CSS::CSSStyleDeclaration const* inline_style() const; + JS::GCPtr inline_style() const { return m_inline_style; } CSS::CSSStyleDeclaration* style_for_bindings();