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 @@ ...@@ -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/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/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/size_assertions.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
...@@ -20,24 +21,30 @@ ASSERT_SIZE(NGBlockBreakToken, SameSizeAsNGBlockBreakToken); ...@@ -20,24 +21,30 @@ ASSERT_SIZE(NGBlockBreakToken, SameSizeAsNGBlockBreakToken);
} // namespace } // namespace
NGBlockBreakToken::NGBlockBreakToken( scoped_refptr<NGBlockBreakToken> NGBlockBreakToken::Create(
PassKey key, const NGBoxFragmentBuilder& builder) {
NGLayoutInputNode node, // We store the children list inline in the break token as a flexible
LayoutUnit consumed_block_size, // array. Therefore, we need to make sure to allocate enough space for that
unsigned sequence_number, // array here, which requires a manual allocation + placement new.
const NGBreakTokenVector& child_break_tokens, void* data = ::WTF::Partitions::FastMalloc(
NGBreakAppeal break_appeal, sizeof(NGBlockBreakToken) +
bool has_seen_all_children, builder.child_break_tokens_.size() * sizeof(NGBreakToken*),
bool is_at_block_end) ::WTF::GetStringWithTypeName<NGBlockBreakToken>());
: NGBreakToken(kBlockBreakToken, kUnfinished, node), new (data) NGBlockBreakToken(PassKey(), builder);
consumed_block_size_(consumed_block_size), return base::AdoptRef(static_cast<NGBlockBreakToken*>(data));
sequence_number_(sequence_number), }
num_children_(child_break_tokens.size()) {
break_appeal_ = break_appeal; NGBlockBreakToken::NGBlockBreakToken(PassKey key,
has_seen_all_children_ = has_seen_all_children; const NGBoxFragmentBuilder& builder)
is_at_block_end_ = is_at_block_end; : NGBreakToken(kBlockBreakToken, kUnfinished, builder.node_),
for (wtf_size_t i = 0; i < child_break_tokens.size(); ++i) { consumed_block_size_(builder.consumed_block_size_),
child_break_tokens_[i] = child_break_tokens[i].get(); 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(); child_break_tokens_[i]->AddRef();
} }
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
namespace blink { namespace blink {
class NGBoxFragmentBuilder;
class NGInlineBreakToken; class NGInlineBreakToken;
// Represents a break token for a block node. // Represents a break token for a block node.
...@@ -24,27 +25,7 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken { ...@@ -24,27 +25,7 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken {
// //
// The node is NGBlockNode, or any other NGLayoutInputNode that produces // The node is NGBlockNode, or any other NGLayoutInputNode that produces
// anonymous box. // anonymous box.
static scoped_refptr<NGBlockBreakToken> Create( static scoped_refptr<NGBlockBreakToken> Create(const NGBoxFragmentBuilder&);
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));
}
// Creates a break token for a node that needs to produce its first fragment // 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 // 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 { ...@@ -145,14 +126,7 @@ class CORE_EXPORT NGBlockBreakToken final : public NGBreakToken {
// Must only be called from Create(), because it assumes that enough space // Must only be called from Create(), because it assumes that enough space
// has been allocated in the flexible array to store the children. // has been allocated in the flexible array to store the children.
NGBlockBreakToken(PassKey, NGBlockBreakToken(PassKey, const NGBoxFragmentBuilder&);
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);
explicit NGBlockBreakToken(PassKey, NGLayoutInputNode node); explicit NGBlockBreakToken(PassKey, NGLayoutInputNode node);
......
...@@ -7,11 +7,30 @@ ...@@ -7,11 +7,30 @@
#include "testing/gtest/include/gtest/gtest.h" #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_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_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" #include "third_party/blink/renderer/core/layout/ng/ng_layout_test.h"
namespace blink { namespace blink {
namespace { 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; using NGBlockChildIteratorTest = NGLayoutTest;
TEST_F(NGBlockChildIteratorTest, NullFirstChild) { TEST_F(NGBlockChildIteratorTest, NullFirstChild) {
...@@ -57,21 +76,14 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) { ...@@ -57,21 +76,14 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
NGLayoutInputNode node4 = node3.NextSibling(); NGLayoutInputNode node4 = node3.NextSibling();
NGBreakTokenVector empty_tokens_list; NGBreakTokenVector empty_tokens_list;
scoped_refptr<NGBreakToken> child_token1 = NGBlockBreakToken::Create( scoped_refptr<const NGBreakToken> child_token1 = CreateBreakToken(node1);
node1, LayoutUnit(), 0, empty_tokens_list, kBreakAppealPerfect, scoped_refptr<const NGBreakToken> child_token2 = CreateBreakToken(node2);
/* has_seen_all_children */ false, /* is_at_block_end */ false); scoped_refptr<const NGBreakToken> child_token3 = CreateBreakToken(node3);
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);
NGBreakTokenVector child_break_tokens; NGBreakTokenVector child_break_tokens;
child_break_tokens.push_back(child_token1); child_break_tokens.push_back(child_token1);
scoped_refptr<NGBlockBreakToken> parent_token = NGBlockBreakToken::Create( scoped_refptr<const NGBlockBreakToken> parent_token =
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect, CreateBreakToken(container, &child_break_tokens);
/* has_seen_all_children */ false, /* is_at_block_end */ false);
NGBlockChildIterator iterator(node1, parent_token.get()); NGBlockChildIterator iterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()), ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()),
...@@ -85,9 +97,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) { ...@@ -85,9 +97,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
child_break_tokens.clear(); child_break_tokens.clear();
child_break_tokens.push_back(child_token1); child_break_tokens.push_back(child_token1);
child_break_tokens.push_back(child_token2); child_break_tokens.push_back(child_token2);
parent_token = NGBlockBreakToken::Create( parent_token = CreateBreakToken(container, &child_break_tokens);
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
iterator = NGBlockChildIterator(node1, parent_token.get()); iterator = NGBlockChildIterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()), ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()),
...@@ -102,9 +112,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) { ...@@ -102,9 +112,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
child_break_tokens.clear(); child_break_tokens.clear();
child_break_tokens.push_back(child_token2); child_break_tokens.push_back(child_token2);
child_break_tokens.push_back(child_token3); child_break_tokens.push_back(child_token3);
parent_token = NGBlockBreakToken::Create( parent_token = CreateBreakToken(container, &child_break_tokens);
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
iterator = NGBlockChildIterator(node1, parent_token.get()); iterator = NGBlockChildIterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node2, child_token2.get()), ASSERT_EQ(NGBlockChildIterator::Entry(node2, child_token2.get()),
...@@ -118,9 +126,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) { ...@@ -118,9 +126,7 @@ TEST_F(NGBlockChildIteratorTest, BreakTokens) {
child_break_tokens.clear(); child_break_tokens.clear();
child_break_tokens.push_back(child_token1); child_break_tokens.push_back(child_token1);
child_break_tokens.push_back(child_token3); child_break_tokens.push_back(child_token3);
parent_token = NGBlockBreakToken::Create( parent_token = CreateBreakToken(container, &child_break_tokens);
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
iterator = NGBlockChildIterator(node1, parent_token.get()); iterator = NGBlockChildIterator(node1, parent_token.get());
ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()), ASSERT_EQ(NGBlockChildIterator::Entry(node1, child_token1.get()),
...@@ -143,16 +149,12 @@ TEST_F(NGBlockChildIteratorTest, SeenAllChildren) { ...@@ -143,16 +149,12 @@ TEST_F(NGBlockChildIteratorTest, SeenAllChildren) {
NGBlockNode(ToLayoutBox(GetLayoutObjectByElementId("container"))); NGBlockNode(ToLayoutBox(GetLayoutObjectByElementId("container")));
NGLayoutInputNode node1 = container.FirstChild(); NGLayoutInputNode node1 = container.FirstChild();
NGBreakTokenVector empty_tokens_list; scoped_refptr<const NGBlockBreakToken> child_token1 = CreateBreakToken(node1);
scoped_refptr<NGBreakToken> child_token1 = NGBlockBreakToken::Create(
node1, LayoutUnit(), 0, empty_tokens_list, kBreakAppealPerfect,
/* has_seen_all_children */ false, /* is_at_block_end */ false);
NGBreakTokenVector child_break_tokens; NGBreakTokenVector child_break_tokens;
child_break_tokens.push_back(child_token1); child_break_tokens.push_back(child_token1);
scoped_refptr<NGBlockBreakToken> parent_token = NGBlockBreakToken::Create( scoped_refptr<const NGBlockBreakToken> parent_token = CreateBreakToken(
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect, container, &child_break_tokens, /* has_seen_all_children*/ true);
/* has_seen_all_children */ true, /* is_at_block_end */ false);
// We have a break token for #child1, but have seen all children. This happens // 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 // e.g. when #child1 has overflow into a new fragmentainer, while #child2 was
...@@ -164,10 +166,8 @@ TEST_F(NGBlockChildIteratorTest, SeenAllChildren) { ...@@ -164,10 +166,8 @@ TEST_F(NGBlockChildIteratorTest, SeenAllChildren) {
ASSERT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr), ASSERT_EQ(NGBlockChildIterator::Entry(nullptr, nullptr),
iterator.NextChild()); iterator.NextChild());
child_break_tokens.clear(); parent_token = CreateBreakToken(container, /* child_break_tokens */ nullptr,
parent_token = NGBlockBreakToken::Create( /* has_seen_all_children*/ true);
container, LayoutUnit(), 0, child_break_tokens, kBreakAppealPerfect,
/* has_seen_all_children */ true, /* is_at_block_end */ false);
// We have no break tokens, but have seen all children. This happens e.g. when // 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 // we have a large container with fixed block-size, with empty space at the
......
...@@ -328,11 +328,8 @@ scoped_refptr<const NGLayoutResult> NGBoxFragmentBuilder::ToBoxFragment( ...@@ -328,11 +328,8 @@ scoped_refptr<const NGLayoutResult> NGBoxFragmentBuilder::ToBoxFragment(
child_break_tokens_.push_back(std::move(token)); child_break_tokens_.push_back(std::move(token));
} }
} }
if (DidBreakSelf() || HasChildBreakInside()) { if (DidBreakSelf() || HasChildBreakInside())
break_token_ = NGBlockBreakToken::Create( break_token_ = NGBlockBreakToken::Create(*this);
node_, consumed_block_size_, sequence_number_, child_break_tokens_,
break_appeal_, has_seen_all_children_, is_at_block_end_);
}
} }
if (!has_floating_descendants_for_paint_ && items_builder_) { if (!has_floating_descendants_for_paint_ && items_builder_) {
......
...@@ -585,6 +585,7 @@ class CORE_EXPORT NGBoxFragmentBuilder final ...@@ -585,6 +585,7 @@ class CORE_EXPORT NGBoxFragmentBuilder final
bool block_size_is_for_all_fragments_ = false; bool block_size_is_for_all_fragments_ = false;
#endif #endif
friend class NGBlockBreakToken;
friend class NGPhysicalBoxFragment; friend class NGPhysicalBoxFragment;
friend class NGLayoutResult; 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