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

Side by Side Diff: third_party/WebKit/Source/core/editing/BackspaceStateMachine.cpp

Issue 1832343002: Introduce BackspaceStateMachine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary includes. Created 4 years, 8 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 2016 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/editing/BackspaceStateMachine.h"
6
7 #include "wtf/text/Unicode.h"
8
9 namespace blink {
10
11 int BackspaceStateMachine::finalizeAndGetCodeUnitCountToBeDeleted()
12 {
13 if (m_trailSurrogate != 0) {
14 // Unpaired trail surrogate. Removing broken surrogate.
15 ++m_codeUnitsToBeDeleted;
16 m_trailSurrogate = 0;
17 }
18 return m_codeUnitsToBeDeleted;
19 }
20
21 bool BackspaceStateMachine::updateState(UChar codeUnit)
22 {
23 uint32_t codePoint = codeUnit;
24 if (U16_IS_LEAD(codeUnit)) {
25 if (m_trailSurrogate == 0) {
26 // Unpaired lead surrogate. Aborting with deleting broken surrogate.
27 ++m_codeUnitsToBeDeleted;
28 return true;
29 }
30 codePoint = U16_GET_SUPPLEMENTARY(codeUnit, m_trailSurrogate);
31 m_trailSurrogate = 0;
32 } else if (U16_IS_TRAIL(codeUnit)) {
33 if (m_trailSurrogate != 0) {
34 // Unpaired trail surrogate. Aborting with deleting broken
35 // surrogate.
36 return true;
37 }
38 m_trailSurrogate = codeUnit;
39 return false; // Needs surrogate lead.
40 } else {
41 if (m_trailSurrogate != 0) {
42 // Unpaired trail surrogate. Aborting with deleting broken
43 // surrogate.
44 return true;
45 }
46 }
47
48 // TODO(nona): Handle emoji sequences.
49 m_codeUnitsToBeDeleted = U16_LENGTH(codePoint);
50 return true;
51 }
52
53 void BackspaceStateMachine::reset()
54 {
55 m_codeUnitsToBeDeleted = 0;
56 m_trailSurrogate = 0;
57 }
58
59 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698