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

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

Issue 2540653003: Implement collection of out-of-flow descendants (Closed)
Patch Set: Merge conflicts resolved Created 4 years 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 #include "core/layout/ng/ng_block_node.h" 6 #include "core/layout/ng/ng_block_node.h"
7 #include "core/style/ComputedStyle.h" 7 #include "core/style/ComputedStyle.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
(...skipping 26 matching lines...) Expand all
37 overflow_.inline_size = size; 37 overflow_.inline_size = size;
38 return *this; 38 return *this;
39 } 39 }
40 40
41 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) { 41 NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) {
42 overflow_.block_size = size; 42 overflow_.block_size = size;
43 return *this; 43 return *this;
44 } 44 }
45 45
46 NGFragmentBuilder& NGFragmentBuilder::AddChild(NGFragmentBase* child, 46 NGFragmentBuilder& NGFragmentBuilder::AddChild(NGFragmentBase* child,
47 NGLogicalOffset offset) { 47 NGLogicalOffset child_offset) {
48 DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentBox) 48 DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentBox)
49 << "Only box fragments can have children"; 49 << "Only box fragments can have children";
50 children_.append(child->PhysicalFragment()); 50 children_.append(child->PhysicalFragment());
51 offsets_.append(offset); 51 offsets_.append(child_offset);
52 // Collect child's out of flow descendants.
53 // TODO(atotic) All fragments can carry oof descendants.
54 // Therefore, oof descendants should move from NGPhysicalFragment to
55 // NGPhysicalFragmentBase
56 if (child->PhysicalFragment()->Type() ==
57 NGPhysicalFragmentBase::kFragmentBox) {
58 const NGPhysicalFragment* physical_child =
59 static_cast<const NGPhysicalFragment*>(&*child->PhysicalFragment());
60 const Vector<NGStaticPosition>& oof_positions =
61 physical_child->OutOfFlowPositions();
62 size_t oof_index = 0;
63 for (auto& oof_node : physical_child->OutOfFlowDescendants()) {
64 NGStaticPosition oof_position = oof_positions[oof_index++];
65 out_of_flow_descendant_candidates_.add(oof_node);
66 out_of_flow_candidate_placements_.append(
67 OutOfFlowPlacement{child_offset, oof_position});
68 }
69 }
52 return *this; 70 return *this;
53 } 71 }
54 72
73 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowChildCandidate(
74 NGBlockNode* child,
75 NGLogicalOffset child_offset) {
76 out_of_flow_descendant_candidates_.add(child);
77 NGStaticPosition child_position =
78 NGStaticPosition::Create(writing_mode_, direction_, NGPhysicalOffset());
79 out_of_flow_candidate_placements_.append(
80 OutOfFlowPlacement{child_offset, child_position});
81 return *this;
82 }
83
84 void NGFragmentBuilder::GetAndClearOutOfFlowDescendantCandidates(
85 WeakBoxList* descendants,
86 Vector<NGStaticPosition>* descendant_positions) {
87 DCHECK(descendants->isEmpty());
88 DCHECK(descendant_positions->isEmpty());
89
90 DCHECK_GE(size_.inline_size, LayoutUnit());
91 DCHECK_GE(size_.block_size, LayoutUnit());
92 NGPhysicalSize builder_physical_size{size_.ConvertToPhysical(writing_mode_)};
93
94 size_t placement_index = 0;
95 for (auto& oof_node : out_of_flow_descendant_candidates_) {
96 OutOfFlowPlacement oof_placement =
97 out_of_flow_candidate_placements_[placement_index++];
98
99 NGPhysicalOffset child_offset =
100 oof_placement.child_offset.ConvertToPhysical(
101 writing_mode_, direction_, builder_physical_size, NGPhysicalSize());
102
103 NGStaticPosition builder_relative_position;
104 builder_relative_position.type = oof_placement.descendant_position.type;
105 builder_relative_position.offset =
106 child_offset + oof_placement.descendant_position.offset;
107 descendants->add(oof_node);
108 descendant_positions->append(builder_relative_position);
109 }
110 out_of_flow_descendant_candidates_.clear();
111 out_of_flow_candidate_placements_.clear();
112 }
113
114 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowDescendant(
115 NGBlockNode* descendant,
116 const NGStaticPosition& position) {
117 out_of_flow_descendants_.add(descendant);
118 out_of_flow_positions_.append(position);
119 return *this;
120 }
121
55 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockStart( 122 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockStart(
56 const NGMarginStrut& from) { 123 const NGMarginStrut& from) {
57 margin_strut_.margin_block_start = from.margin_block_start; 124 margin_strut_.margin_block_start = from.margin_block_start;
58 margin_strut_.negative_margin_block_start = from.negative_margin_block_start; 125 margin_strut_.negative_margin_block_start = from.negative_margin_block_start;
59 return *this; 126 return *this;
60 } 127 }
61 128
62 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd( 129 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd(
63 const NGMarginStrut& from) { 130 const NGMarginStrut& from) {
64 margin_strut_.margin_block_end = from.margin_block_end; 131 margin_strut_.margin_block_end = from.margin_block_end;
(...skipping 11 matching lines...) Expand all
76 children.reserveCapacity(children_.size()); 143 children.reserveCapacity(children_.size());
77 144
78 for (size_t i = 0; i < children_.size(); ++i) { 145 for (size_t i = 0; i < children_.size(); ++i) {
79 NGPhysicalFragmentBase* child = children_[i].get(); 146 NGPhysicalFragmentBase* child = children_[i].get();
80 child->SetOffset(offsets_[i].ConvertToPhysical( 147 child->SetOffset(offsets_[i].ConvertToPhysical(
81 writing_mode_, direction_, physical_size, child->Size())); 148 writing_mode_, direction_, physical_size, child->Size()));
82 children.append(child); 149 children.append(child);
83 } 150 }
84 return new NGPhysicalFragment( 151 return new NGPhysicalFragment(
85 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, 152 physical_size, overflow_.ConvertToPhysical(writing_mode_), children,
86 out_of_flow_descendants_, out_of_flow_offsets_, margin_strut_); 153 out_of_flow_descendants_, out_of_flow_positions_, margin_strut_);
87 } 154 }
88 155
89 DEFINE_TRACE(NGFragmentBuilder) { 156 DEFINE_TRACE(NGFragmentBuilder) {
90 visitor->trace(children_); 157 visitor->trace(children_);
158 visitor->trace(out_of_flow_descendant_candidates_);
91 visitor->trace(out_of_flow_descendants_); 159 visitor->trace(out_of_flow_descendants_);
92 } 160 }
93 161
94 } // namespace blink 162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698