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

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

Issue 2014013002: Add SkBitmap StructTraits for skia::mojo::Bitmap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix empty image handling; avoid resetting info. Created 4 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 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/sysui/shelf_delegate_mus.h" 5 #include "ash/sysui/shelf_delegate_mus.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/shelf/shelf.h" 9 #include "ash/shelf/shelf.h"
10 #include "ash/shelf/shelf_item_delegate.h" 10 #include "ash/shelf/shelf_item_delegate.h"
11 #include "ash/shelf/shelf_item_delegate_manager.h" 11 #include "ash/shelf/shelf_item_delegate_manager.h"
12 #include "ash/shelf/shelf_layout_manager.h" 12 #include "ash/shelf/shelf_layout_manager.h"
13 #include "ash/shelf/shelf_menu_model.h" 13 #include "ash/shelf/shelf_menu_model.h"
14 #include "ash/shelf/shelf_model.h" 14 #include "ash/shelf/shelf_model.h"
15 #include "ash/shelf/shelf_types.h" 15 #include "ash/shelf/shelf_types.h"
16 #include "ash/shelf/shelf_widget.h" 16 #include "ash/shelf/shelf_widget.h"
17 #include "ash/shell.h" 17 #include "ash/shell.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "components/mus/public/cpp/property_type_converters.h" 19 #include "components/mus/public/cpp/property_type_converters.h"
20 #include "components/mus/public/cpp/window.h" 20 #include "components/mus/public/cpp/window.h"
21 #include "components/mus/public/cpp/window_property.h" 21 #include "components/mus/public/cpp/window_property.h"
22 #include "mojo/common/common_type_converters.h" 22 #include "mojo/common/common_type_converters.h"
23 #include "services/shell/public/cpp/connector.h" 23 #include "services/shell/public/cpp/connector.h"
24 #include "skia/public/type_converters.h"
25 #include "ui/aura/mus/mus_util.h" 24 #include "ui/aura/mus/mus_util.h"
26 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/gfx/image/image_skia.h" 26 #include "ui/gfx/image/image_skia.h"
28 #include "ui/resources/grit/ui_resources.h" 27 #include "ui/resources/grit/ui_resources.h"
29 #include "ui/views/mus/window_manager_connection.h" 28 #include "ui/views/mus/window_manager_connection.h"
30 29
31 using mash::wm::mojom::UserWindowController; 30 using mash::wm::mojom::UserWindowController;
32 31
33 namespace ash { 32 namespace ash {
34 namespace sysui { 33 namespace sysui {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return; 307 return;
309 } 308 }
310 309
311 ShelfID shelf_id = model_->next_id(); 310 ShelfID shelf_id = model_->next_id();
312 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); 311 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id));
313 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id)); 312 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id));
314 313
315 ShelfItem shelf_item; 314 ShelfItem shelf_item;
316 shelf_item.type = TYPE_APP_SHORTCUT; 315 shelf_item.type = TYPE_APP_SHORTCUT;
317 shelf_item.status = STATUS_CLOSED; 316 shelf_item.status = STATUS_CLOSED;
318 shelf_item.image = GetShelfIconFromBitmap(item->image.To<SkBitmap>()); 317 shelf_item.image = GetShelfIconFromBitmap(item->image);
319 model_->Add(shelf_item); 318 model_->Add(shelf_item);
320 319
321 std::unique_ptr<ShelfItemDelegateMus> item_delegate( 320 std::unique_ptr<ShelfItemDelegateMus> item_delegate(
322 new ShelfItemDelegateMus(user_window_controller_.get())); 321 new ShelfItemDelegateMus(user_window_controller_.get()));
323 item_delegate->SetDelegate(std::move(delegate)); 322 item_delegate->SetDelegate(std::move(delegate));
324 item_delegate->set_pinned(true); 323 item_delegate->set_pinned(true);
325 item_delegate->set_title(item->app_title.To<base::string16>()); 324 item_delegate->set_title(item->app_title.To<base::string16>());
326 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( 325 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate(
327 shelf_id, std::move(item_delegate)); 326 shelf_id, std::move(item_delegate));
328 } 327 }
329 328
330 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { 329 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) {
331 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) 330 if (!app_id_to_shelf_id_.count(app_id.To<std::string>()))
332 return; 331 return;
333 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; 332 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()];
334 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); 333 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id);
335 DCHECK(item_delegate->pinned()); 334 DCHECK(item_delegate->pinned());
336 item_delegate->set_pinned(false); 335 item_delegate->set_pinned(false);
337 if (item_delegate->window_id_to_title().empty()) { 336 if (item_delegate->window_id_to_title().empty()) {
338 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); 337 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id));
339 app_id_to_shelf_id_.erase(app_id.To<std::string>()); 338 app_id_to_shelf_id_.erase(app_id.To<std::string>());
340 shelf_id_to_app_id_.erase(shelf_id); 339 shelf_id_to_app_id_.erase(shelf_id);
341 } 340 }
342 } 341 }
343 342
344 void ShelfDelegateMus::SetItemImage(const mojo::String& app_id, 343 void ShelfDelegateMus::SetItemImage(const mojo::String& app_id,
345 skia::mojom::BitmapPtr image) { 344 const SkBitmap& image) {
346 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) 345 if (!app_id_to_shelf_id_.count(app_id.To<std::string>()))
347 return; 346 return;
348 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; 347 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()];
349 int index = model_->ItemIndexByID(shelf_id); 348 int index = model_->ItemIndexByID(shelf_id);
350 DCHECK_GE(index, 0); 349 DCHECK_GE(index, 0);
351 ShelfItem item = *model_->ItemByID(shelf_id); 350 ShelfItem item = *model_->ItemByID(shelf_id);
352 item.image = GetShelfIconFromBitmap(image.To<SkBitmap>()); 351 item.image = GetShelfIconFromBitmap(image);
353 model_->Set(index, item); 352 model_->Set(index, item);
354 } 353 }
355 354
356 void ShelfDelegateMus::OnUserWindowObserverAdded( 355 void ShelfDelegateMus::OnUserWindowObserverAdded(
357 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) { 356 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) {
358 for (size_t i = 0; i < user_windows.size(); ++i) 357 for (size_t i = 0; i < user_windows.size(); ++i)
359 OnUserWindowAdded(std::move(user_windows[i])); 358 OnUserWindowAdded(std::move(user_windows[i]));
360 } 359 }
361 360
362 void ShelfDelegateMus::OnUserWindowAdded( 361 void ShelfDelegateMus::OnUserWindowAdded(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 StatusAreaWidget* status_widget = widget->status_area_widget(); 473 StatusAreaWidget* status_widget = widget->status_area_widget();
475 mus::Window* status_window = 474 mus::Window* status_window =
476 aura::GetMusWindow(status_widget->GetNativeWindow()); 475 aura::GetMusWindow(status_widget->GetNativeWindow());
477 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); 476 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size();
478 status_window->SetSharedProperty<gfx::Size>( 477 status_window->SetSharedProperty<gfx::Size>(
479 mus::mojom::WindowManager::kPreferredSize_Property, status_size); 478 mus::mojom::WindowManager::kPreferredSize_Property, status_size);
480 } 479 }
481 480
482 } // namespace sysui 481 } // namespace sysui
483 } // namespace ash 482 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698