OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NGPagedLayoutAlgorithm_h |
| 6 #define NGPagedLayoutAlgorithm_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/geometry/ng_margin_strut.h" |
| 10 #include "core/layout/ng/ng_block_node.h" |
| 11 #include "core/layout/ng/ng_constraint_space_builder.h" |
| 12 #include "core/layout/ng/ng_fragment_builder.h" |
| 13 #include "core/layout/ng/ng_layout_algorithm.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 class ComputedStyle; |
| 18 class NGBlockBreakToken; |
| 19 class NGConstraintSpace; |
| 20 class NGLayoutResult; |
| 21 |
| 22 // A class for general block layout (e.g. a <div> with no special style). |
| 23 // Lays out the children in sequence. |
| 24 class CORE_EXPORT NGPagedLayoutAlgorithm : public NGLayoutAlgorithm { |
| 25 public: |
| 26 // Default constructor. |
| 27 // @param node The input node to perform layout upon. |
| 28 // @param space The constraint space which the algorithm should generate a |
| 29 // fragment within. |
| 30 // @param break_token The break token from which the layout should start. |
| 31 NGPagedLayoutAlgorithm(NGBlockNode* node, |
| 32 NGConstraintSpace* space, |
| 33 NGBlockBreakToken* break_token = nullptr); |
| 34 |
| 35 Optional<MinMaxContentSize> ComputeMinMaxContentSize() const override; |
| 36 RefPtr<NGLayoutResult> Layout() override; |
| 37 |
| 38 private: |
| 39 NGBoxStrut CalculateMargins(NGBlockNode* child, |
| 40 const NGConstraintSpace& space); |
| 41 |
| 42 // Creates a new constraint space for the current child. |
| 43 RefPtr<NGConstraintSpace> CreateConstraintSpaceForChild(NGLayoutInputNode*); |
| 44 void PrepareChildLayout(NGLayoutInputNode*); |
| 45 void FinishChildLayout(NGLayoutInputNode*, |
| 46 NGConstraintSpace*, |
| 47 RefPtr<NGLayoutResult>); |
| 48 |
| 49 // Final adjustments before fragment creation. We need to prevent the |
| 50 // fragment from crossing fragmentainer boundaries, and rather create a break |
| 51 // token if we're out of space. |
| 52 void FinalizeForFragmentation(); |
| 53 |
| 54 // Calculates logical offset for the current fragment using either |
| 55 // {@code content_size_} when the fragment doesn't know it's offset |
| 56 // or {@code known_fragment_offset} if the fragment knows it's offset |
| 57 // @return Fragment's offset relative to the fragment's parent. |
| 58 NGLogicalOffset CalculateLogicalOffset( |
| 59 const WTF::Optional<NGLogicalOffset>& known_fragment_offset); |
| 60 |
| 61 // Updates the fragment's BFC offset if it's not already set. |
| 62 void UpdateFragmentBfcOffset(const NGLogicalOffset& offset); |
| 63 |
| 64 NGLogicalOffset GetChildSpaceOffset() const { |
| 65 return NGLogicalOffset(border_and_padding_.inline_start, content_size_); |
| 66 } |
| 67 |
| 68 const NGConstraintSpace& ConstraintSpace() const { |
| 69 DCHECK(constraint_space_); |
| 70 return *constraint_space_; |
| 71 } |
| 72 |
| 73 const ComputedStyle& Style() const { return node_->Style(); } |
| 74 |
| 75 Persistent<NGBlockNode> node_; |
| 76 NGConstraintSpace* constraint_space_; |
| 77 |
| 78 // The break token from which we are currently resuming layout. |
| 79 NGBlockBreakToken* break_token_; |
| 80 |
| 81 NGFragmentBuilder builder_; |
| 82 NGConstraintSpaceBuilder space_builder_; |
| 83 |
| 84 NGBoxStrut border_and_padding_; |
| 85 LayoutUnit content_size_; |
| 86 LayoutUnit max_inline_size_; |
| 87 // MarginStrut for the previous child. |
| 88 NGMarginStrut curr_margin_strut_; |
| 89 NGLogicalOffset curr_bfc_offset_; |
| 90 NGBoxStrut curr_child_margins_; |
| 91 }; |
| 92 |
| 93 } // namespace blink |
| 94 |
| 95 #endif // NGPagedLayoutAlgorithm_h |
OLD | NEW |