From 8aa408e3e129cd74d99491efcf72a15bc343a296 Mon Sep 17 00:00:00 2001 From: "mats.palmgren@bredband.net" Date: Tue, 8 May 2007 02:43:59 -0700 Subject: [PATCH] Search docshell ancestors for a device context if it can't be found on the current one. b=377539 r+sr=bzbarsky --- dom/src/base/nsScreen.cpp | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/dom/src/base/nsScreen.cpp b/dom/src/base/nsScreen.cpp index bcb2db257d3a..3d701c48383a 100644 --- a/dom/src/base/nsScreen.cpp +++ b/dom/src/base/nsScreen.cpp @@ -39,12 +39,13 @@ #include "nscore.h" #include "nsScreen.h" #include "nsPIDOMWindow.h" -#include "nsIScriptGlobalObject.h" +#include "nsIBaseWindow.h" #include "nsIDocShell.h" +#include "nsIDocShellTreeItem.h" #include "nsIDeviceContext.h" +#include "nsIWidget.h" #include "nsPresContext.h" #include "nsCOMPtr.h" -#include "nsIDocumentViewer.h" #include "nsDOMClassInfo.h" #include "nsIInterfaceRequestorUtils.h" @@ -198,36 +199,36 @@ nsScreen::GetAvailTop(PRInt32* aAvailTop) nsIDeviceContext* nsScreen::GetDeviceContext() { - if(!mDocShell) - return nsnull; + nsCOMPtr docShell = mDocShell; + while (docShell) { + // Now make sure our size is up to date. That will mean that the device + // context does the right thing on multi-monitor systems when we return it to + // the caller. It will also make sure that our prescontext has been created, + // if we're supposed to have one. + nsCOMPtr win = do_GetInterface(docShell); + if (!win) { + // No reason to go on + return nsnull; + } - // Now make sure our size is up to date. That will mean that the device - // context does the right thing on multi-monitor systems when we return it to - // the caller. It will also make sure that our prescontext has been created, - // if we're supposed to have one. - nsCOMPtr win = do_GetInterface(mDocShell); - if (!win) { - // No reason to go on - return nsnull; + win->EnsureSizeUpToDate(); + + nsCOMPtr baseWindow = do_QueryInterface(docShell); + NS_ENSURE_TRUE(baseWindow, nsnull); + + nsCOMPtr mainWidget; + baseWindow->GetMainWidget(getter_AddRefs(mainWidget)); + if (mainWidget) { + return mainWidget->GetDeviceContext(); + } + + nsCOMPtr curItem = do_QueryInterface(docShell); + nsCOMPtr parentItem; + curItem->GetParent(getter_AddRefs(parentItem)); + docShell = do_QueryInterface(parentItem); } - win->EnsureSizeUpToDate(); - - nsCOMPtr contentViewer; - mDocShell->GetContentViewer(getter_AddRefs(contentViewer)); - - nsCOMPtr docViewer(do_QueryInterface(contentViewer)); - if(!docViewer) - return nsnull; - - nsCOMPtr presContext; - docViewer->GetPresContext(getter_AddRefs(presContext)); - - nsIDeviceContext* context = nsnull; - if(presContext) - context = presContext->DeviceContext(); - - return context; + return nsnull; } nsresult