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 NGColumnMapper_h |
| 6 #define NGColumnMapper_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "core/layout/ng/ng_block_break_token.h" |
| 10 #include "platform/heap/Handle.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 // Keeps track of the current column, and is used to map offsets from the |
| 15 // coordinate established by the fragmented flow [1] to visual coordinates. |
| 16 // |
| 17 // [1] https://drafts.csswg.org/css-break/#fragmented-flow |
| 18 // |
| 19 // TODO(mstensho): Add a NGFragmentainerMapper super class. There are other |
| 20 // fragmentation types than multicol (regions, pagination for printing). |
| 21 class CORE_EXPORT NGColumnMapper |
| 22 : public GarbageCollectedFinalized<NGColumnMapper> { |
| 23 public: |
| 24 NGColumnMapper(LayoutUnit inline_progression, LayoutUnit block_size) |
| 25 : inline_progression_(inline_progression), block_size_(block_size) {} |
| 26 |
| 27 // Column block length. |
| 28 LayoutUnit BlockSize() const { return block_size_; } |
| 29 |
| 30 // Offset for next break, in the fragmented flow coordinate space. |
| 31 LayoutUnit NextBreakOffset() const { |
| 32 return last_break_block_offset_ + block_size_; |
| 33 } |
| 34 |
| 35 // Convert an offset in the fragmented flow coordinate space to the visual |
| 36 // coordinate space. |
| 37 void ToVisualOffset(NGLogicalOffset& offset) { |
| 38 offset.inline_offset += inline_offset_; |
| 39 offset.block_offset -= last_break_block_offset_; |
| 40 } |
| 41 |
| 42 // Specify where in the content to start layout of the next column. |
| 43 void SetBreakToken(NGBlockBreakToken* token) { |
| 44 DCHECK(!break_token_); |
| 45 break_token_ = token; |
| 46 } |
| 47 bool HasBreakToken() const { return break_token_; } |
| 48 |
| 49 // Advance to the next column. Returns the break token to resume at. If |
| 50 // nullptr is returned, there's no more content to process. |
| 51 NGBlockBreakToken* Advance() { |
| 52 NGBlockBreakToken* token = break_token_; |
| 53 break_token_ = nullptr; |
| 54 if (token) { |
| 55 inline_offset_ += inline_progression_; |
| 56 last_break_block_offset_ += block_size_; |
| 57 } |
| 58 return token; |
| 59 } |
| 60 |
| 61 DEFINE_INLINE_TRACE() { visitor->trace(break_token_); } |
| 62 |
| 63 private: |
| 64 // Where to resume in the next column. |
| 65 Member<NGBlockBreakToken> break_token_; |
| 66 |
| 67 // The sum of used column-width and column_gap. |
| 68 LayoutUnit inline_progression_; |
| 69 |
| 70 // Inline offset to the current column. |
| 71 LayoutUnit inline_offset_; |
| 72 |
| 73 // Block size of a column. |
| 74 LayoutUnit block_size_; |
| 75 |
| 76 // Amount of content held by previous columns. |
| 77 LayoutUnit last_break_block_offset_; |
| 78 }; |
| 79 |
| 80 } // namespace blink |
| 81 |
| 82 #endif // NGColumnMapper_h |
OLD | NEW |