OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/ppb_widget_impl.h" | 5 #include "content/renderer/pepper/ppb_widget_impl.h" |
6 | 6 |
7 #include "content/renderer/pepper/host_globals.h" | 7 #include "content/renderer/pepper/host_globals.h" |
8 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 8 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
9 #include "content/renderer/pepper/ppb_image_data_impl.h" | 9 #include "content/renderer/pepper/ppb_image_data_impl.h" |
10 #include "content/renderer/pepper/plugin_module.h" | 10 #include "content/renderer/pepper/plugin_module.h" |
11 #include "ppapi/c/dev/ppp_widget_dev.h" | 11 #include "ppapi/c/dev/ppp_widget_dev.h" |
12 #include "ppapi/thunk/enter.h" | 12 #include "ppapi/thunk/enter.h" |
13 #include "ppapi/thunk/ppb_input_event_api.h" | 13 #include "ppapi/thunk/ppb_input_event_api.h" |
14 #include "ppapi/thunk/ppb_widget_api.h" | 14 #include "ppapi/thunk/ppb_widget_api.h" |
15 | 15 |
16 using ppapi::thunk::EnterResourceNoLock; | 16 using ppapi::thunk::EnterResourceNoLock; |
17 using ppapi::thunk::PPB_ImageData_API; | 17 using ppapi::thunk::PPB_ImageData_API; |
18 using ppapi::thunk::PPB_InputEvent_API; | 18 using ppapi::thunk::PPB_InputEvent_API; |
19 using ppapi::thunk::PPB_Widget_API; | 19 using ppapi::thunk::PPB_Widget_API; |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 PPB_Widget_Impl::PPB_Widget_Impl(PP_Instance instance) | 23 PPB_Widget_Impl::PPB_Widget_Impl(PP_Instance instance) |
24 : Resource(ppapi::OBJECT_IS_IMPL, instance), | 24 : Resource(ppapi::OBJECT_IS_IMPL, instance), scale_(1.0f) { |
25 scale_(1.0f) { | |
26 memset(&location_, 0, sizeof(location_)); | 25 memset(&location_, 0, sizeof(location_)); |
27 } | 26 } |
28 | 27 |
29 PPB_Widget_Impl::~PPB_Widget_Impl() { | 28 PPB_Widget_Impl::~PPB_Widget_Impl() {} |
30 } | |
31 | 29 |
32 PPB_Widget_API* PPB_Widget_Impl::AsPPB_Widget_API() { | 30 PPB_Widget_API* PPB_Widget_Impl::AsPPB_Widget_API() { return this; } |
33 return this; | |
34 } | |
35 | 31 |
36 PP_Bool PPB_Widget_Impl::Paint(const PP_Rect* rect, PP_Resource image_id) { | 32 PP_Bool PPB_Widget_Impl::Paint(const PP_Rect* rect, PP_Resource image_id) { |
37 EnterResourceNoLock<PPB_ImageData_API> enter(image_id, true); | 33 EnterResourceNoLock<PPB_ImageData_API> enter(image_id, true); |
38 if (enter.failed()) | 34 if (enter.failed()) |
39 return PP_FALSE; | 35 return PP_FALSE; |
40 return PaintInternal(gfx::Rect(rect->point.x, rect->point.y, | 36 return PaintInternal( |
41 rect->size.width, rect->size.height), | 37 gfx::Rect( |
42 static_cast<PPB_ImageData_Impl*>(enter.object())); | 38 rect->point.x, rect->point.y, rect->size.width, rect->size.height), |
| 39 static_cast<PPB_ImageData_Impl*>(enter.object())); |
43 } | 40 } |
44 | 41 |
45 PP_Bool PPB_Widget_Impl::HandleEvent(PP_Resource pp_input_event) { | 42 PP_Bool PPB_Widget_Impl::HandleEvent(PP_Resource pp_input_event) { |
46 EnterResourceNoLock<PPB_InputEvent_API> enter(pp_input_event, true); | 43 EnterResourceNoLock<PPB_InputEvent_API> enter(pp_input_event, true); |
47 if (enter.failed()) | 44 if (enter.failed()) |
48 return PP_FALSE; | 45 return PP_FALSE; |
49 return HandleEventInternal(enter.object()->GetInputEventData()); | 46 return HandleEventInternal(enter.object()->GetInputEventData()); |
50 } | 47 } |
51 | 48 |
52 PP_Bool PPB_Widget_Impl::GetLocation(PP_Rect* location) { | 49 PP_Bool PPB_Widget_Impl::GetLocation(PP_Rect* location) { |
53 *location = location_; | 50 *location = location_; |
54 return PP_TRUE; | 51 return PP_TRUE; |
55 } | 52 } |
56 | 53 |
57 void PPB_Widget_Impl::SetLocation(const PP_Rect* location) { | 54 void PPB_Widget_Impl::SetLocation(const PP_Rect* location) { |
58 location_ = *location; | 55 location_ = *location; |
59 SetLocationInternal(location); | 56 SetLocationInternal(location); |
60 } | 57 } |
61 | 58 |
62 void PPB_Widget_Impl::SetScale(float scale) { | 59 void PPB_Widget_Impl::SetScale(float scale) { scale_ = scale; } |
63 scale_ = scale; | |
64 } | |
65 | 60 |
66 void PPB_Widget_Impl::Invalidate(const PP_Rect* dirty) { | 61 void PPB_Widget_Impl::Invalidate(const PP_Rect* dirty) { |
67 PepperPluginInstanceImpl* plugin_instance = | 62 PepperPluginInstanceImpl* plugin_instance = |
68 HostGlobals::Get()->GetInstance(pp_instance()); | 63 HostGlobals::Get()->GetInstance(pp_instance()); |
69 if (!plugin_instance) | 64 if (!plugin_instance) |
70 return; | 65 return; |
71 const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( | 66 const PPP_Widget_Dev* widget = static_cast<const PPP_Widget_Dev*>( |
72 plugin_instance->module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); | 67 plugin_instance->module()->GetPluginInterface(PPP_WIDGET_DEV_INTERFACE)); |
73 if (!widget) | 68 if (!widget) |
74 return; | 69 return; |
75 widget->Invalidate(pp_instance(), pp_resource(), dirty); | 70 widget->Invalidate(pp_instance(), pp_resource(), dirty); |
76 } | 71 } |
77 | 72 |
78 } // namespace content | 73 } // namespace content |
79 | |
OLD | NEW |