Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc

Issue 2943573002: Make NGInlineItemsBuilder construct whitespace-collapsed offset mapping (Closed)
Patch Set: Wed Jun 28 11:44:29 PDT 2017 Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698