Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Bug 749186, Followup Patch 1: Cache font inflation settings in pres s…
Browse files Browse the repository at this point in the history
…hell to prevent crash. [r=dbaron][a=blassey]
  • Loading branch information
Scott Johnson committed Jun 6, 2012
1 parent fca11ee commit 020cec1
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 29 deletions.
50 changes: 26 additions & 24 deletions dom/base/nsDOMWindowUtils.cpp
Expand Up @@ -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);
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions layout/base/nsIPresShell.h
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
};

/**
Expand Down
13 changes: 9 additions & 4 deletions layout/base/nsLayoutUtils.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions layout/base/nsPresShell.cpp
Expand Up @@ -1020,6 +1020,9 @@ PresShell::Init(nsIDocument* aDocument,
// Get our activeness from the docShell.
QueryIsActive();

// Setup our font inflation preferences.
SetupFontInflation();

return NS_OK;
}

Expand Down Expand Up @@ -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();
}
9 changes: 9 additions & 0 deletions layout/base/nsPresShell.h
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion layout/generic/nsFontInflationData.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit 020cec1

Please sign in to comment.