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/ui/ash/launcher/shell_window_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_number_conversions.h" |
| 13 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
15 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
16 #include "chrome/browser/ui/extensions/shell_window.h" | 18 #include "chrome/browser/ui/extensions/shell_window.h" |
17 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
18 #include "ui/aura/client/activation_client.h" | 20 #include "ui/aura/client/activation_client.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 // Currently apps have a single launcher item, so the launcher id is the | |
23 // same as the app id. In the future, this may not be true (e.g. for panels). | |
24 std::string GetAppLauncherId(ShellWindow* shell_window) { | 24 std::string GetAppLauncherId(ShellWindow* shell_window) { |
| 25 if (shell_window->window_type() == ShellWindow::WINDOW_TYPE_PANEL) |
| 26 return StringPrintf("panel:%d", shell_window->session_id().id()); |
25 return shell_window->extension()->id(); | 27 return shell_window->extension()->id(); |
26 } | 28 } |
27 | 29 |
28 bool AppLauncherIdIsForApp(const std::string& app_launcher_id, | |
29 const std::string& app_id) { | |
30 return app_launcher_id == app_id; | |
31 } | |
32 | |
33 // Functor for std::find_if used in AppLauncherItemController. | 30 // Functor for std::find_if used in AppLauncherItemController. |
34 class ShellWindowHasWindow { | 31 class ShellWindowHasWindow { |
35 public: | 32 public: |
36 explicit ShellWindowHasWindow(aura::Window* window) : window_(window) { } | 33 explicit ShellWindowHasWindow(aura::Window* window) : window_(window) { } |
37 | 34 |
38 bool operator()(ShellWindow* shell_window) const { | 35 bool operator()(ShellWindow* shell_window) const { |
39 return shell_window->GetNativeWindow() == window_; | 36 return shell_window->GetNativeWindow() == window_; |
40 } | 37 } |
41 | 38 |
42 private: | 39 private: |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 virtual bool IsOpen() const OVERRIDE { | 104 virtual bool IsOpen() const OVERRIDE { |
108 return !shell_windows_.empty(); | 105 return !shell_windows_.empty(); |
109 } | 106 } |
110 | 107 |
111 virtual void Launch(int event_flags) OVERRIDE { | 108 virtual void Launch(int event_flags) OVERRIDE { |
112 launcher_controller()->LaunchApp(app_id(), ui::EF_NONE); | 109 launcher_controller()->LaunchApp(app_id(), ui::EF_NONE); |
113 } | 110 } |
114 | 111 |
115 virtual void Activate() OVERRIDE { | 112 virtual void Activate() OVERRIDE { |
116 DCHECK(!shell_windows_.empty()); | 113 DCHECK(!shell_windows_.empty()); |
117 ShowAndActivate(shell_windows_.front()); | 114 shell_windows_.front()->GetBaseWindow()->Activate(); |
118 } | 115 } |
119 | 116 |
120 virtual void Close() OVERRIDE { | 117 virtual void Close() OVERRIDE { |
121 // Note: Closing windows may affect the contents of shell_windows_. | 118 // Note: Closing windows may affect the contents of shell_windows_. |
122 ShellWindowList windows_to_close = shell_windows_; | 119 ShellWindowList windows_to_close = shell_windows_; |
123 for (ShellWindowList::iterator iter = windows_to_close.begin(); | 120 for (ShellWindowList::iterator iter = windows_to_close.begin(); |
124 iter != windows_to_close.end(); ++iter) { | 121 iter != windows_to_close.end(); ++iter) { |
125 (*iter)->GetBaseWindow()->Close(); | 122 (*iter)->GetBaseWindow()->Close(); |
126 } | 123 } |
127 } | 124 } |
128 | 125 |
129 // Behavior for app windows: | 126 // Behavior for app windows: |
130 // * One window: Toggle minimization when clicked. | 127 // * One window: Toggle minimization when clicked. |
131 // * Multiple windows: | 128 // * Multiple windows: |
132 // ** If the first window is not active, activate it. | 129 // ** If the first window is not active, activate it. |
133 // ** Otherwise activate the next window. | 130 // ** Otherwise activate the next window. |
134 virtual void Clicked() OVERRIDE { | 131 virtual void Clicked() OVERRIDE { |
135 if (shell_windows_.empty()) | 132 if (shell_windows_.empty()) |
136 return; | 133 return; |
137 ShellWindow* first_window = shell_windows_.front(); | 134 ShellWindow* first_window = shell_windows_.front(); |
138 if (shell_windows_.size() == 1) { | 135 if (shell_windows_.size() == 1) { |
139 if (first_window->GetBaseWindow()->IsActive()) | 136 if (first_window->GetBaseWindow()->IsActive()) |
140 first_window->GetBaseWindow()->Minimize(); | 137 first_window->GetBaseWindow()->Minimize(); |
141 else | 138 else |
142 ShowAndActivate(first_window); | 139 RestoreOrShow(first_window); |
143 } else { | 140 } else { |
144 if (!first_window->GetBaseWindow()->IsActive()) { | 141 if (!first_window->GetBaseWindow()->IsActive()) { |
145 ShowAndActivate(first_window); | 142 RestoreOrShow(first_window); |
146 } else { | 143 } else { |
147 shell_windows_.pop_front(); | 144 shell_windows_.pop_front(); |
148 shell_windows_.push_back(first_window); | 145 shell_windows_.push_back(first_window); |
149 ShowAndActivate(shell_windows_.front()); | 146 RestoreOrShow(shell_windows_.front()); |
150 } | 147 } |
151 } | 148 } |
152 } | 149 } |
153 | 150 |
154 virtual void OnRemoved() OVERRIDE { | 151 virtual void OnRemoved() OVERRIDE { |
155 } | 152 } |
156 | 153 |
157 virtual void LauncherItemChanged(int model_index, | 154 virtual void LauncherItemChanged(int model_index, |
158 const ash::LauncherItem& old_item) OVERRIDE { | 155 const ash::LauncherItem& old_item) OVERRIDE { |
159 } | 156 } |
160 | 157 |
161 size_t shell_window_count() const { return shell_windows_.size(); } | 158 size_t shell_window_count() const { return shell_windows_.size(); } |
162 | 159 |
163 private: | 160 private: |
164 typedef std::list<ShellWindow*> ShellWindowList; | 161 typedef std::list<ShellWindow*> ShellWindowList; |
165 | 162 |
166 void ShowAndActivate(ShellWindow* shell_window) { | 163 void RestoreOrShow(ShellWindow* shell_window) { |
167 shell_window->GetBaseWindow()->Show(); | 164 if (shell_window->GetBaseWindow()->IsMinimized()) |
| 165 shell_window->GetBaseWindow()->Restore(); |
| 166 else |
| 167 shell_window->GetBaseWindow()->Show(); |
| 168 // Always activate windows when shown from the launcher. |
168 shell_window->GetBaseWindow()->Activate(); | 169 shell_window->GetBaseWindow()->Activate(); |
169 } | 170 } |
170 | 171 |
171 // List of associated shell windows in activation order. | 172 // List of associated shell windows in activation order. |
172 ShellWindowList shell_windows_; | 173 ShellWindowList shell_windows_; |
173 | 174 |
174 // The launcher id associated with this set of windows. There is one | 175 // The launcher id associated with this set of windows. There is one |
175 // AppLauncherItemController for each |app_launcher_id_|. | 176 // AppLauncherItemController for each |app_launcher_id_|. |
176 const std::string app_launcher_id_; | 177 const std::string app_launcher_id_; |
177 | 178 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 WindowToAppLauncherIdMap::iterator iter1 = | 305 WindowToAppLauncherIdMap::iterator iter1 = |
305 window_to_app_launcher_id_map_.find(window); | 306 window_to_app_launcher_id_map_.find(window); |
306 if (iter1 == window_to_app_launcher_id_map_.end()) | 307 if (iter1 == window_to_app_launcher_id_map_.end()) |
307 return NULL; | 308 return NULL; |
308 std::string app_launcher_id = iter1->second; | 309 std::string app_launcher_id = iter1->second; |
309 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); | 310 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); |
310 if (iter2 == app_controller_map_.end()) | 311 if (iter2 == app_controller_map_.end()) |
311 return NULL; | 312 return NULL; |
312 return iter2->second; | 313 return iter2->second; |
313 } | 314 } |
OLD | NEW |