Issue #2790 - Part 2: Address BZ bugs: 1355438 and 1341230

This commit is contained in:
MeladJM 2025-07-22 03:21:45 +08:00 • committed by roytam1
commit d99eab0d9d
8 changed files with 85 additions and 0 deletions

View file

@ -4058,3 +4058,27 @@ nsTranslationNodeList::GetLength(uint32_t* aRetVal)
*aRetVal = mLength; *aRetVal = mLength;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDOMWindowUtils::AddElementEventState(nsIDOMElement* aElement, uint64_t aState)
{
NS_ENSURE_ARG_POINTER(aElement);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
if (!content) {
return NS_ERROR_INVALID_ARG;
}
content->AddStates(mozilla::EventStates(aState));
return NS_OK;
}
NS_IMETHODIMP
nsDOMWindowUtils::RemoveElementEventState(nsIDOMElement* aElement, uint64_t aState)
{
NS_ENSURE_ARG_POINTER(aElement);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
if (!content) {
return NS_ERROR_INVALID_ARG;
}
content->RemoveStates(mozilla::EventStates(aState));
return NS_OK;
}

View file

@ -63,6 +63,8 @@ public:
explicit nsDOMWindowUtils(nsGlobalWindow *aWindow); explicit nsDOMWindowUtils(nsGlobalWindow *aWindow);
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIDOMWINDOWUTILS NS_DECL_NSIDOMWINDOWUTILS
NS_IMETHOD AddElementEventState(nsIDOMElement* aElement, uint64_t aState) override;
NS_IMETHOD RemoveElementEventState(nsIDOMElement* aElement, uint64_t aState) override;
protected: protected:
~nsDOMWindowUtils(); ~nsDOMWindowUtils();

View file

@ -2835,10 +2835,16 @@ HTMLInputElement::SetUserInput(const nsAString& aValue)
void void
HTMLInputElement::SetAutofilled(bool aAutofilled) HTMLInputElement::SetAutofilled(bool aAutofilled)
{ {
printf("🔍 AUTOFILL C++: SetAutofilled called with aAutofilled=%s\n", aAutofilled ? "true" : "false");
if (aAutofilled) { if (aAutofilled) {
printf("🔍 AUTOFILL C++: Adding NS_EVENT_STATE_AUTOFILL state\n");
AddStates(NS_EVENT_STATE_AUTOFILL); AddStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: State added successfully\n");
} else { } else {
printf("🔍 AUTOFILL C++: Removing NS_EVENT_STATE_AUTOFILL state\n");
RemoveStates(NS_EVENT_STATE_AUTOFILL); RemoveStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: State removed successfully\n");
} }
} }
@ -8519,7 +8525,9 @@ HTMLInputElement::OnValueChanged(bool aNotify, bool aWasInteractiveUserChange)
// Clear autofilled state if this was an interactive user change // Clear autofilled state if this was an interactive user change
if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) { if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) {
printf("🔍 AUTOFILL C++: User changed autofilled input, clearing state\n");
RemoveStates(NS_EVENT_STATE_AUTOFILL); RemoveStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: Autofill state cleared from input\n");
} }
UpdateAllValidityStates(aNotify); UpdateAllValidityStates(aNotify);

View file

@ -369,10 +369,16 @@ HTMLTextAreaElement::SetUserInput(const nsAString& aValue)
void void
HTMLTextAreaElement::SetAutofilled(bool aAutofilled) HTMLTextAreaElement::SetAutofilled(bool aAutofilled)
{ {
printf("🔍 AUTOFILL C++: HTMLTextAreaElement::SetAutofilled called with aAutofilled=%s\n", aAutofilled ? "true" : "false");
if (aAutofilled) { if (aAutofilled) {
printf("🔍 AUTOFILL C++: Adding NS_EVENT_STATE_AUTOFILL state to textarea\n");
AddStates(NS_EVENT_STATE_AUTOFILL); AddStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: State added successfully to textarea\n");
} else { } else {
printf("🔍 AUTOFILL C++: Removing NS_EVENT_STATE_AUTOFILL state from textarea\n");
RemoveStates(NS_EVENT_STATE_AUTOFILL); RemoveStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: State removed successfully from textarea\n");
} }
} }
@ -1645,7 +1651,9 @@ HTMLTextAreaElement::OnValueChanged(bool aNotify, bool aWasInteractiveUserChange
// Clear autofilled state if this was an interactive user change // Clear autofilled state if this was an interactive user change
if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) { if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) {
printf("🔍 AUTOFILL C++: User changed autofilled textarea, clearing state\n");
RemoveStates(NS_EVENT_STATE_AUTOFILL); RemoveStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: Autofill state cleared from textarea\n");
} }
// Update the validity state // Update the validity state

View file

@ -1944,6 +1944,20 @@ interface nsIDOMWindowUtils : nsISupports {
const long MOUSE_BUTTONS_5TH_BUTTON = 0x10; const long MOUSE_BUTTONS_5TH_BUTTON = 0x10;
// Buttons are not specified, will be calculated from |aButton|. // Buttons are not specified, will be calculated from |aButton|.
const long MOUSE_BUTTONS_NOT_SPECIFIED = -1; const long MOUSE_BUTTONS_NOT_SPECIFIED = -1;
/**
* Add an EventState bit to an element (privileged only).
* @param element The element to modify.
* @param state The EventState bit (see EventStates.h, e.g. NS_EVENT_STATE_AUTOFILL).
*/
void addElementEventState(in nsIDOMElement element, in unsigned long long state);
/**
* Remove an EventState bit from an element (privileged only).
* @param element The element to modify.
* @param state The EventState bit.
*/
void removeElementEventState(in nsIDOMElement element, in unsigned long long state);
}; };
[scriptable, uuid(c694e359-7227-4392-a138-33c0cc1f15a6)] [scriptable, uuid(c694e359-7227-4392-a138-33c0cc1f15a6)]

View file

@ -277,6 +277,9 @@ CSS_STATE_PSEUDO_CLASS(mozMeterSubSubOptimum, ":-moz-meter-sub-sub-optimum", 0,
// Those values should be parsed but do nothing. // Those values should be parsed but do nothing.
CSS_STATE_PSEUDO_CLASS(mozPlaceholder, ":-moz-placeholder", 0, "", NS_EVENT_STATE_IGNORE) CSS_STATE_PSEUDO_CLASS(mozPlaceholder, ":-moz-placeholder", 0, "", NS_EVENT_STATE_IGNORE)
// Internal-only pseudo-class for autofill highlight
CSS_STATE_PSEUDO_CLASS(mozAutofillHighlight, ":-moz-autofill-highlight", CSS_PSEUDO_CLASS_ENABLED_IN_UA_SHEETS, "", NS_EVENT_STATE_AUTOFILL)
#ifdef DEFINED_CSS_STATE_PSEUDO_CLASS #ifdef DEFINED_CSS_STATE_PSEUDO_CLASS
#undef DEFINED_CSS_STATE_PSEUDO_CLASS #undef DEFINED_CSS_STATE_PSEUDO_CLASS
#undef CSS_STATE_PSEUDO_CLASS #undef CSS_STATE_PSEUDO_CLASS

View file

@ -1149,3 +1149,9 @@ input[type="date"],
input[type="time"] { input[type="time"] {
overflow: hidden !important; overflow: hidden !important;
} }
/* Autofill highlight for internal-only pseudo-class */
input:-moz-autofill-highlight,
textarea:-moz-autofill-highlight {
background-color: #ffff99 !important;
}

View file

@ -11,6 +11,8 @@
"use strict"; "use strict";
console.log('🔍 AUTOFILL: FormAutofillContentService.js loaded');
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
@ -130,7 +132,9 @@ FormHandler.prototype = {
return "cancel"; return "cancel";
} }
console.log('🔍 AUTOFILL: About to call autofillFormFields with result:', result);
this.autofillFormFields(result); this.autofillFormFields(result);
console.log('🔍 AUTOFILL: autofillFormFields completed');
return "success"; return "success";
}), }),
@ -226,22 +230,38 @@ FormHandler.prototype = {
* } * }
*/ */
autofillFormFields: function (aAutofillResult) { autofillFormFields: function (aAutofillResult) {
console.log('🔍 AUTOFILL: autofillFormFields called with', aAutofillResult);
for (let field of aAutofillResult.fields) { for (let field of aAutofillResult.fields) {
console.log('🔍 AUTOFILL: Processing field', field);
// Get the field details, if it was processed by the user interface. // Get the field details, if it was processed by the user interface.
let fieldDetail = this.fieldDetails let fieldDetail = this.fieldDetails
.find(f => f.section == field.section && .find(f => f.section == field.section &&
f.addressType == field.addressType && f.addressType == field.addressType &&
f.contactType == field.contactType && f.contactType == field.contactType &&
f.fieldName == field.fieldName); f.fieldName == field.fieldName);
console.log('🔍 AUTOFILL: Found fieldDetail?', !!fieldDetail, fieldDetail);
if (!fieldDetail) { if (!fieldDetail) {
console.log('🔍 AUTOFILL: No fieldDetail found, skipping');
continue; continue;
} }
console.log('🔍 AUTOFILL: Setting value on element', fieldDetail.element);
fieldDetail.element.value = field.value; fieldDetail.element.value = field.value;
// Set the autofilled state on the element // Set the autofilled state on the element
console.log('🔍 AUTOFILL: Checking if setAutofilled exists on element');
console.log('🔍 AUTOFILL: setAutofilled type:', typeof fieldDetail.element.setAutofilled);
if (typeof fieldDetail.element.setAutofilled === 'function') { if (typeof fieldDetail.element.setAutofilled === 'function') {
console.log('🔍 AUTOFILL: Calling setAutofilled(true) on element');
fieldDetail.element.setAutofilled(true); fieldDetail.element.setAutofilled(true);
console.log('🔍 AUTOFILL: setAutofilled(true) called successfully');
} else {
console.log('🔍 AUTOFILL: setAutofilled is not a function on this element');
} }
} }
}, },