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

Unified 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, 6 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc b/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d42e54cf8429eec5eddbf5f3518bde3e7466b46
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/inline/ng_offset_mapping_builder.cc
@@ -0,0 +1,50 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/layout/ng/inline/ng_offset_mapping_builder.h"
+
+#include "platform/wtf/text/StringBuilder.h"
+
+namespace blink {
+
+NGOffsetMappingBuilder::NGOffsetMappingBuilder() {
+ mapping_.push_back(0);
+}
+
+void NGOffsetMappingBuilder::AppendIdentityMapping(unsigned length) {
+ DCHECK_GT(length, 0u);
+ DCHECK(!mapping_.IsEmpty());
+ for (unsigned i = 0; i < length; ++i) {
+ unsigned next = mapping_.back() + 1;
+ mapping_.push_back(next);
+ }
+}
+
+void NGOffsetMappingBuilder::AppendCollapsedMapping(unsigned length) {
+ DCHECK_GT(length, 0u);
+ DCHECK(!mapping_.IsEmpty());
+ const unsigned back = mapping_.back();
+ for (unsigned i = 0; i < length; ++i)
+ mapping_.push_back(back);
+}
+
+void NGOffsetMappingBuilder::CollapseTrailingSpace(unsigned skip_length) {
+ DCHECK(!mapping_.IsEmpty());
+
+ // Find the |skipped_count + 1|-st last uncollapsed character. By collapsing
+ // it, all mapping values beyond this position are decremented by 1.
+ unsigned skipped_count = 0;
+ for (unsigned i = mapping_.size() - 1; skipped_count <= skip_length; --i) {
+ DCHECK_GT(i, 0u);
+ if (mapping_[i] != mapping_[i - 1])
+ ++skipped_count;
+ --mapping_[i];
+ }
+}
+
+Vector<unsigned> NGOffsetMappingBuilder::DumpOffsetMappingForTesting() const {
+ return mapping_;
+}
+
+} // namespace blink
« 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