Bug 520304 - Improve responsiveness of idle service on mobile platforms. r=roc
authorDoug Turner <dougt@meer.net>
Tue, 06 Oct 2009 11:47:46 -0700
changeset 33517 21ca51ccd2a9ce51c343f4942527fcc1b0993688
parent 33516 b8529fc4706065f646149cbc65d83d75eae1c9bd
child 33518 eb366cb6f05c67df18f69c1e133f077cf7ce67d1
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs520304
milestone1.9.3a1pre
Bug 520304 - Improve responsiveness of idle service on mobile platforms. r=roc
widget/src/gtk2/nsWindow.cpp
widget/src/windows/nsWindow.cpp
widget/src/xpwidgets/nsIdleService.cpp
widget/src/xpwidgets/nsIdleService.h
--- a/widget/src/gtk2/nsWindow.cpp
+++ b/widget/src/gtk2/nsWindow.cpp
@@ -78,16 +78,18 @@
 
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
 #include "nsGfxCIID.h"
 #include "nsIObserverService.h"
 
+#include "nsIdleService.h"
+
 #ifdef ACCESSIBILITY
 #include "nsIAccessibilityService.h"
 #include "nsIAccessibleRole.h"
 #include "nsIAccessibleEvent.h"
 #include "prenv.h"
 #include "stdlib.h"
 static PRBool sAccessibilityChecked = PR_FALSE;
 /* static */
@@ -260,16 +262,24 @@ static PRBool gdk_keyboard_get_modmap_ma
                                             PRUint32* aScrollLockMask);
 #endif /* MOZ_X11 */
 
 /* initialization static functions */
 static nsresult    initialize_prefs        (void);
 
 PRUint32        gLastInputEventTime = 0;
 
+static void UpdateLastInputEventTime() {
+  gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+  nsCOMPtr<nsIIdleService> idleService = do_GetService("@mozilla.org/widget/idleservice;1");
+  nsIdleService* is = static_cast<nsIdleService*>(idleService.get());
+  if (is)
+    is->IdleTimeWasModified();
+}
+
 // this is the last window that had a drag event happen on it.
 nsWindow *nsWindow::mLastDragMotionWindow = NULL;
 PRBool nsWindow::sIsDraggingOutOf = PR_FALSE;
 
 // This is the time of the last button press event.  The drag service
 // uses it as the time to start drags.
 guint32   nsWindow::mLastButtonPressTime = 0;
 // Time of the last button release event. We use it to detect when the
@@ -5431,17 +5441,17 @@ GetFirstNSWindowForGDKWindow(GdkWindow *
     }
     return window;
 }
 
 /* static */
 gboolean
 motion_notify_event_cb(GtkWidget *widget, GdkEventMotion *event)
 {
-    gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+    UpdateLastInputEventTime();
 
     nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
     if (!window)
         return FALSE;
 
     window->OnMotionNotifyEvent(widget, event);
 
 #ifdef HAVE_GTK_MOTION_HINTS
@@ -5449,32 +5459,32 @@ motion_notify_event_cb(GtkWidget *widget
 #endif
     return TRUE;
 }
 
 /* static */
 gboolean
 button_press_event_cb(GtkWidget *widget, GdkEventButton *event)
 {
-    gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+    UpdateLastInputEventTime();
 
     nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
     if (!window)
         return FALSE;
 
     window->OnButtonPressEvent(widget, event);
 
     return TRUE;
 }
 
 /* static */
 gboolean
 button_release_event_cb(GtkWidget *widget, GdkEventButton *event)
 {
-    gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+    UpdateLastInputEventTime();
 
     nsWindow *window = GetFirstNSWindowForGDKWindow(event->window);
     if (!window)
         return FALSE;
 
     window->OnButtonReleaseEvent(widget, event);
 
     return TRUE;
@@ -5602,17 +5612,17 @@ plugin_client_message_filter(GdkXEvent *
 #endif /* MOZ_X11 */
 
 /* static */
 gboolean
 key_press_event_cb(GtkWidget *widget, GdkEventKey *event)
 {
     LOG(("key_press_event_cb\n"));
 
-    gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+    UpdateLastInputEventTime();
 
     // find the window with focus and dispatch this event to that widget
     nsWindow *window = get_window_for_gtk_widget(widget);
     if (!window)
         return FALSE;
 
     nsRefPtr<nsWindow> focusWindow = gFocusWindow ? gFocusWindow : window;
 
@@ -5645,17 +5655,17 @@ key_press_event_cb(GtkWidget *widget, Gd
     return focusWindow->OnKeyPressEvent(widget, event);
 }
 
 gboolean
 key_release_event_cb(GtkWidget *widget, GdkEventKey *event)
 {
     LOG(("key_release_event_cb\n"));
 
-    gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+    UpdateLastInputEventTime();
 
     // find the window with focus and dispatch this event to that widget
     nsWindow *window = get_window_for_gtk_widget(widget);
     if (!window)
         return FALSE;
 
     nsRefPtr<nsWindow> focusWindow = gFocusWindow ? gFocusWindow : window;
 
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -131,17 +131,17 @@
 #include "nsIRegion.h"
 #include "nsIServiceManager.h"
 #include "nsIClipboard.h"
 #include "nsIMM32Handler.h"
 #include "nsILocalFile.h"
 #include "nsIFontMetrics.h"
 #include "nsIFontEnumerator.h"
 #include "nsIDeviceContext.h"
-
+#include "nsIdleService.h"
 #include "nsGUIEvent.h"
 #include "nsFont.h"
 #include "nsRect.h"
 #include "nsThreadUtils.h"
 #include "nsNativeCharsetUtils.h"
 #include "nsWidgetAtoms.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
@@ -305,16 +305,25 @@ static PRBool    gCheckForHTCApi = PR_FA
 // it returns the current time. The value is compatible
 // with PR_IntervalToMicroseconds(PR_IntervalNow()).
 #if !defined(WINCE)
 static PRUint32 gLastInputEventTime               = 0;
 #else
 PRUint32        gLastInputEventTime               = 0;
 #endif
 
+static void UpdateLastInputEventTime() {
+  gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+  nsCOMPtr<nsIIdleService> idleService = do_GetService("@mozilla.org/widget/idleservice;1");
+  nsIdleService* is = static_cast<nsIdleService*>(idleService.get());
+  if (is)
+    is->IdleTimeWasModified();
+}
+
+
 // Global user preference for disabling native theme. Used
 // in NativeWindowTheme.
 PRBool          gDisableNativeTheme               = PR_FALSE;
 
 // Global used in Show window enumerations.
 static PRBool   gWindowsVisible                   = PR_FALSE;
 
 static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
@@ -3054,17 +3063,17 @@ BOOL CALLBACK nsWindow::DispatchStarvedP
 // Check for pending paints and dispatch any pending paint
 // messages for any nsIWidget which is a descendant of the
 // top-level window that *this* window is embedded within.
 //
 // Note: We do not dispatch pending paint messages for non
 // nsIWidget managed windows.
 void nsWindow::DispatchPendingEvents()
 {
-  gLastInputEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
+  UpdateLastInputEventTime();
 
   // We need to ensure that reflow events do not get starved.
   // At the same time, we don't want to recurse through here
   // as that would prevent us from dispatching starved paints.
   static int recursionBlocker = 0;
   if (recursionBlocker++ == 0) {
     NS_ProcessPendingEvents(nsnull, PR_MillisecondsToInterval(100));
     --recursionBlocker;
--- a/widget/src/xpwidgets/nsIdleService.cpp
+++ b/widget/src/xpwidgets/nsIdleService.cpp
@@ -234,8 +234,14 @@ nsIdleService::StartTimer(PRUint32 aDela
 
 void
 nsIdleService::StopTimer()
 {
     if (mTimer) {
         mTimer->Cancel();
     }
 }
+
+void
+nsIdleService::IdleTimeWasModified()
+{
+    StartTimer(0);
+}
--- a/widget/src/xpwidgets/nsIdleService.h
+++ b/widget/src/xpwidgets/nsIdleService.h
@@ -66,16 +66,18 @@ public:
     nsIdleService();
 
     // Implement nsIIdleService methods, but not the idleTime getter,
     // which is platform-dependent.
     NS_IMETHOD AddIdleObserver(nsIObserver* aObserver, PRUint32 aIdleTime);
     NS_IMETHOD RemoveIdleObserver(nsIObserver* aObserver, PRUint32 aIdleTime);
 
     static void IdleTimerCallback(nsITimer* aTimer, void* aClosure);
+    
+    void IdleTimeWasModified();
 
 protected:
     void CheckAwayState();
     ~nsIdleService();
 
 private:
     void StartTimer(PRUint32 aDelay);
     void StopTimer();