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

Side by Side Diff: ui/base/window_tracker_template.h

Issue 2455963006: Wires up drag/drop for aura-mus (Closed)
Patch Set: twweaks Created 4 years, 1 month 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 | « ui/aura/mus/window_tree_client.cc ('k') | ui/views/mus/drop_target_mus.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ 5 #ifndef UI_BASE_WINDOW_TRACKER_TEMPLATE_H_
6 #define UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ 6 #define UI_BASE_WINDOW_TRACKER_TEMPLATE_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 12 matching lines...) Expand all
23 // A vector<> is used for tracking the windows (instead of a set<>) because 23 // A vector<> is used for tracking the windows (instead of a set<>) because
24 // the user may want to know about the order of the windows that have been 24 // the user may want to know about the order of the windows that have been
25 // added. 25 // added.
26 using WindowList = std::vector<T*>; 26 using WindowList = std::vector<T*>;
27 27
28 explicit WindowTrackerTemplate(const WindowList& windows) { 28 explicit WindowTrackerTemplate(const WindowList& windows) {
29 for (T* window : windows) 29 for (T* window : windows)
30 Add(window); 30 Add(window);
31 } 31 }
32 WindowTrackerTemplate() {} 32 WindowTrackerTemplate() {}
33 ~WindowTrackerTemplate() override { 33 ~WindowTrackerTemplate() override { RemoveAll(); }
34 for (T* window : windows_)
35 window->RemoveObserver(this);
36 }
37 34
38 // Returns the set of windows being observed. 35 // Returns the set of windows being observed.
39 const WindowList& windows() const { return windows_; } 36 const WindowList& windows() const { return windows_; }
40 37
41 // Adds |window| to the set of Windows being tracked. 38 // Adds |window| to the set of Windows being tracked.
42 void Add(T* window) { 39 void Add(T* window) {
43 if (base::ContainsValue(windows_, window)) 40 if (base::ContainsValue(windows_, window))
44 return; 41 return;
45 42
46 window->AddObserver(this); 43 window->AddObserver(this);
47 windows_.push_back(window); 44 windows_.push_back(window);
48 } 45 }
49 46
47 void RemoveAll() {
48 for (T* window : windows_)
49 window->RemoveObserver(this);
50 windows_.clear();
51 }
52
50 // Removes |window| from the set of windows being tracked. 53 // Removes |window| from the set of windows being tracked.
51 void Remove(T* window) { 54 void Remove(T* window) {
52 auto iter = std::find(windows_.begin(), windows_.end(), window); 55 auto iter = std::find(windows_.begin(), windows_.end(), window);
53 if (iter != windows_.end()) { 56 if (iter != windows_.end()) {
54 window->RemoveObserver(this); 57 window->RemoveObserver(this);
55 windows_.erase(iter); 58 windows_.erase(iter);
56 } 59 }
57 } 60 }
58 61
59 T* Pop() { 62 T* Pop() {
(...skipping 17 matching lines...) Expand all
77 80
78 private: 81 private:
79 WindowList windows_; 82 WindowList windows_;
80 83
81 DISALLOW_COPY_AND_ASSIGN(WindowTrackerTemplate); 84 DISALLOW_COPY_AND_ASSIGN(WindowTrackerTemplate);
82 }; 85 };
83 86
84 } // namespace ui 87 } // namespace ui
85 88
86 #endif // UI_BASE_WINDOW_TRACKER_TEMPLATE_H_ 89 #endif // UI_BASE_WINDOW_TRACKER_TEMPLATE_H_
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/views/mus/drop_target_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698