Bug 1850293 - Make indeterminate state non-intrinsic. r=edgar

Differential Revision: https://phabricator.services.mozilla.com/D187015
This commit is contained in:
Emilio Cobos Álvarez
2023-08-30 09:18:32 +00:00
parent ff4402054b
commit 127accb890
6 changed files with 50 additions and 44 deletions

View File

@@ -1483,6 +1483,11 @@ uint32_t HTMLInputElement::Height() {
void HTMLInputElement::SetIndeterminateInternal(bool aValue,
bool aShouldInvalidate) {
mIndeterminate = aValue;
if (mType != FormControlType::InputCheckbox) {
return;
}
SetStates(ElementState::INDETERMINATE, aValue);
if (aShouldInvalidate) {
// Repaint the frame
@@ -1490,8 +1495,6 @@ void HTMLInputElement::SetIndeterminateInternal(bool aValue,
frame->InvalidateFrameSubtree();
}
}
UpdateState(true);
}
void HTMLInputElement::SetIndeterminate(bool aValue) {
@@ -2954,6 +2957,19 @@ void HTMLInputElement::UpdateCheckedState(bool aNotify) {
SetStates(ElementState::CHECKED, IsRadioOrCheckbox() && mChecked, aNotify);
}
void HTMLInputElement::UpdateIndeterminateState(bool aNotify) {
bool indeterminate = [&] {
if (mType == FormControlType::InputCheckbox) {
return mIndeterminate;
}
if (mType == FormControlType::InputRadio) {
return !mChecked && !GetSelectedRadioButton();
}
return false;
}();
SetStates(ElementState::INDETERMINATE, indeterminate, aNotify);
}
void HTMLInputElement::SetCheckedInternal(bool aChecked, bool aNotify) {
// Set the value
mChecked = aChecked;
@@ -2969,7 +2985,8 @@ void HTMLInputElement::SetCheckedInternal(bool aChecked, bool aNotify) {
// No need to update element state, since we're about to call
// UpdateState anyway.
UpdateAllValidityStatesButNotElementState();
// :indeterminate and validity state still require UpdateState to be called.
UpdateIndeterminateState(aNotify);
// validity state still require UpdateState to be called.
UpdateState(aNotify);
// Notify all radios in the group that value has changed, this is to let
@@ -4394,6 +4411,7 @@ void HTMLInputElement::HandleTypeChange(FormControlType aNewType,
// Whether readonly applies might have changed.
UpdateReadOnlyState(aNotify);
UpdateCheckedState(aNotify);
UpdateIndeterminateState(aNotify);
const bool isDefault = IsRadioOrCheckbox()
? DefaultChecked()
: (mForm && mForm->IsDefaultSubmitElement(this));
@@ -6041,16 +6059,7 @@ ElementState HTMLInputElement::IntrinsicState() const {
// HandleTypeChange.
ElementState state =
nsGenericHTMLFormControlElementWithState::IntrinsicState();
// Check current indeterminate state (:indeterminate)
if (mType == FormControlType::InputCheckbox && mIndeterminate) {
state |= ElementState::INDETERMINATE;
} else if (mType == FormControlType::InputRadio) {
HTMLInputElement* selected = GetSelectedRadioButton();
const bool indeterminate = !selected && !mChecked;
if (indeterminate) {
state |= ElementState::INDETERMINATE;
}
} else if (mType == FormControlType::InputImage) {
if (mType == FormControlType::InputImage) {
state |= nsImageLoadingContent::ImageState();
}