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

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

Issue 1833413002: [All-in-one patch] Implement own grapheme boundary breaker for editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload All-in-one patch Created 4 years, 9 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
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 1a7dc9d74831dcea9f16d3e7d42fa0ccdb41cffe..bece627f2094ea307e21deef3257d170738912d2 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,11 @@ int findNextBoundaryOffset(const String& str, int current)
int uncheckedPreviousOffset(const Node* node, int current)
{
- 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);
}
static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int current)
@@ -601,13 +598,11 @@ int uncheckedNextOffset(const Node* node, int current)
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 | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/editing/EditingUtilitiesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698