Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| diff --git a/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| index 41d5953e1cda765dc682a8263440d1ea3a7683d6..78b4b90c929c547a0c82dc8a5f25bb6a28e8ac30 100644 |
| --- a/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| +++ b/chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc |
| @@ -17,8 +17,11 @@ |
| #include "ui/wm/core/window_animations.h" |
| AppWindowLauncherItemController::AppWindowLauncherItemController( |
| - const ash::ShelfID& shelf_id) |
| - : ash::ShelfItemDelegate(shelf_id), observed_windows_(this) {} |
| + const ash::ShelfID& shelf_id, |
| + ChromeLauncherController* owner) |
| + : ash::ShelfItemDelegate(shelf_id), |
| + owner_(owner), |
| + observed_windows_(this) {} |
| AppWindowLauncherItemController::~AppWindowLauncherItemController() {} |
| @@ -27,7 +30,7 @@ void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* app_window) { |
| aura::Window* window = app_window->GetNativeWindow(); |
| if (window) |
| observed_windows_.Add(window); |
| - UpdateLauncherItem(); |
| + UpdateShelfItemIcon(); |
| } |
| AppWindowLauncherItemController::WindowList::iterator |
| @@ -51,7 +54,7 @@ void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { |
| return; |
| } |
| windows_.erase(iter); |
| - UpdateLauncherItem(); |
| + UpdateShelfItemIcon(); |
| } |
| ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( |
| @@ -66,7 +69,7 @@ void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { |
| ui::BaseWindow* app_window = GetAppWindow(window); |
| if (app_window) |
| last_active_window_ = app_window; |
| - UpdateLauncherItem(); |
| + UpdateShelfItemIcon(); |
| } |
| AppWindowLauncherItemController* |
| @@ -143,6 +146,8 @@ void AppWindowLauncherItemController::OnWindowPropertyChanged( |
| status = ash::STATUS_RUNNING; |
| } |
| ChromeLauncherController::instance()->SetItemStatus(shelf_id(), status); |
| + } else if (key == aura::client::kAppIconKey) { |
| + UpdateShelfItemIcon(); |
| } |
| } |
| @@ -174,3 +179,29 @@ AppWindowLauncherItemController::ActivateOrAdvanceToNextAppWindow( |
| } |
| return ash::SHELF_ACTION_NONE; |
| } |
| + |
| +void AppWindowLauncherItemController::UpdateShelfItemIcon() { |
| + // App window may optionally contain an attached icon we may use for the shelf |
| + // item. Read this icon from the last active window in this controller. Note, |
| + // last active window does not necessarily mean that is active window in the |
| + // system, window from another controller may be active this time. In case |
| + // such icon is available and non-empty set is as a shelf item icon. Otherwise |
|
stevenjb
2017/05/23 18:19:22
s/set is/set it/
khmel
2017/05/24 20:10:11
Done.
|
| + // use the default app icon. This function is called when the app window |
| + // added/removed to/from this controller, active window was changed or window |
| + // property that holds the icon is changed. In result, shelf icon may be |
| + // dynamically changed for the same controller. |
| + const gfx::ImageSkia* app_icon = nullptr; |
| + ui::BaseWindow* last_active_window = GetLastActiveWindow(); |
| + if (last_active_window && last_active_window->GetNativeWindow()) { |
| + app_icon = last_active_window->GetNativeWindow()->GetProperty( |
| + aura::client::kAppIconKey); |
| + } |
| + // TODO(khmel): Remove using image_set_by_controller |
| + if (app_icon && !app_icon->isNull()) { |
| + set_image_set_by_controller(true); |
| + owner()->SetLauncherItemImage(shelf_id(), *app_icon); |
| + } else if (image_set_by_controller()) { |
| + set_image_set_by_controller(false); |
| + owner()->UpdateLauncherItemImage(shelf_id().app_id); |
| + } |
| +} |