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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 | 46 |
47 UndoStack::~UndoStack() | 47 UndoStack::~UndoStack() |
48 { | 48 { |
49 } | 49 } |
50 | 50 |
51 PassOwnPtr<UndoStack> UndoStack::create() | 51 PassOwnPtr<UndoStack> UndoStack::create() |
52 { | 52 { |
53 return adoptPtr(new UndoStack()); | 53 return adoptPtr(new UndoStack()); |
54 } | 54 } |
55 | 55 |
56 void UndoStack::registerUndoStep(PassRefPtr<UndoStep> step) | 56 void UndoStack::registerUndoStep(PassRefPtrWillBeRawPtr<UndoStep> step) |
57 { | 57 { |
58 if (m_undoStack.size() == maximumUndoStackDepth) | 58 if (m_undoStack.size() == maximumUndoStackDepth) |
59 m_undoStack.removeFirst(); // drop oldest item off the far end | 59 m_undoStack.removeFirst(); // drop oldest item off the far end |
60 if (!m_inRedo) | 60 if (!m_inRedo) |
61 m_redoStack.clear(); | 61 m_redoStack.clear(); |
62 m_undoStack.append(step); | 62 m_undoStack.append(step); |
63 } | 63 } |
64 | 64 |
65 void UndoStack::registerRedoStep(PassRefPtr<UndoStep> step) | 65 void UndoStack::registerRedoStep(PassRefPtrWillBeRawPtr<UndoStep> step) |
66 { | 66 { |
67 m_redoStack.append(step); | 67 m_redoStack.append(step); |
68 } | 68 } |
69 | 69 |
70 void UndoStack::didUnloadFrame(const LocalFrame& frame) | 70 void UndoStack::didUnloadFrame(const LocalFrame& frame) |
71 { | 71 { |
72 NoEventDispatchAssertion assertNoEventDispatch; | 72 NoEventDispatchAssertion assertNoEventDispatch; |
73 filterOutUndoSteps(m_undoStack, frame); | 73 filterOutUndoSteps(m_undoStack, frame); |
74 filterOutUndoSteps(m_redoStack, frame); | 74 filterOutUndoSteps(m_redoStack, frame); |
75 } | 75 } |
76 | 76 |
77 void UndoStack::filterOutUndoSteps(UndoStepStack& stack, const LocalFrame& frame ) | 77 void UndoStack::filterOutUndoSteps(UndoStepStack& stack, const LocalFrame& frame ) |
78 { | 78 { |
79 UndoStepStack newStack; | 79 UndoStepStack newStack; |
haraken
2014/05/26 02:36:12
This shouldn't be a persistent handle.
sof
2014/05/28 08:31:35
Tidied.
| |
80 while (!stack.isEmpty()) { | 80 while (!stack.isEmpty()) { |
81 UndoStep* step = stack.first().get(); | 81 UndoStep* step = stack.first().get(); |
82 if (!step->belongsTo(frame)) | 82 if (!step->belongsTo(frame)) |
83 newStack.append(step); | 83 newStack.append(step); |
84 stack.removeFirst(); | 84 stack.removeFirst(); |
85 } | 85 } |
86 stack.swap(newStack); | 86 stack.swap(newStack); |
87 } | 87 } |
88 | 88 |
89 bool UndoStack::canUndo() const | 89 bool UndoStack::canUndo() const |
90 { | 90 { |
91 return !m_undoStack.isEmpty(); | 91 return !m_undoStack.isEmpty(); |
92 } | 92 } |
93 | 93 |
94 bool UndoStack::canRedo() const | 94 bool UndoStack::canRedo() const |
95 { | 95 { |
96 return !m_redoStack.isEmpty(); | 96 return !m_redoStack.isEmpty(); |
97 } | 97 } |
98 | 98 |
99 void UndoStack::undo() | 99 void UndoStack::undo() |
100 { | 100 { |
101 if (canUndo()) { | 101 if (canUndo()) { |
102 UndoStepStack::iterator back = --m_undoStack.end(); | 102 UndoStepStack::iterator back = --m_undoStack.end(); |
103 RefPtr<UndoStep> step(*back); | 103 RefPtrWillBeRawPtr<UndoStep> step(back->get()); |
104 m_undoStack.remove(back); | 104 m_undoStack.remove(back); |
105 step->unapply(); | 105 step->unapply(); |
106 // unapply will call us back to push this command onto the redo stack. | 106 // unapply will call us back to push this command onto the redo stack. |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 void UndoStack::redo() | 110 void UndoStack::redo() |
111 { | 111 { |
112 if (canRedo()) { | 112 if (canRedo()) { |
113 UndoStepStack::iterator back = --m_redoStack.end(); | 113 UndoStepStack::iterator back = --m_redoStack.end(); |
114 RefPtr<UndoStep> step(*back); | 114 RefPtrWillBeRawPtr<UndoStep> step(back->get()); |
115 m_redoStack.remove(back); | 115 m_redoStack.remove(back); |
116 | 116 |
117 ASSERT(!m_inRedo); | 117 ASSERT(!m_inRedo); |
118 TemporaryChange<bool> redoScope(m_inRedo, true); | 118 TemporaryChange<bool> redoScope(m_inRedo, true); |
119 step->reapply(); | 119 step->reapply(); |
120 // reapply will call us back to push this command onto the undo stack. | 120 // reapply will call us back to push this command onto the undo stack. |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 } // namesace WebCore | 124 } // namesace WebCore |
OLD | NEW |