Sfoglia il codice sorgente

LibWeb: Move font list from NodeWithStyle to ComputedValues

Same here, no need for this to live in NodeWithStyle. Inheritance
behavior for free in ComputedValues.
Andreas Kling 1 anno fa
parent
commit
bc3a16396e

+ 4 - 0
Userland/Libraries/LibWeb/CSS/ComputedValues.h

@@ -7,6 +7,7 @@
 #pragma once
 #pragma once
 
 
 #include <AK/Optional.h>
 #include <AK/Optional.h>
+#include <LibGfx/FontCascadeList.h>
 #include <LibGfx/Painter.h>
 #include <LibGfx/Painter.h>
 #include <LibWeb/CSS/BackdropFilter.h>
 #include <LibWeb/CSS/BackdropFilter.h>
 #include <LibWeb/CSS/CalculatedOr.h>
 #include <LibWeb/CSS/CalculatedOr.h>
@@ -388,6 +389,7 @@ public:
     Vector<CSS::Transformation> const& transformations() const { return m_noninherited.transformations; }
     Vector<CSS::Transformation> const& transformations() const { return m_noninherited.transformations; }
     CSS::TransformOrigin const& transform_origin() const { return m_noninherited.transform_origin; }
     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; }
     CSSPixels font_size() const { return m_inherited.font_size; }
     int font_weight() const { return m_inherited.font_weight; }
     int font_weight() const { return m_inherited.font_weight; }
     CSS::FontVariant font_variant() const { return m_inherited.font_variant; }
     CSS::FontVariant font_variant() const { return m_inherited.font_variant; }
@@ -416,6 +418,7 @@ public:
 
 
 protected:
 protected:
     struct {
     struct {
+        RefPtr<Gfx::FontCascadeList> font_list {};
         CSSPixels font_size { InitialValues::font_size() };
         CSSPixels font_size { InitialValues::font_size() };
         int font_weight { InitialValues::font_weight() };
         int font_weight { InitialValues::font_weight() };
         CSS::FontVariant font_variant { InitialValues::font_variant() };
         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_aspect_ratio(AspectRatio aspect_ratio) { m_noninherited.aspect_ratio = aspect_ratio; }
+    void set_font_list(NonnullRefPtr<Gfx::FontCascadeList> 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_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_weight(int font_weight) { m_inherited.font_weight = font_weight; }
     void set_font_variant(CSS::FontVariant font_variant) { m_inherited.font_variant = font_variant; }
     void set_font_variant(CSS::FontVariant font_variant) { m_inherited.font_variant = font_variant; }

+ 1 - 1
Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp

@@ -190,7 +190,7 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next_without_lookahead(
         Vector<Gfx::DrawGlyphOrEmoji> glyph_run;
         Vector<Gfx::DrawGlyphOrEmoji> glyph_run;
         float glyph_run_width = 0;
         float glyph_run_width = 0;
         Gfx::for_each_glyph_position(
         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);
                 glyph_run.append(glyph_or_emoji);
                 return IterationDecision::Continue;
                 return IterationDecision::Continue;
             },
             },

+ 1 - 4
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.
     // 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.
     //       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.
     //       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_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this));
     computed_values.set_font_weight(round_to<int>(computed_style.property(CSS::PropertyID::FontWeight)->as_number().number()));
     computed_values.set_font_weight(round_to<int>(computed_style.property(CSS::PropertyID::FontWeight)->as_number().number()));
     computed_values.set_line_height(computed_style.line_height());
     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<TableWrapper*>(parent());
         auto& table_wrapper = *static_cast<TableWrapper*>(parent());
         static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(table_wrapper.computed_values()))).inherit_from(m_computed_values);
         static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(table_wrapper.computed_values()))).inherit_from(m_computed_values);
         transfer_table_box_computed_values_to_wrapper_computed_values(table_wrapper.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!)
     // 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<TableWrapper>(child)) {
         if (child.is_anonymous() && !is<TableWrapper>(child)) {
             auto& child_computed_values = static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(child.computed_values())));
             auto& child_computed_values = static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(child.computed_values())));
             child_computed_values.inherit_from(m_computed_values);
             child_computed_values.inherit_from(m_computed_values);
-            child.set_font_list(*m_font_list);
         }
         }
     });
     });
 }
 }
@@ -943,7 +941,6 @@ JS::NonnullGCPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
 {
 {
     auto wrapper = heap().allocate_without_realm<BlockContainer>(const_cast<DOM::Document&>(document()), nullptr, m_computed_values.clone_inherited_values());
     auto wrapper = heap().allocate_without_realm<BlockContainer>(const_cast<DOM::Document&>(document()), nullptr, m_computed_values.clone_inherited_values());
     static_cast<CSS::MutableComputedValues&>(wrapper->m_computed_values).set_display(CSS::Display(CSS::DisplayOutside::Block, CSS::DisplayInside::Flow));
     static_cast<CSS::MutableComputedValues&>(wrapper->m_computed_values).set_display(CSS::Display(CSS::DisplayOutside::Block, CSS::DisplayInside::Flow));
-    wrapper->m_font_list = m_font_list;
     return *wrapper;
     return *wrapper;
 }
 }
 
 

+ 1 - 24
Userland/Libraries/LibWeb/Layout/Node.h

@@ -142,13 +142,11 @@ public:
 
 
     bool can_contain_boxes_with_position_absolute() const;
     bool can_contain_boxes_with_position_absolute() const;
 
 
-    Gfx::FontCascadeList const& font_list() const;
     Gfx::Font const& first_available_font() const;
     Gfx::Font const& first_available_font() const;
     Gfx::Font const& scaled_font(PaintContext&) const;
     Gfx::Font const& scaled_font(PaintContext&) const;
     Gfx::Font const& scaled_font(float scale_factor) const;
     Gfx::Font const& scaled_font(float scale_factor) const;
 
 
     CSS::ImmutableComputedValues const& computed_values() const;
     CSS::ImmutableComputedValues const& computed_values() const;
-    CSSPixels line_height() const;
 
 
     NodeWithStyle* parent();
     NodeWithStyle* parent();
     NodeWithStyle const* parent() const;
     NodeWithStyle const* parent() const;
@@ -218,8 +216,6 @@ public:
     void apply_style(const CSS::StyleProperties&);
     void apply_style(const CSS::StyleProperties&);
 
 
     Gfx::Font const& first_available_font() const;
     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<CSS::BackgroundLayerData> const& background_layers() const { return computed_values().background_layers(); }
     Vector<CSS::BackgroundLayerData> const& background_layers() const { return computed_values().background_layers(); }
     const CSS::AbstractImageStyleValue* list_style_image() const { return m_list_style_image; }
     const CSS::AbstractImageStyleValue* list_style_image() const { return m_list_style_image; }
 
 
@@ -238,8 +234,6 @@ private:
     void propagate_style_to_anonymous_wrappers();
     void propagate_style_to_anonymous_wrappers();
 
 
     CSS::ComputedValues m_computed_values;
     CSS::ComputedValues m_computed_values;
-    RefPtr<Gfx::FontCascadeList const> m_font_list;
-    CSSPixels m_line_height { 0 };
     RefPtr<CSS::AbstractImageStyleValue const> m_list_style_image;
     RefPtr<CSS::AbstractImageStyleValue const> m_list_style_image;
 };
 };
 
 
@@ -283,14 +277,6 @@ inline Gfx::Font const& Node::first_available_font() const
     return parent()->first_available_font();
     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<NodeWithStyle const*>(this)->font_list();
-    return parent()->font_list();
-}
-
 inline Gfx::Font const& Node::scaled_font(PaintContext& context) const
 inline Gfx::Font const& Node::scaled_font(PaintContext& context) const
 {
 {
     return scaled_font(context.device_pixels_per_css_pixel());
     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();
     return parent()->computed_values();
 }
 }
 
 
-inline CSSPixels Node::line_height() const
-{
-    VERIFY(has_style_or_parent_with_style());
-
-    if (m_has_style)
-        return static_cast<NodeWithStyle const*>(this)->line_height();
-    return parent()->line_height();
-}
-
 inline NodeWithStyle const* Node::parent() const
 inline NodeWithStyle const* Node::parent() const
 {
 {
     return static_cast<NodeWithStyle const*>(TreeNode<Node>::parent());
     return static_cast<NodeWithStyle const*>(TreeNode<Node>::parent());
@@ -335,7 +312,7 @@ inline Gfx::Font const& NodeWithStyle::first_available_font() const
     // https://drafts.csswg.org/css-fonts/#first-available-font
     // 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
     // FIXME: Should be be the first font for which the character U+0020 (space) instead of
     //        any first font in the list
     //        any first font in the list
-    return m_font_list->first();
+    return computed_values().font_list().first();
 }
 }
 
 
 }
 }

+ 0 - 4
Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp

@@ -419,7 +419,6 @@ ErrorOr<void> TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::
 
 
         auto content_box_computed_values = parent.computed_values().clone_inherited_values();
         auto content_box_computed_values = parent.computed_values().clone_inherited_values();
         auto content_box_wrapper = parent.heap().template allocate_without_realm<BlockContainer>(parent.document(), nullptr, move(content_box_computed_values));
         auto content_box_wrapper = parent.heap().template allocate_without_realm<BlockContainer>(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());
         content_box_wrapper->set_children_are_inline(parent.children_are_inline());
 
 
         Vector<JS::Handle<Node>> sequence;
         Vector<JS::Handle<Node>> sequence;
@@ -620,7 +619,6 @@ static void wrap_in_anonymous(Vector<JS::Handle<Node>>& sequence, Node* nearest_
         wrapper->append_child(*child);
         wrapper->append_child(*child);
     }
     }
     wrapper->set_children_are_inline(parent.children_are_inline());
     wrapper->set_children_are_inline(parent.children_are_inline());
-    wrapper->set_font_list(parent.font_list());
     if (nearest_sibling)
     if (nearest_sibling)
         parent.insert_before(*wrapper, *nearest_sibling);
         parent.insert_before(*wrapper, *nearest_sibling);
     else
     else
@@ -707,7 +705,6 @@ Vector<JS::Handle<Box>> TreeBuilder::generate_missing_parents(NodeWithStyle& roo
 
 
         parent.remove_child(*table_box);
         parent.remove_child(*table_box);
         wrapper->append_child(*table_box);
         wrapper->append_child(*table_box);
-        wrapper->set_font_list(parent.font_list());
 
 
         if (nearest_sibling)
         if (nearest_sibling)
             parent.insert_before(*wrapper, *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.
         // 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);
         cell_computed_values.set_vertical_align(CSS::VerticalAlign::Middle);
         auto cell_box = row_box.heap().template allocate_without_realm<BlockContainer>(row_box.document(), nullptr, cell_computed_values);
         auto cell_box = row_box.heap().template allocate_without_realm<BlockContainer>(row_box.document(), nullptr, cell_computed_values);
-        cell_box->set_font_list(row_box.font_list());
         row_box.append_child(cell_box);
         row_box.append_child(cell_box);
     }
     }
 }
 }