Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/app_window_launcher_item_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 13 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 13 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 14 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/base/base_window.h" | 16 #include "ui/base/base_window.h" |
| 17 #include "ui/wm/core/window_animations.h" | 17 #include "ui/wm/core/window_animations.h" |
| 18 | 18 |
| 19 AppWindowLauncherItemController::AppWindowLauncherItemController( | 19 AppWindowLauncherItemController::AppWindowLauncherItemController( |
| 20 const ash::ShelfID& shelf_id) | 20 const ash::ShelfID& shelf_id, |
| 21 : ash::ShelfItemDelegate(shelf_id), observed_windows_(this) {} | 21 ChromeLauncherController* owner) |
| 22 : ash::ShelfItemDelegate(shelf_id), | |
| 23 owner_(owner), | |
| 24 observed_windows_(this) {} | |
| 22 | 25 |
| 23 AppWindowLauncherItemController::~AppWindowLauncherItemController() {} | 26 AppWindowLauncherItemController::~AppWindowLauncherItemController() {} |
| 24 | 27 |
| 25 void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* app_window) { | 28 void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* app_window) { |
| 26 windows_.push_front(app_window); | 29 windows_.push_front(app_window); |
| 27 aura::Window* window = app_window->GetNativeWindow(); | 30 aura::Window* window = app_window->GetNativeWindow(); |
| 28 if (window) | 31 if (window) |
| 29 observed_windows_.Add(window); | 32 observed_windows_.Add(window); |
| 30 UpdateLauncherItem(); | 33 UpdateShelfItemIcon(); |
| 31 } | 34 } |
| 32 | 35 |
| 33 AppWindowLauncherItemController::WindowList::iterator | 36 AppWindowLauncherItemController::WindowList::iterator |
| 34 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) { | 37 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) { |
| 35 return std::find_if(windows_.begin(), windows_.end(), | 38 return std::find_if(windows_.begin(), windows_.end(), |
| 36 [window](ui::BaseWindow* base_window) { | 39 [window](ui::BaseWindow* base_window) { |
| 37 return base_window->GetNativeWindow() == window; | 40 return base_window->GetNativeWindow() == window; |
| 38 }); | 41 }); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { | 44 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { |
| 42 DCHECK(app_window); | 45 DCHECK(app_window); |
| 43 aura::Window* window = app_window->GetNativeWindow(); | 46 aura::Window* window = app_window->GetNativeWindow(); |
| 44 if (window) | 47 if (window) |
| 45 observed_windows_.Remove(window); | 48 observed_windows_.Remove(window); |
| 46 if (app_window == last_active_window_) | 49 if (app_window == last_active_window_) |
| 47 last_active_window_ = nullptr; | 50 last_active_window_ = nullptr; |
| 48 auto iter = std::find(windows_.begin(), windows_.end(), app_window); | 51 auto iter = std::find(windows_.begin(), windows_.end(), app_window); |
| 49 if (iter == windows_.end()) { | 52 if (iter == windows_.end()) { |
| 50 NOTREACHED(); | 53 NOTREACHED(); |
| 51 return; | 54 return; |
| 52 } | 55 } |
| 53 windows_.erase(iter); | 56 windows_.erase(iter); |
| 54 UpdateLauncherItem(); | 57 UpdateShelfItemIcon(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( | 60 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( |
| 58 aura::Window* window) { | 61 aura::Window* window) { |
| 59 const auto iter = GetFromNativeWindow(window); | 62 const auto iter = GetFromNativeWindow(window); |
| 60 if (iter != windows_.end()) | 63 if (iter != windows_.end()) |
| 61 return *iter; | 64 return *iter; |
| 62 return nullptr; | 65 return nullptr; |
| 63 } | 66 } |
| 64 | 67 |
| 65 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { | 68 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { |
| 66 ui::BaseWindow* app_window = GetAppWindow(window); | 69 ui::BaseWindow* app_window = GetAppWindow(window); |
| 67 if (app_window) | 70 if (app_window) |
| 68 last_active_window_ = app_window; | 71 last_active_window_ = app_window; |
| 69 UpdateLauncherItem(); | 72 UpdateShelfItemIcon(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 AppWindowLauncherItemController* | 75 AppWindowLauncherItemController* |
| 73 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { | 76 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { |
| 74 return this; | 77 return this; |
| 75 } | 78 } |
| 76 | 79 |
| 77 void AppWindowLauncherItemController::ItemSelected( | 80 void AppWindowLauncherItemController::ItemSelected( |
| 78 std::unique_ptr<ui::Event> event, | 81 std::unique_ptr<ui::Event> event, |
| 79 int64_t display_id, | 82 int64_t display_id, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 if (key == aura::client::kDrawAttentionKey) { | 139 if (key == aura::client::kDrawAttentionKey) { |
| 137 ash::ShelfItemStatus status; | 140 ash::ShelfItemStatus status; |
| 138 if (ash::wm::IsActiveWindow(window)) { | 141 if (ash::wm::IsActiveWindow(window)) { |
| 139 status = ash::STATUS_ACTIVE; | 142 status = ash::STATUS_ACTIVE; |
| 140 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { | 143 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { |
| 141 status = ash::STATUS_ATTENTION; | 144 status = ash::STATUS_ATTENTION; |
| 142 } else { | 145 } else { |
| 143 status = ash::STATUS_RUNNING; | 146 status = ash::STATUS_RUNNING; |
| 144 } | 147 } |
| 145 ChromeLauncherController::instance()->SetItemStatus(shelf_id(), status); | 148 ChromeLauncherController::instance()->SetItemStatus(shelf_id(), status); |
| 149 } else if (key == aura::client::kAppIconKey) { | |
| 150 UpdateShelfItemIcon(); | |
| 146 } | 151 } |
| 147 } | 152 } |
| 148 | 153 |
| 149 ash::ShelfAction AppWindowLauncherItemController::ShowAndActivateOrMinimize( | 154 ash::ShelfAction AppWindowLauncherItemController::ShowAndActivateOrMinimize( |
| 150 ui::BaseWindow* app_window) { | 155 ui::BaseWindow* app_window) { |
| 151 // Either show or minimize windows when shown from the launcher. | 156 // Either show or minimize windows when shown from the launcher. |
| 152 return ChromeLauncherController::instance()->ActivateWindowOrMinimizeIfActive( | 157 return ChromeLauncherController::instance()->ActivateWindowOrMinimizeIfActive( |
| 153 app_window, GetAppMenuItems(ui::EF_NONE).size() == 1); | 158 app_window, GetAppMenuItems(ui::EF_NONE).size() == 1); |
| 154 } | 159 } |
| 155 | 160 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 167 if (window_to_show->IsActive()) { | 172 if (window_to_show->IsActive()) { |
| 168 // Coming here, only a single window is active. For keyboard activations | 173 // Coming here, only a single window is active. For keyboard activations |
| 169 // the window gets animated. | 174 // the window gets animated. |
| 170 AnimateWindow(window_to_show->GetNativeWindow(), | 175 AnimateWindow(window_to_show->GetNativeWindow(), |
| 171 wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 176 wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 172 } else { | 177 } else { |
| 173 return ShowAndActivateOrMinimize(window_to_show); | 178 return ShowAndActivateOrMinimize(window_to_show); |
| 174 } | 179 } |
| 175 return ash::SHELF_ACTION_NONE; | 180 return ash::SHELF_ACTION_NONE; |
| 176 } | 181 } |
| 182 | |
| 183 void AppWindowLauncherItemController::UpdateShelfItemIcon() { | |
| 184 // App window may optionally contain an attached icon we may use for the shelf | |
|
msw
2017/06/01 19:47:28
optional nit: consider replacing this comment with
khmel
2017/06/01 21:55:46
Thanks!
| |
| 185 // item. Read this icon from the last active window in this controller. Note, | |
| 186 // last active window does not necessarily mean that is active window in the | |
| 187 // system, window from another controller may be active this time. In case | |
| 188 // such icon is available and non-empty set it as a shelf item icon. Otherwise | |
| 189 // use the default app icon. This function is called when the app window | |
| 190 // added/removed to/from this controller, active window was changed or window | |
| 191 // property that holds the icon is changed. In result, shelf icon may be | |
| 192 // dynamically changed for the same controller. | |
| 193 const gfx::ImageSkia* app_icon = nullptr; | |
| 194 ui::BaseWindow* last_active_window = GetLastActiveWindow(); | |
| 195 if (last_active_window && last_active_window->GetNativeWindow()) { | |
| 196 app_icon = last_active_window->GetNativeWindow()->GetProperty( | |
| 197 aura::client::kAppIconKey); | |
| 198 } | |
| 199 // TODO(khmel): Remove using image_set_by_controller | |
| 200 if (app_icon && !app_icon->isNull()) { | |
| 201 set_image_set_by_controller(true); | |
| 202 owner()->SetLauncherItemImage(shelf_id(), *app_icon); | |
| 203 } else if (image_set_by_controller()) { | |
| 204 set_image_set_by_controller(false); | |
| 205 owner()->UpdateLauncherItemImage(shelf_id().app_id); | |
| 206 } | |
| 207 } | |
| OLD | NEW |