Bug 827976 - Tablet Mode detection should favor using an existing window instead of the hidden window. r=aklotz
☠☠ backed out by bf3cbcc82527 ☠ ☠
authorFelipe Gomes <felipc@gmail.com>
Fri, 01 Mar 2019 21:05:32 +0000
changeset 519894 9203871a5c6f9bbb69c425ae2ec0b1cc805a061d
parent 519893 96a507c818e278fc85c23b60f83a93d9ca517100
child 519895 69d0378e0c098473f288d02557b7871f0eb685ff
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs827976
milestone67.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 827976 - Tablet Mode detection should favor using an existing window instead of the hidden window. r=aklotz Differential Revision: https://phabricator.services.mozilla.com/D21073
widget/windows/WindowsUIUtils.cpp
--- a/widget/windows/WindowsUIUtils.cpp
+++ b/widget/windows/WindowsUIUtils.cpp
@@ -13,19 +13,22 @@
 
 #include "nsIObserverService.h"
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
 #include "nsIAppShellService.h"
 #include "nsAppShellCID.h"
 #include "nsIXULWindow.h"
 #include "mozilla/Services.h"
+#include "mozilla/WidgetUtils.h"
 #include "mozilla/WindowsVersion.h"
 #include "nsString.h"
 #include "nsIWidget.h"
+#include "nsIWindowMediator.h"
+#include "nsPIDOMWindow.h"
 
 /* mingw currently doesn't support windows.ui.viewmanagement.h, so we disable it
  * until it's fixed. */
 #ifndef __MINGW32__
 
 #  include <windows.ui.viewmanagement.h>
 
 #  pragma comment(lib, "runtimeobject.lib")
@@ -131,37 +134,41 @@ WindowsUIUtils::GetInTabletMode(bool* aR
 
 NS_IMETHODIMP
 WindowsUIUtils::UpdateTabletModeState() {
 #ifndef __MINGW32__
   if (!IsWin10OrLater()) {
     return NS_OK;
   }
 
-  nsCOMPtr<nsIAppShellService> appShell(
-      do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
-  nsCOMPtr<nsIXULWindow> hiddenWindow;
-
-  nsresult rv = appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
+  nsresult rv;
+  nsCOMPtr<nsIWindowMediator> winMediator(
+      do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv));
   if (NS_FAILED(rv)) {
     return rv;
   }
 
-  nsCOMPtr<nsIDocShell> docShell;
-  rv = hiddenWindow->GetDocShell(getter_AddRefs(docShell));
-  if (NS_FAILED(rv) || !docShell) {
-    return rv;
+  nsCOMPtr<nsIWidget> widget;
+  nsCOMPtr<mozIDOMWindowProxy> navWin;
+
+  rv = winMediator->GetMostRecentWindow(u"navigator:browser",
+                                        getter_AddRefs(navWin));
+  if (NS_FAILED(rv) || !navWin) {
+    // Fall back to the hidden window
+    nsCOMPtr<nsIAppShellService> appShell(
+      do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
+
+    rv = appShell->GetHiddenDOMWindow(getter_AddRefs(navWin));
+    if (NS_FAILED(rv) || !navWin) {
+      return rv;
+    }
   }
 
-  nsCOMPtr<nsIBaseWindow> baseWindow(do_QueryInterface(docShell));
-
-  if (!baseWindow) return NS_ERROR_FAILURE;
-
-  nsCOMPtr<nsIWidget> widget;
-  baseWindow->GetMainWidget(getter_AddRefs(widget));
+  nsPIDOMWindowOuter* win = nsPIDOMWindowOuter::From(navWin);
+  widget = widget::WidgetUtils::DOMWindowToWidget(win);
 
   if (!widget) return NS_ERROR_FAILURE;
 
   HWND winPtr = (HWND)widget->GetNativeData(NS_NATIVE_WINDOW);
   ComPtr<IUIViewSettingsInterop> uiViewSettingsInterop;
 
   HRESULT hr = GetActivationFactory(
       HStringReference(RuntimeClass_Windows_UI_ViewManagement_UIViewSettings)