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:
Jessica Jong 2016-05-30 02:26:00 +02:00
Родитель bd172274b3
Коммит 2f552465b5
2 изменённых файлов: 23 добавлений и 6 удалений

Просмотреть файл

@ -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();
}