mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
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.
This commit is contained in:
parent
785ace4fc2
commit
3dc6f0bc47
2 changed files with 28 additions and 8 deletions
|
@ -818,13 +818,12 @@ void StyleResolver::absolutize_values(StyleProperties& style, DOM::Element const
|
||||||
float root_font_size = 10;
|
float root_font_size = 10;
|
||||||
|
|
||||||
for (auto& it : style.properties()) {
|
for (auto& it : style.properties()) {
|
||||||
if (!it.value->is_length())
|
it.value->visit_lengths([&](Length& length) {
|
||||||
continue;
|
if (length.is_absolute() || length.is_relative()) {
|
||||||
auto length = it.value->to_length();
|
auto px = length.to_px(viewport_rect, font_metrics, root_font_size);
|
||||||
if (length.is_relative()) {
|
length = Length::make_px(px);
|
||||||
auto px = length.relative_length_to_px(viewport_rect, font_metrics, root_font_size);
|
|
||||||
it.value = LengthStyleValue::create(CSS::Length::make_px(px));
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Function.h>
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/NonnullOwnPtrVector.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <AK/NonnullRefPtrVector.h>
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
|
@ -357,6 +358,8 @@ public:
|
||||||
return to_string() == other.to_string();
|
return to_string() == other.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void visit_lengths(Function<void(CSS::Length&)>) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit StyleValue(Type);
|
explicit StyleValue(Type);
|
||||||
|
|
||||||
|
@ -514,12 +517,18 @@ private:
|
||||||
m_is_elliptical = (m_horizontal_radius != m_vertical_radius);
|
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;
|
bool m_is_elliptical;
|
||||||
Length m_horizontal_radius;
|
Length m_horizontal_radius;
|
||||||
Length m_vertical_radius;
|
Length m_vertical_radius;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BoxShadowStyleValue : public StyleValue {
|
class BoxShadowStyleValue final : public StyleValue {
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<BoxShadowStyleValue> create(Length const& offset_x, Length const& offset_y, Length const& blur_radius, Color const& color)
|
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_x;
|
||||||
Length m_offset_y;
|
Length m_offset_y;
|
||||||
Length m_blur_radius;
|
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;
|
Length m_length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue