Index: ash/public/interfaces/shelf_struct_traits.cc |
diff --git a/ash/public/interfaces/shelf_struct_traits.cc b/ash/public/interfaces/shelf_struct_traits.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..279d0f1ffbd4debdae4aa628e283de7dd237582c |
--- /dev/null |
+++ b/ash/public/interfaces/shelf_struct_traits.cc |
@@ -0,0 +1,83 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/public/interfaces/shelf_struct_traits.h" |
+ |
+#include "mojo/common/common_custom_types_struct_traits.h" |
+#include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" |
+#include "ui/gfx/image/image_skia.h" |
+ |
+namespace mojo { |
+ |
+// static |
+ash::ShelfItemType StructTraits<ash::mojom::ShelfItemDataView, |
James Cook
2017/03/16 16:48:50
optional: Is it possible to do "using ash::mojom::
msw
2017/03/16 23:15:50
I defined these inline for efficiency gains, at Yu
|
+ ash::ShelfItem>::type(const ash::ShelfItem& i) { |
+ return i.type; |
+} |
+ |
+// static |
+const SkBitmap& StructTraits<ash::mojom::ShelfItemDataView, |
+ ash::ShelfItem>::image(const ash::ShelfItem& i) { |
+ // TODO(msw): Remove this when we have a gfx::Image[Skia] mojom. |
+ static const SkBitmap kNullSkBitmap; |
+ return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap(); |
+} |
+ |
+// static |
+int64_t StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::shelf_id( |
+ const ash::ShelfItem& i) { |
+ return i.id; |
+} |
+ |
+// static |
+ash::ShelfItemStatus |
+StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::status( |
+ const ash::ShelfItem& i) { |
+ return i.status; |
+} |
+ |
+// static |
+const std::string& |
+StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::app_id( |
+ const ash::ShelfItem& i) { |
+ return i.app_id; |
+} |
+ |
+// static |
+const base::string16& |
+StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::title( |
+ const ash::ShelfItem& i) { |
+ return i.title; |
+} |
+ |
+// static |
+bool StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::shows_tooltip( |
+ const ash::ShelfItem& i) { |
+ return i.shows_tooltip; |
+} |
+ |
+// static |
+bool StructTraits<ash::mojom::ShelfItemDataView, |
+ ash::ShelfItem>::pinned_by_policy(const ash::ShelfItem& i) { |
+ return i.pinned_by_policy; |
+} |
+ |
+// static |
+bool StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::Read( |
+ ash::mojom::ShelfItemDataView data, |
+ ash::ShelfItem* out) { |
+ SkBitmap image; |
+ if (!data.ReadType(&out->type) || !data.ReadImage(&image) || |
+ !data.ReadStatus(&out->status) || !data.ReadAppId(&out->app_id) || |
+ !data.ReadTitle(&out->title)) { |
+ return false; |
+ } |
+ out->id = data.shelf_id(); |
+ out->image = gfx::ImageSkia::CreateFrom1xBitmap(image); |
James Cook
2017/03/16 16:48:50
This needs a TODO or bug -- I think we support 2x
Tom Sepez
2017/03/16 17:59:25
Can this fail?
msw
2017/03/16 23:15:50
Done.
msw
2017/03/16 23:15:50
It seems the returned ImageSkia instance is always
|
+ out->shows_tooltip = data.shows_tooltip(); |
+ out->pinned_by_policy = data.pinned_by_policy(); |
+ return true; |
+} |
+ |
+} // namespace mojo |