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 3fb0b5148012e7efc9751f8f5dda2c60fee0db47..bb3f0d1738dfdaa546bd416742a9a36b561bae28 100644 |
| --- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| +++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp |
| @@ -42,6 +42,8 @@ |
| #include "core/editing/iterators/TextIterator.h" |
| #include "core/editing/serializers/HTMLInterchange.h" |
| #include "core/editing/state_machines/BackspaceStateMachine.h" |
| +#include "core/editing/state_machines/BackwardGraphemeBoundaryStateMachine.h" |
| +#include "core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/UseCounter.h" |
| #include "core/html/HTMLBRElement.h" |
| @@ -555,7 +557,7 @@ int findNextBoundaryOffset(const String& str, int current) |
| if (state != TextSegmentationMachineState::NeedMoreCodeUnit) |
| break; |
| } |
| - if (state == TextSegmentationMachineState::NeedMoreCodeUnit) |
| + if (current == 0 || state == TextSegmentationMachineState::NeedMoreCodeUnit) |
| state = machine.tellEndOfPrecedingText(); |
| if (state == TextSegmentationMachineState::Finished) |
| return current + machine.finalizeAndGetBoundaryOffset(); |
| @@ -571,16 +573,12 @@ int findNextBoundaryOffset(const String& str, int current) |
| int previousGraphemeBoundaryOf(const Node* node, int current) |
|
yosin_UTC9
2016/04/07 01:06:53
Could you add TODO comment that we need to support
Seigo Nonaka
2016/04/07 03:44:59
Done.
|
| { |
| - if (!node->isTextNode()) |
| + DCHECK_GE(current, 0); |
| + if (current <= 1 || !node->isTextNode()) |
| return current - 1; |
| const String& text = toText(node)->data(); |
| - if (text.is8Bit()) |
| - return current - 1; // TODO(nona): Good to support CR x LF. |
| - TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), text.length()); |
| - if (!iterator) |
| - return current - 1; |
| - const int result = iterator->preceding(current); |
| - return result == TextBreakDone ? current - 1 : result; |
| + return findNextBoundaryOffset<BackwardGraphemeBoundaryStateMachine>( |
| + text, current); |
|
yosin_UTC9
2016/04/07 01:06:53
nit: Could you make this call in one line to follo
Seigo Nonaka
2016/04/07 03:44:59
Done.
|
| } |
| static int previousBackwardDeletionOffsetOf(const Node* node, int current) |
| @@ -601,13 +599,12 @@ int nextGraphemeBoundaryOf(const Node* node, int current) |
| if (!node->isTextNode()) |
|
yosin_UTC9
2016/04/07 01:06:53
Could you add TODO comment that we need to support
Seigo Nonaka
2016/04/07 03:44:59
Done.
|
| return current + 1; |
| const String& text = toText(node)->data(); |
| - if (text.is8Bit()) |
| - return current + 1; // TODO(nona): Good to support CR x LF. |
| - TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), text.length()); |
| - if (!iterator) |
| + const int length = text.length(); |
| + DCHECK_LE(current, length); |
| + if (current >= (length - 1)) |
|
yosin_UTC9
2016/04/07 01:06:53
nit: We don't need to have parenthesis for |(lengt
Seigo Nonaka
2016/04/07 03:44:59
Done.
|
| return current + 1; |
| - const int result = iterator->following(current); |
| - return result == TextBreakDone ? current + 1 : result; |
| + return findNextBoundaryOffset<ForwardGraphemeBoundaryStateMachine>( |
| + text, current); |
|
yosin_UTC9
2016/04/07 01:06:53
nit: Could you make this call in one line to follo
Seigo Nonaka
2016/04/07 03:44:59
Done.
|
| } |
| template <typename Strategy> |