mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1741469 part 2: Add an off-by-default pref to control whether input type="number" fields are modified when mousewheel-scrolled. r=smaug
The C++ code change here is simply replacing an ifdef with a pref-check (and associated reindentation for being placed in an "if"-block). The pref is off-by-default for now, since no other browser seems to modify these fields through mousewheel scrolling, and users seem to be surprised when they encounter the behavior in Firefox. See discussion on the bugzilla page. Note: now that this behavior is controlled by a pref, we don't need to have platform-specific #ifdefs and "skip-if" test exemptions. If we decide to bring this behavior back on certain platforms, we can do so by simply changing the default value of the pref on those platforms. Differential Revision: https://phabricator.services.mozilla.com/D175719
This commit is contained in:
parent
8a8b01a6e0
commit
c97c4ebace
@ -3962,39 +3962,41 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
#if !defined(ANDROID) && !defined(XP_MACOSX)
|
||||
case eWheel: {
|
||||
// Handle wheel events as increasing / decreasing the input element's
|
||||
// value when it's focused and it's type is number or range.
|
||||
WidgetWheelEvent* wheelEvent = aVisitor.mEvent->AsWheelEvent();
|
||||
if (!aVisitor.mEvent->DefaultPrevented() &&
|
||||
aVisitor.mEvent->IsTrusted() && IsMutable() && wheelEvent &&
|
||||
wheelEvent->mDeltaY != 0 &&
|
||||
wheelEvent->mDeltaMode != WheelEvent_Binding::DOM_DELTA_PIXEL) {
|
||||
if (mType == FormControlType::InputNumber) {
|
||||
if (nsContentUtils::IsFocusedContent(this)) {
|
||||
StepNumberControlForUserEvent(wheelEvent->mDeltaY > 0 ? -1 : 1);
|
||||
if (StaticPrefs::dom_input_scrollwheel_modifies_number_value()) {
|
||||
// Handle wheel events as increasing / decreasing the input
|
||||
// element's value when it's focused and it's type is number or
|
||||
// range.
|
||||
WidgetWheelEvent* wheelEvent = aVisitor.mEvent->AsWheelEvent();
|
||||
if (!aVisitor.mEvent->DefaultPrevented() &&
|
||||
aVisitor.mEvent->IsTrusted() && IsMutable() && wheelEvent &&
|
||||
wheelEvent->mDeltaY != 0 &&
|
||||
wheelEvent->mDeltaMode != WheelEvent_Binding::DOM_DELTA_PIXEL) {
|
||||
if (mType == FormControlType::InputNumber) {
|
||||
if (nsContentUtils::IsFocusedContent(this)) {
|
||||
StepNumberControlForUserEvent(wheelEvent->mDeltaY > 0 ? -1
|
||||
: 1);
|
||||
FireChangeEventIfNeeded();
|
||||
aVisitor.mEvent->PreventDefault();
|
||||
}
|
||||
} else if (mType == FormControlType::InputRange &&
|
||||
nsContentUtils::IsFocusedContent(this) &&
|
||||
GetMinimum() < GetMaximum()) {
|
||||
Decimal value = GetValueAsDecimal();
|
||||
Decimal step = GetStep();
|
||||
if (step == kStepAny) {
|
||||
step = GetDefaultStep();
|
||||
}
|
||||
MOZ_ASSERT(value.isFinite() && step.isFinite());
|
||||
SetValueOfRangeForUserEvent(
|
||||
wheelEvent->mDeltaY < 0 ? value + step : value - step);
|
||||
FireChangeEventIfNeeded();
|
||||
aVisitor.mEvent->PreventDefault();
|
||||
}
|
||||
} else if (mType == FormControlType::InputRange &&
|
||||
nsContentUtils::IsFocusedContent(this) &&
|
||||
GetMinimum() < GetMaximum()) {
|
||||
Decimal value = GetValueAsDecimal();
|
||||
Decimal step = GetStep();
|
||||
if (step == kStepAny) {
|
||||
step = GetDefaultStep();
|
||||
}
|
||||
MOZ_ASSERT(value.isFinite() && step.isFinite());
|
||||
SetValueOfRangeForUserEvent(
|
||||
wheelEvent->mDeltaY < 0 ? value + step : value - step);
|
||||
FireChangeEventIfNeeded();
|
||||
aVisitor.mEvent->PreventDefault();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case eMouseClick: {
|
||||
if (!aVisitor.mEvent->DefaultPrevented() &&
|
||||
aVisitor.mEvent->IsTrusted() &&
|
||||
|
@ -562,7 +562,6 @@ skip-if =
|
||||
[test_bug1250401.html]
|
||||
[test_bug1260664.html]
|
||||
[test_bug1261673.html]
|
||||
skip-if = (os == 'android' || os == 'mac')
|
||||
[test_bug1261674-1.html]
|
||||
skip-if = (os == 'android' || os == 'mac')
|
||||
[test_bug1261674-2.html]
|
||||
|
@ -52,6 +52,10 @@ function runTests() {
|
||||
let actualChangeCount = 0;
|
||||
let expectedChangeCount = 0;
|
||||
|
||||
const prefName = "dom.input.scrollwheel-modifies-number-value";
|
||||
let didFlipPref = false;
|
||||
let isPrefEnabled = SpecialPowers.getBoolPref(prefName);
|
||||
is(isPrefEnabled, false, "Expecting pref to be disabled by default");
|
||||
input.addEventListener("change", () => {
|
||||
++actualChangeCount;
|
||||
});
|
||||
@ -59,22 +63,35 @@ function runTests() {
|
||||
function runNext() {
|
||||
let p = params[testIdx];
|
||||
(p.focus) ? input.focus() : input.blur();
|
||||
if (p.valueChanged != 0) {
|
||||
if (isPrefEnabled && p.valueChanged != 0) {
|
||||
expectedChangeCount++;
|
||||
expectedValue += p.valueChanged;
|
||||
}
|
||||
|
||||
sendWheelAndPaint(input, 1, 1, { deltaY: p.deltaY, deltaMode: p.deltaMode },
|
||||
() => {
|
||||
async () => {
|
||||
is(parseInt(input.value), expectedValue,
|
||||
"Handle wheel in number input test-" + testIdx);
|
||||
"Handle wheel in number input test-" + testIdx +
|
||||
" with pref " + (isPrefEnabled ? "en" : "dis") + "abled");
|
||||
|
||||
is(actualChangeCount, expectedChangeCount,
|
||||
"UA should fire change event when input's value changed");
|
||||
if (++testIdx < params.length) {
|
||||
// More subtests remain; kick off the next one.
|
||||
runNext();
|
||||
} else if (!didFlipPref) {
|
||||
// Reached the end of the subtest list. Flip the pref
|
||||
// and restart our iteration over the subtests.
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [[prefName, !isPrefEnabled]],
|
||||
});
|
||||
isPrefEnabled = !isPrefEnabled;
|
||||
didFlipPref = true;
|
||||
testIdx = actualChangeCount = expectedChangeCount = 0;
|
||||
runNext();
|
||||
} else {
|
||||
// Reached the end of the subtest list. We're done!
|
||||
// Reached the end of the subtest list, for both pref settings.
|
||||
// We're done!
|
||||
SimpleTest.finish();
|
||||
}
|
||||
});
|
||||
|
@ -3036,6 +3036,13 @@
|
||||
value: true
|
||||
mirror: always
|
||||
|
||||
# Does mousewheel scrolling over a focused <input type="number"> field cause
|
||||
# the number value to increase/decrease (rather than scrolling the page)?
|
||||
- name: dom.input.scrollwheel-modifies-number-value
|
||||
type: RelaxedAtomicBool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# Whether to allow or disallow web apps to cancel `beforeinput` events caused
|
||||
# by MozEditableElement#setUserInput() which is used by autocomplete, autofill
|
||||
# and password manager.
|
||||
|
Loading…
Reference in New Issue
Block a user