Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/ng/inline/ng_inline_node.cc |
| diff --git a/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_node.cc b/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_node.cc |
| index 7c048de1350880c5663a48df6b6fc11c6512572a..da9aa216bc02d9fe12a341ac6eef4f753780cbc6 100644 |
| --- a/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_node.cc |
| +++ b/third_party/WebKit/Source/core/layout/ng/inline/ng_inline_node.cc |
| @@ -16,6 +16,7 @@ |
| #include "core/layout/ng/inline/ng_inline_items_builder.h" |
| #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" |
| #include "core/layout/ng/inline/ng_line_box_fragment.h" |
| +#include "core/layout/ng/inline/ng_line_breaker.h" |
| #include "core/layout/ng/inline/ng_physical_line_box_fragment.h" |
| #include "core/layout/ng/inline/ng_physical_text_fragment.h" |
| #include "core/layout/ng/inline/ng_text_fragment.h" |
| @@ -208,18 +209,53 @@ MinMaxContentSize NGInlineNode::ComputeMinMaxContentSize() { |
| if (!IsPrepareLayoutFinished()) |
| PrepareLayout(); |
| - // Compute the max of inline sizes of all line boxes with 0 available inline |
| - // size. This gives the min-content, the width where lines wrap at every break |
| - // opportunity. |
| - NGWritingMode writing_mode = |
| - FromPlatformWritingMode(Style().GetWritingMode()); |
| - RefPtr<NGConstraintSpace> constraint_space = |
| - NGConstraintSpaceBuilder(writing_mode) |
| - .SetTextDirection(Style().Direction()) |
| - .SetAvailableSize({LayoutUnit(), NGSizeIndefinite}) |
| - .ToConstraintSpace(writing_mode); |
| - NGInlineLayoutAlgorithm algorithm(this, constraint_space.Get()); |
| - return algorithm.ComputeMinMaxContentSizeByLayout(); |
| + const ComputedStyle& style = Style(); |
| + NGWritingMode writing_mode = FromPlatformWritingMode(style.GetWritingMode()); |
| + NGConstraintSpaceBuilder space_builder(writing_mode); |
| + space_builder.SetTextDirection(style.Direction()); |
| + |
| + MinMaxContentSize sizes; |
| + NGInlineItemResults item_results; |
| + RefPtr<NGConstraintSpace> space; |
| + { |
|
eae
2017/05/10 21:31:38
Could we break these blocks out into separate stat
kojii
2017/05/11 16:17:36
Done. I'd like this to be more efficient than runn
|
| + // Compute the max of inline sizes of all line boxes with 0 available inline |
| + // size. This gives the min-content, the width where lines wrap at every |
| + // break opportunity. |
| + space_builder.SetAvailableSize({LayoutUnit(), NGSizeIndefinite}); |
| + space = space_builder.ToConstraintSpace(writing_mode); |
| + NGLineBreaker line_breaker(this, space.Get()); |
| + NGInlineLayoutAlgorithm algorithm(this, space.Get()); |
| + while (true) { |
| + line_breaker.NextLine(&item_results, &algorithm); |
| + if (item_results.IsEmpty()) |
| + break; |
| + LayoutUnit inline_size; |
| + for (const NGInlineItemResult item_result : item_results) |
| + inline_size += item_result.inline_size; |
| + sizes.min_content = std::max(inline_size, sizes.min_content); |
| + item_results.clear(); |
| + } |
| + } |
| + |
| + { |
| + // TODO(kojii): NGConstraintSpaceBuilder does not allow NGSizeIndefinite |
| + // inline available size. We can allow it, or make this more efficient |
| + // without using NGLineBreaker. |
| + space_builder.SetAvailableSize({LayoutUnit::Max(), NGSizeIndefinite}); |
| + space = space_builder.ToConstraintSpace(writing_mode); |
| + NGLineBreaker line_breaker(this, space.Get()); |
| + NGInlineLayoutAlgorithm algorithm(this, space.Get()); |
| + while (true) { |
| + line_breaker.NextLine(&item_results, &algorithm); |
| + if (item_results.IsEmpty()) |
| + break; |
| + for (const NGInlineItemResult item_result : item_results) |
| + sizes.max_content += item_result.inline_size; |
| + item_results.clear(); |
| + } |
| + } |
| + |
| + return sizes; |
| } |
| NGLayoutInputNode* NGInlineNode::NextSibling() { |