From 020cec1d6dc28f4eced2016261d1ef4214bf0541 Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Tue, 5 Jun 2012 23:28:21 -0500 Subject: [PATCH] Bug 749186, Followup Patch 1: Cache font inflation settings in pres shell to prevent crash. [r=dbaron][a=blassey] --- dom/base/nsDOMWindowUtils.cpp | 50 +++++++++++++------------- layout/base/nsIPresShell.h | 24 +++++++++++++ layout/base/nsLayoutUtils.cpp | 13 ++++--- layout/base/nsPresShell.cpp | 11 ++++++ layout/base/nsPresShell.h | 9 +++++ layout/generic/nsFontInflationData.cpp | 3 +- 6 files changed, 81 insertions(+), 29 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 141c8b133a06..c4ba0de2a601 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -289,30 +289,32 @@ static void DestroyNsRect(void* aObject, nsIAtom* aPropertyName, static void MaybeReflowForInflationScreenWidthChange(nsPresContext *aPresContext) { - if (aPresContext && - nsLayoutUtils::FontSizeInflationEnabled(aPresContext) && - nsLayoutUtils::FontSizeInflationMinTwips() != 0) { - bool changed; - aPresContext->ScreenWidthInchesForFontInflation(&changed); - if (changed) { - nsCOMPtr container = aPresContext->GetContainer(); - nsCOMPtr docShell = do_QueryInterface(container); - if (docShell) { - nsCOMPtr cv; - docShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr mudv = do_QueryInterface(cv); - if (mudv) { - nsTArray > array; - mudv->AppendSubtree(array); - for (PRUint32 i = 0, iEnd = array.Length(); i < iEnd; ++i) { - nsCOMPtr shell; - nsCOMPtr cv = do_QueryInterface(array[i]); - cv->GetPresShell(getter_AddRefs(shell)); - if (shell) { - nsIFrame *rootFrame = shell->GetRootFrame(); - if (rootFrame) { - shell->FrameNeedsReflow(rootFrame, nsIPresShell::eResize, - NS_FRAME_IS_DIRTY); + if (aPresContext) { + nsIPresShell* presShell = aPresContext->GetPresShell(); + if (presShell && nsLayoutUtils::FontSizeInflationEnabled(aPresContext) && + presShell->FontSizeInflationMinTwips() != 0) { + bool changed; + aPresContext->ScreenWidthInchesForFontInflation(&changed); + if (changed) { + nsCOMPtr container = aPresContext->GetContainer(); + nsCOMPtr docShell = do_QueryInterface(container); + if (docShell) { + nsCOMPtr cv; + docShell->GetContentViewer(getter_AddRefs(cv)); + nsCOMPtr mudv = do_QueryInterface(cv); + if (mudv) { + nsTArray > array; + mudv->AppendSubtree(array); + for (PRUint32 i = 0, iEnd = array.Length(); i < iEnd; ++i) { + nsCOMPtr shell; + nsCOMPtr cv = do_QueryInterface(array[i]); + cv->GetPresShell(getter_AddRefs(shell)); + if (shell) { + nsIFrame *rootFrame = shell->GetRootFrame(); + if (rootFrame) { + shell->FrameNeedsReflow(rootFrame, nsIPresShell::eResize, + NS_FRAME_IS_DIRTY); + } } } } diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index 512e77d974e1..1d1c9f346046 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -1224,7 +1224,24 @@ class nsIPresShell : public nsIPresShell_base size_t *aStyleSetsSize, size_t *aTextRunsSize) const = 0; + + /** + * Methods that retrieve the cached font inflation preferences. + */ + PRUint32 FontSizeInflationEmPerLine() const { + return mFontSizeInflationEmPerLine; + } + + PRUint32 FontSizeInflationMinTwips() const { + return mFontSizeInflationMinTwips; + } + + PRUint32 FontSizeInflationLineThreshold() const { + return mFontSizeInflationLineThreshold; + } + /** + * * Refresh observer management. */ protected: @@ -1347,6 +1364,13 @@ class nsIPresShell : public nsIPresShell_base nsSize mScrollPositionClampingScrollPortSize; static nsIContent* gKeyDownTarget; + + + // Cached font inflation values. This is done to prevent changing of font + // inflation until a page is reloaded. + PRUint32 mFontSizeInflationEmPerLine; + PRUint32 mFontSizeInflationMinTwips; + PRUint32 mFontSizeInflationLineThreshold; }; /** diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index a3ac33e1ffdd..15bf0ccad10b 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -4651,8 +4651,10 @@ nsReflowFrameRunnable::Run() static nscoord MinimumFontSizeFor(nsPresContext* aPresContext, nscoord aContainerWidth) { - PRUint32 emPerLine = nsLayoutUtils::FontSizeInflationEmPerLine(); - PRUint32 minTwips = nsLayoutUtils::FontSizeInflationMinTwips(); + nsIPresShell* presShell = aPresContext->PresShell(); + + PRUint32 emPerLine = presShell->FontSizeInflationEmPerLine(); + PRUint32 minTwips = presShell->FontSizeInflationMinTwips(); if (emPerLine == 0 && minTwips == 0) { return 0; } @@ -4799,8 +4801,11 @@ nsLayoutUtils::FontSizeInflationFor(const nsIFrame *aFrame) /* static */ bool nsLayoutUtils::FontSizeInflationEnabled(nsPresContext *aPresContext) { - if ((sFontSizeInflationEmPerLine == 0 && - sFontSizeInflationMinTwips == 0) || + nsIPresShell* presShell = aPresContext->GetPresShell(); + + if (!presShell || + (presShell->FontSizeInflationEmPerLine() == 0 && + presShell->FontSizeInflationMinTwips() == 0) || aPresContext->IsChrome()) { return false; } diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index e1cc3fccea31..61f9d3c17b76 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1020,6 +1020,9 @@ PresShell::Init(nsIDocument* aDocument, // Get our activeness from the docShell. QueryIsActive(); + // Setup our font inflation preferences. + SetupFontInflation(); + return NS_OK; } @@ -9176,3 +9179,11 @@ nsIPresShell::SetScrollPositionClampingScrollPortSize(nscoord aWidth, nscoord aH mScrollPositionClampingScrollPortSize.width = aWidth; mScrollPositionClampingScrollPortSize.height = aHeight; } + +void +PresShell::SetupFontInflation() +{ + mFontSizeInflationEmPerLine = nsLayoutUtils::FontSizeInflationEmPerLine(); + mFontSizeInflationMinTwips = nsLayoutUtils::FontSizeInflationMinTwips(); + mFontSizeInflationLineThreshold = nsLayoutUtils::FontSizeInflationLineThreshold(); +} diff --git a/layout/base/nsPresShell.h b/layout/base/nsPresShell.h index 465f2f8b4071..29a0c5a3b695 100644 --- a/layout/base/nsPresShell.h +++ b/layout/base/nsPresShell.h @@ -497,6 +497,15 @@ class PresShell : public nsIPresShell, ScrollAxis aHorizontal, PRUint32 aFlags); + /** + * Initialize cached font inflation preference values. + * + * @see nsLayoutUtils::sFontSizeInflationEmPerLine + * @see nsLayoutUtils::sFontSizeInflationMinTwips + * @see nsLayoutUtils::sFontSizeInflationLineThreshold + */ + void SetupFontInflation(); + friend struct AutoRenderingStateSaveRestore; friend struct RenderingState; diff --git a/layout/generic/nsFontInflationData.cpp b/layout/generic/nsFontInflationData.cpp index 0a629e2a19f8..9bb82c54bc32 100644 --- a/layout/generic/nsFontInflationData.cpp +++ b/layout/generic/nsFontInflationData.cpp @@ -226,7 +226,8 @@ nsFontInflationData::UpdateWidth(const nsHTMLReflowState &aReflowState) // See comment above "font.size.inflation.lineThreshold" in // modules/libpref/src/init/all.js . - PRUint32 lineThreshold = nsLayoutUtils::FontSizeInflationLineThreshold(); + nsIPresShell* presShell = bfc->PresContext()->PresShell(); + PRUint32 lineThreshold = presShell->FontSizeInflationLineThreshold(); nscoord newTextThreshold = (newNCAWidth * lineThreshold) / 100; if (mTextThreshold <= mTextAmount && mTextAmount < newTextThreshold) {