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

Unified 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, 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
Index: third_party/WebKit/Source/core/layout/ng/api/ng_offset_mapping_builder.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/api/ng_offset_mapping_builder.cc b/third_party/WebKit/Source/core/layout/ng/api/ng_offset_mapping_builder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..721775a3d3d20adbb007aefcc2693e0d6a87ce96
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/api/ng_offset_mapping_builder.cc
@@ -0,0 +1,48 @@
+// 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/api/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);
yosin_UTC9 2017/06/28 01:44:21 Please add |DCHECK(!mapping_.IsEmpty())| for |mapp
Xiaocheng 2017/06/28 03:34:04 Done.
+ 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);
+ 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.
+ for (unsigned i = 0; i < length; ++i)
+ mapping_.push_back(back);
+}
+
+void NGOffsetMappingBuilder::CollapseTrailingSpace(unsigned skip_length) {
+ 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.
+
+ // 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

Powered by Google App Engine
This is Rietveld 408576698