@@ -972,7 +972,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
972972 return camel_case_string_from_property_id (a) < camel_case_string_from_property_id (b);
973973 };
974974
975- compute_font (computed_properties, & element, pseudo_element);
975+ compute_font (computed_properties, DOM::AbstractElement { element, pseudo_element } );
976976 compute_property_values (computed_properties);
977977 Length::FontMetrics font_metrics {
978978 computed_properties.font_size (),
@@ -1760,22 +1760,23 @@ CSSPixelFraction StyleComputer::absolute_size_mapping(Keyword keyword)
17601760 }
17611761}
17621762
1763- RefPtr<Gfx::FontCascadeList const > StyleComputer::compute_font_for_style_values (DOM::Element const * element, Optional<CSS::PseudoElement> pseudo_element , StyleValue const & font_family, StyleValue const & font_size, StyleValue const & font_style, StyleValue const & font_weight, StyleValue const & font_stretch, int math_depth) const
1763+ RefPtr<Gfx::FontCascadeList const > StyleComputer::compute_font_for_style_values (Optional<DOM::AbstractElement> abstract_element , StyleValue const & font_family, StyleValue const & font_size, StyleValue const & font_style, StyleValue const & font_weight, StyleValue const & font_stretch, int math_depth) const
17641764{
1765- auto parent_element = element ? element->element_to_inherit_style_from (pseudo_element) : nullptr ;
1765+ auto parent_element = abstract_element.has_value () ? abstract_element->element_to_inherit_style_from () : OptionalNone {};
1766+ GC::Ptr element = abstract_element.has_value () ? &abstract_element->element () : nullptr ;
17661767
17671768 auto width = font_stretch.to_font_width ();
17681769 auto weight = font_weight.to_font_weight ();
17691770
17701771 auto font_size_in_px = default_user_font_size ();
17711772
17721773 Gfx::FontPixelMetrics font_pixel_metrics;
1773- if (parent_element && parent_element->computed_properties ())
1774+ if (parent_element. has_value () && parent_element->computed_properties ())
17741775 font_pixel_metrics = parent_element->computed_properties ()->first_available_computed_font ().pixel_metrics ();
17751776 else
17761777 font_pixel_metrics = Platform::FontPlugin::the ().default_font (font_size_in_px.to_float ())->pixel_metrics ();
17771778 auto parent_font_size = [&]() -> CSSPixels {
1778- if (!parent_element || !parent_element->computed_properties ())
1779+ if (!parent_element. has_value () || !parent_element->computed_properties ())
17791780 return font_size_in_px;
17801781 auto const & value = parent_element->computed_properties ()->property (CSS::PropertyID::FontSize);
17811782 if (value.is_length ()) {
@@ -1797,7 +1798,7 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
17971798 // If the specified value font-size is math then the computed value of font-size is obtained by multiplying
17981799 // the inherited value of font-size by a nonzero scale factor calculated by the following procedure:
17991800 // 1. Let A be the inherited math-depth value, B the computed math-depth value, C be 0.71 and S be 1.0
1800- int inherited_math_depth = parent_element && parent_element->computed_properties ()
1801+ int inherited_math_depth = parent_element. has_value () && parent_element->computed_properties ()
18011802 ? parent_element->computed_properties ()->math_depth ()
18021803 : InitialValues::math_depth ();
18031804 int computed_math_depth = math_depth;
@@ -1837,7 +1838,7 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
18371838 // larger may compute the font size to the next entry in the table,
18381839 // and smaller may compute the font size to the previous entry in the table.
18391840 if (keyword == Keyword::Smaller || keyword == Keyword::Larger) {
1840- if (parent_element && parent_element->computed_properties ()) {
1841+ if (parent_element. has_value () && parent_element->computed_properties ()) {
18411842 font_size_in_px = CSSPixels::nearest_value_for (parent_element->computed_properties ()->first_available_computed_font ().pixel_metrics ().size );
18421843 }
18431844 }
@@ -1984,15 +1985,15 @@ RefPtr<Gfx::FontCascadeList const> StyleComputer::compute_font_for_style_values(
19841985 return font_list;
19851986}
19861987
1987- void StyleComputer::compute_font (ComputedProperties& style, DOM::Element const * element, Optional<CSS::PseudoElement> pseudo_element ) const
1988+ void StyleComputer::compute_font (ComputedProperties& style, Optional<DOM::AbstractElement> abstract_element ) const
19881989{
19891990 auto const & font_family = style.property (CSS::PropertyID::FontFamily);
19901991 auto const & font_size = style.property (CSS::PropertyID::FontSize);
19911992 auto const & font_style = style.property (CSS::PropertyID::FontStyle);
19921993 auto const & font_weight = style.property (CSS::PropertyID::FontWeight);
19931994 auto const & font_width = style.property (CSS::PropertyID::FontWidth);
19941995
1995- auto font_list = compute_font_for_style_values (element, pseudo_element , font_family, font_size, font_style, font_weight, font_width, style.math_depth ());
1996+ auto font_list = compute_font_for_style_values (abstract_element , font_family, font_size, font_style, font_weight, font_width, style.math_depth ());
19961997 VERIFY (font_list);
19971998 VERIFY (!font_list->is_empty ());
19981999
@@ -2009,7 +2010,7 @@ void StyleComputer::compute_font(ComputedProperties& style, DOM::Element const*
20092010
20102011 style.set_computed_font_list (*font_list);
20112012
2012- if (element && is<HTML::HTMLHtmlElement>(* element)) {
2013+ if (abstract_element. has_value () && is<HTML::HTMLHtmlElement>(abstract_element-> element () )) {
20132014 const_cast <StyleComputer&>(*this ).m_root_element_font_metrics = calculate_root_element_font_metrics (style);
20142015 }
20152016}
@@ -2322,7 +2323,7 @@ GC::Ref<ComputedProperties> StyleComputer::create_document_style() const
23222323 }
23232324
23242325 compute_math_depth (style, {});
2325- compute_font (style, nullptr , {});
2326+ compute_font (style, {});
23262327 compute_property_values (style);
23272328 style->set_property (CSS::PropertyID::Width, CSS::LengthStyleValue::create (CSS::Length::make_px (viewport_rect ().width ())));
23282329 style->set_property (CSS::PropertyID::Height, CSS::LengthStyleValue::create (CSS::Length::make_px (viewport_rect ().height ())));
@@ -2439,10 +2440,7 @@ static bool is_monospace(StyleValue const& value)
24392440// instead of the default font size (16px).
24402441// See this blog post for a lot more details about this weirdness:
24412442// https://manishearth.github.io/blog/2017/08/10/font-size-an-unexpectedly-complex-css-property/
2442- RefPtr<StyleValue const > StyleComputer::recascade_font_size_if_needed (
2443- DOM::Element& element,
2444- Optional<CSS::PseudoElement> pseudo_element,
2445- CascadedProperties& cascaded_properties) const
2443+ RefPtr<StyleValue const > StyleComputer::recascade_font_size_if_needed (DOM::AbstractElement abstract_element, CascadedProperties& cascaded_properties) const
24462444{
24472445 // Check for `font-family: monospace`. Note that `font-family: monospace, AnythingElse` does not trigger this path.
24482446 // Some CSS frameworks use `font-family: monospace, monospace` to work around this behavior.
@@ -2457,17 +2455,15 @@ RefPtr<StyleValue const> StyleComputer::recascade_font_size_if_needed(
24572455
24582456 // Reconstruct the line of ancestor elements we need to inherit style from, and then do the cascade again
24592457 // but only for the font-size property.
2460- Vector<DOM::Element const &> ancestors;
2461- if (pseudo_element.has_value ())
2462- ancestors.append (element);
2463- for (auto ancestor = element.element_to_inherit_style_from (pseudo_element); ancestor; ancestor = ancestor->element_to_inherit_style_from ({}))
2458+ Vector<DOM::AbstractElement> ancestors;
2459+ for (auto ancestor = abstract_element.element_to_inherit_style_from (); ancestor.has_value (); ancestor = ancestor->element_to_inherit_style_from ())
24642460 ancestors.append (*ancestor);
24652461
24662462 NonnullRefPtr<StyleValue const > new_font_size = CSS::LengthStyleValue::create (CSS::Length::make_px (default_monospace_font_size_in_px));
24672463 CSSPixels current_size_in_px = default_monospace_font_size_in_px;
24682464
24692465 for (auto & ancestor : ancestors.in_reverse ()) {
2470- auto & ancestor_cascaded_properties = *ancestor.cascaded_properties ({} );
2466+ auto & ancestor_cascaded_properties = *ancestor.cascaded_properties ();
24712467 auto font_size_value = ancestor_cascaded_properties.property (CSS::PropertyID::FontSize);
24722468
24732469 if (!font_size_value)
@@ -2508,7 +2504,7 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::Element& elem
25082504 DOM::AbstractElement abstract_element { element, pseudo_element };
25092505 auto computed_style = document ().heap ().allocate <CSS::ComputedProperties>();
25102506
2511- auto new_font_size = recascade_font_size_if_needed (element, pseudo_element , cascaded_properties);
2507+ auto new_font_size = recascade_font_size_if_needed (abstract_element , cascaded_properties);
25122508 if (new_font_size)
25132509 computed_style->set_property (PropertyID::FontSize, *new_font_size, ComputedProperties::Inherited::No, Important::No);
25142510
@@ -2630,7 +2626,7 @@ GC::Ref<ComputedProperties> StyleComputer::compute_properties(DOM::Element& elem
26302626 compute_math_depth (computed_style, abstract_element);
26312627
26322628 // 3. Compute the font, since that may be needed for font-relative CSS units
2633- compute_font (computed_style, & element, pseudo_element);
2629+ compute_font (computed_style, DOM::AbstractElement { element, pseudo_element } );
26342630
26352631 // 4. Convert properties into their computed forms
26362632 compute_property_values (computed_style);
0 commit comments