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) r=roc

--HG--
extra : transplant_source : %19%A1%9B%BC%FD_H%5C%60%BB%88%1E%F6%D1%D5%85%24%F7%26%1B
This commit is contained in:
L. David Baron 2012-05-05 15:25:45 +02:00
Родитель b4ff21d2cc
Коммит 87599f798d
3 изменённых файлов: 45 добавлений и 6 удалений

Просмотреть файл

@ -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 ));

Просмотреть файл

@ -209,7 +209,8 @@ destroy_loads(nsIFrame* aKey, nsRefPtr<nsImageLoader>& 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,

Просмотреть файл

@ -564,6 +564,17 @@ public:
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;