| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 NGBlockBreakToken_h | 5 #ifndef NGBlockBreakToken_h |
| 6 #define NGBlockBreakToken_h | 6 #define NGBlockBreakToken_h |
| 7 | 7 |
| 8 #include "core/CoreExport.h" | 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/ng_break_token.h" | 9 #include "core/layout/ng/ng_break_token.h" |
| 10 #include "platform/LayoutUnit.h" | 10 #include "platform/LayoutUnit.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class NGBlockNode; | 14 class NGBlockNode; |
| 15 | 15 |
| 16 // Represents a break token for a block node. | 16 // Represents a break token for a block node. |
| 17 class CORE_EXPORT NGBlockBreakToken : public NGBreakToken { | 17 class CORE_EXPORT NGBlockBreakToken : public NGBreakToken { |
| 18 public: | 18 public: |
| 19 // Creates a break token for a node which did fragment, and can potentially | 19 // Creates a break token for a node which did fragment, and can potentially |
| 20 // produce more fragments. | 20 // produce more fragments. |
| 21 // | 21 // |
| 22 // The NGBlockBreakToken takes ownership of child_break_tokens, leaving it | 22 // The NGBlockBreakToken takes ownership of child_break_tokens, leaving it |
| 23 // empty for the caller. | 23 // empty for the caller. |
| 24 NGBlockBreakToken(NGBlockNode* node, | 24 static RefPtr<NGBlockBreakToken> create( |
| 25 LayoutUnit used_block_size, | 25 NGBlockNode* node, |
| 26 HeapVector<Member<NGBreakToken>>& child_break_tokens); | 26 LayoutUnit used_block_size, |
| 27 Vector<RefPtr<NGBreakToken>>& child_break_tokens) { |
| 28 return adoptRef( |
| 29 new NGBlockBreakToken(node, used_block_size, child_break_tokens)); |
| 30 } |
| 27 | 31 |
| 28 // Creates a break token for a node which cannot produce any more fragments. | 32 // Creates a break token for a node which cannot produce any more fragments. |
| 29 explicit NGBlockBreakToken(NGLayoutInputNode* node); | 33 static RefPtr<NGBlockBreakToken> create(NGLayoutInputNode* node) { |
| 34 return adoptRef(new NGBlockBreakToken(node)); |
| 35 } |
| 30 | 36 |
| 31 // Represents the amount of block size used in previous fragments. | 37 // Represents the amount of block size used in previous fragments. |
| 32 // | 38 // |
| 33 // E.g. if the layout block specifies a block size of 200px, and the previous | 39 // E.g. if the layout block specifies a block size of 200px, and the previous |
| 34 // fragments of this block used 150px (used block size), the next fragment | 40 // fragments of this block used 150px (used block size), the next fragment |
| 35 // should have a size of 50px (assuming no additional fragmentation). | 41 // should have a size of 50px (assuming no additional fragmentation). |
| 36 LayoutUnit UsedBlockSize() const { return used_block_size_; } | 42 LayoutUnit UsedBlockSize() const { return used_block_size_; } |
| 37 | 43 |
| 38 // The break tokens for children of the layout node. | 44 // The break tokens for children of the layout node. |
| 39 // | 45 // |
| 40 // Each child we have visited previously in the block-flow layout algorithm | 46 // Each child we have visited previously in the block-flow layout algorithm |
| 41 // has an associated break token. This may be either finished (we should skip | 47 // has an associated break token. This may be either finished (we should skip |
| 42 // this child) or unfinished (we should try and produce the next fragment for | 48 // this child) or unfinished (we should try and produce the next fragment for |
| 43 // this child). | 49 // this child). |
| 44 // | 50 // |
| 45 // A child which we haven't visited yet doesn't have a break token here. | 51 // A child which we haven't visited yet doesn't have a break token here. |
| 46 const HeapVector<Member<NGBreakToken>>& ChildBreakTokens() const { | 52 const Vector<RefPtr<NGBreakToken>>& ChildBreakTokens() const { |
| 47 return child_break_tokens_; | 53 return child_break_tokens_; |
| 48 } | 54 } |
| 49 | 55 |
| 50 DEFINE_INLINE_VIRTUAL_TRACE() { | 56 private: |
| 51 NGBreakToken::trace(visitor); | 57 NGBlockBreakToken(NGBlockNode* node, |
| 52 visitor->trace(child_break_tokens_); | 58 LayoutUnit used_block_size, |
| 53 } | 59 Vector<RefPtr<NGBreakToken>>& child_break_tokens); |
| 54 | 60 |
| 55 private: | 61 explicit NGBlockBreakToken(NGLayoutInputNode* node); |
| 62 |
| 56 LayoutUnit used_block_size_; | 63 LayoutUnit used_block_size_; |
| 57 HeapVector<Member<NGBreakToken>> child_break_tokens_; | 64 Vector<RefPtr<NGBreakToken>> child_break_tokens_; |
| 58 }; | 65 }; |
| 59 | 66 |
| 60 DEFINE_TYPE_CASTS(NGBlockBreakToken, | 67 DEFINE_TYPE_CASTS(NGBlockBreakToken, |
| 61 NGBreakToken, | 68 NGBreakToken, |
| 62 token, | 69 token, |
| 63 token->Type() == NGBreakToken::kBlockBreakToken, | 70 token->Type() == NGBreakToken::kBlockBreakToken, |
| 64 token.Type() == NGBreakToken::kBlockBreakToken); | 71 token.Type() == NGBreakToken::kBlockBreakToken); |
| 65 | 72 |
| 66 } // namespace blink | 73 } // namespace blink |
| 67 | 74 |
| 68 #endif // NGBlockBreakToken_h | 75 #endif // NGBlockBreakToken_h |
| OLD | NEW |