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/session/session_state_delegate.h" | 9 #include "ash/session/session_state_delegate.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 aura::Window* container = | 38 aura::Window* container = |
| 39 Shell::GetContainer(root, kShellWindowId_DockedContainer); | 39 Shell::GetContainer(root, kShellWindowId_DockedContainer); |
| 40 const MruWindowTracker::WindowList& children = container->children(); | 40 const MruWindowTracker::WindowList& children = container->children(); |
| 41 for (MruWindowTracker::WindowList::const_iterator iter = children.begin(); | 41 for (MruWindowTracker::WindowList::const_iterator iter = children.begin(); |
| 42 iter != children.end(); ++iter) { | 42 iter != children.end(); ++iter) { |
| 43 if (wm::GetWindowState(*iter)->is_dragged()) | 43 if (wm::GetWindowState(*iter)->is_dragged()) |
| 44 windows->insert(windows->end(), *iter); | 44 windows->insert(windows->end(), *iter); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Returns whether |w1| should be considered less recently used than |w2|. This | 48 // Returns whether |w1| should be considered more recently used than |w2|. This |
| 49 // is used for a stable sort to move minimized windows to the LRU end of the | 49 // is used for a stable sort to move minimized windows to the LRU end of the |
| 50 // list. | 50 // list. |
| 51 bool CompareWindowState(aura::Window* w1, aura::Window* w2) { | 51 bool CompareWindowState(aura::Window* w1, aura::Window* w2) { |
| 52 return ash::wm::IsWindowMinimized(w1) && !ash::wm::IsWindowMinimized(w2); | 52 return !(ash::wm::IsWindowMinimized(w1) && !ash::wm::IsWindowMinimized(w2)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Returns a list of windows ordered by their stacking order. | 55 // Returns a list of windows ordered by their stacking order. |
| 56 // If |mru_windows| is passed, these windows are moved to the front of the list. | 56 // If |mru_windows| is passed, these windows are moved to the front of the list. |
| 57 // If |top_most_at_end|, the list is returned in descending (bottom-most / least | |
| 58 // recently used) order. | |
| 59 MruWindowTracker::WindowList BuildWindowListInternal( | 57 MruWindowTracker::WindowList BuildWindowListInternal( |
| 60 const std::list<aura::Window*>* mru_windows, | 58 const std::list<aura::Window*>* mru_windows) { |
| 61 bool top_most_at_end) { | |
| 62 MruWindowTracker::WindowList windows; | 59 MruWindowTracker::WindowList windows; |
| 63 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 60 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 64 | 61 |
| 65 aura::Window* active_root = Shell::GetTargetRootWindow(); | 62 aura::Window* active_root = Shell::GetTargetRootWindow(); |
| 66 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); | 63 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); |
| 67 iter != root_windows.end(); ++iter) { | 64 iter != root_windows.end(); ++iter) { |
| 68 if (*iter == active_root) | 65 if (*iter == active_root) |
| 69 continue; | 66 continue; |
| 70 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) | 67 for (size_t i = 0; i < kSwitchableWindowContainerIdsLength; ++i) |
| 71 AddTrackedWindows(*iter, kSwitchableWindowContainerIds[i], &windows); | 68 AddTrackedWindows(*iter, kSwitchableWindowContainerIds[i], &windows); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 101 |
| 105 MruWindowTracker::WindowList::iterator window = | 102 MruWindowTracker::WindowList::iterator window = |
| 106 std::find(windows.begin(), windows.end(), *ix); | 103 std::find(windows.begin(), windows.end(), *ix); |
| 107 if (window != windows.end()) { | 104 if (window != windows.end()) { |
| 108 windows.erase(window); | 105 windows.erase(window); |
| 109 windows.push_back(*ix); | 106 windows.push_back(*ix); |
| 110 } | 107 } |
| 111 } | 108 } |
| 112 } | 109 } |
| 113 | 110 |
| 114 // Move minimized windows to the beginning (LRU end) of the list. | 111 // Window cycling expects the topmost window at the front of the list. |
| 112 // Move minimized windows to the end (LRU end) of the list. | |
| 115 std::stable_sort(windows.begin(), windows.end(), CompareWindowState); | 113 std::stable_sort(windows.begin(), windows.end(), CompareWindowState); |
| 116 | 114 |
| 117 // Window cycling expects the topmost window at the front of the list. | |
| 118 if (!top_most_at_end) | |
| 119 std::reverse(windows.begin(), windows.end()); | |
|
oshima
2014/12/08 19:05:27
you have to do this always instead. sorry for not
| |
| 120 | |
| 121 return windows; | 115 return windows; |
| 122 } | 116 } |
| 123 | 117 |
| 124 } // namespace | 118 } // namespace |
| 125 | 119 |
| 126 ////////////////////////////////////////////////////////////////////////////// | 120 ////////////////////////////////////////////////////////////////////////////// |
| 127 // MruWindowTracker, public: | 121 // MruWindowTracker, public: |
| 128 | 122 |
| 129 MruWindowTracker::MruWindowTracker( | 123 MruWindowTracker::MruWindowTracker( |
| 130 aura::client::ActivationClient* activation_client) | 124 aura::client::ActivationClient* activation_client) |
| 131 : activation_client_(activation_client), | 125 : activation_client_(activation_client), |
| 132 ignore_window_activations_(false) { | 126 ignore_window_activations_(false) { |
| 133 activation_client_->AddObserver(this); | 127 activation_client_->AddObserver(this); |
| 134 } | 128 } |
| 135 | 129 |
| 136 MruWindowTracker::~MruWindowTracker() { | 130 MruWindowTracker::~MruWindowTracker() { |
| 137 for (std::list<aura::Window*>::iterator iter = mru_windows_.begin(); | 131 for (std::list<aura::Window*>::iterator iter = mru_windows_.begin(); |
| 138 iter != mru_windows_.end(); ++iter) { | 132 iter != mru_windows_.end(); ++iter) { |
| 139 (*iter)->RemoveObserver(this); | 133 (*iter)->RemoveObserver(this); |
| 140 } | 134 } |
| 141 | 135 |
| 142 activation_client_->RemoveObserver(this); | 136 activation_client_->RemoveObserver(this); |
| 143 } | 137 } |
| 144 | 138 |
| 145 // static | 139 // static |
| 146 MruWindowTracker::WindowList MruWindowTracker::BuildWindowList( | 140 MruWindowTracker::WindowList MruWindowTracker::BuildWindowList() { |
| 147 bool top_most_at_end) { | 141 return BuildWindowListInternal(NULL); |
| 148 return BuildWindowListInternal(NULL, top_most_at_end); | |
| 149 } | 142 } |
| 150 | 143 |
| 151 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() { | 144 MruWindowTracker::WindowList MruWindowTracker::BuildMruWindowList() { |
| 152 return BuildWindowListInternal(&mru_windows_, false); | 145 return BuildWindowListInternal(&mru_windows_); |
| 153 } | 146 } |
| 154 | 147 |
| 155 void MruWindowTracker::SetIgnoreActivations(bool ignore) { | 148 void MruWindowTracker::SetIgnoreActivations(bool ignore) { |
| 156 ignore_window_activations_ = ignore; | 149 ignore_window_activations_ = ignore; |
| 157 | 150 |
| 158 // If no longer ignoring window activations, move currently active window | 151 // If no longer ignoring window activations, move currently active window |
| 159 // to front. | 152 // to front. |
| 160 if (!ignore) | 153 if (!ignore) |
| 161 SetActiveWindow(wm::GetActiveWindow()); | 154 SetActiveWindow(wm::GetActiveWindow()); |
| 162 } | 155 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 190 | 183 |
| 191 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { | 184 void MruWindowTracker::OnWindowDestroyed(aura::Window* window) { |
| 192 // It's possible for OnWindowActivated() to be called after | 185 // It's possible for OnWindowActivated() to be called after |
| 193 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() | 186 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() |
| 194 // else we may end up with a deleted window in |mru_windows_|. | 187 // else we may end up with a deleted window in |mru_windows_|. |
| 195 mru_windows_.remove(window); | 188 mru_windows_.remove(window); |
| 196 window->RemoveObserver(this); | 189 window->RemoveObserver(this); |
| 197 } | 190 } |
| 198 | 191 |
| 199 } // namespace ash | 192 } // namespace ash |
| OLD | NEW |