Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: webkit/glue/webplugin_impl.cc

Issue 115330: linux: Adding events to windowless plugins on Linux (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webplugin_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "config.h" 5 #include "config.h"
6 #include "webkit/glue/webplugin_impl.h" 6 #include "webkit/glue/webplugin_impl.h"
7 7
8 #include "Cursor.h" 8 #include "Cursor.h"
9 #include "Document.h" 9 #include "Document.h"
10 #include "DocumentLoader.h" 10 #include "DocumentLoader.h"
(...skipping 12 matching lines...) Expand all
23 #include "HTMLFormElement.h" 23 #include "HTMLFormElement.h"
24 #include "HTMLNames.h" 24 #include "HTMLNames.h"
25 #include "HTMLPlugInElement.h" 25 #include "HTMLPlugInElement.h"
26 #include "IntRect.h" 26 #include "IntRect.h"
27 #include "KURL.h" 27 #include "KURL.h"
28 #include "KeyboardEvent.h" 28 #include "KeyboardEvent.h"
29 #include "MouseEvent.h" 29 #include "MouseEvent.h"
30 #include "Page.h" 30 #include "Page.h"
31 #include "PlatformContextSkia.h" 31 #include "PlatformContextSkia.h"
32 #include "PlatformMouseEvent.h" 32 #include "PlatformMouseEvent.h"
33 #include "PlatformKeyboardEvent.h"
33 #include "PlatformString.h" 34 #include "PlatformString.h"
35 #include "PlatformWidget.h"
34 #include "RenderBox.h" 36 #include "RenderBox.h"
35 #include "ResourceHandle.h" 37 #include "ResourceHandle.h"
36 #include "ResourceHandleClient.h" 38 #include "ResourceHandleClient.h"
37 #include "ResourceResponse.h" 39 #include "ResourceResponse.h"
38 #include "ScriptController.h" 40 #include "ScriptController.h"
39 #include "ScriptValue.h" 41 #include "ScriptValue.h"
40 #include "ScrollView.h" 42 #include "ScrollView.h"
41 #include "Widget.h" 43 #include "Widget.h"
42 44
43 #undef LOG 45 #undef LOG
44 #include "base/gfx/rect.h" 46 #include "base/gfx/rect.h"
45 #include "base/logging.h" 47 #include "base/logging.h"
46 #include "base/message_loop.h" 48 #include "base/message_loop.h"
47 #include "base/string_util.h" 49 #include "base/string_util.h"
48 #include "base/sys_string_conversions.h" 50 #include "base/sys_string_conversions.h"
49 #include "net/base/escape.h" 51 #include "net/base/escape.h"
52 #include "webkit/api/public/WebInputEvent.h"
50 #include "webkit/api/public/WebKit.h" 53 #include "webkit/api/public/WebKit.h"
51 #include "webkit/api/public/WebKitClient.h" 54 #include "webkit/api/public/WebKitClient.h"
52 #include "webkit/api/public/WebString.h" 55 #include "webkit/api/public/WebString.h"
53 #include "webkit/api/public/WebURL.h" 56 #include "webkit/api/public/WebURL.h"
54 #include "webkit/glue/chrome_client_impl.h" 57 #include "webkit/glue/chrome_client_impl.h"
58 #include "webkit/glue/event_conversion.h"
55 #include "webkit/glue/glue_util.h" 59 #include "webkit/glue/glue_util.h"
56 #include "webkit/glue/multipart_response_delegate.h" 60 #include "webkit/glue/multipart_response_delegate.h"
57 #include "webkit/glue/webcursor.h" 61 #include "webkit/glue/webcursor.h"
58 #include "webkit/glue/webkit_glue.h" 62 #include "webkit/glue/webkit_glue.h"
59 #include "webkit/glue/plugins/plugin_host.h" 63 #include "webkit/glue/plugins/plugin_host.h"
60 #include "webkit/glue/plugins/plugin_instance.h" 64 #include "webkit/glue/plugins/plugin_instance.h"
61 #include "webkit/glue/stacking_order_iterator.h" 65 #include "webkit/glue/stacking_order_iterator.h"
62 #include "webkit/glue/webview_impl.h" 66 #include "webkit/glue/webview_impl.h"
63 #include "googleurl/src/gurl.h" 67 #include "googleurl/src/gurl.h"
64 68
69 using WebKit::WebKeyboardEvent;
70 using WebKit::WebInputEvent;
71 using WebKit::WebMouseEvent;
72
65 // This class handles individual multipart responses. It is instantiated when 73 // This class handles individual multipart responses. It is instantiated when
66 // we receive HTTP status code 206 in the HTTP response. This indicates 74 // we receive HTTP status code 206 in the HTTP response. This indicates
67 // that the response could have multiple parts each separated by a boundary 75 // that the response could have multiple parts each separated by a boundary
68 // specified in the response header. 76 // specified in the response header.
69 class MultiPartResponseClient : public WebCore::ResourceHandleClient { 77 class MultiPartResponseClient : public WebCore::ResourceHandleClient {
70 public: 78 public:
71 MultiPartResponseClient(WebPluginResourceClient* resource_client) 79 MultiPartResponseClient(WebPluginResourceClient* resource_client)
72 : resource_client_(resource_client) { 80 : resource_client_(resource_client) {
73 Clear(); 81 Clear();
74 } 82 }
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structur es5.html#1000000 769 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structur es5.html#1000000
762 // Don't take the documentation as truth, however. I've found 770 // Don't take the documentation as truth, however. I've found
763 // many cases where mozilla behaves differently than the spec. 771 // many cases where mozilla behaves differently than the spec.
764 if (event->isMouseEvent()) 772 if (event->isMouseEvent())
765 handleMouseEvent(static_cast<WebCore::MouseEvent*>(event)); 773 handleMouseEvent(static_cast<WebCore::MouseEvent*>(event));
766 else if (event->isKeyboardEvent()) 774 else if (event->isKeyboardEvent())
767 handleKeyboardEvent(static_cast<WebCore::KeyboardEvent*>(event)); 775 handleKeyboardEvent(static_cast<WebCore::KeyboardEvent*>(event));
768 } 776 }
769 777
770 void WebPluginImpl::handleMouseEvent(WebCore::MouseEvent* event) { 778 void WebPluginImpl::handleMouseEvent(WebCore::MouseEvent* event) {
771 #if defined(OS_WIN)
772 DCHECK(parent()->isFrameView()); 779 DCHECK(parent()->isFrameView());
773 // We cache the parent FrameView here as the plugin widget could be deleted 780 // We cache the parent FrameView here as the plugin widget could be deleted
774 // in the call to HandleEvent. See http://b/issue?id=1362948 781 // in the call to HandleEvent. See http://b/issue?id=1362948
775 WebCore::FrameView* parent_view = static_cast<WebCore::FrameView*>(parent()); 782 WebCore::FrameView* parent_view = static_cast<WebCore::FrameView*>(parent());
776 783
777 WebCore::IntPoint p = 784 WebMouseEvent web_event;
778 parent_view->contentsToWindow(WebCore::IntPoint(event->pageX(), 785 if (!ToWebMouseEvent(*parent_view, *event, &web_event))
779 event->pageY())); 786 return;
780 NPEvent np_event;
781 np_event.lParam = static_cast<uint32>(MAKELPARAM(p.x(), p.y()));
782 np_event.wParam = 0;
783 787
784 if (event->ctrlKey()) 788 if (event->type() == WebCore::eventNames().mousedownEvent) {
785 np_event.wParam |= MK_CONTROL;
786 if (event->shiftKey())
787 np_event.wParam |= MK_SHIFT;
788
789 if ((event->type() == WebCore::eventNames().mousemoveEvent) ||
790 (event->type() == WebCore::eventNames().mouseoutEvent) ||
791 (event->type() == WebCore::eventNames().mouseoverEvent)) {
792 np_event.event = WM_MOUSEMOVE;
793 if (event->buttonDown()) {
794 switch (event->button()) {
795 case WebCore::LeftButton:
796 np_event.wParam |= MK_LBUTTON;
797 break;
798 case WebCore::MiddleButton:
799 np_event.wParam |= MK_MBUTTON;
800 break;
801 case WebCore::RightButton:
802 np_event.wParam |= MK_RBUTTON;
803 break;
804 }
805 }
806 } else if (event->type() == WebCore::eventNames().mousedownEvent) {
807 // Ensure that the frame containing the plugin has focus. 789 // Ensure that the frame containing the plugin has focus.
808 WebCore::Frame* containing_frame = webframe_->frame(); 790 WebCore::Frame* containing_frame = webframe_->frame();
809 if (WebCore::Page* current_page = containing_frame->page()) { 791 if (WebCore::Page* current_page = containing_frame->page()) {
810 current_page->focusController()->setFocusedFrame(containing_frame); 792 current_page->focusController()->setFocusedFrame(containing_frame);
811 } 793 }
812 // Give focus to our containing HTMLPluginElement. 794 // Give focus to our containing HTMLPluginElement.
813 containing_frame->document()->setFocusedNode(element_); 795 containing_frame->document()->setFocusedNode(element_);
814
815 // Ideally we'd translate to WM_xBUTTONDBLCLK here if the click count were
816 // a multiple of 2. But there seems to be no way to get at the click count
817 // or the original Windows message from the WebCore::Event.
818 switch (event->button()) {
819 case WebCore::LeftButton:
820 np_event.event = WM_LBUTTONDOWN;
821 np_event.wParam |= MK_LBUTTON;
822 break;
823 case WebCore::MiddleButton:
824 np_event.event = WM_MBUTTONDOWN;
825 np_event.wParam |= MK_MBUTTON;
826 break;
827 case WebCore::RightButton:
828 np_event.event = WM_RBUTTONDOWN;
829 np_event.wParam |= MK_RBUTTON;
830 break;
831 }
832 } else if (event->type() == WebCore::eventNames().mouseupEvent) {
833 switch (event->button()) {
834 case WebCore::LeftButton:
835 np_event.event = WM_LBUTTONUP;
836 break;
837 case WebCore::MiddleButton:
838 np_event.event = WM_MBUTTONUP;
839 break;
840 case WebCore::RightButton:
841 np_event.event = WM_RBUTTONUP;
842 break;
843 }
844 } else {
845 // Skip all other mouse events.
846 return;
847 } 796 }
848 797
849 // TODO(pkasting): http://b/1119691 This conditional seems exactly backwards, 798 // TODO(pkasting): http://b/1119691 This conditional seems exactly backwards,
850 // but it matches Safari's code, and if I reverse it, giving focus to a 799 // but it matches Safari's code, and if I reverse it, giving focus to a
851 // transparent (windowless) plugin fails. 800 // transparent (windowless) plugin fails.
852 WebCursor cursor; 801 WebCursor cursor;
853 if (!delegate_->HandleEvent(&np_event, &cursor)) 802 if (!delegate_->HandleInputEvent(web_event, &cursor))
854 event->setDefaultHandled(); 803 event->setDefaultHandled();
855 804
856 WebCore::Page* page = parent_view->frame()->page(); 805 WebCore::Page* page = parent_view->frame()->page();
857 if (!page) 806 if (!page)
858 return; 807 return;
859 808
860 ChromeClientImpl* chrome_client = 809 ChromeClientImpl* chrome_client =
861 static_cast<ChromeClientImpl*>(page->chrome()->client()); 810 static_cast<ChromeClientImpl*>(page->chrome()->client());
862 811
863 // A windowless plugin can change the cursor in response to the WM_MOUSEMOVE 812 // A windowless plugin can change the cursor in response to the WM_MOUSEMOVE
864 // event. We need to reflect the changed cursor in the frame view as the 813 // event. We need to reflect the changed cursor in the frame view as the
865 // mouse is moved in the boundaries of the windowless plugin. 814 // mouse is moved in the boundaries of the windowless plugin.
866 chrome_client->SetCursorForPlugin(cursor); 815 chrome_client->SetCursorForPlugin(cursor);
867
868 #else
869 NOTIMPLEMENTED();
870 #endif
871 } 816 }
872 817
873 void WebPluginImpl::handleKeyboardEvent(WebCore::KeyboardEvent* event) { 818 void WebPluginImpl::handleKeyboardEvent(WebCore::KeyboardEvent* event) {
874 #if defined(OS_WIN) 819 WebKeyboardEvent web_event;
875 NPEvent np_event; 820 if (!ToWebKeyboardEvent(*event, &web_event))
876 np_event.wParam = event->keyCode();
877
878 if (event->type() == WebCore::eventNames().keydownEvent) {
879 np_event.event = WM_KEYDOWN;
880 np_event.lParam = 0;
881 } else if (event->type() == WebCore::eventNames().keyupEvent) {
882 np_event.event = WM_KEYUP;
883 np_event.lParam = 0x8000;
884 } else {
885 // Skip all other keyboard events.
886 return; 821 return;
887 }
888
889 // TODO(pkasting): http://b/1119691 See above. 822 // TODO(pkasting): http://b/1119691 See above.
890 WebCursor current_web_cursor; 823 WebCursor current_web_cursor;
891 if (!delegate_->HandleEvent(&np_event, &current_web_cursor)) 824 if (!delegate_->HandleInputEvent(web_event, &current_web_cursor))
892 event->setDefaultHandled(); 825 event->setDefaultHandled();
893 #else
894 NOTIMPLEMENTED();
895 #endif
896 } 826 }
897 827
898 NPObject* WebPluginImpl::GetPluginScriptableObject() { 828 NPObject* WebPluginImpl::GetPluginScriptableObject() {
899 return delegate_->GetPluginScriptableObject(); 829 return delegate_->GetPluginScriptableObject();
900 } 830 }
901 831
902 WebPluginResourceClient* WebPluginImpl::GetClientFromHandle( 832 WebPluginResourceClient* WebPluginImpl::GetClientFromHandle(
903 WebCore::ResourceHandle* handle) { 833 WebCore::ResourceHandle* handle) {
904 for (size_t i = 0; i < clients_.size(); ++i) { 834 for (size_t i = 0; i < clients_.size(); ++i) {
905 if (clients_[i].handle.get() == handle) 835 if (clients_[i].handle.get() == handle)
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 client_index = clients_.erase(client_index); 1344 client_index = clients_.erase(client_index);
1415 if (resource_client) 1345 if (resource_client)
1416 resource_client->DidFail(); 1346 resource_client->DidFail();
1417 } 1347 }
1418 1348
1419 // This needs to be called now and not in the destructor since the 1349 // This needs to be called now and not in the destructor since the
1420 // webframe_ might not be valid anymore. 1350 // webframe_ might not be valid anymore.
1421 webframe_->set_plugin_delegate(NULL); 1351 webframe_->set_plugin_delegate(NULL);
1422 webframe_ = NULL; 1352 webframe_ = NULL;
1423 } 1353 }
OLDNEW
« no previous file with comments | « webkit/glue/webplugin_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698