Skip to content

Commit 823dd11

Browse files
Calme1709AtkinsSJ
authored andcommitted
LibWeb: Add ComputedProperties::set_property_without_modifying_flags
There are a few places in style computation where we want to update the value of a property without modifying the inherited or important flags. Previously we would look up these flags and pass them to the normal `set_property` method but this is unnecessary and was easy to forget to do.
1 parent 8476202 commit 823dd11

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

Libraries/LibWeb/CSS/ComputedProperties.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,18 @@ void ComputedProperties::set_property(PropertyID id, NonnullRefPtr<StyleValue co
118118
{
119119
VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id);
120120

121-
m_property_values[to_underlying(id) - to_underlying(first_longhand_property_id)] = move(value);
121+
set_property_without_modifying_flags(id, move(value));
122122
set_property_important(id, important);
123123
set_property_inherited(id, inherited);
124124
}
125125

126+
void ComputedProperties::set_property_without_modifying_flags(PropertyID id, NonnullRefPtr<StyleValue const> value)
127+
{
128+
VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id);
129+
130+
m_property_values[to_underlying(id) - to_underlying(first_longhand_property_id)] = move(value);
131+
}
132+
126133
void ComputedProperties::revert_property(PropertyID id, ComputedProperties const& style_for_revert)
127134
{
128135
VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id);

Libraries/LibWeb/CSS/ComputedProperties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class WEB_API ComputedProperties final : public JS::Cell {
6060
void set_animated_property_inherited(PropertyID, Inherited);
6161

6262
void set_property(PropertyID, NonnullRefPtr<StyleValue const> value, Inherited = Inherited::No, Important = Important::No);
63+
void set_property_without_modifying_flags(PropertyID, NonnullRefPtr<StyleValue const> value);
6364
void set_animated_property(PropertyID, NonnullRefPtr<StyleValue const> value, Inherited = Inherited::No);
6465
void remove_animated_property(PropertyID);
6566
enum class WithAnimationsApplied {

Libraries/LibWeb/CSS/StyleComputer.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,33 +1959,29 @@ void StyleComputer::compute_font(ComputedProperties& style, Optional<DOM::Abstra
19591959

19601960
auto const& font_size_specified_value = style.property(PropertyID::FontSize, ComputedProperties::WithAnimationsApplied::No);
19611961

1962-
style.set_property(
1962+
style.set_property_without_modifying_flags(
19631963
PropertyID::FontSize,
1964-
compute_font_size(font_size_specified_value, style.math_depth(), inherited_font_size, inherited_math_depth, font_computation_context),
1965-
style.is_property_inherited(PropertyID::FontSize) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
1964+
compute_font_size(font_size_specified_value, style.math_depth(), inherited_font_size, inherited_math_depth, font_computation_context));
19661965

19671966
auto inherited_font_weight = inheritance_parent_has_computed_properties ? inheritance_parent->computed_properties()->font_weight() : InitialValues::font_weight();
19681967

19691968
auto const& font_weight_specified_value = style.property(PropertyID::FontWeight, ComputedProperties::WithAnimationsApplied::No);
19701969

1971-
style.set_property(
1970+
style.set_property_without_modifying_flags(
19721971
PropertyID::FontWeight,
1973-
compute_font_weight(font_weight_specified_value, inherited_font_weight, font_computation_context),
1974-
style.is_property_inherited(PropertyID::FontWeight) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
1972+
compute_font_weight(font_weight_specified_value, inherited_font_weight, font_computation_context));
19751973

19761974
auto const& font_width_specified_value = style.property(PropertyID::FontWidth, ComputedProperties::WithAnimationsApplied::No);
19771975

1978-
style.set_property(
1976+
style.set_property_without_modifying_flags(
19791977
PropertyID::FontWidth,
1980-
compute_font_width(font_width_specified_value, font_computation_context),
1981-
style.is_property_inherited(PropertyID::FontWidth) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
1978+
compute_font_width(font_width_specified_value, font_computation_context));
19821979

19831980
auto const& font_style_specified_value = style.property(PropertyID::FontStyle, ComputedProperties::WithAnimationsApplied::No);
19841981

1985-
style.set_property(
1982+
style.set_property_without_modifying_flags(
19861983
PropertyID::FontStyle,
1987-
compute_font_style(font_style_specified_value, font_computation_context),
1988-
style.is_property_inherited(PropertyID::FontStyle) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
1984+
compute_font_style(font_style_specified_value, font_computation_context));
19891985

19901986
auto const& font_family = style.property(CSS::PropertyID::FontFamily);
19911987

@@ -2014,10 +2010,9 @@ void StyleComputer::compute_font(ComputedProperties& style, Optional<DOM::Abstra
20142010

20152011
auto const& line_height_specified_value = style.property(CSS::PropertyID::LineHeight, ComputedProperties::WithAnimationsApplied::No);
20162012

2017-
style.set_property(
2013+
style.set_property_without_modifying_flags(
20182014
PropertyID::LineHeight,
2019-
compute_line_height(line_height_specified_value, line_height_computation_context),
2020-
style.is_property_inherited(PropertyID::LineHeight) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
2015+
compute_line_height(line_height_specified_value, line_height_computation_context));
20212016

20222017
if (abstract_element.has_value() && is<HTML::HTMLHtmlElement>(abstract_element->element())) {
20232018
const_cast<StyleComputer&>(*this).m_root_element_font_metrics = calculate_root_element_font_metrics(style);
@@ -2096,9 +2091,7 @@ void StyleComputer::compute_property_values(ComputedProperties& style, Optional<
20962091
style.for_each_property([&](PropertyID property_id, auto& specified_value) {
20972092
auto const& computed_value = compute_value_of_property(property_id, specified_value, get_property_specified_value, computation_context, m_document->page().client().device_pixels_per_css_pixel());
20982093

2099-
auto const& is_inherited = style.is_property_inherited(property_id) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No;
2100-
2101-
style.set_property(property_id, computed_value, is_inherited);
2094+
style.set_property_without_modifying_flags(property_id, computed_value);
21022095
});
21032096

21042097
style.set_display_before_box_type_transformation(style.display());

0 commit comments

Comments
 (0)