Chromium Code Reviews| 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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 AppWindowRegistry* registry = AppWindowRegistry::Get(profile); | 71 AppWindowRegistry* registry = AppWindowRegistry::Get(profile); |
| 72 if (registry_.find(registry) != registry_.end()) | 72 if (registry_.find(registry) != registry_.end()) |
| 73 return; | 73 return; |
| 74 | 74 |
| 75 registry->AddObserver(this); | 75 registry->AddObserver(this); |
| 76 registry_.insert(registry); | 76 registry_.insert(registry); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void ExtensionAppWindowLauncherController::OnAppWindowIconChanged( | |
| 80 AppWindow* app_window) { | |
| 81 const ash::ShelfID shelf_id = GetShelfId(app_window); | |
| 82 AppControllerMap::iterator iter = app_controller_map_.find(shelf_id); | |
| 83 if (iter == app_controller_map_.end()) | |
| 84 return; | |
| 85 | |
| 86 // Check if the window actually overrides its default icon. Otherwise use app | |
| 87 // icon loader provided by owner. | |
| 88 if (!app_window->HasCustomIcon() || app_window->app_icon().IsEmpty()) | |
| 89 return; | |
| 90 | |
| 91 ExtensionAppWindowLauncherItemController* controller = iter->second; | |
| 92 controller->set_image_set_by_controller(true); | |
| 93 owner()->SetLauncherItemImage(controller->shelf_id(), | |
| 94 app_window->app_icon().AsImageSkia()); | |
| 95 } | |
| 96 | |
| 97 void ExtensionAppWindowLauncherController::OnAppWindowShown( | 79 void ExtensionAppWindowLauncherController::OnAppWindowShown( |
| 98 AppWindow* app_window, | 80 AppWindow* app_window, |
| 99 bool was_hidden) { | 81 bool was_hidden) { |
| 100 aura::Window* window = app_window->GetNativeWindow(); | 82 aura::Window* window = app_window->GetNativeWindow(); |
| 101 if (!IsRegisteredApp(window)) | 83 if (!IsRegisteredApp(window)) |
| 102 RegisterApp(app_window); | 84 RegisterApp(app_window); |
| 103 } | 85 } |
| 104 | 86 |
| 105 void ExtensionAppWindowLauncherController::OnAppWindowHidden( | 87 void ExtensionAppWindowLauncherController::OnAppWindowHidden( |
| 106 AppWindow* app_window) { | 88 AppWindow* app_window) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 | 125 |
| 144 if (app_controller_iter != app_controller_map_.end()) { | 126 if (app_controller_iter != app_controller_map_.end()) { |
| 145 ExtensionAppWindowLauncherItemController* controller = | 127 ExtensionAppWindowLauncherItemController* controller = |
| 146 app_controller_iter->second; | 128 app_controller_iter->second; |
| 147 DCHECK_EQ(controller->app_id(), shelf_id.app_id); | 129 DCHECK_EQ(controller->app_id(), shelf_id.app_id); |
| 148 controller->AddAppWindow(app_window); | 130 controller->AddAppWindow(app_window); |
| 149 } else { | 131 } else { |
| 150 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = | 132 std::unique_ptr<ExtensionAppWindowLauncherItemController> controller = |
| 151 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id); | 133 base::MakeUnique<ExtensionAppWindowLauncherItemController>(shelf_id); |
| 152 app_controller_map_[shelf_id] = controller.get(); | 134 app_controller_map_[shelf_id] = controller.get(); |
| 153 controller->AddAppWindow(app_window); | |
| 154 | 135 |
| 155 // Check for any existing pinned shelf item with a matching |shelf_id|. | 136 // Check for any existing pinned shelf item with a matching |shelf_id|. |
| 156 if (!owner()->GetItem(shelf_id)) { | 137 if (!owner()->GetItem(shelf_id)) { |
| 157 owner()->CreateAppLauncherItem(std::move(controller), status); | 138 owner()->CreateAppLauncherItem(std::move(controller), status); |
| 158 // Restore any existing app icon and flag as set. | |
| 159 if (app_window->HasCustomIcon() && !app_window->app_icon().IsEmpty()) { | |
| 160 owner()->SetLauncherItemImage(shelf_id, | |
| 161 app_window->app_icon().AsImageSkia()); | |
| 162 app_controller_map_[shelf_id]->set_image_set_by_controller(true); | |
| 163 } | |
| 164 } else { | 139 } else { |
| 165 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, | 140 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, |
| 166 std::move(controller)); | 141 std::move(controller)); |
| 167 } | 142 } |
| 143 | |
| 144 // Register the window after a shelf item is created to let controller set | |
|
msw
2017/06/01 23:48:30
nit: "let the controller"
khmel
2017/06/02 01:52:35
Done.
| |
| 145 // the shelf item properly. | |
|
msw
2017/06/01 23:48:30
nit: did you mean "set the shelf icon property"? o
khmel
2017/06/02 01:52:35
icon property sounds better, thanks!
| |
| 146 app_controller_map_[shelf_id]->AddAppWindow(app_window); | |
| 168 } | 147 } |
| 169 | 148 |
| 170 owner()->SetItemStatus(shelf_id, status); | 149 owner()->SetItemStatus(shelf_id, status); |
| 171 } | 150 } |
| 172 | 151 |
| 173 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { | 152 void ExtensionAppWindowLauncherController::UnregisterApp(aura::Window* window) { |
| 174 const auto window_iter = window_to_shelf_id_map_.find(window); | 153 const auto window_iter = window_to_shelf_id_map_.find(window); |
| 175 DCHECK(window_iter != window_to_shelf_id_map_.end()); | 154 DCHECK(window_iter != window_to_shelf_id_map_.end()); |
| 176 ash::ShelfID shelf_id = window_iter->second; | 155 ash::ShelfID shelf_id = window_iter->second; |
| 177 window_to_shelf_id_map_.erase(window_iter); | 156 window_to_shelf_id_map_.erase(window_iter); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 203 ExtensionAppWindowLauncherController::ControllerForWindow( | 182 ExtensionAppWindowLauncherController::ControllerForWindow( |
| 204 aura::Window* window) { | 183 aura::Window* window) { |
| 205 const auto window_iter = window_to_shelf_id_map_.find(window); | 184 const auto window_iter = window_to_shelf_id_map_.find(window); |
| 206 if (window_iter == window_to_shelf_id_map_.end()) | 185 if (window_iter == window_to_shelf_id_map_.end()) |
| 207 return nullptr; | 186 return nullptr; |
| 208 const auto controller_iter = app_controller_map_.find(window_iter->second); | 187 const auto controller_iter = app_controller_map_.find(window_iter->second); |
| 209 if (controller_iter == app_controller_map_.end()) | 188 if (controller_iter == app_controller_map_.end()) |
| 210 return nullptr; | 189 return nullptr; |
| 211 return controller_iter->second; | 190 return controller_iter->second; |
| 212 } | 191 } |
| OLD | NEW |