Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/editing/BackspaceStateMachine.h" | 5 #include "core/editing/BackspaceStateMachine.h" |
| 6 | 6 |
| 7 #include "wtf/text/Unicode.h" | 7 #include "wtf/text/Unicode.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 int BackspaceStateMachine::finalizeAndGetCodeUnitCountToBeDeleted() | 11 BackspaceStateMachine::State BackspaceStateMachine::feedPrecedingCodeUnit(UChar codeUnit) |
| 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 { | 12 { |
| 23 uint32_t codePoint = codeUnit; | 13 uint32_t codePoint = codeUnit; |
| 24 if (U16_IS_LEAD(codeUnit)) { | 14 if (U16_IS_LEAD(codeUnit)) { |
| 25 if (m_trailSurrogate == 0) { | 15 if (m_trailSurrogate == 0) { |
| 26 // Unpaired lead surrogate. Aborting with deleting broken surrogate. | 16 // Unpaired lead surrogate. Aborting with deleting broken surrogate. |
| 27 ++m_codeUnitsToBeDeleted; | 17 ++m_codeUnitsToBeDeleted; |
| 28 return true; | 18 return State::Finished; |
| 29 } | 19 } |
| 30 codePoint = U16_GET_SUPPLEMENTARY(codeUnit, m_trailSurrogate); | 20 codePoint = U16_GET_SUPPLEMENTARY(codeUnit, m_trailSurrogate); |
| 31 m_trailSurrogate = 0; | 21 m_trailSurrogate = 0; |
| 32 } else if (U16_IS_TRAIL(codeUnit)) { | 22 } else if (U16_IS_TRAIL(codeUnit)) { |
| 33 if (m_trailSurrogate != 0) { | 23 if (m_trailSurrogate != 0) { |
| 34 // Unpaired trail surrogate. Aborting with deleting broken | 24 // Unpaired trail surrogate. Aborting with deleting broken |
| 35 // surrogate. | 25 // surrogate. |
| 36 return true; | 26 return State::Finished; |
| 37 } | 27 } |
| 38 m_trailSurrogate = codeUnit; | 28 m_trailSurrogate = codeUnit; |
| 39 return false; // Needs surrogate lead. | 29 return State::NeedMoreCodeUnit; |
| 40 } else { | 30 } else { |
| 41 if (m_trailSurrogate != 0) { | 31 if (m_trailSurrogate != 0) { |
| 42 // Unpaired trail surrogate. Aborting with deleting broken | 32 // Unpaired trail surrogate. Aborting with deleting broken |
| 43 // surrogate. | 33 // surrogate. |
| 44 return true; | 34 return State::Finished; |
| 45 } | 35 } |
| 46 } | 36 } |
| 47 | 37 |
| 48 // TODO(nona): Handle emoji sequences. | 38 // TODO(nona): Handle emoji sequences. |
| 49 m_codeUnitsToBeDeleted = U16_LENGTH(codePoint); | 39 m_codeUnitsToBeDeleted = U16_LENGTH(codePoint); |
| 50 return true; | 40 return State::Finished; |
| 41 } | |
| 42 | |
| 43 BackspaceStateMachine::State BackspaceStateMachine::notifyEndOfPrecedingText() | |
| 44 { | |
| 45 if (m_trailSurrogate != 0) { | |
| 46 // Unpaired trail surrogate. Removing broken surrogate. | |
| 47 ++m_codeUnitsToBeDeleted; | |
| 48 m_trailSurrogate = 0; | |
| 49 } | |
| 50 return State::Finished; | |
| 51 } | |
| 52 | |
| 53 BackspaceStateMachine::State BackspaceStateMachine::feedFollowingCodeUnit(UChar codeUnit) | |
| 54 { | |
| 55 NOTREACHED(); | |
| 56 return State::Unknown; | |
|
yosin_UTC9
2016/03/30 07:43:06
|Invalid| is better for here? Because state machin
Seigo Nonaka
2016/03/30 08:13:09
Done.
| |
| 57 } | |
| 58 | |
| 59 int BackspaceStateMachine::finalizeAndGetBoundaryOffset() | |
| 60 { | |
| 61 if (m_trailSurrogate != 0) { | |
| 62 // Unpaired trail surrogate. Removing broken surrogate. | |
| 63 ++m_codeUnitsToBeDeleted; | |
| 64 m_trailSurrogate = 0; | |
| 65 } | |
| 66 return -m_codeUnitsToBeDeleted; | |
| 51 } | 67 } |
| 52 | 68 |
| 53 void BackspaceStateMachine::reset() | 69 void BackspaceStateMachine::reset() |
| 54 { | 70 { |
| 55 m_codeUnitsToBeDeleted = 0; | 71 m_codeUnitsToBeDeleted = 0; |
| 56 m_trailSurrogate = 0; | 72 m_trailSurrogate = 0; |
| 57 } | 73 } |
| 58 | 74 |
| 59 } // namespace blink | 75 } // namespace blink |
| OLD | NEW |