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 NGLayoutAlgorithm_h | 5 #ifndef NGLayoutAlgorithm_h |
6 #define NGLayoutAlgorithm_h | 6 #define NGLayoutAlgorithm_h |
7 | 7 |
8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
9 #include "core/layout/ng/ng_min_max_content_size.h" | 9 #include "core/layout/ng/ng_min_max_content_size.h" |
10 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
11 #include "wtf/Noncopyable.h" | |
12 #include "wtf/Optional.h" | 11 #include "wtf/Optional.h" |
13 | 12 |
14 namespace blink { | 13 namespace blink { |
15 | 14 |
16 struct MinMaxContentSize; | 15 class ComputedStyle; |
| 16 class NGConstraintSpace; |
17 class NGLayoutResult; | 17 class NGLayoutResult; |
18 | 18 |
19 // Base class for all LayoutNG algorithms. | 19 // Base class for all LayoutNG algorithms. |
| 20 template <typename NGInputNodeType, typename NGBreakTokenType> |
20 class CORE_EXPORT NGLayoutAlgorithm { | 21 class CORE_EXPORT NGLayoutAlgorithm { |
21 STACK_ALLOCATED(); | 22 STACK_ALLOCATED(); |
| 23 public: |
| 24 NGLayoutAlgorithm(NGInputNodeType* node, |
| 25 NGConstraintSpace* space, |
| 26 NGBreakTokenType* break_token) |
| 27 : node_(node), constraint_space_(space), break_token_(break_token) {} |
22 | 28 |
23 public: | |
24 virtual ~NGLayoutAlgorithm() {} | 29 virtual ~NGLayoutAlgorithm() {} |
25 | 30 |
26 // Actual layout function. Lays out the children and descendants within the | 31 // Actual layout function. Lays out the children and descendants within the |
27 // constraints given by the NGConstraintSpace. Returns a layout result with | 32 // constraints given by the NGConstraintSpace. Returns a layout result with |
28 // the resulting layout information. | 33 // the resulting layout information. |
29 // TODO(layout-dev): attempt to make this function const. | 34 // TODO(layout-dev): attempt to make this function const. |
30 virtual RefPtr<NGLayoutResult> Layout() = 0; | 35 virtual RefPtr<NGLayoutResult> Layout() = 0; |
31 | 36 |
32 // Computes the min-content and max-content intrinsic sizes for the given box. | 37 // Computes the min-content and max-content intrinsic sizes for the given box. |
33 // The result will not take any min-width, max-width or width properties into | 38 // The result will not take any min-width, max-width or width properties into |
34 // account. If the return value is empty, the caller is expected to synthesize | 39 // account. If the return value is empty, the caller is expected to synthesize |
35 // this value from the overflow rect returned from Layout called with an | 40 // this value from the overflow rect returned from Layout called with an |
36 // available width of 0 and LayoutUnit::max(), respectively. | 41 // available width of 0 and LayoutUnit::max(), respectively. |
37 virtual Optional<MinMaxContentSize> ComputeMinMaxContentSize() const { | 42 virtual Optional<MinMaxContentSize> ComputeMinMaxContentSize() const { |
38 return WTF::nullopt; | 43 return WTF::nullopt; |
39 } | 44 } |
| 45 |
| 46 protected: |
| 47 const NGConstraintSpace& ConstraintSpace() const { |
| 48 DCHECK(constraint_space_); |
| 49 return *constraint_space_; |
| 50 } |
| 51 NGConstraintSpace* MutableConstraintSpace() { return constraint_space_; } |
| 52 |
| 53 const ComputedStyle& Style() const { |
| 54 DCHECK(node_); |
| 55 return node_->Style(); |
| 56 } |
| 57 |
| 58 virtual NGInputNodeType* Node() const { return node_; } |
| 59 |
| 60 NGBreakTokenType* BreakToken() const { return break_token_; } |
| 61 |
| 62 Persistent<NGInputNodeType> node_; |
| 63 NGConstraintSpace* constraint_space_; |
| 64 |
| 65 // The break token from which we are currently resuming layout. |
| 66 NGBreakTokenType* break_token_; |
40 }; | 67 }; |
41 | 68 |
42 } // namespace blink | 69 } // namespace blink |
43 | 70 |
44 #endif // NGLayoutAlgorithm_h | 71 #endif // NGLayoutAlgorithm_h |
OLD | NEW |