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

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

Issue 2943573002: Make NGInlineItemsBuilder construct whitespace-collapsed offset mapping (Closed)
Patch Set: Tue Jun 27 15:22:36 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
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/api/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);
yosin_UTC9 2017/06/28 01:44:21 Please add |DCHECK(!mapping_.IsEmpty())| for |mapp
Xiaocheng 2017/06/28 03:34:04 Done.
17 for (unsigned i = 0; i < length; ++i) {
18 unsigned next = mapping_.back() + 1;
19 mapping_.push_back(next);
20 }
21 }
22
23 void NGOffsetMappingBuilder::AppendCollapsedMapping(unsigned length) {
24 DCHECK_GT(length, 0u);
25 unsigned back = mapping_.back();
yosin_UTC9 2017/06/28 01:44:21 nit: s/unsigned/const unsigned/ Please add |DCHECK
Xiaocheng 2017/06/28 03:34:05 Done.
26 for (unsigned i = 0; i < length; ++i)
27 mapping_.push_back(back);
28 }
29
30 void NGOffsetMappingBuilder::CollapseTrailingSpace(unsigned skip_length) {
31 DCHECK(mapping_.size());
yosin_UTC9 2017/06/28 01:44:21 nit: s/mapping_.size()/!mapping.IsEmpty()/
Xiaocheng 2017/06/28 03:34:05 Done.
32
33 // Find the |skipped_count + 1|-st last uncollapsed character. By collapsing
34 // it, all mapping values beyond this position are decremented by 1.
35 unsigned skipped_count = 0;
36 for (unsigned i = mapping_.size() - 1; skipped_count <= skip_length; --i) {
37 DCHECK_GT(i, 0u);
38 if (mapping_[i] != mapping_[i - 1])
39 ++skipped_count;
40 --mapping_[i];
41 }
42 }
43
44 Vector<unsigned> NGOffsetMappingBuilder::DumpOffsetMappingForTesting() const {
45 return mapping_;
46 }
47
48 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698