diff options
author | Hidehiko Abe <hidehiko@google.com> | 2018-04-24 01:37:19 +0900 |
---|---|---|
committer | Hidehiko Abe <hidehiko@google.com> | 2018-04-24 03:09:01 +0900 |
commit | b268b43ac6fdbc4f3a2ed1429b99ace424906090 (patch) | |
tree | bd2d04362f66c36d4279f7a9735ba21ea3a2a021 /ui | |
parent | 4a54b98aa445f521c6945e4f4a1e0ea788fa7da8 (diff) | |
download | libchrome-b268b43ac6fdbc4f3a2ed1429b99ace424906090.tar.gz |
Migrate libmojo repository into libchrome, part 2.
This CL moves following files.
- .gitignore
- Android.bp is merged into libchrome's Android.bp.
- base/android/*
- build/* except build_config.h which is exactly same with libchrome's.
- ipc/*
- mojo/* except mojo/public/tools/bindings/generators/__init__.py
which is unused and not in chrome repository.
- soong/* into libchrome_tools/
- third_party/{catapult,jinja2,markupsafe,ply}/*
- ui/gfx/{geometry,range}/mojo/*
Then, update several paths/build rules to be adapted.
Bug: 73606903
Test: Built locally. Ran on DUT.
Change-Id: I2a532a42aa68dcb215dbd71d8673192311509726
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/geometry/mojo/BUILD.gn | 49 | ||||
-rw-r--r-- | ui/gfx/geometry/mojo/DEPS | 4 | ||||
-rw-r--r-- | ui/gfx/geometry/mojo/geometry.mojom | 63 | ||||
-rw-r--r-- | ui/gfx/geometry/mojo/geometry.typemap | 32 | ||||
-rw-r--r-- | ui/gfx/geometry/mojo/geometry_struct_traits.h | 146 | ||||
-rw-r--r-- | ui/gfx/geometry/mojo/geometry_struct_traits_unittest.cc | 206 | ||||
-rw-r--r-- | ui/gfx/geometry/mojo/geometry_traits_test_service.mojom | 41 | ||||
-rw-r--r-- | ui/gfx/range/mojo/BUILD.gn | 49 | ||||
-rw-r--r-- | ui/gfx/range/mojo/DEPS | 4 | ||||
-rw-r--r-- | ui/gfx/range/mojo/range.mojom | 15 | ||||
-rw-r--r-- | ui/gfx/range/mojo/range.typemap | 17 | ||||
-rw-r--r-- | ui/gfx/range/mojo/range_struct_traits.h | 38 | ||||
-rw-r--r-- | ui/gfx/range/mojo/range_struct_traits_unittest.cc | 65 | ||||
-rw-r--r-- | ui/gfx/range/mojo/range_traits_test_service.mojom | 17 |
14 files changed, 746 insertions, 0 deletions
diff --git a/ui/gfx/geometry/mojo/BUILD.gn b/ui/gfx/geometry/mojo/BUILD.gn new file mode 100644 index 0000000000..f6cda9d3be --- /dev/null +++ b/ui/gfx/geometry/mojo/BUILD.gn @@ -0,0 +1,49 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//mojo/public/tools/bindings/mojom.gni") + +# This target does NOT depend on skia. One can depend on this target to avoid +# picking up a dependency on skia. +mojom("mojo") { + sources = [ + "geometry.mojom", + ] +} + +mojom("test_interfaces") { + sources = [ + "geometry_traits_test_service.mojom", + ] + + public_deps = [ + ":mojo", + ] +} + +source_set("unit_test") { + testonly = true + + sources = [ + "geometry_struct_traits_unittest.cc", + ] + + deps = [ + ":test_interfaces", + "//base", + "//mojo/public/cpp/bindings", + "//testing/gtest", + "//ui/gfx/geometry", + ] +} + +source_set("struct_traits") { + sources = [ + "geometry_struct_traits.h", + ] + public_deps = [ + ":mojo_shared_cpp_sources", + "//ui/gfx/geometry", + ] +} diff --git a/ui/gfx/geometry/mojo/DEPS b/ui/gfx/geometry/mojo/DEPS new file mode 100644 index 0000000000..3ad6543823 --- /dev/null +++ b/ui/gfx/geometry/mojo/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+mojo/public", + "+ui/gfx/geometry", +] diff --git a/ui/gfx/geometry/mojo/geometry.mojom b/ui/gfx/geometry/mojo/geometry.mojom new file mode 100644 index 0000000000..97143866da --- /dev/null +++ b/ui/gfx/geometry/mojo/geometry.mojom @@ -0,0 +1,63 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module gfx.mojom; + +struct Point { + int32 x; + int32 y; +}; + +struct PointF { + float x; + float y; +}; + +struct Size { + int32 width; + int32 height; +}; + +struct SizeF { + float width; + float height; +}; + +struct Rect { + int32 x; + int32 y; + int32 width; + int32 height; +}; + +struct RectF { + float x; + float y; + float width; + float height; +}; + +struct Insets { + int32 top; + int32 left; + int32 bottom; + int32 right; +}; + +struct InsetsF { + float top; + float left; + float bottom; + float right; +}; + +struct Vector2d { + int32 x; + int32 y; +}; + +struct Vector2dF { + float x; + float y; +}; diff --git a/ui/gfx/geometry/mojo/geometry.typemap b/ui/gfx/geometry/mojo/geometry.typemap new file mode 100644 index 0000000000..686ea05cfb --- /dev/null +++ b/ui/gfx/geometry/mojo/geometry.typemap @@ -0,0 +1,32 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +mojom = "//ui/gfx/geometry/mojo/geometry.mojom" +public_headers = [ + "//ui/gfx/geometry/point.h", + "//ui/gfx/geometry/point_f.h", + "//ui/gfx/geometry/size.h", + "//ui/gfx/geometry/rect.h", + "//ui/gfx/geometry/rect_f.h", + "//ui/gfx/geometry/safe_integer_conversions.h", + "//ui/gfx/geometry/insets.h", + "//ui/gfx/geometry/vector2d.h", + "//ui/gfx/geometry/vector2d_f.h", +] +traits_headers = [ "//ui/gfx/geometry/mojo/geometry_struct_traits.h" ] +deps = [ + "//ui/gfx/geometry/mojo:struct_traits", +] +type_mappings = [ + "gfx.mojom.Point=gfx::Point", + "gfx.mojom.PointF=gfx::PointF", + "gfx.mojom.Size=gfx::Size", + "gfx.mojom.SizeF=gfx::SizeF", + "gfx.mojom.Rect=gfx::Rect", + "gfx.mojom.RectF=gfx::RectF", + "gfx.mojom.Insets=gfx::Insets", + "gfx.mojom.InsetsF=gfx::InsetsF", + "gfx.mojom.Vector2d=gfx::Vector2d", + "gfx.mojom.Vector2dF=gfx::Vector2dF", +] diff --git a/ui/gfx/geometry/mojo/geometry_struct_traits.h b/ui/gfx/geometry/mojo/geometry_struct_traits.h new file mode 100644 index 0000000000..a31d7385b6 --- /dev/null +++ b/ui/gfx/geometry/mojo/geometry_struct_traits.h @@ -0,0 +1,146 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ +#define UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ + +#include "ui/gfx/geometry/insets.h" +#include "ui/gfx/geometry/insets_f.h" +#include "ui/gfx/geometry/mojo/geometry.mojom-shared.h" +#include "ui/gfx/geometry/point.h" +#include "ui/gfx/geometry/point_f.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" + +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->Set(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->Set(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::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; + } +}; + +} // namespace mojo + +#endif // UI_GFX_GEOMETRY_MOJO_GEOMETRY_STRUCT_TRAITS_H_ diff --git a/ui/gfx/geometry/mojo/geometry_struct_traits_unittest.cc b/ui/gfx/geometry/mojo/geometry_struct_traits_unittest.cc new file mode 100644 index 0000000000..d59579443a --- /dev/null +++ b/ui/gfx/geometry/mojo/geometry_struct_traits_unittest.cc @@ -0,0 +1,206 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/message_loop/message_loop.h" +#include "mojo/public/cpp/bindings/binding_set.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/geometry/mojo/geometry_traits_test_service.mojom.h" +#include "ui/gfx/geometry/point.h" + +namespace gfx { + +namespace { + +class GeometryStructTraitsTest : public testing::Test, + public mojom::GeometryTraitsTestService { + public: + GeometryStructTraitsTest() {} + + protected: + mojom::GeometryTraitsTestServicePtr GetTraitsTestProxy() { + return traits_test_bindings_.CreateInterfacePtrAndBind(this); + } + + private: + // GeometryTraitsTestService: + void EchoPoint(const Point& p, const EchoPointCallback& callback) override { + callback.Run(p); + } + + void EchoPointF(const PointF& p, + const EchoPointFCallback& callback) override { + callback.Run(p); + } + + void EchoSize(const Size& s, const EchoSizeCallback& callback) override { + callback.Run(s); + } + + void EchoSizeF(const SizeF& s, const EchoSizeFCallback& callback) override { + callback.Run(s); + } + + void EchoRect(const Rect& r, const EchoRectCallback& callback) override { + callback.Run(r); + } + + void EchoRectF(const RectF& r, const EchoRectFCallback& callback) override { + callback.Run(r); + } + + void EchoInsets(const Insets& i, + const EchoInsetsCallback& callback) override { + callback.Run(i); + } + + void EchoInsetsF(const InsetsF& i, + const EchoInsetsFCallback& callback) override { + callback.Run(i); + } + + void EchoVector2d(const Vector2d& v, + const EchoVector2dCallback& callback) override { + callback.Run(v); + } + + void EchoVector2dF(const Vector2dF& v, + const EchoVector2dFCallback& callback) override { + callback.Run(v); + } + + base::MessageLoop loop_; + mojo::BindingSet<GeometryTraitsTestService> traits_test_bindings_; + + DISALLOW_COPY_AND_ASSIGN(GeometryStructTraitsTest); +}; + +} // namespace + +TEST_F(GeometryStructTraitsTest, Point) { + const int32_t x = 1234; + const int32_t y = -5678; + gfx::Point input(x, y); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::Point output; + proxy->EchoPoint(input, &output); + EXPECT_EQ(x, output.x()); + EXPECT_EQ(y, output.y()); +} + +TEST_F(GeometryStructTraitsTest, PointF) { + const float x = 1234.5f; + const float y = 6789.6f; + gfx::PointF input(x, y); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::PointF output; + proxy->EchoPointF(input, &output); + EXPECT_EQ(x, output.x()); + EXPECT_EQ(y, output.y()); +} + +TEST_F(GeometryStructTraitsTest, Size) { + const int32_t width = 1234; + const int32_t height = 5678; + gfx::Size input(width, height); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::Size output; + proxy->EchoSize(input, &output); + EXPECT_EQ(width, output.width()); + EXPECT_EQ(height, output.height()); +} + +TEST_F(GeometryStructTraitsTest, SizeF) { + const float width = 1234.5f; + const float height = 6789.6f; + gfx::SizeF input(width, height); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::SizeF output; + proxy->EchoSizeF(input, &output); + EXPECT_EQ(width, output.width()); + EXPECT_EQ(height, output.height()); +} + +TEST_F(GeometryStructTraitsTest, Rect) { + const int32_t x = 1234; + const int32_t y = 5678; + const int32_t width = 4321; + const int32_t height = 8765; + gfx::Rect input(x, y, width, height); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::Rect output; + proxy->EchoRect(input, &output); + EXPECT_EQ(x, output.x()); + EXPECT_EQ(y, output.y()); + EXPECT_EQ(width, output.width()); + EXPECT_EQ(height, output.height()); +} + +TEST_F(GeometryStructTraitsTest, RectF) { + const float x = 1234.1f; + const float y = 5678.2f; + const float width = 4321.3f; + const float height = 8765.4f; + gfx::RectF input(x, y, width, height); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::RectF output; + proxy->EchoRectF(input, &output); + EXPECT_EQ(x, output.x()); + EXPECT_EQ(y, output.y()); + EXPECT_EQ(width, output.width()); + EXPECT_EQ(height, output.height()); +} + +TEST_F(GeometryStructTraitsTest, Insets) { + const int32_t top = 1234; + const int32_t left = 5678; + const int32_t bottom = 4321; + const int32_t right = 8765; + gfx::Insets input(top, left, bottom, right); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::Insets output; + proxy->EchoInsets(input, &output); + EXPECT_EQ(top, output.top()); + EXPECT_EQ(left, output.left()); + EXPECT_EQ(bottom, output.bottom()); + EXPECT_EQ(right, output.right()); +} + +TEST_F(GeometryStructTraitsTest, InsetsF) { + const float top = 1234.1f; + const float left = 5678.2f; + const float bottom = 4321.3f; + const float right = 8765.4f; + gfx::InsetsF input(top, left, bottom, right); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::InsetsF output; + proxy->EchoInsetsF(input, &output); + EXPECT_EQ(top, output.top()); + EXPECT_EQ(left, output.left()); + EXPECT_EQ(bottom, output.bottom()); + EXPECT_EQ(right, output.right()); +} + +TEST_F(GeometryStructTraitsTest, Vector2d) { + const int32_t x = 1234; + const int32_t y = -5678; + gfx::Vector2d input(x, y); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::Vector2d output; + proxy->EchoVector2d(input, &output); + EXPECT_EQ(x, output.x()); + EXPECT_EQ(y, output.y()); +} + +TEST_F(GeometryStructTraitsTest, Vector2dF) { + const float x = 1234.5f; + const float y = 6789.6f; + gfx::Vector2dF input(x, y); + mojom::GeometryTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::Vector2dF output; + proxy->EchoVector2dF(input, &output); + EXPECT_EQ(x, output.x()); + EXPECT_EQ(y, output.y()); +} + +} // namespace gfx diff --git a/ui/gfx/geometry/mojo/geometry_traits_test_service.mojom b/ui/gfx/geometry/mojo/geometry_traits_test_service.mojom new file mode 100644 index 0000000000..8d4fb94697 --- /dev/null +++ b/ui/gfx/geometry/mojo/geometry_traits_test_service.mojom @@ -0,0 +1,41 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module gfx.mojom; + +import "ui/gfx/geometry/mojo/geometry.mojom"; + +// All functions on this interface echo their arguments to test StructTraits +// serialization and deserialization. +interface GeometryTraitsTestService { + [Sync] + EchoPoint(Point p) => (Point pass); + + [Sync] + EchoPointF(PointF p) => (PointF pass); + + [Sync] + EchoSize(Size s) => (Size pass); + + [Sync] + EchoSizeF(SizeF s) => (SizeF pass); + + [Sync] + EchoRect(Rect r) => (Rect pass); + + [Sync] + EchoRectF(RectF r) => (RectF pass); + + [Sync] + EchoInsets(Insets i) => (Insets pass); + + [Sync] + EchoInsetsF(InsetsF i) => (InsetsF pass); + + [Sync] + EchoVector2d(Vector2d v) => (Vector2d pass); + + [Sync] + EchoVector2dF(Vector2dF v) => (Vector2dF pass); +}; diff --git a/ui/gfx/range/mojo/BUILD.gn b/ui/gfx/range/mojo/BUILD.gn new file mode 100644 index 0000000000..b6d458dbc9 --- /dev/null +++ b/ui/gfx/range/mojo/BUILD.gn @@ -0,0 +1,49 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//mojo/public/tools/bindings/mojom.gni") + +# This target does NOT depend on skia. One can depend on this target to avoid +# picking up a dependency on skia. +mojom("mojo") { + sources = [ + "range.mojom", + ] +} + +mojom("test_interfaces") { + sources = [ + "range_traits_test_service.mojom", + ] + + public_deps = [ + ":mojo", + ] +} + +source_set("unit_test") { + testonly = true + + sources = [ + "range_struct_traits_unittest.cc", + ] + + deps = [ + ":test_interfaces", + "//base", + "//mojo/public/cpp/bindings", + "//testing/gtest", + "//ui/gfx/range", + ] +} + +source_set("struct_traits") { + sources = [ + "range_struct_traits.h", + ] + public_deps = [ + ":mojo_shared_cpp_sources", + "//ui/gfx/range", + ] +} diff --git a/ui/gfx/range/mojo/DEPS b/ui/gfx/range/mojo/DEPS new file mode 100644 index 0000000000..418fc69e2e --- /dev/null +++ b/ui/gfx/range/mojo/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+mojo/public", + "+ui/gfx/range", +] diff --git a/ui/gfx/range/mojo/range.mojom b/ui/gfx/range/mojo/range.mojom new file mode 100644 index 0000000000..079c14611e --- /dev/null +++ b/ui/gfx/range/mojo/range.mojom @@ -0,0 +1,15 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module gfx.mojom; + +struct Range { + uint32 start; + uint32 end; +}; + +struct RangeF { + float start; + float end; +}; diff --git a/ui/gfx/range/mojo/range.typemap b/ui/gfx/range/mojo/range.typemap new file mode 100644 index 0000000000..ebf07d1478 --- /dev/null +++ b/ui/gfx/range/mojo/range.typemap @@ -0,0 +1,17 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +mojom = "//ui/gfx/range/mojo/range.mojom" +public_headers = [ + "//ui/gfx/range/range.h", + "//ui/gfx/range/range_f.h", +] +traits_headers = [ "//ui/gfx/range/mojo/range_struct_traits.h" ] +deps = [ + "//ui/gfx/range/mojo:struct_traits", +] +type_mappings = [ + "gfx.mojom.Range=gfx::Range", + "gfx.mojom.RangeF=gfx::RangeF", +] diff --git a/ui/gfx/range/mojo/range_struct_traits.h b/ui/gfx/range/mojo/range_struct_traits.h new file mode 100644 index 0000000000..e717d418c4 --- /dev/null +++ b/ui/gfx/range/mojo/range_struct_traits.h @@ -0,0 +1,38 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_RANGE_MOJO_RANGE_STRUCT_TRAITS_H_ +#define UI_GFX_RANGE_MOJO_RANGE_STRUCT_TRAITS_H_ + +#include "ui/gfx/range/mojo/range.mojom-shared.h" +#include "ui/gfx/range/range.h" +#include "ui/gfx/range/range_f.h" + +namespace mojo { + +template <> +struct StructTraits<gfx::mojom::RangeDataView, gfx::Range> { + static uint32_t start(const gfx::Range& r) { return r.start(); } + static uint32_t end(const gfx::Range& r) { return r.end(); } + static bool Read(gfx::mojom::RangeDataView data, gfx::Range* out) { + out->set_start(data.start()); + out->set_end(data.end()); + return true; + } +}; + +template <> +struct StructTraits<gfx::mojom::RangeFDataView, gfx::RangeF> { + static float start(const gfx::RangeF& r) { return r.start(); } + static float end(const gfx::RangeF& r) { return r.end(); } + static bool Read(gfx::mojom::RangeFDataView data, gfx::RangeF* out) { + out->set_start(data.start()); + out->set_end(data.end()); + return true; + } +}; + +} // namespace mojo + +#endif // UI_GFX_RANGE_MOJO_RANGE_STRUCT_TRAITS_H_ diff --git a/ui/gfx/range/mojo/range_struct_traits_unittest.cc b/ui/gfx/range/mojo/range_struct_traits_unittest.cc new file mode 100644 index 0000000000..70b32f3ff7 --- /dev/null +++ b/ui/gfx/range/mojo/range_struct_traits_unittest.cc @@ -0,0 +1,65 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/message_loop/message_loop.h" +#include "mojo/public/cpp/bindings/binding_set.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/gfx/range/mojo/range_traits_test_service.mojom.h" + +namespace gfx { + +namespace { + +class RangeStructTraitsTest : public testing::Test, + public mojom::RangeTraitsTestService { + public: + RangeStructTraitsTest() {} + + protected: + mojom::RangeTraitsTestServicePtr GetTraitsTestProxy() { + return traits_test_bindings_.CreateInterfacePtrAndBind(this); + } + + private: + // RangeTraitsTestService: + void EchoRange(const Range& p, const EchoRangeCallback& callback) override { + callback.Run(p); + } + + void EchoRangeF(const RangeF& p, + const EchoRangeFCallback& callback) override { + callback.Run(p); + } + + base::MessageLoop loop_; + mojo::BindingSet<RangeTraitsTestService> traits_test_bindings_; + + DISALLOW_COPY_AND_ASSIGN(RangeStructTraitsTest); +}; + +} // namespace + +TEST_F(RangeStructTraitsTest, Range) { + const uint32_t start = 1234; + const uint32_t end = 5678; + gfx::Range input(start, end); + mojom::RangeTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::Range output; + proxy->EchoRange(input, &output); + EXPECT_EQ(start, output.start()); + EXPECT_EQ(end, output.end()); +} + +TEST_F(RangeStructTraitsTest, RangeF) { + const float start = 1234.5f; + const float end = 6789.6f; + gfx::RangeF input(start, end); + mojom::RangeTraitsTestServicePtr proxy = GetTraitsTestProxy(); + gfx::RangeF output; + proxy->EchoRangeF(input, &output); + EXPECT_EQ(start, output.start()); + EXPECT_EQ(end, output.end()); +} + +} // namespace gfx diff --git a/ui/gfx/range/mojo/range_traits_test_service.mojom b/ui/gfx/range/mojo/range_traits_test_service.mojom new file mode 100644 index 0000000000..3cde75ca7d --- /dev/null +++ b/ui/gfx/range/mojo/range_traits_test_service.mojom @@ -0,0 +1,17 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module gfx.mojom; + +import "ui/gfx/range/mojo/range.mojom"; + +// All functions on this interface echo their arguments to test StructTraits +// serialization and deserialization. +interface RangeTraitsTestService { + [Sync] + EchoRange(Range p) => (Range pass); + + [Sync] + EchoRangeF(RangeF p) => (RangeF pass); +}; |