Bug 1741469 part 3: Add an off-by-default pref to control whether input type="number"/"range" 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:
@@ -3962,39 +3962,42 @@ 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_number_and_range_modified_by_mousewheel()) {
|
||||
// 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 ePointerClick: {
|
||||
if (!aVisitor.mEvent->DefaultPrevented() &&
|
||||
aVisitor.mEvent->IsTrusted() &&
|
||||
|
||||
Reference in New Issue
Block a user