Commit 42d1175c authored by Ana SollanoKim's avatar Ana SollanoKim Committed by Chromium LUCI CQ

[GridNG] Containing block rect addition and simplification of

NG Out Of flow Layout part

This change prepares the out of flow logic to incorporate a containing
block rect that will be passed from AddOutOfFlowChildCandidate as the
out of flow items' grid area. As a result, both AddOutOfFlowChild
Candidate and OutOfFlowPositionedNode have a new, default, optional
LogicalRect argument. ContainingBlockInfo was simplified to account for
this addition and thus, NGOutOfFlowLayoutPart was refactored.

Bug: 1045599
Change-Id: Ibab921ed449513d8f802e4467e845fcfb327c11f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593715
Commit-Queue: Ana Sollano Kim <ansollan@microsoft.com>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarKurt Catti-Schmidt <kschmi@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#838506}
parent d04b58c0
...@@ -168,7 +168,8 @@ void NGContainerFragmentBuilder::AddOutOfFlowChildCandidate( ...@@ -168,7 +168,8 @@ void NGContainerFragmentBuilder::AddOutOfFlowChildCandidate(
const LogicalOffset& child_offset, const LogicalOffset& child_offset,
NGLogicalStaticPosition::InlineEdge inline_edge, NGLogicalStaticPosition::InlineEdge inline_edge,
NGLogicalStaticPosition::BlockEdge block_edge, NGLogicalStaticPosition::BlockEdge block_edge,
bool needs_block_offset_adjustment) { bool needs_block_offset_adjustment,
const base::Optional<LogicalRect> containing_block_rect) {
DCHECK(child); DCHECK(child);
// If an OOF-positioned candidate has a static-position which uses a // If an OOF-positioned candidate has a static-position which uses a
...@@ -181,7 +182,9 @@ void NGContainerFragmentBuilder::AddOutOfFlowChildCandidate( ...@@ -181,7 +182,9 @@ void NGContainerFragmentBuilder::AddOutOfFlowChildCandidate(
oof_positioned_candidates_.emplace_back( oof_positioned_candidates_.emplace_back(
child, NGLogicalStaticPosition{child_offset, inline_edge, block_edge}, child, NGLogicalStaticPosition{child_offset, inline_edge, block_edge},
/* inline_container */ nullptr, needs_block_offset_adjustment); /* inline_container */ nullptr, needs_block_offset_adjustment,
/*containing_block_offset */ LogicalOffset(),
/* containing_block_fragment */ nullptr, containing_block_rect);
} }
void NGContainerFragmentBuilder::AddOutOfFlowInlineChildCandidate( void NGContainerFragmentBuilder::AddOutOfFlowInlineChildCandidate(
......
...@@ -111,7 +111,8 @@ class CORE_EXPORT NGContainerFragmentBuilder : public NGFragmentBuilder { ...@@ -111,7 +111,8 @@ class CORE_EXPORT NGContainerFragmentBuilder : public NGFragmentBuilder {
NGLogicalStaticPosition::InlineEdge = NGLogicalStaticPosition::InlineEdge =
NGLogicalStaticPosition::kInlineStart, NGLogicalStaticPosition::kInlineStart,
NGLogicalStaticPosition::BlockEdge = NGLogicalStaticPosition::kBlockStart, NGLogicalStaticPosition::BlockEdge = NGLogicalStaticPosition::kBlockStart,
bool needs_block_offset_adjustment = true); bool needs_block_offset_adjustment = true,
const base::Optional<LogicalRect> containing_block_rect = base::nullopt);
// This should only be used for inline-level OOF-positioned nodes. // This should only be used for inline-level OOF-positioned nodes.
// |inline_container_direction| is the current text direction for determining // |inline_container_direction| is the current text direction for determining
......
...@@ -105,6 +105,7 @@ NGOutOfFlowLayoutPart::NGOutOfFlowLayoutPart( ...@@ -105,6 +105,7 @@ NGOutOfFlowLayoutPart::NGOutOfFlowLayoutPart(
base::Optional<LogicalSize> initial_containing_block_fixed_size) base::Optional<LogicalSize> initial_containing_block_fixed_size)
: container_builder_(container_builder), : container_builder_(container_builder),
writing_mode_(container_style.GetWritingMode()), writing_mode_(container_style.GetWritingMode()),
default_writing_direction_(container_style.GetWritingDirection()),
is_absolute_container_(is_absolute_container), is_absolute_container_(is_absolute_container),
is_fixed_container_(is_fixed_container), is_fixed_container_(is_fixed_container),
has_block_fragmentation_(container_space.HasBlockFragmentation()) { has_block_fragmentation_(container_space.HasBlockFragmentation()) {
...@@ -113,20 +114,23 @@ NGOutOfFlowLayoutPart::NGOutOfFlowLayoutPart( ...@@ -113,20 +114,23 @@ NGOutOfFlowLayoutPart::NGOutOfFlowLayoutPart(
->HasPositionedObjects()) ->HasPositionedObjects())
return; return;
default_containing_block_.writing_direction = default_containing_block_info_for_absolute_.writing_direction =
container_style.GetWritingDirection(); default_writing_direction_;
default_containing_block_info_for_fixed_.writing_direction =
default_writing_direction_;
const NGBoxStrut border_scrollbar = const NGBoxStrut border_scrollbar =
container_builder->Borders() + container_builder->Scrollbar(); container_builder->Borders() + container_builder->Scrollbar();
allow_first_tier_oof_cache_ = border_scrollbar.IsEmpty(); allow_first_tier_oof_cache_ = border_scrollbar.IsEmpty();
default_containing_block_.content_size_for_absolute = default_containing_block_info_for_absolute_.rect.size =
ShrinkLogicalSize(container_builder_->Size(), border_scrollbar); ShrinkLogicalSize(container_builder_->Size(), border_scrollbar);
default_containing_block_.content_size_for_fixed = default_containing_block_info_for_fixed_.rect.size =
initial_containing_block_fixed_size initial_containing_block_fixed_size
? *initial_containing_block_fixed_size ? *initial_containing_block_fixed_size
: default_containing_block_.content_size_for_absolute; : default_containing_block_info_for_absolute_.rect.size;
LogicalOffset container_offset = {border_scrollbar.inline_start,
default_containing_block_.container_offset = LogicalOffset( border_scrollbar.block_start};
border_scrollbar.inline_start, border_scrollbar.block_start); default_containing_block_info_for_absolute_.rect.offset = container_offset;
default_containing_block_info_for_fixed_.rect.offset = container_offset;
} }
void NGOutOfFlowLayoutPart::Run(const LayoutBox* only_layout) { void NGOutOfFlowLayoutPart::Run(const LayoutBox* only_layout) {
...@@ -287,14 +291,16 @@ bool NGOutOfFlowLayoutPart::SweepLegacyCandidates( ...@@ -287,14 +291,16 @@ bool NGOutOfFlowLayoutPart::SweepLegacyCandidates(
// When fragmenting, the ContainingBlockInfo is not stored ahead of time and // When fragmenting, the ContainingBlockInfo is not stored ahead of time and
// must be generated on demand. The reason being that during fragmentation, we // must be generated on demand. The reason being that during fragmentation, we
// wait to place positioned nodes until they've reached the fragmentation // wait to place positioned nodes until they've reached the fragmentation
// context root. In such cases, we cannot use |default_containing_block_| since // context root. In such cases, we cannot use default |ContainingBlockInfo|
// the fragmentation root is not the containing block of the positioned nodes. // since the fragmentation root is not the containing block of the positioned
// Rather, we must generate their ContainingBlockInfo based on the provided // nodes. Rather, we must generate their ContainingBlockInfo based on the
// |containing_block_fragment|. // provided |containing_block_fragment|.
const NGOutOfFlowLayoutPart::ContainingBlockInfo& const NGOutOfFlowLayoutPart::ContainingBlockInfo
NGOutOfFlowLayoutPart::GetContainingBlockInfo( NGOutOfFlowLayoutPart::GetContainingBlockInfo(
const NGLogicalOutOfFlowPositionedNode& candidate, const NGLogicalOutOfFlowPositionedNode& candidate,
const NGPhysicalContainerFragment* containing_block_fragment) { const NGPhysicalContainerFragment* containing_block_fragment) {
if (candidate.containing_block_rect)
return {default_writing_direction_, *candidate.containing_block_rect};
if (candidate.inline_container) { if (candidate.inline_container) {
const auto it = containing_blocks_map_.find(candidate.inline_container); const auto it = containing_blocks_map_.find(candidate.inline_container);
DCHECK(it != containing_blocks_map_.end()); DCHECK(it != containing_blocks_map_.end());
...@@ -327,14 +333,17 @@ NGOutOfFlowLayoutPart::GetContainingBlockInfo( ...@@ -327,14 +333,17 @@ NGOutOfFlowLayoutPart::GetContainingBlockInfo(
LogicalOffset(border.inline_start, border.block_start); LogicalOffset(border.inline_start, border.block_start);
container_offset += candidate.containing_block_offset; container_offset += candidate.containing_block_offset;
ContainingBlockInfo containing_block_info{writing_direction, content_size, ContainingBlockInfo containing_block_info{
content_size, container_offset}; writing_direction, LogicalRect(container_offset, content_size)};
return containing_blocks_map_ return containing_blocks_map_
.insert(containing_block, containing_block_info) .insert(containing_block, containing_block_info)
.stored_value->value; .stored_value->value;
} }
return default_containing_block_;
return candidate.node.Style().GetPosition() == EPosition::kAbsolute
? default_containing_block_info_for_absolute_
: default_containing_block_info_for_fixed_;
} }
void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks( void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks(
...@@ -417,7 +426,7 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks( ...@@ -417,7 +426,7 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks(
DCHECK(inline_cb_style); DCHECK(inline_cb_style);
const auto container_writing_direction = const auto container_writing_direction =
default_containing_block_.writing_direction; default_containing_block_info_for_absolute_.writing_direction;
const auto inline_writing_direction = const auto inline_writing_direction =
inline_cb_style->GetWritingDirection(); inline_cb_style->GetWritingDirection();
NGBoxStrut inline_cb_borders = ComputeBordersForInline(*inline_cb_style); NGBoxStrut inline_cb_borders = ComputeBordersForInline(*inline_cb_style);
...@@ -475,8 +484,8 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks( ...@@ -475,8 +484,8 @@ void NGOutOfFlowLayoutPart::ComputeInlineContainingBlocks(
containing_blocks_map_.insert( containing_blocks_map_.insert(
block_info.key, block_info.key,
ContainingBlockInfo{inline_writing_direction, inline_cb_size, ContainingBlockInfo{inline_writing_direction,
inline_cb_size, container_offset}); LogicalRect(container_offset, inline_cb_size)});
} }
} }
...@@ -542,15 +551,13 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate( ...@@ -542,15 +551,13 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate(
node.GetLayoutBox()->ContainingBlock()) || node.GetLayoutBox()->ContainingBlock()) ||
node.GetLayoutBox()->ContainingBlock()->IsTable()); node.GetLayoutBox()->ContainingBlock()->IsTable());
const auto default_writing_direction = const ContainingBlockInfo container_info = GetContainingBlockInfo(candidate);
default_containing_block_.writing_direction;
const ContainingBlockInfo& container_info = GetContainingBlockInfo(candidate);
const ComputedStyle& candidate_style = node.Style(); const ComputedStyle& candidate_style = node.Style();
const auto candidate_writing_direction = const auto candidate_writing_direction =
candidate_style.GetWritingDirection(); candidate_style.GetWritingDirection();
LogicalSize container_content_size = LogicalSize container_content_size = container_info.rect.size;
container_info.ContentSize(candidate_style.GetPosition());
PhysicalSize container_physical_content_size = PhysicalSize container_physical_content_size =
ToPhysicalSize(container_content_size, writing_mode_); ToPhysicalSize(container_content_size, writing_mode_);
...@@ -577,12 +584,12 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate( ...@@ -577,12 +584,12 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate(
// container's border-box). ng_absolute_utils expects the static position to // container's border-box). ng_absolute_utils expects the static position to
// be relative to the container's padding-box. // be relative to the container's padding-box.
NGLogicalStaticPosition static_position = candidate.static_position; NGLogicalStaticPosition static_position = candidate.static_position;
static_position.offset -= container_info.container_offset; static_position.offset -= container_info.rect.offset;
NGLogicalStaticPosition candidate_static_position = NGLogicalStaticPosition candidate_static_position =
static_position static_position
.ConvertToPhysical( .ConvertToPhysical(
{default_writing_direction, container_physical_content_size}) {default_writing_direction_, container_physical_content_size})
.ConvertToLogical( .ConvertToLogical(
{candidate_writing_direction, container_physical_content_size}); {candidate_writing_direction, container_physical_content_size});
...@@ -599,7 +606,7 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate( ...@@ -599,7 +606,7 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::LayoutCandidate(
scoped_refptr<const NGLayoutResult> layout_result = scoped_refptr<const NGLayoutResult> layout_result =
Layout(node, candidate_constraint_space, candidate_static_position, Layout(node, candidate_constraint_space, candidate_static_position,
container_physical_content_size, container_info, container_physical_content_size, container_info,
default_writing_direction, only_layout); default_writing_direction_, only_layout);
if (!freeze_scrollbars.has_value()) { if (!freeze_scrollbars.has_value()) {
// Since out-of-flow positioning sets up a constraint space with fixed // Since out-of-flow positioning sets up a constraint space with fixed
...@@ -670,7 +677,7 @@ NGOutOfFlowLayoutPart::LayoutFragmentainerDescendant( ...@@ -670,7 +677,7 @@ NGOutOfFlowLayoutPart::LayoutFragmentainerDescendant(
containing_block_fragment->GetLayoutObject() == containing_block_fragment->GetLayoutObject() ==
node.GetLayoutBox()->ContainingBlock()); node.GetLayoutBox()->ContainingBlock());
const ContainingBlockInfo& container_info = const ContainingBlockInfo container_info =
GetContainingBlockInfo(descendant, containing_block_fragment); GetContainingBlockInfo(descendant, containing_block_fragment);
const auto default_writing_direction = const auto default_writing_direction =
containing_block_fragment->Style().GetWritingDirection(); containing_block_fragment->Style().GetWritingDirection();
...@@ -678,19 +685,18 @@ NGOutOfFlowLayoutPart::LayoutFragmentainerDescendant( ...@@ -678,19 +685,18 @@ NGOutOfFlowLayoutPart::LayoutFragmentainerDescendant(
const auto descendant_writing_direction = const auto descendant_writing_direction =
descendant_style.GetWritingDirection(); descendant_style.GetWritingDirection();
LogicalSize container_content_size = LogicalSize container_content_size = container_info.rect.size;
container_info.ContentSize(descendant_style.GetPosition());
PhysicalSize container_physical_content_size = ToPhysicalSize( PhysicalSize container_physical_content_size = ToPhysicalSize(
container_content_size, default_writing_direction.GetWritingMode()); container_content_size, default_writing_direction.GetWritingMode());
// Adjust the |static_position| (which is currently relative to the default // Adjust the |static_position| (which is currently relative to the default
// container's border-box). ng_absolute_utils expects the static position to // container's border-box). ng_absolute_utils expects the static position to
// be relative to the container's padding-box. Since // be relative to the container's padding-box. Since
// |container_info.container_offset| is relative to its fragmentainer in this // |container_info.rect.offset| is relative to its fragmentainer in this
// case, we also need to adjust the offset to account for this. // case, we also need to adjust the offset to account for this.
NGLogicalStaticPosition static_position = descendant.static_position; NGLogicalStaticPosition static_position = descendant.static_position;
static_position.offset -= static_position.offset -=
container_info.container_offset - descendant.containing_block_offset; container_info.rect.offset - descendant.containing_block_offset;
NGLogicalStaticPosition descendant_static_position = NGLogicalStaticPosition descendant_static_position =
static_position static_position
...@@ -878,7 +884,7 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::Layout( ...@@ -878,7 +884,7 @@ scoped_refptr<const NGLayoutResult> NGOutOfFlowLayoutPart::Layout(
// |inset| is relative to the container's padding-box. Convert this to being // |inset| is relative to the container's padding-box. Convert this to being
// relative to the default container's border-box. // relative to the default container's border-box.
LogicalOffset offset = container_info.container_offset; LogicalOffset offset = container_info.rect.offset;
offset.inline_offset += inset.inline_start; offset.inline_offset += inset.inline_start;
offset.block_offset += inset.block_start; offset.block_offset += inset.block_start;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "base/optional.h" #include "base/optional.h"
#include "third_party/blink/renderer/core/layout/geometry/logical_rect.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_offset.h" #include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
#include "third_party/blink/renderer/core/layout/ng/ng_absolute_utils.h" #include "third_party/blink/renderer/core/layout/ng/ng_absolute_utils.h"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h" #include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h"
...@@ -80,23 +81,13 @@ class CORE_EXPORT NGOutOfFlowLayoutPart { ...@@ -80,23 +81,13 @@ class CORE_EXPORT NGOutOfFlowLayoutPart {
// The writing direction of the container. // The writing direction of the container.
WritingDirectionMode writing_direction = {WritingMode::kHorizontalTb, WritingDirectionMode writing_direction = {WritingMode::kHorizontalTb,
TextDirection::kLtr}; TextDirection::kLtr};
// Logical in containing block coordinates. // Size and offset of the container.
LogicalSize content_size_for_absolute; LogicalRect rect;
// Content size for fixed is different for the ICB.
LogicalSize content_size_for_fixed;
// Offset of the container's padding-box.
LogicalOffset container_offset;
LogicalSize ContentSize(EPosition position) const {
return position == EPosition::kAbsolute ? content_size_for_absolute
: content_size_for_fixed;
}
}; };
bool SweepLegacyCandidates(HashSet<const LayoutObject*>* placed_objects); bool SweepLegacyCandidates(HashSet<const LayoutObject*>* placed_objects);
const ContainingBlockInfo& GetContainingBlockInfo( const ContainingBlockInfo GetContainingBlockInfo(
const NGLogicalOutOfFlowPositionedNode&, const NGLogicalOutOfFlowPositionedNode&,
const NGPhysicalContainerFragment* = nullptr); const NGPhysicalContainerFragment* = nullptr);
...@@ -151,7 +142,8 @@ class CORE_EXPORT NGOutOfFlowLayoutPart { ...@@ -151,7 +142,8 @@ class CORE_EXPORT NGOutOfFlowLayoutPart {
LogicalOffset* offset) const; LogicalOffset* offset) const;
NGBoxFragmentBuilder* container_builder_; NGBoxFragmentBuilder* container_builder_;
ContainingBlockInfo default_containing_block_; ContainingBlockInfo default_containing_block_info_for_absolute_;
ContainingBlockInfo default_containing_block_info_for_fixed_;
HashMap<const LayoutObject*, ContainingBlockInfo> containing_blocks_map_; HashMap<const LayoutObject*, ContainingBlockInfo> containing_blocks_map_;
HashMap<wtf_size_t, NGConstraintSpace> fragmentainer_constraint_space_map_; HashMap<wtf_size_t, NGConstraintSpace> fragmentainer_constraint_space_map_;
// Map of fragmentainer indexes to a list of descendant layout results to // Map of fragmentainer indexes to a list of descendant layout results to
...@@ -159,6 +151,7 @@ class CORE_EXPORT NGOutOfFlowLayoutPart { ...@@ -159,6 +151,7 @@ class CORE_EXPORT NGOutOfFlowLayoutPart {
HashMap<wtf_size_t, Vector<scoped_refptr<const NGLayoutResult>>> HashMap<wtf_size_t, Vector<scoped_refptr<const NGLayoutResult>>>
fragmentainer_descendant_results_; fragmentainer_descendant_results_;
const WritingMode writing_mode_; const WritingMode writing_mode_;
const WritingDirectionMode default_writing_direction_;
LayoutUnit column_inline_progression_ = kIndefiniteSize; LayoutUnit column_inline_progression_ = kIndefiniteSize;
// The block size of the multi-column (before adjustment for spanners, etc.) // The block size of the multi-column (before adjustment for spanners, etc.)
// This is used to calculate the column size of any newly added proxy // This is used to calculate the column size of any newly added proxy
......
...@@ -73,6 +73,7 @@ struct NGLogicalOutOfFlowPositionedNode { ...@@ -73,6 +73,7 @@ struct NGLogicalOutOfFlowPositionedNode {
bool needs_block_offset_adjustment; bool needs_block_offset_adjustment;
LogicalOffset containing_block_offset; LogicalOffset containing_block_offset;
scoped_refptr<const NGPhysicalContainerFragment> containing_block_fragment; scoped_refptr<const NGPhysicalContainerFragment> containing_block_fragment;
base::Optional<LogicalRect> containing_block_rect;
NGLogicalOutOfFlowPositionedNode( NGLogicalOutOfFlowPositionedNode(
NGBlockNode node, NGBlockNode node,
...@@ -81,13 +82,15 @@ struct NGLogicalOutOfFlowPositionedNode { ...@@ -81,13 +82,15 @@ struct NGLogicalOutOfFlowPositionedNode {
bool needs_block_offset_adjustment = false, bool needs_block_offset_adjustment = false,
LogicalOffset containing_block_offset = LogicalOffset(), LogicalOffset containing_block_offset = LogicalOffset(),
scoped_refptr<const NGPhysicalContainerFragment> scoped_refptr<const NGPhysicalContainerFragment>
containing_block_fragment = nullptr) containing_block_fragment = nullptr,
const base::Optional<LogicalRect> containing_block_rect = base::nullopt)
: node(node), : node(node),
static_position(static_position), static_position(static_position),
inline_container(inline_container), inline_container(inline_container),
needs_block_offset_adjustment(needs_block_offset_adjustment), needs_block_offset_adjustment(needs_block_offset_adjustment),
containing_block_offset(containing_block_offset), containing_block_offset(containing_block_offset),
containing_block_fragment(std::move(containing_block_fragment)) { containing_block_fragment(std::move(containing_block_fragment)),
containing_block_rect(containing_block_rect) {
DCHECK(!inline_container || DCHECK(!inline_container ||
inline_container == inline_container->ContinuationRoot()); inline_container == inline_container->ContinuationRoot());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment