Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| index 3fe2471ade436bcc32bb056d46e8063e953f0e89..f5bb891756e6c701e495db8a9335a6b1f8093537 100644 |
| --- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| +++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| @@ -32,6 +32,7 @@ |
| #include "core/dom/Range.h" |
| #include "core/dom/Text.h" |
| #include "core/dom/shadow/ShadowRoot.h" |
| +#include "core/editing/BackspaceStateMachine.h" |
| #include "core/editing/EditingStrategy.h" |
| #include "core/editing/Editor.h" |
| #include "core/editing/PlainTextRange.h" |
| @@ -543,6 +544,34 @@ PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat |
| return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeStrategy>(position, highestRoot); |
| } |
| +template<typename StateMachine> |
| +int findNextBoundaryOffset(const String& str, int current) |
| +{ |
| + constexpr typename StateMachine::State NeedMoreCodeUnit = StateMachine::State::NeedMoreCodeUnit; |
|
yosin_UTC9
2016/03/30 07:43:07
Sorry, |constexpr| is still banned feature. But, i
Seigo Nonaka
2016/03/30 08:13:09
Sure, to address DCHECK_EQ in following comments,
|
| + constexpr typename StateMachine::State Finished = StateMachine::State::Finished; |
| + constexpr typename StateMachine::State Unknown = StateMachine::State::Unknown; |
| + |
| + StateMachine machine; |
| + typename StateMachine::State state = Unknown; |
| + |
| + for (int i = current - 1; i >= 0; --i) { |
| + state = machine.feedPrecedingCodeUnit(str[i]); |
| + if (state != NeedMoreCodeUnit) |
| + break; |
| + } |
| + if (state == NeedMoreCodeUnit) |
| + state = machine.notifyEndOfPrecedingText(); |
| + if (state == Finished) |
| + return current + machine.finalizeAndGetBoundaryOffset(); |
| + const int length = str.length(); |
|
yosin_UTC9
2016/03/30 07:43:07
DCHECK_EQ(StateMachine::State::NeedFollowingCodeUn
Seigo Nonaka
2016/03/30 08:13:09
Done.
|
| + for (int i = current; i < length; ++i) { |
| + state = machine.feedFollowingCodeUnit(str[i]); |
| + if (state != NeedMoreCodeUnit) |
| + break; |
| + } |
| + return current + machine.finalizeAndGetBoundaryOffset(); |
| +} |
| + |
| int uncheckedPreviousOffset(const Node* node, int current) |
| { |
| if (!node->isTextNode()) |
| @@ -567,11 +596,7 @@ static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr |
| const String& text = toText(node)->data(); |
| DCHECK(static_cast<unsigned>(current - 1) < text.length()); |
|
yosin_UTC9
2016/03/30 07:43:07
Oops, DCHECK_LT(static_cast<unsigned>(current), te
Seigo Nonaka
2016/03/30 08:13:09
Done.
|
| - if (U16_IS_TRAIL(text[--current])) |
| - --current; |
| - if (current < 0) |
| - current = 0; |
| - return current; |
| + return findNextBoundaryOffset<BackspaceStateMachine>(text, current); |
| } |
| int uncheckedNextOffset(const Node* node, int current) |