| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 DCHECK(m_fragment); | 42 DCHECK(m_fragment); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void MoveSelectionCommand::doApply(EditingState* editingState) { | 45 void MoveSelectionCommand::doApply(EditingState* editingState) { |
| 46 DCHECK(endingSelection().isNonOrphanedRange()); | 46 DCHECK(endingSelection().isNonOrphanedRange()); |
| 47 | 47 |
| 48 Position pos = m_position; | 48 Position pos = m_position; |
| 49 if (pos.isNull()) | 49 if (pos.isNull()) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 // Update the position otherwise it may become invalid after the selection is
deleted. | 52 // Update the position otherwise it may become invalid after the selection is |
| 53 // deleted. |
| 53 Position selectionEnd = endingSelection().end(); | 54 Position selectionEnd = endingSelection().end(); |
| 54 if (pos.isOffsetInAnchor() && selectionEnd.isOffsetInAnchor() && | 55 if (pos.isOffsetInAnchor() && selectionEnd.isOffsetInAnchor() && |
| 55 selectionEnd.computeContainerNode() == pos.computeContainerNode() && | 56 selectionEnd.computeContainerNode() == pos.computeContainerNode() && |
| 56 selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) { | 57 selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) { |
| 57 pos = Position( | 58 pos = Position( |
| 58 pos.computeContainerNode(), | 59 pos.computeContainerNode(), |
| 59 pos.offsetInContainerNode() - selectionEnd.offsetInContainerNode()); | 60 pos.offsetInContainerNode() - selectionEnd.offsetInContainerNode()); |
| 60 | 61 |
| 61 Position selectionStart = endingSelection().start(); | 62 Position selectionStart = endingSelection().start(); |
| 62 if (selectionStart.isOffsetInAnchor() && | 63 if (selectionStart.isOffsetInAnchor() && |
| 63 selectionStart.computeContainerNode() == pos.computeContainerNode()) | 64 selectionStart.computeContainerNode() == pos.computeContainerNode()) |
| 64 pos = Position( | 65 pos = Position( |
| 65 pos.computeContainerNode(), | 66 pos.computeContainerNode(), |
| 66 pos.offsetInContainerNode() + selectionStart.offsetInContainerNode()); | 67 pos.offsetInContainerNode() + selectionStart.offsetInContainerNode()); |
| 67 } | 68 } |
| 68 | 69 |
| 69 deleteSelection(editingState, m_smartDelete); | 70 deleteSelection(editingState, m_smartDelete); |
| 70 if (editingState->isAborted()) | 71 if (editingState->isAborted()) |
| 71 return; | 72 return; |
| 72 | 73 |
| 73 // If the node for the destination has been removed as a result of the deletio
n, | 74 // If the node for the destination has been removed as a result of the |
| 74 // set the destination to the ending point after the deletion. | 75 // deletion, set the destination to the ending point after the deletion. |
| 75 // Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in ReplaceSelectio
nCommand; | 76 // Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in |
| 76 // selection is empty, leading to null deref | 77 // ReplaceSelectionCommand; selection is empty, leading to null deref |
| 77 if (!pos.isConnected()) | 78 if (!pos.isConnected()) |
| 78 pos = endingSelection().start(); | 79 pos = endingSelection().start(); |
| 79 | 80 |
| 80 cleanupAfterDeletion(editingState, createVisiblePositionDeprecated(pos)); | 81 cleanupAfterDeletion(editingState, createVisiblePositionDeprecated(pos)); |
| 81 if (editingState->isAborted()) | 82 if (editingState->isAborted()) |
| 82 return; | 83 return; |
| 83 | 84 |
| 84 setEndingSelection(createVisibleSelectionDeprecated( | 85 setEndingSelection(createVisibleSelectionDeprecated( |
| 85 pos, endingSelection().affinity(), endingSelection().isDirectional())); | 86 pos, endingSelection().affinity(), endingSelection().isDirectional())); |
| 86 if (!pos.isConnected()) { | 87 if (!pos.isConnected()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 101 return InputEvent::InputType::None; | 102 return InputEvent::InputType::None; |
| 102 } | 103 } |
| 103 | 104 |
| 104 DEFINE_TRACE(MoveSelectionCommand) { | 105 DEFINE_TRACE(MoveSelectionCommand) { |
| 105 visitor->trace(m_fragment); | 106 visitor->trace(m_fragment); |
| 106 visitor->trace(m_position); | 107 visitor->trace(m_position); |
| 107 CompositeEditCommand::trace(visitor); | 108 CompositeEditCommand::trace(visitor); |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |