Bug 1452080: Remove ComputedStyle::PresContext usage from layout and canvas code. r=xidorn

Couldn't find an easy way of splitting these up :(

MozReview-Commit-ID: 2kTZ5McREUT
This commit is contained in:
Emilio Cobos Álvarez
2018-04-06 14:52:12 +02:00
parent 19d1b6d206
commit 65978b31f3
20 changed files with 154 additions and 92 deletions

View File

@@ -4299,9 +4299,10 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
MOZ_ASSERT(!presShell->IsDestroying(), MOZ_ASSERT(!presShell->IsDestroying(),
"GetCurrentFontStyle() should have returned null if the presshell is being destroyed"); "GetCurrentFontStyle() should have returned null if the presshell is being destroyed");
nsPresContext* presContext = presShell->GetPresContext();
// ensure user font set is up to date // ensure user font set is up to date
currentFontStyle-> currentFontStyle->SetUserFontSet(presContext->GetUserFontSet());
SetUserFontSet(presShell->GetPresContext()->GetUserFontSet());
if (currentFontStyle->GetStyle()->size == 0.0F) { if (currentFontStyle->GetStyle()->size == 0.0F) {
if (aWidth) { if (aWidth) {
@@ -4320,6 +4321,7 @@ CanvasRenderingContext2D::DrawOrMeasureText(const nsAString& aRawText,
// (for now, at least; perhaps we need new Canvas API to control this). // (for now, at least; perhaps we need new Canvas API to control this).
processor.mTextRunFlags = canvasStyle processor.mTextRunFlags = canvasStyle
? nsLayoutUtils::GetTextRunFlagsForStyle(canvasStyle, ? nsLayoutUtils::GetTextRunFlagsForStyle(canvasStyle,
presContext,
canvasStyle->StyleFont(), canvasStyle->StyleFont(),
canvasStyle->StyleText(), canvasStyle->StyleText(),
0) 0)

View File

@@ -270,10 +270,16 @@ SVGContentUtils::GetStrokeWidth(nsSVGElement* aElement,
} }
float float
SVGContentUtils::GetFontSize(Element *aElement) SVGContentUtils::GetFontSize(Element* aElement)
{ {
if (!aElement) if (!aElement) {
return 1.0f; return 1.0f;
}
nsPresContext* pc = nsContentUtils::GetContextForContent(aElement);
if (!pc) {
return 1.0f;
}
RefPtr<ComputedStyle> computedStyle = RefPtr<ComputedStyle> computedStyle =
nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr); nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
@@ -283,63 +289,66 @@ SVGContentUtils::GetFontSize(Element *aElement)
return 1.0f; return 1.0f;
} }
return GetFontSize(computedStyle); return GetFontSize(computedStyle, pc);
} }
float float
SVGContentUtils::GetFontSize(nsIFrame *aFrame) SVGContentUtils::GetFontSize(nsIFrame* aFrame)
{ {
MOZ_ASSERT(aFrame, "NULL frame in GetFontSize"); MOZ_ASSERT(aFrame, "NULL frame in GetFontSize");
return GetFontSize(aFrame->Style()); return GetFontSize(aFrame->Style(), aFrame->PresContext());
} }
float float
SVGContentUtils::GetFontSize(ComputedStyle *aComputedStyle) SVGContentUtils::GetFontSize(ComputedStyle* aComputedStyle,
nsPresContext* aPresContext)
{ {
MOZ_ASSERT(aComputedStyle, "NULL ComputedStyle in GetFontSize"); MOZ_ASSERT(aComputedStyle);
MOZ_ASSERT(aPresContext);
nsPresContext *presContext = aComputedStyle->PresContext();
MOZ_ASSERT(presContext, "NULL pres context in GetFontSize");
nscoord fontSize = aComputedStyle->StyleFont()->mSize; nscoord fontSize = aComputedStyle->StyleFont()->mSize;
return nsPresContext::AppUnitsToFloatCSSPixels(fontSize) / return nsPresContext::AppUnitsToFloatCSSPixels(fontSize) /
presContext->EffectiveTextZoom(); aPresContext->EffectiveTextZoom();
} }
float float
SVGContentUtils::GetFontXHeight(Element *aElement) SVGContentUtils::GetFontXHeight(Element* aElement)
{ {
if (!aElement) if (!aElement) {
return 1.0f; return 1.0f;
}
RefPtr<ComputedStyle> computedStyle = nsPresContext* pc = nsContentUtils::GetContextForContent(aElement);
if (!pc) {
return 1.0f;
}
RefPtr<ComputedStyle> style =
nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr); nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
if (!computedStyle) { if (!style) {
// ReportToConsole // ReportToConsole
NS_WARNING("Couldn't get ComputedStyle for content in GetFontStyle"); NS_WARNING("Couldn't get ComputedStyle for content in GetFontStyle");
return 1.0f; return 1.0f;
} }
return GetFontXHeight(computedStyle); return GetFontXHeight(style, pc);
} }
float float
SVGContentUtils::GetFontXHeight(nsIFrame *aFrame) SVGContentUtils::GetFontXHeight(nsIFrame *aFrame)
{ {
MOZ_ASSERT(aFrame, "NULL frame in GetFontXHeight"); MOZ_ASSERT(aFrame, "NULL frame in GetFontXHeight");
return GetFontXHeight(aFrame->Style()); return GetFontXHeight(aFrame->Style(), aFrame->PresContext());
} }
float float
SVGContentUtils::GetFontXHeight(ComputedStyle *aComputedStyle) SVGContentUtils::GetFontXHeight(ComputedStyle* aComputedStyle,
nsPresContext* aPresContext)
{ {
MOZ_ASSERT(aComputedStyle, "NULL ComputedStyle in GetFontXHeight"); MOZ_ASSERT(aComputedStyle && aPresContext);
nsPresContext *presContext = aComputedStyle->PresContext();
MOZ_ASSERT(presContext, "NULL pres context in GetFontXHeight");
RefPtr<nsFontMetrics> fontMetrics = RefPtr<nsFontMetrics> fontMetrics =
nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle); nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle, aPresContext);
if (!fontMetrics) { if (!fontMetrics) {
// ReportToConsole // ReportToConsole
@@ -349,7 +358,7 @@ SVGContentUtils::GetFontXHeight(ComputedStyle *aComputedStyle)
nscoord xHeight = fontMetrics->XHeight(); nscoord xHeight = fontMetrics->XHeight();
return nsPresContext::AppUnitsToFloatCSSPixels(xHeight) / return nsPresContext::AppUnitsToFloatCSSPixels(xHeight) /
presContext->EffectiveTextZoom(); aPresContext->EffectiveTextZoom();
} }
nsresult nsresult
SVGContentUtils::ReportToConsole(nsIDocument* doc, SVGContentUtils::ReportToConsole(nsIDocument* doc,

View File

@@ -20,6 +20,7 @@
class nsIContent; class nsIContent;
class nsIDocument; class nsIDocument;
class nsIFrame; class nsIFrame;
class nsPresContext;
class nsStyleCoord; class nsStyleCoord;
class nsSVGElement; class nsSVGElement;
@@ -180,9 +181,9 @@ public:
* XXX document the conditions under which these may fail, and what they * XXX document the conditions under which these may fail, and what they
* return in those cases. * return in those cases.
*/ */
static float GetFontSize(mozilla::dom::Element *aElement); static float GetFontSize(mozilla::dom::Element* aElement);
static float GetFontSize(nsIFrame *aFrame); static float GetFontSize(nsIFrame* aFrame);
static float GetFontSize(ComputedStyle *aComputedStyle); static float GetFontSize(ComputedStyle*, nsPresContext*);
/* /*
* Get the number of CSS px (user units) per ex (i.e. the x-height in user * Get the number of CSS px (user units) per ex (i.e. the x-height in user
* units) for an nsIContent * units) for an nsIContent
@@ -190,9 +191,9 @@ public:
* XXX document the conditions under which these may fail, and what they * XXX document the conditions under which these may fail, and what they
* return in those cases. * return in those cases.
*/ */
static float GetFontXHeight(mozilla::dom::Element *aElement); static float GetFontXHeight(mozilla::dom::Element* aElement);
static float GetFontXHeight(nsIFrame *aFrame); static float GetFontXHeight(nsIFrame* aFrame);
static float GetFontXHeight(ComputedStyle *aComputedStyle); static float GetFontXHeight(ComputedStyle*, nsPresContext*);
/* /*
* Report a localized error message to the error console. * Report a localized error message to the error console.

View File

@@ -4423,8 +4423,7 @@ const nsCSSFrameConstructor::FrameConstructionData*
nsCSSFrameConstructor::FindXULMenubarData(Element* aElement, nsCSSFrameConstructor::FindXULMenubarData(Element* aElement,
ComputedStyle* aComputedStyle) ComputedStyle* aComputedStyle)
{ {
nsCOMPtr<nsIDocShell> treeItem = nsCOMPtr<nsIDocShell> treeItem = aElement->OwnerDoc()->GetDocShell();
aComputedStyle->PresContext()->GetDocShell();
if (treeItem && nsIDocShellTreeItem::typeChrome == treeItem->ItemType()) { if (treeItem && nsIDocShellTreeItem::typeChrome == treeItem->ItemType()) {
nsCOMPtr<nsIDocShellTreeItem> parent; nsCOMPtr<nsIDocShellTreeItem> parent;
treeItem->GetParent(getter_AddRefs(parent)); treeItem->GetParent(getter_AddRefs(parent));

View File

@@ -4695,16 +4695,16 @@ nsLayoutUtils::GetFontMetricsForFrame(const nsIFrame* aFrame, float aInflation)
variantWidth = NS_FONT_VARIANT_WIDTH_QUARTER; variantWidth = NS_FONT_VARIANT_WIDTH_QUARTER;
} }
} }
return GetFontMetricsForComputedStyle(computedStyle, aInflation, variantWidth); return GetFontMetricsForComputedStyle(computedStyle, aFrame->PresContext(),
aInflation, variantWidth);
} }
already_AddRefed<nsFontMetrics> already_AddRefed<nsFontMetrics>
nsLayoutUtils::GetFontMetricsForComputedStyle(ComputedStyle* aComputedStyle, nsLayoutUtils::GetFontMetricsForComputedStyle(ComputedStyle* aComputedStyle,
float aInflation, nsPresContext* aPresContext,
uint8_t aVariantWidth) float aInflation,
uint8_t aVariantWidth)
{ {
nsPresContext* pc = aComputedStyle->PresContext();
WritingMode wm(aComputedStyle); WritingMode wm(aComputedStyle);
const nsStyleFont* styleFont = aComputedStyle->StyleFont(); const nsStyleFont* styleFont = aComputedStyle->StyleFont();
nsFontMetrics::Params params; nsFontMetrics::Params params;
@@ -4715,8 +4715,8 @@ nsLayoutUtils::GetFontMetricsForComputedStyle(ComputedStyle* aComputedStyle,
: gfxFont::eHorizontal; : gfxFont::eHorizontal;
// pass the user font set object into the device context to // pass the user font set object into the device context to
// pass along to CreateFontGroup // pass along to CreateFontGroup
params.userFontSet = pc->GetUserFontSet(); params.userFontSet = aPresContext->GetUserFontSet();
params.textPerf = pc->GetTextPerfMetrics(); params.textPerf = aPresContext->GetTextPerfMetrics();
// When aInflation is 1.0 and we don't require width variant, avoid // When aInflation is 1.0 and we don't require width variant, avoid
// making a local copy of the nsFont. // making a local copy of the nsFont.
@@ -4724,13 +4724,13 @@ nsLayoutUtils::GetFontMetricsForComputedStyle(ComputedStyle* aComputedStyle,
// which would be lossy. Fortunately, in such cases, aInflation is // which would be lossy. Fortunately, in such cases, aInflation is
// guaranteed to be 1.0f. // guaranteed to be 1.0f.
if (aInflation == 1.0f && aVariantWidth == NS_FONT_VARIANT_WIDTH_NORMAL) { if (aInflation == 1.0f && aVariantWidth == NS_FONT_VARIANT_WIDTH_NORMAL) {
return pc->DeviceContext()->GetMetricsFor(styleFont->mFont, params); return aPresContext->DeviceContext()->GetMetricsFor(styleFont->mFont, params);
} }
nsFont font = styleFont->mFont; nsFont font = styleFont->mFont;
font.size = NSToCoordRound(font.size * aInflation); font.size = NSToCoordRound(font.size * aInflation);
font.variantWidth = aVariantWidth; font.variantWidth = aVariantWidth;
return pc->DeviceContext()->GetMetricsFor(font, params); return aPresContext->DeviceContext()->GetMetricsFor(font, params);
} }
nsIFrame* nsIFrame*
@@ -7521,6 +7521,7 @@ nsLayoutUtils::GetReferenceFrame(nsIFrame* aFrame)
/* static */ gfx::ShapedTextFlags /* static */ gfx::ShapedTextFlags
nsLayoutUtils::GetTextRunFlagsForStyle(ComputedStyle* aComputedStyle, nsLayoutUtils::GetTextRunFlagsForStyle(ComputedStyle* aComputedStyle,
nsPresContext* aPresContext,
const nsStyleFont* aStyleFont, const nsStyleFont* aStyleFont,
const nsStyleText* aStyleText, const nsStyleText* aStyleText,
nscoord aLetterSpacing) nscoord aLetterSpacing)
@@ -7538,8 +7539,7 @@ nsLayoutUtils::GetTextRunFlagsForStyle(ComputedStyle* aComputedStyle,
result |= gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED; result |= gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED;
break; break;
case NS_STYLE_TEXT_RENDERING_AUTO: case NS_STYLE_TEXT_RENDERING_AUTO:
if (aStyleFont->mFont.size < if (aStyleFont->mFont.size < aPresContext->GetAutoQualityMinFontSize()) {
aComputedStyle->PresContext()->GetAutoQualityMinFontSize()) {
result |= gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED; result |= gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED;
} }
break; break;

View File

@@ -1303,6 +1303,7 @@ public:
*/ */
static already_AddRefed<nsFontMetrics> GetFontMetricsForComputedStyle( static already_AddRefed<nsFontMetrics> GetFontMetricsForComputedStyle(
ComputedStyle* aComputedStyle, ComputedStyle* aComputedStyle,
nsPresContext* aPresContext,
float aSizeInflation = 1.0f, float aSizeInflation = 1.0f,
uint8_t aVariantWidth = NS_FONT_VARIANT_WIDTH_NORMAL); uint8_t aVariantWidth = NS_FONT_VARIANT_WIDTH_NORMAL);
@@ -1315,9 +1316,12 @@ public:
*/ */
static already_AddRefed<nsFontMetrics> GetFontMetricsOfEmphasisMarks( static already_AddRefed<nsFontMetrics> GetFontMetricsOfEmphasisMarks(
ComputedStyle* aComputedStyle, ComputedStyle* aComputedStyle,
nsPresContext* aPresContext,
float aInflation) float aInflation)
{ {
return GetFontMetricsForComputedStyle(aComputedStyle, aInflation * 0.5f); return GetFontMetricsForComputedStyle(aComputedStyle,
aPresContext,
aInflation * 0.5f);
} }
/** /**
@@ -2066,6 +2070,7 @@ public:
*/ */
static mozilla::gfx::ShapedTextFlags static mozilla::gfx::ShapedTextFlags
GetTextRunFlagsForStyle(ComputedStyle* aComputedStyle, GetTextRunFlagsForStyle(ComputedStyle* aComputedStyle,
nsPresContext* aPresContext,
const nsStyleFont* aStyleFont, const nsStyleFont* aStyleFont,
const nsStyleText* aStyleText, const nsStyleText* aStyleText,
nscoord aLetterSpacing); nscoord aLetterSpacing);

View File

@@ -175,8 +175,11 @@ nsTextControlFrame::CalcIntrinsicSize(gfxContext* aRenderingContext,
nsLayoutUtils::GetFontMetricsForFrame(this, aFontSizeInflation); nsLayoutUtils::GetFontMetricsForFrame(this, aFontSizeInflation);
lineHeight = lineHeight =
ReflowInput::CalcLineHeight(GetContent(), Style(), ReflowInput::CalcLineHeight(GetContent(),
NS_AUTOHEIGHT, aFontSizeInflation); Style(),
PresContext(),
NS_AUTOHEIGHT,
aFontSizeInflation);
charWidth = fontMet->AveCharWidth(); charWidth = fontMet->AveCharWidth();
charMaxAdvance = fontMet->MaxAdvance(); charMaxAdvance = fontMet->MaxAdvance();
@@ -633,8 +636,11 @@ nsTextControlFrame::Reflow(nsPresContext* aPresContext,
nscoord lineHeight = aReflowInput.ComputedBSize(); nscoord lineHeight = aReflowInput.ComputedBSize();
float inflation = nsLayoutUtils::FontSizeInflationFor(this); float inflation = nsLayoutUtils::FontSizeInflationFor(this);
if (!IsSingleLineTextControl()) { if (!IsSingleLineTextControl()) {
lineHeight = ReflowInput::CalcLineHeight(GetContent(), Style(), lineHeight = ReflowInput::CalcLineHeight(GetContent(),
NS_AUTOHEIGHT, inflation); Style(),
PresContext(),
NS_AUTOHEIGHT,
inflation);
} }
RefPtr<nsFontMetrics> fontMet = RefPtr<nsFontMetrics> fontMet =
nsLayoutUtils::GetFontMetricsForFrame(this, inflation); nsLayoutUtils::GetFontMetricsForFrame(this, inflation);

View File

@@ -2850,6 +2850,7 @@ GetNormalLineHeight(nsFontMetrics* aFontMetrics)
static inline nscoord static inline nscoord
ComputeLineHeight(ComputedStyle* aComputedStyle, ComputeLineHeight(ComputedStyle* aComputedStyle,
nsPresContext* aPresContext,
nscoord aBlockBSize, nscoord aBlockBSize,
float aFontSizeInflation) float aFontSizeInflation)
{ {
@@ -2883,7 +2884,7 @@ ComputeLineHeight(ComputedStyle* aComputedStyle,
} }
RefPtr<nsFontMetrics> fm = nsLayoutUtils:: RefPtr<nsFontMetrics> fm = nsLayoutUtils::
GetFontMetricsForComputedStyle(aComputedStyle, aFontSizeInflation); GetFontMetricsForComputedStyle(aComputedStyle, aPresContext, aFontSizeInflation);
return GetNormalLineHeight(fm); return GetNormalLineHeight(fm);
} }
@@ -2894,20 +2895,27 @@ ReflowInput::CalcLineHeight() const
nsLayoutUtils::IsNonWrapperBlock(mFrame) ? ComputedBSize() : nsLayoutUtils::IsNonWrapperBlock(mFrame) ? ComputedBSize() :
(mCBReflowInput ? mCBReflowInput->ComputedBSize() : NS_AUTOHEIGHT); (mCBReflowInput ? mCBReflowInput->ComputedBSize() : NS_AUTOHEIGHT);
return CalcLineHeight(mFrame->GetContent(), mFrame->Style(), blockBSize, return CalcLineHeight(mFrame->GetContent(),
mFrame->Style(),
mFrame->PresContext(),
blockBSize,
nsLayoutUtils::FontSizeInflationFor(mFrame)); nsLayoutUtils::FontSizeInflationFor(mFrame));
} }
/* static */ nscoord /* static */ nscoord
ReflowInput::CalcLineHeight(nsIContent* aContent, ReflowInput::CalcLineHeight(nsIContent* aContent,
ComputedStyle* aComputedStyle, ComputedStyle* aComputedStyle,
nscoord aBlockBSize, nsPresContext* aPresContext,
float aFontSizeInflation) nscoord aBlockBSize,
float aFontSizeInflation)
{ {
NS_PRECONDITION(aComputedStyle, "Must have a ComputedStyle"); NS_PRECONDITION(aComputedStyle, "Must have a ComputedStyle");
nscoord lineHeight = nscoord lineHeight =
ComputeLineHeight(aComputedStyle, aBlockBSize, aFontSizeInflation); ComputeLineHeight(aComputedStyle,
aPresContext,
aBlockBSize,
aFontSizeInflation);
NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up"); NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");

View File

@@ -771,6 +771,7 @@ public:
*/ */
static nscoord CalcLineHeight(nsIContent* aContent, static nscoord CalcLineHeight(nsIContent* aContent,
ComputedStyle* aComputedStyle, ComputedStyle* aComputedStyle,
nsPresContext* aPresContext,
nscoord aBlockBSize, nscoord aBlockBSize,
float aFontSizeInflation); float aFontSizeInflation);

View File

@@ -530,8 +530,11 @@ nsBlockFrame::GetCaretBaseline() const
RefPtr<nsFontMetrics> fm = RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForFrame(this, inflation); nsLayoutUtils::GetFontMetricsForFrame(this, inflation);
nscoord lineHeight = nscoord lineHeight =
ReflowInput::CalcLineHeight(GetContent(), Style(), ReflowInput::CalcLineHeight(GetContent(),
contentRect.height, inflation); Style(),
PresContext(),
contentRect.height,
inflation);
const WritingMode wm = GetWritingMode(); const WritingMode wm = GetWritingMode();
return nsLayoutUtils::GetCenteredFontBaseline(fm, lineHeight, return nsLayoutUtils::GetCenteredFontBaseline(fm, lineHeight,
wm.IsLineInverted()) + bp.top; wm.IsLineInverted()) + bp.top;

View File

@@ -487,7 +487,7 @@ nsImageFrame::ShouldCreateImageFrameFor(Element* aElement,
// text). // text).
useSizedBox = true; useSizedBox = true;
} }
else if (aComputedStyle->PresContext()->CompatibilityMode() != else if (aElement->OwnerDoc()->GetCompatibilityMode() !=
eCompatibility_NavQuirks) { eCompatibility_NavQuirks) {
useSizedBox = false; useSizedBox = false;
} }

View File

@@ -1662,8 +1662,10 @@ nsLineLayout::PlaceTopBottomFrames(PerSpanData* psd,
static nscoord static nscoord
GetBSizeOfEmphasisMarks(nsIFrame* aSpanFrame, float aInflation) GetBSizeOfEmphasisMarks(nsIFrame* aSpanFrame, float aInflation)
{ {
RefPtr<nsFontMetrics> fm = nsLayoutUtils:: RefPtr<nsFontMetrics> fm =
GetFontMetricsOfEmphasisMarks(aSpanFrame->Style(), aInflation); nsLayoutUtils::GetFontMetricsOfEmphasisMarks(aSpanFrame->Style(),
aSpanFrame->PresContext(),
aInflation);
return fm->MaxHeight(); return fm->MaxHeight();
} }
@@ -1884,10 +1886,12 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
// compute the top leading. // compute the top leading.
float inflation = float inflation =
GetInflationForBlockDirAlignment(spanFrame, mInflationMinFontSize); GetInflationForBlockDirAlignment(spanFrame, mInflationMinFontSize);
nscoord logicalBSize = ReflowInput:: nscoord logicalBSize =
CalcLineHeight(spanFrame->GetContent(), spanFrame->Style(), ReflowInput::CalcLineHeight(spanFrame->GetContent(),
mBlockReflowInput->ComputedHeight(), spanFrame->Style(),
inflation); spanFrame->PresContext(),
mBlockReflowInput->ComputedHeight(),
inflation);
nscoord contentBSize = spanFramePFD->mBounds.BSize(lineWM) - nscoord contentBSize = spanFramePFD->mBounds.BSize(lineWM) -
spanFramePFD->mBorderPadding.BStartEnd(lineWM); spanFramePFD->mBorderPadding.BStartEnd(lineWM);
@@ -2173,8 +2177,11 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
// of the elements line block size value. // of the elements line block size value.
float inflation = float inflation =
GetInflationForBlockDirAlignment(frame, mInflationMinFontSize); GetInflationForBlockDirAlignment(frame, mInflationMinFontSize);
pctBasis = ReflowInput::CalcLineHeight(frame->GetContent(), pctBasis = ReflowInput::CalcLineHeight(
frame->Style(), mBlockReflowInput->ComputedBSize(), frame->GetContent(),
frame->Style(),
frame->PresContext(),
mBlockReflowInput->ComputedBSize(),
inflation); inflation);
} }
nscoord offset = verticalAlign.ComputeCoordPercentCalc(pctBasis); nscoord offset = verticalAlign.ComputeCoordPercentCalc(pctBasis);

View File

@@ -1897,6 +1897,9 @@ BuildTextRunsScanner::ContinueTextRunAcrossFrames(nsTextFrame* aFrame1, nsTextFr
if (sc1 == sc2) if (sc1 == sc2)
return true; return true;
nsPresContext* pc = aFrame1->PresContext();
MOZ_ASSERT(pc == aFrame2->PresContext());
const nsStyleFont* fontStyle1 = sc1->StyleFont(); const nsStyleFont* fontStyle1 = sc1->StyleFont();
const nsStyleFont* fontStyle2 = sc2->StyleFont(); const nsStyleFont* fontStyle2 = sc2->StyleFont();
nscoord letterSpacing1 = LetterSpacing(aFrame1); nscoord letterSpacing1 = LetterSpacing(aFrame1);
@@ -1904,8 +1907,8 @@ BuildTextRunsScanner::ContinueTextRunAcrossFrames(nsTextFrame* aFrame1, nsTextFr
return fontStyle1->mFont == fontStyle2->mFont && return fontStyle1->mFont == fontStyle2->mFont &&
fontStyle1->mLanguage == fontStyle2->mLanguage && fontStyle1->mLanguage == fontStyle2->mLanguage &&
textStyle1->mTextTransform == textStyle2->mTextTransform && textStyle1->mTextTransform == textStyle2->mTextTransform &&
nsLayoutUtils::GetTextRunFlagsForStyle(sc1, fontStyle1, textStyle1, letterSpacing1) == nsLayoutUtils::GetTextRunFlagsForStyle(sc1, pc, fontStyle1, textStyle1, letterSpacing1) ==
nsLayoutUtils::GetTextRunFlagsForStyle(sc2, fontStyle2, textStyle2, letterSpacing2); nsLayoutUtils::GetTextRunFlagsForStyle(sc2, pc, fontStyle2, textStyle2, letterSpacing2);
} }
void BuildTextRunsScanner::ScanFrame(nsIFrame* aFrame) void BuildTextRunsScanner::ScanFrame(nsIFrame* aFrame)
@@ -2300,7 +2303,8 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer)
// frame's style is used, so we use a mixture of the first frame and // frame's style is used, so we use a mixture of the first frame and
// last frame's style // last frame's style
flags |= nsLayoutUtils::GetTextRunFlagsForStyle(lastComputedStyle, flags |= nsLayoutUtils::GetTextRunFlagsForStyle(lastComputedStyle,
fontStyle, textStyle, LetterSpacing(firstFrame, textStyle)); firstFrame->PresContext(), fontStyle, textStyle,
LetterSpacing(firstFrame, textStyle));
// XXX this is a bit of a hack. For performance reasons, if we're favouring // XXX this is a bit of a hack. For performance reasons, if we're favouring
// performance over quality, don't try to get accurate glyph extents. // performance over quality, don't try to get accurate glyph extents.
if (!(flags & gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED)) { if (!(flags & gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED)) {
@@ -2349,7 +2353,7 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer)
// want to create new nsTransformedCharStyle for them anyway. // want to create new nsTransformedCharStyle for them anyway.
if (sc != f->Style() || sc->IsTextCombined()) { if (sc != f->Style() || sc->IsTextCombined()) {
sc = f->Style(); sc = f->Style();
charStyle = new nsTransformedCharStyle(sc); charStyle = new nsTransformedCharStyle(sc, f->PresContext());
if (sc->IsTextCombined() && f->CountGraphemeClusters() > 1) { if (sc->IsTextCombined() && f->CountGraphemeClusters() > 1) {
charStyle->mForceNonFullWidth = true; charStyle->mForceNonFullWidth = true;
} }
@@ -5555,8 +5559,10 @@ nsTextFrame::UpdateTextEmphasis(WritingMode aWM, PropertyProvider& aProvider)
if (isTextCombined) { if (isTextCombined) {
computedStyle = GetParent()->Style(); computedStyle = GetParent()->Style();
} }
RefPtr<nsFontMetrics> fm = nsLayoutUtils:: RefPtr<nsFontMetrics> fm =
GetFontMetricsOfEmphasisMarks(computedStyle, GetFontSizeInflation()); nsLayoutUtils::GetFontMetricsOfEmphasisMarks(computedStyle,
PresContext(),
GetFontSizeInflation());
EmphasisMarkInfo* info = new EmphasisMarkInfo; EmphasisMarkInfo* info = new EmphasisMarkInfo;
info->textRun = info->textRun =
GenerateTextRunForEmphasisMarks(this, fm, computedStyle, styleText); GenerateTextRunForEmphasisMarks(this, fm, computedStyle, styleText);
@@ -5787,8 +5793,10 @@ nsTextFrame::ComputeDescentLimitForSelectionUnderline(
gfxFloat app = aPresContext->AppUnitsPerDevPixel(); gfxFloat app = aPresContext->AppUnitsPerDevPixel();
nscoord lineHeightApp = nscoord lineHeightApp =
ReflowInput::CalcLineHeight(GetContent(), ReflowInput::CalcLineHeight(GetContent(),
Style(), NS_AUTOHEIGHT, Style(),
GetFontSizeInflation()); PresContext(),
NS_AUTOHEIGHT,
GetFontSizeInflation());
gfxFloat lineHeight = gfxFloat(lineHeightApp) / app; gfxFloat lineHeight = gfxFloat(lineHeightApp) / app;
if (lineHeight <= aFontMetrics.maxHeight) { if (lineHeight <= aFontMetrics.maxHeight) {
return aFontMetrics.maxDescent; return aFontMetrics.maxDescent;

View File

@@ -12,24 +12,26 @@
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "gfxTextRun.h" #include "gfxTextRun.h"
#include "mozilla/ComputedStyle.h" #include "mozilla/ComputedStyle.h"
#include "nsPresContext.h"
class nsTransformedTextRun; class nsTransformedTextRun;
struct nsTransformedCharStyle final { struct nsTransformedCharStyle final {
NS_INLINE_DECL_REFCOUNTING(nsTransformedCharStyle) NS_INLINE_DECL_REFCOUNTING(nsTransformedCharStyle)
explicit nsTransformedCharStyle(mozilla::ComputedStyle* aStyle) explicit nsTransformedCharStyle(mozilla::ComputedStyle* aStyle,
nsPresContext* aPresContext)
: mFont(aStyle->StyleFont()->mFont) : mFont(aStyle->StyleFont()->mFont)
, mLanguage(aStyle->StyleFont()->mLanguage) , mLanguage(aStyle->StyleFont()->mLanguage)
, mPresContext(aStyle->PresContext()) , mPresContext(aPresContext)
, mScriptSizeMultiplier(aStyle->StyleFont()->mScriptSizeMultiplier) , mScriptSizeMultiplier(aStyle->StyleFont()->mScriptSizeMultiplier)
, mTextTransform(aStyle->StyleText()->mTextTransform) , mTextTransform(aStyle->StyleText()->mTextTransform)
, mMathVariant(aStyle->StyleFont()->mMathVariant) , mMathVariant(aStyle->StyleFont()->mMathVariant)
, mExplicitLanguage(aStyle->StyleFont()->mExplicitLanguage) {} , mExplicitLanguage(aStyle->StyleFont()->mExplicitLanguage) {}
nsFont mFont; nsFont mFont;
RefPtr<nsAtom> mLanguage; RefPtr<nsAtom> mLanguage;
RefPtr<nsPresContext> mPresContext; RefPtr<nsPresContext> mPresContext;
float mScriptSizeMultiplier; float mScriptSizeMultiplier;
uint8_t mTextTransform; uint8_t mTextTransform;
uint8_t mMathVariant; uint8_t mMathVariant;

View File

@@ -231,7 +231,9 @@ nsMathMLFrame::CalcLength(nsPresContext* aPresContext,
else if (eCSSUnit_XHeight == unit) { else if (eCSSUnit_XHeight == unit) {
aPresContext->SetUsesExChUnits(true); aPresContext->SetUsesExChUnits(true);
RefPtr<nsFontMetrics> fm = nsLayoutUtils:: RefPtr<nsFontMetrics> fm = nsLayoutUtils::
GetFontMetricsForComputedStyle(aComputedStyle, aFontSizeInflation); GetFontMetricsForComputedStyle(aComputedStyle,
aPresContext,
aFontSizeInflation);
nscoord xHeight = fm->XHeight(); nscoord xHeight = fm->XHeight();
return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight); return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight);
} }

View File

@@ -5636,9 +5636,13 @@ nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)
} }
} }
nsPresContext* presContext = mPresShell->GetPresContext();
// lie about font size inflation since we lie about font size (since // lie about font size inflation since we lie about font size (since
// the inflation only applies to text) // the inflation only applies to text)
aCoord = ReflowInput::CalcLineHeight(mContent, mComputedStyle, aCoord = ReflowInput::CalcLineHeight(mContent,
mComputedStyle,
presContext,
blockHeight, 1.0f); blockHeight, 1.0f);
// CalcLineHeight uses font->mFont.size, but we want to use // CalcLineHeight uses font->mFont.size, but we want to use
@@ -5647,7 +5651,7 @@ nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)
const nsStyleFont* font = StyleFont(); const nsStyleFont* font = StyleFont();
float fCoord = float(aCoord); float fCoord = float(aCoord);
if (font->mAllowZoom) { if (font->mAllowZoom) {
fCoord /= mPresShell->GetPresContext()->EffectiveTextZoom(); fCoord /= presContext->EffectiveTextZoom();
} }
if (font->mFont.size != font->mSize) { if (font->mFont.size != font->mSize) {
fCoord = fCoord * (float(font->mSize) / float(font->mFont.size)); fCoord = fCoord * (float(font->mSize) / float(font->mFont.size));

View File

@@ -18,6 +18,7 @@ using namespace mozilla;
static bool static bool
ComputedStyleContainsFont(ComputedStyle* aComputedStyle, ComputedStyleContainsFont(ComputedStyle* aComputedStyle,
nsPresContext* aPresContext,
const gfxUserFontSet* aUserFontSet, const gfxUserFontSet* aUserFontSet,
const gfxUserFontEntry* aFont) const gfxUserFontEntry* aFont)
{ {
@@ -38,7 +39,9 @@ ComputedStyleContainsFont(ComputedStyle* aComputedStyle,
// family name is in the fontlist, check to see if the font group // family name is in the fontlist, check to see if the font group
// associated with the frame includes the specific userfont // associated with the frame includes the specific userfont
RefPtr<nsFontMetrics> fm = RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle, 1.0f); nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle,
aPresContext,
1.0f);
if (fm->GetThebesFontGroup()->ContainsUserFont(aFont)) { if (fm->GetThebesFontGroup()->ContainsUserFont(aFont)) {
return true; return true;
@@ -51,8 +54,9 @@ static bool
FrameUsesFont(nsIFrame* aFrame, const gfxUserFontEntry* aFont) FrameUsesFont(nsIFrame* aFrame, const gfxUserFontEntry* aFont)
{ {
// check the style of the frame // check the style of the frame
gfxUserFontSet* ufs = aFrame->PresContext()->GetUserFontSet(); nsPresContext* pc = aFrame->PresContext();
if (ComputedStyleContainsFont(aFrame->Style(), ufs, aFont)) { gfxUserFontSet* ufs = pc->GetUserFontSet();
if (ComputedStyleContainsFont(aFrame->Style(), pc, ufs, aFont)) {
return true; return true;
} }
@@ -61,7 +65,7 @@ FrameUsesFont(nsIFrame* aFrame, const gfxUserFontEntry* aFont)
for (ComputedStyle* extraContext; for (ComputedStyle* extraContext;
(extraContext = aFrame->GetAdditionalComputedStyle(contextIndex)); (extraContext = aFrame->GetAdditionalComputedStyle(contextIndex));
++contextIndex) { ++contextIndex) {
if (ComputedStyleContainsFont(extraContext, ufs, aFont)) { if (ComputedStyleContainsFont(extraContext, pc, ufs, aFont)) {
return true; return true;
} }
} }

View File

@@ -67,7 +67,7 @@ NS_IMPL_FRAMEARENA_HELPERS(nsSVGOuterSVGFrame)
nsSVGOuterSVGFrame::nsSVGOuterSVGFrame(ComputedStyle* aStyle) nsSVGOuterSVGFrame::nsSVGOuterSVGFrame(ComputedStyle* aStyle)
: nsSVGDisplayContainerFrame(aStyle, kClassID) : nsSVGDisplayContainerFrame(aStyle, kClassID)
, mCallingReflowSVG(false) , mCallingReflowSVG(false)
, mFullZoom(aStyle->PresContext()->GetFullZoom()) , mFullZoom(PresContext()->GetFullZoom())
, mViewportInitialized(false) , mViewportInitialized(false)
, mIsRootContent(false) , mIsRootContent(false)
{ {

View File

@@ -741,7 +741,8 @@ nsListBoxBodyFrame::ComputeIntrinsicISize(nsBoxLayoutState& aBoxLayoutState)
} }
RefPtr<nsFontMetrics> fm = RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForComputedStyle(computedStyle); nsLayoutUtils::GetFontMetricsForComputedStyle(computedStyle,
presContext);
nscoord textWidth = nscoord textWidth =
nsLayoutUtils::AppUnitWidthOfStringBidi(value, this, *fm, nsLayoutUtils::AppUnitWidthOfStringBidi(value, this, *fm,

View File

@@ -1252,7 +1252,7 @@ nsTreeBodyFrame::GetCoordsForCellItem(int32_t aRow, nsITreeColumn* aCol, const n
ComputedStyle* textContext = GetPseudoComputedStyle(nsCSSAnonBoxes::mozTreeCellText); ComputedStyle* textContext = GetPseudoComputedStyle(nsCSSAnonBoxes::mozTreeCellText);
RefPtr<nsFontMetrics> fm = RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForComputedStyle(textContext); nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, presContext);
nscoord height = fm->MaxHeight(); nscoord height = fm->MaxHeight();
nsMargin textMargin; nsMargin textMargin;
@@ -1626,7 +1626,7 @@ nsTreeBodyFrame::GetItemWithinCellAt(nscoord aX, const nsRect& aCellRect,
AdjustForBorderPadding(textContext, textRect); AdjustForBorderPadding(textContext, textRect);
RefPtr<nsFontMetrics> fm = RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForComputedStyle(textContext); nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, presContext);
AdjustForCellText(cellText, aRowIndex, aColumn, *rc, *fm, textRect); AdjustForCellText(cellText, aRowIndex, aColumn, *rc, *fm, textRect);
if (aX >= textRect.x && aX < textRect.x + textRect.width) if (aX >= textRect.x && aX < textRect.x + textRect.width)
@@ -1754,7 +1754,7 @@ nsTreeBodyFrame::GetCellWidth(int32_t aRow, nsTreeColumn* aCol,
GetBorderPadding(textContext, bp); GetBorderPadding(textContext, bp);
RefPtr<nsFontMetrics> fm = RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetFontMetricsForComputedStyle(textContext); nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, PresContext());
// Get the width of the text itself // Get the width of the text itself
nscoord width = nsLayoutUtils::AppUnitWidthOfStringBidi(cellText, this, *fm, nscoord width = nsLayoutUtils::AppUnitWidthOfStringBidi(cellText, this, *fm,
*aRenderingContext); *aRenderingContext);
@@ -3752,7 +3752,7 @@ nsTreeBodyFrame::PaintText(int32_t aRowIndex,
// Compute our text size. // Compute our text size.
RefPtr<nsFontMetrics> fontMet = RefPtr<nsFontMetrics> fontMet =
nsLayoutUtils::GetFontMetricsForComputedStyle(textContext); nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, PresContext());
nscoord height = fontMet->MaxHeight(); nscoord height = fontMet->MaxHeight();
nscoord baseline = fontMet->MaxAscent(); nscoord baseline = fontMet->MaxAscent();