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

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

Issue 2883193002: WIP
Patch Set: git cl try Created 3 years, 7 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
OLDNEW
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
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::OnWindowChanged(
87 ArcAppWindow* arc_app_window) {
88 DCHECK(arc_app_window && arc_app_window->controller() == this);
89 if (GetLastActiveWindow() == arc_app_window)
90 UpdateIcon(arc_app_window);
91 }
92
93 void ArcAppWindowLauncherItemController::UpdateIcon(
94 ArcAppWindow* arc_app_window) {
95 if (!arc_app_window || arc_app_window->image_skia().isNull()) {
96 if (image_set_by_controller()) {
97 set_image_set_by_controller(false);
98 owner_->SetLauncherItemImage(shelf_id(), gfx::ImageSkia());
99 AppIconLoader* icon_loader = owner_->GetAppIconLoaderForApp(app_id());
100 if (icon_loader)
101 icon_loader->UpdateImage(app_id());
102 }
103 } else {
104 owner_->SetLauncherItemImage(shelf_id(), arc_app_window->image_skia());
105 set_image_set_by_controller(true);
106 }
107 }
108
109 void ArcAppWindowLauncherItemController::OnActiveWindowChanged(
110 ui::BaseWindow* active_window) {
111 UpdateIcon(static_cast<ArcAppWindow*>(active_window));
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698