Bug 1383634: Remove usage of GetParentAllowServo in mathml code. r=xidorn

MozReview-Commit-ID: JncrAto7T3K

--HG--
extra : rebase_source : 818e5bbf148f30b9a62eaa0c55528daf921eb01a
This commit is contained in:
Emilio Cobos Álvarez 2017-07-24 10:11:41 +02:00
Родитель a132872286
Коммит cfe31ad4cc
7 изменённых файлов: 62 добавлений и 68 удалений

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

@ -752,7 +752,6 @@ InitCharGlobals()
nsMathMLChar::~nsMathMLChar()
{
MOZ_COUNT_DTOR(nsMathMLChar);
mStyleContext->Release();
}
nsStyleContext*
@ -765,15 +764,8 @@ nsMathMLChar::GetStyleContext() const
void
nsMathMLChar::SetStyleContext(nsStyleContext* aStyleContext)
{
NS_PRECONDITION(aStyleContext, "null ptr");
if (aStyleContext != mStyleContext) {
if (mStyleContext)
mStyleContext->Release();
if (aStyleContext) {
mStyleContext = aStyleContext;
aStyleContext->AddRef();
}
}
MOZ_ASSERT(aStyleContext);
mStyleContext = aStyleContext;
}
void
@ -1504,7 +1496,7 @@ InsertMathFallbacks(FontFamilyList& aFamilyList,
}
nsresult
nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
nsMathMLChar::StretchInternal(nsIFrame* aForFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
nsStretchDirection& aStretchDirection,
@ -1516,6 +1508,8 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
float aMaxSize,
bool aMaxSizeIsAbsolute)
{
nsPresContext* presContext = aForFrame->PresContext();
// if we have been called before, and we didn't actually stretch, our
// direction may have been set to NS_STRETCH_DIRECTION_UNSUPPORTED.
// So first set our direction back to its instrinsic value
@ -1524,23 +1518,23 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
// Set default font and get the default bounding metrics
// mStyleContext is a leaf context used only when stretching happens.
// For the base size, the default font should come from the parent context
nsFont font = mStyleContext->GetParentAllowServo()->StyleFont()->mFont;
nsFont font = aForFrame->StyleFont()->mFont;
NormalizeDefaultFont(font, aFontSizeInflation);
const nsStyleFont* styleFont = mStyleContext->StyleFont();
nsFontMetrics::Params params;
params.language = styleFont->mLanguage;
params.explicitLanguage = styleFont->mExplicitLanguage;
params.userFontSet = aPresContext->GetUserFontSet();
params.textPerf = aPresContext->GetTextPerfMetrics();
params.userFontSet = presContext->GetUserFontSet();
params.textPerf = presContext->GetTextPerfMetrics();
RefPtr<nsFontMetrics> fm =
aPresContext->DeviceContext()->GetMetricsFor(font, params);
presContext->DeviceContext()->GetMetricsFor(font, params);
uint32_t len = uint32_t(mData.Length());
mGlyphs[0] = fm->GetThebesFontGroup()->
MakeTextRun(static_cast<const char16_t*>(mData.get()), len, aDrawTarget,
aPresContext->AppUnitsPerDevPixel(),
presContext->AppUnitsPerDevPixel(),
gfx::ShapedTextFlags(), nsTextFrameUtils::Flags(),
aPresContext->MissingFontRecorder());
presContext->MissingFontRecorder());
aDesiredStretchSize = MeasureTextRun(aDrawTarget, mGlyphs[0].get());
bool maxWidth = (NS_STRETCH_MAXWIDTH & aStretchHint) != 0;
@ -1656,7 +1650,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
printf("Searching in "%s" for a glyph of appropriate size for: 0x%04X:%c\n",
NS_ConvertUTF16toUTF8(fontlistStr).get(), mData[0], mData[0]&0x00FF);
#endif
StretchEnumContext enumData(this, aPresContext, aDrawTarget,
StretchEnumContext enumData(this, presContext, aDrawTarget,
aFontSizeInflation,
aStretchDirection, targetSize, aStretchHint,
aDesiredStretchSize, font.fontlist, glyphFound);
@ -1684,7 +1678,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
// We did not find a size variant or a glyph assembly to stretch this
// operator. Verify whether a font with an OpenType MATH table is available
// and record missing math script otherwise.
gfxMissingFontRecorder* MFR = aPresContext->MissingFontRecorder();
gfxMissingFontRecorder* MFR = presContext->MissingFontRecorder();
if (MFR && !fm->GetThebesFontGroup()->GetFirstMathFont()) {
MFR->RecordScript(unicode::Script::MATHEMATICAL_NOTATION);
}
@ -1768,7 +1762,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
}
nsresult
nsMathMLChar::Stretch(nsPresContext* aPresContext,
nsMathMLChar::Stretch(nsIFrame* aForFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
nsStretchDirection aStretchDirection,
@ -1787,7 +1781,7 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext,
mScaleY = mScaleX = 1.0;
mDirection = aStretchDirection;
nsresult rv =
StretchInternal(aPresContext, aDrawTarget, aFontSizeInflation, mDirection,
StretchInternal(aForFrame, aDrawTarget, aFontSizeInflation, mDirection,
aContainerSize, aDesiredStretchSize, aStretchHint);
// Record the metrics
@ -1809,15 +1803,17 @@ nsMathMLChar::Stretch(nsPresContext* aPresContext,
// minimum size, so that only widths of smaller subsequent characters are
// considered.
nscoord
nsMathMLChar::GetMaxWidth(nsPresContext* aPresContext, DrawTarget* aDrawTarget,
float aFontSizeInflation, uint32_t aStretchHint)
nsMathMLChar::GetMaxWidth(nsIFrame* aForFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
uint32_t aStretchHint)
{
nsBoundingMetrics bm;
nsStretchDirection direction = NS_STRETCH_DIRECTION_VERTICAL;
const nsBoundingMetrics container; // zero target size
StretchInternal(aPresContext, aDrawTarget, aFontSizeInflation, direction,
container, bm, aStretchHint | NS_STRETCH_MAXWIDTH);
StretchInternal(aForFrame, aDrawTarget, aFontSizeInflation,
direction, container, bm, aStretchHint | NS_STRETCH_MAXWIDTH);
return std::max(bm.width, bm.rightBearing) - std::min(0, bm.leftBearing);
}
@ -1888,8 +1884,7 @@ public:
virtual void Paint(nsDisplayListBuilder* aBuilder,
gfxContext* aCtx) override
{
mChar->PaintForeground(mFrame->PresContext(), *aCtx,
ToReferenceFrame(), mIsSelected);
mChar->PaintForeground(mFrame, *aCtx, ToReferenceFrame(), mIsSelected);
}
NS_DISPLAY_DECL_NAME("MathMLCharForeground", TYPE_MATHML_CHAR_FOREGROUND)
@ -1965,7 +1960,7 @@ nsMathMLChar::Display(nsDisplayListBuilder* aBuilder,
uint32_t aIndex,
const nsRect* aSelectedRect)
{
nsStyleContext* parentContext = mStyleContext->GetParentAllowServo();
nsStyleContext* parentContext = aForFrame->StyleContext();
nsStyleContext* styleContext = mStyleContext;
if (mDraw == DRAW_NORMAL) {
@ -2038,13 +2033,14 @@ nsMathMLChar::ApplyTransforms(gfxContext* aThebesContext,
}
void
nsMathMLChar::PaintForeground(nsPresContext* aPresContext,
nsMathMLChar::PaintForeground(nsIFrame* aForFrame,
gfxContext& aRenderingContext,
nsPoint aPt,
bool aIsSelected)
{
nsStyleContext* parentContext = mStyleContext->GetParentAllowServo();
nsStyleContext* parentContext = aForFrame->StyleContext();
nsStyleContext* styleContext = mStyleContext;
nsPresContext* presContext = aForFrame->PresContext();
if (mDraw == DRAW_NORMAL) {
// normal drawing if there is nothing special about this char
@ -2063,7 +2059,7 @@ nsMathMLChar::PaintForeground(nsPresContext* aPresContext,
aRenderingContext.SetColor(Color::FromABGR(fgColor));
aRenderingContext.Save();
nsRect r = mRect + aPt;
ApplyTransforms(&aRenderingContext, aPresContext->AppUnitsPerDevPixel(), r);
ApplyTransforms(&aRenderingContext, aForFrame->PresContext()->AppUnitsPerDevPixel(), r);
switch(mDraw)
{
@ -2079,9 +2075,9 @@ nsMathMLChar::PaintForeground(nsPresContext* aPresContext,
case DRAW_PARTS: {
// paint by parts
if (NS_STRETCH_DIRECTION_VERTICAL == mDirection)
PaintVertically(aPresContext, &aRenderingContext, r, fgColor);
PaintVertically(presContext, &aRenderingContext, r, fgColor);
else if (NS_STRETCH_DIRECTION_HORIZONTAL == mDirection)
PaintHorizontally(aPresContext, &aRenderingContext, r, fgColor);
PaintHorizontally(presContext, &aRenderingContext, r, fgColor);
break;
}
default:

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

@ -106,7 +106,7 @@ public:
uint32_t aIndex,
const nsRect* aSelectedRect = nullptr);
void PaintForeground(nsPresContext* aPresContext,
void PaintForeground(nsIFrame* aForFrame,
gfxContext& aRenderingContext,
nsPoint aPt,
bool aIsSelected);
@ -115,7 +115,7 @@ public:
// @param aContainerSize - IN - suggested size for the stretched char
// @param aDesiredStretchSize - OUT - the size that the char wants
nsresult
Stretch(nsPresContext* aPresContext,
Stretch(nsIFrame* aForFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
nsStretchDirection aStretchDirection,
@ -165,7 +165,7 @@ public:
// @param aStretchHint can be the value that will be passed to Stretch().
// It is used to determine whether the operator is stretchy or a largeop.
nscoord
GetMaxWidth(nsPresContext* aPresContext,
GetMaxWidth(nsIFrame* aForFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
uint32_t aStretchHint = NS_STRETCH_NORMAL);
@ -203,7 +203,7 @@ private:
nsRect mRect;
nsStretchDirection mDirection;
nsBoundingMetrics mBoundingMetrics;
nsStyleContext* mStyleContext;
RefPtr<nsStyleContext> mStyleContext;
// mGlyphs/mBmData are arrays describing the glyphs used to draw the operator.
// See the drawing methods below.
RefPtr<gfxTextRun> mGlyphs[4];
@ -239,7 +239,7 @@ private:
RefPtr<gfxFontGroup>* aFontGroup);
nsresult
StretchInternal(nsPresContext* aPresContext,
StretchInternal(nsIFrame* aForFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
nsStretchDirection& aStretchDirection,

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

@ -483,7 +483,7 @@ nsMathMLmencloseFrame::PlaceInternal(DrawTarget* aDrawTarget,
if (IsToDraw(NOTATION_LONGDIV)) {
if (aWidthOnly) {
nscoord longdiv_width = mMathMLChar[mLongDivCharIndex].
GetMaxWidth(PresContext(), aDrawTarget, fontSizeInflation);
GetMaxWidth(this, aDrawTarget, fontSizeInflation);
// Update horizontal parameters
dx_left = std::max(dx_left, longdiv_width);
@ -495,7 +495,7 @@ nsMathMLmencloseFrame::PlaceInternal(DrawTarget* aDrawTarget,
contSize.descent = bmBase.ascent + bmBase.descent + psi;
// height(longdiv) should be >= height(base) + psi + mRuleThickness
mMathMLChar[mLongDivCharIndex].Stretch(PresContext(), aDrawTarget,
mMathMLChar[mLongDivCharIndex].Stretch(this, aDrawTarget,
fontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
contSize, bmLongdivChar,
@ -525,7 +525,7 @@ nsMathMLmencloseFrame::PlaceInternal(DrawTarget* aDrawTarget,
if (aWidthOnly) {
nscoord radical_width = mMathMLChar[mRadicalCharIndex].
GetMaxWidth(PresContext(), aDrawTarget, fontSizeInflation);
GetMaxWidth(this, aDrawTarget, fontSizeInflation);
// Update horizontal parameters
*dx_leading = std::max(*dx_leading, radical_width);
@ -537,7 +537,7 @@ nsMathMLmencloseFrame::PlaceInternal(DrawTarget* aDrawTarget,
contSize.descent = bmBase.ascent + bmBase.descent + psi;
// height(radical) should be >= height(base) + psi + mRadicalRuleThickness
mMathMLChar[mRadicalCharIndex].Stretch(PresContext(), aDrawTarget,
mMathMLChar[mRadicalCharIndex].Stretch(this, aDrawTarget,
fontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
contSize, bmRadicalChar,

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

@ -190,7 +190,7 @@ of the nsMathMLChar. As we only stretch fences and separators in the vertical
direction, this has no impact on overall appearance.
*/
static void
ApplyUnstretchedMetrics(nsPresContext* aPresContext,
ApplyUnstretchedMetrics(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,
@ -199,7 +199,7 @@ ApplyUnstretchedMetrics(nsPresContext* aPresContext,
{
if (aMathMLChar && 0 < aMathMLChar->Length()) {
nsBoundingMetrics charSize;
aMathMLChar->Stretch(aPresContext, aDrawTarget, aFontSizeInflation,
aMathMLChar->Stretch(aFrame, aDrawTarget, aFontSizeInflation,
NS_STRETCH_DIRECTION_DEFAULT,
aMetrics, // size is unimportant as we aren't stretching
charSize, NS_STRETCH_NONE, aIsRTL);
@ -322,15 +322,15 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext,
// To achieve a minimum size of "1", the container should be enlarged by the
// unstretched metrics of the fences and separators.
ApplyUnstretchedMetrics(aPresContext, drawTarget,
ApplyUnstretchedMetrics(this, drawTarget,
fontSizeInflation, mOpenChar,
containerSize, isRTL);
for (i = 0; i < mSeparatorsCount; i++) {
ApplyUnstretchedMetrics(aPresContext, drawTarget,
ApplyUnstretchedMetrics(this, drawTarget,
fontSizeInflation, &mSeparatorsChar[i],
containerSize, isRTL);
}
ApplyUnstretchedMetrics(aPresContext, drawTarget,
ApplyUnstretchedMetrics(this, drawTarget,
fontSizeInflation, mCloseChar,
containerSize, isRTL);
@ -346,21 +346,21 @@ nsMathMLmfencedFrame::Reflow(nsPresContext* aPresContext,
/////////////////
// opening fence ...
ReflowChar(aPresContext, drawTarget, *fm,
ReflowChar(drawTarget, *fm,
fontSizeInflation, mOpenChar,
NS_MATHML_OPERATOR_FORM_PREFIX, font->mScriptLevel,
axisHeight, leading, em, containerSize, ascent, descent, isRTL);
/////////////////
// separators ...
for (i = 0; i < mSeparatorsCount; i++) {
ReflowChar(aPresContext, drawTarget, *fm,
ReflowChar(drawTarget, *fm,
fontSizeInflation, &mSeparatorsChar[i],
NS_MATHML_OPERATOR_FORM_INFIX, font->mScriptLevel,
axisHeight, leading, em, containerSize, ascent, descent, isRTL);
}
/////////////////
// closing fence ...
ReflowChar(aPresContext, drawTarget, *fm,
ReflowChar(drawTarget, *fm,
fontSizeInflation, mCloseChar,
NS_MATHML_OPERATOR_FORM_POSTFIX, font->mScriptLevel,
axisHeight, leading, em, containerSize, ascent, descent, isRTL);
@ -476,9 +476,8 @@ GetCharSpacing(nsMathMLChar* aMathMLChar,
}
// helper functions to perform the common task of formatting our chars
/*static*/ nsresult
nsMathMLmfencedFrame::ReflowChar(nsPresContext* aPresContext,
DrawTarget* aDrawTarget,
nsresult
nsMathMLmfencedFrame::ReflowChar(DrawTarget* aDrawTarget,
nsFontMetrics& aFontMetrics,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,
@ -499,7 +498,7 @@ nsMathMLmfencedFrame::ReflowChar(nsPresContext* aPresContext,
// stretch the char to the appropriate height if it is not big enough.
nsBoundingMetrics charSize;
nsresult res = aMathMLChar->Stretch(aPresContext, aDrawTarget,
nsresult res = aMathMLChar->Stretch(this, aDrawTarget,
aFontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
aContainerSize, charSize,
@ -580,7 +579,7 @@ nsMathMLmfencedFrame::PlaceChar(nsMathMLChar* aMathMLChar,
}
static nscoord
GetMaxCharWidth(nsPresContext* aPresContext,
GetMaxCharWidth(nsIFrame* aFrame,
DrawTarget* aDrawTarget,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,
@ -588,7 +587,7 @@ GetMaxCharWidth(nsPresContext* aPresContext,
int32_t aScriptLevel,
nscoord em)
{
nscoord width = aMathMLChar->GetMaxWidth(aPresContext, aDrawTarget,
nscoord width = aMathMLChar->GetMaxWidth(aFrame, aDrawTarget,
aFontSizeInflation);
if (0 < aMathMLChar->Length()) {
@ -607,7 +606,6 @@ nsMathMLmfencedFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext, Re
{
nscoord width = 0;
nsPresContext* presContext = PresContext();
const nsStyleFont* font = StyleFont();
float fontSizeInflation = nsLayoutUtils:: FontSizeInflationFor(this);
RefPtr<nsFontMetrics> fm =
@ -617,7 +615,7 @@ nsMathMLmfencedFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext, Re
if (mOpenChar) {
width +=
GetMaxCharWidth(presContext, aRenderingContext->GetDrawTarget(),
GetMaxCharWidth(this, aRenderingContext->GetDrawTarget(),
fontSizeInflation, mOpenChar,
NS_MATHML_OPERATOR_FORM_PREFIX, font->mScriptLevel, em);
}
@ -632,7 +630,7 @@ nsMathMLmfencedFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext, Re
if (i < mSeparatorsCount) {
width +=
GetMaxCharWidth(presContext, aRenderingContext->GetDrawTarget(),
GetMaxCharWidth(this, aRenderingContext->GetDrawTarget(),
fontSizeInflation, &mSeparatorsChar[i],
NS_MATHML_OPERATOR_FORM_INFIX, font->mScriptLevel, em);
}
@ -641,7 +639,7 @@ nsMathMLmfencedFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext, Re
if (mCloseChar) {
width +=
GetMaxCharWidth(presContext, aRenderingContext->GetDrawTarget(),
GetMaxCharWidth(this, aRenderingContext->GetDrawTarget(),
fontSizeInflation, mCloseChar,
NS_MATHML_OPERATOR_FORM_POSTFIX, font->mScriptLevel, em);
}

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

@ -62,9 +62,8 @@ public:
FixInterFrameSpacing(ReflowOutput& aDesiredSize) override;
// helper routines to format the MathMLChars involved here
static nsresult
ReflowChar(nsPresContext* aPresContext,
DrawTarget* aDrawTarget,
nsresult
ReflowChar(DrawTarget* aDrawTarget,
nsFontMetrics& aFontMetrics,
float aFontSizeInflation,
nsMathMLChar* aMathMLChar,

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

@ -738,7 +738,8 @@ nsMathMLmoFrame::Stretch(DrawTarget* aDrawTarget,
}
// let the MathMLChar stretch itself...
nsresult res = mMathMLChar.Stretch(PresContext(), aDrawTarget,
nsresult res = mMathMLChar.Stretch(this,
aDrawTarget,
fontSizeInflation,
aStretchDirection, container, charSize,
stretchHint,
@ -974,7 +975,7 @@ nsMathMLmoFrame::Place(DrawTarget* aDrawTarget,
StyleFont()->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK &&
NS_MATHML_OPERATOR_IS_LARGEOP(mFlags) && UseMathMLChar()) {
nsBoundingMetrics newMetrics;
rv = mMathMLChar.Stretch(PresContext(), aDrawTarget,
rv = mMathMLChar.Stretch(this, aDrawTarget,
nsLayoutUtils::FontSizeInflationFor(this),
NS_STRETCH_DIRECTION_VERTICAL,
aDesiredSize.mBoundingMetrics, newMetrics,
@ -1035,7 +1036,7 @@ nsMathMLmoFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext,
uint32_t stretchHint = GetStretchHint(mFlags, mPresentationData, true,
StyleFont());
aDesiredSize.Width() = mMathMLChar.
GetMaxWidth(PresContext(), aRenderingContext->GetDrawTarget(),
GetMaxWidth(this, aRenderingContext->GetDrawTarget(),
nsLayoutUtils::FontSizeInflationFor(this),
stretchHint);
}

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

@ -261,7 +261,7 @@ nsMathMLmrootFrame::Reflow(nsPresContext* aPresContext,
// height(radical) should be >= height(base) + psi + ruleThickness
nsBoundingMetrics radicalSize;
mSqrChar.Stretch(aPresContext, drawTarget,
mSqrChar.Stretch(this, drawTarget,
fontSizeInflation,
NS_STRETCH_DIRECTION_VERTICAL,
contSize, radicalSize,
@ -377,7 +377,7 @@ nsMathMLmrootFrame::GetIntrinsicISizeMetrics(gfxContext* aRenderingContext, Refl
nscoord indexWidth =
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, indexFrame,
nsLayoutUtils::PREF_ISIZE);
nscoord sqrWidth = mSqrChar.GetMaxWidth(PresContext(),
nscoord sqrWidth = mSqrChar.GetMaxWidth(this,
aRenderingContext->GetDrawTarget(),
fontSizeInflation);