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

Side by Side Diff: Source/core/editing/Editor.cpp

Issue 315493004: reset VisibleSelection at the Undo command. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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 unified diff | Download patch
« Source/core/dom/Range.cpp ('K') | « Source/core/dom/Range.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 // Only register a new undo command if the command passed in is 703 // Only register a new undo command if the command passed in is
704 // different from the last command 704 // different from the last command
705 m_lastEditCommand = cmd; 705 m_lastEditCommand = cmd;
706 if (UndoStack* undoStack = this->undoStack()) 706 if (UndoStack* undoStack = this->undoStack())
707 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); 707 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition());
708 } 708 }
709 709
710 respondToChangedContents(newSelection); 710 respondToChangedContents(newSelection);
711 } 711 }
712 712
713 static bool isValidPosition(const Position& position)
714 {
715 if (!position.inDocument())
716 return false;
717
718 if (position.anchorType() != Position::PositionIsOffsetInAnchor)
719 return true;
720
721 if (position.offsetInContainerNode() < 0)
722 return false;
723
724 const unsigned offset = static_cast<unsigned>(position.offsetInContainerNode ());
725 const unsigned nodeLength = Range::lengthOfContentsInNode(position.anchorNod e());
726 return offset <= nodeLength;
727 }
728
713 void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd ) 729 void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd )
714 { 730 {
715 EventQueueScope scope; 731 EventQueueScope scope;
716 m_frame.document()->updateLayout(); 732 m_frame.document()->updateLayout();
717 733
718 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); 734 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement());
719 735
720 VisibleSelection newSelection(cmd->startingSelection()); 736 VisibleSelection newSelection(cmd->startingSelection());
737 if (!isValidPosition(newSelection.base()) || !isValidPosition(newSelection.e xtent()) || !isValidPosition(newSelection.start()) || !isValidPosition(newSelect ion.end()))
738 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
721 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); 739 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle);
722 740
723 m_lastEditCommand = nullptr; 741 m_lastEditCommand = nullptr;
724 if (UndoStack* undoStack = this->undoStack()) 742 if (UndoStack* undoStack = this->undoStack())
725 undoStack->registerRedoStep(cmd); 743 undoStack->registerRedoStep(cmd);
726 respondToChangedContents(newSelection); 744 respondToChangedContents(newSelection);
727 } 745 }
728 746
729 void Editor::reappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd ) 747 void Editor::reappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd )
730 { 748 {
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); 1253 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
1236 } 1254 }
1237 1255
1238 void Editor::trace(Visitor* visitor) 1256 void Editor::trace(Visitor* visitor)
1239 { 1257 {
1240 visitor->trace(m_lastEditCommand); 1258 visitor->trace(m_lastEditCommand);
1241 visitor->trace(m_mark); 1259 visitor->trace(m_mark);
1242 } 1260 }
1243 1261
1244 } // namespace WebCore 1262 } // namespace WebCore
OLDNEW
« Source/core/dom/Range.cpp ('K') | « Source/core/dom/Range.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698