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 // A non-empty launch id requires a non-empty app id. | |
| 21 return data.ReadAppId(&out->app_id) && !data.ReadLaunchId(&out->launch_id) && | |
|
James Cook
2017/05/04 22:14:08
extra "!" here?
Also, this might be clearer if it
msw
2017/05/04 23:06:50
Done. Good catch!
| |
| 22 (out->launch_id.empty() || !out->app_id.empty()); | |
| 23 } | |
| 24 | |
| 25 // static | |
| 17 const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) { | 26 const SkBitmap& ShelfItemStructTraits::image(const ash::ShelfItem& i) { |
| 18 // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom. | 27 // TODO(crbug.com/655874): Remove this when we have a gfx::Image[Skia] mojom. |
| 19 static const SkBitmap kNullSkBitmap; | 28 static const SkBitmap kNullSkBitmap; |
| 20 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap(); | 29 return i.image.isNull() ? kNullSkBitmap : *i.image.bitmap(); |
| 21 } | 30 } |
| 22 | 31 |
| 23 // static | 32 // static |
| 24 bool ShelfItemStructTraits::Read(ash::mojom::ShelfItemDataView data, | 33 bool ShelfItemStructTraits::Read(ash::mojom::ShelfItemDataView data, |
| 25 ash::ShelfItem* out) { | 34 ash::ShelfItem* out) { |
| 26 SkBitmap image; | 35 SkBitmap image; |
| 27 std::string app_id; | |
| 28 std::string launch_id; | |
| 29 if (!data.ReadType(&out->type) || !data.ReadImage(&image) || | 36 if (!data.ReadType(&out->type) || !data.ReadImage(&image) || |
| 30 !data.ReadStatus(&out->status) || !data.ReadAppId(&app_id) || | 37 !data.ReadStatus(&out->status) || !data.ReadShelfId(&out->id) || |
| 31 !data.ReadLaunchId(&launch_id) || !data.ReadTitle(&out->title)) { | 38 !data.ReadTitle(&out->title)) { |
| 32 return false; | 39 return false; |
| 33 } | 40 } |
| 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. | 41 // TODO(crbug.com/655874): Support high-dpi images via gfx::Image[Skia] mojom. |
| 37 out->image = gfx::ImageSkia::CreateFrom1xBitmap(image); | 42 out->image = gfx::ImageSkia::CreateFrom1xBitmap(image); |
| 38 out->shows_tooltip = data.shows_tooltip(); | 43 out->shows_tooltip = data.shows_tooltip(); |
| 39 out->pinned_by_policy = data.pinned_by_policy(); | 44 out->pinned_by_policy = data.pinned_by_policy(); |
| 40 return true; | 45 return true; |
| 41 } | 46 } |
| 42 | 47 |
| 43 } // namespace mojo | 48 } // namespace mojo |
| OLD | NEW |