Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/ng/ng_box.cc |
| diff --git a/third_party/WebKit/Source/core/layout/ng/ng_box.cc b/third_party/WebKit/Source/core/layout/ng/ng_box.cc |
| index 40062d95e97e529b9d4adec139b79c4ada13e61d..6e430da1e2ece72a56a513d3652539d60b4a3b49 100644 |
| --- a/third_party/WebKit/Source/core/layout/ng/ng_box.cc |
| +++ b/third_party/WebKit/Source/core/layout/ng/ng_box.cc |
| @@ -7,6 +7,7 @@ |
| #include "core/layout/LayoutBlockFlow.h" |
| #include "core/layout/ng/layout_ng_block_flow.h" |
| #include "core/layout/ng/ng_block_layout_algorithm.h" |
| +#include "core/layout/ng/ng_constraint_space_builder.h" |
| #include "core/layout/ng/ng_constraint_space.h" |
| #include "core/layout/ng/ng_direction.h" |
| #include "core/layout/ng/ng_fragment.h" |
| @@ -63,6 +64,66 @@ bool NGBox::Layout(const NGConstraintSpace* constraint_space, |
| return true; |
| } |
| +bool NGBox::ComputeOrSynthesizeMinAndMaxContentSizes( |
|
atotic
2016/11/01 21:56:02
This routine name is 41 chars long, 1/2 of our lin
cbiesinger
2016/11/02 20:18:08
Ok, I renamed it back to ComputeMinAndMaxContentSi
|
| + MinAndMaxContentSizes* sizes) { |
| + if (!algorithm_) { |
| + NGConstraintSpaceBuilder builder( |
| + FromPlatformWritingMode(Style()->getWritingMode())); |
| + |
| + builder.SetContainerSize(NGLogicalSize(LayoutUnit(), LayoutUnit())); |
| + // TODO(layoutng): Use builder.ToConstraintSpace.ToLogicalConstraintSpace |
| + // once |
| + // that's available. |
| + NGConstraintSpace* constraint_space = new NGConstraintSpace( |
| + FromPlatformWritingMode(Style()->getWritingMode()), |
| + FromPlatformDirection(Style()->direction()), |
| + builder.ToConstraintSpace()); |
| + |
| + algorithm_ = |
|
atotic
2016/11/01 21:56:02
algorithm_ is used in 2 functions (Layout & MinMax
cbiesinger
2016/11/02 20:18:08
OK -- I will do that for now. Once we have the sta
|
| + new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space); |
| + } |
| + // TODO(cbiesinger): For orthogonal children, we need to always synthesize. |
| + NGLayoutAlgorithm::MinAndMaxState state = |
| + algorithm_->ComputeMinAndMaxContentSizes(sizes); |
| + if (state == NGLayoutAlgorithm::Success) |
| + return true; |
| + if (state == NGLayoutAlgorithm::Pending) |
| + return false; |
| + DCHECK_EQ(state, NGLayoutAlgorithm::NotImplemented); |
| + |
| + // TODO(cbiesinger): Replace the loops below with a state machine like in |
| + // Layout. |
| + |
| + // Have to synthesize this value. |
| + NGPhysicalFragment* physical_fragment; |
| + while (!algorithm_->Layout(&physical_fragment)) |
| + continue; |
| + NGFragment* fragment = new NGFragment( |
| + FromPlatformWritingMode(Style()->getWritingMode()), |
| + FromPlatformDirection(Style()->direction()), physical_fragment); |
| + |
| + sizes->min_content = fragment->InlineOverflow(); |
| + |
| + // Now, redo with infinite space for max_content |
| + NGConstraintSpaceBuilder builder( |
| + FromPlatformWritingMode(Style()->getWritingMode())); |
| + builder.SetContainerSize(NGLogicalSize(LayoutUnit::max(), LayoutUnit())); |
| + NGConstraintSpace* constraint_space = new NGConstraintSpace( |
| + FromPlatformWritingMode(Style()->getWritingMode()), |
| + FromPlatformDirection(Style()->direction()), builder.ToConstraintSpace()); |
| + |
| + algorithm_ = |
| + new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space); |
| + while (!algorithm_->Layout(&physical_fragment)) |
| + continue; |
| + |
| + fragment = new NGFragment(FromPlatformWritingMode(Style()->getWritingMode()), |
| + FromPlatformDirection(Style()->direction()), |
| + physical_fragment); |
| + sizes->max_content = fragment->InlineOverflow(); |
| + return true; |
| +} |
| + |
| const ComputedStyle* NGBox::Style() const { |
| if (style_) |
| return style_.get(); |
| @@ -97,6 +158,13 @@ void NGBox::SetFirstChild(NGBox* child) { |
| first_child_ = child; |
| } |
| +DEFINE_TRACE(NGBox) { |
| + visitor->trace(algorithm_); |
| + visitor->trace(fragment_); |
| + visitor->trace(next_sibling_); |
| + visitor->trace(first_child_); |
| +} |
| + |
| void NGBox::PositionUpdated() { |
| if (!layout_box_) |
| return; |