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

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

Issue 166903006: Move *ShellWindowLauncher* to *AppWindowLauncher* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months 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_item_controller.h " 5 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
6 6
7 #include "apps/app_window.h" 7 #include "apps/app_window.h"
8 #include "apps/ui/native_app_window.h" 8 #include "apps/ui/native_app_window.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/wm/window_state.h" 10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" 15 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 bool operator()(AppWindow* app_window) const { 58 bool operator()(AppWindow* app_window) const {
59 return app_window->GetNativeWindow() == window_; 59 return app_window->GetNativeWindow() == window_;
60 } 60 }
61 61
62 private: 62 private:
63 const aura::Window* window_; 63 const aura::Window* window_;
64 }; 64 };
65 65
66 } // namespace 66 } // namespace
67 67
68 ShellWindowLauncherItemController::ShellWindowLauncherItemController( 68 AppWindowLauncherItemController::AppWindowLauncherItemController(
69 Type type, 69 Type type,
70 const std::string& app_shelf_id, 70 const std::string& app_shelf_id,
71 const std::string& app_id, 71 const std::string& app_id,
72 ChromeLauncherController* controller) 72 ChromeLauncherController* controller)
73 : LauncherItemController(type, app_id, controller), 73 : LauncherItemController(type, app_id, controller),
74 last_active_app_window_(NULL), 74 last_active_app_window_(NULL),
75 app_shelf_id_(app_shelf_id), 75 app_shelf_id_(app_shelf_id),
76 observed_windows_(this) {} 76 observed_windows_(this) {}
77 77
78 ShellWindowLauncherItemController::~ShellWindowLauncherItemController() { 78 AppWindowLauncherItemController::~AppWindowLauncherItemController() {}
79 }
80 79
81 void ShellWindowLauncherItemController::AddAppWindow( 80 void AppWindowLauncherItemController::AddAppWindow(
82 AppWindow* app_window, 81 AppWindow* app_window,
83 ash::ShelfItemStatus status) { 82 ash::ShelfItemStatus status) {
84 if (app_window->window_type_is_panel() && type() != TYPE_APP_PANEL) 83 if (app_window->window_type_is_panel() && type() != TYPE_APP_PANEL)
85 LOG(ERROR) << "AppWindow of type Panel added to non-panel launcher item"; 84 LOG(ERROR) << "AppWindow of type Panel added to non-panel launcher item";
86 app_windows_.push_front(app_window); 85 app_windows_.push_front(app_window);
87 observed_windows_.Add(app_window->GetNativeWindow()); 86 observed_windows_.Add(app_window->GetNativeWindow());
88 } 87 }
89 88
90 void ShellWindowLauncherItemController::RemoveShellWindowForWindow( 89 void AppWindowLauncherItemController::RemoveAppWindowForWindow(
91 aura::Window* window) { 90 aura::Window* window) {
92 AppWindowList::iterator iter = std::find_if( 91 AppWindowList::iterator iter = std::find_if(
93 app_windows_.begin(), app_windows_.end(), AppWindowHasWindow(window)); 92 app_windows_.begin(), app_windows_.end(), AppWindowHasWindow(window));
94 if (iter != app_windows_.end()) { 93 if (iter != app_windows_.end()) {
95 if (*iter == last_active_app_window_) 94 if (*iter == last_active_app_window_)
96 last_active_app_window_ = NULL; 95 last_active_app_window_ = NULL;
97 app_windows_.erase(iter); 96 app_windows_.erase(iter);
98 } 97 }
99 observed_windows_.Remove(window); 98 observed_windows_.Remove(window);
100 } 99 }
101 100
102 void ShellWindowLauncherItemController::SetActiveWindow(aura::Window* window) { 101 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) {
103 AppWindowList::iterator iter = std::find_if( 102 AppWindowList::iterator iter = std::find_if(
104 app_windows_.begin(), app_windows_.end(), AppWindowHasWindow(window)); 103 app_windows_.begin(), app_windows_.end(), AppWindowHasWindow(window));
105 if (iter != app_windows_.end()) 104 if (iter != app_windows_.end())
106 last_active_app_window_ = *iter; 105 last_active_app_window_ = *iter;
107 } 106 }
108 107
109 bool ShellWindowLauncherItemController::IsOpen() const { 108 bool AppWindowLauncherItemController::IsOpen() const {
110 return !app_windows_.empty(); 109 return !app_windows_.empty();
111 } 110 }
112 111
113 bool ShellWindowLauncherItemController::IsVisible() const { 112 bool AppWindowLauncherItemController::IsVisible() const {
114 // Return true if any windows are visible. 113 // Return true if any windows are visible.
115 for (AppWindowList::const_iterator iter = app_windows_.begin(); 114 for (AppWindowList::const_iterator iter = app_windows_.begin();
116 iter != app_windows_.end(); 115 iter != app_windows_.end();
117 ++iter) { 116 ++iter) {
118 if ((*iter)->GetNativeWindow()->IsVisible()) 117 if ((*iter)->GetNativeWindow()->IsVisible())
119 return true; 118 return true;
120 } 119 }
121 return false; 120 return false;
122 } 121 }
123 122
124 void ShellWindowLauncherItemController::Launch(ash::LaunchSource source, 123 void AppWindowLauncherItemController::Launch(ash::LaunchSource source,
125 int event_flags) { 124 int event_flags) {
126 launcher_controller()->LaunchApp(app_id(), 125 launcher_controller()->LaunchApp(app_id(), source, ui::EF_NONE);
127 source,
128 ui::EF_NONE);
129 } 126 }
130 127
131 bool ShellWindowLauncherItemController::Activate(ash::LaunchSource source) { 128 bool AppWindowLauncherItemController::Activate(ash::LaunchSource source) {
132 DCHECK(!app_windows_.empty()); 129 DCHECK(!app_windows_.empty());
133 AppWindow* window_to_activate = 130 AppWindow* window_to_activate =
134 last_active_app_window_ ? last_active_app_window_ : app_windows_.back(); 131 last_active_app_window_ ? last_active_app_window_ : app_windows_.back();
135 window_to_activate->GetBaseWindow()->Activate(); 132 window_to_activate->GetBaseWindow()->Activate();
136 return false; 133 return false;
137 } 134 }
138 135
139 void ShellWindowLauncherItemController::Close() { 136 void AppWindowLauncherItemController::Close() {
140 // Note: Closing windows may affect the contents of app_windows_. 137 // Note: Closing windows may affect the contents of app_windows_.
141 AppWindowList windows_to_close = app_windows_; 138 AppWindowList windows_to_close = app_windows_;
142 for (AppWindowList::iterator iter = windows_to_close.begin(); 139 for (AppWindowList::iterator iter = windows_to_close.begin();
143 iter != windows_to_close.end(); 140 iter != windows_to_close.end();
144 ++iter) { 141 ++iter) {
145 (*iter)->GetBaseWindow()->Close(); 142 (*iter)->GetBaseWindow()->Close();
146 } 143 }
147 } 144 }
148 145
149 void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) { 146 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) {
150 if (index >= app_windows_.size()) 147 if (index >= app_windows_.size())
151 return; 148 return;
152 AppWindowList::iterator it = app_windows_.begin(); 149 AppWindowList::iterator it = app_windows_.begin();
153 std::advance(it, index); 150 std::advance(it, index);
154 ShowAndActivateOrMinimize(*it); 151 ShowAndActivateOrMinimize(*it);
155 } 152 }
156 153
157 ChromeLauncherAppMenuItems 154 ChromeLauncherAppMenuItems AppWindowLauncherItemController::GetApplicationList(
158 ShellWindowLauncherItemController::GetApplicationList(int event_flags) { 155 int event_flags) {
159 ChromeLauncherAppMenuItems items; 156 ChromeLauncherAppMenuItems items;
160 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); 157 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false));
161 int index = 0; 158 int index = 0;
162 for (AppWindowList::iterator iter = app_windows_.begin(); 159 for (AppWindowList::iterator iter = app_windows_.begin();
163 iter != app_windows_.end(); 160 iter != app_windows_.end();
164 ++iter) { 161 ++iter) {
165 AppWindow* app_window = *iter; 162 AppWindow* app_window = *iter;
166 scoped_ptr<gfx::Image> image(GetAppListIcon(app_window)); 163 scoped_ptr<gfx::Image> image(GetAppListIcon(app_window));
167 items.push_back(new ChromeLauncherAppMenuItemV2App( 164 items.push_back(new ChromeLauncherAppMenuItemV2App(
168 app_window->GetTitle(), 165 app_window->GetTitle(),
169 image.get(), // Will be copied 166 image.get(), // Will be copied
170 app_id(), 167 app_id(),
171 launcher_controller(), 168 launcher_controller(),
172 index, 169 index,
173 index == 0 /* has_leading_separator */)); 170 index == 0 /* has_leading_separator */));
174 ++index; 171 ++index;
175 } 172 }
176 return items.Pass(); 173 return items.Pass();
177 } 174 }
178 175
179 bool ShellWindowLauncherItemController::ItemSelected(const ui::Event& event) { 176 bool AppWindowLauncherItemController::ItemSelected(const ui::Event& event) {
180 if (app_windows_.empty()) 177 if (app_windows_.empty())
181 return false; 178 return false;
182 if (type() == TYPE_APP_PANEL) { 179 if (type() == TYPE_APP_PANEL) {
183 DCHECK(app_windows_.size() == 1); 180 DCHECK(app_windows_.size() == 1);
184 AppWindow* panel = app_windows_.front(); 181 AppWindow* panel = app_windows_.front();
185 aura::Window* panel_window = panel->GetNativeWindow(); 182 aura::Window* panel_window = panel->GetNativeWindow();
186 // If the panel is attached on another display, move it to the current 183 // If the panel is attached on another display, move it to the current
187 // display and activate it. 184 // display and activate it.
188 if (ash::wm::GetWindowState(panel_window)->panel_attached() && 185 if (ash::wm::GetWindowState(panel_window)->panel_attached() &&
189 ash::wm::MoveWindowToEventRoot(panel_window, event)) { 186 ash::wm::MoveWindowToEventRoot(panel_window, event)) {
190 if (!panel->GetBaseWindow()->IsActive()) 187 if (!panel->GetBaseWindow()->IsActive())
191 ShowAndActivateOrMinimize(panel); 188 ShowAndActivateOrMinimize(panel);
192 } else { 189 } else {
193 ShowAndActivateOrMinimize(panel); 190 ShowAndActivateOrMinimize(panel);
194 } 191 }
195 } else { 192 } else {
196 AppWindow* window_to_show = last_active_app_window_ 193 AppWindow* window_to_show = last_active_app_window_
197 ? last_active_app_window_ 194 ? last_active_app_window_
198 : app_windows_.front(); 195 : app_windows_.front();
199 // If the event was triggered by a keystroke, we try to advance to the next 196 // If the event was triggered by a keystroke, we try to advance to the next
200 // item if the window we are trying to activate is already active. 197 // item if the window we are trying to activate is already active.
201 if (app_windows_.size() >= 1 && 198 if (app_windows_.size() >= 1 &&
202 window_to_show->GetBaseWindow()->IsActive() && 199 window_to_show->GetBaseWindow()->IsActive() &&
203 event.type() == ui::ET_KEY_RELEASED) { 200 event.type() == ui::ET_KEY_RELEASED) {
204 ActivateOrAdvanceToNextShellWindow(window_to_show); 201 ActivateOrAdvanceToNextAppWindow(window_to_show);
205 } else { 202 } else {
206 ShowAndActivateOrMinimize(window_to_show); 203 ShowAndActivateOrMinimize(window_to_show);
207 } 204 }
208 } 205 }
209 return false; 206 return false;
210 } 207 }
211 208
212 base::string16 ShellWindowLauncherItemController::GetTitle() { 209 base::string16 AppWindowLauncherItemController::GetTitle() {
213 // For panels return the title of the contents if set. 210 // For panels return the title of the contents if set.
214 // Otherwise return the title of the app. 211 // Otherwise return the title of the app.
215 if (type() == TYPE_APP_PANEL && !app_windows_.empty()) { 212 if (type() == TYPE_APP_PANEL && !app_windows_.empty()) {
216 AppWindow* app_window = app_windows_.front(); 213 AppWindow* app_window = app_windows_.front();
217 if (app_window->web_contents()) { 214 if (app_window->web_contents()) {
218 base::string16 title = app_window->web_contents()->GetTitle(); 215 base::string16 title = app_window->web_contents()->GetTitle();
219 if (!title.empty()) 216 if (!title.empty())
220 return title; 217 return title;
221 } 218 }
222 } 219 }
223 return GetAppTitle(); 220 return GetAppTitle();
224 } 221 }
225 222
226 ui::MenuModel* ShellWindowLauncherItemController::CreateContextMenu( 223 ui::MenuModel* AppWindowLauncherItemController::CreateContextMenu(
227 aura::Window* root_window) { 224 aura::Window* root_window) {
228 ash::ShelfItem item = 225 ash::ShelfItem item = *(launcher_controller()->model()->ItemByID(shelf_id()));
229 *(launcher_controller()->model()->ItemByID(shelf_id()));
230 return new LauncherContextMenu(launcher_controller(), &item, root_window); 226 return new LauncherContextMenu(launcher_controller(), &item, root_window);
231 } 227 }
232 228
233 ash::ShelfMenuModel* ShellWindowLauncherItemController::CreateApplicationMenu( 229 ash::ShelfMenuModel* AppWindowLauncherItemController::CreateApplicationMenu(
234 int event_flags) { 230 int event_flags) {
235 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); 231 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags));
236 } 232 }
237 233
238 bool ShellWindowLauncherItemController::IsDraggable() { 234 bool AppWindowLauncherItemController::IsDraggable() {
239 if (type() == TYPE_APP_PANEL) 235 if (type() == TYPE_APP_PANEL)
240 return true; 236 return true;
241 return launcher_controller()->CanPin() ? true : false; 237 return launcher_controller()->CanPin() ? true : false;
242 } 238 }
243 239
244 bool ShellWindowLauncherItemController::ShouldShowTooltip() { 240 bool AppWindowLauncherItemController::ShouldShowTooltip() {
245 if (type() == TYPE_APP_PANEL && IsVisible()) 241 if (type() == TYPE_APP_PANEL && IsVisible())
246 return false; 242 return false;
247 return true; 243 return true;
248 } 244 }
249 245
250 void ShellWindowLauncherItemController::OnWindowPropertyChanged( 246 void AppWindowLauncherItemController::OnWindowPropertyChanged(
251 aura::Window* window, 247 aura::Window* window,
252 const void* key, 248 const void* key,
253 intptr_t old) { 249 intptr_t old) {
254 if (key == aura::client::kDrawAttentionKey) { 250 if (key == aura::client::kDrawAttentionKey) {
255 ash::ShelfItemStatus status; 251 ash::ShelfItemStatus status;
256 if (ash::wm::IsActiveWindow(window)) { 252 if (ash::wm::IsActiveWindow(window)) {
257 status = ash::STATUS_ACTIVE; 253 status = ash::STATUS_ACTIVE;
258 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { 254 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) {
259 status = ash::STATUS_ATTENTION; 255 status = ash::STATUS_ATTENTION;
260 } else { 256 } else {
261 status = ash::STATUS_RUNNING; 257 status = ash::STATUS_RUNNING;
262 } 258 }
263 launcher_controller()->SetItemStatus(shelf_id(), status); 259 launcher_controller()->SetItemStatus(shelf_id(), status);
264 } 260 }
265 } 261 }
266 262
267 void ShellWindowLauncherItemController::ShowAndActivateOrMinimize( 263 void AppWindowLauncherItemController::ShowAndActivateOrMinimize(
268 AppWindow* app_window) { 264 AppWindow* app_window) {
269 // Either show or minimize windows when shown from the launcher. 265 // Either show or minimize windows when shown from the launcher.
270 launcher_controller()->ActivateWindowOrMinimizeIfActive( 266 launcher_controller()->ActivateWindowOrMinimizeIfActive(
271 app_window->GetBaseWindow(), GetApplicationList(0).size() == 2); 267 app_window->GetBaseWindow(), GetApplicationList(0).size() == 2);
272 } 268 }
273 269
274 void ShellWindowLauncherItemController::ActivateOrAdvanceToNextShellWindow( 270 void AppWindowLauncherItemController::ActivateOrAdvanceToNextAppWindow(
275 AppWindow* window_to_show) { 271 AppWindow* window_to_show) {
276 AppWindowList::iterator i( 272 AppWindowList::iterator i(
277 std::find(app_windows_.begin(), app_windows_.end(), window_to_show)); 273 std::find(app_windows_.begin(), app_windows_.end(), window_to_show));
278 if (i != app_windows_.end()) { 274 if (i != app_windows_.end()) {
279 if (++i != app_windows_.end()) 275 if (++i != app_windows_.end())
280 window_to_show = *i; 276 window_to_show = *i;
281 else 277 else
282 window_to_show = app_windows_.front(); 278 window_to_show = app_windows_.front();
283 } 279 }
284 if (window_to_show->GetBaseWindow()->IsActive()) { 280 if (window_to_show->GetBaseWindow()->IsActive()) {
285 // Coming here, only a single window is active. For keyboard activations 281 // Coming here, only a single window is active. For keyboard activations
286 // the window gets animated. 282 // the window gets animated.
287 AnimateWindow(window_to_show->GetNativeWindow(), 283 AnimateWindow(window_to_show->GetNativeWindow(),
288 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); 284 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE);
289 } else { 285 } else {
290 ShowAndActivateOrMinimize(window_to_show); 286 ShowAndActivateOrMinimize(window_to_show);
291 } 287 }
292 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698