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/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
10 #include "ash/common/wm/focus_rules.h" | 10 #include "ash/common/wm/focus_rules.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // Adds the windows that can be cycled through for the specified window id to | 27 // Adds the windows that can be cycled through for the specified window id to |
28 // |windows|. | 28 // |windows|. |
29 void AddTrackedWindows(WmWindow* root, | 29 void AddTrackedWindows(WmWindow* root, |
30 int container_id, | 30 int container_id, |
31 MruWindowTracker::WindowList* windows) { | 31 MruWindowTracker::WindowList* windows) { |
32 WmWindow* container = root->GetChildByShellWindowId(container_id); | 32 WmWindow* container = root->GetChildByShellWindowId(container_id); |
33 const MruWindowTracker::WindowList children(container->GetChildren()); | 33 const MruWindowTracker::WindowList children(container->GetChildren()); |
34 windows->insert(windows->end(), children.begin(), children.end()); | 34 windows->insert(windows->end(), children.begin(), children.end()); |
35 } | 35 } |
36 | 36 |
37 // Returns whether |w1| should be considered less recently used than |w2|. This | |
38 // is used for a stable sort to move minimized windows to the LRU end of the | |
39 // list. | |
40 bool CompareWindowState(WmWindow* w1, WmWindow* w2) { | |
41 return w1->GetWindowState()->IsMinimized() && | |
42 !w2->GetWindowState()->IsMinimized(); | |
43 } | |
44 | |
45 // Returns a list of windows ordered by their stacking order. | 37 // Returns a list of windows ordered by their stacking order. |
46 // If |mru_windows| is passed, these windows are moved to the front of the list. | 38 // If |mru_windows| is passed, these windows are moved to the front of the list. |
47 // It uses the given |should_include_window_predicate| to determine whether to | 39 // It uses the given |should_include_window_predicate| to determine whether to |
48 // include a window in the returned list or not. | 40 // include a window in the returned list or not. |
49 MruWindowTracker::WindowList BuildWindowListInternal( | 41 MruWindowTracker::WindowList BuildWindowListInternal( |
50 const std::list<WmWindow*>* mru_windows, | 42 const std::list<WmWindow*>* mru_windows, |
51 const CanActivateWindowPredicate& should_include_window_predicate) { | 43 const CanActivateWindowPredicate& should_include_window_predicate) { |
52 MruWindowTracker::WindowList windows; | 44 MruWindowTracker::WindowList windows; |
53 WmWindow* active_root = WmShell::Get()->GetRootWindowForNewWindows(); | 45 WmWindow* active_root = WmShell::Get()->GetRootWindowForNewWindows(); |
54 for (WmWindow* window : WmShell::Get()->GetAllRootWindows()) { | 46 for (WmWindow* window : WmShell::Get()->GetAllRootWindows()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 80 |
89 MruWindowTracker::WindowList::iterator window = | 81 MruWindowTracker::WindowList::iterator window = |
90 std::find(windows.begin(), windows.end(), *ix); | 82 std::find(windows.begin(), windows.end(), *ix); |
91 if (window != windows.end()) { | 83 if (window != windows.end()) { |
92 windows.erase(window); | 84 windows.erase(window); |
93 windows.push_back(*ix); | 85 windows.push_back(*ix); |
94 } | 86 } |
95 } | 87 } |
96 } | 88 } |
97 | 89 |
98 // Move minimized windows to the beginning (LRU end) of the list. | |
99 std::stable_sort(windows.begin(), windows.end(), CompareWindowState); | |
100 | |
101 // Window cycling expects the topmost window at the front of the list. | 90 // Window cycling expects the topmost window at the front of the list. |
102 std::reverse(windows.begin(), windows.end()); | 91 std::reverse(windows.begin(), windows.end()); |
103 | 92 |
104 return windows; | 93 return windows; |
105 } | 94 } |
106 | 95 |
107 } // namespace | 96 } // namespace |
108 | 97 |
109 ////////////////////////////////////////////////////////////////////////////// | 98 ////////////////////////////////////////////////////////////////////////////// |
110 // MruWindowTracker, public: | 99 // MruWindowTracker, public: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 152 |
164 void MruWindowTracker::OnWindowDestroyed(WmWindow* window) { | 153 void MruWindowTracker::OnWindowDestroyed(WmWindow* window) { |
165 // It's possible for OnWindowActivated() to be called after | 154 // It's possible for OnWindowActivated() to be called after |
166 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() | 155 // OnWindowDestroying(). This means we need to override OnWindowDestroyed() |
167 // 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_|. |
168 mru_windows_.remove(window); | 157 mru_windows_.remove(window); |
169 window->RemoveObserver(this); | 158 window->RemoveObserver(this); |
170 } | 159 } |
171 | 160 |
172 } // namespace ash | 161 } // namespace ash |
OLD | NEW |