Bug 757680 - Add a pref to turn off event coalescing. r=kats
authorWes Johnston <wjohnston@mozilla.com>
Thu, 09 Aug 2012 12:54:36 -0700
changeset 102002 7ba91b3e9f38f3662f3e2f6f31c2fb36be29dde6
parent 102001 62f8e90be342294ff40d91fa66c38c9a322d7d28
child 102003 cee342fc2c0d70ade9a6ac353b16943f4a80e128
push id13267
push userwjohnston@mozilla.com
push dateThu, 09 Aug 2012 19:55:07 +0000
treeherdermozilla-inbound@7ba91b3e9f38 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs757680
milestone17.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 757680 - Add a pref to turn off event coalescing. r=kats
mobile/android/app/mobile.js
widget/android/nsAppShell.cpp
widget/android/nsAppShell.h
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -683,8 +683,11 @@ pref("reader.font_size", 4);
 // The default of margin size in reader (5%-25%)
 pref("reader.margin_size", 5);
 
 // The default color scheme in reader (light, dark, sepia)
 pref("reader.color_scheme", "light");
 
 // Used to show a first-launch tip in reader
 pref("reader.has_used_toolbar", false);
+
+// Coalesce touch events to prevent them from flooding the event queue
+pref("dom.event.touch.coalescing.enabled", true);
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -208,19 +208,21 @@ void
 nsAppShell::NotifyNativeEvent()
 {
     MutexAutoLock lock(mCondLock);
     mQueueCond.Notify();
 }
 
 #define PREFNAME_MATCH_OS  "intl.locale.matchOS"
 #define PREFNAME_UA_LOCALE "general.useragent.locale"
+#define PREFNAME_COALESCE_TOUCHES "dom.event.touch.coalescing.enabled"
 static const char* kObservedPrefs[] = {
   PREFNAME_MATCH_OS,
   PREFNAME_UA_LOCALE,
+  PREFNAME_COALESCE_TOUCHES,
   nullptr
 };
 
 nsresult
 nsAppShell::Init()
 {
 #ifdef PR_LOGGING
     if (!gWidgetLog)
@@ -257,16 +259,17 @@ nsAppShell::Init()
 
     nsAutoString locale;
     rv = Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale);
     if (NS_FAILED(rv)) {
         rv = Preferences::GetString(PREFNAME_UA_LOCALE, &locale);
     }
 
     bridge->SetSelectedLocale(locale);
+    mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true);
     return rv;
 }
 
 NS_IMETHODIMP
 nsAppShell::Observe(nsISupports* aSubject,
                     const char* aTopic,
                     const PRUnichar* aData)
 {
@@ -274,16 +277,18 @@ nsAppShell::Observe(nsISupports* aSubjec
         // We need to ensure no observers stick around after XPCOM shuts down
         // or we'll see crashes, as the app shell outlives XPConnect.
         mObserversHash.Clear();
         return nsBaseAppShell::Observe(aSubject, aTopic, aData);
     } else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && aData && (
                    nsDependentString(aData).Equals(
                        NS_LITERAL_STRING(PREFNAME_UA_LOCALE)) ||
                    nsDependentString(aData).Equals(
+                       NS_LITERAL_STRING(PREFNAME_COALESCE_TOUCHES)) ||
+                   nsDependentString(aData).Equals(
                        NS_LITERAL_STRING(PREFNAME_MATCH_OS)))) {
         AndroidBridge* bridge = AndroidBridge::Bridge();
         if (!bridge) {
             return NS_OK;
         }
 
         bool match;
         nsresult rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match);
@@ -296,16 +301,18 @@ nsAppShell::Observe(nsISupports* aSubjec
 
         nsAutoString locale;
         if (NS_FAILED(Preferences::GetLocalizedString(PREFNAME_UA_LOCALE,
                                                       &locale))) {
             locale = Preferences::GetString(PREFNAME_UA_LOCALE);
         }
 
         bridge->SetSelectedLocale(locale);
+
+        mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true);
         return NS_OK;
     }
     return NS_OK;
 }
 
 void
 nsAppShell::ScheduleNativeEventCallback()
 {
@@ -756,17 +763,17 @@ nsAppShell::PostEvent(AndroidGeckoEvent 
             // event as soon as possible after a viewport change
             mAllowCoalescingNextDraw = false;
             allowCoalescingNextViewport = true;
 
             mEventQueue.AppendElement(ae);
             break;
 
         case AndroidGeckoEvent::MOTION_EVENT:
-            if (ae->Action() == AndroidMotionEvent::ACTION_MOVE) {
+            if (ae->Action() == AndroidMotionEvent::ACTION_MOVE && mAllowCoalescingTouches) {
                 int len = mEventQueue.Length();
                 if (len > 0) {
                     AndroidGeckoEvent* event = mEventQueue[len - 1];
                     if (event->Type() == AndroidGeckoEvent::MOTION_EVENT && event->Action() == AndroidMotionEvent::ACTION_MOVE) {
                         // consecutive motion-move events; drop the last one before adding the new one
                         EVLOG("nsAppShell: Dropping old move event at %p in favour of new move event %p", event, ae);
                         mEventQueue.RemoveElementAt(len - 1);
                         delete event;
--- a/widget/android/nsAppShell.h
+++ b/widget/android/nsAppShell.h
@@ -65,16 +65,17 @@ protected:
     virtual ~nsAppShell();
 
     Mutex mQueueLock;
     Mutex mCondLock;
     CondVar mQueueCond;
     mozilla::AndroidGeckoEvent *mQueuedDrawEvent;
     mozilla::AndroidGeckoEvent *mQueuedViewportEvent;
     bool mAllowCoalescingNextDraw;
+    bool mAllowCoalescingTouches;
     nsTArray<mozilla::AndroidGeckoEvent *> mEventQueue;
     nsInterfaceHashtable<nsStringHashKey, nsIObserver> mObserversHash;
 
     mozilla::AndroidGeckoEvent *PopNextEvent();
     mozilla::AndroidGeckoEvent *PeekNextEvent();
 
     nsCOMPtr<nsIAndroidBrowserApp> mBrowserApp;
 };