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 "third_party/ppapi/c/pp_completion_callback.h" |
| 9 #include "third_party/ppapi/c/pp_errors.h" |
| 10 #include "third_party/ppapi/c/ppb_widget.h" |
| 11 #include "third_party/ppapi/c/ppp_widget.h" |
| 12 #include "webkit/glue/plugins/pepper_image_data.h" |
| 13 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
| 14 #include "webkit/glue/plugins/pepper_plugin_module.h" |
| 15 |
| 16 namespace pepper { |
| 17 |
| 18 namespace { |
| 19 |
| 20 bool IsWidget(PP_Resource resource) { |
| 21 return !!Resource::GetAs<Widget>(resource).get(); |
| 22 } |
| 23 |
| 24 bool Paint(PP_Resource resource, const PP_Rect* rect, PP_Resource image_id) { |
| 25 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); |
| 26 if (!widget.get()) |
| 27 return false; |
| 28 |
| 29 scoped_refptr<ImageData> image(Resource::GetAs<ImageData>(image_id)); |
| 30 return widget.get() && widget->Paint(rect, image); |
| 31 } |
| 32 |
| 33 bool HandleEvent(PP_Resource resource, const PP_Event* event) { |
| 34 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); |
| 35 return widget.get() && widget->HandleEvent(event); |
| 36 } |
| 37 |
| 38 bool GetLocation(PP_Resource resource, PP_Rect* location) { |
| 39 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); |
| 40 return widget.get() && widget->GetLocation(location); |
| 41 } |
| 42 |
| 43 void SetLocation(PP_Resource resource, const PP_Rect* location) { |
| 44 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); |
| 45 if (widget.get()) |
| 46 widget->SetLocation(location); |
| 47 } |
| 48 |
| 49 const PPB_Widget ppb_widget = { |
| 50 &IsWidget, |
| 51 &Paint, |
| 52 &HandleEvent, |
| 53 &GetLocation, |
| 54 &SetLocation, |
| 55 }; |
| 56 |
| 57 } // namespace |
| 58 |
| 59 Widget::Widget(PluginInstance* instance) |
| 60 : Resource(instance->module()), |
| 61 instance_(instance) { |
| 62 } |
| 63 |
| 64 Widget::~Widget() { |
| 65 } |
| 66 |
| 67 // static |
| 68 const PPB_Widget* Widget::GetInterface() { |
| 69 return &ppb_widget; |
| 70 } |
| 71 |
| 72 bool Widget::GetLocation(PP_Rect* location) { |
| 73 *location = location_; |
| 74 return true; |
| 75 } |
| 76 |
| 77 void Widget::SetLocation(const PP_Rect* location) { |
| 78 location_ = *location; |
| 79 SetLocationInternal(location); |
| 80 } |
| 81 |
| 82 void Widget::Invalidate(const PP_Rect* dirty) { |
| 83 const PPP_Widget* widget = static_cast<const PPP_Widget*>( |
| 84 module()->GetPluginInterface(PPP_WIDGET_INTERFACE)); |
| 85 if (!widget) |
| 86 return; |
| 87 widget->Invalidate(instance_->GetPPInstance(), GetResource(), dirty); |
| 88 } |
| 89 |
| 90 } // namespace pepper |
OLD | NEW |