From 4cdce19d4b7fd9ac70a57e4873f93ecd18148d5a Mon Sep 17 00:00:00 2001 From: "joshmoz%gmail.com" Date: Thu, 6 Sep 2007 05:11:35 +0000 Subject: [PATCH] send native events to plugins on mouse enter and exit. b=332597 r=smichaud sr=roc --- widget/src/cocoa/nsChildView.mm | 35 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 808f112cc4c..03a8dd4c932 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -87,6 +87,11 @@ PRLogModuleInfo* sCocoaLog = nsnull; #endif +// npapi.h defines NPEventType_AdjustCursorEvent but we don't want to include npapi.h here. +// We need to send this in the "what" field for certain native plugin events. WebKit does +// this as well. +#define adjustCursorEvent 33 + extern "C" { CG_EXTERN void CGContextResetCTM(CGContextRef); CG_EXTERN void CGContextSetCTM(CGContextRef, CGAffineTransform); @@ -2621,11 +2626,12 @@ class nsNonNativeContextMenuEvent : public nsRunnable { } -static nsEventStatus SendMouseEvent(PRBool isTrusted, - PRUint32 msg, - nsIWidget *widget, - nsMouseEvent::reasonType aReason, - NSPoint* localEventLocation) +// sends a mouse enter or exit event into gecko +static nsEventStatus SendGeckoMouseEnterOrExitEvent(PRBool isTrusted, + PRUint32 msg, + nsIWidget *widget, + nsMouseEvent::reasonType aReason, + NSPoint* localEventLocation) { if (!widget || !localEventLocation) return nsEventStatus_eIgnore; @@ -2634,6 +2640,14 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, event.refPoint.x = nscoord((PRInt32)localEventLocation->x); event.refPoint.y = nscoord((PRInt32)localEventLocation->y); + EventRecord macEvent; + macEvent.what = adjustCursorEvent; + macEvent.message = 0; + macEvent.when = ::TickCount(); + ::GetGlobalMouse(&macEvent.where); + macEvent.modifiers = GetCurrentKeyModifiers(); + event.nativeMsg = &macEvent; + nsEventStatus status; widget->DispatchEvent(&event, status); return status; @@ -2655,7 +2669,7 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, if (![NSApp isActive] && ![ChildView mouseEventIsOverRollupWidget:theEvent]) { if (sLastViewEntered) { nsIWidget* lastViewEnteredWidget = [(NSView*)sLastViewEntered widget]; - SendMouseEvent(PR_TRUE, NS_MOUSE_EXIT, lastViewEnteredWidget, nsMouseEvent::eReal, &viewEventLocation); + SendGeckoMouseEnterOrExitEvent(PR_TRUE, NS_MOUSE_EXIT, lastViewEnteredWidget, nsMouseEvent::eReal, &viewEventLocation); sLastViewEntered = nil; } return; @@ -2733,7 +2747,7 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, if (sLastViewEntered) { // NSLog(@"sending NS_MOUSE_EXIT event with point %f,%f\n", viewEventLocation.x, viewEventLocation.y); nsIWidget* lastViewEnteredWidget = [(NSView*)sLastViewEntered widget]; - SendMouseEvent(PR_TRUE, NS_MOUSE_EXIT, lastViewEnteredWidget, nsMouseEvent::eReal, &viewEventLocation); + SendGeckoMouseEnterOrExitEvent(PR_TRUE, NS_MOUSE_EXIT, lastViewEnteredWidget, nsMouseEvent::eReal, &viewEventLocation); sLastViewEntered = nil; } return; @@ -2748,11 +2762,11 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, if (sLastViewEntered) { // NSLog(@"sending NS_MOUSE_EXIT event with point %f,%f\n", viewEventLocation.x, viewEventLocation.y); nsIWidget* lastViewEnteredWidget = [(NSView*)sLastViewEntered widget]; - SendMouseEvent(PR_TRUE, NS_MOUSE_EXIT, lastViewEnteredWidget, nsMouseEvent::eReal, &viewEventLocation); + SendGeckoMouseEnterOrExitEvent(PR_TRUE, NS_MOUSE_EXIT, lastViewEnteredWidget, nsMouseEvent::eReal, &viewEventLocation); } // NSLog(@"sending NS_MOUSE_ENTER event with point %f,%f\n", viewEventLocation.x, viewEventLocation.y); - SendMouseEvent(PR_TRUE, NS_MOUSE_ENTER, mGeckoChild, nsMouseEvent::eReal, &viewEventLocation); + SendGeckoMouseEnterOrExitEvent(PR_TRUE, NS_MOUSE_ENTER, mGeckoChild, nsMouseEvent::eReal, &viewEventLocation); // mark this view as the last view entered sLastViewEntered = (NSView*)self; @@ -2772,11 +2786,10 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, // create native EventRecord for use by plugins EventRecord macEvent; - macEvent.what = nullEvent; + macEvent.what = adjustCursorEvent; macEvent.message = 0; macEvent.when = ::TickCount(); ::GetGlobalMouse(&macEvent.where); - macEvent.modifiers = GetCurrentKeyModifiers(); geckoEvent.nativeMsg = &macEvent;