| 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 "ash/common/wm/mru_window_tracker.h" | 5 #include "ash/common/wm/mru_window_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/wm/focus_rules.h" | 9 #include "ash/common/wm/focus_rules.h" |
| 10 #include "ash/common/wm/switchable_windows.h" | 10 #include "ash/common/wm/switchable_windows.h" |
| 11 #include "ash/common/wm/window_state.h" | 11 #include "ash/common/wm/window_state.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/common/wm_window.h" | 13 #include "ash/common/wm_window.h" |
| 14 #include "ash/public/cpp/shell_window_ids.h" | 14 #include "ash/public/cpp/shell_window_ids.h" |
| 15 #include "ash/shell.h" |
| 15 #include "base/bind.h" | 16 #include "base/bind.h" |
| 16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/wm/public/activation_client.h" |
| 17 | 19 |
| 18 namespace ash { | 20 namespace ash { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 using CanActivateWindowPredicate = base::Callback<bool(WmWindow*)>; | 24 using CanActivateWindowPredicate = base::Callback<bool(WmWindow*)>; |
| 23 | 25 |
| 24 bool CallCanActivate(WmWindow* window) { | 26 bool CallCanActivate(WmWindow* window) { |
| 25 return window->CanActivate(); | 27 return window->CanActivate(); |
| 26 } | 28 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 94 |
| 93 return windows; | 95 return windows; |
| 94 } | 96 } |
| 95 | 97 |
| 96 } // namespace | 98 } // namespace |
| 97 | 99 |
| 98 ////////////////////////////////////////////////////////////////////////////// | 100 ////////////////////////////////////////////////////////////////////////////// |
| 99 // MruWindowTracker, public: | 101 // MruWindowTracker, public: |
| 100 | 102 |
| 101 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { | 103 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { |
| 102 WmShell::Get()->AddActivationObserver(this); | 104 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 103 } | 105 } |
| 104 | 106 |
| 105 MruWindowTracker::~MruWindowTracker() { | 107 MruWindowTracker::~MruWindowTracker() { |
| 106 WmShell::Get()->RemoveActivationObserver(this); | 108 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 107 for (WmWindow* window : mru_windows_) | 109 for (WmWindow* window : mru_windows_) |
| 108 window->aura_window()->RemoveObserver(this); | 110 window->aura_window()->RemoveObserver(this); |
| 109 } | 111 } |
| 110 | 112 |
| 111 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { | 113 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { |
| 112 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); | 114 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); |
| 113 } | 115 } |
| 114 | 116 |
| 115 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal() | 117 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal() |
| 116 const { | 118 const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 std::list<WmWindow*>::iterator iter = | 139 std::list<WmWindow*>::iterator iter = |
| 138 std::find(mru_windows_.begin(), mru_windows_.end(), active_window); | 140 std::find(mru_windows_.begin(), mru_windows_.end(), active_window); |
| 139 // Observe all newly tracked windows. | 141 // Observe all newly tracked windows. |
| 140 if (iter == mru_windows_.end()) | 142 if (iter == mru_windows_.end()) |
| 141 active_window->aura_window()->AddObserver(this); | 143 active_window->aura_window()->AddObserver(this); |
| 142 else | 144 else |
| 143 mru_windows_.erase(iter); | 145 mru_windows_.erase(iter); |
| 144 mru_windows_.push_front(active_window); | 146 mru_windows_.push_front(active_window); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void MruWindowTracker::OnWindowActivated(WmWindow* gained_active, | 149 void MruWindowTracker::OnWindowActivated(ActivationReason reason, |
| 148 WmWindow* lost_active) { | 150 aura::Window* gained_active, |
| 151 aura::Window* lost_active) { |
| 149 if (!ignore_window_activations_) | 152 if (!ignore_window_activations_) |
| 150 SetActiveWindow(gained_active); | 153 SetActiveWindow(WmWindow::Get(gained_active)); |
| 151 } | 154 } |
| 152 | 155 |
| 153 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { | 156 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { |
| 154 // It's possible for OnWindowActivated() to be called after | 157 // It's possible for OnWindowActivated() to be called after |
| 155 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() | 158 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() |
| 156 // else we may end up with a deleted window in |mru_windows_|. | 159 // else we may end up with a deleted window in |mru_windows_|. |
| 157 mru_windows_.remove(WmWindow::Get(window)); | 160 mru_windows_.remove(WmWindow::Get(window)); |
| 158 window->RemoveObserver(this); | 161 window->RemoveObserver(this); |
| 159 } | 162 } |
| 160 | 163 |
| 161 } // namespace ash | 164 } // namespace ash |
| OLD | NEW |