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

Side by Side Diff: ash/wm/mru_window_tracker.cc

Issue 2895713002: [mus+ash] Removes WmWindow from ash/wm/mru_window_tracker and overview mode (Closed)
Patch Set: Address nits, unit_tests target compiles Created 3 years, 7 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
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 #include "ash/wm/mru_window_tracker.h" 5 #include "ash/wm/mru_window_tracker.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_port.h" 11 #include "ash/shell_port.h"
12 #include "ash/wm/focus_rules.h" 12 #include "ash/wm/focus_rules.h"
13 #include "ash/wm/switchable_windows.h" 13 #include "ash/wm/switchable_windows.h"
14 #include "ash/wm/window_state.h" 14 #include "ash/wm/window_state.h"
15 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
16 #include "ash/wm_window.h"
17 #include "base/bind.h" 16 #include "base/bind.h"
18 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/wm/core/window_util.h"
19 #include "ui/wm/public/activation_client.h" 19 #include "ui/wm/public/activation_client.h"
20 20
21 namespace ash { 21 namespace ash {
22 22
23 namespace { 23 namespace {
24 24
25 using CanActivateWindowPredicate = base::Callback<bool(WmWindow*)>; 25 using CanActivateWindowPredicate = base::Callback<bool(aura::Window*)>;
26 26
27 bool CallCanActivate(WmWindow* window) { 27 bool CallCanActivate(aura::Window* window) {
28 return window->CanActivate(); 28 return ::wm::CanActivateWindow(window);
29 } 29 }
30 30
31 // Adds the windows that can be cycled through for the specified window id to 31 // Adds the windows that can be cycled through for the specified window id to
32 // |windows|. 32 // |windows|.
33 void AddTrackedWindows(WmWindow* root, 33 void AddTrackedWindows(aura::Window* root,
34 int container_id, 34 int container_id,
35 MruWindowTracker::WindowList* windows) { 35 MruWindowTracker::WindowList* windows) {
36 WmWindow* container = root->GetChildByShellWindowId(container_id); 36 aura::Window* container = root->GetChildById(container_id);
37 const MruWindowTracker::WindowList children(container->GetChildren()); 37 const MruWindowTracker::WindowList children(container->children());
38 windows->insert(windows->end(), children.begin(), children.end()); 38 windows->insert(windows->end(), children.begin(), children.end());
39 } 39 }
40 40
41 // Returns a list of windows ordered by their stacking order. 41 // Returns a list of windows ordered by their stacking order.
42 // If |mru_windows| is passed, these windows are moved to the front of the list. 42 // If |mru_windows| is passed, these windows are moved to the front of the list.
43 // It uses the given |should_include_window_predicate| to determine whether to 43 // It uses the given |should_include_window_predicate| to determine whether to
44 // include a window in the returned list or not. 44 // include a window in the returned list or not.
45 MruWindowTracker::WindowList BuildWindowListInternal( 45 MruWindowTracker::WindowList BuildWindowListInternal(
46 const std::list<WmWindow*>* mru_windows, 46 const std::list<aura::Window*>* mru_windows,
47 const CanActivateWindowPredicate& should_include_window_predicate) { 47 const CanActivateWindowPredicate& should_include_window_predicate) {
48 MruWindowTracker::WindowList windows; 48 MruWindowTracker::WindowList windows;
49 aura::Window* active_root = Shell::GetRootWindowForNewWindows(); 49 aura::Window* active_root = Shell::GetRootWindowForNewWindows();
50 for (WmWindow* window : ShellPort::Get()->GetAllRootWindows()) { 50 for (auto* window : Shell::GetAllRootWindows()) {
51 if (window->aura_window() == active_root) 51 if (window == active_root)
52 continue; 52 continue;
53 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) 53 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i)
54 AddTrackedWindows(window, wm::kSwitchableWindowContainerIds[i], &windows); 54 AddTrackedWindows(window, wm::kSwitchableWindowContainerIds[i], &windows);
55 } 55 }
56 56
57 // Add windows in the active root windows last so that the topmost window 57 // Add windows in the active root windows last so that the topmost window
58 // in the active root window becomes the front of the list. 58 // in the active root window becomes the front of the list.
59 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) { 59 for (size_t i = 0; i < wm::kSwitchableWindowContainerIdsLength; ++i) {
60 AddTrackedWindows(WmWindow::Get(active_root), 60 AddTrackedWindows(active_root, wm::kSwitchableWindowContainerIds[i],
61 wm::kSwitchableWindowContainerIds[i], &windows); 61 &windows);
62 } 62 }
63 63
64 // Removes unfocusable windows. 64 // Removes unfocusable windows.
65 std::vector<WmWindow*>::iterator itr = windows.begin(); 65 MruWindowTracker::WindowList::iterator itr = windows.begin();
66 while (itr != windows.end()) { 66 while (itr != windows.end()) {
67 if (!should_include_window_predicate.Run(*itr)) 67 if (!should_include_window_predicate.Run(*itr))
68 itr = windows.erase(itr); 68 itr = windows.erase(itr);
69 else 69 else
70 ++itr; 70 ++itr;
71 } 71 }
72 72
73 // Put the windows in the mru_windows list at the head, if it's available. 73 // Put the windows in the mru_windows list at the head, if it's available.
74 if (mru_windows) { 74 if (mru_windows) {
75 // Iterate through the list backwards, so that we can move each window to 75 // Iterate through the list backwards, so that we can move each window to
76 // the front of the windows list as we find them. 76 // the front of the windows list as we find them.
77 for (auto ix = mru_windows->rbegin(); ix != mru_windows->rend(); ++ix) { 77 for (auto ix = mru_windows->rbegin(); ix != mru_windows->rend(); ++ix) {
78 // Exclude windows in non-switchable containers and those which cannot 78 // Exclude windows in non-switchable containers and those which cannot
79 // be activated. 79 // be activated.
80 if (((*ix)->GetParent() && 80 if (((*ix)->parent() && !wm::IsSwitchableContainer((*ix)->parent())) ||
81 !wm::IsSwitchableContainer((*ix)->GetParent()->aura_window())) ||
82 !should_include_window_predicate.Run(*ix)) { 81 !should_include_window_predicate.Run(*ix)) {
83 continue; 82 continue;
84 } 83 }
85 84
86 MruWindowTracker::WindowList::iterator window = 85 MruWindowTracker::WindowList::iterator window =
87 std::find(windows.begin(), windows.end(), *ix); 86 std::find(windows.begin(), windows.end(), *ix);
88 if (window != windows.end()) { 87 if (window != windows.end()) {
89 windows.erase(window); 88 windows.erase(window);
90 windows.push_back(*ix); 89 windows.push_back(*ix);
91 } 90 }
(...skipping 10 matching lines...) Expand all
102 101
103 ////////////////////////////////////////////////////////////////////////////// 102 //////////////////////////////////////////////////////////////////////////////
104 // MruWindowTracker, public: 103 // MruWindowTracker, public:
105 104
106 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { 105 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) {
107 Shell::Get()->activation_client()->AddObserver(this); 106 Shell::Get()->activation_client()->AddObserver(this);
108 } 107 }
109 108
110 MruWindowTracker::~MruWindowTracker() { 109 MruWindowTracker::~MruWindowTracker() {
111 Shell::Get()->activation_client()->RemoveObserver(this); 110 Shell::Get()->activation_client()->RemoveObserver(this);
112 for (WmWindow* window : mru_windows_) 111 for (auto* window : mru_windows_)
113 window->aura_window()->RemoveObserver(this); 112 window->RemoveObserver(this);
114 } 113 }
115 114
116 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { 115 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const {
117 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); 116 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate));
118 } 117 }
119 118
120 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal() 119 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal()
121 const { 120 const {
122 return BuildWindowListInternal(nullptr, 121 return BuildWindowListInternal(nullptr,
123 base::Bind(&IsWindowConsideredActivatable)); 122 base::Bind(&IsWindowConsideredActivatable));
124 } 123 }
125 124
126 void MruWindowTracker::SetIgnoreActivations(bool ignore) { 125 void MruWindowTracker::SetIgnoreActivations(bool ignore) {
127 ignore_window_activations_ = ignore; 126 ignore_window_activations_ = ignore;
128 127
129 // If no longer ignoring window activations, move currently active window 128 // If no longer ignoring window activations, move currently active window
130 // to front. 129 // to front.
131 if (!ignore) 130 if (!ignore)
132 SetActiveWindow(WmWindow::Get(wm::GetActiveWindow())); 131 SetActiveWindow(wm::GetActiveWindow());
133 } 132 }
134 133
135 ////////////////////////////////////////////////////////////////////////////// 134 //////////////////////////////////////////////////////////////////////////////
136 // MruWindowTracker, private: 135 // MruWindowTracker, private:
137 136
138 void MruWindowTracker::SetActiveWindow(WmWindow* active_window) { 137 void MruWindowTracker::SetActiveWindow(aura::Window* active_window) {
139 if (!active_window) 138 if (!active_window)
140 return; 139 return;
141 140
142 std::list<WmWindow*>::iterator iter = 141 std::list<aura::Window*>::iterator iter =
143 std::find(mru_windows_.begin(), mru_windows_.end(), active_window); 142 std::find(mru_windows_.begin(), mru_windows_.end(), active_window);
144 // Observe all newly tracked windows. 143 // Observe all newly tracked windows.
145 if (iter == mru_windows_.end()) 144 if (iter == mru_windows_.end())
146 active_window->aura_window()->AddObserver(this); 145 active_window->AddObserver(this);
147 else 146 else
148 mru_windows_.erase(iter); 147 mru_windows_.erase(iter);
149 mru_windows_.push_front(active_window); 148 mru_windows_.push_front(active_window);
150 } 149 }
151 150
152 void MruWindowTracker::OnWindowActivated(ActivationReason reason, 151 void MruWindowTracker::OnWindowActivated(ActivationReason reason,
153 aura::Window* gained_active, 152 aura::Window* gained_active,
154 aura::Window* lost_active) { 153 aura::Window* lost_active) {
155 if (!ignore_window_activations_) 154 if (!ignore_window_activations_)
156 SetActiveWindow(WmWindow::Get(gained_active)); 155 SetActiveWindow(gained_active);
157 } 156 }
158 157
159 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { 158 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) {
160 // It's possible for OnWindowActivated() to be called after 159 // It's possible for OnWindowActivated() to be called after
161 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() 160 // OnWindowDestroying(). This means we need to override OnWindowDestroyed()
162 // else we may end up with a deleted window in |mru_windows_|. 161 // else we may end up with a deleted window in |mru_windows_|.
163 mru_windows_.remove(WmWindow::Get(window)); 162 mru_windows_.remove(window);
164 window->RemoveObserver(this); 163 window->RemoveObserver(this);
165 } 164 }
166 165
167 } // namespace ash 166 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698