1 // Copyright (c) 2010 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.
5 #include "ppapi/cpp/dev/widget_dev.h"
7 #include "ppapi/c/dev/ppb_widget_dev.h"
8 #include "ppapi/cpp/image_data.h"
9 #include "ppapi/cpp/input_event.h"
10 #include "ppapi/cpp/instance.h"
11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/rect.h"
13 #include "ppapi/cpp/module_impl.h"
19 template <> const char* interface_name
<PPB_Widget_Dev_0_3
>() {
20 return PPB_WIDGET_DEV_INTERFACE_0_3
;
23 template <> const char* interface_name
<PPB_Widget_Dev_0_4
>() {
24 return PPB_WIDGET_DEV_INTERFACE_0_4
;
29 Widget_Dev::Widget_Dev(PP_Resource resource
) : Resource(resource
) {
32 Widget_Dev::Widget_Dev(const Widget_Dev
& other
) : Resource(other
) {
35 bool Widget_Dev::Paint(const Rect
& rect
, ImageData
* image
) {
36 if (has_interface
<PPB_Widget_Dev_0_4
>()) {
37 return PP_ToBool(get_interface
<PPB_Widget_Dev_0_4
>()->Paint(
38 pp_resource(), &rect
.pp_rect(), image
->pp_resource()));
39 } else if (has_interface
<PPB_Widget_Dev_0_3
>()) {
40 return PP_ToBool(get_interface
<PPB_Widget_Dev_0_3
>()->Paint(
41 pp_resource(), &rect
.pp_rect(), image
->pp_resource()));
46 bool Widget_Dev::HandleEvent(const InputEvent
& event
) {
47 if (has_interface
<PPB_Widget_Dev_0_4
>()) {
48 return PP_ToBool(get_interface
<PPB_Widget_Dev_0_4
>()->HandleEvent(
49 pp_resource(), event
.pp_resource()));
50 } else if (has_interface
<PPB_Widget_Dev_0_3
>()) {
51 return PP_ToBool(get_interface
<PPB_Widget_Dev_0_3
>()->HandleEvent(
52 pp_resource(), event
.pp_resource()));
57 bool Widget_Dev::GetLocation(Rect
* location
) {
58 if (has_interface
<PPB_Widget_Dev_0_4
>()) {
59 return PP_ToBool(get_interface
<PPB_Widget_Dev_0_4
>()->GetLocation(
60 pp_resource(), &location
->pp_rect()));
61 } else if (has_interface
<PPB_Widget_Dev_0_3
>()) {
62 return PP_ToBool(get_interface
<PPB_Widget_Dev_0_3
>()->GetLocation(
63 pp_resource(), &location
->pp_rect()));
68 void Widget_Dev::SetLocation(const Rect
& location
) {
69 if (has_interface
<PPB_Widget_Dev_0_4
>()) {
70 get_interface
<PPB_Widget_Dev_0_4
>()->SetLocation(pp_resource(),
72 } else if (has_interface
<PPB_Widget_Dev_0_3
>()) {
73 get_interface
<PPB_Widget_Dev_0_3
>()->SetLocation(pp_resource(),
78 void Widget_Dev::SetScale(float scale
) {
79 if (has_interface
<PPB_Widget_Dev_0_4
>())
80 get_interface
<PPB_Widget_Dev_0_4
>()->SetScale(pp_resource(), scale
);