From d5a643b3c3a317fc30ac818fb84267f83d01542b Mon Sep 17 00:00:00 2001 From: Georg Fritzsche Date: Fri, 10 Aug 2012 20:28:34 +0200 Subject: [PATCH] Bug 751809 - Fix OSX focus issue with click-to-play. r=josh --- dom/plugins/base/nsPluginInstanceOwner.cpp | 6 ++ dom/plugins/test/mochitest/Makefile.in | 1 + .../test/mochitest/test_bug751809.html | 92 +++++++++++++++++++ dom/plugins/test/testplugin/nptest.cpp | 20 +++- dom/plugins/test/testplugin/nptest.h | 1 + dom/plugins/test/testplugin/nptest_gtk2.cpp | 6 ++ dom/plugins/test/testplugin/nptest_macosx.mm | 6 ++ dom/plugins/test/testplugin/nptest_qt.cpp | 1 + .../test/testplugin/nptest_windows.cpp | 3 + 9 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 dom/plugins/test/mochitest/test_bug751809.html diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index a7b11d1776d5..6fe8d14890c2 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -3777,6 +3777,12 @@ void nsPluginInstanceOwner::SetFrame(nsObjectFrame *aFrame) } } #endif + + nsFocusManager* fm = nsFocusManager::GetFocusManager(); + const nsIContent* content = aFrame->GetContent(); + if (fm && content) { + mContentFocused = (content == fm->GetFocusedContent()); + } } } diff --git a/dom/plugins/test/mochitest/Makefile.in b/dom/plugins/test/mochitest/Makefile.in index 666850b25f9b..8c634d3991e5 100644 --- a/dom/plugins/test/mochitest/Makefile.in +++ b/dom/plugins/test/mochitest/Makefile.in @@ -64,6 +64,7 @@ MOCHITEST_FILES = \ test_bug771202.html \ file_bug771202.html \ test_bug777098.html \ + test_bug751809.html \ test_enumerate.html \ test_npruntime_construct.html \ 307-xo-redirect.sjs \ diff --git a/dom/plugins/test/mochitest/test_bug751809.html b/dom/plugins/test/mochitest/test_bug751809.html new file mode 100644 index 000000000000..3dfab1a5a29d --- /dev/null +++ b/dom/plugins/test/mochitest/test_bug751809.html @@ -0,0 +1,92 @@ + + + Bug 751809 + + + + + + + + + diff --git a/dom/plugins/test/testplugin/nptest.cpp b/dom/plugins/test/testplugin/nptest.cpp index 968b767eb553..d90a7f1132fb 100644 --- a/dom/plugins/test/testplugin/nptest.cpp +++ b/dom/plugins/test/testplugin/nptest.cpp @@ -163,6 +163,7 @@ static bool setSitesWithData(NPObject* npobj, const NPVariant* args, uint32_t ar static bool setSitesWithDataCapabilities(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool getLastKeyText(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static bool getNPNVdocumentOrigin(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); +static bool getMouseUpEventCount(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result); static const NPUTF8* sPluginMethodIdentifierNames[] = { "npnEvaluateTest", @@ -222,7 +223,8 @@ static const NPUTF8* sPluginMethodIdentifierNames[] = { "setSitesWithData", "setSitesWithDataCapabilities", "getLastKeyText", - "getNPNVdocumentOrigin" + "getNPNVdocumentOrigin", + "getMouseUpEventCount" }; static NPIdentifier sPluginMethodIdentifiers[ARRAY_LENGTH(sPluginMethodIdentifierNames)]; static const ScriptableFunction sPluginMethodFunctions[] = { @@ -283,7 +285,8 @@ static const ScriptableFunction sPluginMethodFunctions[] = { setSitesWithData, setSitesWithDataCapabilities, getLastKeyText, - getNPNVdocumentOrigin + getNPNVdocumentOrigin, + getMouseUpEventCount }; STATIC_ASSERT(ARRAY_LENGTH(sPluginMethodIdentifierNames) == @@ -777,6 +780,7 @@ NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* instanceData->asyncDrawing = AD_NONE; instanceData->frontBuffer = NULL; instanceData->backBuffer = NULL; + instanceData->mouseUpEventCount = 0; instance->pdata = instanceData; TestNPObject* scriptableObject = (TestNPObject*)NPN_CreateObject(instance, &sNPClass); @@ -3649,3 +3653,15 @@ bool getNPNVdocumentOrigin(NPObject* npobj, const NPVariant* args, uint32_t argC STRINGZ_TO_NPVARIANT(origin, *result); return true; } + +bool getMouseUpEventCount(NPObject* npobj, const NPVariant* args, uint32_t argCount, NPVariant* result) +{ + if (argCount != 0) { + return false; + } + + NPP npp = static_cast(npobj)->npp; + InstanceData* id = static_cast(npp->pdata); + INT32_TO_NPVARIANT(id->mouseUpEventCount, *result); + return true; +} diff --git a/dom/plugins/test/testplugin/nptest.h b/dom/plugins/test/testplugin/nptest.h index 1d28c6ac1aa1..029aef35db44 100644 --- a/dom/plugins/test/testplugin/nptest.h +++ b/dom/plugins/test/testplugin/nptest.h @@ -150,6 +150,7 @@ typedef struct InstanceData { AsyncDrawing asyncDrawing; NPAsyncSurface *frontBuffer; NPAsyncSurface *backBuffer; + int32_t mouseUpEventCount; } InstanceData; void notifyDidPaint(InstanceData* instanceData); diff --git a/dom/plugins/test/testplugin/nptest_gtk2.cpp b/dom/plugins/test/testplugin/nptest_gtk2.cpp index a75cd70135de..f9bf3c134a33 100644 --- a/dom/plugins/test/testplugin/nptest_gtk2.cpp +++ b/dom/plugins/test/testplugin/nptest_gtk2.cpp @@ -254,6 +254,9 @@ ButtonEvent(GtkWidget* widget, GdkEventButton* event, InstanceData* instanceData = static_cast(user_data); instanceData->lastMouseX = event->x; instanceData->lastMouseY = event->y; + if (event->type == GDK_BUTTON_RELEASE) { + instanceData->mouseUpEventCount++; + } return TRUE; } @@ -418,6 +421,9 @@ pluginHandleEvent(InstanceData* instanceData, void* event) XButtonEvent* button = &nsEvent->xbutton; instanceData->lastMouseX = button->x; instanceData->lastMouseY = button->y; + if (nsEvent->type == ButtonRelease) { + instanceData->mouseUpEventCount++; + } break; } default: diff --git a/dom/plugins/test/testplugin/nptest_macosx.mm b/dom/plugins/test/testplugin/nptest_macosx.mm index 46a0f3fca76e..3637c0170827 100644 --- a/dom/plugins/test/testplugin/nptest_macosx.mm +++ b/dom/plugins/test/testplugin/nptest_macosx.mm @@ -276,6 +276,9 @@ pluginHandleEvent(InstanceData* instanceData, void* event) ::GetWindowBounds(nativeWindow, kWindowStructureRgn, &globalBounds); instanceData->lastMouseX = carbonEvent->where.h - w->x - globalBounds.left; instanceData->lastMouseY = carbonEvent->where.v - w->y - globalBounds.top; + if (carbonEvent->what == mouseUp) { + instanceData->mouseUpEventCount++; + } break; } default: @@ -299,6 +302,9 @@ pluginHandleEvent(InstanceData* instanceData, void* event) case NPCocoaEventMouseMoved: instanceData->lastMouseX = (int32_t)cocoaEvent->data.mouse.pluginX; instanceData->lastMouseY = (int32_t)cocoaEvent->data.mouse.pluginY; + if (cocoaEvent->type == NPCocoaEventMouseUp) { + instanceData->mouseUpEventCount++; + } break; case NPCocoaEventWindowFocusChanged: instanceData->topLevelWindowActivationState = cocoaEvent->data.focus.hasFocus ? diff --git a/dom/plugins/test/testplugin/nptest_qt.cpp b/dom/plugins/test/testplugin/nptest_qt.cpp index 7042ea32b0ac..aba43271a0a3 100644 --- a/dom/plugins/test/testplugin/nptest_qt.cpp +++ b/dom/plugins/test/testplugin/nptest_qt.cpp @@ -193,6 +193,7 @@ pluginHandleEvent(InstanceData* instanceData, void* event) XButtonEvent* button = &nsEvent->xbutton; instanceData->lastMouseX = button->x; instanceData->lastMouseY = button->y; + instanceData->mouseUpEventCount++; break; } default: diff --git a/dom/plugins/test/testplugin/nptest_windows.cpp b/dom/plugins/test/testplugin/nptest_windows.cpp index 4fbe96d13cc2..0a638a179364 100644 --- a/dom/plugins/test/testplugin/nptest_windows.cpp +++ b/dom/plugins/test/testplugin/nptest_windows.cpp @@ -602,6 +602,9 @@ handleEventInternal(InstanceData* instanceData, NPEvent* pe, LRESULT* result) int y = instanceData->hasWidget ? 0 : instanceData->winY; instanceData->lastMouseX = GET_X_LPARAM(pe->lParam) - x; instanceData->lastMouseY = GET_Y_LPARAM(pe->lParam) - y; + if ((UINT)pe->event == WM_LBUTTONUP) { + instanceData->mouseUpEventCount++; + } return true; }