bug 794038 pt 0.9 - provide an unscaledDevicePixelsPerCSSPixel attribute on nsIBaseWindow to expose the default device-pix/css-pix ratio. r=roc
authorJonathan Kew <jkew@mozilla.com>
Tue, 16 Oct 2012 20:41:19 +0100
changeset 110422 5ec67c1dd2e1d5b737a60a8118034e40171dfc5b
parent 110421 a2a2ad2cfb501526bf5e0c60f9ce67dfd8c85c32
child 110423 4120e702e25bc06052fc984a0cef151f87ddaa3d
push id16548
push userjkew@mozilla.com
push dateTue, 16 Oct 2012 19:43:27 +0000
treeherdermozilla-inbound@eaccb5bb50c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs794038
milestone19.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 794038 pt 0.9 - provide an unscaledDevicePixelsPerCSSPixel attribute on nsIBaseWindow to expose the default device-pix/css-pix ratio. r=roc
docshell/base/nsDocShell.cpp
embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
embedding/browser/webBrowser/nsWebBrowser.cpp
widget/nsIBaseWindow.idl
xpfe/appshell/src/nsChromeTreeOwner.cpp
xpfe/appshell/src/nsContentTreeOwner.cpp
xpfe/appshell/src/nsXULWindow.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -4929,16 +4929,33 @@ nsDocShell::Destroy()
 
     // Cancel any timers that were set for this docshell; this is needed
     // to break the cycle between us and the timers.
     CancelRefreshURITimers();
     return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocShell::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
+{
+    if (mParentWidget) {
+        *aScale = mParentWidget->GetDefaultScale();
+        return NS_OK;
+    }
+
+    nsCOMPtr<nsIBaseWindow> ownerWindow(do_QueryInterface(mTreeOwner));
+    if (ownerWindow) {
+        return ownerWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
+    }
+
+    *aScale = 1.0;
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDocShell::SetPosition(int32_t x, int32_t y)
 {
     mBounds.x = x;
     mBounds.y = y;
 
     if (mContentViewer)
         NS_ENSURE_SUCCESS(mContentViewer->Move(x, y), NS_ERROR_FAILURE);
 
--- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
@@ -466,16 +466,27 @@ nsDocShellTreeOwner::Destroy()
   {
     return webBrowserChrome->DestroyBrowserWindow();
   }
 
   return NS_ERROR_NULL_POINTER;
 }
 
 NS_IMETHODIMP
+nsDocShellTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
+{
+  if (mWebBrowser) {
+    return mWebBrowser->GetUnscaledDevicePixelsPerCSSPixel(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);
   }
--- a/embedding/browser/webBrowser/nsWebBrowser.cpp
+++ b/embedding/browser/webBrowser/nsWebBrowser.cpp
@@ -1234,16 +1234,22 @@ NS_IMETHODIMP nsWebBrowser::Destroy()
    InternalDestroy();
 
    if(!mInitInfo)
       mInitInfo = new nsWebBrowserInitInfo();
 
    return NS_OK;
 }
 
+NS_IMETHODIMP nsWebBrowser::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
+{
+  *aScale = mParentWidget ? mParentWidget->GetDefaultScale() : 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(7144AC8B-6702-4A4B-A73D-D1D4E9717E46)]
+[scriptable, uuid(9DA319F3-EEE6-4504-81A5-6A19CF6215BF)]
 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.
 
@@ -177,17 +177,26 @@ interface nsIBaseWindow : nsISupports
     attribute boolean enabled;
 
 	/*
 	Allows you to find out what the widget is of a given object.  Depending
 	on the object, this may return the parent widget in which this object
 	lives if it has not had to create its own widget.
 	*/
 	[noscript] readonly attribute nsIWidget mainWidget;
-	
+
+	/*
+	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;
+
 	/**
 	* Give the window focus.
 	*/
 	void setFocus();
 
 	/*
 	Title of the window.
 	*/
--- a/xpfe/appshell/src/nsChromeTreeOwner.cpp
+++ b/xpfe/appshell/src/nsChromeTreeOwner.cpp
@@ -343,16 +343,22 @@ NS_IMETHODIMP nsChromeTreeOwner::Create(
 }
 
 NS_IMETHODIMP nsChromeTreeOwner::Destroy()
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->Destroy();
 }
 
+NS_IMETHODIMP nsChromeTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
+{
+   NS_ENSURE_STATE(mXULWindow);
+   return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(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/src/nsContentTreeOwner.cpp
+++ b/xpfe/appshell/src/nsContentTreeOwner.cpp
@@ -560,16 +560,22 @@ NS_IMETHODIMP nsContentTreeOwner::Create
 }
 
 NS_IMETHODIMP nsContentTreeOwner::Destroy()
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->Destroy();
 }
 
+NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(double* aScale)
+{
+   NS_ENSURE_STATE(mXULWindow);
+   return mXULWindow->GetUnscaledDevicePixelsPerCSSPixel(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/src/nsXULWindow.cpp
+++ b/xpfe/appshell/src/nsXULWindow.cpp
@@ -526,16 +526,22 @@ NS_IMETHODIMP nsXULWindow::Destroy()
 
     if (obssvc)
       obssvc->NotifyObservers(nullptr, "xul-window-destroyed", nullptr);
   }
 
   return NS_OK;
 }
 
+NS_IMETHODIMP nsXULWindow::GetUnscaledDevicePixelsPerCSSPixel(double *aScale)
+{
+  *aScale = mWindow ? mWindow->GetDefaultScale() : 1.0;
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsXULWindow::SetPosition(int32_t aX, int32_t aY)
 {
   // Don't reset the window's size mode here - platforms that don't want to move
   // maximized windows should reset it in their respective Move implementation.
   NS_ENSURE_SUCCESS(mWindow->Move(aX, aY), NS_ERROR_FAILURE);
   if (!mChromeLoaded) {
     // If we're called before the chrome is loaded someone obviously wants this
     // window at this position. We don't persist this one-time position.