| 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 // actions -- unbroken stretches of typed characters are coalesced | 37 // actions -- unbroken stretches of typed characters are coalesced |
| 38 // into a single action. | 38 // into a single action. |
| 39 static const size_t maximumUndoStackDepth = 1000; | 39 static const size_t maximumUndoStackDepth = 1000; |
| 40 | 40 |
| 41 UndoStack::UndoStack() : m_inRedo(false) {} | 41 UndoStack::UndoStack() : m_inRedo(false) {} |
| 42 | 42 |
| 43 UndoStack* UndoStack::create() { | 43 UndoStack* UndoStack::create() { |
| 44 return new UndoStack(); | 44 return new UndoStack(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void UndoStack::registerUndoStep(EditCommandComposition* step) { | 47 void UndoStack::registerUndoStep(UndoStep* step) { |
| 48 if (m_undoStack.size() == maximumUndoStackDepth) | 48 if (m_undoStack.size() == maximumUndoStackDepth) |
| 49 m_undoStack.removeFirst(); // drop oldest item off the far end | 49 m_undoStack.removeFirst(); // drop oldest item off the far end |
| 50 if (!m_inRedo) | 50 if (!m_inRedo) |
| 51 m_redoStack.clear(); | 51 m_redoStack.clear(); |
| 52 m_undoStack.append(step); | 52 m_undoStack.append(step); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void UndoStack::registerRedoStep(EditCommandComposition* step) { | 55 void UndoStack::registerRedoStep(UndoStep* step) { |
| 56 m_redoStack.append(step); | 56 m_redoStack.append(step); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool UndoStack::canUndo() const { | 59 bool UndoStack::canUndo() const { |
| 60 return !m_undoStack.isEmpty(); | 60 return !m_undoStack.isEmpty(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool UndoStack::canRedo() const { | 63 bool UndoStack::canRedo() const { |
| 64 return !m_redoStack.isEmpty(); | 64 return !m_redoStack.isEmpty(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void UndoStack::undo() { | 67 void UndoStack::undo() { |
| 68 if (canUndo()) { | 68 if (canUndo()) { |
| 69 UndoStepStack::iterator back = --m_undoStack.end(); | 69 UndoStepStack::iterator back = --m_undoStack.end(); |
| 70 EditCommandComposition* step(back->get()); | 70 UndoStep* step(back->get()); |
| 71 m_undoStack.remove(back); | 71 m_undoStack.remove(back); |
| 72 step->unapply(); | 72 step->unapply(); |
| 73 // unapply will call us back to push this command onto the redo stack. | 73 // unapply will call us back to push this command onto the redo stack. |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void UndoStack::redo() { | 77 void UndoStack::redo() { |
| 78 if (canRedo()) { | 78 if (canRedo()) { |
| 79 UndoStepStack::iterator back = --m_redoStack.end(); | 79 UndoStepStack::iterator back = --m_redoStack.end(); |
| 80 EditCommandComposition* step(back->get()); | 80 UndoStep* step(back->get()); |
| 81 m_redoStack.remove(back); | 81 m_redoStack.remove(back); |
| 82 | 82 |
| 83 DCHECK(!m_inRedo); | 83 DCHECK(!m_inRedo); |
| 84 AutoReset<bool> redoScope(&m_inRedo, true); | 84 AutoReset<bool> redoScope(&m_inRedo, true); |
| 85 step->reapply(); | 85 step->reapply(); |
| 86 // reapply will call us back to push this command onto the undo stack. | 86 // reapply will call us back to push this command onto the undo stack. |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 void UndoStack::clear() { | 90 void UndoStack::clear() { |
| 91 m_undoStack.clear(); | 91 m_undoStack.clear(); |
| 92 m_redoStack.clear(); | 92 m_redoStack.clear(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 DEFINE_TRACE(UndoStack) { | 95 DEFINE_TRACE(UndoStack) { |
| 96 visitor->trace(m_undoStack); | 96 visitor->trace(m_undoStack); |
| 97 visitor->trace(m_redoStack); | 97 visitor->trace(m_redoStack); |
| 98 } | 98 } |
| 99 | 99 |
| 100 } // namespace blink | 100 } // namespace blink |
| OLD | NEW |