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;
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);
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMWINDOWUTILS
NS_IMETHOD AddElementEventState(nsIDOMElement* aElement, uint64_t aState) override;
NS_IMETHOD RemoveElementEventState(nsIDOMElement* aElement, uint64_t aState) override;
protected:
~nsDOMWindowUtils();

View file

@ -2835,10 +2835,16 @@ HTMLInputElement::SetUserInput(const nsAString& aValue)
void
HTMLInputElement::SetAutofilled(bool aAutofilled)
{
printf("🔍 AUTOFILL C++: SetAutofilled called with aAutofilled=%s\n", aAutofilled ? "true" : "false");
if (aAutofilled) {
printf("🔍 AUTOFILL C++: Adding NS_EVENT_STATE_AUTOFILL state\n");
AddStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: State added successfully\n");
} else {
printf("🔍 AUTOFILL C++: Removing NS_EVENT_STATE_AUTOFILL state\n");
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
if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) {
printf("🔍 AUTOFILL C++: User changed autofilled input, clearing state\n");
RemoveStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: Autofill state cleared from input\n");
}
UpdateAllValidityStates(aNotify);

View file

@ -369,10 +369,16 @@ HTMLTextAreaElement::SetUserInput(const nsAString& aValue)
void
HTMLTextAreaElement::SetAutofilled(bool aAutofilled)
{
printf("🔍 AUTOFILL C++: HTMLTextAreaElement::SetAutofilled called with aAutofilled=%s\n", aAutofilled ? "true" : "false");
if (aAutofilled) {
printf("🔍 AUTOFILL C++: Adding NS_EVENT_STATE_AUTOFILL state to textarea\n");
AddStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: State added successfully to textarea\n");
} else {
printf("🔍 AUTOFILL C++: Removing NS_EVENT_STATE_AUTOFILL state from textarea\n");
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
if (aWasInteractiveUserChange && State().HasState(NS_EVENT_STATE_AUTOFILL)) {
printf("🔍 AUTOFILL C++: User changed autofilled textarea, clearing state\n");
RemoveStates(NS_EVENT_STATE_AUTOFILL);
printf("🔍 AUTOFILL C++: Autofill state cleared from textarea\n");
}
// Update the validity state

View file

@ -1944,6 +1944,20 @@ interface nsIDOMWindowUtils : nsISupports {
const long MOUSE_BUTTONS_5TH_BUTTON = 0x10;
// Buttons are not specified, will be calculated from |aButton|.
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)]