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

Side by Side Diff: ui/gfx/geometry/mojo/geometry_struct_traits.h

Issue 2008193002: Change mojo geometry structs from using type converters to StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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
« no previous file with comments | « ui/gfx/geometry/mojo/geometry.typemap ('k') | ui/gfx/geometry/mojo/geometry_type_converters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « ui/gfx/geometry/mojo/geometry.typemap ('k') | ui/gfx/geometry/mojo/geometry_type_converters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698