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>
@@ -47,6 +48,21 @@ namespace Web::CSS {
4748
4849GC_DEFINE_ALLOCATOR (ComputedProperties);
4950
51+ static HashTable<PropertyID> font_affecting_properties ()
52+ {
53+ static HashTable<PropertyID> font_affecting_properties;
54+ if (font_affecting_properties.is_empty ()) {
55+ font_affecting_properties.set (PropertyID::FontFamily);
56+ font_affecting_properties.set (PropertyID::FontSize);
57+ font_affecting_properties.set (PropertyID::FontStyle);
58+ font_affecting_properties.set (PropertyID::FontWeight);
59+ font_affecting_properties.set (PropertyID::FontWidth);
60+ font_affecting_properties.set (PropertyID::FontVariationSettings);
61+ }
62+
63+ return font_affecting_properties;
64+ }
65+
5066ComputedProperties::ComputedProperties () = default ;
5167
5268ComputedProperties::~ComputedProperties () = default ;
@@ -128,6 +144,9 @@ void ComputedProperties::set_property_without_modifying_flags(PropertyID id, Non
128144 VERIFY (id >= first_longhand_property_id && id <= last_longhand_property_id);
129145
130146 m_property_values[to_underlying (id) - to_underlying (first_longhand_property_id)] = move (value);
147+
148+ if (font_affecting_properties ().contains (id))
149+ clear_computed_font_list_cache ();
131150}
132151
133152void ComputedProperties::revert_property (PropertyID id, ComputedProperties const & style_for_revert)
@@ -153,6 +172,9 @@ void ComputedProperties::set_animated_property(PropertyID id, NonnullRefPtr<Styl
153172{
154173 m_animated_property_values.set (id, move (value));
155174 set_animated_property_inherited (id, inherited);
175+
176+ if (font_affecting_properties ().contains (id))
177+ clear_computed_font_list_cache ();
156178}
157179
158180void ComputedProperties::remove_animated_property (PropertyID id)
@@ -175,7 +197,7 @@ StyleValue const& ComputedProperties::property(PropertyID property_id, WithAnima
175197 return *animated_value.value ();
176198 }
177199
178- // By the time we call this method, all properties have values assigned.
200+ // By the time we call this method, the property should have been assigned
179201 return *m_property_values[to_underlying (property_id) - to_underlying (first_longhand_property_id)];
180202}
181203
@@ -2232,6 +2254,26 @@ WillChange ComputedProperties::will_change() const
22322254 return WillChange::make_auto ();
22332255}
22342256
2257+ ValueComparingNonnullRefPtr<Gfx::FontCascadeList const > ComputedProperties::computed_font_list (FontComputer const & font_computer) const
2258+ {
2259+ if (!m_cached_computed_font_list) {
2260+ 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 ());
2261+ VERIFY (!m_cached_computed_font_list->is_empty ());
2262+ }
2263+
2264+ return *m_cached_computed_font_list;
2265+ }
2266+
2267+ ValueComparingNonnullRefPtr<Gfx::Font const > ComputedProperties::first_available_computed_font (FontComputer const & font_computer) const
2268+ {
2269+ if (!m_cached_first_available_computed_font)
2270+ // https://drafts.csswg.org/css-fonts/#first-available-font
2271+ // First font for which the character U+0020 (space) is not excluded by a unicode-range
2272+ const_cast <ComputedProperties*>(this )->m_cached_first_available_computed_font = computed_font_list (font_computer)->font_for_code_point (' ' );
2273+
2274+ return *m_cached_first_available_computed_font;
2275+ }
2276+
22352277CSSPixels ComputedProperties::font_size () const
22362278{
22372279 return property (PropertyID::FontSize).as_length ().length ().absolute_length_to_px ();
0 commit comments