summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-03-11 12:53:32 +0000
committerAndreas Kling <kling@serenityos.org>2022-03-11 15:53:35 +0100
commit332799fbcbd97f2be5ea9afef9d2f1cd3c2b090b (patch)
treee1a982190dfbbd08ab4b3362598e1a0f7a3f9049
parent870b835115bf9008a56a2a2eb6a95a6873701830 (diff)
downloadserenity-332799fbcbd97f2be5ea9afef9d2f1cd3c2b090b.zip
LibWeb: Stub getting the initial font instead of the root one
Previously this queried the root layout-node's font, which was both wrong and could crash if the layout wasn't ready yet. Now, it's just wrong. But at least all the font-related wrongness is grouped together in StyleComputer. :^)
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQuery.cpp15
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp6
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.h2
3 files changed, 14 insertions, 9 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
index 8d8346bb50..e358ece64c 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
+++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
@@ -159,15 +159,12 @@ bool MediaFeature::compare(HTML::Window const& window, MediaFeatureValue left, C
} else {
Gfx::IntRect viewport_rect { 0, 0, window.inner_width(), window.inner_height() };
- // FIXME: This isn't right - we want to query the initial-value font, which is the one used
- // if no author styles are defined.
- auto& root_layout_node = *window.associated_document().root().layout_node();
- auto const& font = root_layout_node.font();
- Gfx::FontMetrics const& font_metrics = font.metrics('M');
- float root_font_size = root_layout_node.computed_values().font_size();
-
- left_px = left.length().to_px(viewport_rect, font_metrics, root_font_size, root_font_size);
- right_px = right.length().to_px(viewport_rect, font_metrics, root_font_size, root_font_size);
+ auto const& initial_font = window.associated_document().style_computer().initial_font();
+ Gfx::FontMetrics const& initial_font_metrics = initial_font.metrics('M');
+ float initial_font_size = initial_font.presentation_size();
+
+ left_px = left.length().to_px(viewport_rect, initial_font_metrics, initial_font_size, initial_font_size);
+ right_px = right.length().to_px(viewport_rect, initial_font_metrics, initial_font_size, initial_font_size);
}
switch (comparison) {
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index d1152f31e1..393918b348 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -908,6 +908,12 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele
style.set_computed_font(found_font.release_nonnull());
}
+Gfx::Font const& StyleComputer::initial_font() const
+{
+ // FIXME: This is not correct.
+ return StyleProperties::font_fallback(false, false);
+}
+
void StyleComputer::absolutize_values(StyleProperties& style, DOM::Element const*, Optional<CSS::Selector::PseudoElement>) const
{
auto viewport_rect = document().browsing_context()->viewport_rect();
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
index 7383269fed..107efc5194 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
@@ -69,6 +69,8 @@ public:
void invalidate_rule_cache();
+ Gfx::Font const& initial_font() const;
+
private:
void compute_cascaded_values(StyleProperties&, DOM::Element&, Optional<CSS::Selector::PseudoElement>) const;
void compute_font(StyleProperties&, DOM::Element const*, Optional<CSS::Selector::PseudoElement>) const;