OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #ifndef UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ | |
6 #define UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ | |
7 | |
8 #include "ui/gfx/geometry/insets.h" | |
9 #include "ui/gfx/geometry/insets_f.h" | |
10 #include "ui/gfx/geometry/mojo/geometry.mojom.h" | |
11 #include "ui/gfx/geometry/point.h" | |
12 #include "ui/gfx/geometry/point_f.h" | |
13 #include "ui/gfx/geometry/rect.h" | |
14 #include "ui/gfx/geometry/rect_f.h" | |
15 #include "ui/gfx/geometry/size.h" | |
16 #include "ui/gfx/geometry/size_f.h" | |
17 | |
18 namespace mojo { | |
19 | |
20 template <> | |
21 struct StructTraits<mojo::Insets, gfx::Insets> { | |
22 static int top(const gfx::Insets& p) { return p.top(); } | |
23 static int left(const gfx::Insets& p) { return p.left(); } | |
24 static int bottom(const gfx::Insets& p) { return p.bottom(); } | |
25 static int right(const gfx::Insets& p) { return p.right(); } | |
26 static bool Read(mojo::InsetsDataView data, gfx::Insets* out) { | |
27 out->Set(data.top(), data.left(), data.bottom(), data.right()); | |
28 return true; | |
29 } | |
30 }; | |
31 | |
32 template <> | |
33 struct StructTraits<mojo::InsetsF, gfx::InsetsF> { | |
34 static float top(const gfx::InsetsF& p) { return p.top(); } | |
35 static float left(const gfx::InsetsF& p) { return p.left(); } | |
36 static float bottom(const gfx::InsetsF& p) { return p.bottom(); } | |
37 static float right(const gfx::InsetsF& p) { return p.right(); } | |
38 static bool Read(mojo::InsetsFDataView data, gfx::InsetsF* out) { | |
39 out->Set(data.top(), data.left(), data.bottom(), data.right()); | |
40 return true; | |
41 } | |
42 }; | |
43 | |
44 template <> | |
45 struct StructTraits<mojo::Point, gfx::Point> { | |
46 static int x(const gfx::Point& p) { return p.x(); } | |
47 static int y(const gfx::Point& p) { return p.y(); } | |
48 static bool Read(mojo::PointDataView data, gfx::Point* out) { | |
49 out->SetPoint(data.x(), data.y()); | |
50 return true; | |
51 } | |
52 }; | |
53 | |
54 template <> | |
55 struct StructTraits<mojo::PointF, gfx::PointF> { | |
56 static float x(const gfx::PointF& p) { return p.x(); } | |
57 static float y(const gfx::PointF& p) { return p.y(); } | |
58 static bool Read(mojo::PointFDataView data, gfx::PointF* out) { | |
59 out->SetPoint(data.x(), data.y()); | |
60 return true; | |
61 } | |
62 }; | |
63 | |
64 template <> | |
65 struct StructTraits<mojo::Rect, gfx::Rect> { | |
66 static int x(const gfx::Rect& p) { return p.x(); } | |
67 static int y(const gfx::Rect& p) { return p.y(); } | |
68 static int width(const gfx::Rect& p) { return p.width(); } | |
69 static int height(const gfx::Rect& p) { return p.height(); } | |
70 static bool Read(mojo::RectDataView data, gfx::Rect* out) { | |
71 out->SetRect(data.x(), data.y(), data.width(), data.height()); | |
72 return true; | |
73 } | |
74 }; | |
75 | |
76 template <> | |
77 struct StructTraits<mojo::RectF, gfx::RectF> { | |
78 static float x(const gfx::RectF& p) { return p.x(); } | |
79 static float y(const gfx::RectF& p) { return p.y(); } | |
80 static float width(const gfx::RectF& p) { return p.width(); } | |
81 static float height(const gfx::RectF& p) { return p.height(); } | |
82 static bool Read(mojo::RectFDataView data, gfx::RectF* out) { | |
83 out->SetRect(data.x(), data.y(), data.width(), data.height()); | |
dcheng
2016/06/07 23:38:37
I missed this in the initial review, but Rect/Rect
| |
84 return true; | |
85 } | |
86 }; | |
87 | |
88 template <> | |
89 struct StructTraits<mojo::Size, gfx::Size> { | |
90 static int width(const gfx::Size& p) { return p.width(); } | |
91 static int height(const gfx::Size& p) { return p.height(); } | |
92 static bool Read(mojo::SizeDataView data, gfx::Size* out) { | |
93 out->SetSize(data.width(), data.height()); | |
94 return true; | |
95 } | |
96 }; | |
97 | |
98 template <> | |
99 struct StructTraits<mojo::SizeF, gfx::SizeF> { | |
100 static float width(const gfx::SizeF& p) { return p.width(); } | |
101 static float height(const gfx::SizeF& p) { return p.height(); } | |
102 static bool Read(mojo::SizeFDataView data, gfx::SizeF* out) { | |
103 out->SetSize(data.width(), data.height()); | |
104 return true; | |
105 } | |
106 }; | |
107 | |
108 } // namespace mojo | |
109 | |
110 #endif // UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ | |
OLD | NEW |