Bug 594140. Make window.open width/height parameters respect opener's CSS-pixel-to-device-pixel ratio. r=tnikkel,a=jst
--- 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)