1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_GEOMETRY_MOJOM_GEOMETRY_MOJOM_TRAITS_H_
#define UI_GFX_GEOMETRY_MOJOM_GEOMETRY_MOJOM_TRAITS_H_
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/insets_f.h"
#include "ui/gfx/geometry/mojom/geometry.mojom-shared.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point3_f.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/quaternion.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/geometry/vector3d_f.h"
namespace mojo {
template <>
struct StructTraits<gfx::mojom::InsetsDataView, gfx::Insets> {
static int top(const gfx::Insets& p) { return p.top(); }
static int left(const gfx::Insets& p) { return p.left(); }
static int bottom(const gfx::Insets& p) { return p.bottom(); }
static int right(const gfx::Insets& p) { return p.right(); }
static bool Read(gfx::mojom::InsetsDataView data, gfx::Insets* out) {
*out =
gfx::Insets::TLBR(data.top(), data.left(), data.bottom(), data.right());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::InsetsFDataView, gfx::InsetsF> {
static float top(const gfx::InsetsF& p) { return p.top(); }
static float left(const gfx::InsetsF& p) { return p.left(); }
static float bottom(const gfx::InsetsF& p) { return p.bottom(); }
static float right(const gfx::InsetsF& p) { return p.right(); }
static bool Read(gfx::mojom::InsetsFDataView data, gfx::InsetsF* out) {
*out = gfx::InsetsF::TLBR(data.top(), data.left(), data.bottom(),
data.right());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::PointDataView, gfx::Point> {
static int x(const gfx::Point& p) { return p.x(); }
static int y(const gfx::Point& p) { return p.y(); }
static bool Read(gfx::mojom::PointDataView data, gfx::Point* out) {
out->SetPoint(data.x(), data.y());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::PointFDataView, gfx::PointF> {
static float x(const gfx::PointF& p) { return p.x(); }
static float y(const gfx::PointF& p) { return p.y(); }
static bool Read(gfx::mojom::PointFDataView data, gfx::PointF* out) {
out->SetPoint(data.x(), data.y());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::Point3FDataView, gfx::Point3F> {
static float x(const gfx::Point3F& p) { return p.x(); }
static float y(const gfx::Point3F& p) { return p.y(); }
static float z(const gfx::Point3F& p) { return p.z(); }
static bool Read(gfx::mojom::Point3FDataView data, gfx::Point3F* out) {
out->SetPoint(data.x(), data.y(), data.z());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::RectDataView, gfx::Rect> {
static int x(const gfx::Rect& p) { return p.x(); }
static int y(const gfx::Rect& p) { return p.y(); }
static int width(const gfx::Rect& p) { return p.width(); }
static int height(const gfx::Rect& p) { return p.height(); }
static bool Read(gfx::mojom::RectDataView data, gfx::Rect* out) {
if (data.width() < 0 || data.height() < 0)
return false;
out->SetRect(data.x(), data.y(), data.width(), data.height());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::RectFDataView, gfx::RectF> {
static float x(const gfx::RectF& p) { return p.x(); }
static float y(const gfx::RectF& p) { return p.y(); }
static float width(const gfx::RectF& p) { return p.width(); }
static float height(const gfx::RectF& p) { return p.height(); }
static bool Read(gfx::mojom::RectFDataView data, gfx::RectF* out) {
if (data.width() < 0 || data.height() < 0)
return false;
out->SetRect(data.x(), data.y(), data.width(), data.height());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::SizeDataView, gfx::Size> {
static int width(const gfx::Size& p) { return p.width(); }
static int height(const gfx::Size& p) { return p.height(); }
static bool Read(gfx::mojom::SizeDataView data, gfx::Size* out) {
if (data.width() < 0 || data.height() < 0)
return false;
out->SetSize(data.width(), data.height());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::SizeFDataView, gfx::SizeF> {
static float width(const gfx::SizeF& p) { return p.width(); }
static float height(const gfx::SizeF& p) { return p.height(); }
static bool Read(gfx::mojom::SizeFDataView data, gfx::SizeF* out) {
if (data.width() < 0 || data.height() < 0)
return false;
out->SetSize(data.width(), data.height());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::Vector2dDataView, gfx::Vector2d> {
static int x(const gfx::Vector2d& v) { return v.x(); }
static int y(const gfx::Vector2d& v) { return v.y(); }
static bool Read(gfx::mojom::Vector2dDataView data, gfx::Vector2d* out) {
out->set_x(data.x());
out->set_y(data.y());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::Vector2dFDataView, gfx::Vector2dF> {
static float x(const gfx::Vector2dF& v) { return v.x(); }
static float y(const gfx::Vector2dF& v) { return v.y(); }
static bool Read(gfx::mojom::Vector2dFDataView data, gfx::Vector2dF* out) {
out->set_x(data.x());
out->set_y(data.y());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::Vector3dFDataView, gfx::Vector3dF> {
static float x(const gfx::Vector3dF& v) { return v.x(); }
static float y(const gfx::Vector3dF& v) { return v.y(); }
static float z(const gfx::Vector3dF& v) { return v.z(); }
static bool Read(gfx::mojom::Vector3dFDataView data, gfx::Vector3dF* out) {
out->set_x(data.x());
out->set_y(data.y());
out->set_z(data.z());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::QuaternionDataView, gfx::Quaternion> {
static double x(const gfx::Quaternion& q) { return q.x(); }
static double y(const gfx::Quaternion& q) { return q.y(); }
static double z(const gfx::Quaternion& q) { return q.z(); }
static double w(const gfx::Quaternion& q) { return q.w(); }
static bool Read(gfx::mojom::QuaternionDataView data, gfx::Quaternion* out) {
out->set_x(data.x());
out->set_y(data.y());
out->set_z(data.z());
out->set_w(data.w());
return true;
}
};
template <>
struct StructTraits<gfx::mojom::QuadFDataView, gfx::QuadF> {
static gfx::PointF p1(const gfx::QuadF& q) { return q.p1(); }
static gfx::PointF p2(const gfx::QuadF& q) { return q.p2(); }
static gfx::PointF p3(const gfx::QuadF& q) { return q.p3(); }
static gfx::PointF p4(const gfx::QuadF& q) { return q.p4(); }
static bool Read(gfx::mojom::QuadFDataView data, gfx::QuadF* out) {
gfx::PointF p1;
if (!data.ReadP1(&p1)) {
return false;
}
out->set_p1(p1);
gfx::PointF p2;
if (!data.ReadP2(&p2)) {
return false;
}
out->set_p2(p2);
gfx::PointF p3;
if (!data.ReadP3(&p3)) {
return false;
}
out->set_p3(p3);
gfx::PointF p4;
if (!data.ReadP4(&p4)) {
return false;
}
out->set_p4(p4);
return true;
}
};
} // namespace mojo
#endif // UI_GFX_GEOMETRY_MOJOM_GEOMETRY_MOJOM_TRAITS_H_
|