mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 09:18:55 +00:00
LibWeb: Don't store separate computed value for font_size
The StyleValue stored in m_property_values is already in it's computed form and it's trivial to pull the underlying value out so there is no need to store this separately. Also removes unnecessary handling of percentage values in `absolutize_values` - this is already handled within `compute_font`.
This commit is contained in:
parent
8682a97933
commit
1a3da3d825
Notes:
github-actions[bot]
2025-08-26 10:19:33 +00:00
Author: https://github.com/Calme1709
Commit: 1a3da3d825
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5984
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/gmta ✅
5 changed files with 14 additions and 23 deletions
|
@ -1977,4 +1977,9 @@ WillChange ComputedProperties::will_change() const
|
||||||
return WillChange::make_auto();
|
return WillChange::make_auto();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSSPixels ComputedProperties::font_size() const
|
||||||
|
{
|
||||||
|
return property(PropertyID::FontSize).as_length().length().absolute_length_to_px();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,8 +227,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] CSSPixels line_height() const { return *m_line_height; }
|
[[nodiscard]] CSSPixels line_height() const { return *m_line_height; }
|
||||||
void set_line_height(Badge<StyleComputer> const&, CSSPixels line_height) { m_line_height = line_height; }
|
void set_line_height(Badge<StyleComputer> const&, CSSPixels line_height) { m_line_height = line_height; }
|
||||||
[[nodiscard]] CSSPixels font_size() const { return *m_font_size; }
|
[[nodiscard]] CSSPixels font_size() const;
|
||||||
void set_font_size(Badge<StyleComputer> const&, CSSPixels font_size) { m_font_size = font_size; }
|
|
||||||
|
|
||||||
bool operator==(ComputedProperties const&) const;
|
bool operator==(ComputedProperties const&) const;
|
||||||
|
|
||||||
|
@ -283,7 +282,6 @@ private:
|
||||||
RefPtr<Gfx::Font const> m_first_available_computed_font;
|
RefPtr<Gfx::Font const> m_first_available_computed_font;
|
||||||
|
|
||||||
Optional<CSSPixels> m_line_height;
|
Optional<CSSPixels> m_line_height;
|
||||||
Optional<CSSPixels> m_font_size;
|
|
||||||
|
|
||||||
PseudoClassBitmap m_attempted_pseudo_class_matches;
|
PseudoClassBitmap m_attempted_pseudo_class_matches;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1098,7 +1098,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
|
||||||
};
|
};
|
||||||
|
|
||||||
compute_font(computed_properties, &element, pseudo_element);
|
compute_font(computed_properties, &element, pseudo_element);
|
||||||
absolutize_values(computed_properties, element);
|
absolutize_values(computed_properties);
|
||||||
Length::FontMetrics font_metrics {
|
Length::FontMetrics font_metrics {
|
||||||
computed_properties.font_size(),
|
computed_properties.font_size(),
|
||||||
computed_properties.first_available_computed_font().pixel_metrics()
|
computed_properties.first_available_computed_font().pixel_metrics()
|
||||||
|
@ -2136,25 +2136,13 @@ Gfx::Font const& StyleComputer::initial_font() const
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyleComputer::absolutize_values(ComputedProperties& style, GC::Ptr<DOM::Element const> element) const
|
void StyleComputer::absolutize_values(ComputedProperties& style) const
|
||||||
{
|
{
|
||||||
Length::FontMetrics font_metrics {
|
Length::FontMetrics font_metrics {
|
||||||
root_element_font_metrics_for_element(element).font_size,
|
style.font_size(),
|
||||||
style.first_available_computed_font().pixel_metrics()
|
style.first_available_computed_font().pixel_metrics()
|
||||||
};
|
};
|
||||||
|
|
||||||
// "A percentage value specifies an absolute font size relative to the parent element’s computed font-size. Negative percentages are invalid."
|
|
||||||
auto& font_size_value_slot = style.m_property_values[to_underlying(CSS::PropertyID::FontSize)];
|
|
||||||
if (font_size_value_slot && font_size_value_slot->is_percentage()) {
|
|
||||||
auto parent_font_size = get_inherit_value(CSS::PropertyID::FontSize, element)->as_length().length().to_px(viewport_rect(), font_metrics, m_root_element_font_metrics);
|
|
||||||
font_size_value_slot = LengthStyleValue::create(
|
|
||||||
Length::make_px(CSSPixels::nearest_value_for(parent_font_size * font_size_value_slot->as_percentage().percentage().as_fraction())));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto font_size = font_size_value_slot->as_length().length().to_px(viewport_rect(), font_metrics, m_root_element_font_metrics);
|
|
||||||
font_metrics.font_size = font_size;
|
|
||||||
style.set_font_size({}, font_size);
|
|
||||||
|
|
||||||
// NOTE: Percentage line-height values are relative to the font-size of the element.
|
// NOTE: Percentage line-height values are relative to the font-size of the element.
|
||||||
// We have to resolve them right away, so that the *computed* line-height is ready for inheritance.
|
// We have to resolve them right away, so that the *computed* line-height is ready for inheritance.
|
||||||
// We can't simply absolutize *all* percentage values against the font size,
|
// We can't simply absolutize *all* percentage values against the font size,
|
||||||
|
@ -2162,7 +2150,7 @@ void StyleComputer::absolutize_values(ComputedProperties& style, GC::Ptr<DOM::El
|
||||||
auto& line_height_value_slot = style.m_property_values[to_underlying(CSS::PropertyID::LineHeight)];
|
auto& line_height_value_slot = style.m_property_values[to_underlying(CSS::PropertyID::LineHeight)];
|
||||||
if (line_height_value_slot && line_height_value_slot->is_percentage()) {
|
if (line_height_value_slot && line_height_value_slot->is_percentage()) {
|
||||||
line_height_value_slot = LengthStyleValue::create(
|
line_height_value_slot = LengthStyleValue::create(
|
||||||
Length::make_px(CSSPixels::nearest_value_for(font_size * static_cast<double>(line_height_value_slot->as_percentage().percentage().as_fraction()))));
|
Length::make_px(CSSPixels::nearest_value_for(style.font_size() * static_cast<double>(line_height_value_slot->as_percentage().percentage().as_fraction()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto line_height = style.compute_line_height(viewport_rect(), font_metrics, m_root_element_font_metrics);
|
auto line_height = style.compute_line_height(viewport_rect(), font_metrics, m_root_element_font_metrics);
|
||||||
|
@ -2396,7 +2384,7 @@ GC::Ref<ComputedProperties> StyleComputer::create_document_style() const
|
||||||
|
|
||||||
compute_math_depth(style, {});
|
compute_math_depth(style, {});
|
||||||
compute_font(style, nullptr, {});
|
compute_font(style, nullptr, {});
|
||||||
absolutize_values(style, nullptr);
|
absolutize_values(style);
|
||||||
style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().width())));
|
style->set_property(CSS::PropertyID::Width, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().width())));
|
||||||
style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().height())));
|
style->set_property(CSS::PropertyID::Height, CSS::LengthStyleValue::create(CSS::Length::make_px(viewport_rect().height())));
|
||||||
style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::Block)));
|
style->set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::Block)));
|
||||||
|
@ -2708,7 +2696,7 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::Element& elem
|
||||||
compute_font(computed_style, &element, pseudo_element);
|
compute_font(computed_style, &element, pseudo_element);
|
||||||
|
|
||||||
// 4. Absolutize values, turning font/viewport relative lengths into absolute lengths
|
// 4. Absolutize values, turning font/viewport relative lengths into absolute lengths
|
||||||
absolutize_values(computed_style, element);
|
absolutize_values(computed_style);
|
||||||
|
|
||||||
// 5. Run automatic box type transformations
|
// 5. Run automatic box type transformations
|
||||||
transform_box_type_if_needed(computed_style, element, pseudo_element);
|
transform_box_type_if_needed(computed_style, element, pseudo_element);
|
||||||
|
|
|
@ -193,7 +193,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] GC::Ref<ComputedProperties> compute_properties(DOM::Element&, Optional<PseudoElement>, CascadedProperties&) const;
|
[[nodiscard]] GC::Ref<ComputedProperties> compute_properties(DOM::Element&, Optional<PseudoElement>, CascadedProperties&) const;
|
||||||
|
|
||||||
void absolutize_values(ComputedProperties&, GC::Ptr<DOM::Element const>) const;
|
void absolutize_values(ComputedProperties&) const;
|
||||||
void compute_font(ComputedProperties&, DOM::Element const*, Optional<CSS::PseudoElement>) const;
|
void compute_font(ComputedProperties&, DOM::Element const*, Optional<CSS::PseudoElement>) const;
|
||||||
|
|
||||||
[[nodiscard]] inline bool should_reject_with_ancestor_filter(Selector const&) const;
|
[[nodiscard]] inline bool should_reject_with_ancestor_filter(Selector const&) const;
|
||||||
|
|
|
@ -839,7 +839,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style()
|
||||||
return invalidation;
|
return invalidation;
|
||||||
|
|
||||||
document().style_computer().compute_font(*computed_properties, this, {});
|
document().style_computer().compute_font(*computed_properties, this, {});
|
||||||
document().style_computer().absolutize_values(*computed_properties, this);
|
document().style_computer().absolutize_values(*computed_properties);
|
||||||
|
|
||||||
for (auto [property_id, old_value] : old_values_with_relative_units) {
|
for (auto [property_id, old_value] : old_values_with_relative_units) {
|
||||||
auto new_value = computed_properties->maybe_null_property(static_cast<CSS::PropertyID>(property_id));
|
auto new_value = computed_properties->maybe_null_property(static_cast<CSS::PropertyID>(property_id));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue