зеркало из https://github.com/mozilla/gecko-dev.git
Bug 617528 Part 1 - Dispatch shift right click (contextmenu event) only to chrome. r=smaug
This commit is contained in:
Родитель
4e13ae6fbb
Коммит
f3265d93ce
|
@ -489,6 +489,21 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget,
|
||||||
|
|
||||||
nsCOMPtr<nsPIDOMEventTarget> target = do_QueryInterface(aTarget);
|
nsCOMPtr<nsPIDOMEventTarget> target = do_QueryInterface(aTarget);
|
||||||
|
|
||||||
|
PRBool retargeted = PR_FALSE;
|
||||||
|
|
||||||
|
if (aEvent->flags & NS_EVENT_RETARGET_TO_NON_NATIVE_ANONYMOUS) {
|
||||||
|
nsCOMPtr<nsIContent> content = do_QueryInterface(target);
|
||||||
|
if (content && content->IsInNativeAnonymousSubtree()) {
|
||||||
|
nsCOMPtr<nsPIDOMEventTarget> newTarget =
|
||||||
|
do_QueryInterface(content->FindFirstNonNativeAnonymous());
|
||||||
|
NS_ENSURE_STATE(newTarget);
|
||||||
|
|
||||||
|
aEvent->originalTarget = target;
|
||||||
|
target = newTarget;
|
||||||
|
retargeted = PR_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (aEvent->flags & NS_EVENT_FLAG_ONLY_CHROME_DISPATCH) {
|
if (aEvent->flags & NS_EVENT_FLAG_ONLY_CHROME_DISPATCH) {
|
||||||
nsCOMPtr<nsINode> node = do_QueryInterface(aTarget);
|
nsCOMPtr<nsINode> node = do_QueryInterface(aTarget);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
|
@ -579,7 +594,16 @@ nsEventDispatcher::Dispatch(nsISupports* aTarget,
|
||||||
aEvent->target = aEvent->target->GetTargetForEventTargetChain();
|
aEvent->target = aEvent->target->GetTargetForEventTargetChain();
|
||||||
NS_ENSURE_STATE(aEvent->target);
|
NS_ENSURE_STATE(aEvent->target);
|
||||||
}
|
}
|
||||||
aEvent->originalTarget = aEvent->target;
|
|
||||||
|
if (retargeted) {
|
||||||
|
aEvent->originalTarget =
|
||||||
|
aEvent->originalTarget->GetTargetForEventTargetChain();
|
||||||
|
NS_ENSURE_STATE(aEvent->originalTarget);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aEvent->originalTarget = aEvent->target;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->originalTarget);
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aEvent->originalTarget);
|
||||||
PRBool isInAnon = (content && content->IsInAnonymousSubtree());
|
PRBool isInAnon = (content && content->IsInAnonymousSubtree());
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,8 @@ _CHROME_FILES = \
|
||||||
bug415498-doc2.html \
|
bug415498-doc2.html \
|
||||||
bug602962.xul \
|
bug602962.xul \
|
||||||
test_bug602962.xul \
|
test_bug602962.xul \
|
||||||
|
test_bug617528.xul \
|
||||||
|
window_bug617528.xul \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
libs:: $(_TEST_FILES)
|
libs:: $(_TEST_FILES)
|
||||||
|
|
|
@ -0,0 +1,97 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
||||||
|
<?xml-stylesheet type="text/css"
|
||||||
|
href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=617528
|
||||||
|
-->
|
||||||
|
<window title="Mozilla Bug 617528"
|
||||||
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||||
|
|
||||||
|
<script type="application/javascript"
|
||||||
|
src="chrome://mochikit/content/MochiKit/packed.js"/>
|
||||||
|
<script type="application/javascript"
|
||||||
|
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
||||||
|
|
||||||
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=617528"
|
||||||
|
target="_blank">Mozilla Bug 617528</a>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
<script type="application/javascript"><![CDATA[
|
||||||
|
var _window;
|
||||||
|
var browser;
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
_window = window.open("window_bug617528.xul", "_new", "chrome");
|
||||||
|
_window.addEventListener("load", onLoad, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onLoad() {
|
||||||
|
_window.removeEventListener("load", onLoad, false);
|
||||||
|
|
||||||
|
browser = _window.document.getElementById("browser");
|
||||||
|
browser.addEventListener("pageshow", onPageShow, false);
|
||||||
|
|
||||||
|
var uri='data:text/html,\
|
||||||
|
<html>\
|
||||||
|
<body>\
|
||||||
|
<div oncontextmenu="event.preventDefault()">\
|
||||||
|
<input id="node" type="text" value="Click here"></input>\
|
||||||
|
</div>\
|
||||||
|
</body>\
|
||||||
|
</html>';
|
||||||
|
browser.loadURI(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPageShow() {
|
||||||
|
browser.removeEventListener("pageshow", onPageShow, true);
|
||||||
|
SimpleTest.executeSoon(doTest);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onContextMenu1(event) {
|
||||||
|
is(event.defaultPrevented, true,
|
||||||
|
"expected event.defaultPrevented to be true (1)");
|
||||||
|
is(event.target.localName, "input",
|
||||||
|
"expected event.target.localName to be 'input' (1)");
|
||||||
|
is(event.originalTarget.localName, "div",
|
||||||
|
"expected event.originalTarget.localName to be 'div' (1)");
|
||||||
|
}
|
||||||
|
|
||||||
|
function onContextMenu2(event) {
|
||||||
|
is(event.defaultPrevented, false,
|
||||||
|
"expected event.defaultPrevented to be false (2)");
|
||||||
|
is(event.target.localName, "input",
|
||||||
|
"expected event.target.localName to be 'input' (2)");
|
||||||
|
is(event.originalTarget.localName, "div",
|
||||||
|
"expected event.originalTarget.localName to be 'div' (2)");
|
||||||
|
}
|
||||||
|
|
||||||
|
function doTest() {
|
||||||
|
var win = browser.contentWindow;
|
||||||
|
win.focus();
|
||||||
|
var node = win.document.getElementById("node");
|
||||||
|
var rect = node.getBoundingClientRect();
|
||||||
|
var left = rect.left + rect.width / 2;
|
||||||
|
var top = rect.top + rect.height / 2;
|
||||||
|
|
||||||
|
var wu = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||||
|
|
||||||
|
browser.addEventListener("contextmenu", onContextMenu1, false);
|
||||||
|
wu.sendMouseEvent("contextmenu", left, top, 2, 1, 0);
|
||||||
|
browser.removeEventListener("contextmenu", onContextMenu1, false);
|
||||||
|
|
||||||
|
browser.addEventListener("contextmenu", onContextMenu2, false);
|
||||||
|
var shiftMask = Components.interfaces.nsIDOMNSEvent.SHIFT_MASK;
|
||||||
|
wu.sendMouseEvent("contextmenu", left, top, 2, 1, shiftMask);
|
||||||
|
browser.removeEventListener("contextmenu", onContextMenu2, false);
|
||||||
|
|
||||||
|
_window.close();
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
addLoadEvent(start);
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
]]></script>
|
||||||
|
</window>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
|
||||||
|
|
||||||
|
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||||
|
width="640" height="480">
|
||||||
|
|
||||||
|
<browser id="browser" type="content-primary" flex="1" src="about:blank"
|
||||||
|
disablehistory="true" disablesecurity="true"/>
|
||||||
|
|
||||||
|
</window>
|
|
@ -7104,6 +7104,9 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView,
|
||||||
!AdjustContextMenuKeyEvent(me)) {
|
!AdjustContextMenuKeyEvent(me)) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
if (me->isShift)
|
||||||
|
aEvent->flags |= NS_EVENT_FLAG_ONLY_CHROME_DISPATCH |
|
||||||
|
NS_EVENT_RETARGET_TO_NON_NATIVE_ANONYMOUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
|
nsAutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput,
|
||||||
|
|
|
@ -161,6 +161,8 @@ class nsHashKey;
|
||||||
|
|
||||||
#define NS_EVENT_FLAG_PREVENT_ANCHOR_ACTIONS 0x20000
|
#define NS_EVENT_FLAG_PREVENT_ANCHOR_ACTIONS 0x20000
|
||||||
|
|
||||||
|
#define NS_EVENT_RETARGET_TO_NON_NATIVE_ANONYMOUS 0x40000
|
||||||
|
|
||||||
#define NS_EVENT_CAPTURE_MASK (~(NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH))
|
#define NS_EVENT_CAPTURE_MASK (~(NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH))
|
||||||
#define NS_EVENT_BUBBLE_MASK (~(NS_EVENT_FLAG_CAPTURE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH))
|
#define NS_EVENT_BUBBLE_MASK (~(NS_EVENT_FLAG_CAPTURE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH))
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче