Bug 1338396 - LoginManagerContent: Use Date.now() instead of event.timeStamp until high-res timestamps are shipping. r=johannh
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 13 Feb 2017 23:49:16 +0800
changeset 342531 e830c124ad16df24c34a098d2a9dc4422d784fd1
parent 342530 5c52a1658c98986ea4b3710eb0d755d6efd2c66d
child 342532 d67568f1301002c095a479f567657e64edfcc2cc
push id31357
push userkwierso@gmail.com
push dateTue, 14 Feb 2017 00:49:21 +0000
treeherdermozilla-central@bca082441767 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1338396
milestone54.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 1338396 - LoginManagerContent: Use Date.now() instead of event.timeStamp until high-res timestamps are shipping. r=johannh MozReview-Commit-ID: GS8DgpyYnxU
toolkit/components/passwordmgr/LoginManagerContent.jsm
--- a/toolkit/components/passwordmgr/LoginManagerContent.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerContent.jsm
@@ -125,17 +125,19 @@ var observer = {
     switch (aEvent.type) {
       // Only used for username fields.
       case "focus": {
         LoginManagerContent._onUsernameFocus(aEvent);
         break;
       }
 
       case "contextmenu": {
-        gLastContextMenuEventTimeStamp = aEvent.timeStamp;
+        // Date.now() is used instead of event.timeStamp since
+        // dom.event.highrestimestamp.enabled isn't true on all channels yet.
+        gLastContextMenuEventTimeStamp = Date.now();
         break;
       }
 
       default: {
         throw new Error("Unexpected event");
       }
     }
   },
@@ -573,21 +575,25 @@ var LoginManagerContent = {
     }
 
     /*
      * A `focus` event is fired before a `contextmenu` event if a user right-clicks into an
      * unfocused field. In that case we don't want to show both autocomplete and a context menu
      * overlapping so we spin the event loop to see if a `contextmenu` event is coming next. If no
      * `contextmenu` event was seen and the focused field is still focused by the form fill
      * controller then show the autocomplete popup.
+     * Date.now() is used instead of event.timeStamp since dom.event.highrestimestamp.enabled isn't
+     * true on all channels yet.
      */
+    let timestamp = Date.now();
     setTimeout(function maybeOpenAutocompleteAfterFocus() {
-      // Even though the `focus` event happens first, its .timeStamp is greater in
-      // testing and I don't want to rely on that so the absolute value is used.
-      let timeDiff = Math.abs(gLastContextMenuEventTimeStamp - event.timeStamp);
+      // Even though the `focus` event happens first in testing, I don't want to
+      // rely on that since it was supposedly in the opposite order before. Use
+      // the absolute value to handle both orders.
+      let timeDiff = Math.abs(gLastContextMenuEventTimeStamp - timestamp);
       if (timeDiff < AUTOCOMPLETE_AFTER_CONTEXTMENU_THRESHOLD_MS) {
         log("Not opening autocomplete after focus since a context menu was opened within",
             timeDiff, "ms");
         return;
       }
 
       if (this._formFillService.focusedInput == focusedField) {
         log("maybeOpenAutocompleteAfterFocus: Opening the autocomplete popup");