зеркало из https://github.com/mozilla/gecko-dev.git
Bug 926019 - focus and blur an input element should not trigger change event if content hasn't changed. r=smaug
--HG-- extra : rebase_source : 9d56196ae2597cc21f7366326ce7203fe16e6cfb
This commit is contained in:
Родитель
bd172274b3
Коммит
2f552465b5
|
@ -3800,6 +3800,15 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
|||
// We must cache type because mType may change during JS event (bug 2369)
|
||||
aVisitor.mItemFlags |= mType;
|
||||
|
||||
if (aVisitor.mEvent->mMessage == eFocus &&
|
||||
aVisitor.mEvent->IsTrusted() &&
|
||||
MayFireChangeOnBlur() &&
|
||||
// StartRangeThumbDrag already set mFocusedValue on 'mousedown' before
|
||||
// we get the 'focus' event.
|
||||
!mIsDraggingRange) {
|
||||
GetValue(mFocusedValue);
|
||||
}
|
||||
|
||||
// Fire onchange (if necessary), before we do the blur, bug 357684.
|
||||
if (aVisitor.mEvent->mMessage == eBlur) {
|
||||
// Experimental mobile types rely on the system UI to prevent users to not
|
||||
|
@ -4235,12 +4244,6 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
|||
|
||||
if (aVisitor.mEvent->mMessage == eFocus ||
|
||||
aVisitor.mEvent->mMessage == eBlur) {
|
||||
if (aVisitor.mEvent->mMessage == eFocus &&
|
||||
MayFireChangeOnBlur() &&
|
||||
!mIsDraggingRange) { // StartRangeThumbDrag already set mFocusedValue
|
||||
GetValue(mFocusedValue);
|
||||
}
|
||||
|
||||
if (aVisitor.mEvent->mMessage == eBlur) {
|
||||
if (mIsDraggingRange) {
|
||||
FinishRangeThumbDrag();
|
||||
|
|
|
@ -32,6 +32,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=722599
|
|||
<input type="number" id="input_number" onchange="++numberChange;"></input>
|
||||
<input type="range" id="input_range" onchange="++rangeChange;"></input>
|
||||
|
||||
<!-- Input text with default value and blurs on focus-->
|
||||
<input type="text" id="input_text_value" onchange="++textInputValueChange"
|
||||
onfocus="this.blur();" value="foo"></input>
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
@ -42,6 +46,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=722599
|
|||
|
||||
var textareaChange = 0;
|
||||
var fileInputChange = 0;
|
||||
var textInputValueChange = 0;
|
||||
|
||||
var textInputTypes = ["text", "email", "search", "tel", "url", "password"];
|
||||
var textInputChange = [0, 0, 0, 0, 0, 0];
|
||||
|
@ -236,6 +241,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=722599
|
|||
input.blur();
|
||||
is(NonTextInputChange[5], 1, "Change event shouldn't be dispatched for checkbox ---> text input type change");
|
||||
|
||||
setTimeout(testInputWithDefaultValue, 0);
|
||||
}
|
||||
|
||||
function testInputWithDefaultValue() {
|
||||
// focus and blur an input text should not trigger change event if content hasn't changed.
|
||||
var input = document.getElementById('input_text_value');
|
||||
input.focus();
|
||||
is(textInputValueChange, 0, "change event shouldn't be dispatched on input text with default value");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче