Commit d00a20a3 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

[LayoutNG] Fragmentation-aware border+scrollbar+padding strut.

Simplifies the code.

Follow-up to CL:1903193

Change-Id: If5e068a96de44aa938fd3ab83496f1ca757d2dd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1908538Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714406}
parent df94de8c
...@@ -181,6 +181,7 @@ NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( ...@@ -181,6 +181,7 @@ NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(
is_resuming_(IsResumingLayout(params.break_token)), is_resuming_(IsResumingLayout(params.break_token)),
exclusion_space_(params.space.ExclusionSpace()), exclusion_space_(params.space.ExclusionSpace()),
early_break_(params.early_break) { early_break_(params.early_break) {
AdjustForFragmentation(BreakToken(), &border_scrollbar_padding_);
container_builder_.SetIsNewFormattingContext( container_builder_.SetIsNewFormattingContext(
params.space.IsNewFormattingContext()); params.space.IsNewFormattingContext());
container_builder_.SetInitialFragmentGeometry(params.fragment_geometry); container_builder_.SetInitialFragmentGeometry(params.fragment_geometry);
...@@ -462,10 +463,7 @@ inline scoped_refptr<const NGLayoutResult> NGBlockLayoutAlgorithm::Layout( ...@@ -462,10 +463,7 @@ inline scoped_refptr<const NGLayoutResult> NGBlockLayoutAlgorithm::Layout(
container_builder_.SetAdjoiningObjectTypes(adjoining_object_types); container_builder_.SetAdjoiningObjectTypes(adjoining_object_types);
} }
// If we are resuming from a break token our start border and padding is LayoutUnit content_edge = border_scrollbar_padding_.block_start;
// within a previous fragment.
LayoutUnit content_edge =
is_resuming_ ? LayoutUnit() : border_scrollbar_padding_.block_start;
NGPreviousInflowPosition previous_inflow_position = { NGPreviousInflowPosition previous_inflow_position = {
LayoutUnit(), ConstraintSpace().MarginStrut(), LayoutUnit(), ConstraintSpace().MarginStrut(),
......
...@@ -337,7 +337,12 @@ class CORE_EXPORT NGBlockLayoutAlgorithm ...@@ -337,7 +337,12 @@ class CORE_EXPORT NGBlockLayoutAlgorithm
// Returns kIndefiniteSize in all other cases. // Returns kIndefiniteSize in all other cases.
LayoutUnit CalculateMinimumBlockSize(const NGMarginStrut& end_margin_strut); LayoutUnit CalculateMinimumBlockSize(const NGMarginStrut& end_margin_strut);
// Border + padding sum, resolved from the node's computed style.
const NGBoxStrut border_padding_; const NGBoxStrut border_padding_;
// Border + scrollbar + padding sum for the fragment to be generated (most
// importantly, for non-first fragments, leading block border + scrollbar +
// padding is zero).
NGBoxStrut border_scrollbar_padding_; NGBoxStrut border_scrollbar_padding_;
LogicalSize child_available_size_; LogicalSize child_available_size_;
......
...@@ -95,6 +95,7 @@ NGColumnLayoutAlgorithm::NGColumnLayoutAlgorithm( ...@@ -95,6 +95,7 @@ NGColumnLayoutAlgorithm::NGColumnLayoutAlgorithm(
params.fragment_geometry.padding), params.fragment_geometry.padding),
border_scrollbar_padding_(border_padding_ + border_scrollbar_padding_(border_padding_ +
params.fragment_geometry.scrollbar) { params.fragment_geometry.scrollbar) {
AdjustForFragmentation(BreakToken(), &border_scrollbar_padding_);
container_builder_.SetIsNewFormattingContext( container_builder_.SetIsNewFormattingContext(
params.space.IsNewFormattingContext()); params.space.IsNewFormattingContext());
container_builder_.SetInitialFragmentGeometry(params.fragment_geometry); container_builder_.SetInitialFragmentGeometry(params.fragment_geometry);
...@@ -135,9 +136,7 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::Layout() { ...@@ -135,9 +136,7 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::Layout() {
container_builder_.SetIsBlockFragmentationContextRoot(); container_builder_.SetIsBlockFragmentationContextRoot();
// Omit leading border+padding+scrollbar for all fragments but the first. intrinsic_block_size_ = border_scrollbar_padding_.block_start;
if (!IsResumingLayout(BreakToken()))
intrinsic_block_size_ = border_scrollbar_padding_.block_start;
if (!LayoutChildren()) { if (!LayoutChildren()) {
// We need to discard this layout and do it again. We found an earlier break // We need to discard this layout and do it again. We found an earlier break
...@@ -376,8 +375,8 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::LayoutRow( ...@@ -376,8 +375,8 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::LayoutRow(
// fragmentation context. // fragmentation context.
if (is_constrained_by_outer_fragmentation_context_ && if (is_constrained_by_outer_fragmentation_context_ &&
column_size.block_size != kIndefiniteSize) { column_size.block_size != kIndefiniteSize) {
column_size.block_size -= ConsumedBlockSizeInContentBox( if (BreakToken())
border_scrollbar_padding_.block_start, BreakToken()); column_size.block_size -= BreakToken()->ConsumedBlockSize();
// Subtract the space already taken in the current fragment (spanners and // Subtract the space already taken in the current fragment (spanners and
// earlier column rows). // earlier column rows).
...@@ -858,14 +857,6 @@ LayoutUnit NGColumnLayoutAlgorithm::ConstrainColumnBlockSize( ...@@ -858,14 +857,6 @@ LayoutUnit NGColumnLayoutAlgorithm::ConstrainColumnBlockSize(
return size - extra; return size - extra;
} }
LayoutUnit NGColumnLayoutAlgorithm::CurrentContentBlockOffset() const {
// If we're past the block-start border and padding, this is simple:
if (IsResumingLayout(BreakToken()))
return intrinsic_block_size_;
// Otherwise subtract those.
return intrinsic_block_size_ - border_scrollbar_padding_.block_start;
}
void NGColumnLayoutAlgorithm::FinishAfterBreakBeforeSpanner( void NGColumnLayoutAlgorithm::FinishAfterBreakBeforeSpanner(
scoped_refptr<const NGBlockBreakToken> next_column_token) { scoped_refptr<const NGBlockBreakToken> next_column_token) {
// We broke before the spanner. We're done here. Take up the remaining space // We broke before the spanner. We're done here. Take up the remaining space
......
...@@ -62,7 +62,9 @@ class CORE_EXPORT NGColumnLayoutAlgorithm ...@@ -62,7 +62,9 @@ class CORE_EXPORT NGColumnLayoutAlgorithm
LayoutUnit current_column_size) const; LayoutUnit current_column_size) const;
LayoutUnit ConstrainColumnBlockSize(LayoutUnit size) const; LayoutUnit ConstrainColumnBlockSize(LayoutUnit size) const;
LayoutUnit CurrentContentBlockOffset() const; LayoutUnit CurrentContentBlockOffset() const {
return intrinsic_block_size_ - border_scrollbar_padding_.block_start;
}
// Finalize layout after breaking before a spanner. // Finalize layout after breaking before a spanner.
void FinishAfterBreakBeforeSpanner( void FinishAfterBreakBeforeSpanner(
...@@ -87,8 +89,14 @@ class CORE_EXPORT NGColumnLayoutAlgorithm ...@@ -87,8 +89,14 @@ class CORE_EXPORT NGColumnLayoutAlgorithm
// When set, this will specify where to break before or inside. // When set, this will specify where to break before or inside.
const NGEarlyBreak* early_break_ = nullptr; const NGEarlyBreak* early_break_ = nullptr;
// Border + padding sum, resolved from the node's computed style.
const NGBoxStrut border_padding_; const NGBoxStrut border_padding_;
const NGBoxStrut border_scrollbar_padding_;
// Border + scrollbar + padding sum for the fragment to be generated (most
// importantly, for non-first fragments, leading block border + scrollbar +
// padding is zero).
NGBoxStrut border_scrollbar_padding_;
LogicalSize content_box_size_; LogicalSize content_box_size_;
int used_column_count_; int used_column_count_;
LayoutUnit column_inline_size_; LayoutUnit column_inline_size_;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_FRAGMENTATION_UTILS_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_FRAGMENTATION_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_FRAGMENTATION_UTILS_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_FRAGMENTATION_UTILS_H_
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_box_strut.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_break_token.h" #include "third_party/blink/renderer/core/layout/ng/ng_block_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_node.h" #include "third_party/blink/renderer/core/layout/ng/ng_block_node.h"
#include "third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h" #include "third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h"
...@@ -72,6 +73,18 @@ inline LayoutUnit FragmentainerSpaceAtBfcStart(const NGConstraintSpace& space) { ...@@ -72,6 +73,18 @@ inline LayoutUnit FragmentainerSpaceAtBfcStart(const NGConstraintSpace& space) {
return space.FragmentainerBlockSize() - space.FragmentainerOffsetAtBfc(); return space.FragmentainerBlockSize() - space.FragmentainerOffsetAtBfc();
} }
// Adjust the border+scrollbar+padding strut for fragmentation. Leading
// border+scrollbar+padding should only take up space in the first fragment
// generated from a node.
inline void AdjustForFragmentation(const NGBlockBreakToken* break_token,
NGBoxStrut* border_scrollbar_padding) {
if (LIKELY(!break_token))
return;
if (break_token->IsBreakBefore())
return;
border_scrollbar_padding->block_start = LayoutUnit();
}
// Set up a child's constraint space builder for block fragmentation. The child // Set up a child's constraint space builder for block fragmentation. The child
// participates in the same fragmentation context as parent_space. If the child // participates in the same fragmentation context as parent_space. If the child
// establishes a new formatting context, new_bfc_block_offset must be set to the // establishes a new formatting context, new_bfc_block_offset must be set to the
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/optional.h" #include "base/optional.h"
#include "third_party/blink/renderer/core/layout/layout_box.h" #include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_table_cell.h" #include "third_party/blink/renderer/core/layout/layout_table_cell.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/ng_block_node.h" #include "third_party/blink/renderer/core/layout/ng/ng_block_node.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"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space_builder.h" #include "third_party/blink/renderer/core/layout/ng/ng_constraint_space_builder.h"
...@@ -1272,18 +1271,4 @@ base::Optional<MinMaxSize> CalculateMinMaxSizesIgnoringChildren( ...@@ -1272,18 +1271,4 @@ base::Optional<MinMaxSize> CalculateMinMaxSizesIgnoringChildren(
return base::nullopt; return base::nullopt;
} }
LayoutUnit ConsumedBlockSizeInContentBox(
LayoutUnit border_scrollbar_padding_block_start,
const NGBlockBreakToken* break_token) {
if (!break_token)
return LayoutUnit();
LayoutUnit consumed_block_size =
break_token->ConsumedBlockSize() - border_scrollbar_padding_block_start;
// There are no valid break points inside borders and padding, but if the
// fragmentainer is actually shorter than the space taken up bby borders
// and/or padding, we may end up slicing them into multiple fragmentainers
// anyway - in which case the size we just calculated becomes negative.
return consumed_block_size.ClampNegativeToZero();
}
} // namespace blink } // namespace blink
...@@ -24,7 +24,6 @@ class ComputedStyle; ...@@ -24,7 +24,6 @@ class ComputedStyle;
class Length; class Length;
struct MinMaxSizeInput; struct MinMaxSizeInput;
class NGConstraintSpace; class NGConstraintSpace;
class NGBlockBreakToken;
class NGBlockNode; class NGBlockNode;
class NGLayoutInputNode; class NGLayoutInputNode;
...@@ -483,11 +482,6 @@ base::Optional<MinMaxSize> CalculateMinMaxSizesIgnoringChildren( ...@@ -483,11 +482,6 @@ base::Optional<MinMaxSize> CalculateMinMaxSizesIgnoringChildren(
const NGBoxStrut& border_scrollbar_padding, const NGBoxStrut& border_scrollbar_padding,
NGMinMaxSizeType); NGMinMaxSizeType);
// Return the sum of the block-size of the content-boxes in all preceding
// fragments.
LayoutUnit ConsumedBlockSizeInContentBox(
LayoutUnit border_scrollbar_padding_block_start,
const NGBlockBreakToken*);
} // namespace blink } // namespace blink
......
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