| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "webkit/glue/plugins/pepper_widget.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "ppapi/c/dev/ppb_widget_dev.h" | |
| 9 #include "ppapi/c/dev/ppp_widget_dev.h" | |
| 10 #include "ppapi/c/pp_completion_callback.h" | |
| 11 #include "ppapi/c/pp_errors.h" | |
| 12 #include "webkit/glue/plugins/pepper_common.h" | |
| 13 #include "webkit/glue/plugins/pepper_image_data.h" | |
| 14 #include "webkit/glue/plugins/pepper_plugin_instance.h" | |
| 15 #include "webkit/glue/plugins/pepper_plugin_module.h" | |
| 16 | |
| 17 namespace pepper { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 PP_Bool IsWidget(PP_Resource resource) { | |
| 22 return BoolToPPBool(!!Resource::GetAs<Widget>(resource)); | |
| 23 } | |
| 24 | |
| 25 PP_Bool Paint(PP_Resource resource, const PP_Rect* rect, PP_Resource image_id) { | |
| 26 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | |
| 27 if (!widget) | |
| 28 return PP_FALSE; | |
| 29 | |
| 30 scoped_refptr<ImageData> image(Resource::GetAs<ImageData>(image_id)); | |
| 31 if (!image) | |
| 32 return PP_FALSE; | |
| 33 | |
| 34 return BoolToPPBool(widget->Paint(rect, image)); | |
| 35 } | |
| 36 | |
| 37 PP_Bool HandleEvent(PP_Resource resource, const PP_InputEvent* event) { | |
| 38 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | |
| 39 return BoolToPPBool(widget && widget->HandleEvent(event)); | |
| 40 } | |
| 41 | |
| 42 PP_Bool GetLocation(PP_Resource resource, PP_Rect* location) { | |
| 43 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | |
| 44 return BoolToPPBool(widget && widget->GetLocation(location)); | |
| 45 } | |
| 46 | |
| 47 void SetLocation(PP_Resource resource, const PP_Rect* location) { | |
| 48 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | |
| 49 if (widget) | |
| 50 widget->SetLocation(location); | |
| 51 } | |
| 52 | |
| 53 const PPB_Widget_Dev ppb_widget = { | |
| 54 &IsWidget, | |
| 55 &Paint, | |
| 56 &HandleEvent, | |
| 57 &GetLocation, | |
| 58 &SetLocation, | |
| 59 }; | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 Widget::Widget(PluginInstance* instance) | |
| 64 : Resource(instance->module()), | |
| 65 instance_(instance) { | |
| 66 } | |
| 67 | |
| 68 Widget::~Widget() { | |
| 69 } | |
| 70 | |
| 71 // static | |
| 72 const PPB_Widget_Dev* Widget::GetInterface() { | |
| 73 return &ppb_widget; | |
| 74 } | |
| 75 | |
| 76 Widget* Widget::AsWidget() { | |
| 77 return this; | |
| 78 } | |
| 79 | |
| 80 bool Widget::GetLocation(PP_Rect* location) { | |
| 81 *location = location_; | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 void Widget::SetLocation(const PP_Rect* location) { | |
| 86 location_ = *location; | |
| 87 SetLocationInternal(location); | |
| 88 } | |
| 89 | |
| 90 void Widget::Invalidate(const PP_Rect* dirty) { | |
| 91 const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( | |
| 92 module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); | |
| 93 if (!widget) | |
| 94 return; | |
| 95 ScopedResourceId resource(this); | |
| 96 widget->Invalidate(instance_->pp_instance(), resource.id, dirty); | |
| 97 } | |
| 98 | |
| 99 } // namespace pepper | |
| OLD | NEW |