Commit 727d4fe5 authored by Morten Stenshorne's avatar Morten Stenshorne Committed by Commit Bot

[LayoutNG] Pass the fragment builder to the block break token constructor.

The list of parameters was getting too long.

Change-Id: Ia42d102b9333dc37deed7ea8450e4ff42abc3f6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346385Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Morten Stenshorne <mstensho@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796509}
parent 8a8a9201
......@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/layout/ng/ng_block_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_break_token.h"
#include "third_party/blink/renderer/core/layout/ng/ng_box_fragment_builder.h"
#include "third_party/blink/renderer/platform/wtf/size_assertions.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
......@@ -20,24 +21,30 @@ ASSERT_SIZE(NGBlockBreakToken, SameSizeAsNGBlockBreakToken);
} // namespace
NGBlockBreakToken::NGBlockBreakToken(
PassKey key,
NGLayoutInputNode node,
LayoutUnit consumed_block_size,
unsigned sequence_number,
const NGBreakTokenVector& child_break_tokens,
NGBreakAppeal break_appeal,
bool has_seen_all_children,
bool is_at_block_end)
: NGBreakToken(kBlockBreakToken, kUnfinished, node),
consumed_block_size_(consumed_block_size),
sequence_number_(sequence_number),
num_children_(child_break_tokens.size()) {
break_appeal_ = break_appeal;
has_seen_all_children_ = has_seen_all_children;
is_at_block_end_ = is_at_block_end;
for (wtf_size_t i = 0; i < child_break_tokens.size(); ++i) {
child_break_tokens_[i] = child_break_tokens[i].get();
scoped_refptr<NGBlockBreakToken> NGBlockBreakToken::Create(
const NGBoxFragmentBuilder& builder) {
// We store the children list inline in the break token as a flexible
// array. Therefore, we need to make sure to allocate enough space for that
// array here, which requires a manual allocation + placement new.
void* data = ::WTF::Partitions::FastMalloc(
sizeof(NGBlockBreakToken) +
builder.child_break_tokens_.size() * sizeof(NGBreakToken*),
::WTF::GetStringWithTypeName<NGBlockBreakToken>());
new (data) NGBlockBreakToken(PassKey(), builder);
return base::AdoptRef(static_cast<NGBlockBreakToken*>(data));
}
NGBlockBreakToken::NGBlockBreakToken(PassKey key,
const NGBoxFragmentBuilder& builder)
: NGBreakToken(kBlockBreakToken, kUnfinished, builder.node_),
consumed_block_size_(builder.consumed_block_size_),
sequence_number_(builder.sequence_number_),
num_children_(builder.child_break_tokens_.size()) {
break_appeal_ = builder.break_appeal_;
has_seen_all_children_ = builder.has_seen_all_children_;
is_at_block_end_ = builder.is_at_block_end_;
for (wtf_size_t i = 0; i < builder.child_break_tokens_.size(); ++i) {
child_break_tokens_[i] = builder.child_break_tokens_[i].get();
child_break_tokens_[i]->AddRef();
}
}
......
......@@ -14,6 +14,7 @@
namespace blink {
class NGBoxFragmentBuilder;
class NGInlineBreakToken;
// Represents a break token for a block node.
......@@ -24,27 +25,7 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken {
//
// The node is NGBlockNode, or any other NGLayoutInputNode that produces
// anonymous box.
static scoped_refptr<NGBlockBreakToken> Create(
NGLayoutInputNode node,
LayoutUnit consumed_block_size,
unsigned sequence_number,
const NGBreakTokenVector& child_break_tokens,
NGBreakAppeal break_appeal,
bool has_seen_all_children,
bool is_at_block_end) {
// We store the children list inline in the break token as a flexible
// array. Therefore, we need to make sure to allocate enough space for
// that array here, which requires a manual allocation + placement new.
void* data = ::WTF::Partitions::FastMalloc(
sizeof(NGBlockBreakToken) +
child_break_tokens.size() * sizeof(NGBreakToken*),
::WTF::GetStringWithTypeName<NGBlockBreakToken>());
new (data)
NGBlockBreakToken(PassKey(), node, consumed_block_size, sequence_number,
child_break_tokens, break_appeal,
has_seen_all_children, is_at_block_end);
return base::AdoptRef(static_cast<NGBlockBreakToken*>(data));
}
static scoped_refptr<NGBlockBreakToken> Create(const NGBoxFragmentBuilder&);
// Creates a break token for a node that needs to produce its first fragment
// in the next fragmentainer. In this case we create a break token for a node
......@@ -145,14 +126,7 @@ 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(PassKey,
NGLayoutInputNode node,
LayoutUnit consumed_block_size,
unsigned sequence_number,
const NGBreakTokenVector& child_break_tokens,
NGBreakAppeal break_appeal,
bool has_seen_all_children,
bool is_at_block_end);
NGBlockBreakToken(PassKey, const NGBoxFragmentBuilder&);
explicit NGBlockBreakToken(PassKey, NGLayoutInputNode node);
......
......@@ -7,11 +7,30 @@
#include "testing/gtest/include/gtest/gtest.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_box_fragment_builder.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_layout_test.h"
namespace blink {
namespace {
scoped_refptr<const NGBlockBreakToken> CreateBreakToken(
NGLayoutInputNode node,
const NGBreakTokenVector* child_break_tokens = nullptr,
bool has_seen_all_children = false) {
NGBoxFragmentBuilder builder(
node, &node.Style(), /* space */ nullptr,
WritingDirectionMode(WritingMode::kHorizontalTb, TextDirection::kLtr));
if (has_seen_all_children)
builder.SetHasSeenAllChildren();
if (child_break_tokens) {
for (scoped_refptr<const NGBreakToken> token : *child_break_tokens)
builder.AddBreakToken(token);
}
return NGBlockBreakToken::Create(builder);
}
using NGBlockChildIteratorTest = NGLayoutTest;
TEST_F(NGBlockChildIteratorTest, NullFirstChild) {
......@@ -57,21 +76,14 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
NGLayoutInputNode node4 = node3.NextSibling();
NGBreakTokenVector empty_tokens_list;
scoped_refptr<NGBreakToken> child_token1 = NGBlockBreakToken::Create(
node1, LayoutUnit(), 0, empty_tokens_list, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
scoped_refptr<NGBreakToken> child_token2 = NGBlockBreakToken::Create(
node2, LayoutUnit(), 0, empty_tokens_list, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
scoped_refptr<NGBreakToken> child_token3 = NGBlockBreakToken::Create(
node3, LayoutUnit(), 0, empty_tokens_list, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
scoped_refptr<const NGBreakToken> child_token1 = CreateBreakToken(node1);
scoped_refptr<const NGBreakToken> child_token2 = CreateBreakToken(node2);
scoped_refptr<const NGBreakToken> child_token3 = CreateBreakToken(node3);
NGBreakTokenVector child_break_tokens;
child_break_tokens.push_back(child_token1);
scoped_refptr<NGBlockBreakToken> parent_token = NGBlockBreakToken::Create(
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
scoped_refptr<const NGBlockBreakToken> parent_token =
CreateBreakToken(container, &child_break_tokens);
NGBlockChildIterator iterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()),
......@@ -85,9 +97,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
child_break_tokens.clear();
child_break_tokens.push_back(child_token1);
child_break_tokens.push_back(child_token2);
parent_token = NGBlockBreakToken::Create(
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
parent_token = CreateBreakToken(container, &child_break_tokens);
iterator = NGBlockChildIterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()),
......@@ -102,9 +112,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
child_break_tokens.clear();
child_break_tokens.push_back(child_token2);
child_break_tokens.push_back(child_token3);
parent_token = NGBlockBreakToken::Create(
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
parent_token = CreateBreakToken(container, &child_break_tokens);
iterator = NGBlockChildIterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node2, child_token2.get()),
......@@ -118,9 +126,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
child_break_tokens.clear();
child_break_tokens.push_back(child_token1);
child_break_tokens.push_back(child_token3);
parent_token = NGBlockBreakToken::Create(
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
parent_token = CreateBreakToken(container, &child_break_tokens);
iterator = NGBlockChildIterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()),
......@@ -143,16 +149,12 @@ TEST_F(NGBlockChildIteratorTest, SeenAllChildren) {
NGBlockNode(ToLayoutBox(GetLayoutObjectByElementId("container")));
NGLayoutInputNode node1 = container.FirstChild();
NGBreakTokenVector empty_tokens_list;
scoped_refptr<NGBreakToken> child_token1 = NGBlockBreakToken::Create(
node1, LayoutUnit(), 0, empty_tokens_list, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
scoped_refptr<const NGBlockBreakToken> child_token1 = CreateBreakToken(node1);
NGBreakTokenVector child_break_tokens;
child_break_tokens.push_back(child_token1);
scoped_refptr<NGBlockBreakToken> parent_token = NGBlockBreakToken::Create(
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ true, /* is_at_block_end */ false);
scoped_refptr<const NGBlockBreakToken> parent_token = CreateBreakToken(
container, &child_break_tokens, /* has_seen_all_children*/ true);
// We have a break token for #child1, but have seen all children. This happens
// e.g. when #child1 has overflow into a new fragmentainer, while #child2 was
......@@ -164,10 +166,8 @@ TEST_F(NGBlockChildIteratorTest, SeenAllChildren) {
ASSERT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr),
iterator.NextChild());
child_break_tokens.clear();
parent_token = NGBlockBreakToken::Create(
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ true, /* is_at_block_end */ false);
parent_token = CreateBreakToken(container, /* child_break_tokens */ nullptr,
/* has_seen_all_children*/ true);
// We have no break tokens, but have seen all children. This happens e.g. when
// we have a large container with fixed block-size, with empty space at the
......
......@@ -328,11 +328,8 @@ scoped_refptr<const NGLayoutResult> NGBoxFragmentBuilder::ToBoxFragment(
child_break_tokens_.push_back(std::move(token));
}
}
if (DidBreakSelf() || HasChildBreakInside()) {
break_token_ = NGBlockBreakToken::Create(
node_, consumed_block_size_, sequence_number_, child_break_tokens_,
break_appeal_, has_seen_all_children_, is_at_block_end_);
}
if (DidBreakSelf() || HasChildBreakInside())
break_token_ = NGBlockBreakToken::Create(*this);
}
if (!has_floating_descendants_for_paint_ && items_builder_) {
......
......@@ -585,6 +585,7 @@ class CORE_EXPORT NGBoxFragmentBuilder final
bool block_size_is_for_all_fragments_ = false;
#endif
friend class NGBlockBreakToken;
friend class NGPhysicalBoxFragment;
friend class NGLayoutResult;
};
......
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