Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 #include "skia/ext/vector_platform_device_emf_win.h" | 93 #include "skia/ext/vector_platform_device_emf_win.h" |
| 94 #include "ui/gfx/codec/jpeg_codec.h" | 94 #include "ui/gfx/codec/jpeg_codec.h" |
| 95 #include "ui/gfx/gdi_util.h" | 95 #include "ui/gfx/gdi_util.h" |
| 96 #endif | 96 #endif |
| 97 | 97 |
| 98 #if defined(OS_MACOSX) && defined(USE_SKIA) | 98 #if defined(OS_MACOSX) && defined(USE_SKIA) |
| 99 #include "skia/ext/skia_utils_mac.h" | 99 #include "skia/ext/skia_utils_mac.h" |
| 100 #endif | 100 #endif |
| 101 | 101 |
| 102 using base::StringPrintf; | 102 using base::StringPrintf; |
| 103 using ppapi::InputEventData; | |
| 103 using ppapi::InputEventImpl; | 104 using ppapi::InputEventImpl; |
| 104 using ppapi::PpapiGlobals; | 105 using ppapi::PpapiGlobals; |
| 105 using ppapi::StringVar; | 106 using ppapi::StringVar; |
| 106 using ppapi::thunk::EnterResourceNoLock; | 107 using ppapi::thunk::EnterResourceNoLock; |
| 107 using ppapi::thunk::PPB_Buffer_API; | 108 using ppapi::thunk::PPB_Buffer_API; |
| 108 using ppapi::thunk::PPB_Graphics2D_API; | 109 using ppapi::thunk::PPB_Graphics2D_API; |
| 109 using ppapi::thunk::PPB_Graphics3D_API; | 110 using ppapi::thunk::PPB_Graphics3D_API; |
| 110 using ppapi::thunk::PPB_ImageData_API; | 111 using ppapi::thunk::PPB_ImageData_API; |
| 111 using ppapi::thunk::PPB_Instance_FunctionAPI; | 112 using ppapi::thunk::PPB_Instance_FunctionAPI; |
| 112 using ppapi::thunk::PPB_Surface3D_API; | 113 using ppapi::thunk::PPB_Surface3D_API; |
| 113 using ppapi::Var; | 114 using ppapi::Var; |
| 114 using WebKit::WebBindings; | 115 using WebKit::WebBindings; |
| 115 using WebKit::WebCanvas; | 116 using WebKit::WebCanvas; |
| 116 using WebKit::WebConsoleMessage; | 117 using WebKit::WebConsoleMessage; |
| 117 using WebKit::WebCursorInfo; | 118 using WebKit::WebCursorInfo; |
| 118 using WebKit::WebDocument; | 119 using WebKit::WebDocument; |
| 119 using WebKit::WebFrame; | 120 using WebKit::WebFrame; |
| 120 using WebKit::WebElement; | 121 using WebKit::WebElement; |
| 121 using WebKit::WebInputEvent; | 122 using WebKit::WebInputEvent; |
| 123 using WebKit::WebKeyboardEvent; | |
| 124 using WebKit::WebMouseWheelEvent; | |
| 122 using WebKit::WebPluginContainer; | 125 using WebKit::WebPluginContainer; |
| 126 using WebKit::WebPoint; | |
| 123 using WebKit::WebString; | 127 using WebKit::WebString; |
| 128 using WebKit::WebUChar; | |
| 124 using WebKit::WebURLRequest; | 129 using WebKit::WebURLRequest; |
| 125 using WebKit::WebView; | 130 using WebKit::WebView; |
| 126 | 131 |
| 127 namespace webkit { | 132 namespace webkit { |
| 128 namespace ppapi { | 133 namespace ppapi { |
| 129 | 134 |
| 130 #if defined(OS_WIN) | 135 #if defined(OS_WIN) |
| 131 // Exported by pdf.dll | 136 // Exported by pdf.dll |
| 132 typedef bool (*RenderPDFPageToDCProc)( | 137 typedef bool (*RenderPDFPageToDCProc)( |
| 133 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, | 138 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 WebKit::WebSecurityOrigin* security_origin) { | 249 WebKit::WebSecurityOrigin* security_origin) { |
| 245 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); | 250 PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); |
| 246 if (!instance) | 251 if (!instance) |
| 247 return false; | 252 return false; |
| 248 | 253 |
| 249 WebElement plugin_element = instance->container()->element(); | 254 WebElement plugin_element = instance->container()->element(); |
| 250 *security_origin = plugin_element.document().securityOrigin(); | 255 *security_origin = plugin_element.document().securityOrigin(); |
| 251 return true; | 256 return true; |
| 252 } | 257 } |
| 253 | 258 |
| 259 #if !defined(OS_WIN) | |
| 260 #define VK_RETURN 0x0D | |
| 261 | |
| 262 #define VK_PRIOR 0x21 | |
| 263 #define VK_NEXT 0x22 | |
| 264 #define VK_END 0x23 | |
| 265 #define VK_HOME 0x24 | |
| 266 #define VK_LEFT 0x25 | |
| 267 #define VK_UP 0x26 | |
| 268 #define VK_RIGHT 0x27 | |
| 269 #define VK_DOWN 0x28 | |
| 270 #define VK_SNAPSHOT 0x2C | |
| 271 #define VK_INSERT 0x2D | |
| 272 #define VK_DELETE 0x2E | |
| 273 | |
| 274 #define VK_APPS 0x5D | |
| 275 | |
| 276 #define VK_F1 0x70 | |
| 277 #endif | |
| 278 | |
| 279 // Convert a character string to a Windows virtual key code. Adapted from | |
| 280 // src/third_party/WebKit/Tools/DumpRenderTree/chromium/EventSender.cpp. This | |
| 281 // is used by SimulateInputEvent to convert keyboard events. | |
| 282 void GetKeyCode(const std::string& char_text, | |
|
dmichael (off chromium)
2011/11/17 19:27:57
Can you put all this stuff somewhere else, like ev
bbudge
2011/11/17 21:58:24
Done.
| |
| 283 WebUChar& code, | |
| 284 WebUChar& text, | |
| 285 bool& needs_shift_modifier, | |
| 286 bool& generate_char) { | |
| 287 code = 0; | |
| 288 text = 0; | |
| 289 needs_shift_modifier = false; | |
| 290 generate_char = false; | |
| 291 if ("\n" == char_text) { | |
| 292 text = code = VK_RETURN; | |
| 293 generate_char = true; | |
| 294 } else if ("rightArrow" == char_text) { | |
| 295 code = VK_RIGHT; | |
| 296 } else if ("downArrow" == char_text) { | |
| 297 code = VK_DOWN; | |
| 298 } else if ("leftArrow" == char_text) { | |
| 299 code = VK_LEFT; | |
| 300 } else if ("upArrow" == char_text) { | |
| 301 code = VK_UP; | |
| 302 } else if ("insert" == char_text) { | |
| 303 code = VK_INSERT; | |
| 304 } else if ("delete" == char_text) { | |
| 305 code = VK_DELETE; | |
| 306 } else if ("pageUp" == char_text) { | |
| 307 code = VK_PRIOR; | |
| 308 } else if ("pageDown" == char_text) { | |
| 309 code = VK_NEXT; | |
| 310 } else if ("home" == char_text) { | |
| 311 code = VK_HOME; | |
| 312 } else if ("end" == char_text) { | |
| 313 code = VK_END; | |
| 314 } else if ("printScreen" == char_text) { | |
| 315 code = VK_SNAPSHOT; | |
| 316 } else if ("menu" == char_text) { | |
| 317 code = VK_APPS; | |
| 318 } else { | |
| 319 // Compare the input string with the function-key names defined by the | |
| 320 // DOM spec (i.e. "F1",...,"F24"). | |
| 321 for (int i = 1; i <= 24; ++i) { | |
| 322 std::string functionKeyName = base::StringPrintf("F%d", i); | |
| 323 if (functionKeyName == char_text) { | |
| 324 code = VK_F1 + (i - 1); | |
| 325 break; | |
| 326 } | |
| 327 } | |
| 328 if (!code) { | |
| 329 WebString web_char_text = | |
| 330 WebString::fromUTF8(char_text.data(), char_text.size()); | |
| 331 DCHECK_EQ(web_char_text.length(), 1U); | |
| 332 text = code = web_char_text.data()[0]; | |
| 333 needs_shift_modifier = | |
| 334 (code & 0xFF) >= 'A' && (code & 0xFF) <= 'Z'; | |
| 335 if ((code & 0xFF) >= 'a' && (code & 0xFF) <= 'z') | |
| 336 code -= 'a' - 'A'; | |
| 337 generate_char = true; | |
| 338 } | |
| 339 } | |
| 340 } | |
| 341 | |
| 254 } // namespace | 342 } // namespace |
| 255 | 343 |
| 256 // static | 344 // static |
| 257 PluginInstance* PluginInstance::Create1_0(PluginDelegate* delegate, | 345 PluginInstance* PluginInstance::Create1_0(PluginDelegate* delegate, |
| 258 PluginModule* module, | 346 PluginModule* module, |
| 259 const void* ppp_instance_if_1_0) { | 347 const void* ppp_instance_if_1_0) { |
| 260 const PPP_Instance_1_0* instance = | 348 const PPP_Instance_1_0* instance = |
| 261 static_cast<const PPP_Instance_1_0*>(ppp_instance_if_1_0); | 349 static_cast<const PPP_Instance_1_0*>(ppp_instance_if_1_0); |
| 262 return new PluginInstance( | 350 return new PluginInstance( |
| 263 delegate, | 351 delegate, |
| (...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1592 } | 1680 } |
| 1593 | 1681 |
| 1594 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, result); | 1682 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, result); |
| 1595 } | 1683 } |
| 1596 | 1684 |
| 1597 void PluginInstance::OnMouseLockLost() { | 1685 void PluginInstance::OnMouseLockLost() { |
| 1598 if (LoadMouseLockInterface()) | 1686 if (LoadMouseLockInterface()) |
| 1599 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); | 1687 plugin_mouse_lock_interface_->MouseLockLost(pp_instance()); |
| 1600 } | 1688 } |
| 1601 | 1689 |
| 1690 void PluginInstance::SimulateInputEvent(const InputEventData& input_event) { | |
| 1691 WebView* web_view = container()->element().document().frame()->view(); | |
| 1692 if (!web_view) { | |
| 1693 NOTREACHED(); | |
| 1694 return; | |
| 1695 } | |
| 1696 | |
| 1697 scoped_ptr<WebInputEvent> web_input_event(CreateWebInputEvent(input_event)); | |
| 1698 switch (input_event.event_type) { | |
| 1699 case PP_INPUTEVENT_TYPE_MOUSEDOWN: | |
| 1700 case PP_INPUTEVENT_TYPE_MOUSEUP: | |
| 1701 case PP_INPUTEVENT_TYPE_MOUSEMOVE: | |
| 1702 case PP_INPUTEVENT_TYPE_MOUSEENTER: | |
| 1703 case PP_INPUTEVENT_TYPE_MOUSELEAVE: | |
| 1704 web_view->handleInputEvent(*web_input_event); | |
| 1705 break; | |
| 1706 | |
| 1707 case PP_INPUTEVENT_TYPE_WHEEL: { | |
| 1708 // Mouse wheel events need a position inside the plugin area in order to | |
| 1709 // be routed back to the plugin. Choose the midpoint of the plugin | |
| 1710 // instance's area on screen. | |
| 1711 WebMouseWheelEvent* web_mouse_wheel_event = | |
| 1712 static_cast<WebMouseWheelEvent*>(web_input_event.get()); | |
| 1713 web_mouse_wheel_event->x = position().x() + position().width() / 2; | |
| 1714 web_mouse_wheel_event->y = position().y() + position().height() / 2; | |
| 1715 web_view->handleInputEvent(*web_mouse_wheel_event); | |
| 1716 break; | |
| 1717 } | |
| 1718 | |
| 1719 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: | |
| 1720 case PP_INPUTEVENT_TYPE_KEYDOWN: | |
| 1721 case PP_INPUTEVENT_TYPE_KEYUP: { | |
| 1722 WebKeyboardEvent* web_keyboard_event = | |
| 1723 static_cast<WebKeyboardEvent*>(web_input_event.get()); | |
| 1724 // Windows key down events should always be "raw" to avoid an ASSERT. | |
| 1725 #if defined(OS_WIN) | |
| 1726 if (web_keyboard_event->type == WebInputEvent::KeyDown) | |
| 1727 web_keyboard_event->type = WebInputEvent::RawKeyDown; | |
| 1728 #endif | |
| 1729 web_view->handleInputEvent(*web_keyboard_event); | |
| 1730 break; | |
| 1731 } | |
| 1732 | |
| 1733 case PP_INPUTEVENT_TYPE_CHAR: { | |
| 1734 WebKeyboardEvent* web_char_event = | |
| 1735 static_cast<WebKeyboardEvent*>(web_input_event.get()); | |
| 1736 | |
| 1737 WebUChar code, text; | |
| 1738 bool needs_shift_modifier, generate_char; | |
| 1739 GetKeyCode(input_event.character_text, | |
| 1740 code, | |
| 1741 text, | |
| 1742 needs_shift_modifier, | |
| 1743 generate_char); | |
| 1744 | |
| 1745 // We synthesize key down and key up events in all cases. | |
| 1746 WebKeyboardEvent key_down_event, key_up_event; | |
| 1747 key_down_event.type = WebInputEvent::RawKeyDown; | |
| 1748 key_down_event.windowsKeyCode = code; | |
| 1749 key_down_event.nativeKeyCode = code; | |
| 1750 if (needs_shift_modifier) | |
| 1751 key_down_event.modifiers |= WebInputEvent::ShiftKey; | |
| 1752 | |
| 1753 // If a char event is needed, set the text fields. | |
| 1754 if (generate_char) { | |
| 1755 key_down_event.text[0] = text; | |
| 1756 key_down_event.unmodifiedText[0] = text; | |
| 1757 } | |
| 1758 // Convert the key code to a string identifier. | |
| 1759 key_down_event.setKeyIdentifierFromWindowsKeyCode(); | |
| 1760 | |
| 1761 key_up_event = *web_char_event = key_down_event; | |
| 1762 | |
| 1763 web_view->handleInputEvent(key_down_event); | |
| 1764 | |
| 1765 if (generate_char) { | |
| 1766 web_char_event->type = WebInputEvent::Char; | |
| 1767 web_char_event->keyIdentifier[0] = '\0'; | |
| 1768 web_view->handleInputEvent(*web_char_event); | |
| 1769 } | |
| 1770 | |
| 1771 key_up_event.type = WebInputEvent::KeyUp; | |
| 1772 web_view->handleInputEvent(key_up_event); | |
| 1773 break; | |
| 1774 } | |
| 1775 | |
| 1776 default: | |
| 1777 break; | |
| 1778 } | |
| 1779 } | |
| 1780 | |
| 1602 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() { | 1781 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() { |
| 1603 return this; | 1782 return this; |
| 1604 } | 1783 } |
| 1605 | 1784 |
| 1606 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, | 1785 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, |
| 1607 PP_Resource device) { | 1786 PP_Resource device) { |
| 1608 if (bound_graphics_.get()) { | 1787 if (bound_graphics_.get()) { |
| 1609 if (GetBoundGraphics2D()) { | 1788 if (GetBoundGraphics2D()) { |
| 1610 GetBoundGraphics2D()->BindToInstance(NULL); | 1789 GetBoundGraphics2D()->BindToInstance(NULL); |
| 1611 } else if (GetBoundGraphics3D()) { | 1790 } else if (GetBoundGraphics3D()) { |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2037 screen_size_for_fullscreen_ = gfx::Size(); | 2216 screen_size_for_fullscreen_ = gfx::Size(); |
| 2038 WebElement element = container_->element(); | 2217 WebElement element = container_->element(); |
| 2039 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2218 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2040 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2219 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2041 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2220 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2042 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2221 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2043 } | 2222 } |
| 2044 | 2223 |
| 2045 } // namespace ppapi | 2224 } // namespace ppapi |
| 2046 } // namespace webkit | 2225 } // namespace webkit |
| OLD | NEW |