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

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

Issue 2706403008: [LayoutNG] Implement ComputeMinAndMaxContentSizes for inline (Closed)
Patch Set: cbiesinger review Created 3 years, 9 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/ng_inline_node.h" 5 #include "core/layout/ng/ng_inline_node.h"
6 6
7 #include "core/layout/LayoutBlockFlow.h" 7 #include "core/layout/LayoutBlockFlow.h"
8 #include "core/layout/LayoutObject.h" 8 #include "core/layout/LayoutObject.h"
9 #include "core/layout/LayoutText.h" 9 #include "core/layout/LayoutText.h"
10 #include "core/layout/ng/ng_bidi_paragraph.h" 10 #include "core/layout/ng/ng_bidi_paragraph.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 last_inline_ = start_inline_; 54 last_inline_ = start_inline_;
55 for (LayoutObject* curr = start_inline_; curr; curr = curr->nextSibling()) 55 for (LayoutObject* curr = start_inline_; curr; curr = curr->nextSibling())
56 last_inline_ = curr; 56 last_inline_ = curr;
57 57
58 CollectInlines(start_inline_, last_inline_); 58 CollectInlines(start_inline_, last_inline_);
59 if (is_bidi_enabled_) 59 if (is_bidi_enabled_)
60 SegmentText(); 60 SegmentText();
61 ShapeText(); 61 ShapeText();
62 } 62 }
63 63
64 void NGInlineNode::InvalidatePrepareLayout() {
65 text_content_ = String();
66 items_.clear();
67 }
68
64 // Depth-first-scan of all LayoutInline and LayoutText nodes that make up this 69 // Depth-first-scan of all LayoutInline and LayoutText nodes that make up this
65 // NGInlineNode object. Collects LayoutText items, merging them up into the 70 // NGInlineNode object. Collects LayoutText items, merging them up into the
66 // parent LayoutInline where possible, and joining all text content in a single 71 // parent LayoutInline where possible, and joining all text content in a single
67 // string to allow bidi resolution and shaping of the entire block. 72 // string to allow bidi resolution and shaping of the entire block.
68 void NGInlineNode::CollectInlines(LayoutObject* start, LayoutObject* last) { 73 void NGInlineNode::CollectInlines(LayoutObject* start, LayoutObject* last) {
69 DCHECK(text_content_.isNull()); 74 DCHECK(text_content_.isNull());
70 DCHECK(items_.isEmpty()); 75 DCHECK(items_.isEmpty());
71 NGLayoutInlineItemsBuilder builder(&items_); 76 NGLayoutInlineItemsBuilder builder(&items_);
72 builder.EnterBlock(block_style_.get()); 77 builder.EnterBlock(block_style_.get());
73 CollectInlines(start, last, &builder); 78 CollectInlines(start, last, &builder);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 246 }
242 } 247 }
243 248
244 RefPtr<NGLayoutResult> NGInlineNode::Layout(NGConstraintSpace*) { 249 RefPtr<NGLayoutResult> NGInlineNode::Layout(NGConstraintSpace*) {
245 ASSERT_NOT_REACHED(); 250 ASSERT_NOT_REACHED();
246 return nullptr; 251 return nullptr;
247 } 252 }
248 253
249 void NGInlineNode::LayoutInline(NGConstraintSpace* constraint_space, 254 void NGInlineNode::LayoutInline(NGConstraintSpace* constraint_space,
250 NGLineBuilder* line_builder) { 255 NGLineBuilder* line_builder) {
251 PrepareLayout(); 256 if (!IsPrepareLayoutFinished())
257 PrepareLayout();
252 258
253 if (text_content_.isEmpty()) 259 if (text_content_.isEmpty())
254 return; 260 return;
255 261
256 NGTextLayoutAlgorithm(this, constraint_space).LayoutInline(line_builder); 262 NGTextLayoutAlgorithm(this, constraint_space).LayoutInline(line_builder);
257 } 263 }
258 264
265 MinAndMaxContentSizes NGInlineNode::ComputeMinAndMaxContentSizes() {
266 // Compute the max of inline sizes of all line boxes with 0 available inline
267 // size. This gives the min-content, the width where lines wrap at every break
268 // opportunity.
269 NGWritingMode writing_mode =
270 FromPlatformWritingMode(BlockStyle()->getWritingMode());
271 NGConstraintSpace* constraint_space =
272 NGConstraintSpaceBuilder(writing_mode)
273 .SetTextDirection(BlockStyle()->direction())
274 .SetAvailableSize({LayoutUnit(), NGSizeIndefinite})
275 .ToConstraintSpace(writing_mode);
276 NGLineBuilder line_builder(this, constraint_space);
277 LayoutInline(constraint_space, &line_builder);
278 MinAndMaxContentSizes sizes;
279 sizes.min_content = line_builder.MaxInlineSize();
280
281 // max-content is the width without any line wrapping.
282 // TODO(kojii): Implement hard breaks (<br> etc.) to break.
283 for (const auto& item : items_)
284 sizes.max_content += item.InlineSize();
285
286 return sizes;
287 }
288
259 NGInlineNode* NGInlineNode::NextSibling() { 289 NGInlineNode* NGInlineNode::NextSibling() {
260 if (!next_sibling_) { 290 if (!next_sibling_) {
261 LayoutObject* next_sibling = 291 LayoutObject* next_sibling =
262 last_inline_ ? last_inline_->nextSibling() : nullptr; 292 last_inline_ ? last_inline_->nextSibling() : nullptr;
263 next_sibling_ = next_sibling 293 next_sibling_ = next_sibling
264 ? new NGInlineNode(next_sibling, block_style_.get()) 294 ? new NGInlineNode(next_sibling, block_style_.get())
265 : nullptr; 295 : nullptr;
266 } 296 }
267 return next_sibling_; 297 return next_sibling_;
268 } 298 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 Vector<NGLayoutInlineItem>* items, 354 Vector<NGLayoutInlineItem>* items,
325 unsigned start_index, 355 unsigned start_index,
326 unsigned end_index) 356 unsigned end_index)
327 : start_item_(&(*items)[start_index]), 357 : start_item_(&(*items)[start_index]),
328 size_(end_index - start_index), 358 size_(end_index - start_index),
329 start_index_(start_index) { 359 start_index_(start_index) {
330 RELEASE_ASSERT(start_index <= end_index && end_index <= items->size()); 360 RELEASE_ASSERT(start_index <= end_index && end_index <= items->size());
331 } 361 }
332 362
333 } // namespace blink 363 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698