Bug 1850293 - Make editable states not intrinsic. r=smaug,masayuki

This one is tricky because form controls, though I think I got it right...

This fixes a pre-existing bug where we're not following the spec for readonly
inside content-editable.

I filed this as bug 1850390 but other browsers match the spec so add a test and
fix it while at it. This allows cheaper checks for readonlyness in a couple
places.

Differential Revision: https://phabricator.services.mozilla.com/D186896
This commit is contained in:
Emilio Cobos Álvarez
2023-08-30 09:18:31 +00:00
parent a429e38b7d
commit 3e9e56e2c8
21 changed files with 113 additions and 150 deletions

View File

@@ -418,10 +418,10 @@ void nsGenericHTMLElement::UpdateEditableState(bool aNotify) {
// XXX Should we do this only when in a document?
ContentEditableTristate value = GetContentEditableValue();
if (value != eInherit) {
DoSetEditableFlag(!!value, aNotify);
SetEditableFlag(!!value);
UpdateReadOnlyState(aNotify);
return;
}
nsStyledElement::UpdateEditableState(aNotify);
}
@@ -486,8 +486,7 @@ void nsGenericHTMLElement::UnbindFromTree(bool aNullParent) {
RemoveFromNameTable();
if (GetContentEditableValue() == eTrue) {
Document* doc = GetComposedDoc();
if (doc) {
if (Document* doc = GetComposedDoc()) {
doc->ChangeContentEditableCount(this, -1);
}
}
@@ -1704,9 +1703,9 @@ bool nsGenericHTMLElement::IsFormControlDefaultFocusable(
nsGenericHTMLFormElement::nsGenericHTMLFormElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
: nsGenericHTMLElement(std::move(aNodeInfo)) {
// We should add the ElementState::ENABLED bit here as needed, but
// that depends on our type, which is not initialized yet. So we
// have to do this in subclasses.
// We should add the ElementState::ENABLED bit here as needed, but that
// depends on our type, which is not initialized yet. So we have to do this
// in subclasses. Same for a couple other bits.
}
void nsGenericHTMLFormElement::ClearForm(bool aRemoveFromForm,
@@ -2166,11 +2165,18 @@ void nsGenericHTMLFormElement::UpdateDisabledState(bool aNotify) {
ToggleStates(changedStates, aNotify);
if (DoesReadOnlyApply()) {
// :disabled influences :read-only / :read-write.
UpdateState(aNotify);
UpdateReadOnlyState(aNotify);
}
}
}
bool nsGenericHTMLFormElement::IsReadOnlyInternal() const {
if (DoesReadOnlyApply()) {
return IsDisabled() || GetBoolAttr(nsGkAtoms::readonly);
}
return nsGenericHTMLElement::IsReadOnlyInternal();
}
void nsGenericHTMLFormElement::FieldSetDisabledChanged(bool aNotify) {
UpdateDisabledState(aNotify);
}
@@ -2632,14 +2638,6 @@ ElementState nsGenericHTMLFormControlElement::IntrinsicState() const {
state |= ElementState::DEFAULT;
}
// Make the text controls read-write
if (!state.HasState(ElementState::READWRITE) && DoesReadOnlyApply()) {
if (!GetBoolAttr(nsGkAtoms::readonly) && !IsDisabled()) {
state |= ElementState::READWRITE;
state &= ~ElementState::READONLY;
}
}
return state;
}