| 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 "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "ui/aura/window.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 using CanActivateWindowPredicate = base::Callback<bool(WmWindow*)>; | 22 using CanActivateWindowPredicate = base::Callback<bool(WmWindow*)>; |
| 22 | 23 |
| 23 bool CallCanActivate(WmWindow* window) { | 24 bool CallCanActivate(WmWindow* window) { |
| 24 return window->CanActivate(); | 25 return window->CanActivate(); |
| 25 } | 26 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 ////////////////////////////////////////////////////////////////////////////// | 98 ////////////////////////////////////////////////////////////////////////////// |
| 98 // MruWindowTracker, public: | 99 // MruWindowTracker, public: |
| 99 | 100 |
| 100 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { | 101 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { |
| 101 WmShell::Get()->AddActivationObserver(this); | 102 WmShell::Get()->AddActivationObserver(this); |
| 102 } | 103 } |
| 103 | 104 |
| 104 MruWindowTracker::~MruWindowTracker() { | 105 MruWindowTracker::~MruWindowTracker() { |
| 105 WmShell::Get()->RemoveActivationObserver(this); | 106 WmShell::Get()->RemoveActivationObserver(this); |
| 106 for (WmWindow* window : mru_windows_) | 107 for (WmWindow* window : mru_windows_) |
| 107 window->RemoveObserver(this); | 108 window->aura_window()->RemoveObserver(this); |
| 108 } | 109 } |
| 109 | 110 |
| 110 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { | 111 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { |
| 111 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); | 112 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); |
| 112 } | 113 } |
| 113 | 114 |
| 114 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal() | 115 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal() |
| 115 const { | 116 const { |
| 116 return BuildWindowListInternal(nullptr, | 117 return BuildWindowListInternal(nullptr, |
| 117 base::Bind(&IsWindowConsideredActivatable)); | 118 base::Bind(&IsWindowConsideredActivatable)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 130 // MruWindowTracker, private: | 131 // MruWindowTracker, private: |
| 131 | 132 |
| 132 void MruWindowTracker::SetActiveWindow(WmWindow* active_window) { | 133 void MruWindowTracker::SetActiveWindow(WmWindow* active_window) { |
| 133 if (!active_window) | 134 if (!active_window) |
| 134 return; | 135 return; |
| 135 | 136 |
| 136 std::list<WmWindow*>::iterator iter = | 137 std::list<WmWindow*>::iterator iter = |
| 137 std::find(mru_windows_.begin(), mru_windows_.end(), active_window); | 138 std::find(mru_windows_.begin(), mru_windows_.end(), active_window); |
| 138 // Observe all newly tracked windows. | 139 // Observe all newly tracked windows. |
| 139 if (iter == mru_windows_.end()) | 140 if (iter == mru_windows_.end()) |
| 140 active_window->AddObserver(this); | 141 active_window->aura_window()->AddObserver(this); |
| 141 else | 142 else |
| 142 mru_windows_.erase(iter); | 143 mru_windows_.erase(iter); |
| 143 mru_windows_.push_front(active_window); | 144 mru_windows_.push_front(active_window); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void MruWindowTracker::OnWindowActivated(WmWindow* gained_active, | 147 void MruWindowTracker::OnWindowActivated(WmWindow* gained_active, |
| 147 WmWindow* lost_active) { | 148 WmWindow* lost_active) { |
| 148 if (!ignore_window_activations_) | 149 if (!ignore_window_activations_) |
| 149 SetActiveWindow(gained_active); | 150 SetActiveWindow(gained_active); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void MruWindowTracker::OnWindowDestroyed(WmWindow* window) { | 153 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { |
| 153 // It's possible for OnWindowActivated() to be called after | 154 // It's possible for OnWindowActivated() to be called after |
| 154 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() | 155 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() |
| 155 // else we may end up with a deleted window in |mru_windows_|. | 156 // else we may end up with a deleted window in |mru_windows_|. |
| 156 mru_windows_.remove(window); | 157 mru_windows_.remove(WmWindow::Get(window)); |
| 157 window->RemoveObserver(this); | 158 window->RemoveObserver(this); |
| 158 } | 159 } |
| 159 | 160 |
| 160 } // namespace ash | 161 } // namespace ash |
| OLD | NEW |