From bc3a16396ec51b5a53f44690ef91cd89012452e5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 12 Jan 2024 15:38:00 +0100 Subject: [PATCH] LibWeb: Move font list from NodeWithStyle to ComputedValues Same here, no need for this to live in NodeWithStyle. Inheritance behavior for free in ComputedValues. --- .../Libraries/LibWeb/CSS/ComputedValues.h | 4 +++ .../LibWeb/Layout/InlineLevelIterator.cpp | 2 +- Userland/Libraries/LibWeb/Layout/Node.cpp | 5 +--- Userland/Libraries/LibWeb/Layout/Node.h | 25 +------------------ .../Libraries/LibWeb/Layout/TreeBuilder.cpp | 4 --- 5 files changed, 7 insertions(+), 33 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 5188814d40..330529294d 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -388,6 +389,7 @@ public: Vector const& transformations() const { return m_noninherited.transformations; } CSS::TransformOrigin const& transform_origin() const { return m_noninherited.transform_origin; } + Gfx::FontCascadeList const& font_list() const { return *m_inherited.font_list; } CSSPixels font_size() const { return m_inherited.font_size; } int font_weight() const { return m_inherited.font_weight; } CSS::FontVariant font_variant() const { return m_inherited.font_variant; } @@ -416,6 +418,7 @@ public: protected: struct { + RefPtr font_list {}; CSSPixels font_size { InitialValues::font_size() }; int font_weight { InitialValues::font_weight() }; CSS::FontVariant font_variant { InitialValues::font_variant() }; @@ -547,6 +550,7 @@ public: } void set_aspect_ratio(AspectRatio aspect_ratio) { m_noninherited.aspect_ratio = aspect_ratio; } + void set_font_list(NonnullRefPtr font_list) { m_inherited.font_list = move(font_list); } void set_font_size(CSSPixels font_size) { m_inherited.font_size = font_size; } void set_font_weight(int font_weight) { m_inherited.font_weight = font_weight; } void set_font_variant(CSS::FontVariant font_variant) { m_inherited.font_variant = font_variant; } diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index 131f5ea9a0..88be6cb8a4 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -190,7 +190,7 @@ Optional InlineLevelIterator::next_without_lookahead( Vector glyph_run; float glyph_run_width = 0; Gfx::for_each_glyph_position( - { 0, 0 }, chunk.view, text_node.font_list(), [&](Gfx::DrawGlyphOrEmoji const& glyph_or_emoji) { + { 0, 0 }, chunk.view, text_node.computed_values().font_list(), [&](Gfx::DrawGlyphOrEmoji const& glyph_or_emoji) { glyph_run.append(glyph_or_emoji); return IterationDecision::Continue; }, diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 70b74bff9d..c11b7bbd2c 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -349,7 +349,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style) // NOTE: We have to be careful that font-related properties get set in the right order. // m_font is used by Length::to_px() when resolving sizes against this layout node. // That's why it has to be set before everything else. - m_font_list = computed_style.computed_font_list(); + computed_values.set_font_list(computed_style.computed_font_list()); computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this)); computed_values.set_font_weight(round_to(computed_style.property(CSS::PropertyID::FontWeight)->as_number().number())); computed_values.set_line_height(computed_style.line_height()); @@ -873,7 +873,6 @@ void NodeWithStyle::propagate_style_to_anonymous_wrappers() auto& table_wrapper = *static_cast(parent()); static_cast(static_cast(const_cast(table_wrapper.computed_values()))).inherit_from(m_computed_values); transfer_table_box_computed_values_to_wrapper_computed_values(table_wrapper.m_computed_values); - table_wrapper.set_font_list(*m_font_list); } // Propagate style to all anonymous children (except table wrappers!) @@ -881,7 +880,6 @@ void NodeWithStyle::propagate_style_to_anonymous_wrappers() if (child.is_anonymous() && !is(child)) { auto& child_computed_values = static_cast(static_cast(const_cast(child.computed_values()))); child_computed_values.inherit_from(m_computed_values); - child.set_font_list(*m_font_list); } }); } @@ -943,7 +941,6 @@ JS::NonnullGCPtr NodeWithStyle::create_anonymous_wrapper() const { auto wrapper = heap().allocate_without_realm(const_cast(document()), nullptr, m_computed_values.clone_inherited_values()); static_cast(wrapper->m_computed_values).set_display(CSS::Display(CSS::DisplayOutside::Block, CSS::DisplayInside::Flow)); - wrapper->m_font_list = m_font_list; return *wrapper; } diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 47672245d7..e04e682299 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -142,13 +142,11 @@ public: bool can_contain_boxes_with_position_absolute() const; - Gfx::FontCascadeList const& font_list() const; Gfx::Font const& first_available_font() const; Gfx::Font const& scaled_font(PaintContext&) const; Gfx::Font const& scaled_font(float scale_factor) const; CSS::ImmutableComputedValues const& computed_values() const; - CSSPixels line_height() const; NodeWithStyle* parent(); NodeWithStyle const* parent() const; @@ -218,8 +216,6 @@ public: void apply_style(const CSS::StyleProperties&); Gfx::Font const& first_available_font() const; - Gfx::FontCascadeList const& font_list() const { return *m_font_list; } - void set_font_list(Gfx::FontCascadeList const& font_list) { m_font_list = font_list; } Vector const& background_layers() const { return computed_values().background_layers(); } const CSS::AbstractImageStyleValue* list_style_image() const { return m_list_style_image; } @@ -238,8 +234,6 @@ private: void propagate_style_to_anonymous_wrappers(); CSS::ComputedValues m_computed_values; - RefPtr m_font_list; - CSSPixels m_line_height { 0 }; RefPtr m_list_style_image; }; @@ -283,14 +277,6 @@ inline Gfx::Font const& Node::first_available_font() const return parent()->first_available_font(); } -inline Gfx::FontCascadeList const& Node::font_list() const -{ - VERIFY(has_style_or_parent_with_style()); - if (m_has_style) - return static_cast(this)->font_list(); - return parent()->font_list(); -} - inline Gfx::Font const& Node::scaled_font(PaintContext& context) const { return scaled_font(context.device_pixels_per_css_pixel()); @@ -311,15 +297,6 @@ inline const CSS::ImmutableComputedValues& Node::computed_values() const return parent()->computed_values(); } -inline CSSPixels Node::line_height() const -{ - VERIFY(has_style_or_parent_with_style()); - - if (m_has_style) - return static_cast(this)->line_height(); - return parent()->line_height(); -} - inline NodeWithStyle const* Node::parent() const { return static_cast(TreeNode::parent()); @@ -335,7 +312,7 @@ inline Gfx::Font const& NodeWithStyle::first_available_font() const // https://drafts.csswg.org/css-fonts/#first-available-font // FIXME: Should be be the first font for which the character U+0020 (space) instead of // any first font in the list - return m_font_list->first(); + return computed_values().font_list().first(); } } diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index c20bdcd693..31f9cb386a 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -419,7 +419,6 @@ ErrorOr TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder:: auto content_box_computed_values = parent.computed_values().clone_inherited_values(); auto content_box_wrapper = parent.heap().template allocate_without_realm(parent.document(), nullptr, move(content_box_computed_values)); - content_box_wrapper->set_font_list(parent.font_list()); content_box_wrapper->set_children_are_inline(parent.children_are_inline()); Vector> sequence; @@ -620,7 +619,6 @@ static void wrap_in_anonymous(Vector>& sequence, Node* nearest_ wrapper->append_child(*child); } wrapper->set_children_are_inline(parent.children_are_inline()); - wrapper->set_font_list(parent.font_list()); if (nearest_sibling) parent.insert_before(*wrapper, *nearest_sibling); else @@ -707,7 +705,6 @@ Vector> TreeBuilder::generate_missing_parents(NodeWithStyle& roo parent.remove_child(*table_box); wrapper->append_child(*table_box); - wrapper->set_font_list(parent.font_list()); if (nearest_sibling) parent.insert_before(*wrapper, *nearest_sibling); @@ -742,7 +739,6 @@ static void fixup_row(Box& row_box, TableGrid const& table_grid, size_t row_inde // Ensure that the cell (with zero content height) will have the same height as the row by setting vertical-align to middle. cell_computed_values.set_vertical_align(CSS::VerticalAlign::Middle); auto cell_box = row_box.heap().template allocate_without_realm(row_box.document(), nullptr, cell_computed_values); - cell_box->set_font_list(row_box.font_list()); row_box.append_child(cell_box); } }