зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1608010
- Support reversed range for <input type=time>; r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D64416 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
09ea5c7d92
Коммит
e1afc79aff
|
@ -266,6 +266,73 @@ bool TimeInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TimeInputType::HasReversedRange() const {
|
||||
mozilla::Decimal maximum = mInputElement->GetMaximum();
|
||||
if (maximum.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Decimal minimum = mInputElement->GetMinimum();
|
||||
if (minimum.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return maximum < minimum;
|
||||
}
|
||||
|
||||
bool TimeInputType::IsReversedRangeUnderflowAndOverflow() const {
|
||||
mozilla::Decimal maximum = mInputElement->GetMaximum();
|
||||
mozilla::Decimal minimum = mInputElement->GetMinimum();
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
|
||||
MOZ_ASSERT(HasReversedRange(), "Must have reserved range.");
|
||||
|
||||
if (value.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// When an element has a reversed range, and the value is more than the
|
||||
// maximum and less than the minimum the element is simultaneously suffering
|
||||
// from an underflow and suffering from an overflow.
|
||||
return value > maximum && value < minimum;
|
||||
}
|
||||
|
||||
bool TimeInputType::IsRangeOverflow() const {
|
||||
return HasReversedRange() ? IsReversedRangeUnderflowAndOverflow()
|
||||
: DateTimeInputTypeBase::IsRangeOverflow();
|
||||
}
|
||||
|
||||
bool TimeInputType::IsRangeUnderflow() const {
|
||||
return HasReversedRange() ? IsReversedRangeUnderflowAndOverflow()
|
||||
: DateTimeInputTypeBase::IsRangeUnderflow();
|
||||
}
|
||||
|
||||
nsresult TimeInputType::GetReversedRangeUnderflowAndOverflowMessage(
|
||||
nsAString& aMessage) {
|
||||
nsAutoString maxStr;
|
||||
mInputElement->GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxStr);
|
||||
|
||||
nsAutoString minStr;
|
||||
mInputElement->GetAttr(kNameSpaceID_None, nsGkAtoms::min, minStr);
|
||||
|
||||
return nsContentUtils::FormatMaybeLocalizedString(
|
||||
aMessage, nsContentUtils::eDOM_PROPERTIES,
|
||||
"FormValidationTimeReversedRangeUnderflowAndOverflow",
|
||||
mInputElement->OwnerDoc(), minStr, maxStr);
|
||||
}
|
||||
|
||||
nsresult TimeInputType::GetRangeOverflowMessage(nsAString& aMessage) {
|
||||
return HasReversedRange()
|
||||
? GetReversedRangeUnderflowAndOverflowMessage(aMessage)
|
||||
: DateTimeInputTypeBase::GetRangeOverflowMessage(aMessage);
|
||||
}
|
||||
|
||||
nsresult TimeInputType::GetRangeUnderflowMessage(nsAString& aMessage) {
|
||||
return HasReversedRange()
|
||||
? GetReversedRangeUnderflowAndOverflowMessage(aMessage)
|
||||
: DateTimeInputTypeBase::GetRangeUnderflowMessage(aMessage);
|
||||
}
|
||||
|
||||
// input type=week
|
||||
|
||||
bool WeekInputType::ConvertStringToNumber(
|
||||
|
|
|
@ -85,10 +85,19 @@ class TimeInputType : public DateTimeInputTypeBase {
|
|||
mozilla::Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
nsAString& aResultString) const override;
|
||||
bool IsRangeOverflow() const override;
|
||||
bool IsRangeUnderflow() const override;
|
||||
nsresult GetRangeOverflowMessage(nsAString& aMessage) override;
|
||||
nsresult GetRangeUnderflowMessage(nsAString& aMessage) override;
|
||||
|
||||
private:
|
||||
explicit TimeInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: DateTimeInputTypeBase(aInputElement) {}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#has-a-reversed-range
|
||||
bool HasReversedRange() const;
|
||||
bool IsReversedRangeUnderflowAndOverflow() const;
|
||||
nsresult GetReversedRangeUnderflowAndOverflowMessage(nsAString& aMessage);
|
||||
};
|
||||
|
||||
// input type=week
|
||||
|
|
|
@ -52,6 +52,8 @@ FormValidationDateTimeRangeUnderflow=Please select a value that is no earlier th
|
|||
FormValidationStepMismatch=Please select a valid value. The two nearest valid values are %S and %S.
|
||||
# LOCALIZATION NOTE (FormValidationStepMismatchOneValue): %S can be a number, a date or a time. This is called instead of FormValidationStepMismatch when the second value is the same as the first.
|
||||
FormValidationStepMismatchOneValue=Please select a valid value. The nearest valid value is %S.
|
||||
# LOCALIZATION NOTE (FormValidationTimeReversedRangeUnderflowAndOverflow): %1$S,%2$S are time.
|
||||
FormValidationTimeReversedRangeUnderflowAndOverflow=Please select a value between %1$S and %2$S.
|
||||
FormValidationBadInputNumber=Please enter a number.
|
||||
FullscreenDeniedDisabled=Request for fullscreen was denied because Fullscreen API is disabled by user preference.
|
||||
FullscreenDeniedFocusedPlugin=Request for fullscreen was denied because a windowed plugin is focused.
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
[form-validation-validity-rangeOverflow.html]
|
||||
|
||||
[[INPUT in TIME status\] The time is inside the accepted range for reversed range]
|
||||
expected: FAIL
|
||||
|
||||
[[INPUT in TIME status\] The time is min for reversed range]
|
||||
expected: FAIL
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
[form-validation-validity-rangeUnderflow.html]
|
||||
[[INPUT in TIME status\] The time is max for reversed range]
|
||||
expected: FAIL
|
Загрузка…
Ссылка в новой задаче