Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: third_party/WebKit/Source/core/layout/ng/ng_box.cc

Issue 2462153002: [layoutng] Support computing min-content and max-content (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3be44c1d28f0390c273720b26e1fde178222c2b6 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,54 @@ bool NGBox::Layout(const NGConstraintSpace* constraint_space,
return true;
}
+void NGBox::ComputeMinAndMaxContentSizes(NGFragment** min_content,
+ NGFragment** max_content) {
+ NGConstraintSpaceBuilder builder(
+ FromPlatformWritingMode(Style()->getWritingMode()));
+ builder.SetContainerSize(NGLogicalSize(LayoutUnit(), LayoutUnit()));
Gleb Lanbin 2016/10/31 19:52:47 nit. you can chain SetContainerSize call to line a
cbiesinger 2016/11/01 19:10:03 I'd rather not chain something to the constructor
+ NGConstraintSpace* constraint_space = new NGConstraintSpace(
+ FromPlatformWritingMode(Style()->getWritingMode()),
+ FromPlatformDirection(Style()->direction()), builder.ToConstraintSpace());
eae 2016/10/31 19:30:25 Presumably once Ian's work is done this will be bu
cbiesinger 2016/11/01 19:10:03 Ah, is that the plan? Added a TODO.
+
+ NGLayoutAlgorithm* algorithm =
+ new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space);
+ if (algorithm->ComputeMinAndMaxContentSizes(min_content, max_content) ==
Gleb Lanbin 2016/10/31 19:52:47 IMO it's a bit confusing that we have 2 almost ide
cbiesinger 2016/11/01 19:10:03 Renamed this one to ComputeOrSynthesizeMinAndMaxCo
+ NGLayoutAlgorithm::Success)
+ return;
+
+ // Have to synthesize this value.
+ NGPhysicalFragment* fragment;
+ while (!algorithm->Layout(&fragment))
+ continue;
+
+ HeapVector<Member<const NGPhysicalFragmentBase>> empty;
Gleb Lanbin 2016/10/31 19:52:47 may be add an additional constructor to NGPhysical
cbiesinger 2016/11/01 19:10:03 Removed this entirely due to other changes.
+ fragment =
+ new NGPhysicalFragment(fragment->OverflowSize(), fragment->OverflowSize(),
+ empty, NGMarginStrut());
+
+ *min_content =
+ new NGFragment(FromPlatformWritingMode(Style()->getWritingMode()),
+ FromPlatformDirection(Style()->direction()), fragment);
+
+ // Now, redo with infinite space for max_content
+ builder.SetContainerSize(NGLogicalSize(LayoutUnit::max(), LayoutUnit()));
+ constraint_space = new NGConstraintSpace(
+ FromPlatformWritingMode(Style()->getWritingMode()),
+ FromPlatformDirection(Style()->direction()), builder.ToConstraintSpace());
+
+ algorithm =
+ new NGBlockLayoutAlgorithm(Style(), FirstChild(), constraint_space);
+ while (!algorithm->Layout(&fragment))
+ continue;
+
+ fragment =
+ new NGPhysicalFragment(fragment->OverflowSize(), fragment->OverflowSize(),
+ empty, NGMarginStrut());
+ *max_content =
+ new NGFragment(FromPlatformWritingMode(Style()->getWritingMode()),
+ FromPlatformDirection(Style()->direction()), fragment);
+}
+
const ComputedStyle* NGBox::Style() const {
if (style_)
return style_.get();
@@ -97,6 +146,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;

Powered by Google App Engine
This is Rietveld 408576698