Bug 1341582 - Apply form autofill to an already-focused input, r=MattN

MozReview-Commit-ID: C6zT7jKBb4c

--HG--
extra : rebase_source : 1154380e8b4a0c3be5443ac8044febe096f550ff
This commit is contained in:
Luke Chang 2017-02-23 14:44:07 +08:00
Родитель b2013667fb
Коммит 3374d73693
5 изменённых файлов: 20 добавлений и 8 удалений

Просмотреть файл

@ -315,8 +315,8 @@ var FormAutofillContent = {
return formDetails.map(record => record.fieldName);
},
_identifyAutofillFields(doc) {
this.log.debug("_identifyAutofillFields:", "" + doc.location);
identifyAutofillFields(doc) {
this.log.debug("identifyAutofillFields:", "" + doc.location);
let forms = [];
// Collects root forms from inputs.

Просмотреть файл

@ -12,6 +12,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://formautofill/FormAutofillContent.jsm");
/**
* Handles content's interactions for the frame.
@ -38,14 +39,11 @@ var FormAutofillFrameScript = {
if (!(doc instanceof Ci.nsIDOMHTMLDocument)) {
return;
}
this.FormAutofillContent._identifyAutofillFields(doc);
FormAutofillContent.identifyAutofillFields(doc);
break;
}
}
},
};
XPCOMUtils.defineLazyModuleGetter(FormAutofillFrameScript, "FormAutofillContent",
"resource://formautofill/FormAutofillContent.jsm");
FormAutofillFrameScript.init();

Просмотреть файл

@ -77,7 +77,7 @@ TESTCASES.forEach(testcase => {
let doc = MockDocument.createTestDocument(
"http://localhost:8080/test/", testcase.document);
FormAutofillContent._identifyAutofillFields(doc);
FormAutofillContent.identifyAutofillFields(doc);
for (let i in testcase.targetInput) {
let input = doc.getElementById(testcase.targetInput[i]);

Просмотреть файл

@ -64,7 +64,7 @@ TESTCASES.forEach(testcase => {
let doc = MockDocument.createTestDocument(
"http://localhost:8080/test/", testcase.document);
FormAutofillContent._identifyAutofillFields(doc);
FormAutofillContent.identifyAutofillFields(doc);
Assert.deepEqual(markedFieldId, testcase.expectedResult,
"Check the fields were marked correctly.");

Просмотреть файл

@ -309,9 +309,23 @@ nsFormFillController::MarkAsAutofillField(nsIDOMHTMLInputElement *aInput)
*/
nsCOMPtr<nsINode> node = do_QueryInterface(aInput);
NS_ENSURE_STATE(node);
if (mAutofillInputs.Get(node)) {
return NS_OK;
}
mAutofillInputs.Put(node, true);
node->AddMutationObserverUnlessExists(this);
nsFocusManager *fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedContent();
if (SameCOMIdentity(focusedContent, node)) {
nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(node);
MaybeStartControllingInput(input);
}
}
return NS_OK;
}