Bug 1850295 - Update :user-{valid,invalid} to follow the spec. r=smaug

(Modulo open spec issues linked in comments)

Differential Revision: https://phabricator.services.mozilla.com/D196986
This commit is contained in:
Emilio Cobos Álvarez
2024-01-16 11:09:01 +00:00
parent 97909653e7
commit b9aedffc24
69 changed files with 203 additions and 1109 deletions

View File

@@ -15,7 +15,6 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/Variant.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/HTMLFormElement.h" // for HasEverTriedInvalidSubmit()
#include "mozilla/dom/HTMLInputElementBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/UnionTypes.h"
@@ -36,6 +35,7 @@
#include "nsIContentPrefService2.h"
#include "nsContentUtils.h"
class nsIEditor;
class nsIRadioVisitor;
namespace mozilla {
@@ -338,7 +338,7 @@ class HTMLInputElement final : public TextControlElement,
// as needed. aNotify controls whether the element state update
// needs to notify.
void UpdateAllValidityStates(bool aNotify);
void UpdateValidityElementStates(bool aNotify) final;
void UpdateValidityElementStates(bool aNotify);
MOZ_CAN_RUN_SCRIPT
void MaybeUpdateAllValidityStates(bool aNotify) {
// If you need to add new type which supports validationMessage, you should
@@ -395,16 +395,7 @@ class HTMLInputElement final : public TextControlElement,
*/
void SetFilePickerFiltersFromAccept(nsIFilePicker* filePicker);
/**
* The form might need to request an update of the UI bits
* (BF_CAN_SHOW_INVALID_UI and BF_CAN_SHOW_VALID_UI) when an invalid form
* submission is tried.
*
* @param aIsFocused Whether the element is currently focused.
*
* @note The caller is responsible to call ContentStatesChanged.
*/
void UpdateValidityUIBits(bool aIsFocused);
void SetUserInteracted(bool) final;
/**
* Fires change event if mFocusedValue and current value held are unequal and
@@ -1115,37 +1106,6 @@ class HTMLInputElement final : public TextControlElement,
void SetAutoDirectionality(bool aNotify,
const nsAString* aKnownValue = nullptr);
/**
* Return if an element should have a specific validity UI
* (with :-moz-ui-invalid and :-moz-ui-valid pseudo-classes).
*
* @return Whether the element should have a validity UI.
*/
bool ShouldShowValidityUI() const {
/**
* Always show the validity UI if the form has already tried to be submitted
* but was invalid.
*
* Otherwise, show the validity UI if the element's value has been changed.
*/
if (mForm && mForm->HasEverTriedInvalidSubmit()) {
return true;
}
switch (GetValueMode()) {
case VALUE_MODE_DEFAULT:
return true;
case VALUE_MODE_DEFAULT_ON:
return GetCheckedChanged();
case VALUE_MODE_VALUE:
case VALUE_MODE_FILENAME:
return mValueChanged;
}
MOZ_ASSERT_UNREACHABLE("We should not be there: there are no other modes.");
return false;
}
/**
* Returns the radio group container within the DOM tree that the element
* is currently a member of, if one exists.
@@ -1551,6 +1511,8 @@ class HTMLInputElement final : public TextControlElement,
// https://html.spec.whatwg.org/#concept-fe-dirty
// TODO: Maybe rename to match the spec?
bool mValueChanged : 1;
// https://html.spec.whatwg.org/#user-interacted
bool mUserInteracted : 1;
bool mLastValueChangeWasInteractive : 1;
bool mCheckedChanged : 1;
bool mChecked : 1;
@@ -1561,8 +1523,6 @@ class HTMLInputElement final : public TextControlElement,
bool mCheckedIsToggled : 1;
bool mIndeterminate : 1;
bool mInhibitRestoration : 1;
bool mCanShowValidUI : 1;
bool mCanShowInvalidUI : 1;
bool mHasRange : 1;
bool mIsDraggingRange : 1;
bool mNumberControlSpinnerIsSpinning : 1;