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

Side by Side Diff: chrome/browser/ui/ash/launcher/app_window_launcher_item_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 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 : ash::ShelfItemDelegate(shelf_id), observed_windows_(this) {}
22 22
23 AppWindowLauncherItemController::~AppWindowLauncherItemController() {} 23 AppWindowLauncherItemController::~AppWindowLauncherItemController() {}
24 24
25 void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* app_window) { 25 void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* app_window) {
26 windows_.push_front(app_window); 26 windows_.push_front(app_window);
27 aura::Window* window = app_window->GetNativeWindow(); 27 aura::Window* window = app_window->GetNativeWindow();
28 if (window) 28 if (window)
29 observed_windows_.Add(window); 29 observed_windows_.Add(window);
30 UpdateLauncherItem(); 30 UpdateShelfItemIcon();
31 } 31 }
32 32
33 AppWindowLauncherItemController::WindowList::iterator 33 AppWindowLauncherItemController::WindowList::iterator
34 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) { 34 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) {
35 return std::find_if(windows_.begin(), windows_.end(), 35 return std::find_if(windows_.begin(), windows_.end(),
36 [window](ui::BaseWindow* base_window) { 36 [window](ui::BaseWindow* base_window) {
37 return base_window->GetNativeWindow() == window; 37 return base_window->GetNativeWindow() == window;
38 }); 38 });
39 } 39 }
40 40
41 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { 41 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) {
42 DCHECK(app_window); 42 DCHECK(app_window);
43 aura::Window* window = app_window->GetNativeWindow(); 43 aura::Window* window = app_window->GetNativeWindow();
44 if (window) 44 if (window)
45 observed_windows_.Remove(window); 45 observed_windows_.Remove(window);
46 if (app_window == last_active_window_) 46 if (app_window == last_active_window_)
47 last_active_window_ = nullptr; 47 last_active_window_ = nullptr;
48 auto iter = std::find(windows_.begin(), windows_.end(), app_window); 48 auto iter = std::find(windows_.begin(), windows_.end(), app_window);
49 if (iter == windows_.end()) { 49 if (iter == windows_.end()) {
50 NOTREACHED(); 50 NOTREACHED();
51 return; 51 return;
52 } 52 }
53 windows_.erase(iter); 53 windows_.erase(iter);
54 UpdateLauncherItem(); 54 UpdateShelfItemIcon();
55 } 55 }
56 56
57 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( 57 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow(
58 aura::Window* window) { 58 aura::Window* window) {
59 const auto iter = GetFromNativeWindow(window); 59 const auto iter = GetFromNativeWindow(window);
60 if (iter != windows_.end()) 60 if (iter != windows_.end())
61 return *iter; 61 return *iter;
62 return nullptr; 62 return nullptr;
63 } 63 }
64 64
65 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { 65 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) {
66 ui::BaseWindow* app_window = GetAppWindow(window); 66 ui::BaseWindow* app_window = GetAppWindow(window);
67 if (app_window) 67 if (app_window)
68 last_active_window_ = app_window; 68 last_active_window_ = app_window;
69 UpdateLauncherItem(); 69 UpdateShelfItemIcon();
70 } 70 }
71 71
72 AppWindowLauncherItemController* 72 AppWindowLauncherItemController*
73 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { 73 AppWindowLauncherItemController::AsAppWindowLauncherItemController() {
74 return this; 74 return this;
75 } 75 }
76 76
77 void AppWindowLauncherItemController::ItemSelected( 77 void AppWindowLauncherItemController::ItemSelected(
78 std::unique_ptr<ui::Event> event, 78 std::unique_ptr<ui::Event> event,
79 int64_t display_id, 79 int64_t display_id,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (key == aura::client::kDrawAttentionKey) { 136 if (key == aura::client::kDrawAttentionKey) {
137 ash::ShelfItemStatus status; 137 ash::ShelfItemStatus status;
138 if (ash::wm::IsActiveWindow(window)) { 138 if (ash::wm::IsActiveWindow(window)) {
139 status = ash::STATUS_ACTIVE; 139 status = ash::STATUS_ACTIVE;
140 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { 140 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) {
141 status = ash::STATUS_ATTENTION; 141 status = ash::STATUS_ATTENTION;
142 } else { 142 } else {
143 status = ash::STATUS_RUNNING; 143 status = ash::STATUS_RUNNING;
144 } 144 }
145 ChromeLauncherController::instance()->SetItemStatus(shelf_id(), status); 145 ChromeLauncherController::instance()->SetItemStatus(shelf_id(), status);
146 } else if (key == aura::client::kAppIconKey) {
147 UpdateShelfItemIcon();
146 } 148 }
147 } 149 }
148 150
149 ash::ShelfAction AppWindowLauncherItemController::ShowAndActivateOrMinimize( 151 ash::ShelfAction AppWindowLauncherItemController::ShowAndActivateOrMinimize(
150 ui::BaseWindow* app_window) { 152 ui::BaseWindow* app_window) {
151 // Either show or minimize windows when shown from the launcher. 153 // Either show or minimize windows when shown from the launcher.
152 return ChromeLauncherController::instance()->ActivateWindowOrMinimizeIfActive( 154 return ChromeLauncherController::instance()->ActivateWindowOrMinimizeIfActive(
153 app_window, GetAppMenuItems(ui::EF_NONE).size() == 1); 155 app_window, GetAppMenuItems(ui::EF_NONE).size() == 1);
154 } 156 }
155 157
(...skipping 11 matching lines...) Expand all
167 if (window_to_show->IsActive()) { 169 if (window_to_show->IsActive()) {
168 // Coming here, only a single window is active. For keyboard activations 170 // Coming here, only a single window is active. For keyboard activations
169 // the window gets animated. 171 // the window gets animated.
170 AnimateWindow(window_to_show->GetNativeWindow(), 172 AnimateWindow(window_to_show->GetNativeWindow(),
171 wm::WINDOW_ANIMATION_TYPE_BOUNCE); 173 wm::WINDOW_ANIMATION_TYPE_BOUNCE);
172 } else { 174 } else {
173 return ShowAndActivateOrMinimize(window_to_show); 175 return ShowAndActivateOrMinimize(window_to_show);
174 } 176 }
175 return ash::SHELF_ACTION_NONE; 177 return ash::SHELF_ACTION_NONE;
176 } 178 }
179
180 void AppWindowLauncherItemController::UpdateShelfItemIcon() {
181 // Set the shelf item icon from the kAppIconKey property of the current
182 // (or most recently) active window. If there is no valid icon, ask
183 // ChromeLauncherController to update the icon.
184 const gfx::ImageSkia* app_icon = nullptr;
185 ui::BaseWindow* last_active_window = GetLastActiveWindow();
186 if (last_active_window && last_active_window->GetNativeWindow()) {
187 app_icon = last_active_window->GetNativeWindow()->GetProperty(
188 aura::client::kAppIconKey);
189 }
190 // TODO(khmel): Remove using image_set_by_controller
191 if (app_icon && !app_icon->isNull()) {
192 set_image_set_by_controller(true);
193 ChromeLauncherController::instance()->SetLauncherItemImage(shelf_id(),
194 *app_icon);
195 } else if (image_set_by_controller()) {
196 set_image_set_by_controller(false);
197 ChromeLauncherController::instance()->UpdateLauncherItemImage(
198 shelf_id().app_id);
199 }
200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698