Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
|
ikilpatrick
2016/12/02 17:47:06
.nit add period to end.
atotic
2016/12/02 19:55:15
done
| |
| 53 if (child->PhysicalFragment()->Type() == | |
| 54 NGPhysicalFragmentBase::kFragmentBox) { | |
|
ikilpatrick
2016/12/02 17:47:05
this can be fixed here or TODO+another patch, but
atotic
2016/12/02 19:55:15
To rephrase:
All fragments can carry oof descenda
| |
| 55 const NGPhysicalFragment* physical_child = | |
| 56 static_cast<const NGPhysicalFragment*>(&*child->PhysicalFragment()); | |
| 57 Vector<NGCorner> block_offsets = physical_child->OutOfFlowOffsets(); | |
| 58 size_t block_index = 0; | |
| 59 for (auto& block_node : physical_child->OutOfFlowDescendants()) { | |
| 60 NGCorner block_corner = block_offsets[block_index++]; | |
| 61 out_of_flow_descendant_candidates_.add(block_node); | |
|
ikilpatrick
2016/12/02 17:47:06
can we do:
s/block_/oof_/ here?
block is a little
atotic
2016/12/02 19:55:15
done
| |
| 62 oof_candidate_offsets_.append( | |
| 63 OutOfFlowOffset{child_offset, block_corner}); | |
| 64 } | |
| 65 } | |
| 52 return *this; | 66 return *this; |
| 53 } | 67 } |
| 54 | 68 |
| 69 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowCandidateChild( | |
| 70 NGBlockNode* child, | |
| 71 NGLogicalOffset child_offset) { | |
| 72 out_of_flow_descendant_candidates_.add(child); | |
| 73 NGCorner child_corner = | |
| 74 NGCorner::Create(writing_mode_, direction_, NGPhysicalOffset()); | |
| 75 oof_candidate_offsets_.append(OutOfFlowOffset{child_offset, child_corner}); | |
| 76 return *this; | |
| 77 } | |
| 78 | |
| 79 void NGFragmentBuilder::GetOutOfFlowDescendantCandidates( | |
| 80 WeakBoxList& descendants, | |
| 81 Vector<NGCorner>& descendant_corners) { | |
|
ikilpatrick
2016/12/02 17:47:06
change ref to pointer as out param:
https://google
atotic
2016/12/02 19:55:15
done
| |
| 82 descendants.clear(); | |
| 83 descendant_corners.clear(); | |
|
ikilpatrick
2016/12/02 17:47:06
I would do a:
DCHECK(descendants->isEmpty());
DCHE
atotic
2016/12/02 19:55:15
done
| |
| 84 | |
| 85 DCHECK_GE(size_.inline_size, LayoutUnit(0)); | |
| 86 DCHECK_GE(size_.block_size, LayoutUnit(0)); | |
|
ikilpatrick
2016/12/02 17:47:05
just LayoutUnit() for above lines I think.
atotic
2016/12/02 19:55:15
done
| |
| 87 NGPhysicalSize builder_physical_size{size_.ConvertToPhysical(writing_mode_)}; | |
| 88 | |
| 89 size_t offset_index = 0; | |
| 90 for (auto& block_node : out_of_flow_descendant_candidates_) { | |
|
ikilpatrick
2016/12/02 17:47:05
s/block_node/oof_node/
atotic
2016/12/02 19:55:15
done
| |
| 91 OutOfFlowOffset oof_offset = oof_candidate_offsets_[offset_index++]; | |
| 92 | |
| 93 NGPhysicalOffset child_offset = oof_offset.child_offset.ConvertToPhysical( | |
| 94 writing_mode_, direction_, builder_physical_size, NGPhysicalSize()); | |
| 95 | |
| 96 NGCorner builder_relative_corner; | |
| 97 builder_relative_corner.type = oof_offset.descendant_corner.type; | |
| 98 builder_relative_corner.offset = | |
| 99 child_offset + oof_offset.descendant_corner.offset; | |
|
ikilpatrick
2016/12/02 17:47:06
This is great, a lot simpler :)
atotic
2016/12/02 19:55:15
yay
| |
| 100 descendants.add(block_node); | |
| 101 descendant_corners.append(builder_relative_corner); | |
| 102 } | |
| 103 out_of_flow_descendant_candidates_.clear(); | |
| 104 oof_candidate_offsets_.clear(); | |
| 105 } | |
| 106 | |
| 107 NGFragmentBuilder& NGFragmentBuilder::AddOutOfFlowDescendant( | |
| 108 NGBlockNode* descendant, | |
| 109 const NGCorner& corner) { | |
| 110 out_of_flow_descendants_.add(descendant); | |
| 111 out_of_flow_corners_.append(corner); | |
| 112 return *this; | |
| 113 } | |
| 114 | |
| 55 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockStart( | 115 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockStart( |
| 56 const NGMarginStrut& from) { | 116 const NGMarginStrut& from) { |
| 57 margin_strut_.margin_block_start = from.margin_block_start; | 117 margin_strut_.margin_block_start = from.margin_block_start; |
| 58 margin_strut_.negative_margin_block_start = from.negative_margin_block_start; | 118 margin_strut_.negative_margin_block_start = from.negative_margin_block_start; |
| 59 return *this; | 119 return *this; |
| 60 } | 120 } |
| 61 | 121 |
| 62 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd( | 122 NGFragmentBuilder& NGFragmentBuilder::SetMarginStrutBlockEnd( |
| 63 const NGMarginStrut& from) { | 123 const NGMarginStrut& from) { |
| 64 margin_strut_.margin_block_end = from.margin_block_end; | 124 margin_strut_.margin_block_end = from.margin_block_end; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 76 children.reserveCapacity(children_.size()); | 136 children.reserveCapacity(children_.size()); |
| 77 | 137 |
| 78 for (size_t i = 0; i < children_.size(); ++i) { | 138 for (size_t i = 0; i < children_.size(); ++i) { |
| 79 NGPhysicalFragmentBase* child = children_[i].get(); | 139 NGPhysicalFragmentBase* child = children_[i].get(); |
| 80 child->SetOffset(offsets_[i].ConvertToPhysical( | 140 child->SetOffset(offsets_[i].ConvertToPhysical( |
| 81 writing_mode_, direction_, physical_size, child->Size())); | 141 writing_mode_, direction_, physical_size, child->Size())); |
| 82 children.append(child); | 142 children.append(child); |
| 83 } | 143 } |
| 84 return new NGPhysicalFragment( | 144 return new NGPhysicalFragment( |
| 85 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, | 145 physical_size, overflow_.ConvertToPhysical(writing_mode_), children, |
| 86 out_of_flow_descendants_, out_of_flow_offsets_, margin_strut_); | 146 out_of_flow_descendants_, out_of_flow_corners_, margin_strut_); |
| 87 } | 147 } |
| 88 | 148 |
| 89 DEFINE_TRACE(NGFragmentBuilder) { | 149 DEFINE_TRACE(NGFragmentBuilder) { |
| 90 visitor->trace(children_); | 150 visitor->trace(children_); |
| 151 visitor->trace(out_of_flow_descendant_candidates_); | |
| 91 visitor->trace(out_of_flow_descendants_); | 152 visitor->trace(out_of_flow_descendants_); |
| 92 } | 153 } |
| 93 | 154 |
| 94 } // namespace blink | 155 } // namespace blink |
| OLD | NEW |