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_plugin_instance.h" | 5 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "gfx/rect.h" | 9 #include "gfx/rect.h" |
10 #include "third_party/ppapi/c/pp_instance.h" | 10 #include "third_party/ppapi/c/pp_instance.h" |
11 #include "third_party/ppapi/c/pp_event.h" | 11 #include "third_party/ppapi/c/pp_event.h" |
12 #include "third_party/ppapi/c/pp_rect.h" | 12 #include "third_party/ppapi/c/pp_rect.h" |
13 #include "third_party/ppapi/c/pp_resource.h" | 13 #include "third_party/ppapi/c/pp_resource.h" |
14 #include "third_party/ppapi/c/pp_var.h" | 14 #include "third_party/ppapi/c/pp_var.h" |
15 #include "third_party/ppapi/c/ppb_instance.h" | 15 #include "third_party/ppapi/c/ppb_instance.h" |
16 #include "third_party/ppapi/c/ppp_instance.h" | 16 #include "third_party/ppapi/c/ppp_instance.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" |
17 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
20 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
22 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
23 #include "webkit/glue/plugins/pepper_device_context_2d.h" | 24 #include "webkit/glue/plugins/pepper_device_context_2d.h" |
24 #include "webkit/glue/plugins/pepper_event_conversion.h" | 25 #include "webkit/glue/plugins/pepper_event_conversion.h" |
| 26 #include "webkit/glue/plugins/pepper_image_data.h" |
25 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 27 #include "webkit/glue/plugins/pepper_plugin_delegate.h" |
26 #include "webkit/glue/plugins/pepper_plugin_module.h" | 28 #include "webkit/glue/plugins/pepper_plugin_module.h" |
27 #include "webkit/glue/plugins/pepper_url_loader.h" | 29 #include "webkit/glue/plugins/pepper_url_loader.h" |
28 #include "webkit/glue/plugins/pepper_var.h" | 30 #include "webkit/glue/plugins/pepper_var.h" |
29 | 31 |
30 using WebKit::WebCanvas; | 32 using WebKit::WebCanvas; |
31 using WebKit::WebCursorInfo; | 33 using WebKit::WebCursorInfo; |
32 using WebKit::WebFrame; | 34 using WebKit::WebFrame; |
33 using WebKit::WebInputEvent; | 35 using WebKit::WebInputEvent; |
34 using WebKit::WebPluginContainer; | 36 using WebKit::WebPluginContainer; |
35 | 37 |
36 namespace pepper { | 38 namespace pepper { |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
| 42 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ |
| 43 COMPILE_ASSERT(int(WebCursorInfo::webkit_name) == int(np_name), \ |
| 44 mismatching_enums) |
| 45 |
| 46 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_CURSORTYPE_POINTER); |
| 47 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_CURSORTYPE_CROSS); |
| 48 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_CURSORTYPE_HAND); |
| 49 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_CURSORTYPE_IBEAM); |
| 50 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_CURSORTYPE_WAIT); |
| 51 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_CURSORTYPE_HELP); |
| 52 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_CURSORTYPE_EASTRESIZE); |
| 53 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_CURSORTYPE_NORTHRESIZE); |
| 54 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize, |
| 55 PP_CURSORTYPE_NORTHEASTRESIZE); |
| 56 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestResize, |
| 57 PP_CURSORTYPE_NORTHWESTRESIZE); |
| 58 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthResize, PP_CURSORTYPE_SOUTHRESIZE); |
| 59 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastResize, |
| 60 PP_CURSORTYPE_SOUTHEASTRESIZE); |
| 61 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestResize, |
| 62 PP_CURSORTYPE_SOUTHWESTRESIZE); |
| 63 COMPILE_ASSERT_MATCHING_ENUM(TypeWestResize, PP_CURSORTYPE_WESTRESIZE); |
| 64 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthSouthResize, |
| 65 PP_CURSORTYPE_NORTHSOUTHRESIZE); |
| 66 COMPILE_ASSERT_MATCHING_ENUM(TypeEastWestResize, PP_CURSORTYPE_EASTWESTRESIZE); |
| 67 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastSouthWestResize, |
| 68 PP_CURSORTYPE_NORTHEASTSOUTHWESTRESIZE); |
| 69 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestSouthEastResize, |
| 70 PP_CURSORTYPE_NORTHWESTSOUTHEASTRESIZE); |
| 71 COMPILE_ASSERT_MATCHING_ENUM(TypeColumnResize, PP_CURSORTYPE_COLUMNRESIZE); |
| 72 COMPILE_ASSERT_MATCHING_ENUM(TypeRowResize, PP_CURSORTYPE_ROWRESIZE); |
| 73 COMPILE_ASSERT_MATCHING_ENUM(TypeMiddlePanning, PP_CURSORTYPE_MIDDLEPANNING); |
| 74 COMPILE_ASSERT_MATCHING_ENUM(TypeEastPanning, PP_CURSORTYPE_EASTPANNING); |
| 75 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthPanning, PP_CURSORTYPE_NORTHPANNING); |
| 76 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastPanning, |
| 77 PP_CURSORTYPE_NORTHEASTPANNING); |
| 78 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthWestPanning, |
| 79 PP_CURSORTYPE_NORTHWESTPANNING); |
| 80 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthPanning, PP_CURSORTYPE_SOUTHPANNING); |
| 81 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthEastPanning, |
| 82 PP_CURSORTYPE_SOUTHEASTPANNING); |
| 83 COMPILE_ASSERT_MATCHING_ENUM(TypeSouthWestPanning, |
| 84 PP_CURSORTYPE_SOUTHWESTPANNING); |
| 85 COMPILE_ASSERT_MATCHING_ENUM(TypeWestPanning, PP_CURSORTYPE_WESTPANNING); |
| 86 COMPILE_ASSERT_MATCHING_ENUM(TypeMove, PP_CURSORTYPE_MOVE); |
| 87 COMPILE_ASSERT_MATCHING_ENUM(TypeVerticalText, PP_CURSORTYPE_VERTICALTEXT); |
| 88 COMPILE_ASSERT_MATCHING_ENUM(TypeCell, PP_CURSORTYPE_CELL); |
| 89 COMPILE_ASSERT_MATCHING_ENUM(TypeContextMenu, PP_CURSORTYPE_CONTEXTMENU); |
| 90 COMPILE_ASSERT_MATCHING_ENUM(TypeAlias, PP_CURSORTYPE_ALIAS); |
| 91 COMPILE_ASSERT_MATCHING_ENUM(TypeProgress, PP_CURSORTYPE_PROGRESS); |
| 92 COMPILE_ASSERT_MATCHING_ENUM(TypeNoDrop, PP_CURSORTYPE_NODROP); |
| 93 COMPILE_ASSERT_MATCHING_ENUM(TypeCopy, PP_CURSORTYPE_COPY); |
| 94 COMPILE_ASSERT_MATCHING_ENUM(TypeNone, PP_CURSORTYPE_NONE); |
| 95 COMPILE_ASSERT_MATCHING_ENUM(TypeNotAllowed, PP_CURSORTYPE_NOTALLOWED); |
| 96 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomIn, PP_CURSORTYPE_ZOOMIN); |
| 97 COMPILE_ASSERT_MATCHING_ENUM(TypeZoomOut, PP_CURSORTYPE_ZOOMOUT); |
| 98 COMPILE_ASSERT_MATCHING_ENUM(TypeCustom, PP_CURSORTYPE_CUSTOM); |
| 99 |
40 void RectToPPRect(const gfx::Rect& input, PP_Rect* output) { | 100 void RectToPPRect(const gfx::Rect& input, PP_Rect* output) { |
41 *output = PP_MakeRectFromXYWH(input.x(), input.y(), | 101 *output = PP_MakeRectFromXYWH(input.x(), input.y(), |
42 input.width(), input.height()); | 102 input.width(), input.height()); |
43 } | 103 } |
44 | 104 |
45 PP_Var GetWindowObject(PP_Instance instance_id) { | 105 PP_Var GetWindowObject(PP_Instance instance_id) { |
46 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 106 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
47 if (!instance) | 107 if (!instance) |
48 return PP_MakeVoid(); | 108 return PP_MakeVoid(); |
49 return instance->GetWindowObject(); | 109 return instance->GetWindowObject(); |
(...skipping 13 matching lines...) Loading... |
63 return instance->BindGraphicsDeviceContext(device_id); | 123 return instance->BindGraphicsDeviceContext(device_id); |
64 } | 124 } |
65 | 125 |
66 bool IsFullFrame(PP_Instance instance_id) { | 126 bool IsFullFrame(PP_Instance instance_id) { |
67 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 127 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
68 if (!instance) | 128 if (!instance) |
69 return false; | 129 return false; |
70 return instance->full_frame(); | 130 return instance->full_frame(); |
71 } | 131 } |
72 | 132 |
| 133 bool SetCursor(PP_Instance instance_id, |
| 134 PP_CursorType type, |
| 135 PP_Resource custom_image_id, |
| 136 const PP_Point* hot_spot) { |
| 137 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
| 138 if (!instance) |
| 139 return false; |
| 140 |
| 141 scoped_refptr<ImageData> custom_image( |
| 142 Resource::GetAs<ImageData>(custom_image_id)); |
| 143 if (custom_image.get() || hot_spot) { |
| 144 // TODO: implement custom cursors. |
| 145 NOTIMPLEMENTED(); |
| 146 return false; |
| 147 } |
| 148 |
| 149 return instance->SetCursor(type); |
| 150 } |
| 151 |
73 const PPB_Instance ppb_instance = { | 152 const PPB_Instance ppb_instance = { |
74 &GetWindowObject, | 153 &GetWindowObject, |
75 &GetOwnerElementObject, | 154 &GetOwnerElementObject, |
76 &BindGraphicsDeviceContext, | 155 &BindGraphicsDeviceContext, |
77 &IsFullFrame, | 156 &IsFullFrame, |
| 157 &SetCursor, |
78 }; | 158 }; |
79 | 159 |
80 } // namespace | 160 } // namespace |
81 | 161 |
82 PluginInstance::PluginInstance(PluginDelegate* delegate, | 162 PluginInstance::PluginInstance(PluginDelegate* delegate, |
83 PluginModule* module, | 163 PluginModule* module, |
84 const PPP_Instance* instance_interface) | 164 const PPP_Instance* instance_interface) |
85 : delegate_(delegate), | 165 : delegate_(delegate), |
86 module_(module), | 166 module_(module), |
87 instance_interface_(instance_interface), | 167 instance_interface_(instance_interface), |
(...skipping 74 matching lines...) Loading... |
162 if (device_2d) { | 242 if (device_2d) { |
163 if (!device_2d->BindToInstance(this)) | 243 if (!device_2d->BindToInstance(this)) |
164 return false; // Can't bind to more than one instance. | 244 return false; // Can't bind to more than one instance. |
165 device_context_2d_ = device_2d; | 245 device_context_2d_ = device_2d; |
166 // BindToInstance will have invalidated the plugin if necessary. | 246 // BindToInstance will have invalidated the plugin if necessary. |
167 } | 247 } |
168 | 248 |
169 return true; | 249 return true; |
170 } | 250 } |
171 | 251 |
| 252 bool PluginInstance::SetCursor(PP_CursorType type) { |
| 253 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); |
| 254 return true; |
| 255 } |
| 256 |
172 void PluginInstance::Delete() { | 257 void PluginInstance::Delete() { |
173 instance_interface_->Delete(GetPPInstance()); | 258 instance_interface_->Delete(GetPPInstance()); |
174 | 259 |
175 container_ = NULL; | 260 container_ = NULL; |
176 } | 261 } |
177 | 262 |
178 bool PluginInstance::Initialize(WebPluginContainer* container, | 263 bool PluginInstance::Initialize(WebPluginContainer* container, |
179 const std::vector<std::string>& arg_names, | 264 const std::vector<std::string>& arg_names, |
180 const std::vector<std::string>& arg_values, | 265 const std::vector<std::string>& arg_values, |
181 bool full_frame) { | 266 bool full_frame) { |
(...skipping 20 matching lines...) Loading... |
202 return instance_interface_->HandleDocumentLoad(GetPPInstance(), | 287 return instance_interface_->HandleDocumentLoad(GetPPInstance(), |
203 loader->GetResource()); | 288 loader->GetResource()); |
204 } | 289 } |
205 | 290 |
206 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, | 291 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, |
207 WebCursorInfo* cursor_info) { | 292 WebCursorInfo* cursor_info) { |
208 scoped_ptr<PP_Event> pp_event(CreatePP_Event(event)); | 293 scoped_ptr<PP_Event> pp_event(CreatePP_Event(event)); |
209 if (!pp_event.get()) | 294 if (!pp_event.get()) |
210 return false; | 295 return false; |
211 | 296 |
212 return instance_interface_->HandleEvent(GetPPInstance(), pp_event.get()); | 297 bool rv = instance_interface_->HandleEvent(GetPPInstance(), pp_event.get()); |
| 298 if (cursor_.get()) |
| 299 *cursor_info = *cursor_; |
| 300 return rv; |
213 } | 301 } |
214 | 302 |
215 PP_Var PluginInstance::GetInstanceObject() { | 303 PP_Var PluginInstance::GetInstanceObject() { |
216 return instance_interface_->GetInstanceObject(GetPPInstance()); | 304 return instance_interface_->GetInstanceObject(GetPPInstance()); |
217 } | 305 } |
218 | 306 |
219 void PluginInstance::ViewChanged(const gfx::Rect& position, | 307 void PluginInstance::ViewChanged(const gfx::Rect& position, |
220 const gfx::Rect& clip) { | 308 const gfx::Rect& clip) { |
221 position_ = position; | 309 position_ = position; |
222 if (clip.IsEmpty()) { | 310 if (clip.IsEmpty()) { |
(...skipping 16 matching lines...) Loading... |
239 if (device_context_2d_) | 327 if (device_context_2d_) |
240 device_context_2d_->ViewInitiatedPaint(); | 328 device_context_2d_->ViewInitiatedPaint(); |
241 } | 329 } |
242 | 330 |
243 void PluginInstance::ViewFlushedPaint() { | 331 void PluginInstance::ViewFlushedPaint() { |
244 if (device_context_2d_) | 332 if (device_context_2d_) |
245 device_context_2d_->ViewFlushedPaint(); | 333 device_context_2d_->ViewFlushedPaint(); |
246 } | 334 } |
247 | 335 |
248 } // namespace pepper | 336 } // namespace pepper |
OLD | NEW |