From 7eee3f6952ca38d0477c9750f0ab508ac8a13547 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 12 Sep 2023 12:02:16 +0200 Subject: [PATCH] LibWeb: Add `mutable_computed_values()` for `NodeWithStyle` This fixes the issue that we previously had to use a gross static_cast whenever we wanted to mutate computed values outside of the Node methods. --- Userland/Libraries/LibWeb/DOM/Document.cpp | 6 +++--- Userland/Libraries/LibWeb/Layout/Node.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 6a846bac2a..f3e6a72967 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -927,7 +927,7 @@ static void propagate_overflow_to_viewport(Element& root_element, Layout::Viewpo // UAs must apply the overflow-* values set on the root element to the viewport // when the root element’s display value is not none. auto* overflow_origin_node = root_element.layout_node(); - auto& viewport_computed_values = const_cast(static_cast(static_cast(viewport.computed_values()))); + auto& viewport_computed_values = viewport.mutable_computed_values(); // However, when the root element is an [HTML] html element (including XML syntax for HTML) // whose overflow value is visible (in both axes), and that element has as a child @@ -935,7 +935,7 @@ static void propagate_overflow_to_viewport(Element& root_element, Layout::Viewpo // user agents must instead apply the overflow-* values of the first such child element to the viewport. if (root_element.is_html_html_element()) { auto* root_element_layout_node = root_element.layout_node(); - auto& root_element_computed_values = const_cast(static_cast(static_cast(root_element_layout_node->computed_values()))); + auto& root_element_computed_values = root_element_layout_node->mutable_computed_values(); if (root_element_computed_values.overflow_x() == CSS::Overflow::Visible && root_element_computed_values.overflow_y() == CSS::Overflow::Visible) { auto* body_element = root_element.first_child_of_type(); if (body_element && body_element->layout_node()) @@ -944,7 +944,7 @@ static void propagate_overflow_to_viewport(Element& root_element, Layout::Viewpo } // NOTE: This is where we assign the chosen overflow values to the viewport. - auto& overflow_origin_computed_values = const_cast(static_cast(static_cast(overflow_origin_node->computed_values()))); + auto& overflow_origin_computed_values = overflow_origin_node->mutable_computed_values(); viewport_computed_values.set_overflow_x(overflow_origin_computed_values.overflow_x()); viewport_computed_values.set_overflow_y(overflow_origin_computed_values.overflow_y()); diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 62c40ef642..42bc4ab6ea 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -209,6 +209,7 @@ public: virtual ~NodeWithStyle() override = default; const CSS::ImmutableComputedValues& computed_values() const { return static_cast(m_computed_values); } + CSS::MutableComputedValues& mutable_computed_values() { return static_cast(m_computed_values); } void apply_style(const CSS::StyleProperties&);