From: L. David Baron Cache the last device width we used for font inflation on the pres context so that we can track when it changes. (Bug 747231, patch 2) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -4667,21 +4667,18 @@ MinimumFontSizeFor(nsPresContext* aPresC nscoord byLine = 0, byInch = 0; if (sFontSizeInflationEmPerLine != 0) { byLine = effectiveContainerWidth / sFontSizeInflationEmPerLine; } if (sFontSizeInflationMinTwips != 0) { // REVIEW: Is this giving us app units and sizes *not* counting // viewport scaling? - nsDeviceContext *dx = aPresContext->DeviceContext(); - nsRect clientRect; - dx->GetClientRect(clientRect); // FIXME: GetClientRect looks expensive float deviceWidthInches = - float(clientRect.width) / float(dx->AppUnitsPerPhysicalInch()); + aPresContext->ScreenWidthInchesForFontInflation(); byInch = NSToCoordRound(effectiveContainerWidth / (deviceWidthInches * 1440 / sFontSizeInflationMinTwips )); } return NS_MAX(byLine, byInch); } /* static */ float diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -204,17 +204,18 @@ destroy_loads(nsIFrame* aKey, nsRefPtrGetClientRect(clientRect); // FIXME: GetClientRect looks expensive + float deviceWidthInches = + float(clientRect.width) / float(dx->AppUnitsPerPhysicalInch()); + + if (deviceWidthInches != mLastFontInflationScreenWidth) { + if (mLastFontInflationScreenWidth != -1.0) { + if (aChanged) { + *aChanged = true; + } else { + NS_NOTREACHED("somebody should have checked for screen width change " + "and triggered a reflow"); + } + } + mLastFontInflationScreenWidth = deviceWidthInches; + } + + return deviceWidthInches; +} + void nsPresContext::SetImageLoaders(nsIFrame* aTargetFrame, ImageLoadType aType, nsImageLoader* aImageLoaders) { NS_ASSERTION(mShell || !aImageLoaders, "Shouldn't add new image loader after the shell is gone"); diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -558,17 +558,28 @@ public: } float GetFullZoom() { return mFullZoom; } void SetFullZoom(float aZoom); nscoord GetAutoQualityMinFontSize() { return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref); } - + + /** + * Return the device's screen width in inches, for font size + * inflation. + * + * Set |aChanged| to true if the result returned is different from a + * previous call to this method. If a caller passes |aChanged| as + * null, then something else must have already checked whether there + * was a change (by calling this method). + */ + float ScreenWidthInchesForFontInflation(bool* aChanged = nsnull); + static PRInt32 AppUnitsPerCSSPixel() { return nsDeviceContext::AppUnitsPerCSSPixel(); } PRUint32 AppUnitsPerDevPixel() const { return mDeviceContext->AppUnitsPerDevPixel(); } static PRInt32 AppUnitsPerCSSInch() { return nsDeviceContext::AppUnitsPerCSSInch(); } static nscoord CSSPixelsToAppUnits(PRInt32 aPixels) { return NSIntPixelsToAppUnits(aPixels, nsDeviceContext::AppUnitsPerCSSPixel()); } @@ -1141,16 +1152,18 @@ protected: nsWeakPtr mContainer; PRCList mDOMMediaQueryLists; PRInt32 mMinFontSize; // Min font size, defaults to 0 float mTextZoom; // Text zoom, defaults to 1.0 float mFullZoom; // Page zoom, defaults to 1.0 + float mLastFontInflationScreenWidth; + PRInt32 mCurAppUnitsPerDevPixel; PRInt32 mAutoQualityMinFontSizePixelsPref; nsCOMPtr mTheme; nsCOMPtr mLangService; nsCOMPtr mPrintSettings; nsCOMPtr mPrefChangedTimer;