Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / mojo / examples / pepper_container_app / type_converters.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_EXAMPLES_PEPPER_CONTAINER_APP_TYPE_CONVERTERS_H_
6 #define MOJO_EXAMPLES_PEPPER_CONTAINER_APP_TYPE_CONVERTERS_H_
7
8 #include "mojo/public/cpp/bindings/type_converter.h"
9 #include "mojo/services/native_viewport/native_viewport.mojom.h"
10 #include "ppapi/c/pp_point.h"
11 #include "ppapi/c/pp_rect.h"
12 #include "ppapi/c/pp_size.h"
13
14 namespace mojo {
15
16 template <>
17 class TypeConverter<Point, PP_Point> {
18  public:
19   static Point ConvertFrom(const PP_Point& input, Buffer* buf) {
20     Point::Builder point(buf);
21     point.set_x(input.x);
22     point.set_y(input.y);
23     return point.Finish();
24   }
25
26   static PP_Point ConvertTo(const Point& input) {
27     return PP_MakePoint(static_cast<int32_t>(input.x()),
28                         static_cast<int32_t>(input.y()));
29   }
30
31   MOJO_ALLOW_IMPLICIT_TYPE_CONVERSION();
32 };
33
34 template <>
35 class TypeConverter<Size, PP_Size> {
36  public:
37   static Size ConvertFrom(const PP_Size& input, Buffer* buf) {
38     Size::Builder size(buf);
39     size.set_width(input.width);
40     size.set_height(input.height);
41     return size.Finish();
42   }
43
44   static PP_Size ConvertTo(const Size& input) {
45     return PP_MakeSize(static_cast<int32_t>(input.width()),
46                        static_cast<int32_t>(input.height()));
47   }
48
49   MOJO_ALLOW_IMPLICIT_TYPE_CONVERSION();
50 };
51
52 template <>
53 class TypeConverter<Rect, PP_Rect> {
54  public:
55   static Rect ConvertFrom(const PP_Rect& input, Buffer* buf) {
56     Rect::Builder rect(buf);
57     rect.set_position(input.point);
58     rect.set_size(input.size);
59     return rect.Finish();
60   }
61
62   static PP_Rect ConvertTo(const Rect& input) {
63     PP_Rect rect = { input.position().To<PP_Point>(),
64                      input.size().To<PP_Size>() };
65     return rect;
66   }
67
68   MOJO_ALLOW_IMPLICIT_TYPE_CONVERSION();
69 };
70
71 }  // namespace mojo
72
73 #endif  // MOJO_EXAMPLES_PEPPER_CONTAINER_APP_TYPE_CONVERTERS_H_