Bug 1301306 - Stop focus events from anon. content when moving inside input=time element. r=smaug

This commit is contained in:
Jessica Jong 2016-11-04 00:47:00 -04:00
parent 400b326846
commit 726903109f
4 changed files with 119 additions and 1 deletions

View File

@ -4087,6 +4087,26 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
}
}
// Stop the event if the related target's first non-native ancestor is the
// same as the original target's first non-native ancestor (we are moving
// inside of the same element).
if (mType == NS_FORM_INPUT_TIME && !IsExperimentalMobileType(mType) &&
(aVisitor.mEvent->mMessage == eFocus ||
aVisitor.mEvent->mMessage == eFocusIn ||
aVisitor.mEvent->mMessage == eFocusOut ||
aVisitor.mEvent->mMessage == eBlur)) {
nsCOMPtr<nsIContent> originalTarget =
do_QueryInterface(aVisitor.mEvent->AsFocusEvent()->mRelatedTarget);
nsCOMPtr<nsIContent> relatedTarget =
do_QueryInterface(aVisitor.mEvent->AsFocusEvent()->mRelatedTarget);
if (originalTarget && relatedTarget &&
originalTarget->FindFirstNonChromeOnlyAccessContent() ==
relatedTarget->FindFirstNonChromeOnlyAccessContent()) {
aVisitor.mCanHandle = false;
}
}
return rv;
}

View File

@ -70,6 +70,8 @@ skip-if = (buildapp == 'b2g' && toolkit != 'gonk') #Bug 931116, b2g desktop spec
[test_input_textarea_set_value_no_scroll.html]
[test_input_time_key_events.html]
skip-if = os == "android" || appname == "b2g"
[test_input_time_focus_blur_events.html]
skip-if = os == "android" || appname == "b2g"
[test_input_types_pref.html]
[test_input_typing_sanitization.html]
skip-if = buildapp == 'mulet'

View File

@ -0,0 +1,82 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1301306
-->
<head>
<title>Test for Bug 1301306</title>
<script type="text/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" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1301306">Mozilla Bug 722599</a>
<p id="display"></p>
<div id="content">
<input type="time" id="input_time" onfocus="++focusEvent" onblur="++blurEvent"
onfocusin="++focusInEvent" onfocusout="++focusOutEvent">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/**
* Test for Bug 1301306.
* This test checks that when moving inside the time input element, e.g. jumping
* through the inner text boxes, does not fire extra focus/blur events.
**/
var focusEvent = 0;
var focusInEvent = 0;
var focusOutEvent = 0;
var blurEvent = 0;
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
test();
SimpleTest.finish();
});
function test() {
var time = document.getElementById("input_time");
time.focus();
is(focusEvent, 1, "time input element should have dispatched focus event.");
is(focusInEvent, 1, "time input element should have dispatched focusin event.");
is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
is(blurEvent, 0, "time input element should not have dispatched blur event.");
// Move around inside the input element's input box.
synthesizeKey("VK_TAB", {});
is(focusEvent, 1, "time input element should not have dispatched focus event.");
is(focusInEvent, 1, "time input element should have dispatched focusin event.");
is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
is(blurEvent, 0, "time input element should not have dispatched blur event.");
synthesizeKey("VK_RIGHT", {});
is(focusEvent, 1, "time input element should not have dispatched focus event.");
is(focusInEvent, 1, "time input element should have dispatched focusin event.");
is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
is(blurEvent, 0, "time input element should not have dispatched blur event.");
synthesizeKey("VK_LEFT", {});
is(focusEvent, 1, "time input element should not have dispatched focus event.");
is(focusInEvent, 1, "time input element should have dispatched focusin event.");
is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
is(blurEvent, 0, "time input element should not have dispatched blur event.");
synthesizeKey("VK_RIGHT", {});
is(focusEvent, 1, "time input element should not have dispatched focus event.");
is(focusInEvent, 1, "time input element should have dispatched focusin event.");
is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
is(blurEvent, 0, "time input element should not have dispatched blur event.");
time.blur();
is(focusEvent, 1, "time input element should not have dispatched focus event.");
is(focusInEvent, 1, "time input element should have dispatched focusin event.");
is(focusOutEvent, 1, "time input element should not have dispatched focusout event.");
is(blurEvent, 1, "time input element should have dispatched blur event.");
}
</script>
</pre>
</body>
</html>

View File

@ -1088,7 +1088,21 @@ EditorEventListener::Focus(nsIDOMEvent* aEvent)
nsCOMPtr<nsIDOMElement> element;
fm->GetFocusedElement(getter_AddRefs(element));
if (!SameCOMIdentity(element, target)) {
if (!element) {
return NS_OK;
}
nsCOMPtr<nsIDOMEventTarget> originalTarget;
aEvent->GetOriginalTarget(getter_AddRefs(originalTarget));
nsCOMPtr<nsIContent> originalTargetAsContent =
do_QueryInterface(originalTarget);
nsCOMPtr<nsIContent> focusedElementAsContent =
do_QueryInterface(element);
if (!SameCOMIdentity(
focusedElementAsContent->FindFirstNonChromeOnlyAccessContent(),
originalTargetAsContent->FindFirstNonChromeOnlyAccessContent())) {
return NS_OK;
}
}