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/public/interfaces/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 struct TypeConverter<PointPtr, PP_Point> { 18 static PointPtr Convert(const PP_Point& input) { 19 PointPtr point(Point::New()); 20 point->x = input.x; 21 point->y = input.y; 22 return point.Pass(); 23 } 24 }; 25 26 template <> 27 struct TypeConverter<PP_Point, PointPtr> { 28 static PP_Point Convert(const PointPtr& input) { 29 if (!input) 30 return PP_MakePoint(0, 0); 31 return PP_MakePoint(static_cast<int32_t>(input->x), 32 static_cast<int32_t>(input->y)); 33 } 34 }; 35 36 template <> 37 struct TypeConverter<SizePtr, PP_Size> { 38 static SizePtr Convert(const PP_Size& input) { 39 SizePtr size(Size::New()); 40 size->width = input.width; 41 size->height = input.height; 42 return size.Pass(); 43 } 44 }; 45 46 template <> 47 struct TypeConverter<PP_Size, SizePtr> { 48 static PP_Size Convert(const SizePtr& input) { 49 if (!input) 50 return PP_MakeSize(0, 0); 51 return PP_MakeSize(static_cast<int32_t>(input->width), 52 static_cast<int32_t>(input->height)); 53 } 54 }; 55 56 template <> 57 struct TypeConverter<RectPtr, PP_Rect> { 58 static RectPtr Convert(const PP_Rect& input) { 59 RectPtr rect(Rect::New()); 60 rect->x = input.point.x; 61 rect->y = input.point.y; 62 rect->width = input.size.width; 63 rect->height = input.size.height; 64 return rect.Pass(); 65 } 66 }; 67 68 template <> 69 struct TypeConverter<PP_Rect, SizePtr> { 70 static PP_Rect Convert(const SizePtr& input) { 71 if (!input) 72 return PP_MakeRectFromXYWH(0, 0, 0, 0); 73 return PP_MakeRectFromXYWH(0, 0, input->width, input->height); 74 } 75 }; 76 77 } // namespace mojo 78 79 #endif // MOJO_EXAMPLES_PEPPER_CONTAINER_APP_TYPE_CONVERTERS_H_ 80