Index: third_party/WebKit/Source/core/layout/ng/ng_fragment_builder.cc |
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_fragment_builder.cc b/third_party/WebKit/Source/core/layout/ng/ng_fragment_builder.cc |
index f886a2951c332719281328db86467a8e4486901c..ead48f97562d0c6bb878efe08963d135c17ba6be 100644 |
--- a/third_party/WebKit/Source/core/layout/ng/ng_fragment_builder.cc |
+++ b/third_party/WebKit/Source/core/layout/ng/ng_fragment_builder.cc |
@@ -44,11 +44,77 @@ NGFragmentBuilder& NGFragmentBuilder::SetBlockOverflow(LayoutUnit size) { |
} |
NGFragmentBuilder& NGFragmentBuilder::AddChild(NGFragmentBase* child, |
- NGLogicalOffset offset) { |
+ NGLogicalOffset child_offset) { |
DCHECK_EQ(type_, NGPhysicalFragmentBase::kFragmentBox) |
<< "Only box fragments can have children"; |
children_.append(child->PhysicalFragment()); |
- offsets_.append(offset); |
+ offsets_.append(child_offset); |
+ // Collect child's out of flow descendants. |
+ // TODO(atotic) All fragments can carry oof descendants. |
+ // Therefore, oof descendants should move from NGPhysicalFragment to |
+ // NGPhysicalFragmentBase |
+ if (child->PhysicalFragment()->Type() == |
+ NGPhysicalFragmentBase::kFragmentBox) { |
+ const NGPhysicalFragment* physical_child = |
+ static_cast<const NGPhysicalFragment*>(&*child->PhysicalFragment()); |
+ Vector<NGCorner> oof_offsets = physical_child->OutOfFlowOffsets(); |
ikilpatrick
2016/12/02 21:06:13
This is inducing a copy?
Vector<NGCorner>& oof_of
atotic
2016/12/02 22:19:37
done
|
+ size_t oof_index = 0; |
+ for (auto& oof_node : physical_child->OutOfFlowDescendants()) { |
+ NGCorner oof_corner = oof_offsets[oof_index++]; |
+ out_of_flow_descendant_candidates_.add(oof_node); |
+ out_of_flow_candidate_placements_.append( |
+ OutOfFlowPlacement{child_offset, oof_corner}); |
+ } |
+ } |
+ return *this; |
+} |
+ |
+NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowChildCandidate( |
+ NGBlockNode* child, |
+ NGLogicalOffset child_offset) { |
+ out_of_flow_descendant_candidates_.add(child); |
+ NGCorner child_corner = |
+ NGCorner::Create(writing_mode_, direction_, NGPhysicalOffset()); |
+ out_of_flow_candidate_placements_.append( |
+ OutOfFlowPlacement{child_offset, child_corner}); |
+ return *this; |
+} |
+ |
+void NGFragmentBuilder::GetOutOfFlowDescendantCandidates( |
+ WeakBoxList* descendants, |
+ Vector<NGCorner>* descendant_corners) { |
+ DCHECK(descendants->isEmpty()); |
+ DCHECK(descendant_corners->isEmpty()); |
+ |
+ DCHECK_GE(size_.inline_size, LayoutUnit()); |
+ DCHECK_GE(size_.block_size, LayoutUnit()); |
+ NGPhysicalSize builder_physical_size{size_.ConvertToPhysical(writing_mode_)}; |
+ |
+ size_t placement_index = 0; |
+ for (auto& oof_node : out_of_flow_descendant_candidates_) { |
+ OutOfFlowPlacement oof_placement = |
+ out_of_flow_candidate_placements_[placement_index++]; |
+ |
+ NGPhysicalOffset child_offset = |
+ oof_placement.child_offset.ConvertToPhysical( |
+ writing_mode_, direction_, builder_physical_size, NGPhysicalSize()); |
+ |
+ NGCorner builder_relative_corner; |
+ builder_relative_corner.type = oof_placement.descendant_corner.type; |
+ builder_relative_corner.offset = |
+ child_offset + oof_placement.descendant_corner.offset; |
+ descendants->add(oof_node); |
+ descendant_corners->append(builder_relative_corner); |
+ } |
+ out_of_flow_descendant_candidates_.clear(); |
+ out_of_flow_candidate_placements_.clear(); |
+} |
+ |
+NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowDescendant( |
+ NGBlockNode* descendant, |
+ const NGCorner& corner) { |
+ out_of_flow_descendants_.add(descendant); |
+ out_of_flow_corners_.append(corner); |
return *this; |
} |
@@ -83,11 +149,12 @@ NGPhysicalFragment* NGFragmentBuilder::ToFragment() { |
} |
return new NGPhysicalFragment( |
physical_size, overflow_.ConvertToPhysical(writing_mode_), children, |
- out_of_flow_descendants_, out_of_flow_offsets_, margin_strut_); |
+ out_of_flow_descendants_, out_of_flow_corners_, margin_strut_); |
} |
DEFINE_TRACE(NGFragmentBuilder) { |
visitor->trace(children_); |
+ visitor->trace(out_of_flow_descendant_candidates_); |
visitor->trace(out_of_flow_descendants_); |
} |