Chromium Code Reviews| Index: Source/core/editing/Editor.cpp |
| diff --git a/Source/core/editing/Editor.cpp b/Source/core/editing/Editor.cpp |
| index e2b1faa4d1c1eab468eb37be8e8b268ae69f51ec..c40754f96ce3206ad7e3dcb1e48c8a70f26843ec 100644 |
| --- a/Source/core/editing/Editor.cpp |
| +++ b/Source/core/editing/Editor.cpp |
| @@ -710,6 +710,22 @@ void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) |
| respondToChangedContents(newSelection); |
| } |
| +static bool isValidPosition(const Position& position) |
| +{ |
| + if (!position.inDocument()) |
| + return false; |
| + |
| + if (position.anchorType() != Position::PositionIsOffsetInAnchor) |
| + return true; |
| + |
| + if (position.offsetInContainerNode() < 0) |
| + return false; |
| + |
| + const unsigned offset = static_cast<unsigned>(position.offsetInContainerNode()); |
| + const unsigned nodeLength = Range::lengthOfContentsInNode(position.anchorNode()); |
| + return offset <= nodeLength; |
| +} |
| + |
| void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd) |
| { |
| EventQueueScope scope; |
| @@ -718,6 +734,8 @@ void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd |
| dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd->endingRootEditableElement()); |
| VisibleSelection newSelection(cmd->startingSelection()); |
| + if (!isValidPosition(newSelection.base()) || !isValidPosition(newSelection.extent()) || !isValidPosition(newSelection.start()) || !isValidPosition(newSelection.end())) |
| + newSelection = VisibleSelection(newSelection.base(), newSelection.extent(), newSelection.affinity(), newSelection.isDirectional()); |
|
yosin_UTC9
2014/06/04 01:17:30
Q: Why do we create |VisibleSelection| from invali
yoichio
2014/06/04 02:01:46
It's OK to create null VisibleSelection if there a
yosin_UTC9
2014/06/04 02:20:57
I think it is better to reset rather than set unex
Yuta Kitamura
2014/06/05 08:37:55
First of all, in my view this line is very hard to
yoichio
2014/06/06 04:49:21
VisibleSelection is a DISALLOW_ALLOCATION class. I
|
| changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); |
| m_lastEditCommand = nullptr; |