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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "core/layout/ng/ng_constraint_space_builder.h" | 24 #include "core/layout/ng/ng_constraint_space_builder.h" |
25 #include "core/layout/ng/ng_fragment_builder.h" | 25 #include "core/layout/ng/ng_fragment_builder.h" |
26 #include "core/layout/ng/ng_layout_result.h" | 26 #include "core/layout/ng/ng_layout_result.h" |
27 #include "core/layout/ng/ng_physical_box_fragment.h" | 27 #include "core/layout/ng/ng_physical_box_fragment.h" |
28 #include "core/style/ComputedStyle.h" | 28 #include "core/style/ComputedStyle.h" |
29 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 29 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
30 #include "platform/wtf/text/CharacterNames.h" | 30 #include "platform/wtf/text/CharacterNames.h" |
31 | 31 |
32 namespace blink { | 32 namespace blink { |
33 | 33 |
| 34 namespace { |
| 35 |
| 36 // Set the geometry to InlineFlowBox by computing the union of children. |
| 37 void PlaceInlineFlowBoxes(InlineFlowBox* flow_box) { |
| 38 LayoutUnit logical_left = LayoutUnit::Max(); |
| 39 LayoutUnit logical_right = LayoutUnit::Min(); |
| 40 LayoutUnit logical_top = LayoutUnit::Max(); |
| 41 for (InlineBox* curr = flow_box->FirstChild(); curr; |
| 42 curr = curr->NextOnLine()) { |
| 43 if (curr->GetLineLayoutItem().IsLayoutInline()) { |
| 44 InlineFlowBox* flow = ToInlineFlowBox(curr); |
| 45 PlaceInlineFlowBoxes(flow); |
| 46 } |
| 47 logical_left = std::min(curr->LogicalLeft(), logical_left); |
| 48 logical_right = std::max(curr->LogicalRight(), logical_right); |
| 49 logical_top = std::min(curr->LogicalTop(), logical_top); |
| 50 } |
| 51 if (logical_left == LayoutUnit::Max()) |
| 52 return; |
| 53 logical_left -= flow_box->MarginBorderPaddingLogicalLeft(); |
| 54 logical_right += flow_box->MarginBorderPaddingLogicalRight(); |
| 55 flow_box->SetLogicalLeft(logical_left); |
| 56 flow_box->SetLogicalWidth(logical_right - logical_left); |
| 57 flow_box->SetLogicalTop(logical_top); |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 |
34 NGInlineNode::NGInlineNode(LayoutObject* start_inline, LayoutNGBlockFlow* block) | 62 NGInlineNode::NGInlineNode(LayoutObject* start_inline, LayoutNGBlockFlow* block) |
35 : NGLayoutInputNode(NGLayoutInputNodeType::kLegacyInline), | 63 : NGLayoutInputNode(NGLayoutInputNodeType::kLegacyInline), |
36 start_inline_(start_inline), | 64 start_inline_(start_inline), |
37 block_(block) { | 65 block_(block) { |
38 DCHECK(start_inline); | 66 DCHECK(start_inline); |
39 DCHECK(block); | 67 DCHECK(block); |
40 block->ResetNGInlineNodeData(); | 68 block->ResetNGInlineNodeData(); |
41 } | 69 } |
42 | 70 |
43 NGInlineNode::NGInlineNode() | 71 NGInlineNode::NGInlineNode() |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 inline_box->SetLogicalLeft(fragment.InlineOffset()); | 379 inline_box->SetLogicalLeft(fragment.InlineOffset()); |
352 inline_box->SetLogicalTop(fragment.BlockOffset()); | 380 inline_box->SetLogicalTop(fragment.BlockOffset()); |
353 if (inline_box->GetLineLayoutItem().IsBox()) { | 381 if (inline_box->GetLineLayoutItem().IsBox()) { |
354 LineLayoutBox box(inline_box->GetLineLayoutItem()); | 382 LineLayoutBox box(inline_box->GetLineLayoutItem()); |
355 box.SetLocation(inline_box->Location()); | 383 box.SetLocation(inline_box->Location()); |
356 } | 384 } |
357 run = run->Next(); | 385 run = run->Next(); |
358 } | 386 } |
359 DCHECK(!run); | 387 DCHECK(!run); |
360 | 388 |
| 389 // InlineTextBox and InlineBox are placed, but when ConstructLine() created |
| 390 // InlineFlowBox, they needed to be placed as well. |
| 391 PlaceInlineFlowBoxes(root_line_box); |
| 392 |
361 // Copy to RootInlineBox. | 393 // Copy to RootInlineBox. |
362 NGLineBoxFragment line_box(constraint_space.WritingMode(), | 394 NGLineBoxFragment line_box(constraint_space.WritingMode(), |
363 physical_line_box); | 395 physical_line_box); |
364 root_line_box->SetLogicalWidth(line_box.InlineSize()); | 396 root_line_box->SetLogicalWidth(line_box.InlineSize()); |
365 LayoutUnit line_top = line_box.BlockOffset(); | 397 LayoutUnit line_top = line_box.BlockOffset(); |
366 NGLineHeightMetrics line_metrics(Style(), baseline_type); | 398 NGLineHeightMetrics line_metrics(Style(), baseline_type); |
367 const NGLineHeightMetrics& max_with_leading = physical_line_box->Metrics(); | 399 const NGLineHeightMetrics& max_with_leading = physical_line_box->Metrics(); |
368 LayoutUnit baseline = line_top + max_with_leading.ascent; | 400 LayoutUnit baseline = line_top + max_with_leading.ascent; |
369 root_line_box->SetLogicalTop(baseline - line_metrics.ascent); | 401 root_line_box->SetLogicalTop(baseline - line_metrics.ascent); |
370 root_line_box->SetLineTopBottomPositions( | 402 root_line_box->SetLineTopBottomPositions( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 String NGInlineNode::ToString() const { | 448 String NGInlineNode::ToString() const { |
417 return String::Format("NGInlineNode"); | 449 return String::Format("NGInlineNode"); |
418 } | 450 } |
419 | 451 |
420 DEFINE_TRACE(NGInlineNode) { | 452 DEFINE_TRACE(NGInlineNode) { |
421 visitor->Trace(next_sibling_); | 453 visitor->Trace(next_sibling_); |
422 NGLayoutInputNode::Trace(visitor); | 454 NGLayoutInputNode::Trace(visitor); |
423 } | 455 } |
424 | 456 |
425 } // namespace blink | 457 } // namespace blink |
OLD | NEW |