From 13834cfdff9f19573f91a9054f14ba5c14b29c5c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 6 Oct 2022 16:02:53 +0200 Subject: [PATCH] LibWeb: Use Layout::Node::display() everywhere --- .../CSS/ResolvedCSSStyleDeclaration.cpp | 2 +- Userland/Libraries/LibWeb/Dump.cpp | 2 +- .../LibWeb/Layout/FormattingContext.cpp | 12 ++++++------ .../Libraries/LibWeb/Layout/LayoutState.cpp | 6 +++--- Userland/Libraries/LibWeb/Layout/Node.cpp | 19 +++++-------------- .../Libraries/LibWeb/Layout/TreeBuilder.cpp | 16 ++++++++-------- 6 files changed, 24 insertions(+), 33 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp index 2fd5c1ea807..d9816c7e541 100644 --- a/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp @@ -302,7 +302,7 @@ RefPtr 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: diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index 92e13a5a75f..a5bdc34a809 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/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: diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 25377d52e61..fc8ade26d57 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -42,7 +42,7 @@ bool FormattingContext::creates_block_formatting_context(Box const& box) return true; if (is(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::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(child_box)) return make(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(); sibling; sibling = sibling->previous_sibling_of_type()) { - if (sibling->computed_values().display().is_block_outside()) + if (sibling->display().is_block_outside()) return sibling; } return nullptr; diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index ed110d252b8..046d098add6 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/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 diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 1d9da526d7e..af6662d0e80 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/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::create_anonymous_wrapper() const diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index f87568fa71b..412513a995f 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/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 void TreeBuilder::for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback callback) { root.for_each_in_inclusive_subtree_of_type([&](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 void TreeBuilder::for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback callback) { root.for_each_in_inclusive_subtree_of_type([&](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(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(); }