summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-09-23 20:15:26 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-24 15:12:15 +0200
commit3dc6f0bc4718f5f54f2d18119a0f9fe457c283a8 (patch)
tree42f5363163a77ba608bde726d8892157f3b9cca9 /Userland/Libraries
parent785ace4fc20834bf65908cb66acbc2815382ab62 (diff)
downloadserenity-3dc6f0bc4718f5f54f2d18119a0f9fe457c283a8.zip
LibWeb: Absolutize internal lengths in all StyleValues
StyleValue now has a virtual visit_lengths() that allows us to update all CSS lengths during the absolutization phase.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleResolver.cpp13
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h23
2 files changed, 28 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp b/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
index ccbee28a94..5c7217f6b4 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleResolver.cpp
@@ -818,13 +818,12 @@ void StyleResolver::absolutize_values(StyleProperties& style, DOM::Element const
float root_font_size = 10;
for (auto& it : style.properties()) {
- if (!it.value->is_length())
- continue;
- auto length = it.value->to_length();
- if (length.is_relative()) {
- auto px = length.relative_length_to_px(viewport_rect, font_metrics, root_font_size);
- it.value = LengthStyleValue::create(CSS::Length::make_px(px));
- }
+ it.value->visit_lengths([&](Length& length) {
+ if (length.is_absolute() || length.is_relative()) {
+ auto px = length.to_px(viewport_rect, font_metrics, root_font_size);
+ length = Length::make_px(px);
+ }
+ });
}
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 9433e8df86..0e275546f0 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -8,6 +8,7 @@
#pragma once
+#include <AK/Function.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/NonnullRefPtrVector.h>
@@ -357,6 +358,8 @@ public:
return to_string() == other.to_string();
}
+ virtual void visit_lengths(Function<void(CSS::Length&)>) { }
+
protected:
explicit StyleValue(Type);
@@ -514,12 +517,18 @@ private:
m_is_elliptical = (m_horizontal_radius != m_vertical_radius);
}
+ virtual void visit_lengths(Function<void(CSS::Length&)> visitor) override
+ {
+ visitor(m_horizontal_radius);
+ visitor(m_vertical_radius);
+ }
+
bool m_is_elliptical;
Length m_horizontal_radius;
Length m_vertical_radius;
};
-class BoxShadowStyleValue : public StyleValue {
+class BoxShadowStyleValue final : public StyleValue {
public:
static NonnullRefPtr<BoxShadowStyleValue> create(Length const& offset_x, Length const& offset_y, Length const& blur_radius, Color const& color)
{
@@ -545,6 +554,13 @@ private:
{
}
+ virtual void visit_lengths(Function<void(CSS::Length&)> visitor) override
+ {
+ visitor(m_offset_x);
+ visitor(m_offset_y);
+ visitor(m_blur_radius);
+ }
+
Length m_offset_x;
Length m_offset_y;
Length m_blur_radius;
@@ -964,6 +980,11 @@ private:
{
}
+ virtual void visit_lengths(Function<void(CSS::Length&)> visitor) override
+ {
+ visitor(m_length);
+ }
+
Length m_length;
};