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