浏览代码

LibWeb: Use Layout::Node::display() everywhere

Andreas Kling 2 年之前
父节点
当前提交
13834cfdff

+ 1 - 1
Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp

@@ -302,7 +302,7 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
     case CSS::PropertyID::Cursor:
         return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().cursor()));
     case CSS::PropertyID::Display:
-        return style_value_for_display(layout_node.computed_values().display());
+        return style_value_for_display(layout_node.display());
     case CSS::PropertyID::FlexBasis: {
         switch (layout_node.computed_values().flex_basis().type) {
         case FlexBasis::Content:

+ 1 - 1
Userland/Libraries/LibWeb/Dump.cpp

@@ -182,7 +182,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
             builder.appendff(" {}floating{}", floating_color_on, color_off);
         if (box.is_inline_block())
             builder.appendff(" {}inline-block{}", inline_block_color_on, color_off);
-        if (box.computed_values().display().is_flex_inside()) {
+        if (box.display().is_flex_inside()) {
             StringView direction;
             switch (box.computed_values().flex_direction()) {
             case CSS::FlexDirection::Column:

+ 6 - 6
Userland/Libraries/LibWeb/Layout/FormattingContext.cpp

@@ -42,7 +42,7 @@ bool FormattingContext::creates_block_formatting_context(Box const& box)
         return true;
     if (is<TableCellBox>(box))
         return true;
-    if (box.computed_values().display().is_flex_inside())
+    if (box.display().is_flex_inside())
         return false;
 
     CSS::Overflow overflow_x = box.computed_values().overflow_x();
@@ -53,13 +53,13 @@ bool FormattingContext::creates_block_formatting_context(Box const& box)
     if ((overflow_y != CSS::Overflow::Visible) && (overflow_y != CSS::Overflow::Clip))
         return true;
 
-    auto display = box.computed_values().display();
+    auto display = box.display();
 
     if (display.is_flow_root_inside())
         return true;
 
     if (box.parent()) {
-        auto parent_display = box.parent()->computed_values().display();
+        auto parent_display = box.parent()->display();
         if (parent_display.is_flex_inside()) {
             // FIXME: Flex items (direct children of the element with display: flex or inline-flex) if they are neither flex nor grid nor table containers themselves.
             if (!display.is_flex_inside())
@@ -102,7 +102,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
     if (!child_box.can_have_children())
         return {};
 
-    auto child_display = child_box.computed_values().display();
+    auto child_display = child_box.display();
 
     if (is<SVGSVGBox>(child_box))
         return make<SVGFormattingContext>(state, child_box, this);
@@ -246,7 +246,7 @@ float FormattingContext::compute_auto_height_for_block_level_element(Box const&
 
     auto const& box_state = m_state.get(box);
 
-    auto display = box.computed_values().display();
+    auto display = box.display();
     if (display.is_flex_inside()) {
         // https://drafts.csswg.org/css-flexbox-1/#algo-main-container
         // NOTE: The automatic block size of a block-level flex container is its max-content size.
@@ -1127,7 +1127,7 @@ float FormattingContext::containing_block_height_for(Box const& box, LayoutState
 static Box const* previous_block_level_sibling(Box const& box)
 {
     for (auto* sibling = box.previous_sibling_of_type<Box>(); sibling; sibling = sibling->previous_sibling_of_type<Box>()) {
-        if (sibling->computed_values().display().is_block_outside())
+        if (sibling->display().is_block_outside())
             return sibling;
     }
     return nullptr;

+ 3 - 3
Userland/Libraries/LibWeb/Layout/LayoutState.cpp

@@ -197,11 +197,11 @@ void LayoutState::UsedValues::set_node(NodeWithStyleAndBoxModelMetrics& node, Us
         if (size.is_auto()) {
             // NOTE: The width of a non-flex-item block is considered definite if it's auto and the containing block has definite width.
             if (width
-                && node.computed_values().display().is_block_outside()
+                && node.display().is_block_outside()
                 && node.parent()
                 && !node.parent()->is_floating()
-                && (node.parent()->computed_values().display().is_flow_root_inside()
-                    || node.parent()->computed_values().display().is_flow_inside())) {
+                && (node.parent()->display().is_flow_root_inside()
+                    || node.parent()->display().is_flow_inside())) {
                 if (containing_block_has_definite_size) {
                     float available_width = containing_block_used_values->content_width();
                     resolved_definite_size = available_width

+ 5 - 14
Userland/Libraries/LibWeb/Layout/Node.cpp

@@ -91,11 +91,11 @@ bool Node::establishes_stacking_context() const
         return true;
 
     // Element that is a child of a flex container, with z-index value other than auto.
-    if (parent() && parent()->computed_values().display().is_flex_inside() && computed_values().z_index().has_value())
+    if (parent() && parent()->display().is_flex_inside() && computed_values().z_index().has_value())
         return true;
 
     // Element that is a child of a grid container, with z-index value other than auto.
-    if (parent() && parent()->computed_values().display().is_grid_inside() && computed_values().z_index().has_value())
+    if (parent() && parent()->display().is_grid_inside() && computed_values().z_index().has_value())
         return true;
 
     return computed_values().opacity() < 1.0f;
@@ -591,22 +591,13 @@ CSS::Display Node::display() const
 
 bool Node::is_inline() const
 {
-    if (!has_style()) {
-        // NOTE: If this node doesn't have its own style, computed_values() will get style from the parent.
-        //       This could give unwanted results. Besides, if we don't have style, we're some kind of inline text node.
-        return true;
-    }
-    return computed_values().display().is_inline_outside();
+    return display().is_inline_outside();
 }
 
 bool Node::is_inline_block() const
 {
-    if (!has_style()) {
-        // NOTE: If this node doesn't have its own style, computed_values() will get style from the parent.
-        //       This could give unwanted results. Besides, if we don't have style, we're some kind of inline text node.
-        return false;
-    }
-    return computed_values().display().is_inline_outside() && computed_values().display().is_flow_root_inside();
+    auto display = this->display();
+    return display.is_inline_outside() && display.is_flow_root_inside();
 }
 
 NonnullRefPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const

+ 8 - 8
Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp

@@ -61,7 +61,7 @@ static Layout::Node& insertion_parent_for_inline_node(Layout::NodeWithStyle& lay
     if (layout_parent.is_inline() && !layout_parent.is_inline_block())
         return layout_parent;
 
-    if (layout_parent.computed_values().display().is_flex_inside()) {
+    if (layout_parent.display().is_flex_inside()) {
         layout_parent.append_child(layout_parent.create_anonymous_wrapper());
         return *layout_parent.last_child();
     }
@@ -112,7 +112,7 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
 
 void TreeBuilder::insert_node_into_inline_or_block_ancestor(Layout::Node& node, CSS::Display display, AppendOrPrepend mode)
 {
-    if (display.is_inline_outside() && !(display.is_flow_root_inside() && m_ancestor_stack.last().computed_values().display().is_flex_inside())) {
+    if (display.is_inline_outside() && !(display.is_flow_root_inside() && m_ancestor_stack.last().display().is_flex_inside())) {
         // Inlines can be inserted into the nearest ancestor.
         auto& insertion_point = insertion_parent_for_inline_node(m_ancestor_stack.last());
         if (mode == AppendOrPrepend::Prepend)
@@ -293,7 +293,7 @@ template<CSS::Display::Internal internal, typename Callback>
 void TreeBuilder::for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback callback)
 {
     root.for_each_in_inclusive_subtree_of_type<Box>([&](auto& box) {
-        auto const& display = box.computed_values().display();
+        auto const display = box.display();
         if (display.is_internal() && display.internal() == internal)
             callback(box);
         return IterationDecision::Continue;
@@ -304,7 +304,7 @@ template<CSS::Display::Inside inside, typename Callback>
 void TreeBuilder::for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback callback)
 {
     root.for_each_in_inclusive_subtree_of_type<Box>([&](auto& box) {
-        auto const& display = box.computed_values().display();
+        auto const display = box.display();
         if (display.is_outside_and_inside() && display.inside() == inside)
             callback(box);
         return IterationDecision::Continue;
@@ -334,7 +334,7 @@ void TreeBuilder::remove_irrelevant_boxes(NodeWithStyle& root)
     // Children of a table-column-group which are not a table-column.
     for_each_in_tree_with_internal_display<CSS::Display::Internal::TableColumnGroup>(root, [&](Box& table_column_group) {
         table_column_group.for_each_child([&](auto& child) {
-            if (child.computed_values().display().is_table_column())
+            if (child.display().is_table_column())
                 to_remove.append(child);
         });
     });
@@ -369,7 +369,7 @@ static bool is_not_proper_table_child(Node const& node)
 {
     if (!node.has_style())
         return true;
-    auto display = node.computed_values().display();
+    auto const display = node.display();
     return !is_table_track_group(display) && !is_table_track(display) && !display.is_table_caption();
 }
 
@@ -377,7 +377,7 @@ static bool is_not_table_row(Node const& node)
 {
     if (!node.has_style())
         return true;
-    auto display = node.computed_values().display();
+    auto const display = node.display();
     return !display.is_table_row();
 }
 
@@ -385,7 +385,7 @@ static bool is_not_table_cell(Node const& node)
 {
     if (!node.has_style())
         return true;
-    auto display = node.computed_values().display();
+    auto const display = node.display();
     return !display.is_table_cell();
 }