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

Side by Side Diff: ash/public/interfaces/shelf_struct_traits.cc

Issue 2750463009: mash: Fix ShelfItem mojo struct; add enums and traits. (Closed)
Patch Set: Sync and rebase. 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 unified diff | Download patch
OLDNEW
(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/interfaces/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 // static
14 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
15 ash::ShelfItem>::type(const ash::ShelfItem& i) {
16 return i.type;
17 }
18
19 // static
20 const SkBitmap& StructTraits<ash::mojom::ShelfItemDataView,
21 ash::ShelfItem>::image(const ash::ShelfItem& i) {
22 // TODO(msw): Remove this when we have a gfx::Image[Skia] mojom.
23 static const SkBitmap kNullSkBitmap;
24 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap();
25 }
26
27 // static
28 int64_t StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::shelf_id(
29 const ash::ShelfItem& i) {
30 return i.id;
31 }
32
33 // static
34 ash::ShelfItemStatus
35 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::status(
36 const ash::ShelfItem& i) {
37 return i.status;
38 }
39
40 // static
41 const std::string&
42 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::app_id(
43 const ash::ShelfItem& i) {
44 return i.app_id;
45 }
46
47 // static
48 const base::string16&
49 StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::title(
50 const ash::ShelfItem& i) {
51 return i.title;
52 }
53
54 // static
55 bool StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::shows_tooltip(
56 const ash::ShelfItem& i) {
57 return i.shows_tooltip;
58 }
59
60 // static
61 bool StructTraits<ash::mojom::ShelfItemDataView,
62 ash::ShelfItem>::pinned_by_policy(const ash::ShelfItem& i) {
63 return i.pinned_by_policy;
64 }
65
66 // static
67 bool StructTraits<ash::mojom::ShelfItemDataView, ash::ShelfItem>::Read(
68 ash::mojom::ShelfItemDataView data,
69 ash::ShelfItem* out) {
70 SkBitmap image;
71 if (!data.ReadType(&out->type) || !data.ReadImage(&image) ||
72 !data.ReadStatus(&out->status) || !data.ReadAppId(&out->app_id) ||
73 !data.ReadTitle(&out->title)) {
74 return false;
75 }
76 out->id = data.shelf_id();
77 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
78 out->shows_tooltip = data.shows_tooltip();
79 out->pinned_by_policy = data.pinned_by_policy();
80 return true;
81 }
82
83 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698