mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:18:11 +00:00
LibWeb: Make StyleValue absolutization non-destructive
Instead of awkwardly visiting and mutating lengths inside StyleValues, we now simply create a new StyleValue instead. This fixes an issue where inherited relative lengths could get absolutized using a parent as reference, and then not having the correct values when used in a child context.
This commit is contained in:
parent
1cdbd377e7
commit
c59ab7cc8b
3 changed files with 53 additions and 36 deletions
|
@ -909,17 +909,11 @@ void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const
|
|||
float root_font_size = 10;
|
||||
float font_size = style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(viewport_rect, font_metrics, root_font_size, root_font_size);
|
||||
|
||||
for (auto& value_slot : style.m_property_values) {
|
||||
for (size_t i = 0; i < style.m_property_values.size(); ++i) {
|
||||
auto& value_slot = style.m_property_values[i];
|
||||
if (!value_slot)
|
||||
continue;
|
||||
value_slot->visit_lengths([&](Length& length) {
|
||||
if (length.is_px())
|
||||
return;
|
||||
if (length.is_absolute() || length.is_relative()) {
|
||||
auto px = length.to_px(viewport_rect, font_metrics, font_size, root_font_size);
|
||||
length = Length::make_px(px);
|
||||
}
|
||||
});
|
||||
value_slot = value_slot->absolutized(viewport_rect, font_metrics, font_size, root_font_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue