Bug 475361 - Need idle service on windows mobile - r+emaijala, sr+pavlov
authorJohn Wolfe <wolfe@lobo.us>
Tue, 14 Apr 2009 14:23:01 -0400
changeset 27326 ea400876d06cf7a19f5aa895b88d6c02171ef3f6
parent 27325 311315e5e8143b01341a776123b16c3d92ceb984
child 27328 63e6a0222c47f1fe6b76c83d50944934d9860389
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs475361
milestone1.9.2a1pre
Bug 475361 - Need idle service on windows mobile - r+emaijala, sr+pavlov Makes one static variable in nsWindow.cpp, gLastInputEventTime, non-static. Then uses that global variable in nsIdleServiceWin.cpp. Not pretty, but as good (if not better) than the alternatives.
widget/src/build/nsWinWidgetFactory.cpp
widget/src/windows/Makefile.in
widget/src/windows/nsIdleServiceWin.cpp
widget/src/windows/nsIdleServiceWin.h
widget/src/windows/nsWindow.cpp
--- a/widget/src/build/nsWinWidgetFactory.cpp
+++ b/widget/src/build/nsWinWidgetFactory.cpp
@@ -72,26 +72,26 @@
 #endif
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceWin)
 
 #ifndef WINCE
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceWin)
 #endif
 
 #ifdef NS_PRINTING
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsWin, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorWin)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecWin)
 #endif
@@ -126,16 +126,20 @@ static const nsModuleComponentInfo compo
     NS_LOOKANDFEEL_CID,
     "@mozilla.org/widget/lookandfeel;1",
     nsLookAndFeelConstructor },
   { "Native Theme Renderer", 
     NS_THEMERENDERER_CID,
     "@mozilla.org/chrome/chrome-native-theme;1", 
     NS_NewNativeTheme
   },
+  { "User Idle Service",
+    NS_IDLE_SERVICE_CID,
+    "@mozilla.org/widget/idleservice;1",
+    nsIdleServiceWinConstructor },
 
 #ifndef WINCE
   { "Clipboard",
     NS_CLIPBOARD_CID,
     "@mozilla.org/widget/clipboard;1",
     nsClipboardConstructor },
   { "Clipboard Helper",
     NS_CLIPBOARDHELPER_CID,
@@ -148,20 +152,16 @@ static const nsModuleComponentInfo compo
   { "Drag Service",
     NS_DRAGSERVICE_CID,
     "@mozilla.org/widget/dragservice;1",
     nsDragServiceConstructor },
   { "Bidi Keyboard",
     NS_BIDIKEYBOARD_CID,
     "@mozilla.org/widget/bidikeyboard;1",
     nsBidiKeyboardConstructor },
-  { "User Idle Service",
-    NS_IDLE_SERVICE_CID,
-    "@mozilla.org/widget/idleservice;1",
-    nsIdleServiceWinConstructor },
   { "Transferable",
     NS_TRANSFERABLE_CID,
     "@mozilla.org/widget/transferable;1",
     nsTransferableConstructor },
   { "HTML Format Converter",
     NS_HTMLFORMATCONVERTER_CID,
     "@mozilla.org/widget/htmlformatconverter;1",
     nsHTMLFormatConverterConstructor },
--- a/widget/src/windows/Makefile.in
+++ b/widget/src/windows/Makefile.in
@@ -80,16 +80,17 @@ CPPSRCS		= \
 	nsToolkit.cpp        \
 	nsFilePicker.cpp     \
 	nsScreenWin.cpp	\
 	nsScreenManagerWin.cpp \
 	nsLookAndFeel.cpp    \
 	nsUXThemeData.cpp \
 	nsNativeThemeWin.cpp \
 	nsWinGesture.cpp \
+	nsIdleServiceWin.cpp \
 	$(NULL)
 
 ifdef NS_PRINTING
 CPPSRCS		+= \
 	nsPrintOptionsWin.cpp \
 	nsPrintSettingsWin.cpp \
 	nsDeviceContextSpecWin.cpp \
 	$(NULL)
@@ -103,17 +104,16 @@ CPPSRCS += \
 	nsDataObjCollection.cpp  \
 	nsNativeDragTarget.cpp  \
 	nsNativeDragSource.cpp  \
 	nsDragService.cpp  \
 	nsClipboard.cpp      \
 	nsImageClipboard.cpp \
 	nsBidiKeyboard.cpp   \
 	nsSound.cpp          \
-	nsIdleServiceWin.cpp    \
 	nsTextStore.cpp \
 	$(NULL)
 endif
 
 
 DEFINES		+= -D_IMPL_NS_WIDGET -DMOZ_UNICODE 
 
 ifdef BUILD_STATIC_LIBS
--- a/widget/src/windows/nsIdleServiceWin.cpp
+++ b/widget/src/windows/nsIdleServiceWin.cpp
@@ -36,21 +36,40 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIdleServiceWin.h"
 #include <windows.h>
 
+
+#ifdef WINCE
+// The last user input event time in microseconds. If there are any pending
+// native toolkit input events it returns the current time. The value is
+// compatible with PR_IntervalToMicroseconds(PR_IntervalNow()).
+// DEFINED IN widget/src/windows/nsWindow.cpp
+extern PRUint32 gLastInputEventTime;
+#endif
+
+
 NS_IMPL_ISUPPORTS1(nsIdleServiceWin, nsIIdleService)
 
 NS_IMETHODIMP
 nsIdleServiceWin::GetIdleTime(PRUint32 *aTimeDiff)
 {
+#ifndef WINCE
     LASTINPUTINFO inputInfo;
     inputInfo.cbSize = sizeof(inputInfo);
     if (!::GetLastInputInfo(&inputInfo))
         return NS_ERROR_FAILURE;
 
-    *aTimeDiff = GetTickCount() - inputInfo.dwTime;
+    *aTimeDiff = SAFE_COMPARE_EVEN_WITH_WRAPPING(GetTickCount(), inputInfo.dwTime);
+#else
+    // NOTE: nowTime is not necessarily equivalent to GetTickCount() return value
+    //       we need to compare apples to apples - hence the nowTime variable
+    PRUint32 nowTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+
+    *aTimeDiff = SAFE_COMPARE_EVEN_WITH_WRAPPING(nowTime, gLastInputEventTime);
+#endif
+
     return NS_OK;
 }
--- a/widget/src/windows/nsIdleServiceWin.h
+++ b/widget/src/windows/nsIdleServiceWin.h
@@ -38,16 +38,25 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIdleServiceWin_h__
 #define nsIdleServiceWin_h__
 
 #include "nsIdleService.h"
 
+
+/* NOTE: Compare of GetTickCount() could overflow.  This corrects for
+* overflow situations.
+***/
+#ifndef SAFE_COMPARE_EVEN_WITH_WRAPPING
+#define SAFE_COMPARE_EVEN_WITH_WRAPPING(A, B) (((int)((long)A - (long)B) & 0xFFFFFFFF))
+#endif
+
+
 class nsIdleServiceWin : public nsIdleService
 {
 public:
     NS_DECL_ISUPPORTS
 
     NS_IMETHOD GetIdleTime(PRUint32* idleTime);
 };
 
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -448,17 +448,20 @@ static POINT gLastMouseMovePoint;
 static LONG  gLastMouseDownTime = 0L;
 static LONG  gLastClickCount    = 0L;
 static BYTE  gLastMouseButton = 0;
 ////////////////////////////////////////////////////
 
 // The last user input event time in microseconds. If there are any pending
 // native toolkit input events it returns the current time. The value is
 // compatible with PR_IntervalToMicroseconds(PR_IntervalNow()).
-static PRUint32 gLastInputEventTime = 0;
+#ifndef WINCE
+static
+#endif
+PRUint32 gLastInputEventTime = 0;
 
 static int gTrimOnMinimize = 2; // uninitialized, but still true
 
 #if 0
 static PRBool is_vk_down(int vk)
 {
    SHORT st = GetKeyState(vk);
 #ifdef DEBUG
@@ -672,16 +675,19 @@ nsWindow::nsWindow() : nsBaseWidget()
 
 #ifndef WINCE
   if (!sInstanceCount && SUCCEEDED(::OleInitialize(NULL))) {
     sIsOleInitialized = TRUE;
   }
   NS_ASSERTION(sIsOleInitialized, "***** OLE is not initialized!\n");
 #endif
 
+  // Set gLastInputEventTime to some valid number
+  gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+
   sInstanceCount++;
 }
 
 //-------------------------------------------------------------------------
 //
 // nsWindow destructor
 //
 //-------------------------------------------------------------------------