Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
| diff --git a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
| index c2c7571d9db3112564ca2c9c37d4b2ecd381bb10..f8975266907a2ed3a5efa7d6f810988c9f25a417 100644 |
| --- a/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
| +++ b/third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc |
| @@ -184,7 +184,6 @@ NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( |
| NGConstraintSpace* constraint_space, |
| NGBreakToken* break_token) |
| : NGLayoutAlgorithm(kBlockLayoutAlgorithm), |
| - layout_state_(kStateInit), |
| style_(style), |
| first_child_(first_child), |
| constraint_space_(constraint_space), |
| @@ -224,136 +223,113 @@ NGLayoutStatus NGBlockLayoutAlgorithm::Layout( |
| NGPhysicalFragment* child_fragment, |
| NGPhysicalFragment** fragment_out, |
| NGLayoutAlgorithm** algorithm_out) { |
| - switch (layout_state_) { |
| - case kStateInit: { |
| - WTF::Optional<MinAndMaxContentSizes> sizes; |
| - if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style())) { |
| - sizes = MinAndMaxContentSizes(); |
| - ComputeMinAndMaxContentSizes(&*sizes); |
| - } |
| - |
| - border_and_padding_ = |
| - ComputeBorders(Style()) + ComputePadding(ConstraintSpace(), Style()); |
| - |
| - LayoutUnit inline_size = |
| - ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); |
| - LayoutUnit adjusted_inline_size = |
| - inline_size - border_and_padding_.InlineSum(); |
| - // TODO(layout-ng): For quirks mode, should we pass blockSize instead of |
| - // -1? |
| - LayoutUnit block_size = ComputeBlockSizeForFragment( |
| - ConstraintSpace(), Style(), NGSizeIndefinite); |
| - LayoutUnit adjusted_block_size(block_size); |
| - // Our calculated block-axis size may be indefinite at this point. |
| - // If so, just leave the size as NGSizeIndefinite instead of subtracting |
| - // borders and padding. |
| - if (adjusted_block_size != NGSizeIndefinite) |
| - adjusted_block_size -= border_and_padding_.BlockSum(); |
| - |
| - space_builder_ = new NGConstraintSpaceBuilder(constraint_space_); |
| - if (Style().specifiesColumns()) { |
| - space_builder_->SetFragmentationType(kFragmentColumn); |
| - adjusted_inline_size = |
| - ResolveUsedColumnInlineSize(adjusted_inline_size, Style()); |
| - LayoutUnit inline_progression = |
| - adjusted_inline_size + ResolveUsedColumnGap(Style()); |
| - fragmentainer_mapper_ = |
| - new NGColumnMapper(inline_progression, adjusted_block_size); |
| - } |
| - space_builder_->SetAvailableSize( |
| - NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
| - space_builder_->SetPercentageResolutionSize( |
| - NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
| - |
| - builder_ = new NGFragmentBuilder(NGPhysicalFragment::kFragmentBox); |
| - builder_->SetDirection(constraint_space_->Direction()); |
| - builder_->SetWritingMode(constraint_space_->WritingMode()); |
| - builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
| - |
| - if (NGBlockBreakToken* token = CurrentBlockBreakToken()) { |
| - // Resume after a previous break. |
| - content_size_ = token->BreakOffset(); |
| - current_child_ = token->InputNode(); |
| - } else { |
| - content_size_ = border_and_padding_.block_start; |
| - current_child_ = first_child_; |
| - } |
| - |
| - layout_state_ = kStatePrepareForChildLayout; |
| - return kNotFinished; |
| - } |
| - case kStatePrepareForChildLayout: { |
| - if (current_child_) { |
| - EPosition position = current_child_->Style()->position(); |
| - if ((position == AbsolutePosition || position == FixedPosition)) { |
| - builder_->AddOutOfFlowChildCandidate(current_child_, |
| - GetChildSpaceOffset()); |
| - current_child_ = current_child_->NextSibling(); |
| - return kNotFinished; |
| - } |
| - DCHECK(!ConstraintSpace().HasBlockFragmentation() || |
| - SpaceAvailableForCurrentChild() > LayoutUnit()); |
| - space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); |
| - *algorithm_out = NGLayoutInputNode::AlgorithmForInputNode( |
| - current_child_, space_for_current_child_); |
| - layout_state_ = kStateChildLayout; |
| - return kChildAlgorithmRequired; |
| - } |
| - |
| - // Prepare for kStateOutOfFlowLayout |
| - content_size_ += border_and_padding_.block_end; |
| - |
| - // Recompute the block-axis size now that we know our content size. |
| - LayoutUnit block_size = ComputeBlockSizeForFragment( |
| - ConstraintSpace(), Style(), content_size_); |
| - builder_->SetBlockSize(block_size); |
| - |
| - // Out of flow setup. |
| - out_of_flow_layout_ = |
| - new NGOutOfFlowLayoutPart(&Style(), builder_->Size()); |
| - builder_->GetAndClearOutOfFlowDescendantCandidates( |
| - &out_of_flow_candidates_, &out_of_flow_candidate_positions_); |
| - out_of_flow_candidate_positions_index_ = 0; |
| - current_child_ = nullptr; |
| - layout_state_ = kStateOutOfFlowLayout; |
| - return kNotFinished; |
| - } |
| - case kStateChildLayout: { |
| - DCHECK(current_child_); |
| - DCHECK(child_fragment); |
| + WTF::Optional<MinAndMaxContentSizes> sizes; |
| + if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style())) { |
| + // TODO(ikilpatrick): Change ComputeMinAndMaxContentSizes to return |
| + // MinAndMaxContentSizes. |
|
cbiesinger
2017/01/19 18:41:11
Tricky because how do you indicate that it isn't i
ikilpatrick
2017/01/19 18:54:15
I was thinking we could just have a bool NGLayoutA
cbiesinger
2017/01/19 19:06:30
True, that works. sounds good.
|
| + sizes = MinAndMaxContentSizes(); |
| + ComputeMinAndMaxContentSizes(&*sizes); |
| + } |
| - // TODO(layout_ng): Seems like a giant hack to call this here. |
| - current_child_->UpdateLayoutBox(toNGPhysicalBoxFragment(child_fragment), |
| - space_for_current_child_); |
| + border_and_padding_ = |
| + ComputeBorders(Style()) + ComputePadding(ConstraintSpace(), Style()); |
| - FinishCurrentChildLayout(new NGBoxFragment( |
| - ConstraintSpace().WritingMode(), ConstraintSpace().Direction(), |
| - toNGPhysicalBoxFragment(child_fragment))); |
| + LayoutUnit inline_size = |
| + ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); |
| + LayoutUnit adjusted_inline_size = |
| + inline_size - border_and_padding_.InlineSum(); |
| + // TODO(layout-ng): For quirks mode, should we pass blockSize instead of |
| + // -1? |
| + LayoutUnit block_size = |
| + ComputeBlockSizeForFragment(ConstraintSpace(), Style(), NGSizeIndefinite); |
| + LayoutUnit adjusted_block_size(block_size); |
| + // Our calculated block-axis size may be indefinite at this point. |
| + // If so, just leave the size as NGSizeIndefinite instead of subtracting |
| + // borders and padding. |
| + if (adjusted_block_size != NGSizeIndefinite) |
| + adjusted_block_size -= border_and_padding_.BlockSum(); |
| + |
| + space_builder_ = new NGConstraintSpaceBuilder(constraint_space_); |
| + if (Style().specifiesColumns()) { |
| + space_builder_->SetFragmentationType(kFragmentColumn); |
| + adjusted_inline_size = |
| + ResolveUsedColumnInlineSize(adjusted_inline_size, Style()); |
| + LayoutUnit inline_progression = |
| + adjusted_inline_size + ResolveUsedColumnGap(Style()); |
| + fragmentainer_mapper_ = |
| + new NGColumnMapper(inline_progression, adjusted_block_size); |
| + } |
| + space_builder_->SetAvailableSize( |
| + NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
| + space_builder_->SetPercentageResolutionSize( |
| + NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
| + |
| + builder_ = new NGFragmentBuilder(NGPhysicalFragment::kFragmentBox); |
| + builder_->SetDirection(constraint_space_->Direction()); |
| + builder_->SetWritingMode(constraint_space_->WritingMode()); |
| + builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
| + |
| + if (NGBlockBreakToken* token = CurrentBlockBreakToken()) { |
| + // Resume after a previous break. |
| + content_size_ = token->BreakOffset(); |
| + current_child_ = token->InputNode(); |
| + } else { |
| + content_size_ = border_and_padding_.block_start; |
| + current_child_ = first_child_; |
| + } |
| - if (ProceedToNextUnfinishedSibling(child_fragment)) |
| - layout_state_ = kStatePrepareForChildLayout; |
| - else |
| - layout_state_ = kStateFinalize; |
| - return kNotFinished; |
| - } |
| - case kStateOutOfFlowLayout: |
| - if (LayoutOutOfFlowChild()) |
| - layout_state_ = kStateFinalize; |
| - return kNotFinished; |
| - case kStateFinalize: { |
| - builder_->SetInlineOverflow(max_inline_size_) |
| - .SetBlockOverflow(content_size_); |
| - |
| - if (ConstraintSpace().HasBlockFragmentation()) |
| - FinalizeForFragmentation(); |
| - |
| - *fragment_out = builder_->ToBoxFragment(); |
| - layout_state_ = kStateInit; |
| - return kNewFragment; |
| + while (current_child_) { |
| + EPosition position = current_child_->Style()->position(); |
| + if ((position == AbsolutePosition || position == FixedPosition)) { |
|
cbiesinger
2017/01/19 18:41:11
I know you just moved this but maybe remove one se
ikilpatrick
2017/01/19 18:54:15
Done.
|
| + builder_->AddOutOfFlowChildCandidate(current_child_, |
| + GetChildSpaceOffset()); |
| + current_child_ = current_child_->NextSibling(); |
| + continue; |
| } |
| - }; |
| - NOTREACHED(); |
| - *fragment_out = nullptr; |
| + |
| + DCHECK(!ConstraintSpace().HasBlockFragmentation() || |
| + SpaceAvailableForCurrentChild() > LayoutUnit()); |
| + space_for_current_child_ = CreateConstraintSpaceForCurrentChild(); |
| + |
| + NGFragment* fragment; |
| + current_child_->LayoutSync(space_for_current_child_, &fragment); |
| + NGPhysicalFragment* child_fragment = fragment->PhysicalFragment(); |
| + |
| + // TODO(layout_ng): Seems like a giant hack to call this here. |
| + current_child_->UpdateLayoutBox(toNGPhysicalBoxFragment(child_fragment), |
| + space_for_current_child_); |
| + |
| + FinishCurrentChildLayout(new NGBoxFragment( |
| + ConstraintSpace().WritingMode(), ConstraintSpace().Direction(), |
| + toNGPhysicalBoxFragment(child_fragment))); |
| + |
| + if (!ProceedToNextUnfinishedSibling(child_fragment)) |
| + break; |
| + } |
| + |
| + content_size_ += border_and_padding_.block_end; |
| + |
| + // Recompute the block-axis size now that we know our content size. |
| + block_size = |
| + ComputeBlockSizeForFragment(ConstraintSpace(), Style(), content_size_); |
| + builder_->SetBlockSize(block_size); |
| + |
| + // Out of flow setup. |
| + out_of_flow_layout_ = new NGOutOfFlowLayoutPart(&Style(), builder_->Size()); |
| + builder_->GetAndClearOutOfFlowDescendantCandidates( |
| + &out_of_flow_candidates_, &out_of_flow_candidate_positions_); |
| + out_of_flow_candidate_positions_index_ = 0; |
| + current_child_ = nullptr; |
| + |
| + while (!LayoutOutOfFlowChild()) |
| + continue; |
| + |
| + builder_->SetInlineOverflow(max_inline_size_).SetBlockOverflow(content_size_); |
| + |
| + if (ConstraintSpace().HasBlockFragmentation()) |
| + FinalizeForFragmentation(); |
| + |
| + *fragment_out = builder_->ToBoxFragment(); |
| return kNewFragment; |
| } |