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

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

Issue 1847483002: Cleanup leadingWhitespacePosition() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-03-31T14:52:38 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/EditingUtilities.h ('k') | no next file » | 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 ee40e3732833188fb54b6cf9016de93a3ec0c71b..82f031a2fe96d73a59610133e05e505e14b4b07b 100644
--- a/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
+++ b/third_party/WebKit/Source/core/editing/EditingUtilities.cpp
@@ -730,11 +730,6 @@ Element* enclosingBlockFlowElement(const Node& node)
return nullptr;
}
-bool inSameContainingBlockFlowElement(Node* a, Node* b)
-{
- return a && b && enclosingBlockFlowElement(*a) == enclosingBlockFlowElement(*b);
-}
-
bool nodeIsUserSelectAll(const Node* node)
{
return RuntimeEnabledFeatures::userSelectAllEnabled() && node && node->layoutObject() && node->layoutObject()->style()->userSelect() == SELECT_ALL;
@@ -1377,16 +1372,22 @@ Position leadingWhitespacePosition(const Position& position, TextAffinity affini
if (isHTMLBRElement(*mostBackwardCaretPosition(position).anchorNode()))
return Position();
- Position prev = previousCharacterPosition(position, affinity);
- if (prev != position && inSameContainingBlockFlowElement(prev.anchorNode(), position.anchorNode()) && prev.anchorNode()->isTextNode()) {
- String string = toText(prev.anchorNode())->data();
- UChar previousCharacter = string[prev.computeOffsetInContainerNode()];
- bool isSpace = option == ConsiderNonCollapsibleWhitespace ? (isSpaceOrNewline(previousCharacter) || previousCharacter == noBreakSpaceCharacter) : isCollapsibleWhitespace(previousCharacter);
- if (isSpace && isEditablePosition(prev))
- return prev;
- }
-
- return Position();
+ const Position& prev = previousCharacterPosition(position, affinity);
+ if (prev == position)
+ return Position();
+ const Node* const anchorNode = prev.anchorNode();
+ if (!anchorNode || !anchorNode->isTextNode())
+ return Position();
+ if (enclosingBlockFlowElement(*anchorNode) != enclosingBlockFlowElement(*position.anchorNode()))
+ return Position();
+ if (!anchorNode->isTextNode())
+ return Position();
+ const String& string = toText(anchorNode)->data();
+ const UChar previousCharacter = string[prev.computeOffsetInContainerNode()];
+ const bool isSpace = option == ConsiderNonCollapsibleWhitespace ? (isSpaceOrNewline(previousCharacter) || previousCharacter == noBreakSpaceCharacter) : isCollapsibleWhitespace(previousCharacter);
+ if (!isSpace || !isEditablePosition(prev))
+ return Position();
+ return prev;
}
// This assumes that it starts in editable content.
« no previous file with comments | « third_party/WebKit/Source/core/editing/EditingUtilities.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698