Bug 1403592: Never flush the user font set when getting font metrics from style resolution. r?Manishearth
In this case, the caller doesn't go through all the PreTraverseSync stuff (we
don't really want it to do so), via GetComputedStyleNoFlush.
It makes sense to not flush the user font set that case, we'll schedule a
restyle properly if / when needed.
Since the set should be flushed otherwise, let's just not flush it from the
styling code.
MozReview-Commit-ID: LLHfxemJ8QQ
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -2477,19 +2477,20 @@ Gecko_GetFontMetrics(RawGeckoPresContext
// and if so, appends PostTraversalTasks to the current ServoStyleSet
// to be performed immediately after the traversal is finished. This
// works well for starting downloadable font loads, since we don't have
// those fonts available to get metrics for anyway. Platform fonts and
// ArrayBuffer-backed FontFace objects are handled synchronously.
nsPresContext* presContext = const_cast<nsPresContext*>(aPresContext);
presContext->SetUsesExChUnits(true);
- RefPtr<nsFontMetrics> fm = nsRuleNode::GetMetricsFor(presContext, aIsVertical,
- aFont, aFontSize,
- aUseUserFontSet);
+ RefPtr<nsFontMetrics> fm = nsRuleNode::GetMetricsFor(
+ presContext, aIsVertical, aFont, aFontSize, aUseUserFontSet,
+ nsRuleNode::FlushUserFontSet::No);
+
ret.mXSize = fm->XHeight();
gfxFloat zeroWidth = fm->GetThebesFontGroup()->GetFirstValidFont()->
GetMetrics(fm->Orientation()).zeroOrAveCharWidth;
ret.mChSize = ceil(aPresContext->AppUnitsPerDevPixel() * zeroWidth);
return ret;
}
int32_t
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -372,28 +372,30 @@ static inline nscoord ScaleViewportCoord
}
/* static */
already_AddRefed<nsFontMetrics>
nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
bool aIsVertical,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
- bool aUseUserFontSet)
+ bool aUseUserFontSet,
+ FlushUserFontSet aFlushUserFontSet)
{
nsFont font = aStyleFont->mFont;
font.size = aFontSize;
gfxFont::Orientation orientation
= aIsVertical ? gfxFont::eVertical : gfxFont::eHorizontal;
nsFontMetrics::Params params;
params.language = aStyleFont->mLanguage;
params.explicitLanguage = aStyleFont->mExplicitLanguage;
params.orientation = orientation;
- params.userFontSet =
- aUseUserFontSet ? aPresContext->GetUserFontSet() : nullptr;
+ params.userFontSet = aUseUserFontSet
+ ? aPresContext->GetUserFontSet(aFlushUserFontSet == FlushUserFontSet::Yes)
+ : nullptr;
params.textPerf = aPresContext->GetTextPerfMetrics();
return aPresContext->DeviceContext()->GetMetricsFor(font, params);
}
/* static */
already_AddRefed<nsFontMetrics>
nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
nsStyleContext* aStyleContext,
@@ -403,18 +405,19 @@ nsRuleNode::GetMetricsFor(nsPresContext*
{
bool isVertical = false;
if (aStyleContext) {
WritingMode wm(aStyleContext);
if (wm.IsVertical() && !wm.IsSideways()) {
isVertical = true;
}
}
- return nsRuleNode::GetMetricsFor(aPresContext, isVertical, aStyleFont,
- aFontSize, aUseUserFontSet);
+ return nsRuleNode::GetMetricsFor(
+ aPresContext, isVertical, aStyleFont, aFontSize, aUseUserFontSet,
+ FlushUserFontSet::Yes);
}
/* static */
void
nsRuleNode::FixupNoneGeneric(nsFont* aFont,
const nsPresContext* aPresContext,
uint8_t aGenericFontID,
const nsFont* aDefaultVariableFont)
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -802,21 +802,27 @@ private:
public:
// This is infallible; it will never return nullptr.
static already_AddRefed<nsRuleNode> CreateRootNode(nsPresContext* aPresContext);
static void EnsureBlockDisplay(mozilla::StyleDisplay& display,
bool aConvertListItem = false);
static void EnsureInlineDisplay(mozilla::StyleDisplay& display);
+ enum class FlushUserFontSet {
+ Yes,
+ No,
+ };
+
static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
bool aIsVertical,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
- bool aUseUserFontSet);
+ bool aUseUserFontSet,
+ FlushUserFontSet aFlushUserFontSet);
static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
nsStyleContext* aStyleContext,
const nsStyleFont* aStyleFont,
nscoord aFontSize,
bool aUseUserFontSet);
/**