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