1111#include < LibGC/CellAllocator.h>
1212#include < LibWeb/CSS/Clip.h>
1313#include < LibWeb/CSS/ComputedProperties.h>
14+ #include < LibWeb/CSS/FontComputer.h>
1415#include < LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h>
1516#include < LibWeb/CSS/StyleValues/ContentStyleValue.h>
1617#include < LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
@@ -142,11 +143,19 @@ void ComputedProperties::set_property(PropertyID id, NonnullRefPtr<StyleValue co
142143 set_property_inherited (id, inherited);
143144}
144145
146+ static bool property_affects_computed_font_list (PropertyID id)
147+ {
148+ return first_is_one_of (id, PropertyID::FontFamily, PropertyID::FontSize, PropertyID::FontStyle, PropertyID::FontWeight, PropertyID::FontWidth, PropertyID::FontVariationSettings);
149+ }
150+
145151void ComputedProperties::set_property_without_modifying_flags (PropertyID id, NonnullRefPtr<StyleValue const > value)
146152{
147153 VERIFY (id >= first_longhand_property_id && id <= last_longhand_property_id);
148154
149155 m_property_values[to_underlying (id) - to_underlying (first_longhand_property_id)] = move (value);
156+
157+ if (property_affects_computed_font_list (id))
158+ clear_computed_font_list_cache ();
150159}
151160
152161void ComputedProperties::revert_property (PropertyID id, ComputedProperties const & style_for_revert)
@@ -173,6 +182,9 @@ void ComputedProperties::set_animated_property(PropertyID id, NonnullRefPtr<Styl
173182 m_animated_property_values.set (id, move (value));
174183 set_animated_property_inherited (id, inherited);
175184 set_animated_property_result_of_transition (id, animated_property_result_of_transition);
185+
186+ if (property_affects_computed_font_list (id))
187+ clear_computed_font_list_cache ();
176188}
177189
178190void ComputedProperties::remove_animated_property (PropertyID id)
@@ -198,7 +210,7 @@ StyleValue const& ComputedProperties::property(PropertyID property_id, WithAnima
198210 return *animated_value.value ();
199211 }
200212
201- // By the time we call this method, all properties have values assigned.
213+ // By the time we call this method, the property should have been assigned
202214 return *m_property_values[to_underlying (property_id) - to_underlying (first_longhand_property_id)];
203215}
204216
@@ -2543,6 +2555,27 @@ WillChange ComputedProperties::will_change() const
25432555 return WillChange (move (will_change_entries));
25442556}
25452557
2558+ ValueComparingNonnullRefPtr<Gfx::FontCascadeList const > ComputedProperties::computed_font_list (FontComputer const & font_computer) const
2559+ {
2560+ if (!m_cached_computed_font_list) {
2561+ const_cast <ComputedProperties*>(this )->m_cached_computed_font_list = font_computer.compute_font_for_style_values (property (PropertyID::FontFamily), font_size (), font_slope (), font_weight (), font_width (), font_variation_settings ());
2562+ VERIFY (!m_cached_computed_font_list->is_empty ());
2563+ }
2564+
2565+ return *m_cached_computed_font_list;
2566+ }
2567+
2568+ ValueComparingNonnullRefPtr<Gfx::Font const > ComputedProperties::first_available_computed_font (FontComputer const & font_computer) const
2569+ {
2570+ if (!m_cached_first_available_computed_font) {
2571+ // https://drafts.csswg.org/css-fonts/#first-available-font
2572+ // First font for which the character U+0020 (space) is not excluded by a unicode-range
2573+ const_cast <ComputedProperties*>(this )->m_cached_first_available_computed_font = computed_font_list (font_computer)->font_for_code_point (' ' );
2574+ }
2575+
2576+ return *m_cached_first_available_computed_font;
2577+ }
2578+
25462579CSSPixels ComputedProperties::font_size () const
25472580{
25482581 return property (PropertyID::FontSize).as_length ().length ().absolute_length_to_px ();
0 commit comments