| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/plugins/pepper_widget.h" | 5 #include "webkit/plugins/ppapi/ppb_widget_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/dev/ppb_widget_dev.h" | 8 #include "ppapi/c/dev/ppb_widget_dev.h" |
| 9 #include "ppapi/c/dev/ppp_widget_dev.h" | 9 #include "ppapi/c/dev/ppp_widget_dev.h" |
| 10 #include "ppapi/c/pp_completion_callback.h" | 10 #include "ppapi/c/pp_completion_callback.h" |
| 11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
| 12 #include "webkit/glue/plugins/pepper_common.h" | 12 #include "webkit/plugins/ppapi/common.h" |
| 13 #include "webkit/glue/plugins/pepper_image_data.h" | 13 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 14 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 14 #include "webkit/plugins/ppapi/plugin_instance.h" |
| 15 #include "webkit/glue/plugins/pepper_plugin_module.h" | 15 #include "webkit/plugins/ppapi/plugin_module.h" |
| 16 | 16 |
| 17 namespace pepper { | 17 namespace webkit { |
| 18 namespace ppapi { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 PP_Bool IsWidget(PP_Resource resource) { | 22 PP_Bool IsWidget(PP_Resource resource) { |
| 22 return BoolToPPBool(!!Resource::GetAs<Widget>(resource)); | 23 return BoolToPPBool(!!Resource::GetAs<PPB_Widget_Impl>(resource)); |
| 23 } | 24 } |
| 24 | 25 |
| 25 PP_Bool Paint(PP_Resource resource, const PP_Rect* rect, PP_Resource image_id) { | 26 PP_Bool Paint(PP_Resource resource, |
| 26 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | 27 const PP_Rect* rect, |
| 28 PP_Resource image_id) { |
| 29 scoped_refptr<PPB_Widget_Impl> widget( |
| 30 Resource::GetAs<PPB_Widget_Impl>(resource)); |
| 27 if (!widget) | 31 if (!widget) |
| 28 return PP_FALSE; | 32 return PP_FALSE; |
| 29 | 33 |
| 30 scoped_refptr<ImageData> image(Resource::GetAs<ImageData>(image_id)); | 34 scoped_refptr<PPB_ImageData_Impl> image( |
| 35 Resource::GetAs<PPB_ImageData_Impl>(image_id)); |
| 31 if (!image) | 36 if (!image) |
| 32 return PP_FALSE; | 37 return PP_FALSE; |
| 33 | 38 |
| 34 return BoolToPPBool(widget->Paint(rect, image)); | 39 return BoolToPPBool(widget->Paint(rect, image)); |
| 35 } | 40 } |
| 36 | 41 |
| 37 PP_Bool HandleEvent(PP_Resource resource, const PP_InputEvent* event) { | 42 PP_Bool HandleEvent(PP_Resource resource, const PP_InputEvent* event) { |
| 38 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | 43 scoped_refptr<PPB_Widget_Impl> widget( |
| 44 Resource::GetAs<PPB_Widget_Impl>(resource)); |
| 39 return BoolToPPBool(widget && widget->HandleEvent(event)); | 45 return BoolToPPBool(widget && widget->HandleEvent(event)); |
| 40 } | 46 } |
| 41 | 47 |
| 42 PP_Bool GetLocation(PP_Resource resource, PP_Rect* location) { | 48 PP_Bool GetLocation(PP_Resource resource, PP_Rect* location) { |
| 43 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | 49 scoped_refptr<PPB_Widget_Impl> widget( |
| 50 Resource::GetAs<PPB_Widget_Impl>(resource)); |
| 44 return BoolToPPBool(widget && widget->GetLocation(location)); | 51 return BoolToPPBool(widget && widget->GetLocation(location)); |
| 45 } | 52 } |
| 46 | 53 |
| 47 void SetLocation(PP_Resource resource, const PP_Rect* location) { | 54 void SetLocation(PP_Resource resource, const PP_Rect* location) { |
| 48 scoped_refptr<Widget> widget(Resource::GetAs<Widget>(resource)); | 55 scoped_refptr<PPB_Widget_Impl> widget( |
| 56 Resource::GetAs<PPB_Widget_Impl>(resource)); |
| 49 if (widget) | 57 if (widget) |
| 50 widget->SetLocation(location); | 58 widget->SetLocation(location); |
| 51 } | 59 } |
| 52 | 60 |
| 53 const PPB_Widget_Dev ppb_widget = { | 61 const PPB_Widget_Dev ppb_widget = { |
| 54 &IsWidget, | 62 &IsWidget, |
| 55 &Paint, | 63 &Paint, |
| 56 &HandleEvent, | 64 &HandleEvent, |
| 57 &GetLocation, | 65 &GetLocation, |
| 58 &SetLocation, | 66 &SetLocation, |
| 59 }; | 67 }; |
| 60 | 68 |
| 61 } // namespace | 69 } // namespace |
| 62 | 70 |
| 63 Widget::Widget(PluginInstance* instance) | 71 PPB_Widget_Impl::PPB_Widget_Impl(PluginInstance* instance) |
| 64 : Resource(instance->module()), | 72 : Resource(instance->module()), |
| 65 instance_(instance) { | 73 instance_(instance) { |
| 66 } | 74 } |
| 67 | 75 |
| 68 Widget::~Widget() { | 76 PPB_Widget_Impl::~PPB_Widget_Impl() { |
| 69 } | 77 } |
| 70 | 78 |
| 71 // static | 79 // static |
| 72 const PPB_Widget_Dev* Widget::GetInterface() { | 80 const PPB_Widget_Dev* PPB_Widget_Impl::GetInterface() { |
| 73 return &ppb_widget; | 81 return &ppb_widget; |
| 74 } | 82 } |
| 75 | 83 |
| 76 Widget* Widget::AsWidget() { | 84 PPB_Widget_Impl* PPB_Widget_Impl::AsPPB_Widget_Impl() { |
| 77 return this; | 85 return this; |
| 78 } | 86 } |
| 79 | 87 |
| 80 bool Widget::GetLocation(PP_Rect* location) { | 88 bool PPB_Widget_Impl::GetLocation(PP_Rect* location) { |
| 81 *location = location_; | 89 *location = location_; |
| 82 return true; | 90 return true; |
| 83 } | 91 } |
| 84 | 92 |
| 85 void Widget::SetLocation(const PP_Rect* location) { | 93 void PPB_Widget_Impl::SetLocation(const PP_Rect* location) { |
| 86 location_ = *location; | 94 location_ = *location; |
| 87 SetLocationInternal(location); | 95 SetLocationInternal(location); |
| 88 } | 96 } |
| 89 | 97 |
| 90 void Widget::Invalidate(const PP_Rect* dirty) { | 98 void PPB_Widget_Impl::Invalidate(const PP_Rect* dirty) { |
| 91 const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( | 99 const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( |
| 92 module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); | 100 module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); |
| 93 if (!widget) | 101 if (!widget) |
| 94 return; | 102 return; |
| 95 ScopedResourceId resource(this); | 103 ScopedResourceId resource(this); |
| 96 widget->Invalidate(instance_->pp_instance(), resource.id, dirty); | 104 widget->Invalidate(instance_->pp_instance(), resource.id, dirty); |
| 97 } | 105 } |
| 98 | 106 |
| 99 } // namespace pepper | 107 } // namespace ppapi |
| 108 } // namespace webkit |
| 109 |
| OLD | NEW |