Backed out 3 changesets (bug 1452080) for bustage in /builds/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp on a CLOSED TREE
authorNoemi Erli <nerli@mozilla.com>
Mon, 09 Apr 2018 11:18:12 +0300
changeset 468419 28a81bb4a0bd1fc67709038c799da980326752f8
parent 468418 7f5104c7a2425167959f725550c14719cb0c6274
child 468420 40a679f1cb7cf17bfc564b281a5bb742ea62c3fd
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1452080
milestone61.0a1
backs out7f5104c7a2425167959f725550c14719cb0c6274
806a9c95a2432ecac99b3c82088a00f2e07ee16b
bffebe8aa2549848be300e0c96b29477425721d3
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out 3 changesets (bug 1452080) for bustage in /builds/worker/workspace/build/src/layout/base/nsCSSFrameConstructor.cpp on a CLOSED TREE Backed out changeset 7f5104c7a242 (bug 1452080) Backed out changeset 806a9c95a243 (bug 1452080) Backed out changeset bffebe8aa254 (bug 1452080)
dom/animation/KeyframeEffectReadOnly.cpp
dom/animation/KeyframeEffectReadOnly.h
dom/canvas/CanvasRenderingContext2D.cpp
dom/svg/SVGContentUtils.cpp
dom/svg/SVGContentUtils.h
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/forms/nsTextControlFrame.cpp
layout/generic/ReflowInput.cpp
layout/generic/ReflowInput.h
layout/generic/nsBlockFrame.cpp
layout/generic/nsIFrame.h
layout/generic/nsImageFrame.cpp
layout/generic/nsLineLayout.cpp
layout/generic/nsTextFrame.cpp
layout/generic/nsTextRunTransformations.h
layout/mathml/nsMathMLFrame.cpp
layout/style/ComputedStyle.cpp
layout/style/ComputedStyle.h
layout/style/ComputedStyleInlines.h
layout/style/ServoStyleSet.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsFontFaceUtils.cpp
layout/svg/nsSVGOuterSVGFrame.cpp
layout/xul/nsListBoxBodyFrame.cpp
layout/xul/tree/nsTreeBodyFrame.cpp
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -186,25 +186,40 @@ KeyframeEffectReadOnly::SetKeyframes(JSC
 {
   nsTArray<Keyframe> keyframes =
     KeyframeUtils::GetKeyframesFromObject(aContext, mDocument, aKeyframes, aRv);
   if (aRv.Failed()) {
     return;
   }
 
   RefPtr<ComputedStyle> style = GetTargetComputedStyle();
-  SetKeyframes(Move(keyframes), style);
+  if (style) {
+    SetKeyframes(Move(keyframes), style);
+  } else {
+    // SetKeyframes has the same behavior for null StyleType* for
+    // both backends, just pick one and use it.
+    SetKeyframes(Move(keyframes), (ComputedStyle*) nullptr);
+  }
 }
 
 
 void
 KeyframeEffectReadOnly::SetKeyframes(
   nsTArray<Keyframe>&& aKeyframes,
-  const ComputedStyle* aStyle)
+  const ComputedStyle* aComputedValues)
 {
+  DoSetKeyframes(Move(aKeyframes), aComputedValues);
+}
+
+template<typename StyleType>
+void
+KeyframeEffectReadOnly::DoSetKeyframes(nsTArray<Keyframe>&& aKeyframes,
+                                       StyleType* aStyle)
+{
+
   if (KeyframesEqualIgnoringComputedOffsets(aKeyframes, mKeyframes)) {
     return;
   }
 
   mKeyframes = Move(aKeyframes);
   KeyframeUtils::DistributeKeyframes(mKeyframes);
 
   if (mAnimation && mAnimation->IsRelevant()) {
@@ -273,17 +288,24 @@ SpecifiedKeyframeArraysAreEqual(const ns
     }
   }
 
   return true;
 }
 #endif
 
 void
-KeyframeEffectReadOnly::UpdateProperties(const ComputedStyle* aStyle)
+KeyframeEffectReadOnly::UpdateProperties(const ComputedStyle* aComputedStyle)
+{
+  DoUpdateProperties(aComputedStyle);
+}
+
+template<typename StyleType>
+void
+KeyframeEffectReadOnly::DoUpdateProperties(StyleType* aStyle)
 {
   MOZ_ASSERT(aStyle);
 
   // Skip updating properties when we are composing style.
   // FIXME: Bug 1324966. Drop this check once we have a function to get
   // ComputedStyle without resolving animating style.
   MOZ_DIAGNOSTIC_ASSERT(!mIsComposingStyle,
                         "Should not be called while processing ComposeStyle()");
@@ -1451,47 +1473,38 @@ KeyframeEffectReadOnly::SetPerformanceWa
   }
 }
 
 
 already_AddRefed<ComputedStyle>
 KeyframeEffectReadOnly::CreateComputedStyleForAnimationValue(
   nsCSSPropertyID aProperty,
   const AnimationValue& aValue,
-  nsPresContext* aPresContext,
   const ComputedStyle* aBaseComputedStyle)
 {
   MOZ_ASSERT(aBaseComputedStyle,
              "CreateComputedStyleForAnimationValue needs to be called "
              "with a valid ComputedStyle");
 
-  ServoStyleSet* styleSet = aPresContext->StyleSet();
+  ServoStyleSet* styleSet = aBaseComputedStyle->PresContext()->StyleSet();
   Element* elementForResolve =
     EffectCompositor::GetElementToRestyle(mTarget->mElement,
                                           mTarget->mPseudoType);
   MOZ_ASSERT(elementForResolve, "The target element shouldn't be null");
   return styleSet->ResolveServoStyleByAddingAnimation(elementForResolve,
                                                       aBaseComputedStyle,
                                                       aValue.mServo);
 }
 
+template<typename StyleType>
 void
-KeyframeEffectReadOnly::CalculateCumulativeChangeHint(const ComputedStyle* aComputedStyle)
+KeyframeEffectReadOnly::CalculateCumulativeChangeHint(StyleType* aComputedStyle)
 {
   mCumulativeChangeHint = nsChangeHint(0);
 
-  nsPresContext* presContext =
-    nsContentUtils::GetContextForContent(mTarget->mElement);
-  if (!presContext) {
-    // Change hints make no sense if we're not rendered.
-    //
-    // Actually, we cannot even post them anywhere.
-    return;
-  }
-
   for (const AnimationProperty& property : mProperties) {
     // For opacity property we don't produce any change hints that are not
     // included in nsChangeHint_Hints_CanIgnoreIfNotVisible so we can throttle
     // opacity animations regardless of the change they produce.  This
     // optimization is particularly important since it allows us to throttle
     // opacity animations with missing 0%/100% keyframes.
     if (property.mProperty == eCSSProperty_opacity) {
       continue;
@@ -1503,29 +1516,27 @@ KeyframeEffectReadOnly::CalculateCumulat
       // on invisible elements because we can't calculate the change hint for
       // such properties until we compose it.
       if (!segment.HasReplaceableValues()) {
         mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
         return;
       }
       RefPtr<ComputedStyle> fromContext =
         CreateComputedStyleForAnimationValue(property.mProperty,
-                                             segment.mFromValue,
-                                             presContext,
-                                             aComputedStyle);
+                                            segment.mFromValue,
+                                            aComputedStyle);
       if (!fromContext) {
         mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
         return;
       }
 
       RefPtr<ComputedStyle> toContext =
         CreateComputedStyleForAnimationValue(property.mProperty,
-                                             segment.mToValue,
-                                             presContext,
-                                             aComputedStyle);
+                                            segment.mToValue,
+                                            aComputedStyle);
       if (!toContext) {
         mCumulativeChangeHint = ~nsChangeHint_Hints_CanIgnoreIfNotVisible;
         return;
       }
 
       uint32_t equalStructs = 0;
       nsChangeHint changeHint =
         fromContext->CalcStyleDifference(toContext, &equalStructs);
--- a/dom/animation/KeyframeEffectReadOnly.h
+++ b/dom/animation/KeyframeEffectReadOnly.h
@@ -161,17 +161,17 @@ public:
   IterationCompositeOperation IterationComposite() const;
   CompositeOperation Composite() const;
   void NotifyAnimationTimingUpdated();
   void RequestRestyle(EffectCompositor::RestyleType aRestyleType);
   void SetAnimation(Animation* aAnimation) override;
   void SetKeyframes(JSContext* aContext, JS::Handle<JSObject*> aKeyframes,
                     ErrorResult& aRv);
   void SetKeyframes(nsTArray<Keyframe>&& aKeyframes,
-                    const ComputedStyle* aStyle);
+                    const ComputedStyle* aComputedValues);
 
   // Returns true if the effect includes |aProperty| regardless of whether the
   // property is overridden by !important rule.
   bool HasAnimationOfProperty(nsCSSPropertyID aProperty) const;
 
   // GetEffectiveAnimationOfProperty returns AnimationProperty corresponding
   // to a given CSS property if the effect includes the property and the
   // property is not overridden by !important rules.
@@ -239,17 +239,18 @@ public:
   // compositor. |aParams| and |aParamsLength| are optional parameters which
   // will be used to generate a localized message for devtools.
   void SetPerformanceWarning(
     nsCSSPropertyID aProperty,
     const AnimationPerformanceWarning& aWarning);
 
   // Cumulative change hint on each segment for each property.
   // This is used for deciding the animation is paint-only.
-  void CalculateCumulativeChangeHint(const ComputedStyle* aStyle);
+  template<typename StyleType>
+  void CalculateCumulativeChangeHint(StyleType* aComputedStyle);
 
   // Returns true if all of animation properties' change hints
   // can ignore painting if the animation is not visible.
   // See nsChangeHint_Hints_CanIgnoreIfNotVisible in nsChangeHint.h
   // in detail which change hint can be ignored.
   bool CanIgnoreIfNotVisible() const;
 
   // Returns true if the effect is current state and has scale animation.
@@ -373,26 +374,32 @@ protected:
   // True if this effect is in the EffectSet for its target element. This is
   // used as an optimization to avoid unnecessary hashmap lookups on the
   // EffectSet.
   bool mInEffectSet = false;
 
 private:
   nsChangeHint mCumulativeChangeHint;
 
+  template<typename StyleType>
+  void DoSetKeyframes(nsTArray<Keyframe>&& aKeyframes, StyleType* aStyle);
+
+  template<typename StyleType>
+  void DoUpdateProperties(StyleType* aStyle);
+
+
   void ComposeStyleRule(RawServoAnimationValueMap& aAnimationValues,
                         const AnimationProperty& aProperty,
                         const AnimationPropertySegment& aSegment,
                         const ComputedTiming& aComputedTiming);
 
 
   already_AddRefed<ComputedStyle> CreateComputedStyleForAnimationValue(
     nsCSSPropertyID aProperty,
     const AnimationValue& aValue,
-    nsPresContext* aPresContext,
     const ComputedStyle* aBaseComputedStyle);
 
   nsIFrame* GetAnimationFrame() const;
 
   bool CanThrottle() const;
   bool CanThrottleTransformChanges(const nsIFrame& aFrame) const;
   bool CanThrottleTransformChangesInScrollable(nsIFrame& aFrame) const;
 
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -4294,20 +4294,19 @@ CanvasRenderingContext2D::DrawOrMeasureT
   gfxFontGroup* currentFontStyle = GetCurrentFontStyle();
   if (!currentFontStyle) {
     return NS_ERROR_FAILURE;
   }
 
   MOZ_ASSERT(!presShell->IsDestroying(),
              "GetCurrentFontStyle() should have returned null if the presshell is being destroyed");
 
-  nsPresContext* presContext = presShell->GetPresContext();
-
   // ensure user font set is up to date
-  currentFontStyle->SetUserFontSet(presContext->GetUserFontSet());
+  currentFontStyle->
+    SetUserFontSet(presShell->GetPresContext()->GetUserFontSet());
 
   if (currentFontStyle->GetStyle()->size == 0.0F) {
     if (aWidth) {
       *aWidth = 0;
     }
     return NS_OK;
   }
 
@@ -4316,17 +4315,16 @@ CanvasRenderingContext2D::DrawOrMeasureT
   }
 
   CanvasBidiProcessor processor;
 
   // If we don't have a ComputedStyle, we can't set up vertical-text flags
   // (for now, at least; perhaps we need new Canvas API to control this).
   processor.mTextRunFlags = canvasStyle
     ? nsLayoutUtils::GetTextRunFlagsForStyle(canvasStyle,
-                                             presContext,
                                              canvasStyle->StyleFont(),
                                              canvasStyle->StyleText(),
                                              0)
     : gfx::ShapedTextFlags();
 
   GetAppUnitsValues(&processor.mAppUnitsPerDevPixel, nullptr);
   processor.mPt = gfx::Point(aX, aY);
   processor.mDrawTarget =
--- a/dom/svg/SVGContentUtils.cpp
+++ b/dom/svg/SVGContentUtils.cpp
@@ -265,105 +265,96 @@ SVGContentUtils::GetStrokeWidth(nsSVGEle
   if (aContextPaint && styleSVG->StrokeWidthFromObject()) {
     return aContextPaint->GetStrokeWidth();
   }
 
   return SVGContentUtils::CoordToFloat(aElement, styleSVG->mStrokeWidth);
 }
 
 float
-SVGContentUtils::GetFontSize(Element* aElement)
+SVGContentUtils::GetFontSize(Element *aElement)
 {
-  if (!aElement) {
+  if (!aElement)
     return 1.0f;
-  }
-
-  nsPresContext* pc = nsContentUtils::GetContextForContent(aElement);
-  if (!pc) {
-    return 1.0f;
-  }
 
   RefPtr<ComputedStyle> computedStyle =
     nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
   if (!computedStyle) {
     // ReportToConsole
     NS_WARNING("Couldn't get ComputedStyle for content in GetFontStyle");
     return 1.0f;
   }
 
-  return GetFontSize(computedStyle, pc);
+  return GetFontSize(computedStyle);
 }
 
 float
-SVGContentUtils::GetFontSize(nsIFrame* aFrame)
+SVGContentUtils::GetFontSize(nsIFrame *aFrame)
 {
   MOZ_ASSERT(aFrame, "NULL frame in GetFontSize");
-  return GetFontSize(aFrame->Style(), aFrame->PresContext());
+  return GetFontSize(aFrame->Style());
 }
 
 float
-SVGContentUtils::GetFontSize(ComputedStyle* aComputedStyle,
-                             nsPresContext* aPresContext)
+SVGContentUtils::GetFontSize(ComputedStyle *aComputedStyle)
 {
-  MOZ_ASSERT(aComputedStyle);
-  MOZ_ASSERT(aPresContext);
+  MOZ_ASSERT(aComputedStyle, "NULL ComputedStyle in GetFontSize");
+
+  nsPresContext *presContext = aComputedStyle->PresContext();
+  MOZ_ASSERT(presContext, "NULL pres context in GetFontSize");
 
   nscoord fontSize = aComputedStyle->StyleFont()->mSize;
   return nsPresContext::AppUnitsToFloatCSSPixels(fontSize) /
-         aPresContext->EffectiveTextZoom();
+         presContext->EffectiveTextZoom();
 }
 
 float
-SVGContentUtils::GetFontXHeight(Element* aElement)
+SVGContentUtils::GetFontXHeight(Element *aElement)
 {
-  if (!aElement) {
+  if (!aElement)
     return 1.0f;
-  }
 
-  nsPresContext* pc = nsContentUtils::GetContextForContent(aElement);
-  if (!pc) {
-    return 1.0f;
-  }
-
-  RefPtr<ComputedStyle> style =
+  RefPtr<ComputedStyle> computedStyle =
     nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
-  if (!style) {
+  if (!computedStyle) {
     // ReportToConsole
     NS_WARNING("Couldn't get ComputedStyle for content in GetFontStyle");
     return 1.0f;
   }
 
-  return GetFontXHeight(style, pc);
+  return GetFontXHeight(computedStyle);
 }
 
 float
 SVGContentUtils::GetFontXHeight(nsIFrame *aFrame)
 {
   MOZ_ASSERT(aFrame, "NULL frame in GetFontXHeight");
-  return GetFontXHeight(aFrame->Style(), aFrame->PresContext());
+  return GetFontXHeight(aFrame->Style());
 }
 
 float
-SVGContentUtils::GetFontXHeight(ComputedStyle* aComputedStyle,
-                                nsPresContext* aPresContext)
+SVGContentUtils::GetFontXHeight(ComputedStyle *aComputedStyle)
 {
-  MOZ_ASSERT(aComputedStyle && aPresContext);
+  MOZ_ASSERT(aComputedStyle, "NULL ComputedStyle in GetFontXHeight");
+
+  nsPresContext *presContext = aComputedStyle->PresContext();
+  MOZ_ASSERT(presContext, "NULL pres context in GetFontXHeight");
 
   RefPtr<nsFontMetrics> fontMetrics =
-    nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle, aPresContext);
+    nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle);
 
   if (!fontMetrics) {
     // ReportToConsole
     NS_WARNING("no FontMetrics in GetFontXHeight()");
     return 1.0f;
   }
 
   nscoord xHeight = fontMetrics->XHeight();
   return nsPresContext::AppUnitsToFloatCSSPixels(xHeight) /
-         aPresContext->EffectiveTextZoom();
+         presContext->EffectiveTextZoom();
 }
 nsresult
 SVGContentUtils::ReportToConsole(nsIDocument* doc,
                                  const char* aWarning,
                                  const char16_t **aParams,
                                  uint32_t aParamsLength)
 {
   return nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
--- a/dom/svg/SVGContentUtils.h
+++ b/dom/svg/SVGContentUtils.h
@@ -15,17 +15,16 @@
 #include "mozilla/RangedPtr.h"
 #include "nsError.h"
 #include "nsStringFwd.h"
 #include "gfx2DGlue.h"
 
 class nsIContent;
 class nsIDocument;
 class nsIFrame;
-class nsPresContext;
 class nsStyleCoord;
 class nsSVGElement;
 
 namespace mozilla {
 class ComputedStyle;
 class nsSVGAnimatedTransformList;
 class SVGAnimatedPreserveAspectRatio;
 class SVGContextPaint;
@@ -176,29 +175,29 @@ public:
 
   /*
    * Get the number of CSS px (user units) per em (i.e. the em-height in user
    * units) for an nsIContent
    *
    * XXX document the conditions under which these may fail, and what they
    * return in those cases.
    */
-  static float GetFontSize(mozilla::dom::Element* aElement);
-  static float GetFontSize(nsIFrame* aFrame);
-  static float GetFontSize(ComputedStyle*, nsPresContext*);
+  static float GetFontSize(mozilla::dom::Element *aElement);
+  static float GetFontSize(nsIFrame *aFrame);
+  static float GetFontSize(ComputedStyle *aComputedStyle);
   /*
    * Get the number of CSS px (user units) per ex (i.e. the x-height in user
    * units) for an nsIContent
    *
    * XXX document the conditions under which these may fail, and what they
    * return in those cases.
    */
-  static float GetFontXHeight(mozilla::dom::Element* aElement);
-  static float GetFontXHeight(nsIFrame* aFrame);
-  static float GetFontXHeight(ComputedStyle*, nsPresContext*);
+  static float GetFontXHeight(mozilla::dom::Element *aElement);
+  static float GetFontXHeight(nsIFrame *aFrame);
+  static float GetFontXHeight(ComputedStyle *aComputedStyle);
 
   /*
    * Report a localized error message to the error console.
    */
   static nsresult ReportToConsole(nsIDocument* doc,
                                   const char* aWarning,
                                   const char16_t **aParams,
                                   uint32_t aParamsLength);
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -4419,17 +4419,17 @@ nsCSSFrameConstructor::FindXULDescriptio
 
 #ifdef XP_MACOSX
 /* static */
 const nsCSSFrameConstructor::FrameConstructionData*
 nsCSSFrameConstructor::FindXULMenubarData(Element* aElement,
                                           ComputedStyle* aComputedStyle)
 {
   nsCOMPtr<nsIDocShell> treeItem =
-    mPresShell->GetPresContext()->GetDocShell();
+    aComputedStyle->PresContext()->GetDocShell();
   if (treeItem && nsIDocShellTreeItem::typeChrome == treeItem->ItemType()) {
     nsCOMPtr<nsIDocShellTreeItem> parent;
     treeItem->GetParent(getter_AddRefs(parent));
     if (!parent) {
       // This is the root.  Suppress the menubar, since on Mac
       // window menus are not attached to the window.
       static const FrameConstructionData sSuppressData = SUPPRESS_FCDATA();
       return &sSuppressData;
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4690,52 +4690,52 @@ nsLayoutUtils::GetFontMetricsForFrame(co
     if (clusters == 2) {
       variantWidth = NS_FONT_VARIANT_WIDTH_HALF;
     } else if (clusters == 3) {
       variantWidth = NS_FONT_VARIANT_WIDTH_THIRD;
     } else if (clusters == 4) {
       variantWidth = NS_FONT_VARIANT_WIDTH_QUARTER;
     }
   }
-  return GetFontMetricsForComputedStyle(computedStyle, aFrame->PresContext(),
-                                        aInflation, variantWidth);
+  return GetFontMetricsForComputedStyle(computedStyle, aInflation, variantWidth);
 }
 
 already_AddRefed<nsFontMetrics>
 nsLayoutUtils::GetFontMetricsForComputedStyle(ComputedStyle* aComputedStyle,
-                                              nsPresContext* aPresContext,
-                                              float aInflation,
-                                              uint8_t aVariantWidth)
-{
+                                             float aInflation,
+                                             uint8_t aVariantWidth)
+{
+  nsPresContext* pc = aComputedStyle->PresContext();
+
   WritingMode wm(aComputedStyle);
   const nsStyleFont* styleFont = aComputedStyle->StyleFont();
   nsFontMetrics::Params params;
   params.language = styleFont->mLanguage;
   params.explicitLanguage = styleFont->mExplicitLanguage;
   params.orientation =
     wm.IsVertical() && !wm.IsSideways() ? gfxFont::eVertical
                                         : gfxFont::eHorizontal;
   // pass the user font set object into the device context to
   // pass along to CreateFontGroup
-  params.userFontSet = aPresContext->GetUserFontSet();
-  params.textPerf = aPresContext->GetTextPerfMetrics();
+  params.userFontSet = pc->GetUserFontSet();
+  params.textPerf = pc->GetTextPerfMetrics();
 
   // When aInflation is 1.0 and we don't require width variant, avoid
   // making a local copy of the nsFont.
   // This also avoids running font.size through floats when it is large,
   // which would be lossy.  Fortunately, in such cases, aInflation is
   // guaranteed to be 1.0f.
   if (aInflation == 1.0f && aVariantWidth == NS_FONT_VARIANT_WIDTH_NORMAL) {
-    return aPresContext->DeviceContext()->GetMetricsFor(styleFont->mFont, params);
+    return pc->DeviceContext()->GetMetricsFor(styleFont->mFont, params);
   }
 
   nsFont font = styleFont->mFont;
   font.size = NSToCoordRound(font.size * aInflation);
   font.variantWidth = aVariantWidth;
-  return aPresContext->DeviceContext()->GetMetricsFor(font, params);
+  return pc->DeviceContext()->GetMetricsFor(font, params);
 }
 
 nsIFrame*
 nsLayoutUtils::FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame)
 {
   nsIFrame* result = aDescendantFrame;
 
   while (result) {
@@ -7516,17 +7516,16 @@ nsLayoutUtils::GetReferenceFrame(nsIFram
       return f;
     }
     f = parent;
   }
 }
 
 /* static */ gfx::ShapedTextFlags
 nsLayoutUtils::GetTextRunFlagsForStyle(ComputedStyle* aComputedStyle,
-                                       nsPresContext* aPresContext,
                                        const nsStyleFont* aStyleFont,
                                        const nsStyleText* aStyleText,
                                        nscoord aLetterSpacing)
 {
   gfx::ShapedTextFlags result = gfx::ShapedTextFlags();
   if (aLetterSpacing != 0 ||
       aStyleText->mTextJustify == StyleTextJustify::InterCharacter) {
     result |= gfx::ShapedTextFlags::TEXT_DISABLE_OPTIONAL_LIGATURES;
@@ -7534,17 +7533,18 @@ nsLayoutUtils::GetTextRunFlagsForStyle(C
   if (aStyleText->mControlCharacterVisibility == NS_STYLE_CONTROL_CHARACTER_VISIBILITY_HIDDEN) {
     result |= gfx::ShapedTextFlags::TEXT_HIDE_CONTROL_CHARACTERS;
   }
   switch (aComputedStyle->StyleText()->mTextRendering) {
   case NS_STYLE_TEXT_RENDERING_OPTIMIZESPEED:
     result |= gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED;
     break;
   case NS_STYLE_TEXT_RENDERING_AUTO:
-    if (aStyleFont->mFont.size < aPresContext->GetAutoQualityMinFontSize()) {
+    if (aStyleFont->mFont.size <
+        aComputedStyle->PresContext()->GetAutoQualityMinFontSize()) {
       result |= gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED;
     }
     break;
   default:
     break;
   }
   return result | GetTextRunOrientFlagsForStyle(aComputedStyle);
 }
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -1298,35 +1298,31 @@ public:
 
   /**
    * Get the font metrics corresponding to the given style data.
    * @param aComputedStyle the style data
    * @param aSizeInflation number to multiply font size by
    */
   static already_AddRefed<nsFontMetrics> GetFontMetricsForComputedStyle(
       ComputedStyle* aComputedStyle,
-      nsPresContext* aPresContext,
       float aSizeInflation = 1.0f,
       uint8_t aVariantWidth = NS_FONT_VARIANT_WIDTH_NORMAL);
 
   /**
    * Get the font metrics of emphasis marks corresponding to the given
    * style data. The result is same as GetFontMetricsForComputedStyle
    * except that the font size is scaled down to 50%.
    * @param aComputedStyle the style data
    * @param aInflation number to multiple font size by
    */
   static already_AddRefed<nsFontMetrics> GetFontMetricsOfEmphasisMarks(
       ComputedStyle* aComputedStyle,
-      nsPresContext* aPresContext,
       float aInflation)
   {
-    return GetFontMetricsForComputedStyle(aComputedStyle,
-                                          aPresContext,
-                                          aInflation * 0.5f);
+    return GetFontMetricsForComputedStyle(aComputedStyle, aInflation * 0.5f);
   }
 
   /**
    * Find the immediate child of aParent whose frame subtree contains
    * aDescendantFrame. Returns null if aDescendantFrame is not a descendant
    * of aParent.
    */
   static nsIFrame* FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame);
@@ -2065,17 +2061,16 @@ public:
    * Get textrun construction flags determined by a given style; in particular
    * some combination of:
    * -- TEXT_DISABLE_OPTIONAL_LIGATURES if letter-spacing is in use
    * -- TEXT_OPTIMIZE_SPEED if the text-rendering CSS property and font size
    * and prefs indicate we should be optimizing for speed over quality
    */
   static mozilla::gfx::ShapedTextFlags
   GetTextRunFlagsForStyle(ComputedStyle* aComputedStyle,
-                          nsPresContext* aPresContext,
                           const nsStyleFont* aStyleFont,
                           const nsStyleText* aStyleText,
                           nscoord aLetterSpacing);
 
   /**
    * Get orientation flags for textrun construction.
    */
   static mozilla::gfx::ShapedTextFlags
--- a/layout/forms/nsTextControlFrame.cpp
+++ b/layout/forms/nsTextControlFrame.cpp
@@ -170,21 +170,18 @@ nsTextControlFrame::CalcIntrinsicSize(gf
   nscoord lineHeight  = 0;
   nscoord charWidth   = 0;
   nscoord charMaxAdvance  = 0;
 
   RefPtr<nsFontMetrics> fontMet =
     nsLayoutUtils::GetFontMetricsForFrame(this, aFontSizeInflation);
 
   lineHeight =
-    ReflowInput::CalcLineHeight(GetContent(),
-                                Style(),
-                                PresContext(),
-                                NS_AUTOHEIGHT,
-                                aFontSizeInflation);
+    ReflowInput::CalcLineHeight(GetContent(), Style(),
+                                      NS_AUTOHEIGHT, aFontSizeInflation);
   charWidth = fontMet->AveCharWidth();
   charMaxAdvance = fontMet->MaxAdvance();
 
   // Set the width equal to the width in characters
   int32_t cols = GetCols();
   intrinsicSize.ISize(aWM) = cols * charWidth;
 
   // To better match IE, take the maximum character width(in twips) and remove
@@ -631,21 +628,18 @@ nsTextControlFrame::Reflow(nsPresContext
               aReflowInput.ComputedBSize() +
               aReflowInput.ComputedLogicalBorderPadding().BStartEnd(wm));
   aDesiredSize.SetSize(wm, finalSize);
 
   // Calculate the baseline and store it in mFirstBaseline.
   nscoord lineHeight = aReflowInput.ComputedBSize();
   float inflation = nsLayoutUtils::FontSizeInflationFor(this);
   if (!IsSingleLineTextControl()) {
-    lineHeight = ReflowInput::CalcLineHeight(GetContent(),
-                                             Style(),
-                                             PresContext(),
-                                             NS_AUTOHEIGHT,
-                                             inflation);
+    lineHeight = ReflowInput::CalcLineHeight(GetContent(), Style(),
+                                             NS_AUTOHEIGHT, inflation);
   }
   RefPtr<nsFontMetrics> fontMet =
     nsLayoutUtils::GetFontMetricsForFrame(this, inflation);
   mFirstBaseline =
     nsLayoutUtils::GetCenteredFontBaseline(fontMet, lineHeight,
                                            wm.IsLineInverted()) +
     aReflowInput.ComputedLogicalBorderPadding().BStart(wm);
   aDesiredSize.SetBlockStartAscent(mFirstBaseline);
--- a/layout/generic/ReflowInput.cpp
+++ b/layout/generic/ReflowInput.cpp
@@ -2845,17 +2845,16 @@ GetNormalLineHeight(nsFontMetrics* aFont
     //case eNoExternalLeading:
     normalLineHeight = emHeight + internalLeading;
   }
   return normalLineHeight;
 }
 
 static inline nscoord
 ComputeLineHeight(ComputedStyle* aComputedStyle,
-                  nsPresContext* aPresContext,
                   nscoord aBlockBSize,
                   float aFontSizeInflation)
 {
   const nsStyleCoord& lhCoord = aComputedStyle->StyleText()->mLineHeight;
 
   if (lhCoord.GetUnit() == eStyleUnit_Coord) {
     nscoord result = lhCoord.GetCoordValue();
     if (aFontSizeInflation != 1.0f) {
@@ -2879,48 +2878,41 @@ ComputeLineHeight(ComputedStyle* aComput
     NS_ASSERTION(lhCoord.GetIntValue() == NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT,
                  "bad line-height value");
     if (aBlockBSize != NS_AUTOHEIGHT) {
       return aBlockBSize;
     }
   }
 
   RefPtr<nsFontMetrics> fm = nsLayoutUtils::
-    GetFontMetricsForComputedStyle(aComputedStyle, aPresContext, aFontSizeInflation);
+    GetFontMetricsForComputedStyle(aComputedStyle, aFontSizeInflation);
   return GetNormalLineHeight(fm);
 }
 
 nscoord
 ReflowInput::CalcLineHeight() const
 {
   nscoord blockBSize =
     nsLayoutUtils::IsNonWrapperBlock(mFrame) ? ComputedBSize() :
     (mCBReflowInput ? mCBReflowInput->ComputedBSize() : NS_AUTOHEIGHT);
 
-  return CalcLineHeight(mFrame->GetContent(),
-                        mFrame->Style(),
-                        mFrame->PresContext(),
-                        blockBSize,
+  return CalcLineHeight(mFrame->GetContent(), mFrame->Style(), blockBSize,
                         nsLayoutUtils::FontSizeInflationFor(mFrame));
 }
 
 /* static */ nscoord
 ReflowInput::CalcLineHeight(nsIContent* aContent,
-                            ComputedStyle* aComputedStyle,
-                            nsPresContext* aPresContext,
-                            nscoord aBlockBSize,
-                            float aFontSizeInflation)
+                                  ComputedStyle* aComputedStyle,
+                                  nscoord aBlockBSize,
+                                  float aFontSizeInflation)
 {
   NS_PRECONDITION(aComputedStyle, "Must have a ComputedStyle");
 
   nscoord lineHeight =
-    ComputeLineHeight(aComputedStyle,
-                      aPresContext,
-                      aBlockBSize,
-                      aFontSizeInflation);
+    ComputeLineHeight(aComputedStyle, aBlockBSize, aFontSizeInflation);
 
   NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");
 
   HTMLInputElement* input = HTMLInputElement::FromNodeOrNull(aContent);
   if (input && input->IsSingleLineTextControl()) {
     // For Web-compatibility, single-line text input elements cannot
     // have a line-height smaller than one.
     nscoord lineHeightOne =
--- a/layout/generic/ReflowInput.h
+++ b/layout/generic/ReflowInput.h
@@ -766,17 +766,16 @@ public:
    *                     line-height:-moz-block-height.
    * @param aFontSizeInflation The result of the appropriate
    *                           nsLayoutUtils::FontSizeInflationFor call,
    *                           or 1.0 if during intrinsic size
    *                           calculation.
    */
   static nscoord CalcLineHeight(nsIContent* aContent,
                                 ComputedStyle* aComputedStyle,
-                                nsPresContext* aPresContext,
                                 nscoord aBlockBSize,
                                 float aFontSizeInflation);
 
 
   mozilla::LogicalSize ComputeContainingBlockRectangle(
          nsPresContext*           aPresContext,
          const ReflowInput* aContainingBlockRI) const;
 
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -525,21 +525,18 @@ nsBlockFrame::GetCaretBaseline() const
     if (firstLine->GetChildCount()) {
       return bp.top + firstLine->mFirstChild->GetCaretBaseline();
     }
   }
   float inflation = nsLayoutUtils::FontSizeInflationFor(this);
   RefPtr<nsFontMetrics> fm =
     nsLayoutUtils::GetFontMetricsForFrame(this, inflation);
   nscoord lineHeight =
-    ReflowInput::CalcLineHeight(GetContent(),
-                                Style(),
-                                PresContext(),
-                                contentRect.height,
-                                inflation);
+    ReflowInput::CalcLineHeight(GetContent(), Style(),
+                                      contentRect.height, inflation);
   const WritingMode wm = GetWritingMode();
   return nsLayoutUtils::GetCenteredFontBaseline(fm, lineHeight,
                                                 wm.IsLineInverted()) + bp.top;
 }
 
 /////////////////////////////////////////////////////////////////////////////
 // Child frame enumeration
 
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -630,17 +630,17 @@ public:
     , mMayHaveTransformAnimation(false)
     , mMayHaveOpacityAnimation(false)
     , mAllDescendantsAreInvisible(false)
   {
     mozilla::PodZero(&mOverflow);
   }
 
   nsPresContext* PresContext() const {
-    return Style()->PresContextForFrame();
+    return Style()->PresContext();
   }
 
   nsIPresShell* PresShell() const {
     return PresContext()->PresShell();
   }
 
   /**
    * Called to initialize the frame. This is called immediately after creating
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -482,17 +482,17 @@ nsImageFrame::ShouldCreateImageFrameFor(
            !aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::alt) &&
            !aElement->IsHTMLElement(nsGkAtoms::object) &&
            !aElement->IsHTMLElement(nsGkAtoms::input)) {
     // Use a sized box if we have no alt text.  This means no alt attribute
     // and the node is not an object or an input (since those always have alt
     // text).
     useSizedBox = true;
   }
-  else if (aElement->OwnerDoc()->GetCompatibilityMode() !=
+  else if (aComputedStyle->PresContext()->CompatibilityMode() !=
            eCompatibility_NavQuirks) {
     useSizedBox = false;
   }
   else {
     // check whether we have specified size
     useSizedBox = HaveSpecifiedSize(aComputedStyle->StylePosition());
   }
 
--- a/layout/generic/nsLineLayout.cpp
+++ b/layout/generic/nsLineLayout.cpp
@@ -1657,20 +1657,18 @@ nsLineLayout::PlaceTopBottomFrames(PerSp
       PlaceTopBottomFrames(span, fromStart, aLineBSize);
     }
   }
 }
 
 static nscoord
 GetBSizeOfEmphasisMarks(nsIFrame* aSpanFrame, float aInflation)
 {
-  RefPtr<nsFontMetrics> fm =
-    nsLayoutUtils::GetFontMetricsOfEmphasisMarks(aSpanFrame->Style(),
-                                                 aSpanFrame->PresContext(),
-                                                 aInflation);
+  RefPtr<nsFontMetrics> fm = nsLayoutUtils::
+    GetFontMetricsOfEmphasisMarks(aSpanFrame->Style(), aInflation);
   return fm->MaxHeight();
 }
 
 void
 nsLineLayout::AdjustLeadings(nsIFrame* spanFrame, PerSpanData* psd,
                              const nsStyleText* aStyleText, float aInflation,
                              bool* aZeroEffectiveSpanBox)
 {
@@ -1881,22 +1879,20 @@ nsLineLayout::VerticalAlignFrames(PerSpa
 #endif
   }
   else {
     // Compute the logical block size for this span. The logical block size
     // is based on the "line-height" value, not the font-size. Also
     // compute the top leading.
     float inflation =
       GetInflationForBlockDirAlignment(spanFrame, mInflationMinFontSize);
-    nscoord logicalBSize =
-      ReflowInput::CalcLineHeight(spanFrame->GetContent(),
-                                  spanFrame->Style(),
-                                  spanFrame->PresContext(),
-                                  mBlockReflowInput->ComputedHeight(),
-                                  inflation);
+    nscoord logicalBSize = ReflowInput::
+      CalcLineHeight(spanFrame->GetContent(), spanFrame->Style(),
+                     mBlockReflowInput->ComputedHeight(),
+                     inflation);
     nscoord contentBSize = spanFramePFD->mBounds.BSize(lineWM) -
       spanFramePFD->mBorderPadding.BStartEnd(lineWM);
 
     // Special-case for a ::first-letter frame, set the line height to
     // the frame block size if the user has left line-height == normal
     const nsStyleText* styleText = spanFrame->StyleText();
     if (spanFramePFD->mIsLetterFrame &&
         !spanFrame->GetPrevInFlow() &&
@@ -2172,21 +2168,18 @@ nsLineLayout::VerticalAlignFrames(PerSpa
     } else {
       // We have either a coord, a percent, or a calc().
       nscoord pctBasis = 0;
       if (verticalAlign.HasPercent()) {
         // Percentages are like lengths, except treated as a percentage
         // of the elements line block size value.
         float inflation =
           GetInflationForBlockDirAlignment(frame, mInflationMinFontSize);
-        pctBasis = ReflowInput::CalcLineHeight(
-          frame->GetContent(),
-          frame->Style(),
-          frame->PresContext(),
-          mBlockReflowInput->ComputedBSize(),
+        pctBasis = ReflowInput::CalcLineHeight(frame->GetContent(),
+          frame->Style(), mBlockReflowInput->ComputedBSize(),
           inflation);
       }
       nscoord offset = verticalAlign.ComputeCoordPercentCalc(pctBasis);
       // According to the CSS2 spec (10.8.1), a positive value
       // "raises" the box by the given distance while a negative value
       // "lowers" the box by the given distance (with zero being the
       // baseline). Since Y coordinates increase towards the bottom of
       // the screen we reverse the sign, unless the line orientation is
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -1892,28 +1892,25 @@ BuildTextRunsScanner::ContinueTextRunAcr
     return false;
   }
 
   ComputedStyle* sc2 = aFrame2->Style();
   const nsStyleText* textStyle2 = sc2->StyleText();
   if (sc1 == sc2)
     return true;
 
-  nsPresContext* pc = aFrame1->PresContext();
-  MOZ_ASSERT(pc == aFrame2->PresContext());
-
   const nsStyleFont* fontStyle1 = sc1->StyleFont();
   const nsStyleFont* fontStyle2 = sc2->StyleFont();
   nscoord letterSpacing1 = LetterSpacing(aFrame1);
   nscoord letterSpacing2 = LetterSpacing(aFrame2);
   return fontStyle1->mFont == fontStyle2->mFont &&
     fontStyle1->mLanguage == fontStyle2->mLanguage &&
     textStyle1->mTextTransform == textStyle2->mTextTransform &&
-    nsLayoutUtils::GetTextRunFlagsForStyle(sc1, pc, fontStyle1, textStyle1, letterSpacing1) ==
-      nsLayoutUtils::GetTextRunFlagsForStyle(sc2, pc, fontStyle2, textStyle2, letterSpacing2);
+    nsLayoutUtils::GetTextRunFlagsForStyle(sc1, fontStyle1, textStyle1, letterSpacing1) ==
+      nsLayoutUtils::GetTextRunFlagsForStyle(sc2, fontStyle2, textStyle2, letterSpacing2);
 }
 
 void BuildTextRunsScanner::ScanFrame(nsIFrame* aFrame)
 {
   LayoutFrameType frameType = aFrame->Type();
   if (frameType == LayoutFrameType::RubyTextContainer) {
     // Don't include any ruby text container into the text run.
     return;
@@ -2298,18 +2295,17 @@ BuildTextRunsScanner::BuildTextRunForFra
   }
   if (mNextRunContextInfo & nsTextFrameUtils::INCOMING_ARABICCHAR) {
     flags |= gfx::ShapedTextFlags::TEXT_TRAILING_ARABICCHAR;
   }
   // ContinueTextRunAcrossFrames guarantees that it doesn't matter which
   // frame's style is used, so we use a mixture of the first frame and
   // last frame's style
   flags |= nsLayoutUtils::GetTextRunFlagsForStyle(lastComputedStyle,
-      firstFrame->PresContext(), fontStyle, textStyle,
-      LetterSpacing(firstFrame, textStyle));
+      fontStyle, textStyle, LetterSpacing(firstFrame, textStyle));
   // 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.
   if (!(flags & gfx::ShapedTextFlags::TEXT_OPTIMIZE_SPEED)) {
     flags |= gfx::ShapedTextFlags::TEXT_NEED_BOUNDING_BOX;
   }
 
   // Convert linebreak coordinates to transformed string offsets
   NS_ASSERTION(nextBreakIndex == mLineBreakBeforeFrames.Length(),
@@ -2348,17 +2344,17 @@ BuildTextRunsScanner::BuildTextRunForFra
            f = f->GetNextContinuation()) {
         uint32_t offset = iter.GetSkippedOffset();
         iter.AdvanceOriginal(f->GetContentLength());
         uint32_t end = iter.GetSkippedOffset();
         // Text-combined frames have content-dependent transform, so we
         // want to create new nsTransformedCharStyle for them anyway.
         if (sc != f->Style() || sc->IsTextCombined()) {
           sc = f->Style();
-          charStyle = new nsTransformedCharStyle(sc, f->PresContext());
+          charStyle = new nsTransformedCharStyle(sc);
           if (sc->IsTextCombined() && f->CountGraphemeClusters() > 1) {
             charStyle->mForceNonFullWidth = true;
           }
         }
         uint32_t j;
         for (j = offset; j < end; ++j) {
           styles.AppendElement(charStyle);
         }
@@ -5554,20 +5550,18 @@ nsTextFrame::UpdateTextEmphasis(WritingM
     return nsRect();
   }
 
   ComputedStyle* computedStyle = Style();
   bool isTextCombined = computedStyle->IsTextCombined();
   if (isTextCombined) {
     computedStyle = GetParent()->Style();
   }
-  RefPtr<nsFontMetrics> fm =
-    nsLayoutUtils::GetFontMetricsOfEmphasisMarks(computedStyle,
-                                                 PresContext(),
-                                                 GetFontSizeInflation());
+  RefPtr<nsFontMetrics> fm = nsLayoutUtils::
+    GetFontMetricsOfEmphasisMarks(computedStyle, GetFontSizeInflation());
   EmphasisMarkInfo* info = new EmphasisMarkInfo;
   info->textRun =
     GenerateTextRunForEmphasisMarks(this, fm, computedStyle, styleText);
   info->advance = info->textRun->GetAdvanceWidth();
 
   // Calculate the baseline offset
   LogicalSide side = styleText->TextEmphasisSide(aWM);
   LogicalSize frameSize = GetLogicalSize(aWM);
@@ -5788,20 +5782,18 @@ nsTextFrame::UnionAdditionalOverflow(nsP
 gfxFloat
 nsTextFrame::ComputeDescentLimitForSelectionUnderline(
                nsPresContext* aPresContext,
                const gfxFont::Metrics& aFontMetrics)
 {
   gfxFloat app = aPresContext->AppUnitsPerDevPixel();
   nscoord lineHeightApp =
     ReflowInput::CalcLineHeight(GetContent(),
-                                Style(),
-                                PresContext(),
-                                NS_AUTOHEIGHT,
-                                GetFontSizeInflation());
+                                      Style(), NS_AUTOHEIGHT,
+                                      GetFontSizeInflation());
   gfxFloat lineHeight = gfxFloat(lineHeightApp) / app;
   if (lineHeight <= aFontMetrics.maxHeight) {
     return aFontMetrics.maxDescent;
   }
   return aFontMetrics.maxDescent + (lineHeight - aFontMetrics.maxHeight) / 2;
 }
 
 // Make sure this stays in sync with DrawSelectionDecorations below
--- a/layout/generic/nsTextRunTransformations.h
+++ b/layout/generic/nsTextRunTransformations.h
@@ -7,36 +7,34 @@
 #ifndef NSTEXTRUNTRANSFORMATIONS_H_
 #define NSTEXTRUNTRANSFORMATIONS_H_
 
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/UniquePtr.h"
 #include "gfxTextRun.h"
 #include "mozilla/ComputedStyle.h"
-#include "nsPresContext.h"
 
 class nsTransformedTextRun;
 
 struct nsTransformedCharStyle final {
   NS_INLINE_DECL_REFCOUNTING(nsTransformedCharStyle)
 
-  explicit nsTransformedCharStyle(mozilla::ComputedStyle* aStyle,
-                                  nsPresContext* aPresContext)
+  explicit nsTransformedCharStyle(mozilla::ComputedStyle* aStyle)
     : mFont(aStyle->StyleFont()->mFont)
     , mLanguage(aStyle->StyleFont()->mLanguage)
-    , mPresContext(aPresContext)
+    , mPresContext(aStyle->PresContext())
     , mScriptSizeMultiplier(aStyle->StyleFont()->mScriptSizeMultiplier)
     , mTextTransform(aStyle->StyleText()->mTextTransform)
     , mMathVariant(aStyle->StyleFont()->mMathVariant)
     , mExplicitLanguage(aStyle->StyleFont()->mExplicitLanguage) {}
 
   nsFont                  mFont;
-  RefPtr<nsAtom>          mLanguage;
-  RefPtr<nsPresContext>   mPresContext;
+  RefPtr<nsAtom>       mLanguage;
+  RefPtr<nsPresContext> mPresContext;
   float                   mScriptSizeMultiplier;
   uint8_t                 mTextTransform;
   uint8_t                 mMathVariant;
   bool                    mExplicitLanguage;
   bool                    mForceNonFullWidth = false;
 
 private:
   ~nsTransformedCharStyle() {}
--- a/layout/mathml/nsMathMLFrame.cpp
+++ b/layout/mathml/nsMathMLFrame.cpp
@@ -226,19 +226,17 @@ nsMathMLFrame::CalcLength(nsPresContext*
 
   if (eCSSUnit_EM == unit) {
     const nsStyleFont* font = aComputedStyle->StyleFont();
     return NSToCoordRound(aCSSValue.GetFloatValue() * (float)font->mFont.size);
   }
   else if (eCSSUnit_XHeight == unit) {
     aPresContext->SetUsesExChUnits(true);
     RefPtr<nsFontMetrics> fm = nsLayoutUtils::
-      GetFontMetricsForComputedStyle(aComputedStyle,
-                                     aPresContext,
-                                     aFontSizeInflation);
+      GetFontMetricsForComputedStyle(aComputedStyle, aFontSizeInflation);
     nscoord xHeight = fm->XHeight();
     return NSToCoordRound(aCSSValue.GetFloatValue() * (float)xHeight);
   }
 
   // MathML doesn't specify other CSS units such as rem or ch
   NS_ERROR("Unsupported unit");
   return 0;
 }
--- a/layout/style/ComputedStyle.cpp
+++ b/layout/style/ComputedStyle.cpp
@@ -313,17 +313,17 @@ void ComputedStyle::List(FILE* out, int3
   fprintf_stderr(out, "%s{ServoComputedData}\n", str.get());
 }
 #endif
 
 
 nsIPresShell*
 ComputedStyle::Arena()
 {
-  return mPresContext->PresShell();
+  return PresContext()->PresShell();
 }
 
 template<typename Func>
 static nscolor
 GetVisitedDependentColorInternal(ComputedStyle* aSc, Func aColorFunc)
 {
   nscolor colors[2];
   colors[0] = aColorFunc(aSc);
--- a/layout/style/ComputedStyle.h
+++ b/layout/style/ComputedStyle.h
@@ -110,19 +110,17 @@ class ComputedStyle;
 class ComputedStyle
 {
 public:
   ComputedStyle(nsPresContext* aPresContext,
                 nsAtom* aPseudoTag,
                 CSSPseudoElementType aPseudoType,
                 ServoComputedDataForgotten aComputedValues);
 
-  // FIXME(emilio, bug 548397): This will need to go away. Don't add new callers
-  // of this methed.
-  nsPresContext* PresContextForFrame() const { return mPresContext; }
+  nsPresContext* PresContext() const { return mPresContext; }
   const ServoComputedData* ComputedData() const { return &mSource; }
 
   // These two methods are for use by ArenaRefPtr.
   //
   // FIXME(emilio): Think this can go away.
   static mozilla::ArenaObjectID ArenaObjectID()
   {
     return mozilla::eArenaObjectID_GeckoComputedStyle;
--- a/layout/style/ComputedStyleInlines.h
+++ b/layout/style/ComputedStyleInlines.h
@@ -49,34 +49,34 @@ const nsStyle##name_ * ComputedStyle::Do
   }                                                                         \
                                                                             \
   const nsStyle##name_* data = ComputedData()->GetStyle##name_();           \
                                                                             \
   /* perform any remaining main thread work on the struct */                \
   if (needToCompute) {                                                      \
     MOZ_ASSERT(NS_IsMainThread());                                          \
     MOZ_ASSERT(!mozilla::ServoStyleSet::IsInServoTraversal());              \
-    const_cast<nsStyle##name_*>(data)->FinishStyle(mPresContext, nullptr);  \
+    const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext(), nullptr); \
     /* the ComputedStyle owns the struct */                                 \
     AddStyleBit(NS_STYLE_INHERIT_BIT(name_));                               \
   }                                                                         \
   return data;                                                              \
 }
 
 #define STYLE_STRUCT_RESET(name_)                                           \
 template<bool aComputeData>                                                 \
 const nsStyle##name_ * ComputedStyle::DoGetStyle##name_() {                 \
   const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));        \
   if (!aComputeData && needToCompute) {                                     \
     return nullptr;                                                         \
   }                                                                         \
   const nsStyle##name_* data = ComputedData()->GetStyle##name_();           \
   /* perform any remaining main thread work on the struct */                \
   if (needToCompute) {                                                      \
-    const_cast<nsStyle##name_*>(data)->FinishStyle(mPresContext, nullptr);  \
+    const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext(), nullptr); \
     /* the ComputedStyle owns the struct */                                 \
     AddStyleBit(NS_STYLE_INHERIT_BIT(name_));                               \
   }                                                                         \
   return data;                                                              \
 }
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT_RESET
 #undef STYLE_STRUCT_INHERITED
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1416,17 +1416,17 @@ ServoStyleSet::ResolveStyleLazilyInterna
     computedValues =
       Servo_ResolveStyleLazily(elementForStyleResolution,
                                pseudoTypeForStyleResolution,
                                aRuleInclusion,
                                &Snapshots(),
                                mRawSet.get()).Consume();
   }
 
-  MOZ_DIAGNOSTIC_ASSERT(computedValues->PresContextForFrame() == GetPresContext() ||
+  MOZ_DIAGNOSTIC_ASSERT(computedValues->PresContext() == GetPresContext() ||
                         aElement->OwnerDoc()->GetBFCacheEntry());
 
   return computedValues.forget();
 }
 
 bool
 ServoStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
 {
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -5631,32 +5631,28 @@ nsComputedDOMStyle::GetLineHeightCoord(n
 
     if (nsLayoutUtils::IsNonWrapperBlock(mInnerFrame)) {
       blockHeight = mInnerFrame->GetContentRect().height;
     } else {
       GetCBContentHeight(blockHeight);
     }
   }
 
-  nsPresContext* presContext = mPresShell->GetPresContext();
-
   // lie about font size inflation since we lie about font size (since
   // the inflation only applies to text)
-  aCoord = ReflowInput::CalcLineHeight(mContent,
-                                       mComputedStyle,
-                                       presContext,
+  aCoord = ReflowInput::CalcLineHeight(mContent, mComputedStyle,
                                        blockHeight, 1.0f);
 
   // CalcLineHeight uses font->mFont.size, but we want to use
   // font->mSize as the font size.  Adjust for that.  Also adjust for
   // the text zoom, if any.
   const nsStyleFont* font = StyleFont();
   float fCoord = float(aCoord);
   if (font->mAllowZoom) {
-    fCoord /= presContext->EffectiveTextZoom();
+    fCoord /= mPresShell->GetPresContext()->EffectiveTextZoom();
   }
   if (font->mFont.size != font->mSize) {
     fCoord = fCoord * (float(font->mSize) / float(font->mFont.size));
   }
   aCoord = NSToCoordRound(fCoord);
 
   return true;
 }
--- a/layout/style/nsFontFaceUtils.cpp
+++ b/layout/style/nsFontFaceUtils.cpp
@@ -13,17 +13,16 @@
 #include "nsPlaceholderFrame.h"
 #include "nsTArray.h"
 #include "SVGTextFrame.h"
 
 using namespace mozilla;
 
 static bool
 ComputedStyleContainsFont(ComputedStyle* aComputedStyle,
-                          nsPresContext* aPresContext,
                           const gfxUserFontSet* aUserFontSet,
                           const gfxUserFontEntry* aFont)
 {
   // if the font is null, simply check to see whether fontlist includes
   // downloadable fonts
   if (!aFont) {
     const mozilla::FontFamilyList& fontlist =
       aComputedStyle->StyleFont()->mFont.fontlist;
@@ -34,43 +33,40 @@ ComputedStyleContainsFont(ComputedStyle*
   const nsString& familyName = aFont->FamilyName();
   if (!aComputedStyle->StyleFont()->mFont.fontlist.Contains(familyName)) {
     return false;
   }
 
   // family name is in the fontlist, check to see if the font group
   // associated with the frame includes the specific userfont
   RefPtr<nsFontMetrics> fm =
-    nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle,
-                                                  aPresContext,
-                                                  1.0f);
+    nsLayoutUtils::GetFontMetricsForComputedStyle(aComputedStyle, 1.0f);
 
   if (fm->GetThebesFontGroup()->ContainsUserFont(aFont)) {
     return true;
   }
 
   return false;
 }
 
 static bool
 FrameUsesFont(nsIFrame* aFrame, const gfxUserFontEntry* aFont)
 {
   // check the style of the frame
-  nsPresContext* pc = aFrame->PresContext();
-  gfxUserFontSet* ufs = pc->GetUserFontSet();
-  if (ComputedStyleContainsFont(aFrame->Style(), pc, ufs, aFont)) {
+  gfxUserFontSet* ufs = aFrame->PresContext()->GetUserFontSet();
+  if (ComputedStyleContainsFont(aFrame->Style(), ufs, aFont)) {
     return true;
   }
 
   // check additional styles
   int32_t contextIndex = 0;
   for (ComputedStyle* extraContext;
        (extraContext = aFrame->GetAdditionalComputedStyle(contextIndex));
        ++contextIndex) {
-    if (ComputedStyleContainsFont(extraContext, pc, ufs, aFont)) {
+    if (ComputedStyleContainsFont(extraContext, ufs, aFont)) {
       return true;
     }
   }
 
   return false;
 }
 
 static void
--- a/layout/svg/nsSVGOuterSVGFrame.cpp
+++ b/layout/svg/nsSVGOuterSVGFrame.cpp
@@ -62,17 +62,17 @@ NS_NewSVGOuterSVGFrame(nsIPresShell* aPr
   return new (aPresShell) nsSVGOuterSVGFrame(aStyle);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsSVGOuterSVGFrame)
 
 nsSVGOuterSVGFrame::nsSVGOuterSVGFrame(ComputedStyle* aStyle)
   : nsSVGDisplayContainerFrame(aStyle, kClassID)
   , mCallingReflowSVG(false)
-  , mFullZoom(PresContext()->GetFullZoom())
+  , mFullZoom(aStyle->PresContext()->GetFullZoom())
   , mViewportInitialized(false)
   , mIsRootContent(false)
 {
   // Outer-<svg> has CSS layout, so remove this bit:
   RemoveStateBits(NS_FRAME_SVG_LAYOUT);
 }
 
 // helper
--- a/layout/xul/nsListBoxBodyFrame.cpp
+++ b/layout/xul/nsListBoxBodyFrame.cpp
@@ -736,18 +736,17 @@ nsListBoxBodyFrame::ComputeIntrinsicISiz
           for (nsIContent* content = child->GetFirstChild();
                content; content = content->GetNextSibling()) {
             if (Text* text = content->GetAsText()) {
               text->AppendTextTo(value);
             }
           }
 
           RefPtr<nsFontMetrics> fm =
-            nsLayoutUtils::GetFontMetricsForComputedStyle(computedStyle,
-                                                          presContext);
+            nsLayoutUtils::GetFontMetricsForComputedStyle(computedStyle);
 
           nscoord textWidth =
             nsLayoutUtils::AppUnitWidthOfStringBidi(value, this, *fm,
                                                     *rendContext);
           textWidth += width;
 
           if (textWidth > largestWidth)
             largestWidth = textWidth;
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -1247,17 +1247,17 @@ nsTreeBodyFrame::GetCoordsForCellItem(in
 
     // Measure the width of the text. If the width of the text is greater than
     // the remaining width available, then we just assume that the text has
     // been cropped and use the remaining rect as the text Rect. Otherwise,
     // we add in borders and padding to the text dimension and give that back.
     ComputedStyle* textContext = GetPseudoComputedStyle(nsCSSAnonBoxes::mozTreeCellText);
 
     RefPtr<nsFontMetrics> fm =
-      nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, presContext);
+      nsLayoutUtils::GetFontMetricsForComputedStyle(textContext);
     nscoord height = fm->MaxHeight();
 
     nsMargin textMargin;
     textContext->StyleMargin()->GetMargin(textMargin);
     textRect.Deflate(textMargin);
 
     // Center the text. XXX Obey vertical-align style prop?
     if (height < textRect.height) {
@@ -1621,17 +1621,17 @@ nsTreeBodyFrame::GetItemWithinCellAt(nsc
 
   nsMargin textMargin;
   textContext->StyleMargin()->GetMargin(textMargin);
   textRect.Deflate(textMargin);
 
   AdjustForBorderPadding(textContext, textRect);
 
   RefPtr<nsFontMetrics> fm =
-    nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, presContext);
+    nsLayoutUtils::GetFontMetricsForComputedStyle(textContext);
   AdjustForCellText(cellText, aRowIndex, aColumn, *rc, *fm, textRect);
 
   if (aX >= textRect.x && aX < textRect.x + textRect.width)
     return nsCSSAnonBoxes::mozTreeCellText;
   else
     return nsCSSAnonBoxes::mozTreeCell;
 }
 
@@ -1749,17 +1749,17 @@ nsTreeBodyFrame::GetCellWidth(int32_t aR
   CheckTextForBidi(cellText);
 
   ComputedStyle* textContext = GetPseudoComputedStyle(nsCSSAnonBoxes::mozTreeCellText);
 
   // Get the borders and padding for the text.
   GetBorderPadding(textContext, bp);
 
   RefPtr<nsFontMetrics> fm =
-    nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, PresContext());
+    nsLayoutUtils::GetFontMetricsForComputedStyle(textContext);
   // Get the width of the text itself
   nscoord width = nsLayoutUtils::AppUnitWidthOfStringBidi(cellText, this, *fm,
                                                           *aRenderingContext);
   nscoord totalTextWidth = width + bp.left + bp.right;
   aDesiredSize += totalTextWidth;
   return NS_OK;
 }
 
@@ -3747,17 +3747,17 @@ nsTreeBodyFrame::PaintText(int32_t      
 
   // Adjust the rect for its border and padding.
   nsMargin bp(0,0,0,0);
   GetBorderPadding(textContext, bp);
   textRect.Deflate(bp);
 
   // Compute our text size.
   RefPtr<nsFontMetrics> fontMet =
-    nsLayoutUtils::GetFontMetricsForComputedStyle(textContext, PresContext());
+    nsLayoutUtils::GetFontMetricsForComputedStyle(textContext);
 
   nscoord height = fontMet->MaxHeight();
   nscoord baseline = fontMet->MaxAscent();
 
   // Center the text. XXX Obey vertical-align style prop?
   if (height < textRect.height) {
     textRect.y += (textRect.height - height)/2;
     textRect.height = height;