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 #include "core/layout/ng/inline/ng_offset_mapping_builder.h" |
| 6 |
| 7 #include "platform/wtf/text/StringBuilder.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 NGOffsetMappingBuilder::NGOffsetMappingBuilder() { |
| 12 mapping_.push_back(0); |
| 13 } |
| 14 |
| 15 void NGOffsetMappingBuilder::AppendIdentityMapping(unsigned length) { |
| 16 DCHECK_GT(length, 0u); |
| 17 DCHECK(!mapping_.IsEmpty()); |
| 18 for (unsigned i = 0; i < length; ++i) { |
| 19 unsigned next = mapping_.back() + 1; |
| 20 mapping_.push_back(next); |
| 21 } |
| 22 } |
| 23 |
| 24 void NGOffsetMappingBuilder::AppendCollapsedMapping(unsigned length) { |
| 25 DCHECK_GT(length, 0u); |
| 26 DCHECK(!mapping_.IsEmpty()); |
| 27 const unsigned back = mapping_.back(); |
| 28 for (unsigned i = 0; i < length; ++i) |
| 29 mapping_.push_back(back); |
| 30 } |
| 31 |
| 32 void NGOffsetMappingBuilder::CollapseTrailingSpace(unsigned skip_length) { |
| 33 DCHECK(!mapping_.IsEmpty()); |
| 34 |
| 35 // Find the |skipped_count + 1|-st last uncollapsed character. By collapsing |
| 36 // it, all mapping values beyond this position are decremented by 1. |
| 37 unsigned skipped_count = 0; |
| 38 for (unsigned i = mapping_.size() - 1; skipped_count <= skip_length; --i) { |
| 39 DCHECK_GT(i, 0u); |
| 40 if (mapping_[i] != mapping_[i - 1]) |
| 41 ++skipped_count; |
| 42 --mapping_[i]; |
| 43 } |
| 44 } |
| 45 |
| 46 Vector<unsigned> NGOffsetMappingBuilder::DumpOffsetMappingForTesting() const { |
| 47 return mapping_; |
| 48 } |
| 49 |
| 50 } // namespace blink |
OLD | NEW |