| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Apple, Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple, Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google, Inc. All rights reserved. | 3 * Copyright (C) 2012 Google, Inc. All rights reserved. |
| 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 26 matching lines...) Expand all Loading... |
| 37 // unbounded memory. This is the maximum number of distinct undoable | 37 // unbounded memory. This is the maximum number of distinct undoable |
| 38 // actions -- unbroken stretches of typed characters are coalesced | 38 // actions -- unbroken stretches of typed characters are coalesced |
| 39 // into a single action. | 39 // into a single action. |
| 40 static const size_t maximumUndoStackDepth = 1000; | 40 static const size_t maximumUndoStackDepth = 1000; |
| 41 | 41 |
| 42 UndoStack::UndoStack() | 42 UndoStack::UndoStack() |
| 43 : m_inRedo(false) | 43 : m_inRedo(false) |
| 44 { | 44 { |
| 45 } | 45 } |
| 46 | 46 |
| 47 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(UndoStack) | 47 RawPtr<UndoStack> UndoStack::create() |
| 48 | |
| 49 PassOwnPtrWillBeRawPtr<UndoStack> UndoStack::create() | |
| 50 { | 48 { |
| 51 return adoptPtrWillBeNoop(new UndoStack()); | 49 return new UndoStack(); |
| 52 } | 50 } |
| 53 | 51 |
| 54 void UndoStack::registerUndoStep(PassRefPtrWillBeRawPtr<UndoStep> step) | 52 void UndoStack::registerUndoStep(RawPtr<UndoStep> step) |
| 55 { | 53 { |
| 56 if (m_undoStack.size() == maximumUndoStackDepth) | 54 if (m_undoStack.size() == maximumUndoStackDepth) |
| 57 m_undoStack.removeFirst(); // drop oldest item off the far end | 55 m_undoStack.removeFirst(); // drop oldest item off the far end |
| 58 if (!m_inRedo) | 56 if (!m_inRedo) |
| 59 m_redoStack.clear(); | 57 m_redoStack.clear(); |
| 60 m_undoStack.append(step); | 58 m_undoStack.append(step); |
| 61 } | 59 } |
| 62 | 60 |
| 63 void UndoStack::registerRedoStep(PassRefPtrWillBeRawPtr<UndoStep> step) | 61 void UndoStack::registerRedoStep(RawPtr<UndoStep> step) |
| 64 { | 62 { |
| 65 m_redoStack.append(step); | 63 m_redoStack.append(step); |
| 66 } | 64 } |
| 67 | 65 |
| 68 void UndoStack::didUnloadFrame(const LocalFrame& frame) | 66 void UndoStack::didUnloadFrame(const LocalFrame& frame) |
| 69 { | 67 { |
| 70 EventDispatchForbiddenScope assertNoEventDispatch; | 68 EventDispatchForbiddenScope assertNoEventDispatch; |
| 71 filterOutUndoSteps(m_undoStack, frame); | 69 filterOutUndoSteps(m_undoStack, frame); |
| 72 filterOutUndoSteps(m_redoStack, frame); | 70 filterOutUndoSteps(m_redoStack, frame); |
| 73 } | 71 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 91 | 89 |
| 92 bool UndoStack::canRedo() const | 90 bool UndoStack::canRedo() const |
| 93 { | 91 { |
| 94 return !m_redoStack.isEmpty(); | 92 return !m_redoStack.isEmpty(); |
| 95 } | 93 } |
| 96 | 94 |
| 97 void UndoStack::undo() | 95 void UndoStack::undo() |
| 98 { | 96 { |
| 99 if (canUndo()) { | 97 if (canUndo()) { |
| 100 UndoStepStack::iterator back = --m_undoStack.end(); | 98 UndoStepStack::iterator back = --m_undoStack.end(); |
| 101 RefPtrWillBeRawPtr<UndoStep> step(back->get()); | 99 RawPtr<UndoStep> step(back->get()); |
| 102 m_undoStack.remove(back); | 100 m_undoStack.remove(back); |
| 103 step->unapply(); | 101 step->unapply(); |
| 104 // unapply will call us back to push this command onto the redo stack. | 102 // unapply will call us back to push this command onto the redo stack. |
| 105 } | 103 } |
| 106 } | 104 } |
| 107 | 105 |
| 108 void UndoStack::redo() | 106 void UndoStack::redo() |
| 109 { | 107 { |
| 110 if (canRedo()) { | 108 if (canRedo()) { |
| 111 UndoStepStack::iterator back = --m_redoStack.end(); | 109 UndoStepStack::iterator back = --m_redoStack.end(); |
| 112 RefPtrWillBeRawPtr<UndoStep> step(back->get()); | 110 RawPtr<UndoStep> step(back->get()); |
| 113 m_redoStack.remove(back); | 111 m_redoStack.remove(back); |
| 114 | 112 |
| 115 ASSERT(!m_inRedo); | 113 ASSERT(!m_inRedo); |
| 116 TemporaryChange<bool> redoScope(m_inRedo, true); | 114 TemporaryChange<bool> redoScope(m_inRedo, true); |
| 117 step->reapply(); | 115 step->reapply(); |
| 118 // reapply will call us back to push this command onto the undo stack. | 116 // reapply will call us back to push this command onto the undo stack. |
| 119 } | 117 } |
| 120 } | 118 } |
| 121 | 119 |
| 122 DEFINE_TRACE(UndoStack) | 120 DEFINE_TRACE(UndoStack) |
| 123 { | 121 { |
| 124 visitor->trace(m_undoStack); | 122 visitor->trace(m_undoStack); |
| 125 visitor->trace(m_redoStack); | 123 visitor->trace(m_redoStack); |
| 126 } | 124 } |
| 127 | 125 |
| 128 } // namespace blink | 126 } // namespace blink |
| OLD | NEW |