OLD | NEW |
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // Existing controller is destroyed and replaced by registering again. | 351 // Existing controller is destroyed and replaced by registering again. |
352 iter->second = controller; | 352 iter->second = controller; |
353 SetShelfItemDelegate(id, controller); | 353 SetShelfItemDelegate(id, controller); |
354 } else { | 354 } else { |
355 LauncherItemClosed(id); | 355 LauncherItemClosed(id); |
356 } | 356 } |
357 } | 357 } |
358 | 358 |
359 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) { | 359 void ChromeLauncherControllerImpl::UnpinShelfItemInternal(ash::ShelfID id) { |
360 const ash::ShelfItem* item = GetItem(id); | 360 const ash::ShelfItem* item = GetItem(id); |
361 LauncherItemController* controller = GetLauncherItemController(id); | 361 if (item && item->status != ash::STATUS_CLOSED) |
362 if (item && (item->status != ash::STATUS_CLOSED || controller->locked())) | |
363 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 362 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
364 else | 363 else |
365 LauncherItemClosed(id); | 364 LauncherItemClosed(id); |
366 } | 365 } |
367 | 366 |
368 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 367 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
369 const ash::ShelfItem* item = GetItem(id); | 368 const ash::ShelfItem* item = GetItem(id); |
370 return item && ItemTypeIsPinned(*item); | 369 return item && ItemTypeIsPinned(*item); |
371 } | 370 } |
372 | 371 |
373 void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { | 372 void ChromeLauncherControllerImpl::SetV1AppStatus(const std::string& app_id, |
| 373 ash::ShelfItemStatus status) { |
374 ash::ShelfID id = GetShelfIDForAppID(app_id); | 374 ash::ShelfID id = GetShelfIDForAppID(app_id); |
375 if (id == ash::kInvalidShelfID) { | 375 const ash::ShelfItem* item = GetItem(id); |
376 CreateAppShortcutLauncherItemWithType(ash::AppLaunchId(app_id), | 376 if (item) { |
377 model_->item_count(), ash::TYPE_APP); | 377 if (!IsPinned(id) && status == ash::STATUS_CLOSED) |
378 id = GetShelfIDForAppID(app_id); | 378 LauncherItemClosed(id); |
| 379 else |
| 380 SetItemStatus(id, status); |
| 381 } else if (status != ash::STATUS_CLOSED && !app_id.empty()) { |
| 382 InsertAppLauncherItem(AppShortcutLauncherItemController::Create( |
| 383 ash::AppLaunchId(app_id), this), |
| 384 status, model_->item_count(), ash::TYPE_APP); |
379 } | 385 } |
380 CHECK(id); | |
381 GetLauncherItemController(id)->lock(); | |
382 } | |
383 | |
384 void ChromeLauncherControllerImpl::UnlockV1AppWithID( | |
385 const std::string& app_id) { | |
386 ash::ShelfID id = GetShelfIDForAppID(app_id); | |
387 CHECK_NE(id, ash::kInvalidShelfID); | |
388 LauncherItemController* controller = GetLauncherItemController(id); | |
389 controller->unlock(); | |
390 if (!controller->locked() && !IsPinned(id)) | |
391 CloseLauncherItem(id); | |
392 } | 386 } |
393 | 387 |
394 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { | 388 void ChromeLauncherControllerImpl::Launch(ash::ShelfID id, int event_flags) { |
395 LauncherItemController* controller = GetLauncherItemController(id); | 389 LauncherItemController* controller = GetLauncherItemController(id); |
396 if (!controller) | 390 if (!controller) |
397 return; // In case invoked from menu and item closed while menu up. | 391 return; // In case invoked from menu and item closed while menu up. |
398 | 392 |
399 // Launching some items replaces the associated item controller instance, | 393 // Launching some items replaces the associated item controller instance, |
400 // which destroys the app and launch id strings; making copies avoid crashes. | 394 // which destroys the app and launch id strings; making copies avoid crashes. |
401 LaunchApp(ash::AppLaunchId(controller->app_id(), controller->launch_id()), | 395 LaunchApp(ash::AppLaunchId(controller->app_id(), controller->launch_id()), |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 if (ash::Shell::HasInstance()) | 933 if (ash::Shell::HasInstance()) |
940 SetVirtualKeyboardBehaviorFromPrefs(); | 934 SetVirtualKeyboardBehaviorFromPrefs(); |
941 | 935 |
942 prefs_observer_ = | 936 prefs_observer_ = |
943 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); | 937 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); |
944 } | 938 } |
945 | 939 |
946 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( | 940 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( |
947 const ash::AppLaunchId& app_launch_id, | 941 const ash::AppLaunchId& app_launch_id, |
948 int index) { | 942 int index) { |
949 return CreateAppShortcutLauncherItemWithType(app_launch_id, index, | 943 AppShortcutLauncherItemController* controller = |
950 ash::TYPE_PINNED_APP); | 944 AppShortcutLauncherItemController::Create(app_launch_id, this); |
| 945 return InsertAppLauncherItem(controller, ash::STATUS_CLOSED, index, |
| 946 ash::TYPE_PINNED_APP); |
951 } | 947 } |
952 | 948 |
953 /////////////////////////////////////////////////////////////////////////////// | 949 /////////////////////////////////////////////////////////////////////////////// |
954 // ChromeLauncherControllerImpl private: | 950 // ChromeLauncherControllerImpl private: |
955 | 951 |
956 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { | 952 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { |
957 RunningAppListIds list; | 953 RunningAppListIds list; |
958 for (int i = 0; i < model_->item_count(); i++) { | 954 for (int i = 0; i < model_->item_count(); i++) { |
959 if (model_->items()[i].type == ash::TYPE_APP) | 955 if (model_->items()[i].type == ash::TYPE_APP) |
960 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); | 956 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); |
(...skipping 17 matching lines...) Expand all Loading... |
978 if (item && item->type == ash::TYPE_APP) { | 974 if (item && item->type == ash::TYPE_APP) { |
979 int app_index = model_->ItemIndexByID(item->id); | 975 int app_index = model_->ItemIndexByID(item->id); |
980 DCHECK_GE(app_index, 0); | 976 DCHECK_GE(app_index, 0); |
981 if (running_index != app_index) | 977 if (running_index != app_index) |
982 model_->Move(running_index, app_index); | 978 model_->Move(running_index, app_index); |
983 running_index++; | 979 running_index++; |
984 } | 980 } |
985 } | 981 } |
986 } | 982 } |
987 | 983 |
988 ash::ShelfID | |
989 ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( | |
990 const ash::AppLaunchId& app_launch_id, | |
991 int index, | |
992 ash::ShelfItemType shelf_item_type) { | |
993 AppShortcutLauncherItemController* controller = | |
994 AppShortcutLauncherItemController::Create(app_launch_id, this); | |
995 return InsertAppLauncherItem(controller, ash::STATUS_CLOSED, index, | |
996 shelf_item_type); | |
997 } | |
998 | |
999 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { | 984 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { |
1000 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 985 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
1001 CHECK(iter != id_to_item_controller_map_.end()); | 986 CHECK(iter != id_to_item_controller_map_.end()); |
1002 CHECK(iter->second); | 987 CHECK(iter->second); |
1003 const std::string& app_id = iter->second->app_id(); | 988 const std::string& app_id = iter->second->app_id(); |
1004 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 989 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
1005 if (app_icon_loader) | 990 if (app_icon_loader) |
1006 app_icon_loader->ClearImage(app_id); | 991 app_icon_loader->ClearImage(app_id); |
1007 id_to_item_controller_map_.erase(iter); | 992 id_to_item_controller_map_.erase(iter); |
1008 int index = model_->ItemIndexByID(id); | 993 int index = model_->ItemIndexByID(id); |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 LauncherItemController* controller = GetLauncherItemController(item.id); | 1459 LauncherItemController* controller = GetLauncherItemController(item.id); |
1475 if (!controller || controller->image_set_by_controller()) | 1460 if (!controller || controller->image_set_by_controller()) |
1476 continue; | 1461 continue; |
1477 item.image = image; | 1462 item.image = image; |
1478 if (arc_deferred_launcher_) | 1463 if (arc_deferred_launcher_) |
1479 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1464 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
1480 model_->Set(index, item); | 1465 model_->Set(index, item); |
1481 // It's possible we're waiting on more than one item, so don't break. | 1466 // It's possible we're waiting on more than one item, so don't break. |
1482 } | 1467 } |
1483 } | 1468 } |
OLD | NEW |