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_line_breaker.h" |
20 #include "core/layout/ng/inline/ng_physical_line_box_fragment.h" | 20 #include "core/layout/ng/inline/ng_physical_line_box_fragment.h" |
21 #include "core/layout/ng/inline/ng_physical_text_fragment.h" | 21 #include "core/layout/ng/inline/ng_physical_text_fragment.h" |
22 #include "core/layout/ng/inline/ng_text_fragment.h" | 22 #include "core/layout/ng/inline/ng_text_fragment.h" |
| 23 #include "core/layout/ng/layout_ng_block_flow.h" |
23 #include "core/layout/ng/ng_box_fragment.h" | 24 #include "core/layout/ng/ng_box_fragment.h" |
24 #include "core/layout/ng/ng_constraint_space_builder.h" | 25 #include "core/layout/ng/ng_constraint_space_builder.h" |
25 #include "core/layout/ng/ng_fragment_builder.h" | 26 #include "core/layout/ng/ng_fragment_builder.h" |
26 #include "core/layout/ng/ng_layout_result.h" | 27 #include "core/layout/ng/ng_layout_result.h" |
27 #include "core/layout/ng/ng_physical_box_fragment.h" | 28 #include "core/layout/ng/ng_physical_box_fragment.h" |
28 #include "core/style/ComputedStyle.h" | 29 #include "core/style/ComputedStyle.h" |
29 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 30 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
30 #include "platform/wtf/text/CharacterNames.h" | 31 #include "platform/wtf/text/CharacterNames.h" |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 parent->SetLogicalLeft(logical_left); | 145 parent->SetLogicalLeft(logical_left); |
145 parent->SetLogicalWidth(logical_right - logical_left); | 146 parent->SetLogicalWidth(logical_right - logical_left); |
146 parent->SetLogicalTop(logical_top); | 147 parent->SetLogicalTop(logical_top); |
147 } | 148 } |
148 | 149 |
149 return text_index; | 150 return text_index; |
150 } | 151 } |
151 | 152 |
152 } // namespace | 153 } // namespace |
153 | 154 |
154 NGInlineNode::NGInlineNode(LayoutObject* start_inline, LayoutNGBlockFlow* block) | 155 NGInlineNode::NGInlineNode(LayoutNGBlockFlow* block, LayoutObject* start_inline) |
155 : NGLayoutInputNode(NGLayoutInputNodeType::kLegacyInline), | 156 : NGLayoutInputNode(block) { |
156 start_inline_(start_inline), | |
157 block_(block) { | |
158 DCHECK(start_inline); | 157 DCHECK(start_inline); |
159 DCHECK(block); | 158 DCHECK(block); |
160 block->ResetNGInlineNodeData(); | 159 block->SetLayoutNGInline(true); |
| 160 if (!block->HasNGInlineNodeData()) { |
| 161 block->ResetNGInlineNodeData(); |
| 162 } |
| 163 MutableData().start_inline_ = start_inline; |
161 } | 164 } |
162 | 165 |
163 NGInlineNode::NGInlineNode() | |
164 : NGLayoutInputNode(NGLayoutInputNodeType::kLegacyInline), | |
165 start_inline_(nullptr), | |
166 block_(nullptr) {} | |
167 | |
168 NGInlineNode::~NGInlineNode() {} | |
169 | |
170 NGInlineItemRange NGInlineNode::Items(unsigned start, unsigned end) { | 166 NGInlineItemRange NGInlineNode::Items(unsigned start, unsigned end) { |
171 return NGInlineItemRange(&MutableData().items_, start, end); | 167 return NGInlineItemRange(&MutableData().items_, start, end); |
172 } | 168 } |
173 | 169 |
174 void NGInlineNode::InvalidatePrepareLayout() { | 170 void NGInlineNode::InvalidatePrepareLayout() { |
| 171 LayoutObject* start_inline = Data().start_inline_; |
| 172 ToLayoutNGBlockFlow(GetLayoutBlockFlow())->ResetNGInlineNodeData(); |
| 173 MutableData().start_inline_ = start_inline; |
175 MutableData().text_content_ = String(); | 174 MutableData().text_content_ = String(); |
176 MutableData().items_.clear(); | 175 MutableData().items_.clear(); |
177 } | 176 } |
178 | 177 |
179 void NGInlineNode::PrepareLayout() { | 178 void NGInlineNode::PrepareLayout() { |
180 // Scan list of siblings collecting all in-flow non-atomic inlines. A single | 179 // Scan list of siblings collecting all in-flow non-atomic inlines. A single |
181 // NGInlineNode represent a collection of adjacent non-atomic inlines. | 180 // NGInlineNode represent a collection of adjacent non-atomic inlines. |
182 CollectInlines(start_inline_, block_); | 181 CollectInlines(Data().start_inline_, GetLayoutBlockFlow()); |
183 if (Data().is_bidi_enabled_) | 182 if (Data().is_bidi_enabled_) |
184 SegmentText(); | 183 SegmentText(); |
185 ShapeText(); | 184 ShapeText(); |
186 } | 185 } |
187 | 186 |
188 // Depth-first-scan of all LayoutInline and LayoutText nodes that make up this | 187 // Depth-first-scan of all LayoutInline and LayoutText nodes that make up this |
189 // NGInlineNode object. Collects LayoutText items, merging them up into the | 188 // NGInlineNode object. Collects LayoutText items, merging them up into the |
190 // parent LayoutInline where possible, and joining all text content in a single | 189 // parent LayoutInline where possible, and joining all text content in a single |
191 // string to allow bidi resolution and shaping of the entire block. | 190 // string to allow bidi resolution and shaping of the entire block. |
192 void NGInlineNode::CollectInlines(LayoutObject* start, LayoutBlockFlow* block) { | 191 void NGInlineNode::CollectInlines(LayoutObject* start, LayoutBlockFlow* block) { |
193 DCHECK(Data().text_content_.IsNull()); | 192 DCHECK(Data().text_content_.IsNull()); |
194 DCHECK(Data().items_.IsEmpty()); | 193 DCHECK(Data().items_.IsEmpty()); |
195 NGInlineItemsBuilder builder(&MutableData().items_); | 194 NGInlineItemsBuilder builder(&MutableData().items_); |
196 builder.EnterBlock(block->Style()); | 195 builder.EnterBlock(block->Style()); |
197 LayoutObject* next_sibling = CollectInlines(start, block, &builder); | 196 LayoutObject* next_sibling = CollectInlines(start, block, &builder); |
198 builder.ExitBlock(); | 197 builder.ExitBlock(); |
199 | 198 |
200 MutableData().text_content_ = builder.ToString(); | 199 MutableData().text_content_ = builder.ToString(); |
201 DCHECK(!next_sibling || !next_sibling->IsInline()); | 200 DCHECK(!next_sibling || !next_sibling->IsInline()); |
202 next_sibling_ = next_sibling ? new NGBlockNode(next_sibling) : nullptr; | 201 MutableData().next_sibling_ = ToLayoutBox(next_sibling); |
203 MutableData().is_bidi_enabled_ = | 202 MutableData().is_bidi_enabled_ = |
204 !Data().text_content_.IsEmpty() && | 203 !Data().text_content_.IsEmpty() && |
205 !(Data().text_content_.Is8Bit() && !builder.HasBidiControls()); | 204 !(Data().text_content_.Is8Bit() && !builder.HasBidiControls()); |
206 } | 205 } |
207 | 206 |
208 LayoutObject* NGInlineNode::CollectInlines(LayoutObject* start, | 207 LayoutObject* NGInlineNode::CollectInlines(LayoutObject* start, |
209 LayoutBlockFlow* block, | 208 LayoutBlockFlow* block, |
210 NGInlineItemsBuilder* builder) { | 209 NGInlineItemsBuilder* builder) { |
211 LayoutObject* node = start; | 210 LayoutObject* node = start; |
212 while (node) { | 211 while (node) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 item.StartOffset(), item.EndOffset()); | 311 item.StartOffset(), item.EndOffset()); |
313 } | 312 } |
314 } | 313 } |
315 | 314 |
316 RefPtr<NGLayoutResult> NGInlineNode::Layout(NGConstraintSpace* constraint_space, | 315 RefPtr<NGLayoutResult> NGInlineNode::Layout(NGConstraintSpace* constraint_space, |
317 NGBreakToken* break_token) { | 316 NGBreakToken* break_token) { |
318 // TODO(kojii): Invalidate PrepareLayout() more efficiently. | 317 // TODO(kojii): Invalidate PrepareLayout() more efficiently. |
319 InvalidatePrepareLayout(); | 318 InvalidatePrepareLayout(); |
320 PrepareLayout(); | 319 PrepareLayout(); |
321 | 320 |
322 NGInlineLayoutAlgorithm algorithm(this, constraint_space, | 321 NGInlineLayoutAlgorithm algorithm(*this, constraint_space, |
323 ToNGInlineBreakToken(break_token)); | 322 ToNGInlineBreakToken(break_token)); |
324 RefPtr<NGLayoutResult> result = algorithm.Layout(); | 323 RefPtr<NGLayoutResult> result = algorithm.Layout(); |
325 CopyFragmentDataToLayoutBox(*constraint_space, result.Get()); | 324 CopyFragmentDataToLayoutBox(*constraint_space, result.Get()); |
326 return result; | 325 return result; |
327 } | 326 } |
328 | 327 |
329 enum class ContentSizeMode { Max, Sum }; | 328 enum class ContentSizeMode { Max, Sum }; |
330 | 329 |
331 static LayoutUnit ComputeContentSize(NGInlineNode* node, | 330 static LayoutUnit ComputeContentSize(NGInlineNode node, |
332 ContentSizeMode mode, | 331 ContentSizeMode mode, |
333 LayoutUnit available_inline_size, | 332 LayoutUnit available_inline_size) { |
334 NGConstraintSpaceBuilder* space_builder, | 333 const ComputedStyle& style = node.Style(); |
335 NGWritingMode writing_mode) { | 334 NGWritingMode writing_mode = FromPlatformWritingMode(style.GetWritingMode()); |
336 space_builder->SetAvailableSize({available_inline_size, NGSizeIndefinite}); | 335 |
337 RefPtr<NGConstraintSpace> space = | 336 RefPtr<NGConstraintSpace> space = |
338 space_builder->ToConstraintSpace(writing_mode); | 337 NGConstraintSpaceBuilder(writing_mode) |
| 338 .SetTextDirection(style.Direction()) |
| 339 .SetAvailableSize({available_inline_size, NGSizeIndefinite}) |
| 340 .ToConstraintSpace(writing_mode); |
339 NGLineBreaker line_breaker(node, space.Get()); | 341 NGLineBreaker line_breaker(node, space.Get()); |
340 NGInlineLayoutAlgorithm algorithm(node, space.Get()); | 342 NGInlineLayoutAlgorithm algorithm(node, space.Get()); |
341 NGInlineItemResults item_results; | 343 NGInlineItemResults item_results; |
342 LayoutUnit result; | 344 LayoutUnit result; |
343 while (true) { | 345 while (true) { |
344 line_breaker.NextLine(&item_results, &algorithm); | 346 line_breaker.NextLine(&item_results, &algorithm); |
345 if (item_results.IsEmpty()) | 347 if (item_results.IsEmpty()) |
346 break; | 348 break; |
347 LayoutUnit inline_size; | 349 LayoutUnit inline_size; |
348 for (const NGInlineItemResult item_result : item_results) | 350 for (const NGInlineItemResult item_result : item_results) |
(...skipping 13 matching lines...) Expand all Loading... |
362 PrepareLayout(); | 364 PrepareLayout(); |
363 | 365 |
364 // Run line breaking with 0 and indefinite available width. | 366 // Run line breaking with 0 and indefinite available width. |
365 | 367 |
366 // TODO(kojii): There are several ways to make this more efficient and faster | 368 // TODO(kojii): There are several ways to make this more efficient and faster |
367 // than runnning two line breaking. | 369 // than runnning two line breaking. |
368 | 370 |
369 // Compute the max of inline sizes of all line boxes with 0 available inline | 371 // Compute the max of inline sizes of all line boxes with 0 available inline |
370 // size. This gives the min-content, the width where lines wrap at every | 372 // size. This gives the min-content, the width where lines wrap at every |
371 // break opportunity. | 373 // break opportunity. |
372 const ComputedStyle& style = Style(); | |
373 NGWritingMode writing_mode = FromPlatformWritingMode(style.GetWritingMode()); | |
374 NGConstraintSpaceBuilder space_builder(writing_mode); | |
375 space_builder.SetTextDirection(style.Direction()); | |
376 space_builder.SetAvailableSize({LayoutUnit(), NGSizeIndefinite}); | |
377 RefPtr<NGConstraintSpace> space = | |
378 space_builder.ToConstraintSpace(writing_mode); | |
379 MinMaxContentSize sizes; | 374 MinMaxContentSize sizes; |
380 sizes.min_content = ComputeContentSize( | 375 sizes.min_content = |
381 this, ContentSizeMode::Max, LayoutUnit(), &space_builder, writing_mode); | 376 ComputeContentSize(*this, ContentSizeMode::Max, LayoutUnit()); |
382 | 377 |
383 // Compute the sum of inline sizes of all inline boxes with no line breaks. | 378 // Compute the sum of inline sizes of all inline boxes with no line breaks. |
384 // TODO(kojii): NGConstraintSpaceBuilder does not allow NGSizeIndefinite | 379 // TODO(kojii): NGConstraintSpaceBuilder does not allow NGSizeIndefinite |
385 // inline available size. We can allow it, or make this more efficient | 380 // inline available size. We can allow it, or make this more efficient |
386 // without using NGLineBreaker. | 381 // without using NGLineBreaker. |
387 sizes.max_content = | 382 sizes.max_content = |
388 ComputeContentSize(this, ContentSizeMode::Sum, LayoutUnit::Max(), | 383 ComputeContentSize(*this, ContentSizeMode::Sum, LayoutUnit::Max()); |
389 &space_builder, writing_mode); | |
390 | 384 |
391 return sizes; | 385 return sizes; |
392 } | 386 } |
393 | 387 |
394 NGLayoutInputNode* NGInlineNode::NextSibling() { | 388 NGLayoutInputNode NGInlineNode::NextSibling() { |
395 if (!IsPrepareLayoutFinished()) | 389 if (!IsPrepareLayoutFinished()) |
396 PrepareLayout(); | 390 PrepareLayout(); |
397 return next_sibling_; | 391 return NGBlockNode(Data().next_sibling_); |
398 } | |
399 | |
400 LayoutObject* NGInlineNode::GetLayoutObject() const { | |
401 return GetLayoutBlockFlow(); | |
402 } | 392 } |
403 | 393 |
404 void NGInlineNode::CopyFragmentDataToLayoutBox( | 394 void NGInlineNode::CopyFragmentDataToLayoutBox( |
405 const NGConstraintSpace& constraint_space, | 395 const NGConstraintSpace& constraint_space, |
406 NGLayoutResult* layout_result) { | 396 NGLayoutResult* layout_result) { |
407 LayoutBlockFlow* block_flow = GetLayoutBlockFlow(); | 397 LayoutBlockFlow* block_flow = GetLayoutBlockFlow(); |
408 block_flow->DeleteLineBoxTree(); | 398 block_flow->DeleteLineBoxTree(); |
409 | 399 |
410 const Vector<NGInlineItem>& items = Data().items_; | 400 const Vector<NGInlineItem>& items = Data().items_; |
411 Vector<unsigned, 32> text_offsets(items.size()); | 401 Vector<unsigned, 32> text_offsets(items.size()); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 Data().text_content_.length() - current_offset) { | 487 Data().text_content_.length() - current_offset) { |
498 current_text->SetTextInternal( | 488 current_text->SetTextInternal( |
499 Text(current_offset, Data().text_content_.length()).ToString().Impl()); | 489 Text(current_offset, Data().text_content_.length()).ToString().Impl()); |
500 } | 490 } |
501 } | 491 } |
502 | 492 |
503 String NGInlineNode::ToString() const { | 493 String NGInlineNode::ToString() const { |
504 return String::Format("NGInlineNode"); | 494 return String::Format("NGInlineNode"); |
505 } | 495 } |
506 | 496 |
507 DEFINE_TRACE(NGInlineNode) { | |
508 visitor->Trace(next_sibling_); | |
509 NGLayoutInputNode::Trace(visitor); | |
510 } | |
511 | |
512 } // namespace blink | 497 } // namespace blink |
OLD | NEW |