| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/arc_app_window_launcher_item_controller
.h" | 5 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller
.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/app_icon_loader.h" |
| 12 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 13 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 14 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 15 #include "chrome/browser/ui/ash/launcher/arc_app_window.h" |
| 14 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 16 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 16 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 18 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 17 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 18 #include "ui/base/base_window.h" | 20 #include "ui/base/base_window.h" |
| 19 | 21 |
| 20 ArcAppWindowLauncherItemController::ArcAppWindowLauncherItemController( | 22 ArcAppWindowLauncherItemController::ArcAppWindowLauncherItemController( |
| 21 const std::string& arc_app_id) | 23 const std::string& arc_app_id, |
| 22 : AppWindowLauncherItemController(ash::ShelfID(arc_app_id)) {} | 24 ChromeLauncherController* owner) |
| 25 : AppWindowLauncherItemController(ash::ShelfID(arc_app_id)), |
| 26 owner_(owner) {} |
| 23 | 27 |
| 24 ArcAppWindowLauncherItemController::~ArcAppWindowLauncherItemController() {} | 28 ArcAppWindowLauncherItemController::~ArcAppWindowLauncherItemController() {} |
| 25 | 29 |
| 26 void ArcAppWindowLauncherItemController::AddTaskId(int task_id) { | 30 void ArcAppWindowLauncherItemController::AddTaskId(int task_id) { |
| 27 task_ids_.insert(task_id); | 31 task_ids_.insert(task_id); |
| 28 } | 32 } |
| 29 | 33 |
| 30 void ArcAppWindowLauncherItemController::RemoveTaskId(int task_id) { | 34 void ArcAppWindowLauncherItemController::RemoveTaskId(int task_id) { |
| 31 task_ids_.erase(task_id); | 35 task_ids_.erase(task_id); |
| 32 } | 36 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 56 } | 60 } |
| 57 | 61 |
| 58 void ArcAppWindowLauncherItemController::ExecuteCommand(uint32_t command_id, | 62 void ArcAppWindowLauncherItemController::ExecuteCommand(uint32_t command_id, |
| 59 int32_t event_flags) { | 63 int32_t event_flags) { |
| 60 ActivateIndexedApp(command_id); | 64 ActivateIndexedApp(command_id); |
| 61 } | 65 } |
| 62 | 66 |
| 63 ash::MenuItemList ArcAppWindowLauncherItemController::GetAppMenuItems( | 67 ash::MenuItemList ArcAppWindowLauncherItemController::GetAppMenuItems( |
| 64 int event_flags) { | 68 int event_flags) { |
| 65 ash::MenuItemList items; | 69 ash::MenuItemList items; |
| 66 base::string16 app_title = LauncherControllerHelper::GetAppTitle( | 70 base::string16 app_title = |
| 67 ChromeLauncherController::instance()->profile(), app_id()); | 71 LauncherControllerHelper::GetAppTitle(owner_->profile(), app_id()); |
| 68 for (auto it = windows().begin(); it != windows().end(); ++it) { | 72 for (auto it = windows().begin(); it != windows().end(); ++it) { |
| 69 // TODO(khmel): resolve correct icon here. | 73 // TODO(khmel): resolve correct icon here. |
| 70 size_t i = std::distance(windows().begin(), it); | 74 size_t i = std::distance(windows().begin(), it); |
| 71 aura::Window* window = (*it)->GetNativeWindow(); | 75 aura::Window* window = (*it)->GetNativeWindow(); |
| 72 ash::mojom::MenuItemPtr item = ash::mojom::MenuItem::New(); | 76 ash::mojom::MenuItemPtr item = ash::mojom::MenuItem::New(); |
| 73 item->command_id = base::checked_cast<uint32_t>(i); | 77 item->command_id = base::checked_cast<uint32_t>(i); |
| 74 item->label = (window && !window->GetTitle().empty()) ? window->GetTitle() | 78 item->label = (window && !window->GetTitle().empty()) ? window->GetTitle() |
| 75 : app_title; | 79 : app_title; |
| 76 items.push_back(std::move(item)); | 80 items.push_back(std::move(item)); |
| 77 } | 81 } |
| 82 |
| 78 return items; | 83 return items; |
| 79 } | 84 } |
| 85 |
| 86 void ArcAppWindowLauncherItemController::UpdateLauncherItem() { |
| 87 const ArcAppWindow* arc_app_window = |
| 88 static_cast<const ArcAppWindow*>(GetLastActiveWindow()); |
| 89 if (!arc_app_window || arc_app_window->icon().isNull()) { |
| 90 if (!image_set_by_controller()) |
| 91 return; |
| 92 set_image_set_by_controller(false); |
| 93 owner_->SetLauncherItemImage(shelf_id(), gfx::ImageSkia()); |
| 94 AppIconLoader* icon_loader = owner_->GetAppIconLoaderForApp(app_id()); |
| 95 if (icon_loader) |
| 96 icon_loader->UpdateImage(app_id()); |
| 97 return; |
| 98 } |
| 99 |
| 100 owner_->SetLauncherItemImage(shelf_id(), arc_app_window->icon()); |
| 101 set_image_set_by_controller(true); |
| 102 } |
| OLD | NEW |