OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/layout/ng/inline/ng_inline_node.h" | 5 #include "core/layout/ng/inline/ng_inline_node.h" |
6 | 6 |
7 #include "core/layout/BidiRun.h" | 7 #include "core/layout/BidiRun.h" |
8 #include "core/layout/LayoutBlockFlow.h" | 8 #include "core/layout/LayoutBlockFlow.h" |
9 #include "core/layout/LayoutObject.h" | 9 #include "core/layout/LayoutObject.h" |
10 #include "core/layout/LayoutText.h" | 10 #include "core/layout/LayoutText.h" |
11 #include "core/layout/line/LineInfo.h" | 11 #include "core/layout/line/LineInfo.h" |
12 #include "core/layout/line/RootInlineBox.h" | 12 #include "core/layout/line/RootInlineBox.h" |
13 #include "core/layout/ng/inline/ng_bidi_paragraph.h" | 13 #include "core/layout/ng/inline/ng_bidi_paragraph.h" |
14 #include "core/layout/ng/inline/ng_inline_break_token.h" | 14 #include "core/layout/ng/inline/ng_inline_break_token.h" |
15 #include "core/layout/ng/inline/ng_inline_item.h" | 15 #include "core/layout/ng/inline/ng_inline_item.h" |
16 #include "core/layout/ng/inline/ng_inline_items_builder.h" | 16 #include "core/layout/ng/inline/ng_inline_items_builder.h" |
17 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" | 17 #include "core/layout/ng/inline/ng_inline_layout_algorithm.h" |
18 #include "core/layout/ng/inline/ng_line_box_fragment.h" | 18 #include "core/layout/ng/inline/ng_line_box_fragment.h" |
19 #include "core/layout/ng/inline/ng_line_breaker.h" | |
19 #include "core/layout/ng/inline/ng_physical_line_box_fragment.h" | 20 #include "core/layout/ng/inline/ng_physical_line_box_fragment.h" |
20 #include "core/layout/ng/inline/ng_physical_text_fragment.h" | 21 #include "core/layout/ng/inline/ng_physical_text_fragment.h" |
21 #include "core/layout/ng/inline/ng_text_fragment.h" | 22 #include "core/layout/ng/inline/ng_text_fragment.h" |
22 #include "core/layout/ng/ng_box_fragment.h" | 23 #include "core/layout/ng/ng_box_fragment.h" |
23 #include "core/layout/ng/ng_constraint_space_builder.h" | 24 #include "core/layout/ng/ng_constraint_space_builder.h" |
24 #include "core/layout/ng/ng_fragment_builder.h" | 25 #include "core/layout/ng/ng_fragment_builder.h" |
25 #include "core/layout/ng/ng_physical_box_fragment.h" | 26 #include "core/layout/ng/ng_physical_box_fragment.h" |
26 #include "core/style/ComputedStyle.h" | 27 #include "core/style/ComputedStyle.h" |
27 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 28 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
28 #include "platform/wtf/text/CharacterNames.h" | 29 #include "platform/wtf/text/CharacterNames.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 ToNGInlineBreakToken(break_token)); | 202 ToNGInlineBreakToken(break_token)); |
202 RefPtr<NGLayoutResult> result = algorithm.Layout(); | 203 RefPtr<NGLayoutResult> result = algorithm.Layout(); |
203 CopyFragmentDataToLayoutBox(*constraint_space, result.Get()); | 204 CopyFragmentDataToLayoutBox(*constraint_space, result.Get()); |
204 return result; | 205 return result; |
205 } | 206 } |
206 | 207 |
207 MinMaxContentSize NGInlineNode::ComputeMinMaxContentSize() { | 208 MinMaxContentSize NGInlineNode::ComputeMinMaxContentSize() { |
208 if (!IsPrepareLayoutFinished()) | 209 if (!IsPrepareLayoutFinished()) |
209 PrepareLayout(); | 210 PrepareLayout(); |
210 | 211 |
211 // Compute the max of inline sizes of all line boxes with 0 available inline | 212 const ComputedStyle& style = Style(); |
212 // size. This gives the min-content, the width where lines wrap at every break | 213 NGWritingMode writing_mode = FromPlatformWritingMode(style.GetWritingMode()); |
213 // opportunity. | 214 NGConstraintSpaceBuilder space_builder(writing_mode); |
214 NGWritingMode writing_mode = | 215 space_builder.SetTextDirection(style.Direction()); |
215 FromPlatformWritingMode(Style().GetWritingMode()); | 216 |
216 RefPtr<NGConstraintSpace> constraint_space = | 217 MinMaxContentSize sizes; |
217 NGConstraintSpaceBuilder(writing_mode) | 218 NGInlineItemResults item_results; |
218 .SetTextDirection(Style().Direction()) | 219 RefPtr<NGConstraintSpace> space; |
219 .SetAvailableSize({LayoutUnit(), NGSizeIndefinite}) | 220 { |
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
| |
220 .ToConstraintSpace(writing_mode); | 221 // Compute the max of inline sizes of all line boxes with 0 available inline |
221 NGInlineLayoutAlgorithm algorithm(this, constraint_space.Get()); | 222 // size. This gives the min-content, the width where lines wrap at every |
222 return algorithm.ComputeMinMaxContentSizeByLayout(); | 223 // break opportunity. |
224 space_builder.SetAvailableSize({LayoutUnit(), NGSizeIndefinite}); | |
225 space = space_builder.ToConstraintSpace(writing_mode); | |
226 NGLineBreaker line_breaker(this, space.Get()); | |
227 NGInlineLayoutAlgorithm algorithm(this, space.Get()); | |
228 while (true) { | |
229 line_breaker.NextLine(&item_results, &algorithm); | |
230 if (item_results.IsEmpty()) | |
231 break; | |
232 LayoutUnit inline_size; | |
233 for (const NGInlineItemResult item_result : item_results) | |
234 inline_size += item_result.inline_size; | |
235 sizes.min_content = std::max(inline_size, sizes.min_content); | |
236 item_results.clear(); | |
237 } | |
238 } | |
239 | |
240 { | |
241 // TODO(kojii): NGConstraintSpaceBuilder does not allow NGSizeIndefinite | |
242 // inline available size. We can allow it, or make this more efficient | |
243 // without using NGLineBreaker. | |
244 space_builder.SetAvailableSize({LayoutUnit::Max(), NGSizeIndefinite}); | |
245 space = space_builder.ToConstraintSpace(writing_mode); | |
246 NGLineBreaker line_breaker(this, space.Get()); | |
247 NGInlineLayoutAlgorithm algorithm(this, space.Get()); | |
248 while (true) { | |
249 line_breaker.NextLine(&item_results, &algorithm); | |
250 if (item_results.IsEmpty()) | |
251 break; | |
252 for (const NGInlineItemResult item_result : item_results) | |
253 sizes.max_content += item_result.inline_size; | |
254 item_results.clear(); | |
255 } | |
256 } | |
257 | |
258 return sizes; | |
223 } | 259 } |
224 | 260 |
225 NGLayoutInputNode* NGInlineNode::NextSibling() { | 261 NGLayoutInputNode* NGInlineNode::NextSibling() { |
226 if (!IsPrepareLayoutFinished()) | 262 if (!IsPrepareLayoutFinished()) |
227 PrepareLayout(); | 263 PrepareLayout(); |
228 return next_sibling_; | 264 return next_sibling_; |
229 } | 265 } |
230 | 266 |
231 LayoutObject* NGInlineNode::GetLayoutObject() const { | 267 LayoutObject* NGInlineNode::GetLayoutObject() const { |
232 return GetLayoutBlockFlow(); | 268 return GetLayoutBlockFlow(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 String NGInlineNode::ToString() const { | 404 String NGInlineNode::ToString() const { |
369 return String::Format("NGInlineNode"); | 405 return String::Format("NGInlineNode"); |
370 } | 406 } |
371 | 407 |
372 DEFINE_TRACE(NGInlineNode) { | 408 DEFINE_TRACE(NGInlineNode) { |
373 visitor->Trace(next_sibling_); | 409 visitor->Trace(next_sibling_); |
374 NGLayoutInputNode::Trace(visitor); | 410 NGLayoutInputNode::Trace(visitor); |
375 } | 411 } |
376 | 412 |
377 } // namespace blink | 413 } // namespace blink |
OLD | NEW |