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/WebDocument.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h" |
19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
20 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" |
22 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" |
23 #include "webkit/glue/plugins/pepper_device_context_2d.h" | 23 #include "webkit/glue/plugins/pepper_device_context_2d.h" |
| 24 #include "webkit/glue/plugins/pepper_event_conversion.h" |
24 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 25 #include "webkit/glue/plugins/pepper_plugin_delegate.h" |
25 #include "webkit/glue/plugins/pepper_plugin_module.h" | 26 #include "webkit/glue/plugins/pepper_plugin_module.h" |
26 #include "webkit/glue/plugins/pepper_url_loader.h" | 27 #include "webkit/glue/plugins/pepper_url_loader.h" |
27 #include "webkit/glue/plugins/pepper_var.h" | 28 #include "webkit/glue/plugins/pepper_var.h" |
28 | 29 |
| 30 using WebKit::WebCanvas; |
| 31 using WebKit::WebCursorInfo; |
29 using WebKit::WebFrame; | 32 using WebKit::WebFrame; |
30 using WebKit::WebInputEvent; | 33 using WebKit::WebInputEvent; |
31 using WebKit::WebPluginContainer; | 34 using WebKit::WebPluginContainer; |
32 | 35 |
33 namespace pepper { | 36 namespace pepper { |
34 | 37 |
35 namespace { | 38 namespace { |
36 | 39 |
37 void RectToPPRect(const gfx::Rect& input, PP_Rect* output) { | 40 void RectToPPRect(const gfx::Rect& input, PP_Rect* output) { |
38 *output = PP_MakeRectFromXYWH(input.x(), input.y(), | 41 *output = PP_MakeRectFromXYWH(input.x(), input.y(), |
39 input.width(), input.height()); | 42 input.width(), input.height()); |
40 } | 43 } |
41 | 44 |
42 PP_Event_Type ConvertEventTypes(WebInputEvent::Type wetype) { | |
43 switch (wetype) { | |
44 case WebInputEvent::MouseDown: | |
45 return PP_Event_Type_MouseDown; | |
46 case WebInputEvent::MouseUp: | |
47 return PP_Event_Type_MouseUp; | |
48 case WebInputEvent::MouseMove: | |
49 return PP_Event_Type_MouseMove; | |
50 case WebInputEvent::MouseEnter: | |
51 return PP_Event_Type_MouseEnter; | |
52 case WebInputEvent::MouseLeave: | |
53 return PP_Event_Type_MouseLeave; | |
54 case WebInputEvent::MouseWheel: | |
55 return PP_Event_Type_MouseWheel; | |
56 case WebInputEvent::RawKeyDown: | |
57 return PP_Event_Type_RawKeyDown; | |
58 case WebInputEvent::KeyDown: | |
59 return PP_Event_Type_KeyDown; | |
60 case WebInputEvent::KeyUp: | |
61 return PP_Event_Type_KeyUp; | |
62 case WebInputEvent::Char: | |
63 return PP_Event_Type_Char; | |
64 case WebInputEvent::Undefined: | |
65 default: | |
66 return PP_Event_Type_Undefined; | |
67 } | |
68 } | |
69 | |
70 void BuildKeyEvent(const WebInputEvent* event, PP_Event* pp_event) { | |
71 const WebKit::WebKeyboardEvent* key_event = | |
72 reinterpret_cast<const WebKit::WebKeyboardEvent*>(event); | |
73 pp_event->u.key.modifier = key_event->modifiers; | |
74 pp_event->u.key.normalizedKeyCode = key_event->windowsKeyCode; | |
75 } | |
76 | |
77 void BuildCharEvent(const WebInputEvent* event, PP_Event* pp_event) { | |
78 const WebKit::WebKeyboardEvent* key_event = | |
79 reinterpret_cast<const WebKit::WebKeyboardEvent*>(event); | |
80 pp_event->u.character.modifier = key_event->modifiers; | |
81 // For consistency, check that the sizes of the texts agree. | |
82 DCHECK(sizeof(pp_event->u.character.text) == sizeof(key_event->text)); | |
83 DCHECK(sizeof(pp_event->u.character.unmodifiedText) == | |
84 sizeof(key_event->unmodifiedText)); | |
85 for (size_t i = 0; i < WebKit::WebKeyboardEvent::textLengthCap; ++i) { | |
86 pp_event->u.character.text[i] = key_event->text[i]; | |
87 pp_event->u.character.unmodifiedText[i] = key_event->unmodifiedText[i]; | |
88 } | |
89 } | |
90 | |
91 void BuildMouseEvent(const WebInputEvent* event, PP_Event* pp_event) { | |
92 const WebKit::WebMouseEvent* mouse_event = | |
93 reinterpret_cast<const WebKit::WebMouseEvent*>(event); | |
94 pp_event->u.mouse.modifier = mouse_event->modifiers; | |
95 pp_event->u.mouse.button = mouse_event->button; | |
96 pp_event->u.mouse.x = mouse_event->x; | |
97 pp_event->u.mouse.y = mouse_event->y; | |
98 pp_event->u.mouse.clickCount = mouse_event->clickCount; | |
99 } | |
100 | |
101 void BuildMouseWheelEvent(const WebInputEvent* event, PP_Event* pp_event) { | |
102 const WebKit::WebMouseWheelEvent* mouse_wheel_event = | |
103 reinterpret_cast<const WebKit::WebMouseWheelEvent*>(event); | |
104 pp_event->u.wheel.modifier = mouse_wheel_event->modifiers; | |
105 pp_event->u.wheel.deltaX = mouse_wheel_event->deltaX; | |
106 pp_event->u.wheel.deltaY = mouse_wheel_event->deltaY; | |
107 pp_event->u.wheel.wheelTicksX = mouse_wheel_event->wheelTicksX; | |
108 pp_event->u.wheel.wheelTicksY = mouse_wheel_event->wheelTicksY; | |
109 pp_event->u.wheel.scrollByPage = mouse_wheel_event->scrollByPage; | |
110 } | |
111 | |
112 PP_Var GetWindowObject(PP_Instance instance_id) { | 45 PP_Var GetWindowObject(PP_Instance instance_id) { |
113 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 46 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
114 if (!instance) | 47 if (!instance) |
115 return PP_MakeVoid(); | 48 return PP_MakeVoid(); |
116 return instance->GetWindowObject(); | 49 return instance->GetWindowObject(); |
117 } | 50 } |
118 | 51 |
119 PP_Var GetOwnerElementObject(PP_Instance instance_id) { | 52 PP_Var GetOwnerElementObject(PP_Instance instance_id) { |
120 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); | 53 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); |
121 if (!instance) | 54 if (!instance) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 104 |
172 // static | 105 // static |
173 PluginInstance* PluginInstance::FromPPInstance(PP_Instance instance) { | 106 PluginInstance* PluginInstance::FromPPInstance(PP_Instance instance) { |
174 return reinterpret_cast<PluginInstance*>(instance); | 107 return reinterpret_cast<PluginInstance*>(instance); |
175 } | 108 } |
176 | 109 |
177 PP_Instance PluginInstance::GetPPInstance() { | 110 PP_Instance PluginInstance::GetPPInstance() { |
178 return reinterpret_cast<intptr_t>(this); | 111 return reinterpret_cast<intptr_t>(this); |
179 } | 112 } |
180 | 113 |
181 void PluginInstance::Paint(WebKit::WebCanvas* canvas, | 114 void PluginInstance::Paint(WebCanvas* canvas, |
182 const gfx::Rect& plugin_rect, | 115 const gfx::Rect& plugin_rect, |
183 const gfx::Rect& paint_rect) { | 116 const gfx::Rect& paint_rect) { |
184 if (device_context_2d_) | 117 if (device_context_2d_) |
185 device_context_2d_->Paint(canvas, plugin_rect, paint_rect); | 118 device_context_2d_->Paint(canvas, plugin_rect, paint_rect); |
186 } | 119 } |
187 | 120 |
188 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { | 121 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { |
189 if (!container_ || position_.IsEmpty()) | 122 if (!container_ || position_.IsEmpty()) |
190 return; // Nothing to do. | 123 return; // Nothing to do. |
191 if (rect.IsEmpty()) | 124 if (rect.IsEmpty()) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return instance_interface_->Initialize(GetPPInstance(), | 197 return instance_interface_->Initialize(GetPPInstance(), |
265 argc, argn.get(), argv.get()); | 198 argc, argn.get(), argv.get()); |
266 } | 199 } |
267 | 200 |
268 bool PluginInstance::HandleDocumentLoad(URLLoader* loader) { | 201 bool PluginInstance::HandleDocumentLoad(URLLoader* loader) { |
269 return instance_interface_->HandleDocumentLoad(GetPPInstance(), | 202 return instance_interface_->HandleDocumentLoad(GetPPInstance(), |
270 loader->GetResource()); | 203 loader->GetResource()); |
271 } | 204 } |
272 | 205 |
273 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, | 206 bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, |
274 WebKit::WebCursorInfo* cursor_info) { | 207 WebCursorInfo* cursor_info) { |
275 PP_Event pp_event; | 208 scoped_ptr<PP_Event> pp_event(CreatePP_Event(event)); |
| 209 if (!pp_event.get()) |
| 210 return false; |
276 | 211 |
277 pp_event.type = ConvertEventTypes(event.type); | 212 return instance_interface_->HandleEvent(GetPPInstance(), pp_event.get()); |
278 pp_event.size = sizeof(pp_event); | |
279 pp_event.time_stamp_seconds = event.timeStampSeconds; | |
280 switch (pp_event.type) { | |
281 case PP_Event_Type_Undefined: | |
282 return false; | |
283 case PP_Event_Type_MouseDown: | |
284 case PP_Event_Type_MouseUp: | |
285 case PP_Event_Type_MouseMove: | |
286 case PP_Event_Type_MouseEnter: | |
287 case PP_Event_Type_MouseLeave: | |
288 BuildMouseEvent(&event, &pp_event); | |
289 break; | |
290 case PP_Event_Type_MouseWheel: | |
291 BuildMouseWheelEvent(&event, &pp_event); | |
292 break; | |
293 case PP_Event_Type_RawKeyDown: | |
294 case PP_Event_Type_KeyDown: | |
295 case PP_Event_Type_KeyUp: | |
296 BuildKeyEvent(&event, &pp_event); | |
297 break; | |
298 case PP_Event_Type_Char: | |
299 BuildCharEvent(&event, &pp_event); | |
300 break; | |
301 } | |
302 return instance_interface_->HandleEvent(GetPPInstance(), &pp_event); | |
303 } | 213 } |
304 | 214 |
305 PP_Var PluginInstance::GetInstanceObject() { | 215 PP_Var PluginInstance::GetInstanceObject() { |
306 return instance_interface_->GetInstanceObject(GetPPInstance()); | 216 return instance_interface_->GetInstanceObject(GetPPInstance()); |
307 } | 217 } |
308 | 218 |
309 void PluginInstance::ViewChanged(const gfx::Rect& position, | 219 void PluginInstance::ViewChanged(const gfx::Rect& position, |
310 const gfx::Rect& clip) { | 220 const gfx::Rect& clip) { |
311 position_ = position; | 221 position_ = position; |
312 if (clip.IsEmpty()) { | 222 if (clip.IsEmpty()) { |
(...skipping 16 matching lines...) Expand all Loading... |
329 if (device_context_2d_) | 239 if (device_context_2d_) |
330 device_context_2d_->ViewInitiatedPaint(); | 240 device_context_2d_->ViewInitiatedPaint(); |
331 } | 241 } |
332 | 242 |
333 void PluginInstance::ViewFlushedPaint() { | 243 void PluginInstance::ViewFlushedPaint() { |
334 if (device_context_2d_) | 244 if (device_context_2d_) |
335 device_context_2d_->ViewFlushedPaint(); | 245 device_context_2d_->ViewFlushedPaint(); |
336 } | 246 } |
337 | 247 |
338 } // namespace pepper | 248 } // namespace pepper |
OLD | NEW |