OLD | NEW |
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 ash::mojom::UserWindowController; | 30 using ash::mojom::UserWindowController; |
32 | 31 |
33 namespace ash { | 32 namespace ash { |
34 namespace sysui { | 33 namespace sysui { |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 return; | 306 return; |
308 } | 307 } |
309 | 308 |
310 ShelfID shelf_id = model_->next_id(); | 309 ShelfID shelf_id = model_->next_id(); |
311 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); | 310 app_id_to_shelf_id_.insert(std::make_pair(app_id, shelf_id)); |
312 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id)); | 311 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, app_id)); |
313 | 312 |
314 ShelfItem shelf_item; | 313 ShelfItem shelf_item; |
315 shelf_item.type = TYPE_APP_SHORTCUT; | 314 shelf_item.type = TYPE_APP_SHORTCUT; |
316 shelf_item.status = STATUS_CLOSED; | 315 shelf_item.status = STATUS_CLOSED; |
317 shelf_item.image = GetShelfIconFromBitmap(item->image.To<SkBitmap>()); | 316 shelf_item.image = GetShelfIconFromBitmap(item->image); |
318 model_->Add(shelf_item); | 317 model_->Add(shelf_item); |
319 | 318 |
320 std::unique_ptr<ShelfItemDelegateMus> item_delegate( | 319 std::unique_ptr<ShelfItemDelegateMus> item_delegate( |
321 new ShelfItemDelegateMus(user_window_controller_.get())); | 320 new ShelfItemDelegateMus(user_window_controller_.get())); |
322 item_delegate->SetDelegate(std::move(delegate)); | 321 item_delegate->SetDelegate(std::move(delegate)); |
323 item_delegate->set_pinned(true); | 322 item_delegate->set_pinned(true); |
324 item_delegate->set_title(item->app_title.To<base::string16>()); | 323 item_delegate->set_title(item->app_title.To<base::string16>()); |
325 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( | 324 Shell::GetInstance()->shelf_item_delegate_manager()->SetShelfItemDelegate( |
326 shelf_id, std::move(item_delegate)); | 325 shelf_id, std::move(item_delegate)); |
327 } | 326 } |
328 | 327 |
329 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { | 328 void ShelfDelegateMus::UnpinItem(const mojo::String& app_id) { |
330 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) | 329 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) |
331 return; | 330 return; |
332 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; | 331 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; |
333 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 332 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
334 DCHECK(item_delegate->pinned()); | 333 DCHECK(item_delegate->pinned()); |
335 item_delegate->set_pinned(false); | 334 item_delegate->set_pinned(false); |
336 if (item_delegate->window_id_to_title().empty()) { | 335 if (item_delegate->window_id_to_title().empty()) { |
337 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); | 336 model_->RemoveItemAt(model_->ItemIndexByID(shelf_id)); |
338 app_id_to_shelf_id_.erase(app_id.To<std::string>()); | 337 app_id_to_shelf_id_.erase(app_id.To<std::string>()); |
339 shelf_id_to_app_id_.erase(shelf_id); | 338 shelf_id_to_app_id_.erase(shelf_id); |
340 } | 339 } |
341 } | 340 } |
342 | 341 |
343 void ShelfDelegateMus::SetItemImage(const mojo::String& app_id, | 342 void ShelfDelegateMus::SetItemImage(const mojo::String& app_id, |
344 skia::mojom::BitmapPtr image) { | 343 const SkBitmap& image) { |
345 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) | 344 if (!app_id_to_shelf_id_.count(app_id.To<std::string>())) |
346 return; | 345 return; |
347 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; | 346 ShelfID shelf_id = app_id_to_shelf_id_[app_id.To<std::string>()]; |
348 int index = model_->ItemIndexByID(shelf_id); | 347 int index = model_->ItemIndexByID(shelf_id); |
349 DCHECK_GE(index, 0); | 348 DCHECK_GE(index, 0); |
350 ShelfItem item = *model_->ItemByID(shelf_id); | 349 ShelfItem item = *model_->ItemByID(shelf_id); |
351 item.image = GetShelfIconFromBitmap(image.To<SkBitmap>()); | 350 item.image = GetShelfIconFromBitmap(image); |
352 model_->Set(index, item); | 351 model_->Set(index, item); |
353 } | 352 } |
354 | 353 |
355 void ShelfDelegateMus::OnUserWindowObserverAdded( | 354 void ShelfDelegateMus::OnUserWindowObserverAdded( |
356 mojo::Array<mojom::UserWindowPtr> user_windows) { | 355 mojo::Array<mojom::UserWindowPtr> user_windows) { |
357 for (size_t i = 0; i < user_windows.size(); ++i) | 356 for (size_t i = 0; i < user_windows.size(); ++i) |
358 OnUserWindowAdded(std::move(user_windows[i])); | 357 OnUserWindowAdded(std::move(user_windows[i])); |
359 } | 358 } |
360 | 359 |
361 void ShelfDelegateMus::OnUserWindowAdded(mojom::UserWindowPtr user_window) { | 360 void ShelfDelegateMus::OnUserWindowAdded(mojom::UserWindowPtr user_window) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 StatusAreaWidget* status_widget = widget->status_area_widget(); | 471 StatusAreaWidget* status_widget = widget->status_area_widget(); |
473 mus::Window* status_window = | 472 mus::Window* status_window = |
474 aura::GetMusWindow(status_widget->GetNativeWindow()); | 473 aura::GetMusWindow(status_widget->GetNativeWindow()); |
475 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); | 474 gfx::Size status_size = status_widget->GetWindowBoundsInScreen().size(); |
476 status_window->SetSharedProperty<gfx::Size>( | 475 status_window->SetSharedProperty<gfx::Size>( |
477 mus::mojom::WindowManager::kPreferredSize_Property, status_size); | 476 mus::mojom::WindowManager::kPreferredSize_Property, status_size); |
478 } | 477 } |
479 | 478 |
480 } // namespace sysui | 479 } // namespace sysui |
481 } // namespace ash | 480 } // namespace ash |
OLD | NEW |