Permalink
Browse files

Bug 749186, Followup Patch 1: Cache font inflation settings in pres s…

…hell to prevent crash. [r=dbaron][a=blassey]
  • Loading branch information...
1 parent fca11ee commit 020cec1d6dc28f4eced2016261d1ef4214bf0541 Scott Johnson committed Jun 6, 2012
View
50 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<nsISupports> container = aPresContext->GetContainer();
- nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
- if (docShell) {
- nsCOMPtr<nsIContentViewer> cv;
- docShell->GetContentViewer(getter_AddRefs(cv));
- nsCOMPtr<nsIMarkupDocumentViewer> mudv = do_QueryInterface(cv);
- if (mudv) {
- nsTArray<nsCOMPtr<nsIMarkupDocumentViewer> > array;
- mudv->AppendSubtree(array);
- for (PRUint32 i = 0, iEnd = array.Length(); i < iEnd; ++i) {
- nsCOMPtr<nsIPresShell> shell;
- nsCOMPtr<nsIContentViewer> 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<nsISupports> container = aPresContext->GetContainer();
+ nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(container);
+ if (docShell) {
+ nsCOMPtr<nsIContentViewer> cv;
+ docShell->GetContentViewer(getter_AddRefs(cv));
+ nsCOMPtr<nsIMarkupDocumentViewer> mudv = do_QueryInterface(cv);
+ if (mudv) {
+ nsTArray<nsCOMPtr<nsIMarkupDocumentViewer> > array;
+ mudv->AppendSubtree(array);
+ for (PRUint32 i = 0, iEnd = array.Length(); i < iEnd; ++i) {
+ nsCOMPtr<nsIPresShell> shell;
+ nsCOMPtr<nsIContentViewer> 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);
+ }
}
}
}
View
24 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;
};
/**
View
13 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;
}
View
11 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();
+}
View
9 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;
View
3 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) {

0 comments on commit 020cec1

Please sign in to comment.