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

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

Issue 2802953002: Avoid duplicate functions/code in core/editing: computeDistance (Closed)
Patch Set: Created 3 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
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 13539b5bda7fc20fc738591c0044097ff6190ac3..15fcc2f0e3aaf15065c6170b1e2e00f8ad424af3 100644
--- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
+++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
@@ -2059,6 +2059,32 @@ bool isTextSecurityNode(const Node* node) {
node->layoutObject()->style()->textSecurity() != TSNONE;
}
+// If current position is at grapheme boundary, return 0; otherwise, return the
+// distance to its nearest left grapheme boundary.
+size_t computeDistanceToLeftGraphemeBoundary(const Position& position) {
+ const Position& adjustedPosition = previousPositionOf(
+ nextPositionOf(position, PositionMoveType::GraphemeCluster),
+ PositionMoveType::GraphemeCluster);
+ DCHECK_EQ(position.anchorNode(), adjustedPosition.anchorNode());
+ DCHECK_GE(position.computeOffsetInContainerNode(),
+ adjustedPosition.computeOffsetInContainerNode());
+ return static_cast<size_t>(position.computeOffsetInContainerNode() -
+ adjustedPosition.computeOffsetInContainerNode());
+}
+
+// If current position is at grapheme boundary, return 0; otherwise, return the
+// distance to its nearest right grapheme boundary.
+size_t computeDistanceToRightGraphemeBoundary(const Position& position) {
+ const Position& adjustedPosition = nextPositionOf(
+ previousPositionOf(position, PositionMoveType::GraphemeCluster),
+ PositionMoveType::GraphemeCluster);
+ DCHECK_EQ(position.anchorNode(), adjustedPosition.anchorNode());
+ DCHECK_GE(adjustedPosition.computeOffsetInContainerNode(),
+ position.computeOffsetInContainerNode());
+ return static_cast<size_t>(adjustedPosition.computeOffsetInContainerNode() -
+ position.computeOffsetInContainerNode());
+}
+
const StaticRangeVector* targetRangesForInputEvent(const Node& node) {
// TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. see http://crbug.com/590369 for more details.

Powered by Google App Engine
This is Rietveld 408576698