OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "core/editing/commands/ReplaceSelectionCommand.h" | 29 #include "core/editing/commands/ReplaceSelectionCommand.h" |
30 | 30 |
31 namespace blink { | 31 namespace blink { |
32 | 32 |
33 MoveSelectionCommand::MoveSelectionCommand(PassRefPtrWillBeRawPtr<DocumentFragme
nt> fragment, const Position& position, bool smartInsert, bool smartDelete) | 33 MoveSelectionCommand::MoveSelectionCommand(PassRefPtrWillBeRawPtr<DocumentFragme
nt> fragment, const Position& position, bool smartInsert, bool smartDelete) |
34 : CompositeEditCommand(*position.document()), m_fragment(fragment), m_positi
on(position), m_smartInsert(smartInsert), m_smartDelete(smartDelete) | 34 : CompositeEditCommand(*position.document()), m_fragment(fragment), m_positi
on(position), m_smartInsert(smartInsert), m_smartDelete(smartDelete) |
35 { | 35 { |
36 ASSERT(m_fragment); | 36 ASSERT(m_fragment); |
37 } | 37 } |
38 | 38 |
39 void MoveSelectionCommand::doApply(EditingState*) | 39 void MoveSelectionCommand::doApply(EditingState* editingState) |
40 { | 40 { |
41 ASSERT(endingSelection().isNonOrphanedRange()); | 41 ASSERT(endingSelection().isNonOrphanedRange()); |
42 | 42 |
43 Position pos = m_position; | 43 Position pos = m_position; |
44 if (pos.isNull()) | 44 if (pos.isNull()) |
45 return; | 45 return; |
46 | 46 |
47 // Update the position otherwise it may become invalid after the selection i
s deleted. | 47 // Update the position otherwise it may become invalid after the selection i
s deleted. |
48 Position selectionEnd = endingSelection().end(); | 48 Position selectionEnd = endingSelection().end(); |
49 if (pos.isOffsetInAnchor() && selectionEnd.isOffsetInAnchor() | 49 if (pos.isOffsetInAnchor() && selectionEnd.isOffsetInAnchor() |
50 && selectionEnd.computeContainerNode() == pos.computeContainerNode() &&
selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) { | 50 && selectionEnd.computeContainerNode() == pos.computeContainerNode() &&
selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) { |
51 pos = Position(pos.computeContainerNode(), pos.offsetInContainerNode() -
selectionEnd.offsetInContainerNode()); | 51 pos = Position(pos.computeContainerNode(), pos.offsetInContainerNode() -
selectionEnd.offsetInContainerNode()); |
52 | 52 |
53 Position selectionStart = endingSelection().start(); | 53 Position selectionStart = endingSelection().start(); |
54 if (selectionStart.isOffsetInAnchor() && selectionStart.computeContainer
Node() == pos.computeContainerNode()) | 54 if (selectionStart.isOffsetInAnchor() && selectionStart.computeContainer
Node() == pos.computeContainerNode()) |
55 pos = Position(pos.computeContainerNode(), pos.offsetInContainerNode
() + selectionStart.offsetInContainerNode()); | 55 pos = Position(pos.computeContainerNode(), pos.offsetInContainerNode
() + selectionStart.offsetInContainerNode()); |
56 } | 56 } |
57 | 57 |
58 deleteSelection(ASSERT_NO_EDITING_ABORT, m_smartDelete); | 58 deleteSelection(editingState, m_smartDelete); |
| 59 if (editingState->isAborted()) |
| 60 return; |
59 | 61 |
60 // If the node for the destination has been removed as a result of the delet
ion, | 62 // If the node for the destination has been removed as a result of the delet
ion, |
61 // set the destination to the ending point after the deletion. | 63 // set the destination to the ending point after the deletion. |
62 // Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in ReplaceSelect
ionCommand; | 64 // Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in ReplaceSelect
ionCommand; |
63 // selection is empty, leading to null deref | 65 // selection is empty, leading to null deref |
64 if (!pos.inDocument()) | 66 if (!pos.inDocument()) |
65 pos = endingSelection().start(); | 67 pos = endingSelection().start(); |
66 | 68 |
67 cleanupAfterDeletion(createVisiblePosition(pos)); | 69 cleanupAfterDeletion(editingState, createVisiblePosition(pos)); |
| 70 if (editingState->isAborted()) |
| 71 return; |
68 | 72 |
69 setEndingSelection(VisibleSelection(pos, endingSelection().affinity(), endin
gSelection().isDirectional())); | 73 setEndingSelection(VisibleSelection(pos, endingSelection().affinity(), endin
gSelection().isDirectional())); |
70 if (!pos.inDocument()) { | 74 if (!pos.inDocument()) { |
71 // Document was modified out from under us. | 75 // Document was modified out from under us. |
72 return; | 76 return; |
73 } | 77 } |
74 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S
electReplacement | ReplaceSelectionCommand::PreventNesting; | 78 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S
electReplacement | ReplaceSelectionCommand::PreventNesting; |
75 if (m_smartInsert) | 79 if (m_smartInsert) |
76 options |= ReplaceSelectionCommand::SmartReplace; | 80 options |= ReplaceSelectionCommand::SmartReplace; |
77 applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragme
nt, options)); | 81 applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragme
nt, options), editingState); |
78 } | 82 } |
79 | 83 |
80 EditAction MoveSelectionCommand::editingAction() const | 84 EditAction MoveSelectionCommand::editingAction() const |
81 { | 85 { |
82 return EditActionDrag; | 86 return EditActionDrag; |
83 } | 87 } |
84 | 88 |
85 DEFINE_TRACE(MoveSelectionCommand) | 89 DEFINE_TRACE(MoveSelectionCommand) |
86 { | 90 { |
87 visitor->trace(m_fragment); | 91 visitor->trace(m_fragment); |
88 visitor->trace(m_position); | 92 visitor->trace(m_position); |
89 CompositeEditCommand::trace(visitor); | 93 CompositeEditCommand::trace(visitor); |
90 } | 94 } |
91 | 95 |
92 } // namespace blink | 96 } // namespace blink |
OLD | NEW |