Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/public/cpp/shelf_struct_traits.h" | 5 #include "ash/public/cpp/shelf_struct_traits.h" |
| 6 | 6 |
| 7 #include "mojo/common/common_custom_types_struct_traits.h" | 7 #include "mojo/common/common_custom_types_struct_traits.h" |
| 8 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" | 8 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" |
| 9 #include "ui/gfx/image/image_skia.h" | 9 #include "ui/gfx/image/image_skia.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 | 12 |
| 13 using ShelfItemStructTraits = | 13 using ShelfItemStructTraits = |
| 14 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>; | 14 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>; |
| 15 | 15 |
| 16 // static | 16 // static |
| 17 bool StructTraits<ash::mojom::ShelfIDDataView, ash::ShelfID>::Read( | |
| 18 ash::mojom::ShelfIDDataView data, | |
| 19 ash::ShelfID* out) { | |
| 20 std::string app_id; | |
| 21 std::string launch_id; | |
| 22 if (!data.ReadAppId(&app_id) || !data.ReadLaunchId(&launch_id)) | |
| 23 return false; | |
| 24 *out = ash::ShelfID(app_id, launch_id); | |
|
James Cook
2017/05/04 16:38:48
Reading a ShelfID looks like it allocates and copi
msw
2017/05/04 19:05:56
WDYT about instead making AppLaunchId a struct wit
James Cook
2017/05/04 19:45:07
Yeah, I think making ShelfID / AppLaunchId a struc
msw
2017/05/04 20:39:07
Done.
| |
| 25 return true; | |
| 26 } | |
| 27 | |
| 28 // static | |
| 17 const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) { | 29 const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) { |
| 18 // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom. | 30 // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom. |
| 19 static const SkBitmap kNullSkBitmap; | 31 static const SkBitmap kNullSkBitmap; |
| 20 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap(); | 32 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap(); |
| 21 } | 33 } |
| 22 | 34 |
| 23 // static | 35 // static |
| 24 bool ShelfItemStructTraits::Read(ash::mojom::ShelfItemDataView data, | 36 bool ShelfItemStructTraits::Read(ash::mojom::ShelfItemDataView data, |
| 25 ash::ShelfItem* out) { | 37 ash::ShelfItem* out) { |
| 26 SkBitmap image; | 38 SkBitmap image; |
| 27 std::string app_id; | |
| 28 std::string launch_id; | |
| 29 if (!data.ReadType(&out->type) || !data.ReadImage(&image) || | 39 if (!data.ReadType(&out->type) || !data.ReadImage(&image) || |
| 30 !data.ReadStatus(&out->status) || !data.ReadAppId(&app_id) || | 40 !data.ReadStatus(&out->status) || !data.ReadShelfId(&out->id) || |
| 31 !data.ReadLaunchId(&launch_id) || !data.ReadTitle(&out->title)) { | 41 !data.ReadTitle(&out->title)) { |
| 32 return false; | 42 return false; |
| 33 } | 43 } |
| 34 out->id = data.shelf_id(); | |
| 35 out->app_launch_id = ash::AppLaunchId(app_id, launch_id); | |
| 36 // TODO(crbug.com/655874): Support high-dpi images via gfx::Image[Skia] mojom. | 44 // TODO(crbug.com/655874): Support high-dpi images via gfx::Image[Skia] mojom. |
| 37 out->image = gfx::ImageSkia::CreateFrom1xBitmap(image); | 45 out->image = gfx::ImageSkia::CreateFrom1xBitmap(image); |
| 38 out->shows_tooltip = data.shows_tooltip(); | 46 out->shows_tooltip = data.shows_tooltip(); |
| 39 out->pinned_by_policy = data.pinned_by_policy(); | 47 out->pinned_by_policy = data.pinned_by_policy(); |
| 40 return true; | 48 return true; |
| 41 } | 49 } |
| 42 | 50 |
| 43 } // namespace mojo | 51 } // namespace mojo |
| OLD | NEW |