Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: components/undo/undo_manager.h

Issue 2644203003: Remove ScopedVector in //component/undo (Closed)
Patch Set: Remove ScopedVector in //component/undo Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/undo/undo_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
73 // Group multiple operations into one undoable action. 73 // Group multiple operations into one undoable action.
74 void StartGroupingActions(); 74 void StartGroupingActions();
75 void EndGroupingActions(); 75 void EndGroupingActions();
76 76
77 // Suspend undo tracking while processing non-user initiated changes such as 77 // Suspend undo tracking while processing non-user initiated changes such as
78 // profile synchonization. 78 // profile synchonization.
79 void SuspendUndoTracking(); 79 void SuspendUndoTracking();
80 void ResumeUndoTracking(); 80 void ResumeUndoTracking();
81 bool IsUndoTrakingSuspended() const; 81 bool IsUndoTrakingSuspended() const;
82 82
83 // Returns all UndoOperations that are awaiting Undo or Redo. Note that
84 // ownership of the UndoOperations is retained by UndoManager.
85 std::vector<UndoOperation*> GetAllUndoOperations() const;
86
87 // Remove all undo and redo operations. Note that grouping of actions and 83 // Remove all undo and redo operations. Note that grouping of actions and
88 // suspension of undo tracking states are left unchanged. 84 // suspension of undo tracking states are left unchanged.
89 void RemoveAllOperations(); 85 void RemoveAllOperations();
90 86
91 // Observers are notified when the internal state of this class changes. 87 // Observers are notified when the internal state of this class changes.
92 void AddObserver(UndoManagerObserver* observer); 88 void AddObserver(UndoManagerObserver* observer);
93 void RemoveObserver(UndoManagerObserver* observer); 89 void RemoveObserver(UndoManagerObserver* observer);
94 90
95 private: 91 private:
92 friend class UndoManagerTestApi;
93
96 void Undo(bool* performing_indicator, 94 void Undo(bool* performing_indicator,
97 ScopedVector<UndoGroup>* active_undo_group); 95 std::vector<std::unique_ptr<UndoGroup>>* active_undo_group);
98 bool is_user_action() const { return !performing_undo_ && !performing_redo_; } 96 bool is_user_action() const { return !performing_undo_ && !performing_redo_; }
99 97
100 // Notifies the observers that the undo manager's state has changed. 98 // Notifies the observers that the undo manager's state has changed.
101 void NotifyOnUndoManagerStateChange(); 99 void NotifyOnUndoManagerStateChange();
102 100
103 // Handle the addition of |new_undo_group| to the active undo group container. 101 // Handle the addition of |new_undo_group| to the active undo group container.
104 void AddUndoGroup(UndoGroup* new_undo_group); 102 void AddUndoGroup(UndoGroup* new_undo_group);
105 103
106 // Returns the undo or redo UndoGroup container that should store the next 104 // 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. 105 // change taking into account if an undo or redo is being executed.
108 ScopedVector<UndoGroup>* GetActiveUndoGroup(); 106 std::vector<std::unique_ptr<UndoGroup>>* GetActiveUndoGroup();
109 107
110 // Containers of user actions ready for an undo or redo treated as a stack. 108 // Containers of user actions ready for an undo or redo treated as a stack.
111 ScopedVector<UndoGroup> undo_actions_; 109 std::vector<std::unique_ptr<UndoGroup>> undo_actions_;
112 ScopedVector<UndoGroup> redo_actions_; 110 std::vector<std::unique_ptr<UndoGroup>> redo_actions_;
113 111
114 // The observers to notify when internal state changes. 112 // The observers to notify when internal state changes.
115 base::ObserverList<UndoManagerObserver> observers_; 113 base::ObserverList<UndoManagerObserver> observers_;
116 114
117 // Supports grouping operations into a single undo action. 115 // Supports grouping operations into a single undo action.
118 int group_actions_count_; 116 int group_actions_count_;
119 117
120 // The container that is used when actions are grouped. 118 // The container that is used when actions are grouped.
121 std::unique_ptr<UndoGroup> pending_grouped_action_; 119 std::unique_ptr<UndoGroup> pending_grouped_action_;
122 120
123 // The action that is in the process of being undone. 121 // The action that is in the process of being undone.
124 UndoGroup* undo_in_progress_action_; 122 UndoGroup* undo_in_progress_action_;
125 123
126 // Supports the suspension of undo tracking. 124 // Supports the suspension of undo tracking.
127 int undo_suspended_count_; 125 int undo_suspended_count_;
128 126
129 // Set when executing Undo or Redo so that incoming changes are correctly 127 // Set when executing Undo or Redo so that incoming changes are correctly
130 // processed. 128 // processed.
131 bool performing_undo_; 129 bool performing_undo_;
132 bool performing_redo_; 130 bool performing_redo_;
133 131
134 DISALLOW_COPY_AND_ASSIGN(UndoManager); 132 DISALLOW_COPY_AND_ASSIGN(UndoManager);
135 }; 133 };
136 134
137 #endif // COMPONENTS_UNDO_UNDO_MANAGER_H_ 135 #endif // COMPONENTS_UNDO_UNDO_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | components/undo/undo_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698