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

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

Issue 2612103004: [ng_layout] Rename NGFragmentBase,NGFragment,NGPhysicalFragment (Closed)
Patch Set: CR: rename ifdef guards Created 3 years, 11 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_fragment_builder.h" 5 #include "core/layout/ng/ng_fragment_builder.h"
6 6
7 #include "core/layout/ng/ng_block_node.h" 7 #include "core/layout/ng/ng_block_node.h"
8 #include "core/layout/ng/ng_fragment_base.h"
9 #include "core/layout/ng/ng_physical_fragment.h"
10 #include "core/layout/ng/ng_physical_text_fragment.h" 8 #include "core/layout/ng/ng_physical_text_fragment.h"
9 #include "core/layout/ng/ng_fragment.h"
10 #include "core/layout/ng/ng_physical_box_fragment.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 NGFragmentBuilder::NGFragmentBuilder( 14 NGFragmentBuilder::NGFragmentBuilder(NGPhysicalFragment::NGFragmentType type)
15 NGPhysicalFragmentBase::NGFragmentType type)
16 : type_(type), 15 : type_(type),
17 writing_mode_(kHorizontalTopBottom), 16 writing_mode_(kHorizontalTopBottom),
18 direction_(TextDirection::Ltr) {} 17 direction_(TextDirection::Ltr) {}
19 18
20 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode( 19 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode(
21 NGWritingMode writing_mode) { 20 NGWritingMode writing_mode) {
22 writing_mode_ = writing_mode; 21 writing_mode_ = writing_mode;
23 return *this; 22 return *this;
24 } 23 }
25 24
(...skipping 16 matching lines...) Expand all
42 overflow_.inline_size = size; 41 overflow_.inline_size = size;
43 return *this; 42 return *this;
44 } 43 }
45 44
46 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) { 45 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) {
47 overflow_.block_size = size; 46 overflow_.block_size = size;
48 return *this; 47 return *this;
49 } 48 }
50 49
51 NGFragmentBuilder& NGFragmentBuilder::AddChild( 50 NGFragmentBuilder& NGFragmentBuilder::AddChild(
52 NGFragmentBase* child, 51 NGFragment* child,
53 const NGLogicalOffset& child_offset) { 52 const NGLogicalOffset& child_offset) {
54 DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentBox) 53 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox)
55 << "Only box fragments can have children"; 54 << "Only box fragments can have children";
56 children_.append(child->PhysicalFragment()); 55 children_.append(child->PhysicalFragment());
57 offsets_.append(child_offset); 56 offsets_.append(child_offset);
58 // Collect child's out of flow descendants. 57 // Collect child's out of flow descendants.
59 const NGPhysicalFragmentBase* physical_fragment = child->PhysicalFragment(); 58 const NGPhysicalFragment* physical_fragment = child->PhysicalFragment();
60 const Vector<NGStaticPosition>& oof_positions = 59 const Vector<NGStaticPosition>& oof_positions =
61 physical_fragment->OutOfFlowPositions(); 60 physical_fragment->OutOfFlowPositions();
62 size_t oof_index = 0; 61 size_t oof_index = 0;
63 for (auto& oof_node : physical_fragment->OutOfFlowDescendants()) { 62 for (auto& oof_node : physical_fragment->OutOfFlowDescendants()) {
64 NGStaticPosition oof_position = oof_positions[oof_index++]; 63 NGStaticPosition oof_position = oof_positions[oof_index++];
65 out_of_flow_descendant_candidates_.add(oof_node); 64 out_of_flow_descendant_candidates_.add(oof_node);
66 out_of_flow_candidate_placements_.append( 65 out_of_flow_candidate_placements_.append(
67 OutOfFlowPlacement{child_offset, oof_position}); 66 OutOfFlowPlacement{child_offset, oof_position});
68 } 67 }
69 return *this; 68 return *this;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 return *this; 124 return *this;
126 } 125 }
127 126
128 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd( 127 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd(
129 const NGMarginStrut& from) { 128 const NGMarginStrut& from) {
130 margin_strut_.margin_block_end = from.margin_block_end; 129 margin_strut_.margin_block_end = from.margin_block_end;
131 margin_strut_.negative_margin_block_end = from.negative_margin_block_end; 130 margin_strut_.negative_margin_block_end = from.negative_margin_block_end;
132 return *this; 131 return *this;
133 } 132 }
134 133
135 NGPhysicalFragment* NGFragmentBuilder::ToFragment() { 134 NGPhysicalBoxFragment* NGFragmentBuilder::ToBoxFragment() {
136 // TODO(layout-ng): Support text fragments 135 // TODO(layout-ng): Support text fragments
137 DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentBox); 136 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox);
138 DCHECK_EQ(offsets_.size(), children_.size()); 137 DCHECK_EQ(offsets_.size(), children_.size());
139 138
140 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); 139 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_);
141 HeapVector<Member<const NGPhysicalFragmentBase>> children; 140 HeapVector<Member<const NGPhysicalFragment>> children;
142 children.reserveCapacity(children_.size()); 141 children.reserveCapacity(children_.size());
143 142
144 for (size_t i = 0; i < children_.size(); ++i) { 143 for (size_t i = 0; i < children_.size(); ++i) {
145 NGPhysicalFragmentBase* child = children_[i].get(); 144 NGPhysicalFragment* child = children_[i].get();
146 child->SetOffset(offsets_[i].ConvertToPhysical( 145 child->SetOffset(offsets_[i].ConvertToPhysical(
147 writing_mode_, direction_, physical_size, child->Size())); 146 writing_mode_, direction_, physical_size, child->Size()));
148 children.append(child); 147 children.append(child);
149 } 148 }
150 return new NGPhysicalFragment( 149 return new NGPhysicalBoxFragment(
151 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, 150 physical_size, overflow_.ConvertToPhysical(writing_mode_), children,
152 out_of_flow_descendants_, out_of_flow_positions_, margin_strut_); 151 out_of_flow_descendants_, out_of_flow_positions_, margin_strut_);
153 } 152 }
154 153
155 NGPhysicalTextFragment* NGFragmentBuilder::ToTextFragment(NGInlineNode* node, 154 NGPhysicalTextFragment* NGFragmentBuilder::ToTextFragment(NGInlineNode* node,
156 unsigned start_index, 155 unsigned start_index,
157 unsigned end_index) { 156 unsigned end_index) {
158 DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentText); 157 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentText);
159 DCHECK(children_.isEmpty()); 158 DCHECK(children_.isEmpty());
160 DCHECK(offsets_.isEmpty()); 159 DCHECK(offsets_.isEmpty());
161 return new NGPhysicalTextFragment( 160 return new NGPhysicalTextFragment(
162 node, start_index, end_index, size_.ConvertToPhysical(writing_mode_), 161 node, start_index, end_index, size_.ConvertToPhysical(writing_mode_),
163 overflow_.ConvertToPhysical(writing_mode_), out_of_flow_descendants_, 162 overflow_.ConvertToPhysical(writing_mode_), out_of_flow_descendants_,
164 out_of_flow_positions_); 163 out_of_flow_positions_);
165 } 164 }
166 165
167 DEFINE_TRACE(NGFragmentBuilder) { 166 DEFINE_TRACE(NGFragmentBuilder) {
168 visitor->trace(children_); 167 visitor->trace(children_);
169 visitor->trace(out_of_flow_descendant_candidates_); 168 visitor->trace(out_of_flow_descendant_candidates_);
170 visitor->trace(out_of_flow_descendants_); 169 visitor->trace(out_of_flow_descendants_);
171 } 170 }
172 171
173 } // namespace blink 172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698