OLD | NEW |
(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 "services/ui/public/interfaces/cursor/cursor_struct_traits.h" |
| 6 |
| 7 #include "base/time/time.h" |
| 8 #include "mojo/common/common_custom_types_struct_traits.h" |
| 9 #include "skia/public/interfaces/bitmap_array_struct_traits.h" |
| 10 #include "skia/public/interfaces/bitmap_skbitmap_struct_traits.h" |
| 11 #include "third_party/skia/include/core/SkBitmap.h" |
| 12 #include "ui/base/cursor/cursor.h" |
| 13 #include "ui/gfx/geometry/mojo/geometry_struct_traits.h" |
| 14 |
| 15 namespace mojo { |
| 16 |
| 17 // static |
| 18 const base::TimeDelta& |
| 19 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::frame_delay( |
| 20 const ui::CursorData& c) { |
| 21 return c.frame_delay(); |
| 22 } |
| 23 |
| 24 // static |
| 25 const gfx::Point& |
| 26 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::hotspot_in_pixels( |
| 27 const ui::CursorData& c) { |
| 28 return c.hotspot_in_pixels(); |
| 29 } |
| 30 |
| 31 // static |
| 32 const std::vector<SkBitmap>& |
| 33 StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::cursor_frames( |
| 34 const ui::CursorData& c) { |
| 35 return c.cursor_frames(); |
| 36 } |
| 37 |
| 38 // static |
| 39 bool StructTraits<ui::mojom::CursorDataDataView, ui::CursorData>::Read( |
| 40 ui::mojom::CursorDataDataView data, |
| 41 ui::CursorData* out) { |
| 42 ui::mojom::CursorType type = data.cursor_type(); |
| 43 if (type != ui::mojom::CursorType::CUSTOM) { |
| 44 *out = ui::CursorData(static_cast<int>(type)); |
| 45 return true; |
| 46 } |
| 47 |
| 48 gfx::Point hotspot_in_pixels; |
| 49 std::vector<SkBitmap> cursor_frames; |
| 50 float scale_factor = data.scale_factor(); |
| 51 base::TimeDelta frame_delay; |
| 52 |
| 53 if (!data.ReadHotspotInPixels(&hotspot_in_pixels) || |
| 54 !data.ReadCursorFrames(&cursor_frames) || |
| 55 !data.ReadFrameDelay(&frame_delay)) { |
| 56 return false; |
| 57 } |
| 58 |
| 59 *out = ui::CursorData(hotspot_in_pixels, cursor_frames, scale_factor, |
| 60 frame_delay); |
| 61 return true; |
| 62 } |
| 63 |
| 64 } // namespace mojo |
OLD | NEW |