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 NGBreakToken_h | 5 #ifndef NGBreakToken_h |
6 #define NGBreakToken_h | 6 #define NGBreakToken_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 "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "wtf/RefCounted.h" |
10 | 12 |
11 namespace blink { | 13 namespace blink { |
12 | 14 |
13 class NGLayoutInputNode; | |
14 | |
15 // A break token is a continuation token for layout. A single layout input node | 15 // A break token is a continuation token for layout. A single layout input node |
16 // can have multiple fragments asssociated with it. | 16 // can have multiple fragments asssociated with it. |
17 // | 17 // |
18 // Each fragment has a break token which can be used to determine if a layout | 18 // Each fragment has a break token which can be used to determine if a layout |
19 // input node has finished producing fragments (aka. is "exhausted" of | 19 // input node has finished producing fragments (aka. is "exhausted" of |
20 // fragments), and optionally used to produce the next fragment in the chain. | 20 // fragments), and optionally used to produce the next fragment in the chain. |
21 // | 21 // |
22 // See CSS Fragmentation (https://drafts.csswg.org/css-break/) for a detailed | 22 // See CSS Fragmentation (https://drafts.csswg.org/css-break/) for a detailed |
23 // description of different types of breaks which can occur in CSS. | 23 // description of different types of breaks which can occur in CSS. |
24 // | 24 // |
25 // Each layout algorithm which can fragment, e.g. block-flow can optionally | 25 // Each layout algorithm which can fragment, e.g. block-flow can optionally |
26 // accept a break token. For example: | 26 // accept a break token. For example: |
27 // | 27 // |
28 // NGLayoutInputNode* node = ...; | 28 // NGLayoutInputNode* node = ...; |
29 // NGPhysicalFragment* fragment = node->Layout(space); | 29 // NGPhysicalFragment* fragment = node->Layout(space); |
30 // DCHECK(!fragment->BreakToken()->IsFinished()); | 30 // DCHECK(!fragment->BreakToken()->IsFinished()); |
31 // NGPhysicalFragment* fragment2 = node->Layout(space, fragment->BreakToken()); | 31 // NGPhysicalFragment* fragment2 = node->Layout(space, fragment->BreakToken()); |
32 // | 32 // |
33 // The break token should encapsulate enough information to "resume" the layout. | 33 // The break token should encapsulate enough information to "resume" the layout. |
34 class CORE_EXPORT NGBreakToken | 34 class CORE_EXPORT NGBreakToken : public RefCounted<NGBreakToken> { |
35 : public GarbageCollectedFinalized<NGBreakToken> { | |
36 public: | 35 public: |
37 virtual ~NGBreakToken() {} | 36 virtual ~NGBreakToken() {} |
38 | 37 |
39 enum NGBreakTokenType { kBlockBreakToken, kTextBreakToken }; | 38 enum NGBreakTokenType { kBlockBreakToken, kTextBreakToken }; |
40 NGBreakTokenType Type() const { return static_cast<NGBreakTokenType>(type_); } | 39 NGBreakTokenType Type() const { return static_cast<NGBreakTokenType>(type_); } |
41 | 40 |
42 enum NGBreakTokenStatus { kUnfinished, kFinished }; | 41 enum NGBreakTokenStatus { kUnfinished, kFinished }; |
43 | 42 |
44 // Whether the layout node cannot produce any more fragments. | 43 // Whether the layout node cannot produce any more fragments. |
45 bool IsFinished() const { return status_ == kFinished; } | 44 bool IsFinished() const { return status_ == kFinished; } |
46 | 45 |
47 // Returns the node associated with this break token. A break token cannot be | 46 // Returns the node associated with this break token. A break token cannot be |
48 // used with any other node. | 47 // used with any other node. |
49 NGLayoutInputNode* InputNode() const { return node_; } | 48 NGLayoutInputNode* InputNode() const { return node_; } |
50 | 49 |
51 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(node_); } | |
52 | |
53 protected: | 50 protected: |
54 NGBreakToken(NGBreakTokenType type, | 51 NGBreakToken(NGBreakTokenType type, |
55 NGBreakTokenStatus status, | 52 NGBreakTokenStatus status, |
56 NGLayoutInputNode* node) | 53 NGLayoutInputNode* node) |
57 : type_(type), status_(status), node_(node) {} | 54 : type_(type), status_(status), node_(node) {} |
58 | 55 |
59 private: | 56 private: |
60 unsigned type_ : 1; | 57 unsigned type_ : 1; |
61 unsigned status_ : 1; | 58 unsigned status_ : 1; |
62 | 59 |
63 Member<NGLayoutInputNode> node_; | 60 Persistent<NGLayoutInputNode> node_; |
64 }; | 61 }; |
65 | 62 |
66 } // namespace blink | 63 } // namespace blink |
67 | 64 |
68 #endif // NGBreakToken_h | 65 #endif // NGBreakToken_h |
OLD | NEW |