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/layout_ng_block_flow.h" | 5 #include "core/layout/ng/layout_ng_block_flow.h" |
6 | 6 |
7 #include "core/layout/LayoutAnalyzer.h" | 7 #include "core/layout/LayoutAnalyzer.h" |
8 #include "core/layout/ng/ng_constraint_space.h" | 8 #include "core/layout/ng/ng_constraint_space.h" |
9 #include "core/layout/ng/ng_fragment.h" | 9 #include "core/layout/ng/ng_fragment.h" |
10 #include "core/layout/ng/ng_layout_result.h" | 10 #include "core/layout/ng/ng_layout_result.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 LayoutNGBlockFlow::LayoutNGBlockFlow(Element* element) | 14 LayoutNGBlockFlow::LayoutNGBlockFlow(Element* element) |
15 : LayoutBlockFlow(element) {} | 15 : LayoutBlockFlow(element) {} |
16 | 16 |
17 bool LayoutNGBlockFlow::IsOfType(LayoutObjectType type) const { | 17 bool LayoutNGBlockFlow::IsOfType(LayoutObjectType type) const { |
18 return type == kLayoutObjectNGBlockFlow || LayoutBlockFlow::IsOfType(type); | 18 return type == kLayoutObjectNGBlockFlow || LayoutBlockFlow::IsOfType(type); |
19 } | 19 } |
20 | 20 |
21 void LayoutNGBlockFlow::UpdateBlockLayout(bool relayout_children) { | 21 void LayoutNGBlockFlow::UpdateBlockLayout(bool relayout_children) { |
22 LayoutAnalyzer::BlockScope analyzer(*this); | 22 LayoutAnalyzer::BlockScope analyzer(*this); |
23 | 23 |
24 RefPtr<NGConstraintSpace> constraint_space = | 24 RefPtr<NGConstraintSpace> constraint_space = |
25 NGConstraintSpace::CreateFromLayoutObject(*this); | 25 NGConstraintSpace::CreateFromLayoutObject(*this); |
26 | 26 RefPtr<NGLayoutResult> result = |
27 // TODO(layout-dev): This should be created in the constructor once instead. | 27 NGBlockNode(this).Layout(constraint_space.Get()); |
28 // There is some internal state which needs to be cleared between layout | |
29 // passes (probably FirstChild(), etc). | |
30 box_ = new NGBlockNode(this); | |
31 | |
32 RefPtr<NGLayoutResult> result = box_->Layout(constraint_space.Get()); | |
33 | 28 |
34 if (IsOutOfFlowPositioned()) { | 29 if (IsOutOfFlowPositioned()) { |
35 // In legacy layout, abspos differs from regular blocks in that abspos | 30 // In legacy layout, abspos differs from regular blocks in that abspos |
36 // blocks position themselves in their own layout, instead of getting | 31 // blocks position themselves in their own layout, instead of getting |
37 // positioned by their parent. So it we are a positioned block in a legacy- | 32 // positioned by their parent. So it we are a positioned block in a legacy- |
38 // layout containing block, we have to emulate this positioning. | 33 // layout containing block, we have to emulate this positioning. |
39 // Additionally, until we natively support abspos in LayoutNG, this code | 34 // Additionally, until we natively support abspos in LayoutNG, this code |
40 // will also be reached though the layoutPositionedObjects call in | 35 // will also be reached though the layoutPositionedObjects call in |
41 // NGBlockNode::CopyFragmentDataToLayoutBox. | 36 // NGBlockNode::CopyFragmentDataToLayoutBox. |
42 LogicalExtentComputedValues computed_values; | 37 LogicalExtentComputedValues computed_values; |
43 ComputeLogicalWidth(computed_values); | 38 ComputeLogicalWidth(computed_values); |
44 SetLogicalLeft(computed_values.position_); | 39 SetLogicalLeft(computed_values.position_); |
45 ComputeLogicalHeight(LogicalHeight(), LogicalTop(), computed_values); | 40 ComputeLogicalHeight(LogicalHeight(), LogicalTop(), computed_values); |
46 SetLogicalTop(computed_values.position_); | 41 SetLogicalTop(computed_values.position_); |
47 } | 42 } |
48 | 43 |
49 for (auto& descendant : result->OutOfFlowDescendants()) | 44 for (NGBlockNode descendant : result->OutOfFlowDescendants()) |
50 descendant->UseOldOutOfFlowPositioning(); | 45 descendant.UseOldOutOfFlowPositioning(); |
51 | 46 |
52 UpdateAfterLayout(); | 47 UpdateAfterLayout(); |
53 ClearNeedsLayout(); | 48 ClearNeedsLayout(); |
54 } | 49 } |
55 | 50 |
56 NGInlineNodeData& LayoutNGBlockFlow::GetNGInlineNodeData() const { | 51 NGInlineNodeData& LayoutNGBlockFlow::GetNGInlineNodeData() const { |
57 DCHECK(ng_inline_node_data_); | 52 DCHECK(ng_inline_node_data_); |
58 return *ng_inline_node_data_.get(); | 53 return *ng_inline_node_data_.get(); |
59 } | 54 } |
60 | 55 |
61 void LayoutNGBlockFlow::ResetNGInlineNodeData() { | 56 void LayoutNGBlockFlow::ResetNGInlineNodeData() { |
62 ng_inline_node_data_ = WTF::MakeUnique<NGInlineNodeData>(); | 57 ng_inline_node_data_ = WTF::MakeUnique<NGInlineNodeData>(); |
63 } | 58 } |
64 | 59 |
65 } // namespace blink | 60 } // namespace blink |
OLD | NEW |