| 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/shelf/shelf_controller.h" | 5 #include "ash/shelf/shelf_controller.h" |
| 6 | 6 |
| 7 #include "ash/public/interfaces/shelf.mojom.h" | 7 #include "ash/public/interfaces/shelf.mojom.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/app_list_shelf_item_delegate.h" | 9 #include "ash/shelf/app_list_shelf_item_delegate.h" |
| 10 #include "ash/shelf/wm_shelf.h" | 10 #include "ash/shelf/wm_shelf.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm_window.h" | 12 #include "ash/wm_window.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "ui/base/models/simple_menu_model.h" | 14 #include "ui/base/models/simple_menu_model.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | |
| 16 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 17 #include "ui/display/screen.h" | 16 #include "ui/display/screen.h" |
| 18 #include "ui/gfx/image/image_skia.h" | |
| 19 #include "ui/resources/grit/ui_resources.h" | |
| 20 | 17 |
| 21 namespace ash { | 18 namespace ash { |
| 22 | 19 |
| 23 namespace { | 20 namespace { |
| 24 | 21 |
| 25 // Returns an icon image from an SkBitmap, or the default shelf icon image if | |
| 26 // the bitmap is empty. Assumes the bitmap is a 1x icon. | |
| 27 // TODO(jamescook): Support other scale factors. | |
| 28 gfx::ImageSkia GetShelfIconFromBitmap(const SkBitmap& bitmap) { | |
| 29 gfx::ImageSkia icon_image; | |
| 30 if (!bitmap.isNull()) { | |
| 31 icon_image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
| 32 } else { | |
| 33 // Use default icon. | |
| 34 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 35 icon_image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON); | |
| 36 } | |
| 37 return icon_image; | |
| 38 } | |
| 39 | |
| 40 // Returns the WmShelf instance for the display with the given |display_id|. | 22 // Returns the WmShelf instance for the display with the given |display_id|. |
| 41 WmShelf* GetShelfForDisplay(int64_t display_id) { | 23 WmShelf* GetShelfForDisplay(int64_t display_id) { |
| 42 // The controller may be null for invalid ids or for displays being removed. | 24 // The controller may be null for invalid ids or for displays being removed. |
| 43 RootWindowController* root_window_controller = | 25 RootWindowController* root_window_controller = |
| 44 Shell::GetRootWindowControllerWithDisplayId(display_id); | 26 Shell::GetRootWindowControllerWithDisplayId(display_id); |
| 45 return root_window_controller ? root_window_controller->GetShelf() : nullptr; | 27 return root_window_controller ? root_window_controller->GetShelf() : nullptr; |
| 46 } | 28 } |
| 47 | 29 |
| 48 } // namespace | 30 } // namespace |
| 49 | 31 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 mojom::ShelfItemDelegateAssociatedPtrInfo delegate) { | 97 mojom::ShelfItemDelegateAssociatedPtrInfo delegate) { |
| 116 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
| 117 } | 99 } |
| 118 | 100 |
| 119 void ShelfController::UnpinItem(const std::string& app_id) { | 101 void ShelfController::UnpinItem(const std::string& app_id) { |
| 120 NOTIMPLEMENTED(); | 102 NOTIMPLEMENTED(); |
| 121 } | 103 } |
| 122 | 104 |
| 123 void ShelfController::SetItemImage(const std::string& app_id, | 105 void ShelfController::SetItemImage(const std::string& app_id, |
| 124 const SkBitmap& image) { | 106 const SkBitmap& image) { |
| 125 if (!app_id_to_shelf_id_.count(app_id)) | 107 NOTIMPLEMENTED(); |
| 126 return; | |
| 127 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | |
| 128 int index = model_.ItemIndexByID(shelf_id); | |
| 129 DCHECK_GE(index, 0); | |
| 130 ShelfItem item = *model_.ItemByID(shelf_id); | |
| 131 item.image = GetShelfIconFromBitmap(image); | |
| 132 model_.Set(index, item); | |
| 133 } | 108 } |
| 134 | 109 |
| 135 } // namespace ash | 110 } // namespace ash |
| OLD | NEW |