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/ng/ng_layout_input_node.h" | 9 #include "core/layout/ng/ng_layout_input_node.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 class ComputedStyle; | 14 class ComputedStyle; |
15 class LayoutBox; | 15 class LayoutBox; |
16 class LayoutObject; | 16 class LayoutObject; |
17 class NGConstraintSpace; | 17 class NGConstraintSpace; |
18 class NGFragmentBase; | 18 class NGFragment; |
19 class NGLayoutAlgorithm; | 19 class NGLayoutAlgorithm; |
20 class NGLayoutCoordinator; | 20 class NGLayoutCoordinator; |
21 class NGPhysicalFragment; | 21 class NGPhysicalBoxFragment; |
22 struct MinAndMaxContentSizes; | 22 struct MinAndMaxContentSizes; |
23 | 23 |
24 // Represents a node to be laid out. | 24 // Represents a node to be laid out. |
25 class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode { | 25 class CORE_EXPORT NGBlockNode final : public NGLayoutInputNode { |
26 friend NGLayoutInputNode; | 26 friend NGLayoutInputNode; |
27 | 27 |
28 public: | 28 public: |
29 explicit NGBlockNode(LayoutObject*); | 29 explicit NGBlockNode(LayoutObject*); |
30 | 30 |
31 // TODO(layout-ng): make it private and declare a friend class to use in tests | 31 // TODO(layout-ng): make it private and declare a friend class to use in tests |
32 explicit NGBlockNode(ComputedStyle*); | 32 explicit NGBlockNode(ComputedStyle*); |
33 | 33 |
34 ~NGBlockNode() override; | 34 ~NGBlockNode() override; |
35 | 35 |
36 bool Layout(NGConstraintSpace*, NGFragmentBase**) override; | 36 bool Layout(NGConstraintSpace*, NGFragment**) override; |
37 NGBlockNode* NextSibling() override; | 37 NGBlockNode* NextSibling() override; |
38 | 38 |
39 // Computes the value of min-content and max-content for this box. | 39 // Computes the value of min-content and max-content for this box. |
40 // The return value has the same meaning as for Layout. | 40 // The return value has the same meaning as for Layout. |
41 // If the underlying layout algorithm returns NotImplemented from | 41 // If the underlying layout algorithm returns NotImplemented from |
42 // ComputeMinAndMaxContentSizes, this function will synthesize these sizes | 42 // ComputeMinAndMaxContentSizes, this function will synthesize these sizes |
43 // using Layout with special constraint spaces. | 43 // using Layout with special constraint spaces. |
44 // It is not legal to interleave a pending Layout() with a pending | 44 // It is not legal to interleave a pending Layout() with a pending |
45 // ComputeOrSynthesizeMinAndMaxContentSizes (i.e. you have to call Layout | 45 // ComputeOrSynthesizeMinAndMaxContentSizes (i.e. you have to call Layout |
46 // often enough that it returns true before calling | 46 // often enough that it returns true before calling |
47 // ComputeOrSynthesizeMinAndMaxContentSizes) | 47 // ComputeOrSynthesizeMinAndMaxContentSizes) |
48 bool ComputeMinAndMaxContentSizes(MinAndMaxContentSizes*); | 48 bool ComputeMinAndMaxContentSizes(MinAndMaxContentSizes*); |
49 | 49 |
50 const ComputedStyle* Style() const; | 50 const ComputedStyle* Style() const; |
51 ComputedStyle* MutableStyle(); | 51 ComputedStyle* MutableStyle(); |
52 | 52 |
53 NGLayoutInputNode* FirstChild(); | 53 NGLayoutInputNode* FirstChild(); |
54 | 54 |
55 void SetNextSibling(NGBlockNode*); | 55 void SetNextSibling(NGBlockNode*); |
56 void SetFirstChild(NGLayoutInputNode*); | 56 void SetFirstChild(NGLayoutInputNode*); |
57 | 57 |
58 DECLARE_VIRTUAL_TRACE(); | 58 DECLARE_VIRTUAL_TRACE(); |
59 | 59 |
60 // Runs layout on layout_box_ and creates a fragment for the resulting | 60 // Runs layout on layout_box_ and creates a fragment for the resulting |
61 // geometry. | 61 // geometry. |
62 NGPhysicalFragment* RunOldLayout(const NGConstraintSpace&); | 62 NGPhysicalBoxFragment* RunOldLayout(const NGConstraintSpace&); |
63 | 63 |
64 // Called if this is an out-of-flow block which needs to be | 64 // Called if this is an out-of-flow block which needs to be |
65 // positioned with legacy layout. | 65 // positioned with legacy layout. |
66 void UseOldOutOfFlowPositioning(); | 66 void UseOldOutOfFlowPositioning(); |
67 | 67 |
68 void UpdateLayoutBox(NGPhysicalFragment* fragment, | 68 void UpdateLayoutBox(NGPhysicalBoxFragment* fragment, |
69 const NGConstraintSpace* constraint_space); | 69 const NGConstraintSpace* constraint_space); |
70 | 70 |
71 private: | 71 private: |
72 // This is necessary for interop between old and new trees -- after our parent | 72 // This is necessary for interop between old and new trees -- after our parent |
73 // positions us, it calls this function so we can store the position on the | 73 // positions us, it calls this function so we can store the position on the |
74 // underlying LayoutBox. | 74 // underlying LayoutBox. |
75 void PositionUpdated(); | 75 void PositionUpdated(); |
76 | 76 |
77 bool CanUseNewLayout(); | 77 bool CanUseNewLayout(); |
78 bool HasInlineChildren(); | 78 bool HasInlineChildren(); |
79 | 79 |
80 // After we run the layout algorithm, this function copies back the geometry | 80 // After we run the layout algorithm, this function copies back the geometry |
81 // data to the layout box. | 81 // data to the layout box. |
82 void CopyFragmentDataToLayoutBox(const NGConstraintSpace&); | 82 void CopyFragmentDataToLayoutBox(const NGConstraintSpace&); |
83 | 83 |
84 // We can either wrap a layout_box_ or a style_/next_sibling_/first_child_ | 84 // We can either wrap a layout_box_ or a style_/next_sibling_/first_child_ |
85 // combination. | 85 // combination. |
86 LayoutBox* layout_box_; | 86 LayoutBox* layout_box_; |
87 RefPtr<ComputedStyle> style_; | 87 RefPtr<ComputedStyle> style_; |
88 Member<NGBlockNode> next_sibling_; | 88 Member<NGBlockNode> next_sibling_; |
89 Member<NGLayoutInputNode> first_child_; | 89 Member<NGLayoutInputNode> first_child_; |
90 Member<NGLayoutCoordinator> layout_coordinator_; | 90 Member<NGLayoutCoordinator> layout_coordinator_; |
91 Member<NGLayoutAlgorithm> minmax_algorithm_; | 91 Member<NGLayoutAlgorithm> minmax_algorithm_; |
92 Member<NGPhysicalFragment> fragment_; | 92 Member<NGPhysicalBoxFragment> fragment_; |
93 }; | 93 }; |
94 | 94 |
95 DEFINE_TYPE_CASTS(NGBlockNode, | 95 DEFINE_TYPE_CASTS(NGBlockNode, |
96 NGLayoutInputNode, | 96 NGLayoutInputNode, |
97 node, | 97 node, |
98 node->Type() == NGLayoutInputNode::kLegacyBlock, | 98 node->Type() == NGLayoutInputNode::kLegacyBlock, |
99 node.Type() == NGLayoutInputNode::kLegacyBlock); | 99 node.Type() == NGLayoutInputNode::kLegacyBlock); |
100 | 100 |
101 } // namespace blink | 101 } // namespace blink |
102 | 102 |
103 #endif // NGBlockNode | 103 #endif // NGBlockNode |
OLD | NEW |