Commit 7ff21b86 authored by Mounir Lamouri's avatar Mounir Lamouri
Browse files

Bug 720799 - Don't use mDocShell in nsScreen. r=jst

parent 07c11756
Loading
Loading
Loading
Loading
+23 −23
Original line number Diff line number Diff line
@@ -55,6 +55,23 @@ using namespace mozilla::dom;
/* static */ bool nsScreen::sAllowScreenEnabledProperty = false;
/* static */ bool nsScreen::sAllowScreenBrightnessProperty = false;

namespace {

bool
IsChromeType(nsIDocShell *aDocShell)
{
  nsCOMPtr<nsIDocShellTreeItem> 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<nsIDocShellTreeItem> 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;
  }

+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ protected:
  nsresult GetRect(nsRect& aRect);
  nsresult GetAvailRect(nsRect& aRect);

  nsIDocShell* mDocShell; // Weak Reference
  bool mIsChrome;

  mozilla::dom::ScreenOrientation mOrientation;

+2 −2
Original line number Diff line number Diff line
@@ -4005,9 +4005,9 @@ nsLayoutUtils::GetRectDifferenceStrips(const nsRect& aR1, const nsRect& aR2,
}

nsDeviceContext*
nsLayoutUtils::GetDeviceContextForScreenInfo(nsIDocShell* aDocShell)
nsLayoutUtils::GetDeviceContextForScreenInfo(nsPIDOMWindow* aWindow)
{
  nsCOMPtr<nsIDocShell> docShell = aDocShell;
  nsCOMPtr<nsIDocShell> 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
+2 −2
Original line number Diff line number Diff line
@@ -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 ==