Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2025-07-29 10:44:33 +08:00
commit 4c1a4a4402
31 changed files with 827 additions and 36 deletions

View file

@ -9,7 +9,7 @@
* See the nsIFormAutofillContentService documentation for details.
*/
"use strict";
"use strict"
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
@ -29,6 +29,15 @@ function FormHandler(aForm, aWindow) {
this.window = aWindow;
this.fieldDetails = [];
// Add a reset event listener to clear autofill state
this.form.addEventListener("reset", () => {
for (let element of this.form.elements) {
if (typeof element.setAutofilled === "function") {
element.setAutofilled(false);
}
}
});
}
FormHandler.prototype = {
@ -233,11 +242,14 @@ FormHandler.prototype = {
f.addressType == field.addressType &&
f.contactType == field.contactType &&
f.fieldName == field.fieldName);
if (!fieldDetail) {
continue;
}
fieldDetail.element.value = field.value;
if (typeof fieldDetail.element.setAutofilled === 'function') {
fieldDetail.element.setAutofilled(!!field.value);
}
}
},

View file

@ -1189,7 +1189,7 @@ var LoginManagerContent = {
// Fill the form
if (usernameField) {
// Don't modify the username field if it's disabled or readOnly so we preserve its case.
// Don't modify the username field if it's disabled or readOnly so we preserve its case.
let disabledOrReadOnly = usernameField.disabled || usernameField.readOnly;
let userNameDiffers = selectedLogin.username != usernameField.value;
@ -1202,6 +1202,10 @@ var LoginManagerContent = {
if (!disabledOrReadOnly && !userEnteredDifferentCase && userNameDiffers) {
usernameField.setUserInput(selectedLogin.username);
}
//Set autofilled state if value is present
if (typeof usernameField.setAutofilled === "function" && usernameField.value) {
usernameField.setAutofilled(true);
}
}
let doc = form.ownerDocument;
@ -1216,6 +1220,10 @@ var LoginManagerContent = {
};
log("Saving autoFilledLogin", autoFilledLogin.guid, "for", form.rootElement);
this.stateForDocument(doc).fillsByRootElement.set(form.rootElement, autoFilledLogin);
// Set autofilled state if value is present
if (typeof passwordField.setAutofilled === "function" && passwordField.value) {
passwordField.setAutofilled(true);
}
}
log("_fillForm succeeded");

View file

@ -40,6 +40,7 @@
#include "nsIFrame.h"
#include "nsIScriptSecurityManager.h"
#include "nsFocusManager.h"
#include "mozilla/dom/HTMLInputElement.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -541,9 +542,24 @@ nsFormFillController::SetTextValue(const nsAString & aTextValue)
{
nsCOMPtr<nsIDOMNSEditableElement> editable = do_QueryInterface(mFocusedInput);
if (editable) {
editable->BeginProgrammaticValueSet();
mSuppressOnInput = true;
editable->SetUserInput(aTextValue);
mSuppressOnInput = false;
editable->EndProgrammaticValueSet();
if (mFocusedInput) {
nsCOMPtr<nsIContent> content = do_QueryInterface(mFocusedInput);
if (content) {
mozilla::dom::HTMLInputElement* htmlInput = mozilla::dom::HTMLInputElement::FromContentOrNull(content);
if (htmlInput) {
htmlInput->SetAutofilled(true);
nsAutoString value;
htmlInput->GetValue(value);
htmlInput->SetAutofilledValue(value);
}
}
}
}
return NS_OK;
}
@ -1331,9 +1347,6 @@ nsFormFillController::StopControllingInput()
nsresult rv;
nsCOMPtr <nsIFormAutoComplete> formAutoComplete =
do_GetService("@mozilla.org/satchel/form-autocomplete;1", &rv);
if (formAutoComplete) {
formAutoComplete->StopControllingInput(mFocusedInput);
}
mFocusedInputNode = nullptr;
mFocusedInput = nullptr;