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

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: Fixed FrameSelectionTest.cpp 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
Index: Source/core/editing/FrameSelection.cpp
diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp
index 090959156e4ed8647cd256049c840e4fdbdfa09c..bf2225d66de5c321daa6d7a96662e9fe09721a7a 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);
@@ -1838,6 +1838,31 @@ 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);
+ return newSelection;
+ }
+ if (isExtentValid) {
+ newSelection.setWithoutValidation(extent, extent);
+ return newSelection;
+ }
+ return newSelection;
Yuta Kitamura 2014/07/14 10:04:43 I think you can shrink lines 1855-1863 to somethin
tasak 2014/07/25 09:23:34 Done.
+}
+
void FrameSelection::startObservingVisibleSelectionChange()
{
ASSERT(!m_observingVisibleSelection);

Powered by Google App Engine
This is Rietveld 408576698