diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 16:39:03 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-12 16:39:03 +0000 |
commit | a956916ffd429577a979efa34af889801b8ed44e (patch) | |
tree | 8a1e0fb5f875110abaa08606969e610d3c207a09 | |
parent | 78f7decedbe5e08df8aff92dd46a43f4f6afbc17 (diff) | |
download | chromium_src-a956916ffd429577a979efa34af889801b8ed44e.zip chromium_src-a956916ffd429577a979efa34af889801b8ed44e.tar.gz chromium_src-a956916ffd429577a979efa34af889801b8ed44e.tar.bz2 |
Simplify Mac plugin HandleInputEvent logic
- Consolidates most of the Carbon-only code into a single block, to cut down on ifdef's, and puts it into a runtime conditional so we don't do needless work in Cocoa event plugins.
- Changes the internal logic to be WebInputEvent-based, rather than NPEvent-based
- Updates the stored mouse location on all mouse events (whenever the window moves) since the two are closely related. This means that we will update on mouse-exit, so the location sent to Carbon plugins for null events after the mouse leaves will be just outside the plugin bounds, rather than inside.
BUG=none
TEST=Mouse events should continue to work in both Flash 10.0 and 10.1. Hover effects in Flash 10.0 content should not persist after the mouse is moved out of the plugin.
Review URL: http://codereview.chromium.org/550009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36014 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/plugins/webplugin_delegate_impl_mac.mm | 90 |
1 files changed, 44 insertions, 46 deletions
diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index 13afa69..17b33f3 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -415,6 +415,8 @@ void WebPluginDelegateImpl::SetFocus() { void WebPluginDelegateImpl::UpdateWindowLocation(const WebMouseEvent& event) { last_window_x_offset_ = event.globalX - event.windowX; last_window_y_offset_ = event.globalY - event.windowY; + last_mouse_x_ = event.globalX; + last_mouse_y_ = event.globalY; instance_->set_plugin_origin(gfx::Point(event.globalX - event.x, event.globalY - event.y)); @@ -564,6 +566,7 @@ static bool NPEventFromWebKeyboardEvent(const WebKeyboardEvent& event, static bool NPEventFromWebInputEvent(const WebInputEvent& event, NPEvent* np_event) { + np_event->when = TickCount(); if (WebInputEventIsWebMouseEvent(event)) { return NPEventFromWebMouseEvent(*static_cast<const WebMouseEvent*>(&event), np_event); @@ -689,66 +692,61 @@ static bool NPCocoaEventFromWebInputEvent(const WebInputEvent& event, bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, WebCursorInfo* cursor) { -#ifndef NP_NO_CARBON - // If we somehow get an event before we've set up the plugin window, bail. - if (instance()->event_model() == NPEventModelCarbon && - !cg_context_.context) - return false; -#endif DCHECK(windowless_) << "events should only be received in windowless mode"; DCHECK(cursor != NULL); + // if we do not currently have focus and this is a mouseDown, trigger a + // notification that we are taking the keyboard focus. We can't just key + // off of incoming calls to SetFocus, since WebKit may already think we + // have it if we were the most recently focused element on our parent tab. + if (event.type == WebInputEvent::MouseDown && !have_focus_) + SetFocus(); + #ifndef NP_NO_CARBON - NPEvent np_event = {0}; - if (!NPEventFromWebInputEvent(event, &np_event)) { - LOG(WARNING) << "NPEventFromWebInputEvent failed"; - return false; - } - np_event.when = TickCount(); - if (WebInputEventIsWebMouseEvent(event)) { - // Make sure our dummy window has the correct location before we send the - // event to the plugin, so that any coordinate conversion the plugin does - // will work out. - const WebMouseEvent* mouse_event = - static_cast<const WebMouseEvent*>(&event); - UpdateWindowLocation(*mouse_event); - } - if (np_event.what == nullEvent) { - last_mouse_x_ = np_event.where.h; - last_mouse_y_ = np_event.where.v; - if (instance()->event_model() == NPEventModelCarbon) - return true; // Let the recurring task actually send the event. - } else { - // if we do not currently have focus and this is a mouseDown, trigger a - // notification that we are taking the keyboard focus. We can't just key - // off of incoming calls to SetFocus, since WebKit may already think we - // have it if we were the most recently focused element on our parent tab. - if (np_event.what == mouseDown && !have_focus_) - SetFocus(); - } -#endif + if (instance()->event_model() == NPEventModelCarbon) { + // If we somehow get an event before we've set up the plugin window, bail. + if (!cg_context_.context) + return false; - bool ret = false; - switch (instance()->drawing_model()) { + if (WebInputEventIsWebMouseEvent(event)) { + // Make sure our dummy window has the correct location before we send the + // event to the plugin, so that any coordinate conversion the plugin does + // will work out. + const WebMouseEvent* mouse_event = + static_cast<const WebMouseEvent*>(&event); + UpdateWindowLocation(*mouse_event); + + if (event.type == WebInputEvent::MouseMove) { + return true; // The recurring OnNull will send null events. + } + } + + switch (instance()->drawing_model()) { #ifndef NP_NO_QUICKDRAW - case NPDrawingModelQuickDraw: - SetPort(qd_port_.port); - break; + case NPDrawingModelQuickDraw: + SetPort(qd_port_.port); + break; #endif - case NPDrawingModelCoreGraphics: -#ifndef NP_NO_CARBON - if (instance()->event_model() == NPEventModelCarbon) + case NPDrawingModelCoreGraphics: CGContextSaveGState(cg_context_.context); -#endif - break; + break; + } } +#endif + // Create the plugin event structure, and send it to the plugin. + bool ret = false; switch (instance()->event_model()) { #ifndef NP_NO_CARBON - case NPEventModelCarbon: - // Send the event to the plugin. + case NPEventModelCarbon: { + NPEvent np_event = {0}; + if (!NPEventFromWebInputEvent(event, &np_event)) { + LOG(WARNING) << "NPEventFromWebInputEvent failed"; + return false; + } ret = instance()->NPP_HandleEvent(&np_event) != 0; break; + } #endif case NPEventModelCocoa: { NPCocoaEvent np_cocoa_event; |