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

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

Issue 1853033002: Use our own grapheme boundary handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: left TODO 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EditingUtilitiesTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8afb247a50a241ca61970b1d7a698469f2104480..81ad11469833544121e8536a7b734fdbcbd8ca94 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,15 @@ int findNextBoundaryOffset(const String& str, int current)
int previousGraphemeBoundaryOf(const Node* node, int current)
{
- if (!node->isTextNode())
+ // TODO(yosin): Need to support grapheme crossing |Node| boundary.
+ 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)
+ // TODO(yosin): Replace with DCHECK for out-of-range request.
+ if (static_cast<unsigned>(current) > text.length())
return current - 1;
- const int result = iterator->preceding(current);
- return result == TextBreakDone ? current - 1 : result;
+ return findNextBoundaryOffset<BackwardGraphemeBoundaryStateMachine>(text, current);
}
static int previousBackwardDeletionOffsetOf(const Node* node, int current)
@@ -598,16 +599,15 @@ static int previousBackwardDeletionOffsetOf(const Node* node, int current)
int nextGraphemeBoundaryOf(const Node* node, int current)
{
+ // TODO(yosin): Need to support grapheme crossing |Node| boundary.
if (!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)
+ const int length = text.length();
+ DCHECK_LE(current, length);
+ if (current >= length - 1)
return current + 1;
- const int result = iterator->following(current);
- return result == TextBreakDone ? current + 1 : result;
+ return findNextBoundaryOffset<ForwardGraphemeBoundaryStateMachine>(text, current);
}
template <typename Strategy>
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EditingUtilitiesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698