summaryrefslogtreecommitdiffstats
path: root/dom/html/HTMLInputElement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/html/HTMLInputElement.cpp')
-rw-r--r--dom/html/HTMLInputElement.cpp62
1 files changed, 32 insertions, 30 deletions
diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp
index 958601616b..9a7f7e02bd 100644
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -1986,18 +1986,21 @@ Decimal HTMLInputElement::GetStepBase() const {
return kDefaultStepBase;
}
-nsresult HTMLInputElement::GetValueIfStepped(int32_t aStep,
- StepCallerType aCallerType,
- Decimal* aNextStep) {
+Decimal HTMLInputElement::GetValueIfStepped(int32_t aStep,
+ StepCallerType aCallerType,
+ ErrorResult& aRv) {
+ constexpr auto kNaN = Decimal::nan();
if (!DoStepDownStepUpApply()) {
- return NS_ERROR_DOM_INVALID_STATE_ERR;
+ aRv.ThrowInvalidStateError("Step doesn't apply to this input type");
+ return kNaN;
}
Decimal stepBase = GetStepBase();
Decimal step = GetStep();
if (step == kStepAny) {
- if (aCallerType != CALLED_FOR_USER_EVENT) {
- return NS_ERROR_DOM_INVALID_STATE_ERR;
+ if (aCallerType != StepCallerType::ForUserEvent) {
+ aRv.ThrowInvalidStateError("Can't step an input with step=\"any\"");
+ return kNaN;
}
// Allow the spin buttons and up/down arrow keys to do something sensible:
step = GetDefaultStep();
@@ -2015,7 +2018,7 @@ nsresult HTMLInputElement::GetValueIfStepped(int32_t aStep,
// adjustment to align maximum on a step, or else (if we adjusted
// maximum) there is no valid step between minimum and the unadjusted
// maximum.
- return NS_OK;
+ return kNaN;
}
}
}
@@ -2062,25 +2065,20 @@ nsresult HTMLInputElement::GetValueIfStepped(int32_t aStep,
(aStep < 0 && value > valueBeforeStepping))) {
// We don't want step-up to effectively step down, or step-down to
// effectively step up, so return;
- return NS_OK;
+ return kNaN;
}
- *aNextStep = value;
- return NS_OK;
+ return value;
}
-nsresult HTMLInputElement::ApplyStep(int32_t aStep) {
- Decimal nextStep = Decimal::nan(); // unchanged if value will not change
-
- nsresult rv = GetValueIfStepped(aStep, CALLED_FOR_SCRIPT, &nextStep);
-
- if (NS_SUCCEEDED(rv) && nextStep.isFinite()) {
- // We know we're not a file input, so the caller type does not matter; just
- // pass "not system" to be safe.
- SetValue(nextStep, CallerType::NonSystem);
+void HTMLInputElement::ApplyStep(int32_t aStep, ErrorResult& aRv) {
+ Decimal nextStep = GetValueIfStepped(aStep, StepCallerType::ForScript, aRv);
+ if (aRv.Failed() || !nextStep.isFinite()) {
+ return;
}
-
- return rv;
+ // We know we're not a file input, so the caller type does not matter; just
+ // pass "not system" to be safe.
+ SetValue(nextStep, CallerType::NonSystem);
}
bool HTMLInputElement::IsDateTimeInputType(FormControlType aType) {
@@ -3520,11 +3518,9 @@ void HTMLInputElement::StepNumberControlForUserEvent(int32_t aDirection) {
}
}
- Decimal newValue = Decimal::nan(); // unchanged if value will not change
-
- nsresult rv = GetValueIfStepped(aDirection, CALLED_FOR_USER_EVENT, &newValue);
-
- if (NS_FAILED(rv) || !newValue.isFinite()) {
+ Decimal newValue = GetValueIfStepped(aDirection, StepCallerType::ForUserEvent,
+ IgnoreErrors());
+ if (!newValue.isFinite()) {
return; // value should not or will not change
}
@@ -3794,6 +3790,12 @@ nsresult HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
if (mType == FormControlType::InputRadio && keyEvent->IsTrusted() &&
!keyEvent->IsAlt() && !keyEvent->IsControl() &&
!keyEvent->IsMeta()) {
+ // Radio button navigation needs to check visibility, so flush
+ // to ensure visibility is up to date.
+ if (Document* doc = GetComposedDoc()) {
+ doc->FlushPendingNotifications(
+ FlushType::EnsurePresShellInitAndFrames);
+ }
rv = MaybeHandleRadioButtonNavigation(aVisitor, keyEvent->mKeyCode);
}
@@ -6427,10 +6429,10 @@ void HTMLInputElement::RemoveFromRadioGroup() {
mRadioGroupContainer = nullptr;
}
-bool HTMLInputElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
- int32_t* aTabIndex) {
+bool HTMLInputElement::IsHTMLFocusable(IsFocusableFlags aFlags,
+ bool* aIsFocusable, int32_t* aTabIndex) {
if (nsGenericHTMLFormControlElementWithState::IsHTMLFocusable(
- aWithMouse, aIsFocusable, aTabIndex)) {
+ aFlags, aIsFocusable, aTabIndex)) {
return true;
}
@@ -6444,7 +6446,7 @@ bool HTMLInputElement::IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
return false;
}
- const bool defaultFocusable = IsFormControlDefaultFocusable(aWithMouse);
+ const bool defaultFocusable = IsFormControlDefaultFocusable(aFlags);
if (CreatesDateTimeWidget()) {
if (aTabIndex) {
// We only want our native anonymous child to be tabable to, not ourself.