Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: chrome/browser/ui/ash/launcher/shell_window_launcher_controller.cc

Issue 11363250: Allow Chrome apps to create Ash Panels (apps v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback and add unit test for PanelLayoutManager minimize/restore Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 16 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
16 #include "chrome/browser/ui/extensions/shell_window.h" 17 #include "chrome/browser/ui/extensions/shell_window.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
18 #include "ui/aura/client/activation_client.h" 19 #include "ui/aura/client/activation_client.h"
19 20
20 namespace { 21 namespace {
21 22
22 // Currently apps have a single launcher item, so the launcher id is the 23 // 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 // same as the app id. In the future, this may not be true (e.g. for panels).
24 std::string GetAppLauncherId(ShellWindow* shell_window) { 25 std::string GetAppLauncherId(ShellWindow* shell_window) {
26 if (shell_window->window_type() == ShellWindow::WINDOW_TYPE_PANEL)
27 return base::IntToString(shell_window->session_id().id());
25 return shell_window->extension()->id(); 28 return shell_window->extension()->id();
26 } 29 }
27 30
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. 31 // Functor for std::find_if used in AppLauncherItemController.
34 class ShellWindowHasWindow { 32 class ShellWindowHasWindow {
35 public: 33 public:
36 explicit ShellWindowHasWindow(aura::Window* window) : window_(window) { } 34 explicit ShellWindowHasWindow(aura::Window* window) : window_(window) { }
37 35
38 bool operator()(ShellWindow* shell_window) const { 36 bool operator()(ShellWindow* shell_window) const {
39 return shell_window->GetNativeWindow() == window_; 37 return shell_window->GetNativeWindow() == window_;
40 } 38 }
41 39
42 private: 40 private:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 virtual bool IsOpen() const OVERRIDE { 105 virtual bool IsOpen() const OVERRIDE {
108 return !shell_windows_.empty(); 106 return !shell_windows_.empty();
109 } 107 }
110 108
111 virtual void Launch(int event_flags) OVERRIDE { 109 virtual void Launch(int event_flags) OVERRIDE {
112 launcher_controller()->LaunchApp(app_id(), ui::EF_NONE); 110 launcher_controller()->LaunchApp(app_id(), ui::EF_NONE);
113 } 111 }
114 112
115 virtual void Activate() OVERRIDE { 113 virtual void Activate() OVERRIDE {
116 DCHECK(!shell_windows_.empty()); 114 DCHECK(!shell_windows_.empty());
117 ShowAndActivate(shell_windows_.front()); 115 shell_windows_.front()->GetBaseWindow()->Activate();
118 } 116 }
119 117
120 virtual void Close() OVERRIDE { 118 virtual void Close() OVERRIDE {
121 // Note: Closing windows may affect the contents of shell_windows_. 119 // Note: Closing windows may affect the contents of shell_windows_.
122 ShellWindowList windows_to_close = shell_windows_; 120 ShellWindowList windows_to_close = shell_windows_;
123 for (ShellWindowList::iterator iter = windows_to_close.begin(); 121 for (ShellWindowList::iterator iter = windows_to_close.begin();
124 iter != windows_to_close.end(); ++iter) { 122 iter != windows_to_close.end(); ++iter) {
125 (*iter)->GetBaseWindow()->Close(); 123 (*iter)->GetBaseWindow()->Close();
126 } 124 }
127 } 125 }
128 126
129 // Behavior for app windows: 127 // Behavior for app windows:
130 // * One window: Toggle minimization when clicked. 128 // * One window: Toggle minimization when clicked.
131 // * Multiple windows: 129 // * Multiple windows:
132 // ** If the first window is not active, activate it. 130 // ** If the first window is not active, activate it.
133 // ** Otherwise activate the next window. 131 // ** Otherwise activate the next window.
134 virtual void Clicked() OVERRIDE { 132 virtual void Clicked() OVERRIDE {
135 if (shell_windows_.empty()) 133 if (shell_windows_.empty())
136 return; 134 return;
137 ShellWindow* first_window = shell_windows_.front(); 135 ShellWindow* first_window = shell_windows_.front();
138 if (shell_windows_.size() == 1) { 136 if (shell_windows_.size() == 1) {
139 if (first_window->GetBaseWindow()->IsActive()) 137 if (first_window->GetBaseWindow()->IsActive())
140 first_window->GetBaseWindow()->Minimize(); 138 first_window->GetBaseWindow()->Minimize();
141 else 139 else
142 ShowAndActivate(first_window); 140 RestoreOrShow(first_window);
143 } else { 141 } else {
144 if (!first_window->GetBaseWindow()->IsActive()) { 142 if (!first_window->GetBaseWindow()->IsActive()) {
145 ShowAndActivate(first_window); 143 RestoreOrShow(first_window);
146 } else { 144 } else {
147 shell_windows_.pop_front(); 145 shell_windows_.pop_front();
148 shell_windows_.push_back(first_window); 146 shell_windows_.push_back(first_window);
149 ShowAndActivate(shell_windows_.front()); 147 RestoreOrShow(shell_windows_.front());
150 } 148 }
151 } 149 }
152 } 150 }
153 151
154 virtual void OnRemoved() OVERRIDE { 152 virtual void OnRemoved() OVERRIDE {
155 } 153 }
156 154
157 virtual void LauncherItemChanged(int model_index, 155 virtual void LauncherItemChanged(int model_index,
158 const ash::LauncherItem& old_item) OVERRIDE { 156 const ash::LauncherItem& old_item) OVERRIDE {
159 } 157 }
160 158
161 size_t shell_window_count() const { return shell_windows_.size(); } 159 size_t shell_window_count() const { return shell_windows_.size(); }
162 160
163 private: 161 private:
164 typedef std::list<ShellWindow*> ShellWindowList; 162 typedef std::list<ShellWindow*> ShellWindowList;
165 163
166 void ShowAndActivate(ShellWindow* shell_window) { 164 void RestoreOrShow(ShellWindow* shell_window) {
167 shell_window->GetBaseWindow()->Show(); 165 if (shell_window->GetBaseWindow()->IsMinimized()) {
166 shell_window->GetBaseWindow()->Restore();
167 } else {
168 shell_window->GetBaseWindow()->Show();
169 }
170 // Always activate windows when shown from the launcher.
168 shell_window->GetBaseWindow()->Activate(); 171 shell_window->GetBaseWindow()->Activate();
169 } 172 }
170 173
171 // List of associated shell windows in activation order. 174 // List of associated shell windows in activation order.
172 ShellWindowList shell_windows_; 175 ShellWindowList shell_windows_;
173 176
174 // The launcher id associated with this set of windows. There is one 177 // The launcher id associated with this set of windows. There is one
175 // AppLauncherItemController for each |app_launcher_id_|. 178 // AppLauncherItemController for each |app_launcher_id_|.
176 const std::string app_launcher_id_; 179 const std::string app_launcher_id_;
177 180
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 WindowToAppLauncherIdMap::iterator iter1 = 307 WindowToAppLauncherIdMap::iterator iter1 =
305 window_to_app_launcher_id_map_.find(window); 308 window_to_app_launcher_id_map_.find(window);
306 if (iter1 == window_to_app_launcher_id_map_.end()) 309 if (iter1 == window_to_app_launcher_id_map_.end())
307 return NULL; 310 return NULL;
308 std::string app_launcher_id = iter1->second; 311 std::string app_launcher_id = iter1->second;
309 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id); 312 AppControllerMap::iterator iter2 = app_controller_map_.find(app_launcher_id);
310 if (iter2 == app_controller_map_.end()) 313 if (iter2 == app_controller_map_.end())
311 return NULL; 314 return NULL;
312 return iter2->second; 315 return iter2->second;
313 } 316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698