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

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

Issue 2161993004: Make geometry struct_trait shared by Blink and Chromium (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 #ifndef UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ 5 #ifndef UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_
6 #define UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ 6 #define UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_
7 7
8 #include "ui/gfx/geometry/insets.h" 8 #include "ui/gfx/geometry/insets.h"
9 #include "ui/gfx/geometry/insets_f.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" 10 #include "ui/gfx/geometry/point.h"
12 #include "ui/gfx/geometry/point_f.h" 11 #include "ui/gfx/geometry/point_f.h"
13 #include "ui/gfx/geometry/rect.h" 12 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/rect_f.h" 13 #include "ui/gfx/geometry/rect_f.h"
15 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/geometry/size_f.h" 15 #include "ui/gfx/geometry/size_f.h"
17 #include "ui/gfx/geometry/vector2d.h" 16 #include "ui/gfx/geometry/vector2d.h"
18 #include "ui/gfx/geometry/vector2d_f.h" 17 #include "ui/gfx/geometry/vector2d_f.h"
19 18
20 namespace mojo { 19 namespace mojo {
21 20
22 template <> 21 template <typename T>
dcheng 2016/07/20 18:16:10 Why do we need to templatize this? Some of these m
xlai (Olivia) 2016/07/20 19:07:34 My ultimate intention is to use compositor_frame.m
23 struct StructTraits<gfx::mojom::Insets, gfx::Insets> { 22 struct StructTraits<T, gfx::Insets> {
24 static int top(const gfx::Insets& p) { return p.top(); } 23 static int top(const gfx::Insets& p) { return p.top(); }
25 static int left(const gfx::Insets& p) { return p.left(); } 24 static int left(const gfx::Insets& p) { return p.left(); }
26 static int bottom(const gfx::Insets& p) { return p.bottom(); } 25 static int bottom(const gfx::Insets& p) { return p.bottom(); }
27 static int right(const gfx::Insets& p) { return p.right(); } 26 static int right(const gfx::Insets& p) { return p.right(); }
28 static bool Read(gfx::mojom::InsetsDataView data, gfx::Insets* out) { 27 static bool Read(typename T::DataView data, gfx::Insets* out) {
29 out->Set(data.top(), data.left(), data.bottom(), data.right()); 28 out->Set(data.top(), data.left(), data.bottom(), data.right());
30 return true; 29 return true;
31 } 30 }
32 }; 31 };
33 32
34 template <> 33 template <typename T>
35 struct StructTraits<gfx::mojom::InsetsF, gfx::InsetsF> { 34 struct StructTraits<T, gfx::InsetsF> {
36 static float top(const gfx::InsetsF& p) { return p.top(); } 35 static float top(const gfx::InsetsF& p) { return p.top(); }
37 static float left(const gfx::InsetsF& p) { return p.left(); } 36 static float left(const gfx::InsetsF& p) { return p.left(); }
38 static float bottom(const gfx::InsetsF& p) { return p.bottom(); } 37 static float bottom(const gfx::InsetsF& p) { return p.bottom(); }
39 static float right(const gfx::InsetsF& p) { return p.right(); } 38 static float right(const gfx::InsetsF& p) { return p.right(); }
40 static bool Read(gfx::mojom::InsetsFDataView data, gfx::InsetsF* out) { 39 static bool Read(typename T::DataView data, gfx::InsetsF* out) {
41 out->Set(data.top(), data.left(), data.bottom(), data.right()); 40 out->Set(data.top(), data.left(), data.bottom(), data.right());
42 return true; 41 return true;
43 } 42 }
44 }; 43 };
45 44
46 template <> 45 template <typename T>
47 struct StructTraits<gfx::mojom::Point, gfx::Point> { 46 struct StructTraits<T, gfx::Point> {
48 static int x(const gfx::Point& p) { return p.x(); } 47 static int x(const gfx::Point& p) { return p.x(); }
49 static int y(const gfx::Point& p) { return p.y(); } 48 static int y(const gfx::Point& p) { return p.y(); }
50 static bool Read(gfx::mojom::PointDataView data, gfx::Point* out) { 49 static bool Read(typename T::DataView data, gfx::Point* out) {
51 out->SetPoint(data.x(), data.y()); 50 out->SetPoint(data.x(), data.y());
52 return true; 51 return true;
53 } 52 }
54 }; 53 };
55 54
56 template <> 55 template <typename T>
57 struct StructTraits<gfx::mojom::PointF, gfx::PointF> { 56 struct StructTraits<T, gfx::PointF> {
58 static float x(const gfx::PointF& p) { return p.x(); } 57 static float x(const gfx::PointF& p) { return p.x(); }
59 static float y(const gfx::PointF& p) { return p.y(); } 58 static float y(const gfx::PointF& p) { return p.y(); }
60 static bool Read(gfx::mojom::PointFDataView data, gfx::PointF* out) { 59 static bool Read(typename T::DataView data, gfx::PointF* out) {
61 out->SetPoint(data.x(), data.y()); 60 out->SetPoint(data.x(), data.y());
62 return true; 61 return true;
63 } 62 }
64 }; 63 };
65 64
66 template <> 65 template <typename T>
67 struct StructTraits<gfx::mojom::Rect, gfx::Rect> { 66 struct StructTraits<T, gfx::Rect> {
68 static int x(const gfx::Rect& p) { return p.x(); } 67 static int x(const gfx::Rect& p) { return p.x(); }
69 static int y(const gfx::Rect& p) { return p.y(); } 68 static int y(const gfx::Rect& p) { return p.y(); }
70 static int width(const gfx::Rect& p) { return p.width(); } 69 static int width(const gfx::Rect& p) { return p.width(); }
71 static int height(const gfx::Rect& p) { return p.height(); } 70 static int height(const gfx::Rect& p) { return p.height(); }
72 static bool Read(gfx::mojom::RectDataView data, gfx::Rect* out) { 71 static bool Read(typename T::DataView data, gfx::Rect* out) {
73 if (data.width() < 0 || data.height() < 0) 72 if (data.width() < 0 || data.height() < 0)
74 return false; 73 return false;
75 74
76 out->SetRect(data.x(), data.y(), data.width(), data.height()); 75 out->SetRect(data.x(), data.y(), data.width(), data.height());
77 return true; 76 return true;
78 } 77 }
79 }; 78 };
80 79
81 template <> 80 template <typename T>
82 struct StructTraits<gfx::mojom::RectF, gfx::RectF> { 81 struct StructTraits<T, gfx::RectF> {
83 static float x(const gfx::RectF& p) { return p.x(); } 82 static float x(const gfx::RectF& p) { return p.x(); }
84 static float y(const gfx::RectF& p) { return p.y(); } 83 static float y(const gfx::RectF& p) { return p.y(); }
85 static float width(const gfx::RectF& p) { return p.width(); } 84 static float width(const gfx::RectF& p) { return p.width(); }
86 static float height(const gfx::RectF& p) { return p.height(); } 85 static float height(const gfx::RectF& p) { return p.height(); }
87 static bool Read(gfx::mojom::RectFDataView data, gfx::RectF* out) { 86 static bool Read(typename T::DataView data, gfx::RectF* out) {
88 if (data.width() < 0 || data.height() < 0) 87 if (data.width() < 0 || data.height() < 0)
89 return false; 88 return false;
90 89
91 out->SetRect(data.x(), data.y(), data.width(), data.height()); 90 out->SetRect(data.x(), data.y(), data.width(), data.height());
92 return true; 91 return true;
93 } 92 }
94 }; 93 };
95 94
96 template <> 95 template <typename T>
97 struct StructTraits<gfx::mojom::Size, gfx::Size> { 96 struct StructTraits<T, gfx::Size> {
98 static int width(const gfx::Size& p) { return p.width(); } 97 static int width(const gfx::Size& p) { return p.width(); }
99 static int height(const gfx::Size& p) { return p.height(); } 98 static int height(const gfx::Size& p) { return p.height(); }
100 static bool Read(gfx::mojom::SizeDataView data, gfx::Size* out) { 99 static bool Read(typename T::DataView data, gfx::Size* out) {
101 if (data.width() < 0 || data.height() < 0) 100 if (data.width() < 0 || data.height() < 0)
102 return false; 101 return false;
103 102
104 out->SetSize(data.width(), data.height()); 103 out->SetSize(data.width(), data.height());
105 return true; 104 return true;
106 } 105 }
107 }; 106 };
108 107
109 template <> 108 template <typename T>
110 struct StructTraits<gfx::mojom::SizeF, gfx::SizeF> { 109 struct StructTraits<T, gfx::SizeF> {
111 static float width(const gfx::SizeF& p) { return p.width(); } 110 static float width(const gfx::SizeF& p) { return p.width(); }
112 static float height(const gfx::SizeF& p) { return p.height(); } 111 static float height(const gfx::SizeF& p) { return p.height(); }
113 static bool Read(gfx::mojom::SizeFDataView data, gfx::SizeF* out) { 112 static bool Read(typename T::DataView data, gfx::SizeF* out) {
114 if (data.width() < 0 || data.height() < 0) 113 if (data.width() < 0 || data.height() < 0)
115 return false; 114 return false;
116 115
117 out->SetSize(data.width(), data.height()); 116 out->SetSize(data.width(), data.height());
118 return true; 117 return true;
119 } 118 }
120 }; 119 };
121 120
122 template <> 121 template <typename T>
123 struct StructTraits<gfx::mojom::Vector2d, gfx::Vector2d> { 122 struct StructTraits<T, gfx::Vector2d> {
124 static int x(const gfx::Vector2d& v) { return v.x(); } 123 static int x(const gfx::Vector2d& v) { return v.x(); }
125 static int y(const gfx::Vector2d& v) { return v.y(); } 124 static int y(const gfx::Vector2d& v) { return v.y(); }
126 static bool Read(gfx::mojom::Vector2dDataView data, gfx::Vector2d* out) { 125 static bool Read(typename T::DataView data, gfx::Vector2d* out) {
127 out->set_x(data.x()); 126 out->set_x(data.x());
128 out->set_y(data.y()); 127 out->set_y(data.y());
129 return true; 128 return true;
130 } 129 }
131 }; 130 };
132 131
133 template <> 132 template <typename T>
134 struct StructTraits<gfx::mojom::Vector2dF, gfx::Vector2dF> { 133 struct StructTraits<T, gfx::Vector2dF> {
135 static float x(const gfx::Vector2dF& v) { return v.x(); } 134 static float x(const gfx::Vector2dF& v) { return v.x(); }
136 static float y(const gfx::Vector2dF& v) { return v.y(); } 135 static float y(const gfx::Vector2dF& v) { return v.y(); }
137 static bool Read(gfx::mojom::Vector2dFDataView data, gfx::Vector2dF* out) { 136 static bool Read(typename T::DataView data, gfx::Vector2dF* out) {
138 out->set_x(data.x()); 137 out->set_x(data.x());
139 out->set_y(data.y()); 138 out->set_y(data.y());
140 return true; 139 return true;
141 } 140 }
142 }; 141 };
143 142
144 } // namespace mojo 143 } // namespace mojo
145 144
146 #endif // UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ 145 #endif // UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_
OLDNEW
« third_party/WebKit/public/blink.gyp ('K') | « third_party/WebKit/public/blink_typemaps.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698