зеркало из https://github.com/mozilla/gecko-dev.git
Bug 615833 - Change event should not be cancelable. r=smaug a=sicking
--HG-- extra : rebase_source : a067989d8ce1297a9ed9869f931b64f33f2fed9f
This commit is contained in:
Родитель
67259dffcd
Коммит
d0c28d9134
|
@ -444,7 +444,7 @@ AsyncClickHandler::Run()
|
|||
nsContentUtils::DispatchTrustedEvent(mInput->GetOwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(mInput.get()),
|
||||
NS_LITERAL_STRING("change"), PR_TRUE,
|
||||
PR_TRUE);
|
||||
PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1719,20 +1719,6 @@ nsHTMLInputElement::SetCheckedInternal(PRBool aChecked, PRBool aNotify)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsHTMLInputElement::FireOnChange()
|
||||
{
|
||||
//
|
||||
// Since the value is changing, send out an onchange event (bug 23571)
|
||||
//
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsEvent event(PR_TRUE, NS_FORM_CHANGE);
|
||||
nsRefPtr<nsPresContext> presContext = GetPresContext();
|
||||
nsEventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
|
||||
&event, nsnull, &status);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLInputElement::Blur()
|
||||
{
|
||||
|
@ -2234,7 +2220,10 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|||
DoSetChecked(originalCheckedValue, PR_TRUE, PR_TRUE);
|
||||
}
|
||||
} else {
|
||||
FireOnChange();
|
||||
nsContentUtils::DispatchTrustedEvent(GetOwnerDoc(),
|
||||
static_cast<nsIDOMHTMLInputElement*>(this),
|
||||
NS_LITERAL_STRING("change"), PR_TRUE,
|
||||
PR_FALSE);
|
||||
#ifdef ACCESSIBILITY
|
||||
// Fire an event to notify accessibility
|
||||
if (mType == NS_FORM_INPUT_CHECKBOX) {
|
||||
|
|
|
@ -419,11 +419,6 @@ protected:
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the onChange event
|
||||
*/
|
||||
void FireOnChange();
|
||||
|
||||
/**
|
||||
* Visit the group of radio buttons this radio belongs to
|
||||
* @param aVisitor the visitor to visit with
|
||||
|
|
|
@ -251,6 +251,7 @@ _TEST_FILES = \
|
|||
test_bug612730.html \
|
||||
test_bug613722.html \
|
||||
test_bug613979.html \
|
||||
test_bug615833.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -186,7 +186,7 @@ SimpleTest.waitForFocus(function() {
|
|||
document.getElementById('a').addEventListener("change", function(aEvent) {
|
||||
ok(true, "change event correctly sent");
|
||||
ok(aEvent.bubbles, "change event should bubble");
|
||||
todo(!aEvent.cancelable, "change event should not be cancelable");
|
||||
ok(!aEvent.cancelable, "change event should not be cancelable");
|
||||
testCounter++;
|
||||
|
||||
if (testCounter >= testNb) {
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=615697
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 615697</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<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"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=615697">Mozilla Bug 615697</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<input>
|
||||
<textarea></textarea>
|
||||
<input type='radio'>
|
||||
<input type='checkbox'>
|
||||
<select>
|
||||
<option>foo</option>
|
||||
<option>bar</option>
|
||||
</select>
|
||||
<select multiple size='1'>
|
||||
<option>tulip</option>
|
||||
</select>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 615697 **/
|
||||
|
||||
/**
|
||||
* This test is making all elements trigger 'change' event.
|
||||
* You should read the test from bottom to top:
|
||||
* events are registered from the last one to the first one.
|
||||
*
|
||||
* Sometimes, elements are focused before a click. This might sound useless
|
||||
* but it guarantees to have the element visible before simulating the click.
|
||||
*/
|
||||
|
||||
var input = document.getElementsByTagName('input')[0];
|
||||
var textarea = document.getElementsByTagName('textarea')[0];
|
||||
var radio = document.getElementsByTagName('input')[1];
|
||||
var checkbox= document.getElementsByTagName('input')[2];
|
||||
var select = document.getElementsByTagName('select')[0];
|
||||
var selectMultiple = document.getElementsByTagName('select')[1];
|
||||
|
||||
function checkChangeEvent(aEvent)
|
||||
{
|
||||
ok(aEvent.bubbles, "change event should bubble");
|
||||
ok(!aEvent.cancelable, "change event shouldn't be cancelable");
|
||||
}
|
||||
|
||||
selectMultiple.addEventListener("change", function(aEvent) {
|
||||
selectMultiple.removeEventListener("change", arguments.callee, false);
|
||||
checkChangeEvent(aEvent);
|
||||
SimpleTest.finish();
|
||||
}, false);
|
||||
|
||||
selectMultiple.addEventListener("focus", function() {
|
||||
selectMultiple.removeEventListener("focus", arguments.callee, false);
|
||||
synthesizeMouseAtCenter(selectMultiple, {});
|
||||
}, false);
|
||||
|
||||
select.addEventListener("change", function(aEvent) {
|
||||
select.removeEventListener("change", arguments.callee, false);
|
||||
checkChangeEvent(aEvent);
|
||||
selectMultiple.focus();
|
||||
}, false);
|
||||
|
||||
select.addEventListener("keyup", function() {
|
||||
select.removeEventListener("keyup", arguments.callee, false);
|
||||
select.blur();
|
||||
}, false);
|
||||
|
||||
select.addEventListener("focus", function() {
|
||||
select.removeEventListener("focus", arguments.callee, false);
|
||||
synthesizeKey("VK_DOWN", {});
|
||||
}, false);
|
||||
|
||||
checkbox.addEventListener("change", function(aEvent) {
|
||||
checkbox.removeEventListener("change", arguments.callee, false);
|
||||
checkChangeEvent(aEvent);
|
||||
select.focus();
|
||||
}, false);
|
||||
|
||||
checkbox.addEventListener("focus", function() {
|
||||
checkbox.removeEventListener("focus", arguments.callee, false);
|
||||
synthesizeMouseAtCenter(checkbox, {});
|
||||
}, false);
|
||||
|
||||
radio.addEventListener("change", function(aEvent) {
|
||||
radio.removeEventListener("change", arguments.callee, false);
|
||||
checkChangeEvent(aEvent);
|
||||
checkbox.focus();
|
||||
}, false);
|
||||
|
||||
radio.addEventListener("focus", function() {
|
||||
radio.removeEventListener("focus", arguments.callee, false);
|
||||
synthesizeMouseAtCenter(radio, {});
|
||||
}, false);
|
||||
|
||||
textarea.addEventListener("change", function(aEvent) {
|
||||
textarea.removeEventListener("change", arguments.callee, false);
|
||||
checkChangeEvent(aEvent);
|
||||
radio.focus();
|
||||
}, false);
|
||||
|
||||
textarea.addEventListener("input", function() {
|
||||
textarea.removeEventListener("input", arguments.callee, false);
|
||||
textarea.blur();
|
||||
}, false);
|
||||
|
||||
textarea.addEventListener("focus", function() {
|
||||
textarea.removeEventListener("focus", arguments.callee, false);
|
||||
synthesizeKey('f', {});
|
||||
}, false);
|
||||
|
||||
input.addEventListener("change", function(aEvent) {
|
||||
input.removeEventListener("change", arguments.callee, false);
|
||||
checkChangeEvent(aEvent);
|
||||
textarea.focus();
|
||||
}, false);
|
||||
|
||||
input.addEventListener("input", function() {
|
||||
input.removeEventListener("input", arguments.callee, false);
|
||||
input.blur();
|
||||
}, false);
|
||||
|
||||
input.addEventListener("focus", function() {
|
||||
input.removeEventListener("focus", arguments.callee, false);
|
||||
synthesizeKey('f', {});
|
||||
}, false);
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(function() {
|
||||
input.focus();
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -1628,14 +1628,10 @@ nsListControlFrame::FireOnChange()
|
|||
return;
|
||||
}
|
||||
|
||||
// Dispatch the NS_FORM_CHANGE event
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsEvent event(PR_TRUE, NS_FORM_CHANGE);
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell = PresContext()->GetPresShell();
|
||||
if (presShell) {
|
||||
presShell->HandleEventWithTarget(&event, this, nsnull, &status);
|
||||
}
|
||||
// Dispatch the change event.
|
||||
nsContentUtils::DispatchTrustedEvent(mContent->GetOwnerDoc(), mContent,
|
||||
NS_LITERAL_STRING("change"), PR_TRUE,
|
||||
PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1359,11 +1359,10 @@ nsTextControlFrame::CheckFireOnChange()
|
|||
if (!mFocusedValue.Equals(value))
|
||||
{
|
||||
mFocusedValue = value;
|
||||
// Dispatch the change event
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
nsInputEvent event(PR_TRUE, NS_FORM_CHANGE, nsnull);
|
||||
nsCOMPtr<nsIPresShell> shell = PresContext()->PresShell();
|
||||
shell->HandleEventWithTarget(&event, nsnull, mContent, &status);
|
||||
// Dispatch the change event.
|
||||
nsContentUtils::DispatchTrustedEvent(mContent->GetOwnerDoc(), mContent,
|
||||
NS_LITERAL_STRING("change"), PR_TRUE,
|
||||
PR_FALSE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче