Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 #include "wtf/AutoReset.h" | 31 #include "wtf/AutoReset.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 // Arbitrary depth limit for the undo stack, to keep it from using | 35 // Arbitrary depth limit for the undo stack, to keep it from using |
| 36 // unbounded memory. This is the maximum number of distinct undoable | 36 // unbounded memory. This is the maximum number of distinct undoable |
| 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_maxSequence(0), 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(UndoStep* 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 step->setSequence(++m_maxSequence); | |
|
yosin_UTC9
2017/01/17 08:13:29
Usage of |m_maxSequence| isn't clear. Why incremen
Xiaocheng
2017/01/17 09:04:02
This is the place where a new undo step is pushed
| |
| 53 } | |
| 52 m_undoStack.append(step); | 54 m_undoStack.append(step); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void UndoStack::registerRedoStep(UndoStep* step) { | 57 void UndoStack::registerRedoStep(UndoStep* step) { |
| 56 m_redoStack.append(step); | 58 m_redoStack.append(step); |
| 57 } | 59 } |
| 58 | 60 |
| 59 bool UndoStack::canUndo() const { | 61 bool UndoStack::canUndo() const { |
| 60 return !m_undoStack.isEmpty(); | 62 return !m_undoStack.isEmpty(); |
| 61 } | 63 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 91 m_undoStack.clear(); | 93 m_undoStack.clear(); |
| 92 m_redoStack.clear(); | 94 m_redoStack.clear(); |
| 93 } | 95 } |
| 94 | 96 |
| 95 DEFINE_TRACE(UndoStack) { | 97 DEFINE_TRACE(UndoStack) { |
| 96 visitor->trace(m_undoStack); | 98 visitor->trace(m_undoStack); |
| 97 visitor->trace(m_redoStack); | 99 visitor->trace(m_redoStack); |
| 98 } | 100 } |
| 99 | 101 |
| 100 } // namespace blink | 102 } // namespace blink |
| OLD | NEW |