mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 13:58:49 +00:00
Issue #2790 - Part 1: Add: event state, pseudo-class mapping, SetAutofilled methods
This commit is contained in:
@@ -293,6 +293,9 @@ private:
|
||||
// Modal <dialog> element
|
||||
#define NS_EVENT_STATE_MODAL_DIALOG NS_DEFINE_EVENT_STATE_MACRO(54)
|
||||
|
||||
// Autofilled input element (for :autofill pseudo-class)
|
||||
#define NS_EVENT_STATE_AUTOFILL NS_DEFINE_EVENT_STATE_MACRO(55)
|
||||
|
||||
#define DIR_ATTR_STATES (NS_EVENT_STATE_HAS_DIR_ATTR | \
|
||||
NS_EVENT_STATE_DIR_ATTR_LTR | \
|
||||
NS_EVENT_STATE_DIR_ATTR_RTL | \
|
||||
|
||||
@@ -2832,6 +2832,16 @@ HTMLInputElement::SetUserInput(const nsAString& aValue)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLInputElement::SetAutofilled(bool aAutofilled)
|
||||
{
|
||||
if (aAutofilled) {
|
||||
AddStates(NS_EVENT_STATE_AUTOFILL);
|
||||
} else {
|
||||
RemoveStates(NS_EVENT_STATE_AUTOFILL);
|
||||
}
|
||||
}
|
||||
|
||||
nsIEditor*
|
||||
HTMLInputElement::GetEditor()
|
||||
{
|
||||
@@ -8507,6 +8517,11 @@ HTMLInputElement::OnValueChanged(bool aNotify, bool aWasInteractiveUserChange)
|
||||
{
|
||||
mLastValueChangeWasInteractive = aWasInteractiveUserChange;
|
||||
|
||||
// Clear autofilled state if this was an interactive user change
|
||||
if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) {
|
||||
RemoveStates(NS_EVENT_STATE_AUTOFILL);
|
||||
}
|
||||
|
||||
UpdateAllValidityStates(aNotify);
|
||||
|
||||
if (HasDirAuto()) {
|
||||
|
||||
@@ -845,6 +845,16 @@ public:
|
||||
void SetUserInput(const nsAString& aInput,
|
||||
nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
/**
|
||||
* Sets or clears the autofilled state of this input element.
|
||||
* This is used by the browser's autofill system to indicate when
|
||||
* a value has been automatically filled (e.g., from saved passwords
|
||||
* or form data).
|
||||
*
|
||||
* @param aAutofilled Whether the element should be marked as autofilled
|
||||
*/
|
||||
void SetAutofilled(bool aAutofilled);
|
||||
|
||||
// XPCOM GetPhonetic() is OK
|
||||
|
||||
/**
|
||||
|
||||
@@ -366,6 +366,16 @@ HTMLTextAreaElement::SetUserInput(const nsAString& aValue)
|
||||
return SetValueInternal(aValue, nsTextEditorState::eSetValue_BySetUserInput);
|
||||
}
|
||||
|
||||
void
|
||||
HTMLTextAreaElement::SetAutofilled(bool aAutofilled)
|
||||
{
|
||||
if (aAutofilled) {
|
||||
AddStates(NS_EVENT_STATE_AUTOFILL);
|
||||
} else {
|
||||
RemoveStates(NS_EVENT_STATE_AUTOFILL);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLTextAreaElement::SetValueChanged(bool aValueChanged)
|
||||
{
|
||||
@@ -1633,6 +1643,11 @@ HTMLTextAreaElement::OnValueChanged(bool aNotify, bool aWasInteractiveUserChange
|
||||
{
|
||||
mLastValueChangeWasInteractive = aWasInteractiveUserChange;
|
||||
|
||||
// Clear autofilled state if this was an interactive user change
|
||||
if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) {
|
||||
RemoveStates(NS_EVENT_STATE_AUTOFILL);
|
||||
}
|
||||
|
||||
// Update the validity state
|
||||
bool validBefore = IsValid();
|
||||
UpdateTooLongValidityState();
|
||||
|
||||
@@ -70,6 +70,15 @@ public:
|
||||
}
|
||||
NS_IMETHOD SetUserInput(const nsAString& aInput) override;
|
||||
|
||||
/**
|
||||
* Sets or clears the autofilled state of this textarea element.
|
||||
* This is used by the browser's autofill system to indicate when
|
||||
* a value has been automatically filled (e.g., from saved form data).
|
||||
*
|
||||
* @param aAutofilled Whether the element should be marked as autofilled
|
||||
*/
|
||||
void SetAutofilled(bool aAutofilled);
|
||||
|
||||
// nsIFormControl
|
||||
NS_IMETHOD_(uint32_t) GetType() const override { return NS_FORM_TEXTAREA; }
|
||||
NS_IMETHOD Reset() override;
|
||||
|
||||
@@ -200,6 +200,13 @@ partial interface HTMLInputElement {
|
||||
// for example will be dispatched when focusing out the element.
|
||||
[Func="IsChromeOrXBL", NeedsSubjectPrincipal]
|
||||
void setUserInput(DOMString input);
|
||||
|
||||
// Sets or clears the autofilled state of this input element.
|
||||
// This is used by the browser's autofill system to indicate when
|
||||
// a value has been automatically filled (e.g., from saved passwords
|
||||
// or form data).
|
||||
[ChromeOnly]
|
||||
void setAutofilled(boolean autofilled);
|
||||
};
|
||||
|
||||
partial interface HTMLInputElement {
|
||||
|
||||
@@ -97,4 +97,10 @@ partial interface HTMLTextAreaElement {
|
||||
// element.
|
||||
[ChromeOnly]
|
||||
void setUserInput(DOMString input);
|
||||
|
||||
// Sets or clears the autofilled state of this textarea element.
|
||||
// This is used by the browser's autofill system to indicate when
|
||||
// a value has been automatically filled (e.g., from saved form data).
|
||||
[ChromeOnly]
|
||||
void setAutofilled(boolean autofilled);
|
||||
};
|
||||
|
||||
@@ -194,6 +194,9 @@ CSS_STATE_PSEUDO_CLASS(mozFullScreen, ":-moz-full-screen", 0, "", NS_EVENT_STATE
|
||||
CSS_STATE_PSEUDO_CLASS(modal, ":modal", 0, "", NS_EVENT_STATE_MODAL_DIALOG)
|
||||
CSS_STATE_PSEUDO_CLASS(mozModalDialog, ":-moz-modal-dialog", 0, "", NS_EVENT_STATE_MODAL_DIALOG)
|
||||
|
||||
// Matches autofilled input elements
|
||||
CSS_STATE_PSEUDO_CLASS(autofill, ":autofill", 0, "", NS_EVENT_STATE_AUTOFILL)
|
||||
|
||||
// Matches if the element is focused and should show a focus ring
|
||||
CSS_STATE_PSEUDO_CLASS(mozFocusRing, ":-moz-focusring", 0, "", NS_EVENT_STATE_FOCUSRING)
|
||||
|
||||
|
||||
@@ -238,6 +238,11 @@ FormHandler.prototype = {
|
||||
}
|
||||
|
||||
fieldDetail.element.value = field.value;
|
||||
|
||||
// Set the autofilled state on the element
|
||||
if (typeof fieldDetail.element.setAutofilled === 'function') {
|
||||
fieldDetail.element.setAutofilled(true);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user