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

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

Issue 2462753002: Use Ash's ShelfWindowWatcher for app panel windows. (Closed)
Patch Set: Address comments. Created 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 SetVirtualKeyboardBehaviorFromPrefs(); 290 SetVirtualKeyboardBehaviorFromPrefs();
291 291
292 prefs_observer_ = 292 prefs_observer_ =
293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); 293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile());
294 } 294 }
295 295
296 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( 296 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem(
297 LauncherItemController* controller, 297 LauncherItemController* controller,
298 const std::string& app_id, 298 const std::string& app_id,
299 ash::ShelfItemStatus status) { 299 ash::ShelfItemStatus status) {
300 CHECK(controller); 300 return InsertAppLauncherItem(controller, app_id, status, model_->item_count(),
301 int index = 0;
302 // Panels are inserted on the left so as not to push all existing panels over.
303 if (controller->GetShelfItemType() != ash::TYPE_APP_PANEL)
304 index = model_->item_count();
305 return InsertAppLauncherItem(controller, app_id, status, index,
306 controller->GetShelfItemType()); 301 controller->GetShelfItemType());
307 } 302 }
308 303
309 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, 304 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id,
310 ash::ShelfItemStatus status) { 305 ash::ShelfItemStatus status) {
311 int index = model_->ItemIndexByID(id); 306 int index = model_->ItemIndexByID(id);
312 ash::ShelfItemStatus old_status = model_->items()[index].status; 307 ash::ShelfItemStatus old_status = model_->items()[index].status;
313 // Since ordinary browser windows are not registered, we might get a negative 308 // Since ordinary browser windows are not registered, we might get a negative
314 // index here. 309 // index here.
315 if (index >= 0 && old_status != status) { 310 if (index >= 0 && old_status != status) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 419
425 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { 420 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) {
426 ash::ShelfID id = GetShelfIDForAppID(app_id); 421 ash::ShelfID id = GetShelfIDForAppID(app_id);
427 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { 422 if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) {
428 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id), 423 CreateAppShortcutLauncherItemWithType(ash::launcher::AppLauncherId(app_id),
429 model_->item_count(), 424 model_->item_count(),
430 ash::TYPE_WINDOWED_APP); 425 ash::TYPE_WINDOWED_APP);
431 id = GetShelfIDForAppID(app_id); 426 id = GetShelfIDForAppID(app_id);
432 } 427 }
433 CHECK(id); 428 CHECK(id);
434 id_to_item_controller_map_[id]->lock(); 429 GetLauncherItemController(id)->lock();
435 } 430 }
436 431
437 void ChromeLauncherControllerImpl::UnlockV1AppWithID( 432 void ChromeLauncherControllerImpl::UnlockV1AppWithID(
438 const std::string& app_id) { 433 const std::string& app_id) {
439 ash::ShelfID id = GetShelfIDForAppID(app_id); 434 ash::ShelfID id = GetShelfIDForAppID(app_id);
440 CHECK(id); 435 CHECK(id);
441 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); 436 CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id));
442 LauncherItemController* controller = id_to_item_controller_map_[id]; 437 LauncherItemController* controller = GetLauncherItemController(id);
443 controller->unlock(); 438 controller->unlock();
444 if (!controller->locked() && !IsPinned(id)) 439 if (!controller->locked() && !IsPinned(id))
445 CloseLauncherItem(id); 440 CloseLauncherItem(id);
446 } 441 }
447 442
448 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { 443 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) {
449 LauncherItemController* controller = GetLauncherItemController(id); 444 LauncherItemController* controller = GetLauncherItemController(id);
450 if (!controller) 445 if (!controller)
451 return; // In case invoked from menu and item closed while menu up. 446 return; // In case invoked from menu and item closed while menu up.
452 controller->Launch(ash::LAUNCH_FROM_UNKNOWN, event_flags); 447 controller->Launch(ash::LAUNCH_FROM_UNKNOWN, event_flags);
453 } 448 }
454 449
455 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) { 450 void ChromeLauncherControllerImpl::Close(ash::ShelfID id) {
456 LauncherItemController* controller = GetLauncherItemController(id); 451 ash::ShelfItemDelegate* delegate = model_->GetShelfItemDelegate(id);
457 if (!controller) 452 if (!delegate)
458 return; // May happen if menu closed. 453 return; // May happen if menu closed.
459 controller->Close(); 454 delegate->Close();
460 } 455 }
461 456
462 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) { 457 bool ChromeLauncherControllerImpl::IsOpen(ash::ShelfID id) {
463 const int index = model_->ItemIndexByID(id); 458 const int index = model_->ItemIndexByID(id);
464 return index >= 0 && model_->items()[index].status != ash::STATUS_CLOSED; 459 return index >= 0 && model_->items()[index].status != ash::STATUS_CLOSED;
465 } 460 }
466 461
467 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { 462 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) {
468 if (!HasShelfIDToAppIDMapping(id)) 463 if (!HasShelfIDToAppIDMapping(id))
469 return false; 464 return false;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 return static_cast<BrowserShortcutLauncherItemController*>(i->second); 791 return static_cast<BrowserShortcutLauncherItemController*>(i->second);
797 } 792 }
798 NOTREACHED() 793 NOTREACHED()
799 << "There should be always be a BrowserShortcutLauncherItemController."; 794 << "There should be always be a BrowserShortcutLauncherItemController.";
800 return nullptr; 795 return nullptr;
801 } 796 }
802 797
803 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( 798 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController(
804 const ash::ShelfID id) { 799 const ash::ShelfID id) {
805 if (!HasShelfIDToAppIDMapping(id)) 800 if (!HasShelfIDToAppIDMapping(id))
806 return NULL; 801 return nullptr;
807 return id_to_item_controller_map_[id]; 802 return id_to_item_controller_map_[id];
808 } 803 }
809 804
810 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( 805 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser(
811 ash::WmShelf* shelf, 806 ash::WmShelf* shelf,
812 const AccountId& account_id) const { 807 const AccountId& account_id) const {
813 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); 808 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id);
814 if (!other_profile || other_profile == profile()) 809 if (!other_profile || other_profile == profile())
815 return false; 810 return false;
816 811
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 if (app_service) 894 if (app_service)
900 app_service->AddObserverAndStart(this); 895 app_service->AddObserverAndStart(this);
901 } 896 }
902 897
903 /////////////////////////////////////////////////////////////////////////////// 898 ///////////////////////////////////////////////////////////////////////////////
904 // ash::ShelfDelegate: 899 // ash::ShelfDelegate:
905 900
906 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( 901 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID(
907 const std::string& app_id) { 902 const std::string& app_id) {
908 // Get shelf id for app_id and empty launch_id. 903 // Get shelf id for app_id and empty launch_id.
909 return GetShelfIDForAppIDAndLaunchID(app_id, ""); 904 return GetShelfIDForAppIDAndLaunchID(app_id, std::string());
910 } 905 }
911 906
912 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID( 907 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID(
913 const std::string& app_id, 908 const std::string& app_id,
914 const std::string& launch_id) { 909 const std::string& launch_id) {
915 const std::string shelf_app_id = 910 const std::string shelf_app_id =
916 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 911 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
917 for (const auto& id_to_item_controller_pair : id_to_item_controller_map_) { 912 for (const auto& id_to_item_controller_pair : id_to_item_controller_map_) {
918 if (id_to_item_controller_pair.second->type() ==
919 LauncherItemController::TYPE_APP_PANEL)
920 continue; // Don't include panels
921 if (id_to_item_controller_pair.second->app_id() == shelf_app_id && 913 if (id_to_item_controller_pair.second->app_id() == shelf_app_id &&
922 id_to_item_controller_pair.second->launch_id() == launch_id) { 914 id_to_item_controller_pair.second->launch_id() == launch_id) {
923 return id_to_item_controller_pair.first; 915 return id_to_item_controller_pair.first;
924 } 916 }
925 } 917 }
926 return 0; 918 return ash::kInvalidShelfID;
927 } 919 }
928 920
929 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping( 921 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping(
930 ash::ShelfID id) const { 922 ash::ShelfID id) const {
931 return id_to_item_controller_map_.find(id) != 923 return id_to_item_controller_map_.find(id) !=
932 id_to_item_controller_map_.end(); 924 id_to_item_controller_map_.end();
933 } 925 }
934 926
935 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( 927 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID(
936 ash::ShelfID id) { 928 ash::ShelfID id) {
937 LauncherItemController* controller = GetLauncherItemController(id); 929 LauncherItemController* controller = GetLauncherItemController(id);
938 return controller ? controller->app_id() : base::EmptyString(); 930 if (controller)
931 return controller->app_id();
932 ash::ShelfItems::const_iterator item = model_->ItemByID(id);
933 return item != model_->items().end() ? item->app_id : base::EmptyString();
939 } 934 }
940 935
941 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { 936 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) {
942 const std::string shelf_app_id = 937 const std::string shelf_app_id =
943 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); 938 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id);
944 if (GetPinnableForAppID(shelf_app_id, profile()) == 939 if (GetPinnableForAppID(shelf_app_id, profile()) ==
945 AppListControllerDelegate::PIN_EDITABLE) 940 AppListControllerDelegate::PIN_EDITABLE)
946 DoPinAppWithID(shelf_app_id); 941 DoPinAppWithID(shelf_app_id);
947 else 942 else
948 NOTREACHED(); 943 NOTREACHED();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 /////////////////////////////////////////////////////////////////////////////// 1016 ///////////////////////////////////////////////////////////////////////////////
1022 // ChromeLauncherControllerImpl protected: 1017 // ChromeLauncherControllerImpl protected:
1023 1018
1024 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 1019 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
1025 const ash::launcher::AppLauncherId& app_launcher_id, 1020 const ash::launcher::AppLauncherId& app_launcher_id,
1026 int index) { 1021 int index) {
1027 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index, 1022 return CreateAppShortcutLauncherItemWithType(app_launcher_id, index,
1028 ash::TYPE_APP_SHORTCUT); 1023 ash::TYPE_APP_SHORTCUT);
1029 } 1024 }
1030 1025
1031 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest(
1032 ash::ShelfID id) {
1033 return id_to_item_controller_map_[id]->app_id();
1034 }
1035
1036 /////////////////////////////////////////////////////////////////////////////// 1026 ///////////////////////////////////////////////////////////////////////////////
1037 // ChromeLauncherControllerImpl private: 1027 // ChromeLauncherControllerImpl private:
1038 1028
1039 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { 1029 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() {
1040 RunningAppListIds list; 1030 RunningAppListIds list;
1041 for (int i = 0; i < model_->item_count(); i++) { 1031 for (int i = 0; i < model_->item_count(); i++) {
1042 ash::ShelfItemType type = model_->items()[i].type; 1032 ash::ShelfItemType type = model_->items()[i].type;
1043 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) 1033 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP)
1044 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); 1034 list.push_back(GetAppIDForShelfID(model_->items()[i].id));
1045 } 1035 }
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 1340
1351 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( 1341 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem(
1352 LauncherItemController* controller, 1342 LauncherItemController* controller,
1353 const std::string& app_id, 1343 const std::string& app_id,
1354 ash::ShelfItemStatus status, 1344 ash::ShelfItemStatus status,
1355 int index, 1345 int index,
1356 ash::ShelfItemType shelf_item_type) { 1346 ash::ShelfItemType shelf_item_type) {
1357 ash::ShelfID id = model_->next_id(); 1347 ash::ShelfID id = model_->next_id();
1358 CHECK(!HasShelfIDToAppIDMapping(id)); 1348 CHECK(!HasShelfIDToAppIDMapping(id));
1359 CHECK(controller); 1349 CHECK(controller);
1350 // Ash's ShelfWindowWatcher handles app panel windows separately.
1351 DCHECK_NE(ash::TYPE_APP_PANEL, controller->GetShelfItemType());
1360 id_to_item_controller_map_[id] = controller; 1352 id_to_item_controller_map_[id] = controller;
1361 controller->set_shelf_id(id); 1353 controller->set_shelf_id(id);
1362 1354
1363 ash::ShelfItem item; 1355 ash::ShelfItem item;
1364 item.type = shelf_item_type; 1356 item.type = shelf_item_type;
1365 item.image = extensions::util::GetDefaultAppIcon(); 1357 item.image = extensions::util::GetDefaultAppIcon();
1366 1358
1367 ash::ShelfItemStatus new_state = GetAppState(app_id); 1359 ash::ShelfItemStatus new_state = GetAppState(app_id);
1368 if (new_state != ash::STATUS_CLOSED) 1360 if (new_state != ash::STATUS_CLOSED)
1369 status = new_state; 1361 status = new_state;
1370 1362
1371 item.status = status; 1363 item.status = status;
1372
1373 model_->AddAt(index, item); 1364 model_->AddAt(index, item);
1374 1365
1375 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1366 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
1376 if (app_icon_loader) { 1367 if (app_icon_loader) {
1377 app_icon_loader->FetchImage(app_id); 1368 app_icon_loader->FetchImage(app_id);
1378 app_icon_loader->UpdateImage(app_id); 1369 app_icon_loader->UpdateImage(app_id);
1379 } 1370 }
1380 1371
1381 SetShelfItemDelegate(id, controller); 1372 SetShelfItemDelegate(id, controller);
1382 1373
1383 return id; 1374 return id;
1384 } 1375 }
1385 1376
1386 std::vector<content::WebContents*> 1377 std::vector<content::WebContents*>
1387 ChromeLauncherControllerImpl::GetV1ApplicationsFromController( 1378 ChromeLauncherControllerImpl::GetV1ApplicationsFromController(
1388 LauncherItemController* controller) { 1379 LauncherItemController* controller) {
1389 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); 1380 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT);
1390 AppShortcutLauncherItemController* app_controller = 1381 AppShortcutLauncherItemController* app_controller =
1391 static_cast<AppShortcutLauncherItemController*>(controller); 1382 static_cast<AppShortcutLauncherItemController*>(controller);
1392 return app_controller->GetRunningApplications(); 1383 return app_controller->GetRunningApplications();
1393 } 1384 }
1394 1385
1395 ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { 1386 void ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() {
1396 ash::ShelfItem browser_shortcut; 1387 ash::ShelfItem browser_shortcut;
1397 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1388 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1398 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1389 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1399 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1390 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1400 ash::ShelfID id = model_->next_id(); 1391 ash::ShelfID id = model_->next_id();
1401 model_->AddAt(0, browser_shortcut); 1392 model_->AddAt(0, browser_shortcut);
1402 id_to_item_controller_map_[id] = 1393 id_to_item_controller_map_[id] =
1403 new BrowserShortcutLauncherItemController(this, model_); 1394 new BrowserShortcutLauncherItemController(this, model_);
1404 id_to_item_controller_map_[id]->set_shelf_id(id); 1395 id_to_item_controller_map_[id]->set_shelf_id(id);
1405 // ShelfModel owns BrowserShortcutLauncherItemController. 1396 // ShelfModel owns BrowserShortcutLauncherItemController.
1406 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); 1397 SetShelfItemDelegate(id, id_to_item_controller_map_[id]);
1407 return id;
1408 } 1398 }
1409 1399
1410 bool ChromeLauncherControllerImpl::IsIncognito( 1400 bool ChromeLauncherControllerImpl::IsIncognito(
1411 const content::WebContents* web_contents) const { 1401 const content::WebContents* web_contents) const {
1412 const Profile* profile = 1402 const Profile* profile =
1413 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 1403 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1414 return profile->IsOffTheRecord() && !profile->IsGuestSession() && 1404 return profile->IsOffTheRecord() && !profile->IsGuestSession() &&
1415 !profile->IsSystemProfile(); 1405 !profile->IsSystemProfile();
1416 } 1406 }
1417 1407
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 1466
1477 app_list::AppListSyncableService* app_service = 1467 app_list::AppListSyncableService* app_service =
1478 app_list::AppListSyncableServiceFactory::GetForProfile(profile()); 1468 app_list::AppListSyncableServiceFactory::GetForProfile(profile());
1479 if (app_service) 1469 if (app_service)
1480 app_service->RemoveObserver(this); 1470 app_service->RemoveObserver(this);
1481 } 1471 }
1482 1472
1483 /////////////////////////////////////////////////////////////////////////////// 1473 ///////////////////////////////////////////////////////////////////////////////
1484 // ash::ShelfModelObserver: 1474 // ash::ShelfModelObserver:
1485 1475
1486 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { 1476 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) {}
1487 }
1488 1477
1489 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, 1478 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index,
1490 ash::ShelfID id) { 1479 ash::ShelfID id) {
1491 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we 1480 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we
1492 // get into this state in the first place. 1481 // get into this state in the first place.
1493 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1482 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1494 if (iter == id_to_item_controller_map_.end()) 1483 if (iter == id_to_item_controller_map_.end())
1495 return; 1484 return;
1496 1485
1497 LOG(ERROR) << "Unexpected change of shelf item id: " << id; 1486 LOG(ERROR) << "Unexpected removal of shelf item, id: " << id;
1498
1499 id_to_item_controller_map_.erase(iter); 1487 id_to_item_controller_map_.erase(iter);
1500 } 1488 }
1501 1489
1502 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index, 1490 void ChromeLauncherControllerImpl::ShelfItemMoved(int start_index,
1503 int target_index) { 1491 int target_index) {
1504 const ash::ShelfItem& item = model_->items()[target_index]; 1492 const ash::ShelfItem& item = model_->items()[target_index];
1505 // We remember the moved item position if it is either pinnable or 1493 // We remember the moved item position if it is either pinnable or
1506 // it is the app list with the alternate shelf layout. 1494 // it is the app list with the alternate shelf layout.
1507 DCHECK_NE(ash::TYPE_APP_LIST, item.type); 1495 DCHECK_NE(ash::TYPE_APP_LIST, item.type);
1508 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) 1496 if (HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id))
1509 SyncPinPosition(item.id); 1497 SyncPinPosition(item.id);
1510 } 1498 }
1511 1499
1512 void ChromeLauncherControllerImpl::ShelfItemChanged( 1500 void ChromeLauncherControllerImpl::ShelfItemChanged(
1513 int index, 1501 int index,
1514 const ash::ShelfItem& old_item) {} 1502 const ash::ShelfItem& old_item) {}
1515 1503
1516 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( 1504 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate(
1517 ash::ShelfID id, 1505 ash::ShelfID id,
1518 ash::ShelfItemDelegate* item_delegate) { 1506 ash::ShelfItemDelegate* item_delegate) {
1519 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we 1507 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we
1520 // get into this state in the first place. 1508 // get into this state in the first place.
1521 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1509 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1522 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) 1510 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second)
1523 return; 1511 return;
1524 LOG(ERROR) << "Unexpected change of shelf item id: " << id; 1512 LOG(ERROR) << "Unexpected change of shelf item delegate, id: " << id;
1525 id_to_item_controller_map_.erase(iter); 1513 id_to_item_controller_map_.erase(iter);
1526 } 1514 }
1527 1515
1528 /////////////////////////////////////////////////////////////////////////////// 1516 ///////////////////////////////////////////////////////////////////////////////
1529 // ash::WindowTreeHostManager::Observer: 1517 // ash::WindowTreeHostManager::Observer:
1530 1518
1531 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { 1519 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() {
1532 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs. 1520 // In BOTTOM_LOCKED state, ignore the call of SetShelfBehaviorsFromPrefs.
1533 // Because it might be called by some operations, like crbug.com/627040 1521 // Because it might be called by some operations, like crbug.com/627040
1534 // rotating screen. 1522 // rotating screen.
(...skipping 13 matching lines...) Expand all
1548 model_->set_status(ash::ShelfModel::STATUS_NORMAL); 1536 model_->set_status(ash::ShelfModel::STATUS_NORMAL);
1549 } 1537 }
1550 1538
1551 /////////////////////////////////////////////////////////////////////////////// 1539 ///////////////////////////////////////////////////////////////////////////////
1552 // AppIconLoaderDelegate: 1540 // AppIconLoaderDelegate:
1553 1541
1554 void ChromeLauncherControllerImpl::OnAppImageUpdated( 1542 void ChromeLauncherControllerImpl::OnAppImageUpdated(
1555 const std::string& id, 1543 const std::string& id,
1556 const gfx::ImageSkia& image) { 1544 const gfx::ImageSkia& image) {
1557 // TODO: need to get this working for shortcuts. 1545 // TODO: need to get this working for shortcuts.
1558 for (IDToItemControllerMap::const_iterator i = 1546 for (int index = 0; index < model_->item_count(); ++index) {
1559 id_to_item_controller_map_.begin(); 1547 ash::ShelfItem item = model_->items()[index];
1560 i != id_to_item_controller_map_.end(); ++i) { 1548 if (GetAppIDForShelfID(item.id) != id)
1561 LauncherItemController* controller = i->second;
1562 if (controller->app_id() != id)
1563 continue; 1549 continue;
1564 if (controller->image_set_by_controller()) 1550 LauncherItemController* controller = GetLauncherItemController(item.id);
1551 if (!controller || controller->image_set_by_controller())
1565 continue; 1552 continue;
1566 int index = model_->ItemIndexByID(i->first);
1567 if (index == -1)
1568 continue;
1569 ash::ShelfItem item = model_->items()[index];
1570 item.image = image; 1553 item.image = image;
1571 if (arc_deferred_launcher_) 1554 if (arc_deferred_launcher_)
1572 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); 1555 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image);
1573 model_->Set(index, item); 1556 model_->Set(index, item);
1574 // It's possible we're waiting on more than one item, so don't break. 1557 // It's possible we're waiting on more than one item, so don't break.
1575 } 1558 }
1576 } 1559 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698