Skip to content

Commit

Permalink
Modify Layout declarations to take extra parameters and return an enum.
Browse files Browse the repository at this point in the history
Review-Url: https://codereview.chromium.org/2489243002
Cr-Commit-Position: refs/heads/master@{#431215}
  • Loading branch information
shans authored and Commit bot committed Nov 10, 2016
1 parent ce75c6c commit e9f4dc8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(
DCHECK(style_);
}

bool NGBlockLayoutAlgorithm::Layout(NGPhysicalFragmentBase** out) {
NGLayoutStatus NGBlockLayoutAlgorithm::Layout(
NGFragmentBase*,
NGPhysicalFragmentBase** fragment_out,
NGBox**) {
switch (state_) {
case kStateInit: {
border_and_padding_ =
Expand Down Expand Up @@ -197,20 +200,20 @@ bool NGBlockLayoutAlgorithm::Layout(NGPhysicalFragmentBase** out) {
space_for_current_child_ = CreateConstraintSpaceForCurrentChild();

state_ = kStateChildLayout;
return false;
return NotFinished;
}
case kStateChildLayout: {
if (current_child_) {
if (!LayoutCurrentChild())
return false;
return NotFinished;
current_child_ = current_child_->NextSibling();
if (current_child_) {
space_for_current_child_ = CreateConstraintSpaceForCurrentChild();
return false;
return NotFinished;
}
}
state_ = kStateFinalize;
return false;
return NotFinished;
}
case kStateFinalize: {
content_size_ += border_and_padding_.block_end;
Expand All @@ -222,14 +225,14 @@ bool NGBlockLayoutAlgorithm::Layout(NGPhysicalFragmentBase** out) {
builder_->SetBlockSize(block_size)
.SetInlineOverflow(max_inline_size_)
.SetBlockOverflow(content_size_);
*out = builder_->ToFragment();
*fragment_out = builder_->ToFragment();
state_ = kStateInit;
return true;
return NewFragment;
}
};
NOTREACHED();
*out = nullptr;
return true;
*fragment_out = nullptr;
return NewFragment;
}

bool NGBlockLayoutAlgorithm::LayoutCurrentChild() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class CORE_EXPORT NGBlockLayoutAlgorithm : public NGLayoutAlgorithm {
NGConstraintSpace* space,
NGBreakToken* break_token = nullptr);

bool Layout(NGPhysicalFragmentBase**) override;
NGLayoutStatus Layout(NGFragmentBase*,
NGPhysicalFragmentBase**,
NGBox**) override;

DECLARE_VIRTUAL_TRACE();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NGBlockLayoutAlgorithmTest : public ::testing::Test {
NGBox* first_child) {
NGBlockLayoutAlgorithm algorithm(style_, first_child, space);
NGPhysicalFragmentBase* frag;
while (!algorithm.Layout(&frag))
while (!algorithm.Layout(nullptr, &frag, nullptr))
continue;
return toNGPhysicalFragment(frag);
}
Expand Down
6 changes: 3 additions & 3 deletions third_party/WebKit/Source/core/layout/ng/ng_box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool NGBox::Layout(const NGConstraintSpace* constraint_space,
}

NGPhysicalFragmentBase* fragment = nullptr;
if (!layout_algorithm_->Layout(&fragment))
if (!layout_algorithm_->Layout(nullptr, &fragment, nullptr))
return false;
fragment_ = toNGPhysicalFragment(fragment);

Expand Down Expand Up @@ -125,7 +125,7 @@ bool NGBox::ComputeMinAndMaxContentSizes(MinAndMaxContentSizes* sizes) {

// Have to synthesize this value.
NGPhysicalFragmentBase* physical_fragment;
while (!minmax_algorithm_->Layout(&physical_fragment))
while (!minmax_algorithm_->Layout(nullptr, &physical_fragment, nullptr))
continue;
NGFragment* fragment = new NGFragment(
FromPlatformWritingMode(Style()->getWritingMode()), Style()->direction(),
Expand All @@ -145,7 +145,7 @@ bool NGBox::ComputeMinAndMaxContentSizes(MinAndMaxContentSizes* sizes) {

minmax_algorithm_ =
new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space);
while (!minmax_algorithm_->Layout(&physical_fragment))
while (!minmax_algorithm_->Layout(nullptr, &physical_fragment, nullptr))
continue;

fragment = new NGFragment(FromPlatformWritingMode(Style()->getWritingMode()),
Expand Down
2 changes: 1 addition & 1 deletion third_party/WebKit/Source/core/layout/ng/ng_inline_box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool NGInlineBox::Layout(const NGConstraintSpace* constraint_space,
layout_algorithm_ = new NGTextLayoutAlgorithm(this, child_constraint_space);

NGPhysicalFragmentBase* fragment = nullptr;
if (!layout_algorithm_->Layout(&fragment))
if (!layout_algorithm_->Layout(nullptr, &fragment, nullptr))
return false;

// TODO(layout-dev): Implement copying of fragment data to LayoutObject tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ NGInlineLayoutAlgorithm::NGInlineLayoutAlgorithm(
DCHECK(style_);
}

bool NGInlineLayoutAlgorithm::Layout(NGPhysicalFragmentBase** out) {
NGLayoutStatus NGInlineLayoutAlgorithm::Layout(
NGFragmentBase*,
NGPhysicalFragmentBase** fragment_out,
NGBox**) {
NGFragmentBuilder builder(NGPhysicalFragmentBase::FragmentBox);

*out = builder.ToFragment();
return true;
*fragment_out = builder.ToFragment();
return NewFragment;
}

DEFINE_TRACE(NGInlineLayoutAlgorithm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class CORE_EXPORT NGInlineLayoutAlgorithm : public NGLayoutAlgorithm {
NGConstraintSpace* space,
NGBreakToken* break_token = nullptr);

bool Layout(NGPhysicalFragmentBase**) override;
NGLayoutStatus Layout(NGFragmentBase*,
NGPhysicalFragmentBase**,
NGBox**) override;

DECLARE_VIRTUAL_TRACE();

Expand Down
15 changes: 11 additions & 4 deletions third_party/WebKit/Source/core/layout/ng/ng_layout_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
namespace blink {

struct MinAndMaxContentSizes;
class NGBox;
class NGConstraintSpace;
class NGPhysicalFragmentBase;

enum NGLayoutStatus { NotFinished, ChildAlgorithmRequired, NewFragment };

// Base class for all LayoutNG algorithms.
class CORE_EXPORT NGLayoutAlgorithm
: public GarbageCollectedFinalized<NGLayoutAlgorithm> {
Expand All @@ -30,10 +33,14 @@ class CORE_EXPORT NGLayoutAlgorithm
// resulting layout information.
// This function can not be const because for interruptible layout, we have
// to be able to store state information.
// Returns true when done; when this function returns false, it has to be
// called again. The out parameter will only be set when this function
// returns true.
virtual bool Layout(NGPhysicalFragmentBase**) = 0;
// If this function returns NotFinished, it has to be called again.
// If it returns ChildAlgorithmRequired, the NGBox out parameter will
// be set with the NGBox that needs to be layed out next.
// If it returns NewFragment, the NGPhysicalFragmentBase out parameter
// will contain the new fragment.
virtual NGLayoutStatus Layout(NGFragmentBase*,
NGPhysicalFragmentBase**,
NGBox**) = 0;

enum MinAndMaxState { Success, Pending, NotImplemented };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ NGTextLayoutAlgorithm::NGTextLayoutAlgorithm(
DCHECK(inline_box_);
}

bool NGTextLayoutAlgorithm::Layout(NGPhysicalFragmentBase** out) {
NGLayoutStatus NGTextLayoutAlgorithm::Layout(
NGFragmentBase*,
NGPhysicalFragmentBase** fragment_out,
NGBox**) {
// TODO(layout-dev): implement.
*out = nullptr;
return true;
*fragment_out = nullptr;
return NewFragment;
}

DEFINE_TRACE(NGTextLayoutAlgorithm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class CORE_EXPORT NGTextLayoutAlgorithm : public NGLayoutAlgorithm {
NGConstraintSpace* space,
NGBreakToken* break_token = nullptr);

bool Layout(NGPhysicalFragmentBase**) override;
NGLayoutStatus Layout(NGFragmentBase*,
NGPhysicalFragmentBase**,
NGBox**) override;

DECLARE_VIRTUAL_TRACE();

Expand Down

0 comments on commit e9f4dc8

Please sign in to comment.