From 7b9e1161f6c4c94bfaf3f289570132b7ab470d14 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Mon, 6 Feb 2012 16:31:16 +0100 Subject: [PATCH] Bug 720799 - Don't use mDocShell in nsScreen. r=jst --- dom/base/nsScreen.cpp | 46 +++++++++++++++++------------------ dom/base/nsScreen.h | 2 +- layout/base/nsLayoutUtils.cpp | 4 +-- layout/base/nsLayoutUtils.h | 4 +-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index bc7884da7513..68a88af87887 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -55,6 +55,23 @@ using namespace mozilla::dom; /* static */ bool nsScreen::sAllowScreenEnabledProperty = false; /* static */ bool nsScreen::sAllowScreenBrightnessProperty = false; +namespace { + +bool +IsChromeType(nsIDocShell *aDocShell) +{ + nsCOMPtr ds = do_QueryInterface(aDocShell); + if (!ds) { + return false; + } + + PRInt32 itemType; + ds->GetItemType(&itemType); + return itemType == nsIDocShellTreeItem::typeChrome; +} + +} // anonymous namespace + /* static */ void nsScreen::Initialize() { @@ -93,7 +110,7 @@ nsScreen::Create(nsPIDOMWindow* aWindow) screen->mOwner = aWindow; screen->mScriptContext.swap(scriptContext); - screen->mDocShell = aWindow->GetDocShell(); + screen->mIsChrome = IsChromeType(aWindow->GetDocShell()); hal::RegisterScreenOrientationObserver(screen); hal::GetCurrentScreenOrientation(&(screen->mOrientation)); @@ -254,7 +271,7 @@ nsScreen::GetAvailTop(PRInt32* aAvailTop) nsDeviceContext* nsScreen::GetDeviceContext() { - return nsLayoutUtils::GetDeviceContextForScreenInfo(mDocShell); + return nsLayoutUtils::GetDeviceContextForScreenInfo(mOwner); } nsresult @@ -295,27 +312,10 @@ nsScreen::GetAvailRect(nsRect& aRect) return NS_OK; } -namespace { - -bool -IsChromeType(nsIDocShell *aDocShell) -{ - nsCOMPtr ds = do_QueryInterface(aDocShell); - if (!ds) { - return false; - } - - PRInt32 itemType; - ds->GetItemType(&itemType); - return itemType == nsIDocShellTreeItem::typeChrome; -} - -} // anonymous namespace - nsresult nsScreen::GetMozEnabled(bool *aEnabled) { - if (!sAllowScreenEnabledProperty || !IsChromeType(mDocShell)) { + if (!sAllowScreenEnabledProperty || mIsChrome) { *aEnabled = true; return NS_OK; } @@ -327,7 +327,7 @@ nsScreen::GetMozEnabled(bool *aEnabled) nsresult nsScreen::SetMozEnabled(bool aEnabled) { - if (!sAllowScreenEnabledProperty || !IsChromeType(mDocShell)) { + if (!sAllowScreenEnabledProperty || mIsChrome) { return NS_OK; } @@ -340,7 +340,7 @@ nsScreen::SetMozEnabled(bool aEnabled) nsresult nsScreen::GetMozBrightness(double *aBrightness) { - if (!sAllowScreenBrightnessProperty || !IsChromeType(mDocShell)) { + if (!sAllowScreenBrightnessProperty || mIsChrome) { *aBrightness = 1; return NS_OK; } @@ -352,7 +352,7 @@ nsScreen::GetMozBrightness(double *aBrightness) nsresult nsScreen::SetMozBrightness(double aBrightness) { - if (!sAllowScreenBrightnessProperty || !IsChromeType(mDocShell)) { + if (!sAllowScreenBrightnessProperty || mIsChrome) { return NS_OK; } diff --git a/dom/base/nsScreen.h b/dom/base/nsScreen.h index 811355a204df..8dc79dcd4829 100644 --- a/dom/base/nsScreen.h +++ b/dom/base/nsScreen.h @@ -74,7 +74,7 @@ protected: nsresult GetRect(nsRect& aRect); nsresult GetAvailRect(nsRect& aRect); - nsIDocShell* mDocShell; // Weak Reference + bool mIsChrome; mozilla::dom::ScreenOrientation mOrientation; diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 384458b20c4d..edb38aba4b65 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -4005,9 +4005,9 @@ nsLayoutUtils::GetRectDifferenceStrips(const nsRect& aR1, const nsRect& aR2, } nsDeviceContext* -nsLayoutUtils::GetDeviceContextForScreenInfo(nsIDocShell* aDocShell) +nsLayoutUtils::GetDeviceContextForScreenInfo(nsPIDOMWindow* aWindow) { - nsCOMPtr docShell = aDocShell; + nsCOMPtr docShell = aWindow->GetDocShell(); 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 diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 76621a2c82d0..737be3a65485 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -1330,11 +1330,11 @@ public: /** * Get a device context that can be used to get up-to-date device - * dimensions for the given docshell. For some reason, this is more + * dimensions for the given window. For some reason, this is more * complicated than it ought to be in multi-monitor situations. */ static nsDeviceContext* - GetDeviceContextForScreenInfo(nsIDocShell* aDocShell); + GetDeviceContextForScreenInfo(nsPIDOMWindow* aWindow); /** * Some frames with 'position: fixed' (nsStylePosition::mDisplay ==