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

Unified Diff: third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp

Issue 1824143003: [All-In-One] Introduce BackspaceStateMachine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 9 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/editing/BackspaceStateMachine.cpp
diff --git a/third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp b/third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5c054ee21c5b48bd1536a42b4ccbba34decd2544
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp
@@ -0,0 +1,63 @@
+// Copyright 2016 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/editing/BackspaceStateMachine.h"
+
+#include <unicode/utf16.h>
yosin_UTC9 2016/03/25 10:01:05 nit: s/<unicode/utf16.h>/"third_party/icu/source/c
Seigo Nonaka 2016/03/25 10:26:32 Done and also updated DEPS.
+
+namespace blink {
+
+BackspaceStateMachine::BackspaceStateMachine()
+{
+}
+
+int BackspaceStateMachine::finalizeAndGetCodeUnitCountToBeDeleted()
+{
+ if (m_TrailSurrogate != 0) {
+ // Unpaired trail surrogate. Removing broken surrogate.
+ ++m_CodeUnitsToBeDeleted;
+ m_TrailSurrogate = 0;
+ }
+ return m_CodeUnitsToBeDeleted;
+}
+
+bool BackspaceStateMachine::updateState(uint16_t codeUnit)
+{
+ uint32_t codePoint = codeUnit;
+ if (U16_IS_LEAD(codeUnit)) {
+ if (m_TrailSurrogate == 0) {
+ // Unpaired lead surrogate. Aborting with deleting broken surrogate.
+ ++m_CodeUnitsToBeDeleted;
+ return true;
+ }
+ codePoint = U16_GET_SUPPLEMENTARY(codeUnit, m_TrailSurrogate);
+ m_TrailSurrogate = 0;
+ } else if (U16_IS_TRAIL(codeUnit)) {
+ if (m_TrailSurrogate != 0) {
+ // Unpaired trail surrogate. Aborting with deleting broken
+ // surrogate.
+ return true;
+ }
+ m_TrailSurrogate = codeUnit;
+ return false; // Needs surrogate lead.
+ } else {
+ if (m_TrailSurrogate != 0) {
+ // Unpaired trail surrogate. Aborting with deleting broken
+ // surrogate.
+ return true;
+ }
+ }
+
+ // TODO(nona): Handle emoji sequences.
+ m_CodeUnitsToBeDeleted = U16_LENGTH(codePoint);
+ return true;
+}
+
+void BackspaceStateMachine::reset()
+{
+ m_CodeUnitsToBeDeleted = 0;
+ m_TrailSurrogate = 0;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698