Bug 1289701 - Find the root style context by walkng up the style context tree instead of calling ResolveStyleFor or getting it from root element's primary frame. r=dbaron

The only call site of CalcLengthWith() with a null style context is
CalcLengthWithInitialFont(). CalcLengthWithInitialFont() calls
CalcLengthWith() with a valid nsStyleFont and aUseProvidedRootEmSize
true, so we can get the rem unit font size from the nsStyleFont when called
from CalcLengthWithInitialFont().

MozReview-Commit-ID: A9LKfQEozaB
This commit is contained in:
Hiroyuki Ikezoe 2016-11-30 07:46:27 +09:00
Родитель 84eaaaf97d
Коммит 1ef4ddc756
2 изменённых файлов: 27 добавлений и 22 удалений

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

@ -442,6 +442,11 @@ static nsSize CalcViewportUnitsScale(nsPresContext* aPresContext)
return viewportSize;
}
// If |aStyleFont| is nullptr, aStyleContext->StyleFont() is used.
//
// In case that |aValue| is rem unit, if |aStyleContext| is null, callers must
// specify a valid |aStyleFont| and |aUseProvidedRootEmSize| must be true so
// that we can get the length from |aStyleFont|.
static nscoord CalcLengthWith(const nsCSSValue& aValue,
nscoord aFontSize,
const nsStyleFont* aStyleFont,
@ -458,8 +463,8 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
"not a length or calc unit");
NS_ASSERTION(aStyleFont || aStyleContext,
"Must have style data");
NS_ASSERTION(!aStyleFont || !aStyleContext,
"Duplicate sources of data");
NS_ASSERTION(aStyleContext || aUseProvidedRootEmSize,
"Must have style context or specify aUseProvidedRootEmSize");
NS_ASSERTION(aPresContext, "Must have prescontext");
if (aValue.IsFixedLengthUnit()) {
@ -554,21 +559,12 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
} else {
// This is not the root element or we are calculating something other
// than font size, so rem is relative to the root element's font size.
RefPtr<nsStyleContext> rootStyle;
const nsStyleFont *rootStyleFont = styleFont;
Element* docElement = aPresContext->Document()->GetRootElement();
if (docElement) {
nsIFrame* rootFrame = docElement->GetPrimaryFrame();
if (rootFrame) {
rootStyle = rootFrame->StyleContext();
} else {
rootStyle = aPresContext->StyleSet()->AsGecko()->ResolveStyleFor(docElement,
nullptr);
}
rootStyleFont = rootStyle->StyleFont();
// Find the root style context by walking up the style context tree.
nsStyleContext* rootStyle = aStyleContext;
while (rootStyle->GetParent()) {
rootStyle = rootStyle->GetParent();
}
const nsStyleFont *rootStyleFont = rootStyle->StyleFont();
rootFontSize = rootStyleFont->mFont.size;
}
@ -3323,15 +3319,19 @@ struct SetFontSizeCalcOps : public css::BasicCoordCalcOps,
const nscoord mParentSize;
const nsStyleFont* const mParentFont;
nsPresContext* const mPresContext;
nsStyleContext* const mStyleContext;
const bool mAtRoot;
RuleNodeCacheConditions& mConditions;
SetFontSizeCalcOps(nscoord aParentSize, const nsStyleFont* aParentFont,
nsPresContext* aPresContext, bool aAtRoot,
nsPresContext* aPresContext,
nsStyleContext* aStyleContext,
bool aAtRoot,
RuleNodeCacheConditions& aConditions)
: mParentSize(aParentSize),
mParentFont(aParentFont),
mPresContext(aPresContext),
mStyleContext(aStyleContext),
mAtRoot(aAtRoot),
mConditions(aConditions)
{
@ -3346,7 +3346,7 @@ struct SetFontSizeCalcOps : public css::BasicCoordCalcOps,
// between us and the parent is simply ignored.
size = CalcLengthWith(aValue, mParentSize,
mParentFont,
nullptr, mPresContext, mAtRoot,
mStyleContext, mPresContext, mAtRoot,
true, mConditions);
if (!aValue.IsRelativeLengthUnit() && mParentFont->mAllowZoom) {
size = nsStyleFont::ZoomText(mPresContext, size);
@ -3370,6 +3370,7 @@ struct SetFontSizeCalcOps : public css::BasicCoordCalcOps,
/* static */ void
nsRuleNode::SetFontSize(nsPresContext* aPresContext,
nsStyleContext* aContext,
const nsRuleData* aRuleData,
const nsStyleFont* aFont,
const nsStyleFont* aParentFont,
@ -3436,7 +3437,8 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext,
sizeValue->GetUnit() == eCSSUnit_Percent ||
sizeValue->IsCalcUnit()) {
SetFontSizeCalcOps ops(aParentSize, aParentFont,
aPresContext, aAtRoot,
aPresContext, aContext,
aAtRoot,
aConditions);
*aSize = css::ComputeCalc(*sizeValue, ops);
if (*aSize < 0) {
@ -3782,7 +3784,7 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
aFont->mScriptMinSize =
CalcLengthWith(*scriptMinSizeValue, aParentFont->mSize,
aParentFont,
nullptr, aPresContext, atRoot, true,
aContext, aPresContext, atRoot, true /* aUseUserFontSet */,
aConditions);
}
@ -4024,7 +4026,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
scriptLevelAdjustedParentSize !=
scriptLevelAdjustedUnconstrainedParentSize;
SetFontSize(aPresContext, aRuleData, aFont, aParentFont,
SetFontSize(aPresContext, aContext,
aRuleData, aFont, aParentFont,
&aFont->mSize,
systemFont, aParentFont->mSize, scriptLevelAdjustedParentSize,
aUsedStartStruct, atRoot, aConditions);
@ -4054,7 +4057,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
// already called SetUncacheable.
RuleNodeCacheConditions unconstrainedConditions;
SetFontSize(aPresContext, aRuleData, aFont, aParentFont,
SetFontSize(aPresContext, aContext,
aRuleData, aFont, aParentFont,
&aFont->mScriptUnconstrainedSize,
systemFont, aParentFont->mScriptUnconstrainedSize,
scriptLevelAdjustedUnconstrainedParentSize,

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

@ -755,6 +755,7 @@ protected:
// helpers for |ComputeFontData| that need access to |mNoneBits|:
static void SetFontSize(nsPresContext* aPresContext,
nsStyleContext* aContext,
const nsRuleData* aRuleData,
const nsStyleFont* aFont,
const nsStyleFont* aParentFont,