mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Use Layout::Node::display() everywhere
This commit is contained in:
parent
49eb324535
commit
13834cfdff
Notes:
sideshowbarker
2024-07-17 07:16:27 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/13834cfdff
6 changed files with 24 additions and 33 deletions
|
@ -302,7 +302,7 @@ RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout:
|
||||||
case CSS::PropertyID::Cursor:
|
case CSS::PropertyID::Cursor:
|
||||||
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().cursor()));
|
return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().cursor()));
|
||||||
case CSS::PropertyID::Display:
|
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: {
|
case CSS::PropertyID::FlexBasis: {
|
||||||
switch (layout_node.computed_values().flex_basis().type) {
|
switch (layout_node.computed_values().flex_basis().type) {
|
||||||
case FlexBasis::Content:
|
case FlexBasis::Content:
|
||||||
|
|
|
@ -182,7 +182,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
|
||||||
builder.appendff(" {}floating{}", floating_color_on, color_off);
|
builder.appendff(" {}floating{}", floating_color_on, color_off);
|
||||||
if (box.is_inline_block())
|
if (box.is_inline_block())
|
||||||
builder.appendff(" {}inline-block{}", inline_block_color_on, color_off);
|
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;
|
StringView direction;
|
||||||
switch (box.computed_values().flex_direction()) {
|
switch (box.computed_values().flex_direction()) {
|
||||||
case CSS::FlexDirection::Column:
|
case CSS::FlexDirection::Column:
|
||||||
|
|
|
@ -42,7 +42,7 @@ bool FormattingContext::creates_block_formatting_context(Box const& box)
|
||||||
return true;
|
return true;
|
||||||
if (is<TableCellBox>(box))
|
if (is<TableCellBox>(box))
|
||||||
return true;
|
return true;
|
||||||
if (box.computed_values().display().is_flex_inside())
|
if (box.display().is_flex_inside())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CSS::Overflow overflow_x = box.computed_values().overflow_x();
|
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))
|
if ((overflow_y != CSS::Overflow::Visible) && (overflow_y != CSS::Overflow::Clip))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto display = box.computed_values().display();
|
auto display = box.display();
|
||||||
|
|
||||||
if (display.is_flow_root_inside())
|
if (display.is_flow_root_inside())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (box.parent()) {
|
if (box.parent()) {
|
||||||
auto parent_display = box.parent()->computed_values().display();
|
auto parent_display = box.parent()->display();
|
||||||
if (parent_display.is_flex_inside()) {
|
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.
|
// 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())
|
if (!display.is_flex_inside())
|
||||||
|
@ -102,7 +102,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
|
||||||
if (!child_box.can_have_children())
|
if (!child_box.can_have_children())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto child_display = child_box.computed_values().display();
|
auto child_display = child_box.display();
|
||||||
|
|
||||||
if (is<SVGSVGBox>(child_box))
|
if (is<SVGSVGBox>(child_box))
|
||||||
return make<SVGFormattingContext>(state, child_box, this);
|
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 const& box_state = m_state.get(box);
|
||||||
|
|
||||||
auto display = box.computed_values().display();
|
auto display = box.display();
|
||||||
if (display.is_flex_inside()) {
|
if (display.is_flex_inside()) {
|
||||||
// https://drafts.csswg.org/css-flexbox-1/#algo-main-container
|
// 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.
|
// 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)
|
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>()) {
|
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 sibling;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -197,11 +197,11 @@ void LayoutState::UsedValues::set_node(NodeWithStyleAndBoxModelMetrics& node, Us
|
||||||
if (size.is_auto()) {
|
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.
|
// 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
|
if (width
|
||||||
&& node.computed_values().display().is_block_outside()
|
&& node.display().is_block_outside()
|
||||||
&& node.parent()
|
&& node.parent()
|
||||||
&& !node.parent()->is_floating()
|
&& !node.parent()->is_floating()
|
||||||
&& (node.parent()->computed_values().display().is_flow_root_inside()
|
&& (node.parent()->display().is_flow_root_inside()
|
||||||
|| node.parent()->computed_values().display().is_flow_inside())) {
|
|| node.parent()->display().is_flow_inside())) {
|
||||||
if (containing_block_has_definite_size) {
|
if (containing_block_has_definite_size) {
|
||||||
float available_width = containing_block_used_values->content_width();
|
float available_width = containing_block_used_values->content_width();
|
||||||
resolved_definite_size = available_width
|
resolved_definite_size = available_width
|
||||||
|
|
|
@ -91,11 +91,11 @@ bool Node::establishes_stacking_context() const
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Element that is a child of a flex container, with z-index value other than auto.
|
// 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;
|
return true;
|
||||||
|
|
||||||
// Element that is a child of a grid container, with z-index value other than auto.
|
// 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 true;
|
||||||
|
|
||||||
return computed_values().opacity() < 1.0f;
|
return computed_values().opacity() < 1.0f;
|
||||||
|
@ -591,22 +591,13 @@ CSS::Display Node::display() const
|
||||||
|
|
||||||
bool Node::is_inline() const
|
bool Node::is_inline() const
|
||||||
{
|
{
|
||||||
if (!has_style()) {
|
return display().is_inline_outside();
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::is_inline_block() const
|
bool Node::is_inline_block() const
|
||||||
{
|
{
|
||||||
if (!has_style()) {
|
auto display = this->display();
|
||||||
// NOTE: If this node doesn't have its own style, computed_values() will get style from the parent.
|
return display.is_inline_outside() && display.is_flow_root_inside();
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
|
NonnullRefPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
|
||||||
|
|
|
@ -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())
|
if (layout_parent.is_inline() && !layout_parent.is_inline_block())
|
||||||
return layout_parent;
|
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());
|
layout_parent.append_child(layout_parent.create_anonymous_wrapper());
|
||||||
return *layout_parent.last_child();
|
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)
|
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.
|
// Inlines can be inserted into the nearest ancestor.
|
||||||
auto& insertion_point = insertion_parent_for_inline_node(m_ancestor_stack.last());
|
auto& insertion_point = insertion_parent_for_inline_node(m_ancestor_stack.last());
|
||||||
if (mode == AppendOrPrepend::Prepend)
|
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)
|
void TreeBuilder::for_each_in_tree_with_internal_display(NodeWithStyle& root, Callback callback)
|
||||||
{
|
{
|
||||||
root.for_each_in_inclusive_subtree_of_type<Box>([&](auto& box) {
|
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)
|
if (display.is_internal() && display.internal() == internal)
|
||||||
callback(box);
|
callback(box);
|
||||||
return IterationDecision::Continue;
|
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)
|
void TreeBuilder::for_each_in_tree_with_inside_display(NodeWithStyle& root, Callback callback)
|
||||||
{
|
{
|
||||||
root.for_each_in_inclusive_subtree_of_type<Box>([&](auto& box) {
|
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)
|
if (display.is_outside_and_inside() && display.inside() == inside)
|
||||||
callback(box);
|
callback(box);
|
||||||
return IterationDecision::Continue;
|
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.
|
// 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) {
|
for_each_in_tree_with_internal_display<CSS::Display::Internal::TableColumnGroup>(root, [&](Box& table_column_group) {
|
||||||
table_column_group.for_each_child([&](auto& child) {
|
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);
|
to_remove.append(child);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -369,7 +369,7 @@ static bool is_not_proper_table_child(Node const& node)
|
||||||
{
|
{
|
||||||
if (!node.has_style())
|
if (!node.has_style())
|
||||||
return true;
|
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();
|
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())
|
if (!node.has_style())
|
||||||
return true;
|
return true;
|
||||||
auto display = node.computed_values().display();
|
auto const display = node.display();
|
||||||
return !display.is_table_row();
|
return !display.is_table_row();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ static bool is_not_table_cell(Node const& node)
|
||||||
{
|
{
|
||||||
if (!node.has_style())
|
if (!node.has_style())
|
||||||
return true;
|
return true;
|
||||||
auto display = node.computed_values().display();
|
auto const display = node.display();
|
||||||
return !display.is_table_cell();
|
return !display.is_table_cell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue