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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/inline/ng_inline_node.cc

Issue 2871733003: [LayoutNG] Refactor NGLineBreaker for ShapingLineBreaker (Closed)
Patch Set: Cleanup Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
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
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 enum class ContentSizeMode { Max, Sum };
209
210 static LayoutUnit ComputeContentSize(NGInlineNode* node,
211 ContentSizeMode mode,
212 LayoutUnit available_inline_size,
213 NGConstraintSpaceBuilder* space_builder,
214 NGWritingMode writing_mode) {
215 space_builder->SetAvailableSize({available_inline_size, NGSizeIndefinite});
216 RefPtr<NGConstraintSpace> space =
217 space_builder->ToConstraintSpace(writing_mode);
218 NGLineBreaker line_breaker(node, space.Get());
219 NGInlineLayoutAlgorithm algorithm(node, space.Get());
220 NGInlineItemResults item_results;
221 LayoutUnit result;
222 while (true) {
223 line_breaker.NextLine(&item_results, &algorithm);
224 if (item_results.IsEmpty())
225 break;
226 LayoutUnit inline_size;
227 for (const NGInlineItemResult item_result : item_results)
228 inline_size += item_result.inline_size;
229 if (mode == ContentSizeMode::Max) {
230 result = std::max(inline_size, result);
231 } else {
232 result += inline_size;
233 }
234 item_results.clear();
235 }
236 return result;
237 }
238
207 MinMaxContentSize NGInlineNode::ComputeMinMaxContentSize() { 239 MinMaxContentSize NGInlineNode::ComputeMinMaxContentSize() {
208 if (!IsPrepareLayoutFinished()) 240 if (!IsPrepareLayoutFinished())
209 PrepareLayout(); 241 PrepareLayout();
210 242
243 // Run line breaking with 0 and indefinite available width.
244
245 // TODO(kojii): There are several ways to make this more efficient and faster
246 // than runnning two line breaking.
247
211 // Compute the max of inline sizes of all line boxes with 0 available inline 248 // 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 249 // size. This gives the min-content, the width where lines wrap at every
213 // opportunity. 250 // break opportunity.
214 NGWritingMode writing_mode = 251 const ComputedStyle& style = Style();
215 FromPlatformWritingMode(Style().GetWritingMode()); 252 NGWritingMode writing_mode = FromPlatformWritingMode(style.GetWritingMode());
216 RefPtr<NGConstraintSpace> constraint_space = 253 NGConstraintSpaceBuilder space_builder(writing_mode);
217 NGConstraintSpaceBuilder(writing_mode) 254 space_builder.SetTextDirection(style.Direction());
218 .SetTextDirection(Style().Direction()) 255 space_builder.SetAvailableSize({LayoutUnit(), NGSizeIndefinite});
219 .SetAvailableSize({LayoutUnit(), NGSizeIndefinite}) 256 RefPtr<NGConstraintSpace> space =
220 .ToConstraintSpace(writing_mode); 257 space_builder.ToConstraintSpace(writing_mode);
221 NGInlineLayoutAlgorithm algorithm(this, constraint_space.Get()); 258 MinMaxContentSize sizes;
222 return algorithm.ComputeMinMaxContentSizeByLayout(); 259 sizes.min_content = ComputeContentSize(
260 this, ContentSizeMode::Max, LayoutUnit(), &space_builder, writing_mode);
261
262 // Compute the sum of inline sizes of all inline boxes with no line breaks.
263 // TODO(kojii): NGConstraintSpaceBuilder does not allow NGSizeIndefinite
264 // inline available size. We can allow it, or make this more efficient
265 // without using NGLineBreaker.
266 sizes.max_content =
267 ComputeContentSize(this, ContentSizeMode::Sum, LayoutUnit::Max(),
268 &space_builder, writing_mode);
269
270 return sizes;
223 } 271 }
224 272
225 NGLayoutInputNode* NGInlineNode::NextSibling() { 273 NGLayoutInputNode* NGInlineNode::NextSibling() {
226 if (!IsPrepareLayoutFinished()) 274 if (!IsPrepareLayoutFinished())
227 PrepareLayout(); 275 PrepareLayout();
228 return next_sibling_; 276 return next_sibling_;
229 } 277 }
230 278
231 LayoutObject* NGInlineNode::GetLayoutObject() const { 279 LayoutObject* NGInlineNode::GetLayoutObject() const {
232 return GetLayoutBlockFlow(); 280 return GetLayoutBlockFlow();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 String NGInlineNode::ToString() const { 415 String NGInlineNode::ToString() const {
368 return String::Format("NGInlineNode"); 416 return String::Format("NGInlineNode");
369 } 417 }
370 418
371 DEFINE_TRACE(NGInlineNode) { 419 DEFINE_TRACE(NGInlineNode) {
372 visitor->Trace(next_sibling_); 420 visitor->Trace(next_sibling_);
373 NGLayoutInputNode::Trace(visitor); 421 NGLayoutInputNode::Trace(visitor);
374 } 422 }
375 423
376 } // namespace blink 424 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698