Bug 751809 - Fix OSX focus issue with click-to-play. r=josh

This commit is contained in:
Georg Fritzsche 2012-08-10 20:28:34 +02:00
parent 23b07d64df
commit 9037e4a2d2
9 changed files with 131 additions and 2 deletions

View File

@ -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());
}
}
}

View File

@ -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 \

View File

@ -0,0 +1,89 @@
<html>
<head>
<title>Bug 751809</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const Ci = Components.interfaces;
const clickToPlayPref = "plugins.click_to_play";
const utils = window.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
function waitForCondition(condition, nextTest, errorMsg) {
var tries = 0;
var interval = setInterval(function() {
if (tries >= 30) {
ok(false, errorMsg);
moveOn();
}
if (condition()) {
moveOn();
}
tries++;
}, 100);
var moveOn = function() { clearInterval(interval); nextTest(); };
}
function startFocusTest() {
var plugin = document.getElementById('plugin');
ok(plugin, "Got plugin element.");
var condition = function() plugin.getBoundingClientRect().width == 400;
waitForCondition(condition, afterPluginInsertion, "Waited too long for plugin to show up in page");
}
function afterPluginInsertion() {
var plugin = document.getElementById('plugin');
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(!objLoadingContent.activated, "plugin should not be activated");
synthesizeMouseAtCenter(plugin, {}, window);
var condition = function() objLoadingContent.activated;
waitForCondition(condition, afterPluginActivation, "Waited too long for plugin to activate");
}
function afterPluginActivation() {
var plugin = document.getElementById('plugin');
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(objLoadingContent.activated, "plugin should be activated now");
is(plugin.getMouseUpEventCount(), 0, "Plugin should not have received mouse events yet.");
synthesizeMouseAtCenter(plugin, {}, window);
var condition = function() plugin.getMouseUpEventCount() > 0;
waitForCondition(condition, afterFirstClick, "Waited too long for plugin to receive the mouse click");
}
function afterFirstClick() {
var plugin = document.getElementById('plugin');
is(plugin.getMouseUpEventCount(), 1, "Plugin should have received 1 mouse up event.");
testsFinished();
}
function testsFinished() {
try {
SpecialPowers.clearUserPref(clickToPlayPref);
}
catch(e) {
ok(false, "Couldn't reset click-to-play pref");
}
SimpleTest.finish();
}
SpecialPowers.setBoolPref(clickToPlayPref, true);
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
document.write('<embed id="plugin" type="application/x-test" width="400" height="400" drawmode="solid" color="FF00FFFF"></embed>');
SimpleTest.executeSoon(startFocusTest);
</script>
</body>
</html>

View File

@ -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<TestNPObject*>(npobj)->npp;
InstanceData* id = static_cast<InstanceData*>(npp->pdata);
INT32_TO_NPVARIANT(id->mouseUpEventCount, *result);
return true;
}

View File

@ -149,6 +149,7 @@ typedef struct InstanceData {
AsyncDrawing asyncDrawing;
NPAsyncSurface *frontBuffer;
NPAsyncSurface *backBuffer;
int32_t mouseUpEventCount;
} InstanceData;
void notifyDidPaint(InstanceData* instanceData);

View File

@ -254,6 +254,9 @@ ButtonEvent(GtkWidget* widget, GdkEventButton* event,
InstanceData* instanceData = static_cast<InstanceData*>(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:

View File

@ -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 ?

View File

@ -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:

View File

@ -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;
}