Bug 1360370 - Part 2: Support nsIDOMHTMLSelectElement in FormLikeFactory.createFromField.; r=MattN
authorSean Lee <selee@mozilla.com>
Mon, 08 May 2017 17:39:11 +0800
changeset 409568 2568411b8a0a78e823c347e5405af6bdc8d541fb
parent 409567 b4b39120da039b451472853077e5a37b20732606
child 409569 0ab2933e41c3be1825a99247a184c2dbde7fcc76
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1360370
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1360370 - Part 2: Support nsIDOMHTMLSelectElement in FormLikeFactory.createFromField.; r=MattN MozReview-Commit-ID: CHxELtW4wXP
toolkit/modules/FormLikeFactory.jsm
--- a/toolkit/modules/FormLikeFactory.jsm
+++ b/toolkit/modules/FormLikeFactory.jsm
@@ -42,45 +42,45 @@ let FormLikeFactory = {
     }
 
     this._addToJSONProperty(formLike);
 
     return formLike;
   },
 
   /**
-   * Create a FormLike object from an <input> in a document.
+   * Create a FormLike object from an <input>/<select> in a document.
    *
    * If the field is in a <form>, construct the FormLike from the form.
    * Otherwise, create a FormLike with a rootElement (wrapper) according to
-   * heuristics. Currently all <input> not in a <form> are one FormLike but this
-   * shouldn't be relied upon as the heuristics may change to detect multiple
-   * "forms" (e.g. registration and login) on one page with a <form>.
+   * heuristics. Currently all <input>/<select> not in a <form> are one FormLike
+   * but this shouldn't be relied upon as the heuristics may change to detect
+   * multiple "forms" (e.g. registration and login) on one page with a <form>.
    *
    * Note that two FormLikes created from the same field won't return the same FormLike object.
    * Use the `rootElement` property on the FormLike as a key instead.
    *
-   * @param {HTMLInputElement} aField - a field in a document
+   * @param {HTMLInputElement|HTMLSelectElement} aField - an <input> or <select> field in a document
    * @return {FormLike}
    * @throws Error if aField isn't a password or username field in a document
    */
   createFromField(aField) {
-    if (!(aField instanceof Ci.nsIDOMHTMLInputElement) ||
+    if ((!(aField instanceof Ci.nsIDOMHTMLInputElement) && !(aField instanceof Ci.nsIDOMHTMLSelectElement)) ||
         !aField.ownerDocument) {
       throw new Error("createFromField requires a field in a document");
     }
 
     let rootElement = this.findRootForField(aField);
     if (rootElement instanceof Ci.nsIDOMHTMLFormElement) {
       return this.createFromForm(rootElement);
     }
 
     let doc = aField.ownerDocument;
     let elements = [];
-    for (let el of rootElement.querySelectorAll("input")) {
+    for (let el of rootElement.querySelectorAll("input, select")) {
       // Exclude elements inside the rootElement that are already in a <form> as
       // they will be handled by their own FormLike.
       if (!el.form) {
         elements.push(el);
       }
     }
     let formLike = {
       action: doc.baseURI,
@@ -96,17 +96,17 @@ let FormLikeFactory = {
 
   /**
    * Determine the Element that encapsulates the related fields. For example, if
    * a page contains a login form and a checkout form which are "submitted"
    * separately, and the username field is passed in, ideally this would return
    * an ancestor Element of the username and password fields which doesn't
    * include any of the checkout fields.
    *
-   * @param {HTMLInputElement} aField - a field in a document
+   * @param {HTMLInputElement|HTMLSelectElement} aField - a field in a document
    * @return {HTMLElement} - the root element surrounding related fields
    */
   findRootForField(aField) {
     if (aField.form) {
       return aField.form;
     }
 
     return aField.ownerDocument.documentElement;