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

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

Issue 10541109: Implement active window list for platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup Created 8 years, 6 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/views/ash/launcher/chrome_launcher_controller.h" 5 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/launcher/launcher_model.h" 10 #include "ash/launcher/launcher_model.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (controller) { 225 if (controller) {
226 controller->window()->Show(); 226 controller->window()->Show();
227 ash::wm::ActivateWindow(controller->window()); 227 ash::wm::ActivateWindow(controller->window());
228 } else { 228 } else {
229 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type); 229 DCHECK_EQ(TYPE_APP, id_to_item_map_[id].item_type);
230 230
231 // Do nothing for pending app shortcut. 231 // Do nothing for pending app shortcut.
232 if (GetItemStatus(id) == ash::STATUS_IS_PENDING) 232 if (GetItemStatus(id) == ash::STATUS_IS_PENDING)
233 return; 233 return;
234 234
235 // Check if this item has any windows in the activation list.
236 for (WindowList::const_iterator i = activation_order_.begin();
237 i != activation_order_.end(); ++i) {
sky 2012/06/12 04:32:11 nit: indent one more space.
238 if (window_to_id_map_[*i] == id) {
239 ash::wm::ActivateWindow(*i);
240 return;
241 }
242 }
243
235 const Extension* extension = 244 const Extension* extension =
236 profile_->GetExtensionService()->GetInstalledExtension( 245 profile_->GetExtensionService()->GetInstalledExtension(
237 id_to_item_map_[id].app_id); 246 id_to_item_map_[id].app_id);
238 extension_utils::OpenExtension(profile_, extension, event_flags); 247 extension_utils::OpenExtension(profile_, extension, event_flags);
239 } 248 }
240 } 249 }
241 250
242 void ChromeLauncherController::Close(ash::LauncherID id) { 251 void ChromeLauncherController::Close(ash::LauncherID id) {
243 if (id_to_item_map_.find(id) == id_to_item_map_.end()) 252 if (id_to_item_map_.find(id) == id_to_item_map_.end())
244 return; // May happen if menu closed. 253 return; // May happen if menu closed.
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 } 513 }
505 break; 514 break;
506 } 515 }
507 default: 516 default:
508 NOTREACHED() << "Unexpected notification type=" << type; 517 NOTREACHED() << "Unexpected notification type=" << type;
509 } 518 }
510 } 519 }
511 520
512 void ChromeLauncherController::OnShellWindowAdded(ShellWindow* shell_window) { 521 void ChromeLauncherController::OnShellWindowAdded(ShellWindow* shell_window) {
513 aura::Window* window = shell_window->GetNativeWindow(); 522 aura::Window* window = shell_window->GetNativeWindow();
514 ash::LauncherItemStatus status = 523 ash::LauncherItemStatus status = ash::wm::IsActiveWindow(window) ?
515 ash::wm::IsActiveWindow(window) ? 524 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
516 ash::STATUS_ACTIVE : ash::STATUS_RUNNING;
517 window->AddObserver(this); 525 window->AddObserver(this);
518 const std::string app_id = shell_window->extension()->id(); 526 const std::string app_id = shell_window->extension()->id();
527 ash::LauncherID id = 0;
519 for (IDToItemMap::const_iterator i = id_to_item_map_.begin(); 528 for (IDToItemMap::const_iterator i = id_to_item_map_.begin();
520 i != id_to_item_map_.end(); ++i) { 529 i != id_to_item_map_.end(); ++i) {
521 if (i->second.app_id == app_id) { 530 if (i->second.app_id == app_id) {
522 window_to_id_map_[window] = i->first; 531 id = i->first;
523 SetItemStatus(i->first, status); 532 SetItemStatus(id, status);
524 return; 533 break;
525 } 534 }
526 } 535 }
527 ash::LauncherID id = CreateAppLauncherItem(NULL, app_id, status); 536 if (id == 0)
537 id = CreateAppLauncherItem(NULL, app_id, status);
528 window_to_id_map_[window] = id; 538 window_to_id_map_[window] = id;
539 if (status == ash::STATUS_ACTIVE)
540 activation_order_.push_front(window);
541 else
542 activation_order_.push_back(window);
529 } 543 }
530 544
531 void ChromeLauncherController::OnShellWindowRemoved(ShellWindow* shell_window) { 545 void ChromeLauncherController::OnShellWindowRemoved(ShellWindow* shell_window) {
532 // Window removal is handled in OnWindowRemovingFromRootWindow() below. 546 // Window removal is handled in OnWindowRemovingFromRootWindow() below.
533 } 547 }
534 548
535 void ChromeLauncherController::OnWindowActivated(aura::Window* active, 549 void ChromeLauncherController::OnWindowActivated(aura::Window* active,
536 aura::Window* old_active) { 550 aura::Window* old_active) {
537 if (window_to_id_map_.find(old_active) != window_to_id_map_.end()) { 551 if (window_to_id_map_.find(active) != window_to_id_map_.end()) {
538 if (window_to_id_map_.find(active) != window_to_id_map_.end() && 552 ash::LauncherID active_id = window_to_id_map_[active];
539 window_to_id_map_[old_active] == window_to_id_map_[active]) { 553 activation_order_.remove(active);
554 activation_order_.push_front(active);
555 if (window_to_id_map_.find(old_active) != window_to_id_map_.end() &&
556 window_to_id_map_[old_active] == active_id) {
540 // Old and new windows are for the same item. Don't change the status. 557 // Old and new windows are for the same item. Don't change the status.
541 return; 558 return;
542 } 559 }
560 SetItemStatus(active_id, ash::STATUS_ACTIVE);
561 }
562 if (window_to_id_map_.find(old_active) != window_to_id_map_.end())
543 SetItemStatus(window_to_id_map_[old_active], ash::STATUS_RUNNING); 563 SetItemStatus(window_to_id_map_[old_active], ash::STATUS_RUNNING);
544 }
545 if (window_to_id_map_.find(active) != window_to_id_map_.end())
546 SetItemStatus(window_to_id_map_[active], ash::STATUS_ACTIVE);
547 } 564 }
548 565
549 void ChromeLauncherController::OnWindowRemovingFromRootWindow( 566 void ChromeLauncherController::OnWindowRemovingFromRootWindow(
550 aura::Window* window) { 567 aura::Window* window) {
551 window->RemoveObserver(this); 568 window->RemoveObserver(this);
552 DCHECK(window_to_id_map_.find(window) != window_to_id_map_.end()); 569 DCHECK(window_to_id_map_.find(window) != window_to_id_map_.end());
553 ash::LauncherID id = window_to_id_map_[window]; 570 ash::LauncherID id = window_to_id_map_[window];
554 window_to_id_map_.erase(window); 571 window_to_id_map_.erase(window);
555 572
556 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end()); 573 DCHECK(id_to_item_map_.find(id) != id_to_item_map_.end());
574 activation_order_.remove(window);
557 ShellWindowRegistry::ShellWindowSet remaining_windows = 575 ShellWindowRegistry::ShellWindowSet remaining_windows =
558 ShellWindowRegistry::Get(profile_)->GetShellWindowsForApp( 576 ShellWindowRegistry::Get(profile_)->GetShellWindowsForApp(
559 id_to_item_map_[id].app_id); 577 id_to_item_map_[id].app_id);
560 578
561 // We can't count on getting called before or after the ShellWindowRegistry. 579 // We can't count on getting called before or after the ShellWindowRegistry.
562 if (remaining_windows.size() > 1 || 580 if (remaining_windows.size() > 1 ||
563 (remaining_windows.size() == 1 && 581 (remaining_windows.size() == 1 &&
564 (*remaining_windows.begin())->GetNativeWindow() != window)) { 582 (*remaining_windows.begin())->GetNativeWindow() != window)) {
565 return; 583 return;
566 } 584 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 } 788 }
771 model_->AddAt(index, item); 789 model_->AddAt(index, item);
772 790
773 if (!controller || controller->type() != 791 if (!controller || controller->type() !=
774 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) { 792 BrowserLauncherItemController::TYPE_EXTENSION_PANEL) {
775 if (item.status != ash::STATUS_IS_PENDING) 793 if (item.status != ash::STATUS_IS_PENDING)
776 app_icon_loader_->FetchImage(app_id); 794 app_icon_loader_->FetchImage(app_id);
777 } 795 }
778 return id; 796 return id;
779 } 797 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698