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

Side by Side Diff: ash/mus/shelf_delegate_mus.cc

Issue 1824183002: Mash: Show app icons in shelf based on the Widget's app icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: //ui/resources Created 4 years, 9 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 "ash/mus/shelf_delegate_mus.h" 5 #include "ash/mus/shelf_delegate_mus.h"
6 6
7 #include "ash/shelf/shelf.h" 7 #include "ash/shelf/shelf.h"
8 #include "ash/shelf/shelf_item_delegate.h" 8 #include "ash/shelf/shelf_item_delegate.h"
9 #include "ash/shelf/shelf_item_delegate_manager.h" 9 #include "ash/shelf/shelf_item_delegate_manager.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_model.h" 11 #include "ash/shelf/shelf_model.h"
12 #include "ash/shelf/shelf_widget.h" 12 #include "ash/shelf/shelf_widget.h"
13 #include "ash/shell.h" 13 #include "ash/shell.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "components/mus/public/cpp/property_type_converters.h" 15 #include "components/mus/public/cpp/property_type_converters.h"
16 #include "components/mus/public/cpp/window.h" 16 #include "components/mus/public/cpp/window.h"
17 #include "components/mus/public/cpp/window_property.h" 17 #include "components/mus/public/cpp/window_property.h"
18 #include "mojo/common/common_type_converters.h" 18 #include "mojo/common/common_type_converters.h"
19 #include "mojo/shell/public/cpp/connector.h" 19 #include "mojo/shell/public/cpp/connector.h"
20 #include "ui/aura/mus/mus_util.h" 20 #include "ui/aura/mus/mus_util.h"
21 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/image/image_skia.h"
22 #include "ui/resources/grit/ui_resources.h" 23 #include "ui/resources/grit/ui_resources.h"
23 #include "ui/views/mus/window_manager_connection.h" 24 #include "ui/views/mus/window_manager_connection.h"
24 25
25 using mash::wm::mojom::UserWindowController; 26 using mash::wm::mojom::UserWindowController;
26 27
27 namespace ash { 28 namespace ash {
28 namespace sysui { 29 namespace sysui {
29 30
30 namespace { 31 namespace {
31 32
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 void Close() override { NOTIMPLEMENTED(); } 75 void Close() override { NOTIMPLEMENTED(); }
75 76
76 // TODO(msw): Support multiple open windows per button. 77 // TODO(msw): Support multiple open windows per button.
77 uint32_t window_id_; 78 uint32_t window_id_;
78 base::string16 title_; 79 base::string16 title_;
79 UserWindowController* user_window_controller_; 80 UserWindowController* user_window_controller_;
80 81
81 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); 82 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus);
82 }; 83 };
83 84
85 // Returns an icon image from a serialized SkBitmap, or the default shelf icon
86 // image if the bitmap is empty. Assumes the bitmap is a 1x icon.
87 // TODO(jamescook): Support other scale factors.
88 gfx::ImageSkia GetShelfIconFromBitmap(
89 const mojo::Array<uint8_t>& serialized_bitmap) {
90 // Convert the data to an ImageSkia.
91 SkBitmap bitmap = mojo::ConvertTo<SkBitmap, const std::vector<uint8_t>>(
92 serialized_bitmap.storage());
93 gfx::ImageSkia icon_image;
94 if (!bitmap.isNull()) {
95 icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
96 } else {
97 // Use default icon.
98 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
99 icon_image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
100 }
101 return icon_image;
102 }
103
84 } // namespace 104 } // namespace
85 105
86 ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model) 106 ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model)
87 : model_(model), binding_(this) { 107 : model_(model), binding_(this) {
88 mojo::Connector* connector = 108 mojo::Connector* connector =
89 views::WindowManagerConnection::Get()->connector(); 109 views::WindowManagerConnection::Get()->connector();
90 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_); 110 connector->ConnectToInterface("mojo:desktop_wm", &user_window_controller_);
91 user_window_controller_->AddUserWindowObserver( 111 user_window_controller_->AddUserWindowObserver(
92 binding_.CreateInterfacePtrAndBind()); 112 binding_.CreateInterfacePtrAndBind());
93 } 113 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { 166 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) {
147 for (size_t i = 0; i < user_windows.size(); ++i) 167 for (size_t i = 0; i < user_windows.size(); ++i)
148 OnUserWindowAdded(std::move(user_windows[i])); 168 OnUserWindowAdded(std::move(user_windows[i]));
149 } 169 }
150 170
151 void ShelfDelegateMus::OnUserWindowAdded( 171 void ShelfDelegateMus::OnUserWindowAdded(
152 mash::wm::mojom::UserWindowPtr user_window) { 172 mash::wm::mojom::UserWindowPtr user_window) {
153 ShelfItem item; 173 ShelfItem item;
154 item.type = TYPE_PLATFORM_APP; 174 item.type = TYPE_PLATFORM_APP;
155 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING; 175 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING;
156 // TODO(msw): Support actual window icons. 176 item.image = GetShelfIconFromBitmap(user_window->window_app_icon);
157 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
158 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
159 177
160 ShelfID shelf_id = model_->next_id(); 178 ShelfID shelf_id = model_->next_id();
161 window_id_to_shelf_id_.insert( 179 window_id_to_shelf_id_.insert(
162 std::make_pair(user_window->window_id, shelf_id)); 180 std::make_pair(user_window->window_id, shelf_id));
163 model_->Add(item); 181 model_->Add(item);
164 182
165 ShelfItemDelegateManager* manager = 183 ShelfItemDelegateManager* manager =
166 Shell::GetInstance()->shelf_item_delegate_manager(); 184 Shell::GetInstance()->shelf_item_delegate_manager();
167 scoped_ptr<ShelfItemDelegate> delegate(new ShelfItemDelegateMus( 185 scoped_ptr<ShelfItemDelegate> delegate(new ShelfItemDelegateMus(
168 user_window->window_id, user_window->window_title.To<base::string16>(), 186 user_window->window_id, user_window->window_title.To<base::string16>(),
(...skipping 22 matching lines...) Expand all
191 // There's nothing in the ShelfItem that needs to be updated. But we still 209 // There's nothing in the ShelfItem that needs to be updated. But we still
192 // need to update the ShelfModel so that the observers can pick up any 210 // need to update the ShelfModel so that the observers can pick up any
193 // changes. 211 // changes.
194 int index = model_->ItemIndexByID(shelf_id); 212 int index = model_->ItemIndexByID(shelf_id);
195 DCHECK_GE(index, 0); 213 DCHECK_GE(index, 0);
196 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); 214 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id);
197 DCHECK(iter != model_->items().end()); 215 DCHECK(iter != model_->items().end());
198 model_->Set(index, *iter); 216 model_->Set(index, *iter);
199 } 217 }
200 218
219 void ShelfDelegateMus::OnUserWindowAppIconChanged(
220 uint32_t window_id,
221 mojo::Array<uint8_t> app_icon) {
222 // Find the shelf ID for this window.
223 DCHECK(window_id_to_shelf_id_.count(window_id));
224 ShelfID shelf_id = window_id_to_shelf_id_[window_id];
225 DCHECK_GT(shelf_id, 0);
226
227 // Update the icon in the ShelfItem.
228 int index = model_->ItemIndexByID(shelf_id);
229 if (index == -1)
msw 2016/03/24 17:40:54 optional nit: DCHECK and use use ItemByID instead
James Cook 2016/03/25 15:39:28 Done.
230 return;
231 ShelfItem item = model_->items()[index];
232 item.image = GetShelfIconFromBitmap(app_icon);
233 model_->Set(index, item);
234 }
235
201 void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id, 236 void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id,
202 bool has_focus) { 237 bool has_focus) {
203 DCHECK(window_id_to_shelf_id_.count(window_id)); 238 DCHECK(window_id_to_shelf_id_.count(window_id));
204 ShelfID shelf_id = window_id_to_shelf_id_[window_id]; 239 ShelfID shelf_id = window_id_to_shelf_id_[window_id];
205 int index = model_->ItemIndexByID(shelf_id); 240 int index = model_->ItemIndexByID(shelf_id);
206 DCHECK_GE(index, 0); 241 DCHECK_GE(index, 0);
207 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id); 242 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id);
208 DCHECK(iter != model_->items().end()); 243 DCHECK(iter != model_->items().end());
209 ShelfItem item = *iter; 244 ShelfItem item = *iter;
210 item.status = has_focus ? STATUS_ACTIVE : STATUS_RUNNING; 245 item.status = has_focus ? STATUS_ACTIVE : STATUS_RUNNING;
211 model_->Set(index, item); 246 model_->Set(index, item);
212 } 247 }
213 248
214 } // namespace sysui 249 } // namespace sysui
215 } // namespace ash 250 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698