Bug 1278581 - Add 'millisSinceLastUserInput' to nsIDOMWindowUtils r=smaug
authorJames Willcox <snorp@snorp.net>
Tue, 27 Sep 2016 09:22:26 -0500
changeset 315815 41dd7c0d25eb7a0639cab67893f8885d6a178b0d
parent 315814 b6f62be719ae36609cde88c878c35c5160ff502f
child 315816 a13cbb3da4019d38f8426b323be5ff8a198d5f4d
push id30757
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:02:43 +0000
treeherdermozilla-central@5ffed033557e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1278581
milestone52.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 1278581 - Add 'millisSinceLastUserInput' to nsIDOMWindowUtils r=smaug
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3495,16 +3495,29 @@ NS_IMETHODIMP
 nsDOMWindowUtils::GetIsHandlingUserInput(bool* aHandlingUserInput)
 {
   *aHandlingUserInput = EventStateManager::IsHandlingUserInput();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDOMWindowUtils::GetMillisSinceLastUserInput(double* aMillisSinceLastUserInput)
+{
+  TimeStamp lastInput = EventStateManager::LatestUserInputStart();
+  if (lastInput.IsNull()) {
+    *aMillisSinceLastUserInput = 0;
+    return NS_OK;
+  }
+
+  *aMillisSinceLastUserInput = (TimeStamp::Now() - lastInput).ToMilliseconds();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDOMWindowUtils::AllowScriptsToClose()
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(mWindow);
   NS_ENSURE_STATE(window);
   nsGlobalWindow::Cast(window)->AllowScriptsToClose();
   return NS_OK;
 }
 
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -1755,16 +1755,23 @@ interface nsIDOMWindowUtils : nsISupport
   /**
    * Returns true if a user input is being handled.
    *
    * This calls EventStateManager::IsHandlingUserInput().
    */
   readonly attribute boolean isHandlingUserInput;
 
   /**
+   * Returns milliseconds elapsed since last user input was started
+   *
+   * This relies on EventStateManager::LatestUserInputStart()
+   */
+  readonly attribute double millisSinceLastUserInput;
+
+  /**
    * After calling the method, the window for which this DOMWindowUtils
    * was created can be closed using scripts.
    */
   void allowScriptsToClose();
 
   /**
    * Is the parent window's main widget visible?  If it isn't, we probably
    * don't want to display any dialogs etc it may request.  This corresponds