OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/public/cpp/shelf_struct_traits.h" |
| 6 |
| 7 #include "mojo/common/common_custom_types_struct_traits.h" |
| 8 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" |
| 9 #include "ui/gfx/image/image_skia.h" |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 using ShelfItemStructTraits = |
| 14 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>; |
| 15 |
| 16 // static |
| 17 const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) { |
| 18 // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom. |
| 19 static const SkBitmap kNullSkBitmap; |
| 20 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap(); |
| 21 } |
| 22 |
| 23 // static |
| 24 bool ShelfItemStructTraits::Read(ash::mojom::ShelfItemDataView data, |
| 25 ash::ShelfItem* out) { |
| 26 SkBitmap image; |
| 27 if (!data.ReadType(&out->type) || !data.ReadImage(&image) || |
| 28 !data.ReadStatus(&out->status) || !data.ReadAppId(&out->app_id) || |
| 29 !data.ReadTitle(&out->title)) { |
| 30 return false; |
| 31 } |
| 32 out->id = data.shelf_id(); |
| 33 // TODO(crbug.com/655874): Support high-dpi images via gfx::Image[Skia] mojom. |
| 34 out->image = gfx::ImageSkia::CreateFrom1xBitmap(image); |
| 35 out->shows_tooltip = data.shows_tooltip(); |
| 36 out->pinned_by_policy = data.pinned_by_policy(); |
| 37 return true; |
| 38 } |
| 39 |
| 40 } // namespace mojo |
OLD | NEW |