Bug 594140. Make window.open width/height parameters respect opener's CSS-pixel-to-device-pixel ratio. r=tnikkel,a=jst
authorRobert O'Callahan <roc@ocallahan.org>
Thu, 09 Sep 2010 21:57:06 -0700
changeset 52352 c9f69a3d43affd03621dec8e1e744984dcd220f6
parent 52351 6c02033052728409acacc2d7bc5f5199a4e996e2
child 52353 91808d29bce3dfe5005a78103f49437fe2cb1450
push idunknown
push userunknown
push dateunknown
reviewerstnikkel, jst
bugs594140
milestone2.0b6pre
Bug 594140. Make window.open width/height parameters respect opener's CSS-pixel-to-device-pixel ratio. r=tnikkel,a=jst
embedding/components/windowwatcher/src/nsWindowWatcher.cpp
embedding/test/Makefile.in
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -86,16 +86,18 @@
 #include "nsIMutableArray.h"
 #include "nsISupportsArray.h"
 #include "nsIDeviceContext.h"
 #include "nsIDOMStorageObsolete.h"
 #include "nsIDOMStorage.h"
 #include "nsPIDOMStorage.h"
 #include "nsIWidget.h"
 #include "nsFocusManager.h"
+#include "nsIPresShell.h"
+#include "nsPresContext.h"
 
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 
 #ifdef USEWEAKREFS
 #include "nsIWeakReference.h"
 #endif
 
@@ -1898,33 +1900,27 @@ nsWindowWatcher::SizeOpenedDocShellItem(
   // get various interfaces for aDocShellItem, used throughout this method
   nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
   aDocShellItem->GetTreeOwner(getter_AddRefs(treeOwner));
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin(do_QueryInterface(treeOwner));
   if (!treeOwnerAsWin) // we'll need this to actually size the docshell
     return;
     
   float devPixelsPerCSSPixel = 1.0;
-  nsCOMPtr<nsIWidget> mainWidget;
-  treeOwnerAsWin->GetMainWidget(getter_AddRefs(mainWidget));
-  if (!mainWidget) {
-    // Some embedding clients don't support nsIDocShellTreeOwner's
-    // GetMainWidget, so try going through nsIBaseWindow's GetParentWidget
-    nsCOMPtr<nsIBaseWindow> shellWindow(do_QueryInterface(aDocShellItem));
-    if (shellWindow)
-      shellWindow->GetParentWidget(getter_AddRefs(mainWidget));
-  }
-  if (mainWidget) {
-    nsCOMPtr<nsIDeviceContext> ctx = mainWidget->GetDeviceContext();
-    /* we might be called by an extension after mainWidget::OnDestroy() */
-    if (ctx) {
-      PRInt32 unitsPerDevPixel = ctx->AppUnitsPerDevPixel();
-      if (unitsPerDevPixel) {
-        devPixelsPerCSSPixel = float(ctx->AppUnitsPerCSSPixel()) /
-                                     unitsPerDevPixel;
+  if (aParent) {
+    nsCOMPtr<nsIDOMDocument> openerDoc;
+    aParent->GetDocument(getter_AddRefs(openerDoc));
+    if (openerDoc) {
+      nsCOMPtr<nsIDocument> doc = do_QueryInterface(openerDoc);
+      nsIPresShell* shell = doc->GetShell();
+      if (shell) {
+        nsPresContext* presContext = shell->GetPresContext();
+        if (presContext) {
+          devPixelsPerCSSPixel = presContext->CSSPixelsToDevPixels(1.0f);
+        }
       }
     }
   }
 
   /* The current position and size will be unchanged if not specified
      (and they fit entirely onscreen). Also, calculate the difference
      between chrome and content sizes on aDocShellItem's window.
      This latter point becomes important if chrome and content
--- a/embedding/test/Makefile.in
+++ b/embedding/test/Makefile.in
@@ -46,12 +46,13 @@ include $(topsrcdir)/config/rules.mk
 _TEST_FILES = \
 	test_bug293834.html \
 	bug293834_form.html \
 	320x240.ogv \
 	test_bug449141.html \
 	bug449141_page.html \
 	test_bug499115.html \
 	test_nsFind.html \
+	test_window_open_units.html \
 	$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)