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

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

Issue 2850443002: Stop flat tree selection canonicalization from using invalid positions (Closed)
Patch Set: Add expectation check 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/Position.cpp
diff --git a/third_party/WebKit/Source/core/editing/Position.cpp b/third_party/WebKit/Source/core/editing/Position.cpp
index 33084f36ff37e5f1439f03bae91d771d6fee6d33..771328e27d55caed0c567d7e0dd7aec8c337b84d 100644
--- a/third_party/WebKit/Source/core/editing/Position.cpp
+++ b/third_party/WebKit/Source/core/editing/Position.cpp
@@ -544,6 +544,18 @@ PositionInFlatTree ToPositionInFlatTree(const Position& pos) {
if (anchor->IsShadowRoot())
return PositionInFlatTree(anchor->OwnerShadowHost(), pos.AnchorType());
+ if (pos.IsBeforeAnchor() || pos.IsAfterAnchor()) {
+ if (anchor->CanParticipateInFlatTree() &&
+ !FlatTreeTraversal::Parent(*anchor)) {
+ // For Before/AfterAnchor, if |anchor| doesn't have parent in the flat
+ // tree, there is no valid corresponding PositionInFlatTree.
+ // Since this function is a primitive function, we do not adjust |pos|
+ // to somewhere else in flat tree.
+ // Reached by unit test
+ // FrameSelectionTest.SelectInvalidPositionInFlatTreeDoesntCrash.
+ return PositionInFlatTree();
+ }
+ }
// TODO(yosin): Once we have a test case for SLOT or active insertion point,
// this function should handle it.
return PositionInFlatTree(anchor, pos.AnchorType());

Powered by Google App Engine
This is Rietveld 408576698