зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1079236, Event.composedTarget to reveal the original non-native-anonymous event target, r=wchen, r=smaug
This commit is contained in:
Родитель
0031547106
Коммит
faee2dfe7e
|
@ -362,6 +362,20 @@ Event::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
EventTarget*
|
||||
Event::GetComposedTarget() const
|
||||
{
|
||||
EventTarget* et = GetOriginalTarget();
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(et);
|
||||
if (!content) {
|
||||
return et;
|
||||
}
|
||||
nsIContent* nonChrome = content->FindFirstNonChromeOnlyAccessContent();
|
||||
return nonChrome ?
|
||||
static_cast<EventTarget*>(nonChrome) :
|
||||
static_cast<EventTarget*>(content->GetComposedDoc());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
Event::SetTrusted(bool aTrusted)
|
||||
{
|
||||
|
|
|
@ -205,6 +205,7 @@ public:
|
|||
|
||||
EventTarget* GetOriginalTarget() const;
|
||||
EventTarget* GetExplicitOriginalTarget() const;
|
||||
EventTarget* GetComposedTarget() const;
|
||||
|
||||
bool GetPreventDefault() const;
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ skip-if = toolkit == "gonk" || e10s
|
|||
support-files = bug1017086_inner.html
|
||||
[test_bug1017086_enable.html]
|
||||
support-files = bug1017086_inner.html
|
||||
[test_bug1079236.html]
|
||||
[test_clickevent_on_input.html]
|
||||
skip-if = toolkit == 'android' #CRASH_DUMP, RANDOM
|
||||
[test_continuous_wheel_events.html]
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1079236
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test for Bug 1079236</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 1079236 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(runTests);
|
||||
|
||||
function runTests() {
|
||||
var c = document.getElementById("content");
|
||||
var sr = c.createShadowRoot();
|
||||
sr.innerHTML = "<input type='file'" + ">";
|
||||
var file = sr.firstChild;
|
||||
is(file.type, "file");
|
||||
file.offsetLeft; // Flush layout because dispatching mouse events.
|
||||
document.body.onmousemove = function(e) {
|
||||
is(e.target, c, "Event target should be the element in non-Shadow DOM");
|
||||
if (e.originalTarget == file) {
|
||||
is(e.originalTarget, file,
|
||||
"type='file' implementation doesn't seem to have native anonymous content");
|
||||
} else {
|
||||
var wrapped = SpecialPowers.wrap(e.originalTarget);
|
||||
isnot(wrapped, file, "Shouldn't have the same event.target and event.originalTarget");
|
||||
}
|
||||
|
||||
ok(!("composedTarget" in e), "Events shouldn't have composedTarget in non-chrome context!");
|
||||
e = SpecialPowers.wrap(e);
|
||||
var composedTarget = SpecialPowers.unwrap(e.composedTarget);
|
||||
ok(composedTarget, file, "composedTarget should be the file object.");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
var r = file.getBoundingClientRect();
|
||||
synthesizeMouse(file, r.width / 6, r.height / 2, { type: "mousemove"} );
|
||||
document.body.onmousemove = null;
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1079236">Mozilla Bug 1079236</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -355,7 +355,7 @@ let FormAssistant = {
|
|||
},
|
||||
|
||||
handleEvent: function fa_handleEvent(evt) {
|
||||
let target = evt.target;
|
||||
let target = evt.composedTarget;
|
||||
|
||||
let range = null;
|
||||
switch (evt.type) {
|
||||
|
|
|
@ -56,6 +56,7 @@ partial interface Event {
|
|||
|
||||
readonly attribute EventTarget? originalTarget;
|
||||
readonly attribute EventTarget? explicitOriginalTarget;
|
||||
[ChromeOnly] readonly attribute EventTarget? composedTarget;
|
||||
[ChromeOnly] readonly attribute boolean multipleActionsPrevented;
|
||||
[ChromeOnly] readonly attribute boolean isSynthesized;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче