| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/undo/undo_manager.h" | 5 #include "components/undo/undo_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 active_undo_group->begin() + active_undo_group->size() - 1); | 196 active_undo_group->begin() + active_undo_group->size() - 1); |
| 197 | 197 |
| 198 StartGroupingActions(); | 198 StartGroupingActions(); |
| 199 action->Undo(); | 199 action->Undo(); |
| 200 EndGroupingActions(); | 200 EndGroupingActions(); |
| 201 | 201 |
| 202 NotifyOnUndoManagerStateChange(); | 202 NotifyOnUndoManagerStateChange(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void UndoManager::NotifyOnUndoManagerStateChange() { | 205 void UndoManager::NotifyOnUndoManagerStateChange() { |
| 206 FOR_EACH_OBSERVER( | 206 for (auto& observer : observers_) |
| 207 UndoManagerObserver, observers_, OnUndoManagerStateChange()); | 207 observer.OnUndoManagerStateChange(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void UndoManager::AddUndoGroup(UndoGroup* new_undo_group) { | 210 void UndoManager::AddUndoGroup(UndoGroup* new_undo_group) { |
| 211 GetActiveUndoGroup()->push_back(new_undo_group); | 211 GetActiveUndoGroup()->push_back(new_undo_group); |
| 212 | 212 |
| 213 // User actions invalidate any available redo actions. | 213 // User actions invalidate any available redo actions. |
| 214 if (is_user_action()) | 214 if (is_user_action()) |
| 215 redo_actions_.clear(); | 215 redo_actions_.clear(); |
| 216 | 216 |
| 217 // Limit the number of undo levels so the undo stack does not grow unbounded. | 217 // Limit the number of undo levels so the undo stack does not grow unbounded. |
| 218 if (GetActiveUndoGroup()->size() > kMaxUndoGroups) | 218 if (GetActiveUndoGroup()->size() > kMaxUndoGroups) |
| 219 GetActiveUndoGroup()->erase(GetActiveUndoGroup()->begin()); | 219 GetActiveUndoGroup()->erase(GetActiveUndoGroup()->begin()); |
| 220 | 220 |
| 221 NotifyOnUndoManagerStateChange(); | 221 NotifyOnUndoManagerStateChange(); |
| 222 } | 222 } |
| 223 | 223 |
| 224 ScopedVector<UndoGroup>* UndoManager::GetActiveUndoGroup() { | 224 ScopedVector<UndoGroup>* UndoManager::GetActiveUndoGroup() { |
| 225 return performing_undo_ ? &redo_actions_ : &undo_actions_; | 225 return performing_undo_ ? &redo_actions_ : &undo_actions_; |
| 226 } | 226 } |
| OLD | NEW |