Bug 1434317 - Use DOM event dispatching to replace nsIDOMWindowUtils.sendKeyEvent(). r=florian
authorMartin Giger <martin@humanoids.be>
Sat, 03 Feb 2018 03:20:37 +0100
changeset 23274 b0c82d15482c78dab3fd16b030683b52497d4e39
parent 23273 998b4ab68d4c5c574ee1995d513858bd36483ef7
child 23275 36b19d54366f9cfffff4a33b7ca81c4f21f507de
push id14067
push usermozilla@jorgk.com
push dateThu, 08 Feb 2018 21:37:13 +0000
treeherdercomm-central@36b19d54366f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1434317
Bug 1434317 - Use DOM event dispatching to replace nsIDOMWindowUtils.sendKeyEvent(). r=florian
mail/components/im/content/imconv.xml
mail/components/im/content/imconversation.xml
--- a/mail/components/im/content/imconv.xml
+++ b/mail/components/im/content/imconv.xml
@@ -241,28 +241,19 @@
         let isMac = "nsILocalFileMac" in Components.interfaces;
         let accelKeyPressed = isMac ? aEvent.metaKey : aEvent.ctrlKey;
         // If a character was typed or the accel+v copy shortcut was used,
         // focus the input box and resend the key event.
         if (aEvent.charCode != 0 && !aEvent.altKey &&
             (accelKeyPressed && aEvent.charCode == 'v'.charCodeAt(0) ||
              !aEvent.ctrlKey && !aEvent.metaKey)) {
           this.convView.focus();
-          const masks = Components.interfaces.nsIDOMNSEvent;
-          let modifiers = 0;
-          if (aEvent.shiftKey)
-            modifiers |= masks.SHIFT_MASK;
-          if (aEvent.ctrlKey)
-            modifiers |= masks.CONTROL_MASK;
-          if (aEvent.metaKey)
-            modifiers |= masks.META_MASK;
-          window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                .getInterface(Components.interfaces.nsIDOMWindowUtils)
-                .sendKeyEvent(aEvent.type, aEvent.keyCode, aEvent.charCode,
-                              modifiers);
+
+          let clonedEvent = new KeyboardEvent("keypress", aEvent);
+          this.convView.editor.inputField.dispatchEvent(clonedEvent);
           aEvent.preventDefault();
         }
       ]]>
       </body>
      </method>
     </implementation>
     <handlers>
      <handler event="mousedown" phase="capturing">
--- a/mail/components/im/content/imconversation.xml
+++ b/mail/components/im/content/imconversation.xml
@@ -53,17 +53,17 @@
              break;
            }
          }
        }.bind(this)).observe(this.getElt("splitter-bottom"),
                              {attributes: true, attributeOldValue: true,
                               attributeFilter: ["state"]});
 
        var browser = this.browser;
-       browser.addEventListener("keypress", this.browserKeyPress);
+       browser.addEventListener("keypress", this.browserKeyPress.bind(this));
        browser.addEventListener("dblclick", this.browserDblClick.bind(this));
        Services.obs.addObserver(this, "conversation-loaded");
       ]]>
      </constructor>
 
      <destructor>
       <![CDATA[
         this.destroy();
@@ -945,40 +945,25 @@
         if (event.charCode == 0 &&  // it's not a character, it's a command key
             (event.keyCode != 13 && // Return
              event.keyCode != 8 &&  // Backspace
              event.keyCode != 46))  // Delete
           return;
 
         if (accelKeyPressed ||
             !Services.prefs.getBoolPref("accessibility.typeaheadfind"))
-          document.getBindingParent(this).editor.focus();
+          this.editor.focus();
 
         // Returns for Ctrl+V
         if (accelKeyPressed)
           return;
 
-        const masks = Components.interfaces.nsIDOMNSEvent;
-        var modifiers = 0;
-        if (event.shiftKey)
-          modifiers |= masks.SHIFT_MASK;
-        if (event.ctrlKey)
-          modifiers |= masks.CONTROL_MASK;
-        if (event.altKey)
-          modifiers |= masks.ALT_MASK;
-        if (event.metaKey)
-          modifiers |= masks.META_MASK;
-        if (event.accelKey)
-          modifiers |= (navigator.platform.includes("Mac")) ? masks.META_MASK
-                                                            : masks.CONTROL_MASK;
-
         // resend the event
-        window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-              .getInterface(Components.interfaces.nsIDOMWindowUtils)
-              .sendKeyEvent(event.type, event.keyCode, event.charCode, modifiers);
+        let clonedEvent = new KeyboardEvent("keypress", event);
+        this.editor.inputField.dispatchEvent(clonedEvent);
       ]]>
       </body>
      </method>
 
      <method name="browserDblClick">
      <parameter name="event"/>
       <body>
       <![CDATA[