Chromium Code Reviews| 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/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) |
|
msw
2017/05/23 22:50:24
nit: keep curlies for multi-line loop block
varkha
2017/05/24 15:29:14
Done.
| |
| 60 AddTrackedWindows(WmWindow::Get(active_root), | 60 AddTrackedWindows(active_root, wm::kSwitchableWindowContainerIds[i], |
| 61 wm::kSwitchableWindowContainerIds[i], &windows); | 61 &windows); |
| 62 } | |
| 63 | 62 |
| 64 // Removes unfocusable windows. | 63 // Removes unfocusable windows. |
| 65 std::vector<WmWindow*>::iterator itr = windows.begin(); | 64 std::vector<aura::Window*>::iterator itr = windows.begin(); |
|
msw
2017/05/23 22:50:24
nit: aura::Window::Windows
varkha
2017/05/24 15:29:14
Done.
| |
| 66 while (itr != windows.end()) { | 65 while (itr != windows.end()) { |
| 67 if (!should_include_window_predicate.Run(*itr)) | 66 if (!should_include_window_predicate.Run(*itr)) |
| 68 itr = windows.erase(itr); | 67 itr = windows.erase(itr); |
| 69 else | 68 else |
| 70 ++itr; | 69 ++itr; |
| 71 } | 70 } |
| 72 | 71 |
| 73 // Put the windows in the mru_windows list at the head, if it's available. | 72 // Put the windows in the mru_windows list at the head, if it's available. |
| 74 if (mru_windows) { | 73 if (mru_windows) { |
| 75 // Iterate through the list backwards, so that we can move each window to | 74 // Iterate through the list backwards, so that we can move each window to |
| 76 // the front of the windows list as we find them. | 75 // the front of the windows list as we find them. |
| 77 for (auto ix = mru_windows->rbegin(); ix != mru_windows->rend(); ++ix) { | 76 for (auto ix = mru_windows->rbegin(); ix != mru_windows->rend(); ++ix) { |
| 78 // Exclude windows in non-switchable containers and those which cannot | 77 // Exclude windows in non-switchable containers and those which cannot |
| 79 // be activated. | 78 // be activated. |
| 80 if (((*ix)->GetParent() && | 79 if (((*ix)->parent() && !wm::IsSwitchableContainer((*ix)->parent())) || |
| 81 !wm::IsSwitchableContainer((*ix)->GetParent()->aura_window())) || | |
| 82 !should_include_window_predicate.Run(*ix)) { | 80 !should_include_window_predicate.Run(*ix)) { |
| 83 continue; | 81 continue; |
| 84 } | 82 } |
| 85 | 83 |
| 86 MruWindowTracker::WindowList::iterator window = | 84 MruWindowTracker::WindowList::iterator window = |
| 87 std::find(windows.begin(), windows.end(), *ix); | 85 std::find(windows.begin(), windows.end(), *ix); |
| 88 if (window != windows.end()) { | 86 if (window != windows.end()) { |
| 89 windows.erase(window); | 87 windows.erase(window); |
| 90 windows.push_back(*ix); | 88 windows.push_back(*ix); |
| 91 } | 89 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 102 | 100 |
| 103 ////////////////////////////////////////////////////////////////////////////// | 101 ////////////////////////////////////////////////////////////////////////////// |
| 104 // MruWindowTracker, public: | 102 // MruWindowTracker, public: |
| 105 | 103 |
| 106 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { | 104 MruWindowTracker::MruWindowTracker() : ignore_window_activations_(false) { |
| 107 Shell::Get()->activation_client()->AddObserver(this); | 105 Shell::Get()->activation_client()->AddObserver(this); |
| 108 } | 106 } |
| 109 | 107 |
| 110 MruWindowTracker::~MruWindowTracker() { | 108 MruWindowTracker::~MruWindowTracker() { |
| 111 Shell::Get()->activation_client()->RemoveObserver(this); | 109 Shell::Get()->activation_client()->RemoveObserver(this); |
| 112 for (WmWindow* window : mru_windows_) | 110 for (auto* window : mru_windows_) |
| 113 window->aura_window()->RemoveObserver(this); | 111 window->RemoveObserver(this); |
| 114 } | 112 } |
| 115 | 113 |
| 116 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { | 114 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() const { |
| 117 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); | 115 return BuildWindowListInternal(&mru_windows_, base::Bind(&CallCanActivate)); |
| 118 } | 116 } |
| 119 | 117 |
| 120 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal() | 118 MruWindowTracker::WindowList MruWindowTracker::BuildWindowListIgnoreModal() |
| 121 const { | 119 const { |
| 122 return BuildWindowListInternal(nullptr, | 120 return BuildWindowListInternal(nullptr, |
| 123 base::Bind(&IsWindowConsideredActivatable)); | 121 base::Bind(&IsWindowConsideredActivatable)); |
| 124 } | 122 } |
| 125 | 123 |
| 126 void MruWindowTracker::SetIgnoreActivations(bool ignore) { | 124 void MruWindowTracker::SetIgnoreActivations(bool ignore) { |
| 127 ignore_window_activations_ = ignore; | 125 ignore_window_activations_ = ignore; |
| 128 | 126 |
| 129 // If no longer ignoring window activations, move currently active window | 127 // If no longer ignoring window activations, move currently active window |
| 130 // to front. | 128 // to front. |
| 131 if (!ignore) | 129 if (!ignore) |
| 132 SetActiveWindow(WmWindow::Get(wm::GetActiveWindow())); | 130 SetActiveWindow(wm::GetActiveWindow()); |
| 133 } | 131 } |
| 134 | 132 |
| 135 ////////////////////////////////////////////////////////////////////////////// | 133 ////////////////////////////////////////////////////////////////////////////// |
| 136 // MruWindowTracker, private: | 134 // MruWindowTracker, private: |
| 137 | 135 |
| 138 void MruWindowTracker::SetActiveWindow(WmWindow* active_window) { | 136 void MruWindowTracker::SetActiveWindow(aura::Window* active_window) { |
| 139 if (!active_window) | 137 if (!active_window) |
| 140 return; | 138 return; |
| 141 | 139 |
| 142 std::list<WmWindow*>::iterator iter = | 140 std::list<aura::Window*>::iterator iter = |
| 143 std::find(mru_windows_.begin(), mru_windows_.end(), active_window); | 141 std::find(mru_windows_.begin(), mru_windows_.end(), active_window); |
| 144 // Observe all newly tracked windows. | 142 // Observe all newly tracked windows. |
| 145 if (iter == mru_windows_.end()) | 143 if (iter == mru_windows_.end()) |
| 146 active_window->aura_window()->AddObserver(this); | 144 active_window->AddObserver(this); |
| 147 else | 145 else |
| 148 mru_windows_.erase(iter); | 146 mru_windows_.erase(iter); |
| 149 mru_windows_.push_front(active_window); | 147 mru_windows_.push_front(active_window); |
| 150 } | 148 } |
| 151 | 149 |
| 152 void MruWindowTracker::OnWindowActivated(ActivationReason reason, | 150 void MruWindowTracker::OnWindowActivated(ActivationReason reason, |
| 153 aura::Window* gained_active, | 151 aura::Window* gained_active, |
| 154 aura::Window* lost_active) { | 152 aura::Window* lost_active) { |
| 155 if (!ignore_window_activations_) | 153 if (!ignore_window_activations_) |
| 156 SetActiveWindow(WmWindow::Get(gained_active)); | 154 SetActiveWindow(gained_active); |
| 157 } | 155 } |
| 158 | 156 |
| 159 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { | 157 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { |
| 160 // It's possible for OnWindowActivated() to be called after | 158 // It's possible for OnWindowActivated() to be called after |
| 161 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() | 159 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() |
| 162 // else we may end up with a deleted window in |mru_windows_|. | 160 // else we may end up with a deleted window in |mru_windows_|. |
| 163 mru_windows_.remove(WmWindow::Get(window)); | 161 mru_windows_.remove(window); |
| 164 window->RemoveObserver(this); | 162 window->RemoveObserver(this); |
| 165 } | 163 } |
| 166 | 164 |
| 167 } // namespace ash | 165 } // namespace ash |
| OLD | NEW |