Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / mojo / services / native_viewport / geometry_conversions.h
1 // Copyright 2014 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 MOJO_SERVICES_NATIVE_VIEWPORT_GEOMETRY_CONVERSIONS_H_
6 #define MOJO_SERVICES_NATIVE_VIEWPORT_GEOMETRY_CONVERSIONS_H_
7
8 #include "mojom/native_viewport.h"
9 #include "ui/gfx/rect.h"
10
11 namespace mojo {
12
13 template<>
14 class TypeConverter<Point, gfx::Point> {
15 public:
16   static Point ConvertFrom(const gfx::Point& input, Buffer* buf) {
17     Point::Builder point(buf);
18     point.set_x(input.x());
19     point.set_y(input.y());
20     return point.Finish();
21   }
22   static gfx::Point ConvertTo(const Point& input) {
23     return gfx::Point(input.x(), input.y());
24   }
25 };
26
27 template<>
28 class TypeConverter<Size, gfx::Size> {
29 public:
30   static Size ConvertFrom(const gfx::Size& input, Buffer* buf) {
31     mojo::AllocationScope scope;
32     Size::Builder size(buf);
33     size.set_width(input.width());
34     size.set_height(input.height());
35     return size.Finish();
36   }
37   static gfx::Size ConvertTo(const Size& input) {
38     return gfx::Size(input.width(), input.height());
39   }
40 };
41
42 template<>
43 class TypeConverter<Rect, gfx::Rect> {
44  public:
45   static Rect ConvertFrom(const gfx::Rect& input, Buffer* buf) {
46     Rect::Builder rect(buf);
47     rect.set_position(input.origin());
48     rect.set_size(input.size());
49     return rect.Finish();
50   }
51   static gfx::Rect ConvertTo(const Rect& input) {
52     return gfx::Rect(input.position().x(), input.position().y(),
53                      input.size().width(), input.size().height());
54   }
55 };
56
57 }  // namespace mojo
58
59 #endif  // MOJO_SERVICES_NATIVE_VIEWPORT_GEOMETRY_CONVERSIONS_H_