| 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 #ifndef COMPONENTS_UNDO_UNDO_MANAGER_H_ | 5 #ifndef COMPONENTS_UNDO_UNDO_MANAGER_H_ |
| 6 #define COMPONENTS_UNDO_UNDO_MANAGER_H_ | 6 #define COMPONENTS_UNDO_UNDO_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 | 16 |
| 17 class UndoManagerObserver; | 17 class UndoManagerObserver; |
| 18 class UndoOperation; | 18 class UndoOperation; |
| 19 | 19 |
| 20 // UndoGroup ------------------------------------------------------------------ | 20 // UndoGroup ------------------------------------------------------------------ |
| 21 | 21 |
| 22 // UndoGroup represents a user action and stores all the operations that | 22 // UndoGroup represents a user action and stores all the operations that |
| 23 // make that action. Typically there is only one operation per UndoGroup. | 23 // make that action. Typically there is only one operation per UndoGroup. |
| 24 class UndoGroup { | 24 class UndoGroup { |
| 25 public: | 25 public: |
| 26 UndoGroup(); | 26 UndoGroup(); |
| 27 ~UndoGroup(); | 27 ~UndoGroup(); |
| 28 | 28 |
| 29 void AddOperation(std::unique_ptr<UndoOperation> operation); | 29 void AddOperation(std::unique_ptr<UndoOperation> operation); |
| 30 const std::vector<UndoOperation*>& undo_operations() { | 30 const std::vector<std::unique_ptr<UndoOperation>>& undo_operations() { |
| 31 return operations_.get(); | 31 return operations_; |
| 32 } | 32 } |
| 33 void Undo(); | 33 void Undo(); |
| 34 | 34 |
| 35 // The resource string id describing the undo and redo action. | 35 // The resource string id describing the undo and redo action. |
| 36 int get_undo_label_id() const { return undo_label_id_; } | 36 int get_undo_label_id() const { return undo_label_id_; } |
| 37 void set_undo_label_id(int label_id) { undo_label_id_ = label_id; } | 37 void set_undo_label_id(int label_id) { undo_label_id_ = label_id; } |
| 38 | 38 |
| 39 int get_redo_label_id() const { return redo_label_id_; } | 39 int get_redo_label_id() const { return redo_label_id_; } |
| 40 void set_redo_label_id(int label_id) { redo_label_id_ = label_id; } | 40 void set_redo_label_id(int label_id) { redo_label_id_ = label_id; } |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 ScopedVector<UndoOperation> operations_; | 43 std::vector<std::unique_ptr<UndoOperation>> operations_; |
| 44 | 44 |
| 45 // The resource string id describing the undo and redo action. | 45 // The resource string id describing the undo and redo action. |
| 46 int undo_label_id_; | 46 int undo_label_id_; |
| 47 int redo_label_id_; | 47 int redo_label_id_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(UndoGroup); | 49 DISALLOW_COPY_AND_ASSIGN(UndoGroup); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // UndoManager ---------------------------------------------------------------- | 52 // UndoManager ---------------------------------------------------------------- |
| 53 | 53 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Remove all undo and redo operations. Note that grouping of actions and | 87 // Remove all undo and redo operations. Note that grouping of actions and |
| 88 // suspension of undo tracking states are left unchanged. | 88 // suspension of undo tracking states are left unchanged. |
| 89 void RemoveAllOperations(); | 89 void RemoveAllOperations(); |
| 90 | 90 |
| 91 // Observers are notified when the internal state of this class changes. | 91 // Observers are notified when the internal state of this class changes. |
| 92 void AddObserver(UndoManagerObserver* observer); | 92 void AddObserver(UndoManagerObserver* observer); |
| 93 void RemoveObserver(UndoManagerObserver* observer); | 93 void RemoveObserver(UndoManagerObserver* observer); |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 void Undo(bool* performing_indicator, | 96 void Undo(bool* performing_indicator, |
| 97 ScopedVector<UndoGroup>* active_undo_group); | 97 std::vector<std::unique_ptr<UndoGroup>>* active_undo_group); |
| 98 bool is_user_action() const { return !performing_undo_ && !performing_redo_; } | 98 bool is_user_action() const { return !performing_undo_ && !performing_redo_; } |
| 99 | 99 |
| 100 // Notifies the observers that the undo manager's state has changed. | 100 // Notifies the observers that the undo manager's state has changed. |
| 101 void NotifyOnUndoManagerStateChange(); | 101 void NotifyOnUndoManagerStateChange(); |
| 102 | 102 |
| 103 // Handle the addition of |new_undo_group| to the active undo group container. | 103 // Handle the addition of |new_undo_group| to the active undo group container. |
| 104 void AddUndoGroup(UndoGroup* new_undo_group); | 104 void AddUndoGroup(UndoGroup* new_undo_group); |
| 105 | 105 |
| 106 // Returns the undo or redo UndoGroup container that should store the next | 106 // Returns the undo or redo UndoGroup container that should store the next |
| 107 // change taking into account if an undo or redo is being executed. | 107 // change taking into account if an undo or redo is being executed. |
| 108 ScopedVector<UndoGroup>* GetActiveUndoGroup(); | 108 std::vector<std::unique_ptr<UndoGroup>>* GetActiveUndoGroup(); |
| 109 | 109 |
| 110 // Containers of user actions ready for an undo or redo treated as a stack. | 110 // Containers of user actions ready for an undo or redo treated as a stack. |
| 111 ScopedVector<UndoGroup> undo_actions_; | 111 std::vector<std::unique_ptr<UndoGroup>> undo_actions_; |
| 112 ScopedVector<UndoGroup> redo_actions_; | 112 std::vector<std::unique_ptr<UndoGroup>> redo_actions_; |
| 113 | 113 |
| 114 // The observers to notify when internal state changes. | 114 // The observers to notify when internal state changes. |
| 115 base::ObserverList<UndoManagerObserver> observers_; | 115 base::ObserverList<UndoManagerObserver> observers_; |
| 116 | 116 |
| 117 // Supports grouping operations into a single undo action. | 117 // Supports grouping operations into a single undo action. |
| 118 int group_actions_count_; | 118 int group_actions_count_; |
| 119 | 119 |
| 120 // The container that is used when actions are grouped. | 120 // The container that is used when actions are grouped. |
| 121 std::unique_ptr<UndoGroup> pending_grouped_action_; | 121 std::unique_ptr<UndoGroup> pending_grouped_action_; |
| 122 | 122 |
| 123 // The action that is in the process of being undone. | 123 // The action that is in the process of being undone. |
| 124 UndoGroup* undo_in_progress_action_; | 124 UndoGroup* undo_in_progress_action_; |
| 125 | 125 |
| 126 // Supports the suspension of undo tracking. | 126 // Supports the suspension of undo tracking. |
| 127 int undo_suspended_count_; | 127 int undo_suspended_count_; |
| 128 | 128 |
| 129 // Set when executing Undo or Redo so that incoming changes are correctly | 129 // Set when executing Undo or Redo so that incoming changes are correctly |
| 130 // processed. | 130 // processed. |
| 131 bool performing_undo_; | 131 bool performing_undo_; |
| 132 bool performing_redo_; | 132 bool performing_redo_; |
| 133 | 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(UndoManager); | 134 DISALLOW_COPY_AND_ASSIGN(UndoManager); |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 #endif // COMPONENTS_UNDO_UNDO_MANAGER_H_ | 137 #endif // COMPONENTS_UNDO_UNDO_MANAGER_H_ |
| OLD | NEW |