OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 // static | 43 // static |
44 WindowStateManager* g_window_state_manager = NULL; | 44 WindowStateManager* g_window_state_manager = NULL; |
45 | 45 |
46 // WindowStateManager remembers which windows have been minimized in order to | 46 // WindowStateManager remembers which windows have been minimized in order to |
47 // restore them when the wallpaper viewer is hidden. | 47 // restore them when the wallpaper viewer is hidden. |
48 class WindowStateManager : public aura::WindowObserver { | 48 class WindowStateManager : public aura::WindowObserver { |
49 public: | 49 public: |
50 | 50 |
51 // Minimizes all windows except the active window. | 51 // Minimizes all windows except the active window. |
52 static void MinimizeInactiveWindows() { | 52 static void MinimizeInactiveWindows() { |
53 if (g_window_state_manager) | 53 std::vector<aura::Window*> previous_minimized_windows; |
54 if (g_window_state_manager) { | |
55 previous_minimized_windows = g_window_state_manager->windows(); | |
54 delete g_window_state_manager; | 56 delete g_window_state_manager; |
flackr
2012/11/13 16:18:30
Instead of deleting the previous window state mana
bshe
2012/11/13 19:33:22
Reverted the change and will address them in a fol
| |
57 } | |
55 g_window_state_manager = new WindowStateManager(); | 58 g_window_state_manager = new WindowStateManager(); |
56 g_window_state_manager->BuildWindowListAndMinimizeInactive( | 59 g_window_state_manager->BuildWindowListAndMinimizeInactive( |
57 ash::wm::GetActiveWindow()); | 60 ash::wm::GetActiveWindow()); |
61 g_window_state_manager->AppendWindows(previous_minimized_windows); | |
flackr
2012/11/13 16:18:30
This new behavior should be tested in wallpaper_pr
bshe
2012/11/13 19:33:22
Reverted the change and will address them in a fol
| |
58 } | 62 } |
59 | 63 |
60 // Activates all minimized windows restoring them to their previous state. | 64 // Activates all minimized windows restoring them to their previous state. |
61 // This should only be called after calling MinimizeInactiveWindows. | 65 // This should only be called after calling MinimizeInactiveWindows. |
62 static void RestoreWindows() { | 66 static void RestoreWindows() { |
63 DCHECK(g_window_state_manager); | 67 DCHECK(g_window_state_manager); |
64 g_window_state_manager->RestoreMinimizedWindows(); | 68 g_window_state_manager->RestoreMinimizedWindows(); |
65 delete g_window_state_manager; | 69 delete g_window_state_manager; |
66 g_window_state_manager = NULL; | 70 g_window_state_manager = NULL; |
67 } | 71 } |
68 | 72 |
69 private: | 73 private: |
70 WindowStateManager() {} | 74 WindowStateManager() {} |
71 | 75 |
72 ~WindowStateManager() { | 76 ~WindowStateManager() { |
73 for (std::vector<aura::Window*>::iterator iter = windows_.begin(); | 77 for (std::vector<aura::Window*>::iterator iter = windows_.begin(); |
74 iter != windows_.end(); ++iter) { | 78 iter != windows_.end(); ++iter) { |
75 (*iter)->RemoveObserver(this); | 79 (*iter)->RemoveObserver(this); |
76 } | 80 } |
77 } | 81 } |
78 | 82 |
83 std::vector<aura::Window*> windows() const { | |
84 return windows_; | |
85 } | |
86 | |
87 // Appends |windows| to the minimized windows list. This should only be | |
88 // called after BuildWindowListAndMinimizeInactive. | |
89 void AppendWindows(std::vector<aura::Window*> windows) { | |
90 for (std::vector<aura::Window*>::iterator iter = windows.begin(); | |
91 iter != windows.end(); ++iter) { | |
92 // Do not add duplicated window. | |
93 if(std::find(windows_.begin(), windows_.end(), *iter) == windows_.end()) | |
94 windows_.push_back(*iter); | |
95 } | |
96 } | |
97 | |
79 void BuildWindowListAndMinimizeInactive(aura::Window* active_window) { | 98 void BuildWindowListAndMinimizeInactive(aura::Window* active_window) { |
80 windows_ = ash::WindowCycleController::BuildWindowList(NULL); | 99 windows_ = ash::WindowCycleController::BuildWindowList(NULL); |
81 // Remove active window. | 100 // Remove active window. |
82 std::vector<aura::Window*>::iterator last = | 101 std::vector<aura::Window*>::iterator last = |
83 std::remove(windows_.begin(), windows_.end(), active_window); | 102 std::remove(windows_.begin(), windows_.end(), active_window); |
84 // Removes unfocusable windows. | 103 // Removes unfocusable windows. |
85 last = | 104 last = |
86 std::remove_if( | 105 std::remove_if( |
87 windows_.begin(), | 106 windows_.begin(), |
88 last, | 107 last, |
89 std::ptr_fun(ash::wm::IsWindowMinimized)); | 108 std::ptr_fun(ash::wm::IsWindowMinimized)); |
90 windows_.erase(last, windows_.end()); | 109 windows_.erase(last, windows_.end()); |
91 | 110 |
92 for (std::vector<aura::Window*>::iterator iter = windows_.begin(); | 111 for (std::vector<aura::Window*>::iterator iter = windows_.begin(); |
93 iter != windows_.end(); ++iter) { | 112 iter != windows_.end(); ++iter) { |
94 (*iter)->AddObserver(this); | 113 (*iter)->AddObserver(this); |
95 ash::wm::MinimizeWindow(*iter); | 114 ash::wm::MinimizeWindow(*iter); |
96 } | 115 } |
97 } | 116 } |
98 | 117 |
99 void RestoreMinimizedWindows() { | 118 void RestoreMinimizedWindows() { |
100 for (std::vector<aura::Window*>::iterator iter = windows_.begin(); | 119 // The topmost window is at the front of the list. |
flackr
2012/11/13 16:18:30
If you minimize all the windows and then minimize
bshe
2012/11/13 19:33:22
Reverted the change and will address them in a fol
| |
101 iter != windows_.end(); ++iter) { | 120 for (std::vector<aura::Window*>::reverse_iterator iter = windows_.rbegin(); |
121 iter != windows_.rend(); ++iter) { | |
102 ash::wm::ActivateWindow(*iter); | 122 ash::wm::ActivateWindow(*iter); |
103 } | 123 } |
104 } | 124 } |
105 | 125 |
106 // aura::WindowObserver overrides. | 126 // aura::WindowObserver overrides. |
107 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { | 127 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { |
108 window->RemoveObserver(this); | 128 window->RemoveObserver(this); |
109 std::vector<aura::Window*>::iterator i = std::find(windows_.begin(), | 129 std::vector<aura::Window*>::iterator i = std::find(windows_.begin(), |
110 windows_.end(), window); | 130 windows_.end(), window); |
111 DCHECK(i != windows_.end()); | 131 DCHECK(i != windows_.end()); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 } | 406 } |
387 | 407 |
388 WallpaperRestoreMinimizedWindowsFunction:: | 408 WallpaperRestoreMinimizedWindowsFunction:: |
389 ~WallpaperRestoreMinimizedWindowsFunction() { | 409 ~WallpaperRestoreMinimizedWindowsFunction() { |
390 } | 410 } |
391 | 411 |
392 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() { | 412 bool WallpaperRestoreMinimizedWindowsFunction::RunImpl() { |
393 WindowStateManager::RestoreWindows(); | 413 WindowStateManager::RestoreWindows(); |
394 return true; | 414 return true; |
395 } | 415 } |
OLD | NEW |