Bug 890156 - patch 2 - Expose DevicePixelsPerDesktopPixel through nsIBaseWindow and its implementations. r=emk
authorJonathan Kew <jkew@mozilla.com>
Wed, 25 Nov 2015 19:12:07 +0000
changeset 279690 20c8f6d967569c5f878621c6ee15cbc1f3c51017
parent 279689 cc09fb02f2c9191098ff2ab9ba97ed57162e806b
child 279691 443207a1d886ce2d13bc7328e51dbca2300f8fcd
push id70188
push userjkew@mozilla.com
push dateWed, 13 Jan 2016 08:42:41 +0000
treeherdermozilla-inbound@a9f9b36c1a2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs890156
milestone46.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 890156 - patch 2 - Expose DevicePixelsPerDesktopPixel through nsIBaseWindow and its implementations. r=emk
docshell/base/nsDocShell.cpp
embedding/browser/nsDocShellTreeOwner.cpp
embedding/browser/nsWebBrowser.cpp
widget/nsIBaseWindow.idl
xpfe/appshell/nsChromeTreeOwner.cpp
xpfe/appshell/nsContentTreeOwner.cpp
xpfe/appshell/nsXULWindow.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -5778,16 +5778,33 @@ nsDocShell::GetUnscaledDevicePixelsPerCS
     return ownerWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
   }
 
   *aScale = 1.0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocShell::GetDevicePixelsPerDesktopPixel(double* aScale)
+{
+  if (mParentWidget) {
+    *aScale = mParentWidget->GetDesktopToDeviceScale().scale;
+    return NS_OK;
+  }
+
+  nsCOMPtr<nsIBaseWindow> ownerWindow(do_QueryInterface(mTreeOwner));
+  if (ownerWindow) {
+    return ownerWindow->GetDevicePixelsPerDesktopPixel(aScale);
+  }
+
+  *aScale = 1.0;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDocShell::SetPosition(int32_t aX, int32_t aY)
 {
   mBounds.x = aX;
   mBounds.y = aY;
 
   if (mContentViewer) {
     NS_ENSURE_SUCCESS(mContentViewer->Move(aX, aY), NS_ERROR_FAILURE);
   }
--- a/embedding/browser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/nsDocShellTreeOwner.cpp
@@ -556,16 +556,27 @@ nsDocShellTreeOwner::GetUnscaledDevicePi
     return mWebBrowser->GetUnscaledDevicePixelsPerCSSPixel(aScale);
   }
 
   *aScale = 1.0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocShellTreeOwner::GetDevicePixelsPerDesktopPixel(double* aScale)
+{
+  if (mWebBrowser) {
+    return mWebBrowser->GetDevicePixelsPerDesktopPixel(aScale);
+  }
+
+  *aScale = 1.0;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDocShellTreeOwner::SetPosition(int32_t aX, int32_t aY)
 {
   nsCOMPtr<nsIEmbeddingSiteWindow> ownerWin = GetOwnerWin();
   if (ownerWin) {
     return ownerWin->SetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION,
                                    aX, aY, 0, 0);
   }
   return NS_ERROR_NULL_POINTER;
--- a/embedding/browser/nsWebBrowser.cpp
+++ b/embedding/browser/nsWebBrowser.cpp
@@ -1290,16 +1290,24 @@ nsWebBrowser::Destroy()
 NS_IMETHODIMP
 nsWebBrowser::GetUnscaledDevicePixelsPerCSSPixel(double* aScale)
 {
   *aScale = mParentWidget ? mParentWidget->GetDefaultScale().scale : 1.0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsWebBrowser::GetDevicePixelsPerDesktopPixel(double* aScale)
+{
+  *aScale = mParentWidget ? mParentWidget->GetDesktopToDeviceScale().scale
+                          : 1.0;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsWebBrowser::SetPosition(int32_t aX, int32_t aY)
 {
   int32_t cx = 0;
   int32_t cy = 0;
 
   GetSize(&cx, &cy);
 
   return SetPositionAndSize(aX, aY, cx, cy, false);
--- a/widget/nsIBaseWindow.idl
+++ b/widget/nsIBaseWindow.idl
@@ -16,17 +16,17 @@ class nsIWidget;
 typedef voidPtr nativeWindow;
 
 /**
  * The nsIBaseWindow describes a generic window and basic operations that 
  * can be performed on it.  This is not to be a complete windowing interface
  * but rather a common set that nearly all windowed objects support.    
  */
 
-[scriptable, uuid(9DA319F3-EEE6-4504-81A5-6A19CF6215BF)]
+[scriptable, uuid(ca635529-a977-4552-9b8a-66187e54d882)]
 interface nsIBaseWindow : nsISupports
 {
 	/*
 	Allows a client to initialize an object implementing this interface with
 	the usually required window setup information.
 	It is possible to pass null for both parentNativeWindow and parentWidget,
 	but only docshells support this.
 
@@ -187,16 +187,30 @@ interface nsIBaseWindow : nsISupports
 	The number of	device pixels per CSS pixel used on this window's current
 	screen at the default zoom level.
 	This is the value returned by GetDefaultScale() of the underlying widget.
 	Note that this may change if the window is moved between screens with
 	differing resolutions.
 	*/
 	readonly attribute double unscaledDevicePixelsPerCSSPixel;
 
+	/*
+	The number of device pixels per display pixel on this window's current
+	screen. (The meaning of "display pixel" varies across OS environments;
+	it is the pixel units used by the desktop environment to manage screen
+	real estate and window positioning, which may correspond to (per-screen)
+	device pixels, or may be a virtual coordinate space that covers a multi-
+	monitor, mixed-dpi desktop space.)
+	This is the value returned by DevicePixelsPerDesktopPixel() of the underlying
+	widget.
+	Note that this may change if the window is moved between screens with
+	differing resolutions.
+	*/
+	readonly attribute double devicePixelsPerDesktopPixel;
+
 	/**
 	* Give the window focus.
 	*/
 	void setFocus();
 
 	/*
 	Title of the window.
 	*/
--- a/xpfe/appshell/nsChromeTreeOwner.cpp
+++ b/xpfe/appshell/nsChromeTreeOwner.cpp
@@ -377,16 +377,22 @@ NS_IMETHODIMP nsChromeTreeOwner::Destroy
 }
 
 NS_IMETHODIMP nsChromeTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
 }
 
+NS_IMETHODIMP nsChromeTreeOwner::GetDevicePixelsPerDesktopPixel(double *aScale)
+{
+   NS_ENSURE_STATE(mXULWindow);
+   return mXULWindow->GetDevicePixelsPerDesktopPixel(aScale);
+}
+
 NS_IMETHODIMP nsChromeTreeOwner::SetPosition(int32_t x, int32_t y)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->SetPosition(x, y);
 }
 
 NS_IMETHODIMP nsChromeTreeOwner::GetPosition(int32_t* x, int32_t* y)
 {
--- a/xpfe/appshell/nsContentTreeOwner.cpp
+++ b/xpfe/appshell/nsContentTreeOwner.cpp
@@ -616,16 +616,22 @@ NS_IMETHODIMP nsContentTreeOwner::Destro
 }
 
 NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
 }
 
+NS_IMETHODIMP nsContentTreeOwner::GetDevicePixelsPerDesktopPixel(double* aScale)
+{
+   NS_ENSURE_STATE(mXULWindow);
+   return mXULWindow->GetDevicePixelsPerDesktopPixel(aScale);
+}
+
 NS_IMETHODIMP nsContentTreeOwner::SetPosition(int32_t aX, int32_t aY)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->SetPosition(aX, aY);
 }
 
 NS_IMETHODIMP nsContentTreeOwner::GetPosition(int32_t* aX, int32_t* aY)
 {
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -552,16 +552,22 @@ NS_IMETHODIMP nsXULWindow::Destroy()
 
     if (obssvc)
       obssvc->NotifyObservers(nullptr, "xul-window-destroyed", nullptr);
   }
 
   return NS_OK;
 }
 
+NS_IMETHODIMP nsXULWindow::GetDevicePixelsPerDesktopPixel(double *aScale)
+{
+  *aScale = mWindow ? mWindow->GetDesktopToDeviceScale().scale : 1.0;
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsXULWindow::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
 {
   *aScale = mWindow ? mWindow->GetDefaultScale().scale : 1.0;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsXULWindow::SetPosition(int32_t aX, int32_t aY)
 {