summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppb_widget_impl.cc
blob: 89a0c06986c470d5c0058a70adfb0debc918e09a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/plugins/ppapi/ppb_widget_impl.h"

#include "base/logging.h"
#include "ppapi/c/dev/ppb_widget_dev.h"
#include "ppapi/c/dev/ppp_widget_dev.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_errors.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/ppb_image_data_impl.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/plugin_module.h"

namespace webkit {
namespace ppapi {

namespace {

PP_Bool IsWidget(PP_Resource resource) {
  return BoolToPPBool(!!Resource::GetAs<PPB_Widget_Impl>(resource));
}

PP_Bool Paint(PP_Resource resource,
              const PP_Rect* rect,
              PP_Resource image_id) {
  scoped_refptr<PPB_Widget_Impl> widget(
      Resource::GetAs<PPB_Widget_Impl>(resource));
  if (!widget)
    return PP_FALSE;

  scoped_refptr<PPB_ImageData_Impl> image(
      Resource::GetAs<PPB_ImageData_Impl>(image_id));
  if (!image)
    return PP_FALSE;

  return BoolToPPBool(widget->Paint(rect, image));
}

PP_Bool HandleEvent(PP_Resource resource, const PP_InputEvent* event) {
  scoped_refptr<PPB_Widget_Impl> widget(
      Resource::GetAs<PPB_Widget_Impl>(resource));
  return BoolToPPBool(widget && widget->HandleEvent(event));
}

PP_Bool GetLocation(PP_Resource resource, PP_Rect* location) {
  scoped_refptr<PPB_Widget_Impl> widget(
      Resource::GetAs<PPB_Widget_Impl>(resource));
  return BoolToPPBool(widget && widget->GetLocation(location));
}

void SetLocation(PP_Resource resource, const PP_Rect* location) {
  scoped_refptr<PPB_Widget_Impl> widget(
      Resource::GetAs<PPB_Widget_Impl>(resource));
  if (widget)
    widget->SetLocation(location);
}

const PPB_Widget_Dev ppb_widget = {
  &IsWidget,
  &Paint,
  &HandleEvent,
  &GetLocation,
  &SetLocation,
};

}  // namespace

PPB_Widget_Impl::PPB_Widget_Impl(PluginInstance* instance)
    : Resource(instance) {
}

PPB_Widget_Impl::~PPB_Widget_Impl() {
}

// static
const PPB_Widget_Dev* PPB_Widget_Impl::GetInterface() {
  return &ppb_widget;
}

PPB_Widget_Impl* PPB_Widget_Impl::AsPPB_Widget_Impl() {
  return this;
}

bool PPB_Widget_Impl::GetLocation(PP_Rect* location) {
  *location = location_;
  return true;
}

void PPB_Widget_Impl::SetLocation(const PP_Rect* location) {
  location_ = *location;
  SetLocationInternal(location);
}

void PPB_Widget_Impl::Invalidate(const PP_Rect* dirty) {
  const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>(
      instance()->module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE));
  if (!widget)
    return;
  ScopedResourceId resource(this);
  widget->Invalidate(instance_->pp_instance(), resource.id, dirty);
}

}  // namespace ppapi
}  // namespace webkit