зеркало из https://github.com/mozilla/gecko-dev.git
Bug 541904 - Accept middle mouse clicks and Cmd+left clicks on background windows. r=josh
This commit is contained in:
Родитель
fbf4d62272
Коммит
fd0d65678f
|
@ -6329,11 +6329,11 @@ ChildViewMouseTracker::WindowForEvent(NSEvent* anEvent)
|
|||
}
|
||||
|
||||
BOOL
|
||||
ChildViewMouseTracker::WindowAcceptsEvent(NSWindow* aWindow, NSEvent* anEvent)
|
||||
ChildViewMouseTracker::WindowAcceptsEvent(NSWindow* aWindow, NSEvent* aEvent)
|
||||
{
|
||||
// Right mouse down events may get through to all windows, even to a top level
|
||||
// window with an open sheet.
|
||||
if (!aWindow || [anEvent type] == NSRightMouseDown)
|
||||
if (!aWindow || [aEvent type] == NSRightMouseDown)
|
||||
return YES;
|
||||
|
||||
id delegate = [aWindow delegate];
|
||||
|
@ -6347,33 +6347,46 @@ ChildViewMouseTracker::WindowAcceptsEvent(NSWindow* aWindow, NSEvent* anEvent)
|
|||
nsWindowType windowType;
|
||||
windowWidget->GetWindowType(windowType);
|
||||
|
||||
NSWindow* topLevelWindow = nil;
|
||||
|
||||
switch (windowType) {
|
||||
case eWindowType_popup:
|
||||
// If this is a context menu, it won't have a parent. So we'll always
|
||||
// accept mouse move events on context menus even when none of our windows
|
||||
// is active, which is the right thing to do.
|
||||
// For panels, the parent window is the XUL window that owns the panel.
|
||||
return WindowAcceptsEvent([aWindow parentWindow], anEvent);
|
||||
return WindowAcceptsEvent([aWindow parentWindow], aEvent);
|
||||
|
||||
case eWindowType_toplevel:
|
||||
case eWindowType_dialog:
|
||||
// Block all mouse events other than RightMouseDown on background windows
|
||||
// and on windows behind sheets.
|
||||
return [aWindow isMainWindow] && ![aWindow attachedSheet];
|
||||
if ([aWindow attachedSheet])
|
||||
return NO;
|
||||
|
||||
topLevelWindow = aWindow;
|
||||
break;
|
||||
case eWindowType_sheet: {
|
||||
nsIWidget* parentWidget = windowWidget->GetSheetWindowParent();
|
||||
if (!parentWidget)
|
||||
return YES;
|
||||
|
||||
// Only accept mouse events on a sheet whose containing window is active.
|
||||
NSWindow* parentWindow = (NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW);
|
||||
return [parentWindow isMainWindow];
|
||||
topLevelWindow = (NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (!topLevelWindow ||
|
||||
[topLevelWindow isMainWindow] ||
|
||||
[aEvent type] == NSOtherMouseDown ||
|
||||
(([aEvent modifierFlags] & NSCommandKeyMask) != 0 &&
|
||||
[aEvent type] != NSMouseMoved))
|
||||
return YES;
|
||||
|
||||
// If we're here then we're dealing with a left click or mouse move on an
|
||||
// inactive window or something similar. Return NO for now.
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
|
|
@ -113,6 +113,15 @@
|
|||
NSEventTypeBeginGesture = 19,
|
||||
NSEventTypeEndGesture = 20;
|
||||
|
||||
const NSAlphaShiftKeyMask = 1 << 16,
|
||||
NSShiftKeyMask = 1 << 17,
|
||||
NSControlKeyMask = 1 << 18,
|
||||
NSAlternateKeyMask = 1 << 19,
|
||||
NSCommandKeyMask = 1 << 20,
|
||||
NSNumericPadKeyMask = 1 << 21,
|
||||
NSHelpKeyMask = 1 << 22,
|
||||
NSFunctionKeyMask = 1 << 23;
|
||||
|
||||
const gDebug = false;
|
||||
|
||||
function printDebug(msg) { if (gDebug) dump(msg); }
|
||||
|
@ -120,7 +129,7 @@
|
|||
var gExpectedEvents = [];
|
||||
var gRightWindow = null, gPopup = null;
|
||||
|
||||
function testMouse(x, y, msg, elem, win, exp, callback) {
|
||||
function testMouse(x, y, msg, elem, win, exp, flags, callback) {
|
||||
clearExpectedEvents();
|
||||
exp.forEach(function (expEv) {
|
||||
expEv.screenX = x;
|
||||
|
@ -131,7 +140,7 @@
|
|||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
||||
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||
utils.sendNativeMouseEvent(x, y, msg, 0, elem);
|
||||
utils.sendNativeMouseEvent(x, y, msg, flags || 0, elem);
|
||||
SimpleTest.executeSoon(function () {
|
||||
clearExpectedEvents();
|
||||
callback();
|
||||
|
@ -249,6 +258,22 @@
|
|||
[400, 150, NSMouseMoved, null, right, [
|
||||
{ type: "mouseout", target: leftElem },
|
||||
]],
|
||||
// Left-clicking while holding Cmd and middle clicking should work even
|
||||
// on inactive windows, but without making them active.
|
||||
[400, 150, NSLeftMouseDown, null, right, [
|
||||
{ type: "mousedown", target: rightElem },
|
||||
], NSCommandKeyMask],
|
||||
[400, 150, NSLeftMouseUp, null, right, [
|
||||
{ type: "mouseup", target: rightElem },
|
||||
{ type: "click", target: rightElem },
|
||||
], NSCommandKeyMask],
|
||||
[400, 150, NSOtherMouseDown, null, right, [
|
||||
{ type: "mousedown", target: rightElem },
|
||||
]],
|
||||
[400, 150, NSOtherMouseUp, null, right, [
|
||||
{ type: "mouseup", target: rightElem },
|
||||
{ type: "click", target: rightElem },
|
||||
]],
|
||||
// Clicking an inactive window should make it active and fire a mouseover
|
||||
// event.
|
||||
[400, 150, NSLeftMouseDown, null, right, [
|
||||
|
@ -482,8 +507,8 @@
|
|||
if (typeof test == "function")
|
||||
return test(runNextTest);
|
||||
|
||||
var [x, y, msg, elem, win, exp] = test;
|
||||
testMouse(x, y, msg, elem, win, exp, runNextTest);
|
||||
var [x, y, msg, elem, win, exp, flags] = test;
|
||||
testMouse(x, y, msg, elem, win, exp, flags, runNextTest);
|
||||
}
|
||||
runNextTest();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче