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

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

Issue 2910133002: [LayoutNG] Handle empty inlines and border edges (Closed)
Patch Set: Rebase Created 3 years, 6 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"
(...skipping 19 matching lines...) Expand all
30 #include "platform/fonts/shaping/HarfBuzzShaper.h" 30 #include "platform/fonts/shaping/HarfBuzzShaper.h"
31 #include "platform/wtf/text/CharacterNames.h" 31 #include "platform/wtf/text/CharacterNames.h"
32 32
33 namespace blink { 33 namespace blink {
34 34
35 namespace { 35 namespace {
36 36
37 struct FragmentPosition { 37 struct FragmentPosition {
38 NGLogicalOffset offset; 38 NGLogicalOffset offset;
39 LayoutUnit inline_size; 39 LayoutUnit inline_size;
40 NGBorderEdges border_edges;
40 }; 41 };
41 42
42 // Create BidiRuns from a list of NGPhysicalFragment. 43 // Create BidiRuns from a list of NGPhysicalFragment.
43 // Produce a FragmentPosition map to place InlineBoxes. 44 // Produce a FragmentPosition map to place InlineBoxes.
44 void CreateBidiRuns(BidiRunList<BidiRun>* bidi_runs, 45 void CreateBidiRuns(BidiRunList<BidiRun>* bidi_runs,
45 const Vector<RefPtr<NGPhysicalFragment>>& children, 46 const Vector<RefPtr<NGPhysicalFragment>>& children,
46 const NGConstraintSpace& constraint_space, 47 const NGConstraintSpace& constraint_space,
47 NGLogicalOffset parent_offset, 48 NGLogicalOffset parent_offset,
48 const Vector<NGInlineItem>& items, 49 const Vector<NGInlineItem>& items,
49 const Vector<unsigned, 32>& text_offsets, 50 const Vector<unsigned, 32>& text_offsets,
(...skipping 28 matching lines...) Expand all
78 // One LayoutText may produce multiple text fragments that they can't 79 // One LayoutText may produce multiple text fragments that they can't
79 // be set to a map. 80 // be set to a map.
80 positions_for_bidi_runs_out->push_back(FragmentPosition{ 81 positions_for_bidi_runs_out->push_back(FragmentPosition{
81 fragment.Offset() + parent_offset, fragment.InlineSize()}); 82 fragment.Offset() + parent_offset, fragment.InlineSize()});
82 } else { 83 } else {
83 DCHECK_EQ(child->Type(), NGPhysicalFragment::kFragmentBox); 84 DCHECK_EQ(child->Type(), NGPhysicalFragment::kFragmentBox);
84 NGPhysicalBoxFragment* physical_fragment = 85 NGPhysicalBoxFragment* physical_fragment =
85 ToNGPhysicalBoxFragment(child.Get()); 86 ToNGPhysicalBoxFragment(child.Get());
86 NGBoxFragment fragment(constraint_space.WritingMode(), physical_fragment); 87 NGBoxFragment fragment(constraint_space.WritingMode(), physical_fragment);
87 NGLogicalOffset child_offset = fragment.Offset() + parent_offset; 88 NGLogicalOffset child_offset = fragment.Offset() + parent_offset;
88 CreateBidiRuns(bidi_runs, physical_fragment->Children(), constraint_space, 89 if (physical_fragment->Children().size()) {
89 child_offset, items, text_offsets, 90 CreateBidiRuns(bidi_runs, physical_fragment->Children(),
90 positions_for_bidi_runs_out, positions_out); 91 constraint_space, child_offset, items, text_offsets,
92 positions_for_bidi_runs_out, positions_out);
93 } else {
94 // An empty inline needs a BidiRun for itself.
95 LayoutObject* layout_object = physical_fragment->GetLayoutObject();
96 BidiRun* run = new BidiRun(0, 1, 0, LineLayoutItem(layout_object));
97 bidi_runs->AddRun(run);
98 }
91 // Store box fragments in a map by LineLayoutItem. 99 // Store box fragments in a map by LineLayoutItem.
92 positions_out->Set(LineLayoutItem(child->GetLayoutObject()), 100 positions_out->Set(LineLayoutItem(child->GetLayoutObject()),
93 FragmentPosition{child_offset, fragment.InlineSize()}); 101 FragmentPosition{child_offset, fragment.InlineSize(),
102 fragment.BorderEdges()});
94 } 103 }
95 } 104 }
96 } 105 }
97 106
98 // Set the geometry to InlineBoxes by using the FragmentPosition map. 107 // Set the geometry to InlineBoxes by using the FragmentPosition map.
99 // When the map doesn't provide positions; i.e., when InlineFlowBox doesn't have 108 // When the map doesn't provide positions; i.e., when InlineFlowBox doesn't have
100 // corresponding box fragment, compute the union of children. 109 // corresponding box fragment, compute the union of children.
101 unsigned PlaceInlineBoxChildren( 110 unsigned PlaceInlineBoxChildren(
102 InlineFlowBox* parent, 111 InlineFlowBox* parent,
103 const Vector<FragmentPosition, 32>& positions_for_bidi_runs, 112 const Vector<FragmentPosition, 32>& positions_for_bidi_runs,
104 const HashMap<LineLayoutItem, FragmentPosition>& positions, 113 const HashMap<LineLayoutItem, FragmentPosition>& positions,
105 unsigned text_index = 0, 114 unsigned text_index = 0,
106 bool set_parent_position_from_children = false) { 115 bool set_parent_position_from_children = false) {
107 LayoutUnit logical_left = LayoutUnit::Max(); 116 LayoutUnit logical_left = LayoutUnit::Max();
108 LayoutUnit logical_right = LayoutUnit::Min(); 117 LayoutUnit logical_right = LayoutUnit::Min();
109 LayoutUnit logical_top = LayoutUnit::Max(); 118 LayoutUnit logical_top = LayoutUnit::Max();
110 for (InlineBox* inline_box = parent->FirstChild(); inline_box; 119 for (InlineBox* inline_box = parent->FirstChild(); inline_box;
111 inline_box = inline_box->NextOnLine()) { 120 inline_box = inline_box->NextOnLine()) {
112 if (inline_box->IsInlineFlowBox()) { 121 if (inline_box->IsInlineFlowBox()) {
122 InlineFlowBox* flow_box = ToInlineFlowBox(inline_box);
113 const auto& iter = positions.find(inline_box->GetLineLayoutItem()); 123 const auto& iter = positions.find(inline_box->GetLineLayoutItem());
114 if (iter != positions.end()) { 124 if (iter != positions.end()) {
115 const FragmentPosition& position = iter->value; 125 const FragmentPosition& position = iter->value;
116 inline_box->SetLogicalLeft(position.offset.inline_offset); 126 inline_box->SetLogicalLeft(position.offset.inline_offset);
117 inline_box->SetLogicalTop(position.offset.block_offset); 127 inline_box->SetLogicalTop(position.offset.block_offset);
118 inline_box->SetLogicalWidth(position.inline_size); 128 inline_box->SetLogicalWidth(position.inline_size);
129 flow_box->SetEdges(position.border_edges.line_left,
130 position.border_edges.line_right);
119 } 131 }
120 132
121 text_index = PlaceInlineBoxChildren(ToInlineFlowBox(inline_box), 133 text_index =
122 positions_for_bidi_runs, positions, 134 PlaceInlineBoxChildren(flow_box, positions_for_bidi_runs, positions,
123 text_index, iter == positions.end()); 135 text_index, iter == positions.end());
124 } else { 136 } else {
125 const FragmentPosition& position = positions_for_bidi_runs[text_index++]; 137 const FragmentPosition& position = positions_for_bidi_runs[text_index++];
126 inline_box->SetLogicalLeft(position.offset.inline_offset); 138 inline_box->SetLogicalLeft(position.offset.inline_offset);
127 inline_box->SetLogicalTop(position.offset.block_offset); 139 inline_box->SetLogicalTop(position.offset.block_offset);
128 inline_box->SetLogicalWidth(position.inline_size); 140 inline_box->SetLogicalWidth(position.inline_size);
129 if (inline_box->GetLineLayoutItem().IsBox()) { 141 if (inline_box->GetLineLayoutItem().IsBox()) {
130 LineLayoutBox box(inline_box->GetLineLayoutItem()); 142 LineLayoutBox box(inline_box->GetLineLayoutItem());
131 box.SetLocation(inline_box->Location()); 143 box.SetLocation(inline_box->Location());
132 } 144 }
133 } 145 }
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 current_text->SetTextInternal( 500 current_text->SetTextInternal(
489 Text(current_offset, Data().text_content_.length()).ToString().Impl()); 501 Text(current_offset, Data().text_content_.length()).ToString().Impl());
490 } 502 }
491 } 503 }
492 504
493 String NGInlineNode::ToString() const { 505 String NGInlineNode::ToString() const {
494 return String::Format("NGInlineNode"); 506 return String::Format("NGInlineNode");
495 } 507 }
496 508
497 } // namespace blink 509 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698