Chromium Code Reviews| 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); |