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

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

Issue 2900783003: Handle app custom icon via aura::Window property. (Closed)
Patch Set: fix mac compile Created 3 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
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/extension_app_window_launcher_controlle r.h" 5 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_controlle r.h"
6 6
7 #include "ash/public/cpp/shelf_types.h" 7 #include "ash/public/cpp/shelf_types.h"
8 #include "ash/public/cpp/window_properties.h" 8 #include "ash/public/cpp/window_properties.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return; 68 return;
69 69
70 AppWindowRegistry* registry = AppWindowRegistry::Get(profile); 70 AppWindowRegistry* registry = AppWindowRegistry::Get(profile);
71 if (registry_.find(registry) != registry_.end()) 71 if (registry_.find(registry) != registry_.end())
72 return; 72 return;
73 73
74 registry->AddObserver(this); 74 registry->AddObserver(this);
75 registry_.insert(registry); 75 registry_.insert(registry);
76 } 76 }
77 77
78 void ExtensionAppWindowLauncherController::OnAppWindowIconChanged(
79 AppWindow* app_window) {
80 const ash::ShelfID shelf_id = GetShelfId(app_window);
81 AppControllerMap::iterator iter = app_controller_map_.find(shelf_id);
82 if (iter == app_controller_map_.end())
83 return;
84
85 // Check if the window actually overrides its default icon. Otherwise use app
86 // icon loader provided by owner.
87 if (!app_window->HasCustomIcon() || app_window->app_icon().IsEmpty())
88 return;
89
90 ExtensionAppWindowLauncherItemController* controller = iter->second;
91 controller->set_image_set_by_controller(true);
92 owner()->SetLauncherItemImage(controller->shelf_id(),
93 app_window->app_icon().AsImageSkia());
94 }
95
96 void ExtensionAppWindowLauncherController::OnAppWindowShown( 78 void ExtensionAppWindowLauncherController::OnAppWindowShown(
97 AppWindow* app_window, 79 AppWindow* app_window,
98 bool was_hidden) { 80 bool was_hidden) {
99 aura::Window* window = app_window->GetNativeWindow(); 81 aura::Window* window = app_window->GetNativeWindow();
100 if (!IsRegisteredApp(window)) 82 if (!IsRegisteredApp(window))
101 RegisterApp(app_window); 83 RegisterApp(app_window);
102 } 84 }
103 85
104 void ExtensionAppWindowLauncherController::OnAppWindowHidden( 86 void ExtensionAppWindowLauncherController::OnAppWindowHidden(
105 AppWindow* app_window) { 87 AppWindow* app_window) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 124
143 if (app_controller_iter != app_controller_map_.end()) { 125 if (app_controller_iter != app_controller_map_.end()) {
144 ExtensionAppWindowLauncherItemController* controller = 126 ExtensionAppWindowLauncherItemController* controller =
145 app_controller_iter->second; 127 app_controller_iter->second;
146 DCHECK_EQ(controller->app_id(), shelf_id.app_id); 128 DCHECK_EQ(controller->app_id(), shelf_id.app_id);
147 controller->AddAppWindow(app_window); 129 controller->AddAppWindow(app_window);
148 } else { 130 } else {
149 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = 131 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller =
150 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id); 132 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id);
151 app_controller_map_[shelf_id] = controller.get(); 133 app_controller_map_[shelf_id] = controller.get();
152 controller->AddAppWindow(app_window);
153 134
154 // Check for any existing pinned shelf item with a matching |shelf_id|. 135 // Check for any existing pinned shelf item with a matching |shelf_id|.
155 if (!owner()->GetItem(shelf_id)) { 136 if (!owner()->GetItem(shelf_id)) {
156 owner()->CreateAppLauncherItem(std::move(controller), status); 137 owner()->CreateAppLauncherItem(std::move(controller), status);
157 // Restore any existing app icon and flag as set.
158 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) {
159 owner()->SetLauncherItemImage(shelf_id,
160 app_window->app_icon().AsImageSkia());
161 app_controller_map_[shelf_id]->set_image_set_by_controller(true);
162 }
163 } else { 138 } else {
164 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, 139 owner()->shelf_model()->SetShelfItemDelegate(shelf_id,
165 std::move(controller)); 140 std::move(controller));
166 } 141 }
142
143 // Register the window after a shelf item is created to let the controller
144 // set the shelf icon property.
145 app_controller_map_[shelf_id]->AddAppWindow(app_window);
167 } 146 }
168 147
169 owner()->SetItemStatus(shelf_id, status); 148 owner()->SetItemStatus(shelf_id, status);
170 } 149 }
171 150
172 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { 151 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) {
173 const auto window_iter = window_to_shelf_id_map_.find(window); 152 const auto window_iter = window_to_shelf_id_map_.find(window);
174 DCHECK(window_iter != window_to_shelf_id_map_.end()); 153 DCHECK(window_iter != window_to_shelf_id_map_.end());
175 ash::ShelfID shelf_id = window_iter->second; 154 ash::ShelfID shelf_id = window_iter->second;
176 window_to_shelf_id_map_.erase(window_iter); 155 window_to_shelf_id_map_.erase(window_iter);
(...skipping 25 matching lines...) Expand all
202 ExtensionAppWindowLauncherController::ControllerForWindow( 181 ExtensionAppWindowLauncherController::ControllerForWindow(
203 aura::Window* window) { 182 aura::Window* window) {
204 const auto window_iter = window_to_shelf_id_map_.find(window); 183 const auto window_iter = window_to_shelf_id_map_.find(window);
205 if (window_iter == window_to_shelf_id_map_.end()) 184 if (window_iter == window_to_shelf_id_map_.end())
206 return nullptr; 185 return nullptr;
207 const auto controller_iter = app_controller_map_.find(window_iter->second); 186 const auto controller_iter = app_controller_map_.find(window_iter->second);
208 if (controller_iter == app_controller_map_.end()) 187 if (controller_iter == app_controller_map_.end())
209 return nullptr; 188 return nullptr;
210 return controller_iter->second; 189 return controller_iter->second;
211 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698