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

Unified Diff: Source/core/editing/FrameSelection.cpp

Issue 359593002: Selection should be updated after node is moved to another document (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 | « Source/core/editing/FrameSelection.h ('k') | Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/FrameSelection.cpp
diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp
index 7301e5ff67b7d9e8111f4aac4ccdbd0775a7b577..449637f07faa4e0477c284d393e24ca172fff521 100644
--- a/Source/core/editing/FrameSelection.cpp
+++ b/Source/core/editing/FrameSelection.cpp
@@ -223,7 +223,7 @@ void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec
bool shouldClearTypingStyle = options & ClearTypingStyle;
EUserTriggered userTriggered = selectionOptionsToUserTriggered(options);
- VisibleSelection s = newSelection;
+ VisibleSelection s = validateSelection(newSelection);
if (shouldAlwaysUseDirectionalSelection(m_frame))
s.setIsDirectional(true);
@@ -1848,6 +1848,28 @@ void FrameSelection::didChangeVisibleSelection()
m_observingVisibleSelection = false;
}
+VisibleSelection FrameSelection::validateSelection(const VisibleSelection& selection)
+{
+ if (!m_frame || selection.isNone())
+ return selection;
+
+ Position base = selection.base();
+ Position extent = selection.extent();
+ bool isBaseValid = base.document() == m_frame->document();
+ bool isExtentValid = extent.document() == m_frame->document();
+
+ if (isBaseValid && isExtentValid)
+ return selection;
+
+ VisibleSelection newSelection;
+ if (isBaseValid) {
+ newSelection.setWithoutValidation(base, base);
+ } else if (isExtentValid) {
+ newSelection.setWithoutValidation(extent, extent);
+ }
+ return newSelection;
+}
+
void FrameSelection::startObservingVisibleSelectionChange()
{
ASSERT(!m_observingVisibleSelection);
« no previous file with comments | « Source/core/editing/FrameSelection.h ('k') | Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698