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