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

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

Issue 2714803002: [LayoutNG] Allow block-flow layout to be fragmented using new approach. (Closed)
Patch Set: rebase. 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_fragment_builder.h" 5 #include "core/layout/ng/ng_fragment_builder.h"
6 6
7 #include "core/layout/ng/ng_block_break_token.h"
7 #include "core/layout/ng/ng_block_node.h" 8 #include "core/layout/ng/ng_block_node.h"
8 #include "core/layout/ng/ng_break_token.h" 9 #include "core/layout/ng/ng_break_token.h"
9 #include "core/layout/ng/ng_fragment.h" 10 #include "core/layout/ng/ng_fragment.h"
10 #include "core/layout/ng/ng_physical_box_fragment.h" 11 #include "core/layout/ng/ng_physical_box_fragment.h"
11 #include "core/layout/ng/ng_physical_text_fragment.h" 12 #include "core/layout/ng/ng_physical_text_fragment.h"
13 #include "platform/heap/Handle.h"
12 14
13 namespace blink { 15 namespace blink {
14 16
15 // TODO(ikilpatrick): Make writing mode and direction be in the constructor. 17 // TODO(ikilpatrick): Make writing mode and direction be in the constructor.
16 NGFragmentBuilder::NGFragmentBuilder(NGPhysicalFragment::NGFragmentType type, 18 NGFragmentBuilder::NGFragmentBuilder(NGPhysicalFragment::NGFragmentType type,
17 NGLayoutInputNode* node) 19 NGLayoutInputNode* node)
18 : type_(type), 20 : type_(type),
19 writing_mode_(kHorizontalTopBottom), 21 writing_mode_(kHorizontalTopBottom),
20 direction_(TextDirection::kLtr), 22 direction_(TextDirection::kLtr),
21 node_(node) {} 23 node_(node),
24 did_break_(false) {
25 child_break_tokens_ = new HeapVector<Member<NGBreakToken>>();
26 }
22 27
23 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode( 28 NGFragmentBuilder& NGFragmentBuilder::SetWritingMode(
24 NGWritingMode writing_mode) { 29 NGWritingMode writing_mode) {
25 writing_mode_ = writing_mode; 30 writing_mode_ = writing_mode;
26 return *this; 31 return *this;
27 } 32 }
28 33
29 NGFragmentBuilder& NGFragmentBuilder::SetDirection(TextDirection direction) { 34 NGFragmentBuilder& NGFragmentBuilder::SetDirection(TextDirection direction) {
30 direction_ = direction; 35 direction_ = direction;
31 return *this; 36 return *this;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 74
70 return AddChild(child->PhysicalFragment(), child_offset); 75 return AddChild(child->PhysicalFragment(), child_offset);
71 } 76 }
72 77
73 NGFragmentBuilder& NGFragmentBuilder::AddChild( 78 NGFragmentBuilder& NGFragmentBuilder::AddChild(
74 RefPtr<NGPhysicalFragment> child, 79 RefPtr<NGPhysicalFragment> child,
75 const NGLogicalOffset& child_offset) { 80 const NGLogicalOffset& child_offset) {
76 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox) 81 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox)
77 << "Only box fragments can have children"; 82 << "Only box fragments can have children";
78 83
84 // Update if we have fragmented in this flow.
85 did_break_ |= child->IsBox() && !child->BreakToken()->IsFinished();
86
87 child_break_tokens_->push_back(child->BreakToken());
79 children_.push_back(std::move(child)); 88 children_.push_back(std::move(child));
80 offsets_.push_back(child_offset); 89 offsets_.push_back(child_offset);
81 90
82 return *this; 91 return *this;
83 } 92 }
84 93
85 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject( 94 NGFragmentBuilder& NGFragmentBuilder::AddFloatingObject(
86 NGFloatingObject* floating_object, 95 NGFloatingObject* floating_object,
87 const NGLogicalOffset& floating_object_offset) { 96 const NGLogicalOffset& floating_object_offset) {
88 positioned_floats_.push_back(floating_object); 97 positioned_floats_.push_back(floating_object);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 out_of_flow_descendants_.add(descendant); 159 out_of_flow_descendants_.add(descendant);
151 out_of_flow_positions_.push_back(position); 160 out_of_flow_positions_.push_back(position);
152 return *this; 161 return *this;
153 } 162 }
154 163
155 RefPtr<NGLayoutResult> NGFragmentBuilder::ToBoxFragment() { 164 RefPtr<NGLayoutResult> NGFragmentBuilder::ToBoxFragment() {
156 // TODO(layout-ng): Support text fragments 165 // TODO(layout-ng): Support text fragments
157 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox); 166 DCHECK_EQ(type_, NGPhysicalFragment::kFragmentBox);
158 DCHECK_EQ(offsets_.size(), children_.size()); 167 DCHECK_EQ(offsets_.size(), children_.size());
159 168
160 auto* break_token = break_token_.get();
161 break_token_ = nullptr;
162
163 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_); 169 NGPhysicalSize physical_size = size_.ConvertToPhysical(writing_mode_);
164 170
165 for (size_t i = 0; i < children_.size(); ++i) { 171 for (size_t i = 0; i < children_.size(); ++i) {
166 NGPhysicalFragment* child = children_[i].get(); 172 NGPhysicalFragment* child = children_[i].get();
167 child->SetOffset(offsets_[i].ConvertToPhysical( 173 child->SetOffset(offsets_[i].ConvertToPhysical(
168 writing_mode_, direction_, physical_size, child->Size())); 174 writing_mode_, direction_, physical_size, child->Size()));
169 } 175 }
170 176
171 Vector<Persistent<NGFloatingObject>> positioned_floats; 177 Vector<Persistent<NGFloatingObject>> positioned_floats;
172 positioned_floats.reserveCapacity(positioned_floats_.size()); 178 positioned_floats.reserveCapacity(positioned_floats_.size());
173 179
180 Persistent<NGBreakToken> break_token;
181 if (did_break_) {
182 break_token =
183 new NGBlockBreakToken(toNGBlockNode(node_.get()), used_block_size_,
184 *child_break_tokens_.get());
185 } else {
186 break_token = new NGBlockBreakToken(node_.get());
187 }
188
174 for (size_t i = 0; i < positioned_floats_.size(); ++i) { 189 for (size_t i = 0; i < positioned_floats_.size(); ++i) {
175 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i]; 190 Persistent<NGFloatingObject>& floating_object = positioned_floats_[i];
176 NGPhysicalFragment* floating_fragment = floating_object->fragment.get(); 191 NGPhysicalFragment* floating_fragment = floating_object->fragment.get();
177 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical( 192 floating_fragment->SetOffset(floating_object_offsets_[i].ConvertToPhysical(
178 writing_mode_, direction_, physical_size, floating_fragment->Size())); 193 writing_mode_, direction_, physical_size, floating_fragment->Size()));
179 positioned_floats.push_back(floating_object); 194 positioned_floats.push_back(floating_object);
180 } 195 }
181 196
182 RefPtr<NGPhysicalBoxFragment> fragment = adoptRef(new NGPhysicalBoxFragment( 197 RefPtr<NGPhysicalBoxFragment> fragment = adoptRef(new NGPhysicalBoxFragment(
183 node_->GetLayoutObject(), physical_size, 198 node_->GetLayoutObject(), physical_size,
(...skipping 16 matching lines...) Expand all
200 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats; 215 Vector<Persistent<NGFloatingObject>> empty_unpositioned_floats;
201 Vector<Persistent<NGFloatingObject>> empty_positioned_floats; 216 Vector<Persistent<NGFloatingObject>> empty_positioned_floats;
202 217
203 return adoptRef(new NGPhysicalTextFragment( 218 return adoptRef(new NGPhysicalTextFragment(
204 node_->GetLayoutObject(), toNGInlineNode(node_), index, start_offset, 219 node_->GetLayoutObject(), toNGInlineNode(node_), index, start_offset,
205 end_offset, size_.ConvertToPhysical(writing_mode_), 220 end_offset, size_.ConvertToPhysical(writing_mode_),
206 overflow_.ConvertToPhysical(writing_mode_))); 221 overflow_.ConvertToPhysical(writing_mode_)));
207 } 222 }
208 223
209 } // namespace blink 224 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698