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 #ifndef NGBlockNode_h | 5 #ifndef NGBlockNode_h |
6 #define NGBlockNode_h | 6 #define NGBlockNode_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/layout/LayoutBox.h" | 9 #include "core/layout/LayoutBox.h" |
10 #include "core/layout/ng/ng_layout_input_node.h" | 10 #include "core/layout/ng/ng_layout_input_node.h" |
| 11 #include "core/layout/ng/ng_layout_result.h" |
11 #include "core/layout/ng/ng_physical_box_fragment.h" | 12 #include "core/layout/ng/ng_physical_box_fragment.h" |
12 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 class ComputedStyle; | 17 class ComputedStyle; |
17 class LayoutObject; | 18 class LayoutObject; |
18 class NGBreakToken; | 19 class NGBreakToken; |
19 class NGConstraintSpace; | 20 class NGConstraintSpace; |
| 21 class NGLayoutResult; |
20 struct NGLogicalOffset; | 22 struct NGLogicalOffset; |
21 class NGPhysicalFragment; | |
22 struct MinAndMaxContentSizes; | 23 struct MinAndMaxContentSizes; |
23 | 24 |
24 // Represents a node to be laid out. | 25 // Represents a node to be laid out. |
25 class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode { | 26 class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode { |
26 friend NGLayoutInputNode; | 27 friend NGLayoutInputNode; |
27 | 28 |
28 public: | 29 public: |
29 explicit NGBlockNode(LayoutObject*); | 30 explicit NGBlockNode(LayoutObject*); |
30 | 31 |
31 // TODO(layout-ng): make it private and declare a friend class to use in tests | 32 // TODO(layout-ng): make it private and declare a friend class to use in tests |
32 explicit NGBlockNode(ComputedStyle*); | 33 explicit NGBlockNode(ComputedStyle*); |
33 | 34 |
34 ~NGBlockNode() override; | 35 ~NGBlockNode() override; |
35 | 36 |
36 RefPtr<NGPhysicalFragment> Layout( | 37 RefPtr<NGLayoutResult> Layout(NGConstraintSpace* constraint_space) override; |
37 NGConstraintSpace* constraint_space) override; | |
38 NGLayoutInputNode* NextSibling() override; | 38 NGLayoutInputNode* NextSibling() override; |
39 LayoutObject* GetLayoutObject() override; | 39 LayoutObject* GetLayoutObject() override; |
40 | 40 |
41 // Computes the value of min-content and max-content for this box. | 41 // Computes the value of min-content and max-content for this box. |
42 // If the underlying layout algorithm's ComputeMinAndMaxContentSizes returns | 42 // If the underlying layout algorithm's ComputeMinAndMaxContentSizes returns |
43 // no value, this function will synthesize these sizes using Layout with | 43 // no value, this function will synthesize these sizes using Layout with |
44 // special constraint spaces -- infinite available size for max content, zero | 44 // special constraint spaces -- infinite available size for max content, zero |
45 // available size for min content, and percentage resolution size zero for | 45 // available size for min content, and percentage resolution size zero for |
46 // both. | 46 // both. |
47 MinAndMaxContentSizes ComputeMinAndMaxContentSizes(); | 47 MinAndMaxContentSizes ComputeMinAndMaxContentSizes(); |
48 | 48 |
49 const ComputedStyle& Style() const; | 49 const ComputedStyle& Style() const; |
50 | 50 |
51 NGLayoutInputNode* FirstChild(); | 51 NGLayoutInputNode* FirstChild(); |
52 | 52 |
53 void SetNextSibling(NGLayoutInputNode*); | 53 void SetNextSibling(NGLayoutInputNode*); |
54 void SetFirstChild(NGLayoutInputNode*); | 54 void SetFirstChild(NGLayoutInputNode*); |
55 | 55 |
56 void SetFragment(NGPhysicalBoxFragment* fragment) { fragment_ = fragment; } | |
57 NGBreakToken* CurrentBreakToken() const; | 56 NGBreakToken* CurrentBreakToken() const; |
58 bool IsLayoutFinished() const { | 57 bool IsLayoutFinished() const { |
59 return fragment_ && !fragment_->BreakToken(); | 58 return layout_result_ && !layout_result_->PhysicalFragment()->BreakToken(); |
60 } | 59 } |
61 | 60 |
62 DECLARE_VIRTUAL_TRACE(); | 61 DECLARE_VIRTUAL_TRACE(); |
63 | 62 |
64 // Runs layout on layout_box_ and creates a fragment for the resulting | 63 // Runs layout on layout_box_ and creates a fragment for the resulting |
65 // geometry. | 64 // geometry. |
66 RefPtr<NGPhysicalBoxFragment> RunOldLayout(const NGConstraintSpace&); | 65 RefPtr<NGLayoutResult> RunOldLayout(const NGConstraintSpace&); |
67 | 66 |
68 // Called if this is an out-of-flow block which needs to be | 67 // Called if this is an out-of-flow block which needs to be |
69 // positioned with legacy layout. | 68 // positioned with legacy layout. |
70 void UseOldOutOfFlowPositioning(); | 69 void UseOldOutOfFlowPositioning(); |
71 | 70 |
72 // Save static position for legacy AbsPos layout. | 71 // Save static position for legacy AbsPos layout. |
73 void SaveStaticOffsetForLegacy(const NGLogicalOffset&); | 72 void SaveStaticOffsetForLegacy(const NGLogicalOffset&); |
74 private: | 73 private: |
75 | 74 |
76 bool CanUseNewLayout(); | 75 bool CanUseNewLayout(); |
77 bool HasInlineChildren(); | 76 bool HasInlineChildren(); |
78 | 77 |
79 // After we run the layout algorithm, this function copies back the geometry | 78 // After we run the layout algorithm, this function copies back the geometry |
80 // data to the layout box. | 79 // data to the layout box. |
81 void CopyFragmentDataToLayoutBox(const NGConstraintSpace&); | 80 void CopyFragmentDataToLayoutBox(const NGConstraintSpace&); |
82 | 81 |
83 // We can either wrap a layout_box_ or a style_/next_sibling_/first_child_ | 82 // We can either wrap a layout_box_ or a style_/next_sibling_/first_child_ |
84 // combination. | 83 // combination. |
85 LayoutBox* layout_box_; | 84 LayoutBox* layout_box_; |
86 RefPtr<ComputedStyle> style_; | 85 RefPtr<ComputedStyle> style_; |
87 Member<NGLayoutInputNode> next_sibling_; | 86 Member<NGLayoutInputNode> next_sibling_; |
88 Member<NGLayoutInputNode> first_child_; | 87 Member<NGLayoutInputNode> first_child_; |
89 // TODO(mstensho): An input node may produce multiple fragments, so this | 88 // TODO(mstensho): An input node may produce multiple fragments, so this |
90 // should probably be renamed to last_fragment_ or something like that, since | 89 // should probably be renamed to last_result_ or something like that, since |
91 // the last fragment is all we care about when resuming layout. | 90 // the last fragment is all we care about when resuming layout. |
92 RefPtr<NGPhysicalBoxFragment> fragment_; | 91 RefPtr<NGLayoutResult> layout_result_; |
93 }; | 92 }; |
94 | 93 |
95 DEFINE_TYPE_CASTS(NGBlockNode, | 94 DEFINE_TYPE_CASTS(NGBlockNode, |
96 NGLayoutInputNode, | 95 NGLayoutInputNode, |
97 node, | 96 node, |
98 node->Type() == NGLayoutInputNode::kLegacyBlock, | 97 node->Type() == NGLayoutInputNode::kLegacyBlock, |
99 node.Type() == NGLayoutInputNode::kLegacyBlock); | 98 node.Type() == NGLayoutInputNode::kLegacyBlock); |
100 | 99 |
101 } // namespace blink | 100 } // namespace blink |
102 | 101 |
103 #endif // NGBlockNode | 102 #endif // NGBlockNode |
OLD | NEW |