Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Unified Diff: ash/public/cpp/shelf_struct_traits.cc

Issue 2750463009: mash: Fix ShelfItem mojo struct; add enums and traits. (Closed)
Patch Set: Address comment. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/public/cpp/shelf_struct_traits.h ('k') | ash/public/cpp/shelf_struct_traits_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/public/cpp/shelf_struct_traits.cc
diff --git a/ash/public/cpp/shelf_struct_traits.cc b/ash/public/cpp/shelf_struct_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0864433f7ff34a6023514e6eba5bc0f5842ecf21
--- /dev/null
+++ b/ash/public/cpp/shelf_struct_traits.cc
@@ -0,0 +1,40 @@
+// 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/cpp/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 {
+
+using ShelfItemStructTraits =
+ StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>;
+
+// static
+const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) {
+ // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom.
+ static const SkBitmap kNullSkBitmap;
+ return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap();
+}
+
+// static
+bool ShelfItemStructTraits::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();
+ // TODO(crbug.com/655874): Support high-dpi images via gfx::Image[Skia] mojom.
+ out->image = gfx::ImageSkia::CreateFrom1xBitmap(image);
+ out->shows_tooltip = data.shows_tooltip();
+ out->pinned_by_policy = data.pinned_by_policy();
+ return true;
+}
+
+} // namespace mojo
« no previous file with comments | « ash/public/cpp/shelf_struct_traits.h ('k') | ash/public/cpp/shelf_struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698