| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/editing/commands/UndoStep.h" | 5 #include "core/editing/commands/UndoStep.h" |
| 6 | 6 |
| 7 #include "core/editing/Editor.h" | 7 #include "core/editing/Editor.h" |
| 8 #include "core/editing/commands/EditCommand.h" | 8 #include "core/editing/commands/EditCommand.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 EditCommandComposition* EditCommandComposition::create( | 12 UndoStep* UndoStep::create(Document* document, |
| 13 Document* document, | 13 const VisibleSelection& startingSelection, |
| 14 const VisibleSelection& startingSelection, | 14 const VisibleSelection& endingSelection, |
| 15 const VisibleSelection& endingSelection, | 15 InputEvent::InputType inputType) { |
| 16 InputEvent::InputType inputType) { | 16 return new UndoStep(document, startingSelection, endingSelection, inputType); |
| 17 return new EditCommandComposition(document, startingSelection, | |
| 18 endingSelection, inputType); | |
| 19 } | 17 } |
| 20 | 18 |
| 21 EditCommandComposition::EditCommandComposition( | 19 UndoStep::UndoStep(Document* document, |
| 22 Document* document, | 20 const VisibleSelection& startingSelection, |
| 23 const VisibleSelection& startingSelection, | 21 const VisibleSelection& endingSelection, |
| 24 const VisibleSelection& endingSelection, | 22 InputEvent::InputType inputType) |
| 25 InputEvent::InputType inputType) | |
| 26 : m_document(document), | 23 : m_document(document), |
| 27 m_startingSelection(startingSelection), | 24 m_startingSelection(startingSelection), |
| 28 m_endingSelection(endingSelection), | 25 m_endingSelection(endingSelection), |
| 29 m_startingRootEditableElement(startingSelection.rootEditableElement()), | 26 m_startingRootEditableElement(startingSelection.rootEditableElement()), |
| 30 m_endingRootEditableElement(endingSelection.rootEditableElement()), | 27 m_endingRootEditableElement(endingSelection.rootEditableElement()), |
| 31 m_inputType(inputType) {} | 28 m_inputType(inputType) {} |
| 32 | 29 |
| 33 void EditCommandComposition::unapply() { | 30 void UndoStep::unapply() { |
| 34 DCHECK(m_document); | 31 DCHECK(m_document); |
| 35 LocalFrame* frame = m_document->frame(); | 32 LocalFrame* frame = m_document->frame(); |
| 36 DCHECK(frame); | 33 DCHECK(frame); |
| 37 | 34 |
| 38 // Changes to the document may have been made since the last editing operation | 35 // Changes to the document may have been made since the last editing operation |
| 39 // that require a layout, as in <rdar://problem/5658603>. Low level | 36 // that require a layout, as in <rdar://problem/5658603>. Low level |
| 40 // operations, like RemoveNodeCommand, don't require a layout because the high | 37 // operations, like RemoveNodeCommand, don't require a layout because the high |
| 41 // level operations that use them perform one if one is necessary (like for | 38 // level operations that use them perform one if one is necessary (like for |
| 42 // the creation of VisiblePositions). | 39 // the creation of VisiblePositions). |
| 43 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 40 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 44 | 41 |
| 45 { | 42 { |
| 46 size_t size = m_commands.size(); | 43 size_t size = m_commands.size(); |
| 47 for (size_t i = size; i; --i) | 44 for (size_t i = size; i; --i) |
| 48 m_commands[i - 1]->doUnapply(); | 45 m_commands[i - 1]->doUnapply(); |
| 49 } | 46 } |
| 50 | 47 |
| 51 frame->editor().unappliedEditing(this); | 48 frame->editor().unappliedEditing(this); |
| 52 } | 49 } |
| 53 | 50 |
| 54 void EditCommandComposition::reapply() { | 51 void UndoStep::reapply() { |
| 55 DCHECK(m_document); | 52 DCHECK(m_document); |
| 56 LocalFrame* frame = m_document->frame(); | 53 LocalFrame* frame = m_document->frame(); |
| 57 DCHECK(frame); | 54 DCHECK(frame); |
| 58 | 55 |
| 59 // Changes to the document may have been made since the last editing operation | 56 // Changes to the document may have been made since the last editing operation |
| 60 // that require a layout, as in <rdar://problem/5658603>. Low level | 57 // that require a layout, as in <rdar://problem/5658603>. Low level |
| 61 // operations, like RemoveNodeCommand, don't require a layout because the high | 58 // operations, like RemoveNodeCommand, don't require a layout because the high |
| 62 // level operations that use them perform one if one is necessary (like for | 59 // level operations that use them perform one if one is necessary (like for |
| 63 // the creation of VisiblePositions). | 60 // the creation of VisiblePositions). |
| 64 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 61 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 65 | 62 |
| 66 { | 63 { |
| 67 for (const auto& command : m_commands) | 64 for (const auto& command : m_commands) |
| 68 command->doReapply(); | 65 command->doReapply(); |
| 69 } | 66 } |
| 70 | 67 |
| 71 frame->editor().reappliedEditing(this); | 68 frame->editor().reappliedEditing(this); |
| 72 } | 69 } |
| 73 | 70 |
| 74 InputEvent::InputType EditCommandComposition::inputType() const { | 71 InputEvent::InputType UndoStep::inputType() const { |
| 75 return m_inputType; | 72 return m_inputType; |
| 76 } | 73 } |
| 77 | 74 |
| 78 void EditCommandComposition::append(SimpleEditCommand* command) { | 75 void UndoStep::append(SimpleEditCommand* command) { |
| 79 m_commands.push_back(command); | 76 m_commands.push_back(command); |
| 80 } | 77 } |
| 81 | 78 |
| 82 void EditCommandComposition::append(EditCommandComposition* composition) { | 79 void UndoStep::append(UndoStep* composition) { |
| 83 m_commands.appendVector(composition->m_commands); | 80 m_commands.appendVector(composition->m_commands); |
| 84 } | 81 } |
| 85 | 82 |
| 86 void EditCommandComposition::setStartingSelection( | 83 void UndoStep::setStartingSelection(const VisibleSelection& selection) { |
| 87 const VisibleSelection& selection) { | |
| 88 m_startingSelection = selection; | 84 m_startingSelection = selection; |
| 89 m_startingRootEditableElement = selection.rootEditableElement(); | 85 m_startingRootEditableElement = selection.rootEditableElement(); |
| 90 } | 86 } |
| 91 | 87 |
| 92 void EditCommandComposition::setEndingSelection( | 88 void UndoStep::setEndingSelection(const VisibleSelection& selection) { |
| 93 const VisibleSelection& selection) { | |
| 94 m_endingSelection = selection; | 89 m_endingSelection = selection; |
| 95 m_endingRootEditableElement = selection.rootEditableElement(); | 90 m_endingRootEditableElement = selection.rootEditableElement(); |
| 96 } | 91 } |
| 97 | 92 |
| 98 DEFINE_TRACE(EditCommandComposition) { | 93 DEFINE_TRACE(UndoStep) { |
| 99 visitor->trace(m_document); | 94 visitor->trace(m_document); |
| 100 visitor->trace(m_startingSelection); | 95 visitor->trace(m_startingSelection); |
| 101 visitor->trace(m_endingSelection); | 96 visitor->trace(m_endingSelection); |
| 102 visitor->trace(m_commands); | 97 visitor->trace(m_commands); |
| 103 visitor->trace(m_startingRootEditableElement); | 98 visitor->trace(m_startingRootEditableElement); |
| 104 visitor->trace(m_endingRootEditableElement); | 99 visitor->trace(m_endingRootEditableElement); |
| 105 } | 100 } |
| 106 | 101 |
| 107 } // namespace blink | 102 } // namespace blink |
| OLD | NEW |