Bug 1410988 - Add a debug mode pref to emulate odd touchpad utils which give focus to window under mouse cursor when user tries to scroll the content r?jimm draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 19 Oct 2017 02:28:37 +0900
changeset 684934 d971fc7b034857a820816d7d90dd7ffe26754b62
parent 684933 1a3dac78b1eda703bbe0e14b01af86f6d9bba64e
child 686321 08777cffc192d7d710e28098fa52710e7bb4998e
push id85768
push usermasayuki@d-toybox.com
push dateMon, 23 Oct 2017 19:06:34 +0000
reviewersjimm
bugs1410988
milestone58.0a1
Bug 1410988 - Add a debug mode pref to emulate odd touchpad utils which give focus to window under mouse cursor when user tries to scroll the content r?jimm Some odd touchpad utils give focus to window under mouse cursor when user tries to scroll the content with swiping or something. This is really odd behavior because some windows like popup windows doesn't want focus. However, such ones do actually. For making easier to check such device's behavior, we should have a pref to emulate such behavior. MozReview-Commit-ID: 6euwpHn7blf
modules/libpref/init/all.js
widget/windows/WinMouseScrollHandler.cpp
widget/windows/WinMouseScrollHandler.h
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -3985,16 +3985,22 @@ pref("mousewheel.system_settings_cache.f
 
 // High resolution scrolling with supported mouse drivers on Vista or later.
 pref("mousewheel.enable_pixel_scrolling", true);
 
 // If your mouse drive sends WM_*SCROLL messages when you turn your mouse wheel,
 // set this to true.  Then, gecko processes them as mouse wheel messages.
 pref("mousewheel.emulate_at_wm_scroll", false);
 
+// Some odd touchpad utils give focus to window under cursor when user tries
+// to scroll.  If this is true, Gecko tries to emulate such odd behavior.
+// Don't make this true unless you want to debug.  Enabling this pref causes
+// making damage to the performance.
+pref("mousewheel.debug.make_window_under_cursor_foreground", false);
+
 // Enables or disabled the TrackPoint hack, -1 is autodetect, 0 is off,
 // and 1 is on.  Set this to 1 if TrackPoint scrolling is not working.
 pref("ui.trackpoint_hack.enabled", -1);
 
 // Setting this to a non-empty string overrides the Win32 "window class" used
 // for "normal" windows. Setting this to MozillaUIWindowClass might make
 // some trackpad drivers behave better.
 pref("ui.window_class_override", "");
--- a/widget/windows/WinMouseScrollHandler.cpp
+++ b/widget/windows/WinMouseScrollHandler.cpp
@@ -441,16 +441,24 @@ MouseScrollHandler::ProcessNativeMouseWh
           ("MouseScroll::ProcessNativeMouseWheelMessage: Our window which is "
            "managed by nsWindow is not found under the cursor"));
         return;
       }
     }
 
     MOZ_ASSERT(destWindow, "destWindow must not be NULL");
 
+    // Some odd touchpad utils sets focus to window under the mouse cursor.
+    // this emulates the odd behavior for debug.
+    if (mUserPrefs.ShouldEmulateToMakeWindowUnderCursorForeground() &&
+        (aMessage == WM_MOUSEWHEEL || aMessage == WM_MOUSEHWHEEL) &&
+        ::GetForegroundWindow() != destWindow->GetWindowHandle()) {
+      ::SetForegroundWindow(destWindow->GetWindowHandle());
+    }
+
     // If the found window is our plugin window, it means that the message
     // has been handled by the plugin but not consumed.  We should handle the
     // message on its parent window.  However, note that the DOM event may
     // cause accessing the plugin.  Therefore, we should unlock the plugin
     // process by using PostMessage().
     if (destWindow->IsPlugin()) {
       destWindow = destWindow->GetParentWindowBase(false);
       if (!destWindow) {
@@ -1116,35 +1124,40 @@ MouseScrollHandler::UserPrefs::Init()
 
   mScrollMessageHandledAsWheelMessage =
     Preferences::GetBool("mousewheel.emulate_at_wm_scroll", false);
   mEnableSystemSettingCache =
     Preferences::GetBool("mousewheel.system_settings_cache.enabled", true);
   mForceEnableSystemSettingCache =
     Preferences::GetBool("mousewheel.system_settings_cache.force_enabled",
                          false);
+  mEmulateToMakeWindowUnderCursorForeground =
+    Preferences::GetBool("mousewheel.debug.make_window_under_cursor_foreground",
+                         false);
   mOverriddenVerticalScrollAmount =
     Preferences::GetInt("mousewheel.windows.vertical_amount_override", -1);
   mOverriddenHorizontalScrollAmount =
     Preferences::GetInt("mousewheel.windows.horizontal_amount_override", -1);
   mMouseScrollTransactionTimeout =
     Preferences::GetInt("mousewheel.windows.transaction.timeout",
                         DEFAULT_TIMEOUT_DURATION);
 
   MOZ_LOG(gMouseScrollLog, LogLevel::Info,
     ("MouseScroll::UserPrefs::Init(): initialized, "
        "mScrollMessageHandledAsWheelMessage=%s, "
        "mEnableSystemSettingCache=%s, "
        "mForceEnableSystemSettingCache=%s, "
+       "mEmulateToMakeWindowUnderCursorForeground=%s, "
        "mOverriddenVerticalScrollAmount=%d, "
        "mOverriddenHorizontalScrollAmount=%d, "
        "mMouseScrollTransactionTimeout=%d",
      GetBoolName(mScrollMessageHandledAsWheelMessage),
      GetBoolName(mEnableSystemSettingCache),
      GetBoolName(mForceEnableSystemSettingCache),
+     GetBoolName(mEmulateToMakeWindowUnderCursorForeground),
      mOverriddenVerticalScrollAmount, mOverriddenHorizontalScrollAmount,
      mMouseScrollTransactionTimeout));
 }
 
 void
 MouseScrollHandler::UserPrefs::MarkDirty()
 {
   MOZ_LOG(gMouseScrollLog, LogLevel::Info,
--- a/widget/windows/WinMouseScrollHandler.h
+++ b/widget/windows/WinMouseScrollHandler.h
@@ -348,16 +348,22 @@ private:
     }
 
     bool IsSystemSettingCacheForciblyEnabled()
     {
       Init();
       return mForceEnableSystemSettingCache;
     }
 
+    bool ShouldEmulateToMakeWindowUnderCursorForeground()
+    {
+      Init();
+      return mEmulateToMakeWindowUnderCursorForeground;
+    }
+
     int32_t GetOverriddenVerticalScrollAmout()
     {
       Init();
       return mOverriddenVerticalScrollAmount;
     }
 
     int32_t GetOverriddenHorizontalScrollAmout()
     {
@@ -378,16 +384,17 @@ private:
     {
       static_cast<UserPrefs*>(aClosure)->MarkDirty();
     }
 
     bool mInitialized;
     bool mScrollMessageHandledAsWheelMessage;
     bool mEnableSystemSettingCache;
     bool mForceEnableSystemSettingCache;
+    bool mEmulateToMakeWindowUnderCursorForeground;
     int32_t mOverriddenVerticalScrollAmount;
     int32_t mOverriddenHorizontalScrollAmount;
     int32_t mMouseScrollTransactionTimeout;
   };
 
   UserPrefs mUserPrefs;
 
   class SynthesizingEvent {