Bug 938626, be more consistent when handling pref changes in PresContext, r=tn
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Sun, 17 Nov 2013 22:49:52 +0200
changeset 155075 78a02007f3831a6c9e64b14d4c6180bb2bb1acb6
parent 155074 1e6ac3f67e79de40ca2385193612102087fee89c
child 155076 8b676ce79d10328cd475dc160aaaf145248cfbb4
push id25662
push useremorley@mozilla.com
push dateMon, 18 Nov 2013 10:53:03 +0000
treeherdermozilla-central@59f6274ce8f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs938626
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 938626, be more consistent when handling pref changes in PresContext, r=tn
layout/base/nsPresContext.cpp
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -138,17 +138,18 @@ nsPresContext::IsDOMPaintEventPending()
     return true;
   }
   return false;
 }
 
 int
 nsPresContext::PrefChangedCallback(const char* aPrefName, void* instance_data)
 {
-  nsPresContext*  presContext = (nsPresContext*)instance_data;
+  nsRefPtr<nsPresContext>  presContext =
+    static_cast<nsPresContext*>(instance_data);
 
   NS_ASSERTION(nullptr != presContext, "bad instance data");
   if (nullptr != presContext) {
     presContext->PreferenceChanged(aPrefName);
   }
   return 0;  // PREF_OK
 }
 
@@ -801,17 +802,19 @@ nsPresContext::InvalidateThebesLayers()
   }
 }
 
 void
 nsPresContext::AppUnitsPerDevPixelChanged()
 {
   InvalidateThebesLayers();
 
-  mDeviceContext->FlushFontCache();
+  if (mDeviceContext) {
+    mDeviceContext->FlushFontCache();
+  }
 
   if (HasCachedStyleData()) {
     // All cached style data must be recomputed.
     MediaFeatureValuesChanged(eAlwaysRebuildStyle, NS_STYLE_HINT_REFLOW);
   }
 
   mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel();
 }
@@ -819,20 +822,24 @@ nsPresContext::AppUnitsPerDevPixelChange
 void
 nsPresContext::PreferenceChanged(const char* aPrefName)
 {
   nsDependentCString prefName(aPrefName);
   if (prefName.EqualsLiteral("layout.css.dpi") ||
       prefName.EqualsLiteral("layout.css.devPixelsPerPx")) {
     int32_t oldAppUnitsPerDevPixel = AppUnitsPerDevPixel();
     if (mDeviceContext->CheckDPIChange() && mShell) {
+      nsCOMPtr<nsIPresShell> shell = mShell;
       // Re-fetch the view manager's window dimensions in case there's a deferred
       // resize which hasn't affected our mVisibleArea yet
       nscoord oldWidthAppUnits, oldHeightAppUnits;
-      nsViewManager* vm = mShell->GetViewManager();
+      nsRefPtr<nsViewManager> vm = shell->GetViewManager();
+      if (!vm) {
+        return;
+      }
       vm->GetWindowDimensions(&oldWidthAppUnits, &oldHeightAppUnits);
       float oldWidthDevPixels = oldWidthAppUnits/oldAppUnitsPerDevPixel;
       float oldHeightDevPixels = oldHeightAppUnits/oldAppUnitsPerDevPixel;
 
       nscoord width = NSToCoordRound(oldWidthDevPixels*AppUnitsPerDevPixel());
       nscoord height = NSToCoordRound(oldHeightDevPixels*AppUnitsPerDevPixel());
       vm->SetWindowDimensions(width, height);