Skip to content

Commit

Permalink
[LayoutNG] Rename used_block_size to consumed_block_size for fragment…
Browse files Browse the repository at this point in the history
…ation.

"Used" is such an overloaded term. Although "consumed" is a synonym, I
think it's still less ambiguous and also makes the concept of "fooed
block size" more recognizable. This is also more similar to the the term
that Microsoft use when they talk about block fragmentation ("consumed
height" is common).

Change-Id: I64d24b0d2423a34fb8a0ea6f39a172dccf53949c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1746249
Reviewed-by: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685860}
  • Loading branch information
mstensho authored and Commit Bot committed Aug 10, 2019
1 parent 10e48c5 commit afca524
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ static_assert(sizeof(NGBlockBreakToken) == sizeof(SameSizeAsNGBlockBreakToken),

NGBlockBreakToken::NGBlockBreakToken(
NGLayoutInputNode node,
LayoutUnit used_block_size,
LayoutUnit consumed_block_size,
const NGBreakTokenVector& child_break_tokens,
bool has_last_resort_break,
bool has_seen_all_children)
: NGBreakToken(kBlockBreakToken, kUnfinished, node),
used_block_size_(used_block_size),
consumed_block_size_(consumed_block_size),
num_children_(child_break_tokens.size()) {
has_last_resort_break_ = has_last_resort_break;
has_seen_all_children_ = has_seen_all_children;
Expand Down Expand Up @@ -71,8 +71,8 @@ const NGInlineBreakToken* NGBlockBreakToken::InlineBreakTokenFor(
String NGBlockBreakToken::ToString() const {
StringBuilder string_builder;
string_builder.Append(NGBreakToken::ToString());
string_builder.Append(" used:");
string_builder.Append(used_block_size_.ToString());
string_builder.Append(" consumed:");
string_builder.Append(consumed_block_size_.ToString());
string_builder.Append("px");
return string_builder.ToString();
}
Expand Down
20 changes: 11 additions & 9 deletions third_party/blink/renderer/core/layout/ng/ng_block_break_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken {
// anonymous box.
static scoped_refptr<NGBlockBreakToken> Create(
NGLayoutInputNode node,
LayoutUnit used_block_size,
LayoutUnit consumed_block_size,
const NGBreakTokenVector& child_break_tokens,
bool has_last_resort_break,
bool has_seen_all_children) {
Expand All @@ -37,7 +37,7 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken {
sizeof(NGBlockBreakToken) +
child_break_tokens.size() * sizeof(NGBreakToken*),
::WTF::GetStringWithTypeName<NGBlockBreakToken>());
new (data) NGBlockBreakToken(node, used_block_size, child_break_tokens,
new (data) NGBlockBreakToken(node, consumed_block_size, child_break_tokens,
has_last_resort_break, has_seen_all_children);
return base::AdoptRef(static_cast<NGBlockBreakToken*>(data));
}
Expand All @@ -57,12 +57,14 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken {
token->Release();
}

// Represents the amount of block size used in previous fragments.
// Represents the amount of block-size consumed by previous fragments.
//
// E.g. if the layout block specifies a block size of 200px, and the previous
// fragments of this block used 150px (used block size), the next fragment
// should have a size of 50px (assuming no additional fragmentation).
LayoutUnit UsedBlockSize() const { return used_block_size_; }
// E.g. if the node specifies a block-size of 200px, and the previous
// fragments generated for this box consumed 150px in total (which is what
// this method would return then), there's 50px left to consume. The next
// fragment will become 50px tall, assuming no additional fragmentation (if
// the fragmentainer is shorter than 50px, for instance).
LayoutUnit ConsumedBlockSize() const { return consumed_block_size_; }

// Return true if this is a break token that was produced without any
// "preceding" fragment. This happens when we determine that the first
Expand Down Expand Up @@ -102,14 +104,14 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken {
// Must only be called from Create(), because it assumes that enough space
// has been allocated in the flexible array to store the children.
NGBlockBreakToken(NGLayoutInputNode node,
LayoutUnit used_block_size,
LayoutUnit consumed_block_size,
const NGBreakTokenVector& child_break_tokens,
bool has_last_resort_break,
bool has_seen_all_children);

explicit NGBlockBreakToken(NGLayoutInputNode node);

LayoutUnit used_block_size_;
LayoutUnit consumed_block_size_;

wtf_size_t num_children_;
// This must be the last member, because it is a flexible array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1841,15 +1841,15 @@ void NGBlockLayoutAlgorithm::FinalizeForFragmentation() {
container_builder_.SetDidBreak();
}

LayoutUnit used_block_size =
BreakToken() ? BreakToken()->UsedBlockSize() : LayoutUnit();
LayoutUnit consumed_block_size =
BreakToken() ? BreakToken()->ConsumedBlockSize() : LayoutUnit();
LayoutUnit block_size =
ComputeBlockSizeForFragment(ConstraintSpace(), Node(), border_padding_,
used_block_size + intrinsic_block_size_);
consumed_block_size + intrinsic_block_size_);

block_size -= used_block_size;
block_size -= consumed_block_size;
DCHECK_GE(block_size, LayoutUnit())
<< "Adding and subtracting the used_block_size shouldn't leave the "
<< "Adding and subtracting the consumed_block_size shouldn't leave the "
"block_size for this fragment smaller than zero.";

LayoutUnit space_left = FragmentainerSpaceAvailable();
Expand All @@ -1871,8 +1871,8 @@ void NGBlockLayoutAlgorithm::FinalizeForFragmentation() {
if (container_builder_.DidBreak()) {
// One of our children broke. Even if we fit within the remaining space we
// need to prepare a break token.
container_builder_.SetUsedBlockSize(std::min(space_left, block_size) +
used_block_size);
container_builder_.SetConsumedBlockSize(std::min(space_left, block_size) +
consumed_block_size);
container_builder_.SetBlockSize(std::min(space_left, block_size));
container_builder_.SetIntrinsicBlockSize(space_left);

Expand All @@ -1895,7 +1895,7 @@ void NGBlockLayoutAlgorithm::FinalizeForFragmentation() {

if (block_size > space_left) {
// Need a break inside this block.
container_builder_.SetUsedBlockSize(space_left + used_block_size);
container_builder_.SetConsumedBlockSize(space_left + consumed_block_size);
container_builder_.SetDidBreak();
container_builder_.SetBlockSize(space_left);
container_builder_.SetIntrinsicBlockSize(space_left);
Expand All @@ -1904,7 +1904,7 @@ void NGBlockLayoutAlgorithm::FinalizeForFragmentation() {
}

// The end of the block fits in the current fragmentainer.
container_builder_.SetUsedBlockSize(used_block_size + block_size);
container_builder_.SetConsumedBlockSize(consumed_block_size + block_size);
container_builder_.SetBlockSize(block_size);
container_builder_.SetIntrinsicBlockSize(intrinsic_block_size_);
}
Expand Down
8 changes: 4 additions & 4 deletions third_party/blink/renderer/core/layout/ng/ng_block_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
<< "Variable fragment inline size not supported";
LayoutUnit logical_height = fragment_logical_size.block_size;
if (previous_break_token)
logical_height += previous_break_token->UsedBlockSize();
logical_height += previous_break_token->ConsumedBlockSize();
box_->SetLogicalHeight(logical_height);
intrinsic_content_logical_height = box_->IntrinsicContentLogicalHeight();
}
Expand Down Expand Up @@ -753,7 +753,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(

// TODO(mstensho): writing modes
if (previous_break_token)
offset_from_start.top = previous_break_token->UsedBlockSize();
offset_from_start.top = previous_break_token->ConsumedBlockSize();
}
PlaceChildrenInLayoutBox(physical_fragment, offset_from_start);
}
Expand All @@ -762,7 +762,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
if (LIKELY(block && is_last_fragment)) {
LayoutUnit intrinsic_block_size = layout_result.IntrinsicBlockSize();
if (UNLIKELY(previous_break_token))
intrinsic_block_size += previous_break_token->UsedBlockSize();
intrinsic_block_size += previous_break_token->ConsumedBlockSize();

#if DCHECK_IS_ON()
block->CheckPositionedObjectsNeedLayout();
Expand Down Expand Up @@ -847,7 +847,7 @@ void NGBlockNode::PlaceChildrenInFlowThread(
const auto* column = To<NGPhysicalBoxFragment>(child.get());
PlaceChildrenInLayoutBox(*column, offset);
if (const auto* token = To<NGBlockBreakToken>(column->BreakToken()))
flowthread_offset = token->UsedBlockSize();
flowthread_offset = token->ConsumedBlockSize();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ scoped_refptr<const NGLayoutResult> NGBoxFragmentBuilder::ToBoxFragment(
}
if (did_break_) {
break_token_ = NGBlockBreakToken::Create(
node_, used_block_size_, child_break_tokens_, has_last_resort_break_,
has_seen_all_children_);
node_, consumed_block_size_, child_break_tokens_,
has_last_resort_break_, has_seen_all_children_);
}
}

Expand Down Expand Up @@ -305,7 +305,7 @@ void NGBoxFragmentBuilder::ComputeInlineContainerFragments(
void NGBoxFragmentBuilder::CheckNoBlockFragmentation() const {
DCHECK(!did_break_);
DCHECK(!has_forced_break_);
DCHECK_EQ(used_block_size_, LayoutUnit());
DCHECK_EQ(consumed_block_size_, LayoutUnit());
DCHECK_EQ(minimal_space_shortage_, LayoutUnit::Max());
DCHECK_EQ(initial_break_before_, EBreakBetween::kAuto);
DCHECK_EQ(previous_break_after_, EBreakBetween::kAuto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ class CORE_EXPORT NGBoxFragmentBuilder final
const NGLogicalStaticPosition&,
const LayoutInline* inline_container);

// Set how much of the block size we've used so far for this box.
NGBoxFragmentBuilder& SetUsedBlockSize(LayoutUnit used_block_size) {
used_block_size_ = used_block_size;
// Set how much of the block-size we've used so far for this box. This will be
// the sum of the block-size of all previous fragments PLUS the one we're
// building now.
NGBoxFragmentBuilder& SetConsumedBlockSize(LayoutUnit size) {
consumed_block_size_ = size;
return *this;
}

Expand Down Expand Up @@ -264,7 +266,7 @@ class CORE_EXPORT NGBoxFragmentBuilder final
bool has_forced_break_ = false;
bool is_new_fc_ = false;
bool has_seen_all_children_ = false;
LayoutUnit used_block_size_;
LayoutUnit consumed_block_size_;

LayoutUnit minimal_space_shortage_ = LayoutUnit::Max();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::Layout() {
// Figure out how much space we've already been able to process in previous
// fragments, if this multicol container participates in an outer
// fragmentation context.
LayoutUnit previously_used_block_size;
LayoutUnit previously_consumed_block_size;
if (const auto* token = BreakToken())
previously_used_block_size = token->UsedBlockSize();
previously_consumed_block_size = token->ConsumedBlockSize();

bool needs_more_fragments_in_outer = false;
if (ConstraintSpace().HasBlockFragmentation()) {
// Subtract the space for content we've processed in previous fragments.
column_size.block_size -= previously_used_block_size;
column_size.block_size -= previously_consumed_block_size;

// Check if we can fit everything (that's remaining), block-wise, within the
// current outer fragmentainer. If we can't, we need to adjust the block
Expand Down Expand Up @@ -203,17 +203,17 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::Layout() {
// Calculate how much block space we've been able to process so far, in
// this fragment and all previous fragments generated for this multicol
// container.
LayoutUnit used_block_size = fragment_block_size;
LayoutUnit consumed_block_size = fragment_block_size;
// If this isn't the first fragment, add the amount that we were able to
// process in previous fragments. Otherwise, we're the first fragment,
// and we have to add leading border+padding+scrollbar to the fragment
// size (which would otherwise only be the size of the columns), since
// that's put at the start of the first fragment.
if (previously_used_block_size)
used_block_size += previously_used_block_size;
if (previously_consumed_block_size)
consumed_block_size += previously_consumed_block_size;
else
fragment_block_size += border_scrollbar_padding_.block_start;
container_builder_.SetUsedBlockSize(used_block_size);
container_builder_.SetConsumedBlockSize(consumed_block_size);
container_builder_.SetBlockSize(fragment_block_size);
container_builder_.SetDidBreak();
break;
Expand Down Expand Up @@ -266,7 +266,7 @@ scoped_refptr<const NGLayoutResult> NGColumnLayoutAlgorithm::Layout() {
} else {
// TODO(mstensho): end border and padding may overflow the parent
// fragmentainer, and we should avoid that.
block_size = border_box_size.block_size - previously_used_block_size;
block_size = border_box_size.block_size - previously_consumed_block_size;
}
container_builder_.SetBlockSize(block_size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ NGPhysicalBoxFragment::NGPhysicalBoxFragment(
has_padding_ = !padding.IsZero();
if (has_padding_)
*const_cast<NGPhysicalBoxStrut*>(ComputePaddingAddress()) = padding;
// used_block_size_ is only updated if we're in block fragmentation. Otherwise
// it will always be 0.
is_first_for_node_ = builder->used_block_size_ <= builder->size_.block_size;
// consumed_block_size_ is only updated if we're in block
// fragmentation. Otherwise it will always be 0.
is_first_for_node_ =
builder->consumed_block_size_ <= builder->size_.block_size;
is_fieldset_container_ = builder->is_fieldset_container_;
is_legacy_layout_root_ = builder->is_legacy_layout_root_;
border_edge_ = builder->border_edges_.ToPhysical(builder->GetWritingMode());
Expand Down

0 comments on commit afca524

Please sign in to comment.