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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 InvalidatePrepareLayout(); | 198 InvalidatePrepareLayout(); |
198 PrepareLayout(); | 199 PrepareLayout(); |
199 | 200 |
200 NGInlineLayoutAlgorithm algorithm(this, constraint_space, | 201 NGInlineLayoutAlgorithm algorithm(this, constraint_space, |
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 |
| 208 static LayoutUnit ComputeContentSize(NGInlineNode* node, |
| 209 NGConstraintSpace* space, |
| 210 bool compute_min_content) { |
| 211 NGLineBreaker line_breaker(node, space); |
| 212 NGInlineLayoutAlgorithm algorithm(node, space); |
| 213 NGInlineItemResults item_results; |
| 214 LayoutUnit result; |
| 215 while (true) { |
| 216 line_breaker.NextLine(&item_results, &algorithm); |
| 217 if (item_results.IsEmpty()) |
| 218 break; |
| 219 LayoutUnit inline_size; |
| 220 for (const NGInlineItemResult item_result : item_results) |
| 221 inline_size += item_result.inline_size; |
| 222 if (compute_min_content) { |
| 223 result = std::max(inline_size, result); |
| 224 } else { |
| 225 result += inline_size; |
| 226 } |
| 227 item_results.clear(); |
| 228 } |
| 229 return result; |
| 230 } |
| 231 |
207 MinMaxContentSize NGInlineNode::ComputeMinMaxContentSize() { | 232 MinMaxContentSize NGInlineNode::ComputeMinMaxContentSize() { |
208 if (!IsPrepareLayoutFinished()) | 233 if (!IsPrepareLayoutFinished()) |
209 PrepareLayout(); | 234 PrepareLayout(); |
210 | 235 |
| 236 // Run line breaking with 0 and indefinite available width. |
| 237 // TODO(kojii): There are several ways to make this more efficient and faster |
| 238 // than runnning two line breaking. |
| 239 |
211 // Compute the max of inline sizes of all line boxes with 0 available inline | 240 // Compute the max of inline sizes of all line boxes with 0 available inline |
212 // size. This gives the min-content, the width where lines wrap at every break | 241 // size. This gives the min-content, the width where lines wrap at every |
213 // opportunity. | 242 // break opportunity. |
214 NGWritingMode writing_mode = | 243 const ComputedStyle& style = Style(); |
215 FromPlatformWritingMode(Style().GetWritingMode()); | 244 NGWritingMode writing_mode = FromPlatformWritingMode(style.GetWritingMode()); |
216 RefPtr<NGConstraintSpace> constraint_space = | 245 NGConstraintSpaceBuilder space_builder(writing_mode); |
217 NGConstraintSpaceBuilder(writing_mode) | 246 space_builder.SetTextDirection(style.Direction()); |
218 .SetTextDirection(Style().Direction()) | 247 MinMaxContentSize sizes; |
219 .SetAvailableSize({LayoutUnit(), NGSizeIndefinite}) | 248 space_builder.SetAvailableSize({LayoutUnit(), NGSizeIndefinite}); |
220 .ToConstraintSpace(writing_mode); | 249 RefPtr<NGConstraintSpace> space = |
221 NGInlineLayoutAlgorithm algorithm(this, constraint_space.Get()); | 250 space_builder.ToConstraintSpace(writing_mode); |
222 return algorithm.ComputeMinMaxContentSizeByLayout(); | 251 sizes.min_content = ComputeContentSize(this, space.Get(), true); |
| 252 |
| 253 // Compute the sum of inline sizes of all inline boxes with no line breaks. |
| 254 // TODO(kojii): NGConstraintSpaceBuilder does not allow NGSizeIndefinite |
| 255 // inline available size. We can allow it, or make this more efficient |
| 256 // without using NGLineBreaker. |
| 257 space_builder.SetAvailableSize({LayoutUnit::Max(), NGSizeIndefinite}); |
| 258 space = space_builder.ToConstraintSpace(writing_mode); |
| 259 sizes.max_content = ComputeContentSize(this, space.Get(), false); |
| 260 |
| 261 return sizes; |
223 } | 262 } |
224 | 263 |
225 NGLayoutInputNode* NGInlineNode::NextSibling() { | 264 NGLayoutInputNode* NGInlineNode::NextSibling() { |
226 if (!IsPrepareLayoutFinished()) | 265 if (!IsPrepareLayoutFinished()) |
227 PrepareLayout(); | 266 PrepareLayout(); |
228 return next_sibling_; | 267 return next_sibling_; |
229 } | 268 } |
230 | 269 |
231 LayoutObject* NGInlineNode::GetLayoutObject() const { | 270 LayoutObject* NGInlineNode::GetLayoutObject() const { |
232 return GetLayoutBlockFlow(); | 271 return GetLayoutBlockFlow(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 String NGInlineNode::ToString() const { | 407 String NGInlineNode::ToString() const { |
369 return String::Format("NGInlineNode"); | 408 return String::Format("NGInlineNode"); |
370 } | 409 } |
371 | 410 |
372 DEFINE_TRACE(NGInlineNode) { | 411 DEFINE_TRACE(NGInlineNode) { |
373 visitor->Trace(next_sibling_); | 412 visitor->Trace(next_sibling_); |
374 NGLayoutInputNode::Trace(visitor); | 413 NGLayoutInputNode::Trace(visitor); |
375 } | 414 } |
376 | 415 |
377 } // namespace blink | 416 } // namespace blink |
OLD | NEW |