diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 9d687807b643..47b5c905b790 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -4686,11 +4686,8 @@ MinimumFontSizeFor(nsPresContext* aPresContext, nscoord aContainerWidth) 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 )); diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index bf3be06df124..86be2cbe1ac5 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -209,7 +209,8 @@ destroy_loads(nsIFrame* aKey, nsRefPtr& aData, void* closure) nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType) : mType(aType), mDocument(aDocument), mMinFontSize(0), - mTextZoom(1.0), mFullZoom(1.0), mPageSize(-1, -1), mPPScale(1.0f), + mTextZoom(1.0), mFullZoom(1.0), mLastFontInflationScreenWidth(-1.0), + mPageSize(-1, -1), mPPScale(1.0f), mViewportStyleOverflow(NS_STYLE_OVERFLOW_AUTO, NS_STYLE_OVERFLOW_AUTO), mImageAnimationModePref(imgIContainer::kNormalAnimMode) { @@ -1412,6 +1413,34 @@ nsPresContext::SetFullZoom(float aZoom) mCurAppUnitsPerDevPixel = AppUnitsPerDevPixel(); } +float +nsPresContext::ScreenWidthInchesForFontInflation(bool* aChanged) +{ + if (aChanged) { + *aChanged = false; + } + + nsDeviceContext *dx = DeviceContext(); + nsRect clientRect; + dx->GetClientRect(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, diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 59108755842e..5945a87408b7 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -563,7 +563,18 @@ public: 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(); } @@ -1143,6 +1154,8 @@ protected: float mTextZoom; // Text zoom, defaults to 1.0 float mFullZoom; // Page zoom, defaults to 1.0 + float mLastFontInflationScreenWidth; + PRInt32 mCurAppUnitsPerDevPixel; PRInt32 mAutoQualityMinFontSizePixelsPref;