mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1849122, allowing getting and modifying the autofill state directly within the input and select elements, and reset this state when its value changes, r=webidl,emilio
Resetting the state when the value is modified is bug 1359355. Differential Revision: https://phabricator.services.mozilla.com/D210999
This commit is contained in:
parent
702be51774
commit
1515db9b71
@ -6975,6 +6975,10 @@ void HTMLInputElement::OnValueChanged(ValueChangeKind aKind,
|
||||
MOZ_ASSERT_IF(aKnownNewValue, aKnownNewValue->IsEmpty() == aNewValueEmpty);
|
||||
if (aKind != ValueChangeKind::Internal) {
|
||||
mLastValueChangeWasInteractive = aKind == ValueChangeKind::UserInteraction;
|
||||
|
||||
if (State().HasState(ElementState::AUTOFILL)) {
|
||||
RemoveStates(ElementState::AUTOFILL | ElementState::AUTOFILL_PREVIEW);
|
||||
}
|
||||
}
|
||||
|
||||
if (aNewValueEmpty != IsValueEmpty()) {
|
||||
|
@ -248,6 +248,12 @@ class HTMLInputElement final : public TextControlElement,
|
||||
MOZ_CAN_RUN_SCRIPT nsresult CreateEditor() override;
|
||||
void SetPreviewValue(const nsAString& aValue) override;
|
||||
void GetPreviewValue(nsAString& aValue) override;
|
||||
void SetAutofillState(const nsAString& aState) override {
|
||||
SetFormAutofillState(aState);
|
||||
}
|
||||
void GetAutofillState(nsAString& aState) override {
|
||||
GetFormAutofillState(aState);
|
||||
}
|
||||
void EnablePreview() override;
|
||||
bool IsPreviewEnabled() override;
|
||||
void InitializeKeyboardEventListeners() override;
|
||||
|
@ -1595,6 +1595,11 @@ void HTMLSelectElement::OnSelectionChanged() {
|
||||
if (!mDefaultSelectionSet) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (State().HasState(ElementState::AUTOFILL)) {
|
||||
RemoveStates(ElementState::AUTOFILL | ElementState::AUTOFILL_PREVIEW);
|
||||
}
|
||||
|
||||
UpdateSelectedOptions();
|
||||
}
|
||||
|
||||
|
@ -327,6 +327,11 @@ class HTMLSelectElement final : public nsGenericHTMLFormControlElementWithState,
|
||||
void GetPreviewValue(nsAString& aValue) { aValue = mPreviewValue; }
|
||||
void SetPreviewValue(const nsAString& aValue);
|
||||
|
||||
void SetAutofillState(const nsAString& aState) {
|
||||
SetFormAutofillState(aState);
|
||||
}
|
||||
void GetAutofillState(nsAString& aState) { GetFormAutofillState(aState); }
|
||||
|
||||
protected:
|
||||
virtual ~HTMLSelectElement() = default;
|
||||
|
||||
|
@ -95,6 +95,12 @@ class HTMLTextAreaElement final : public TextControlElement,
|
||||
MOZ_CAN_RUN_SCRIPT nsresult CreateEditor() override;
|
||||
void SetPreviewValue(const nsAString& aValue) override;
|
||||
void GetPreviewValue(nsAString& aValue) override;
|
||||
void SetAutofillState(const nsAString& aState) override {
|
||||
SetFormAutofillState(aState);
|
||||
}
|
||||
void GetAutofillState(nsAString& aState) override {
|
||||
GetFormAutofillState(aState);
|
||||
}
|
||||
void EnablePreview() override;
|
||||
bool IsPreviewEnabled() override;
|
||||
void InitializeKeyboardEventListeners() override;
|
||||
|
@ -165,6 +165,16 @@ class TextControlElement : public nsGenericHTMLFormControlElementWithState {
|
||||
*/
|
||||
virtual void GetPreviewValue(nsAString& aValue) = 0;
|
||||
|
||||
/**
|
||||
* Enable preview or autofilled state for the text control.
|
||||
*/
|
||||
virtual void SetAutofillState(const nsAString& aState) = 0;
|
||||
|
||||
/**
|
||||
* Get the current preview or autofilled state for the text control.
|
||||
*/
|
||||
virtual void GetAutofillState(nsAString& aState) = 0;
|
||||
|
||||
/**
|
||||
* Enable preview for text control.
|
||||
*/
|
||||
|
@ -2804,6 +2804,29 @@ nsresult nsGenericHTMLFormControlElement::SubmitDirnameDir(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsGenericHTMLFormControlElement::GetFormAutofillState(
|
||||
nsAString& aState) const {
|
||||
if (State().HasState(ElementState::AUTOFILL_PREVIEW)) {
|
||||
aState.AssignLiteral("preview");
|
||||
} else if (State().HasState(ElementState::AUTOFILL)) {
|
||||
aState.AssignLiteral("autofill");
|
||||
} else {
|
||||
aState.Truncate();
|
||||
}
|
||||
}
|
||||
|
||||
void nsGenericHTMLFormControlElement::SetFormAutofillState(
|
||||
const nsAString& aState) {
|
||||
if (aState.EqualsLiteral("autofill")) {
|
||||
RemoveStates(ElementState::AUTOFILL_PREVIEW);
|
||||
AddStates(ElementState::AUTOFILL);
|
||||
} else if (aState.EqualsLiteral("preview")) {
|
||||
AddStates(ElementState::AUTOFILL | ElementState::AUTOFILL_PREVIEW);
|
||||
} else {
|
||||
RemoveStates(ElementState::AUTOFILL | ElementState::AUTOFILL_PREVIEW);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static const nsAttrValue::EnumTable kPopoverTargetActionTable[] = {
|
||||
|
@ -1225,6 +1225,9 @@ class nsGenericHTMLFormControlElement : public nsGenericHTMLFormElement,
|
||||
|
||||
nsresult SubmitDirnameDir(mozilla::dom::FormData* aFormData);
|
||||
|
||||
void GetFormAutofillState(nsAString& aState) const;
|
||||
void SetFormAutofillState(const nsAString& aState);
|
||||
|
||||
/** The form that contains this control */
|
||||
mozilla::dom::HTMLFormElement* mForm;
|
||||
|
||||
|
@ -191,6 +191,11 @@ partial interface HTMLInputElement {
|
||||
[ChromeOnly]
|
||||
attribute DOMString previewValue;
|
||||
|
||||
// A string indicating that the value of the element has been autofilled:
|
||||
// either "filled", "preview" or "".
|
||||
[ChromeOnly]
|
||||
attribute DOMString autofillState;
|
||||
|
||||
// Last value entered by the user, not by a script.
|
||||
// NOTE(emilio): As of right now some execCommand triggered changes might be
|
||||
// considered interactive.
|
||||
|
@ -79,4 +79,8 @@ partial interface HTMLSelectElement {
|
||||
AutocompleteInfo getAutocompleteInfo();
|
||||
[ChromeOnly]
|
||||
attribute DOMString previewValue;
|
||||
// A string indicating that the value of the element has been autofilled:
|
||||
// either "filled", "preview" or "".
|
||||
[ChromeOnly]
|
||||
attribute DOMString autofillState;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user