Bug 1341724 - Part 1: stylo: Refactor nsRuleNode::GetMetricsFor; r?heycam
MozReview-Commit-ID: G709Er7GXwe
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -364,42 +364,57 @@ static inline nscoord ScaleViewportCoord
// repeatedly use a value and expect some multiple of the value to be
// smaller than a container, we need to use floor rather than round.
// We need to use division by 100.0 rather than multiplication by 0.1f
// to avoid introducing error.
return NSToCoordTruncClamped(aValue.GetFloatValue() *
aViewportSize / 100.0f);
}
+/* static */
already_AddRefed<nsFontMetrics>
-GetMetricsFor(nsPresContext* aPresContext,
- nsStyleContext* aStyleContext,
- const nsStyleFont* aStyleFont,
- nscoord aFontSize, // overrides value from aStyleFont
- bool aUseUserFontSet)
+nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
+ bool aIsVertical,
+ const nsStyleFont* aStyleFont,
+ nscoord aFontSize,
+ bool aUseUserFontSet)
{
nsFont font = aStyleFont->mFont;
font.size = aFontSize;
- gfxFont::Orientation orientation = gfxFont::eHorizontal;
- if (aStyleContext) {
- WritingMode wm(aStyleContext);
- if (wm.IsVertical() && !wm.IsSideways()) {
- orientation = gfxFont::eVertical;
- }
- }
+ 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.textPerf = aPresContext->GetTextPerfMetrics();
return aPresContext->DeviceContext()->GetMetricsFor(font, params);
}
+/* static */
+already_AddRefed<nsFontMetrics>
+nsRuleNode::GetMetricsFor(nsPresContext* aPresContext,
+ nsStyleContext* aStyleContext,
+ const nsStyleFont* aStyleFont,
+ nscoord aFontSize, // overrides value from aStyleFont
+ bool aUseUserFontSet)
+{
+ bool isVertical = false;
+ if (aStyleContext) {
+ WritingMode wm(aStyleContext);
+ if (wm.IsVertical() && !wm.IsSideways()) {
+ isVertical = true;
+ }
+ }
+ return nsRuleNode::GetMetricsFor(aPresContext, isVertical, aStyleFont,
+ aFontSize, aUseUserFontSet);
+}
+
static nsSize CalcViewportUnitsScale(nsPresContext* aPresContext)
{
// The caller is making use of viewport units, so notify the pres context
// that it will need to rebuild the rule tree if the size of the viewport
// changes.
aPresContext->SetUsesViewportUnits(true);
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -17,16 +17,17 @@
#include "mozilla/RangedArray.h"
#include "mozilla/RuleNodeCacheConditions.h"
#include "mozilla/SheetType.h"
#include "nsPresContext.h"
#include "nsStyleStruct.h"
class nsCSSPropertyIDSet;
class nsCSSValue;
+class nsFontMetrics;
class nsIStyleRule;
class nsStyleContext;
class nsStyleCoord;
struct nsCSSRect;
struct nsCSSValueList;
struct nsCSSValuePairList;
struct nsRuleData;
@@ -792,16 +793,28 @@ 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);
+ static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
+ bool aIsVertical,
+ const nsStyleFont* aStyleFont,
+ nscoord aFontSize,
+ bool aUseUserFontSet);
+
+ static already_AddRefed<nsFontMetrics> GetMetricsFor(nsPresContext* aPresContext,
+ nsStyleContext* aStyleContext,
+ const nsStyleFont* aStyleFont,
+ nscoord aFontSize,
+ bool aUseUserFontSet);
+
// Transition never returns null; on out of memory it'll just return |this|.
nsRuleNode* Transition(nsIStyleRule* aRule, mozilla::SheetType aLevel,
bool aIsImportantRule);
nsRuleNode* GetParent() const { return mParent; }
bool IsRoot() const { return mParent == nullptr; }
// Return the root of the rule tree that this rule node is in.
nsRuleNode* RuleTree();