Backed out 2 changesets (bug 1528712) for Linux spcshell and reftest failures (test_ext_browserSettings.js, 1022481-1.html) CLOSED TREE
authorCiure Andrei <aciure@mozilla.com>
Tue, 19 Feb 2019 14:25:57 +0200
changeset 459870 8a4ad06c05759fe087625f9fd8d047d848bee4c2
parent 459869 17d8de567ea416b9a995fcec56897b1bc138b9c6
child 459871 3924d1ec16af9553a1574c0cc87cbd34d695111b
push id35577
push userbtara@mozilla.com
push dateTue, 19 Feb 2019 17:33:29 +0000
treeherdermozilla-central@510bae6520ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1528712, 1022481
milestone67.0a1
backs out2d5c4e71e258e24f1a70ed850c619f97e56f2c60
d981515b874bbece6fee9d6f486612d3ec430ef3
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 2 changesets (bug 1528712) for Linux spcshell and reftest failures (test_ext_browserSettings.js, 1022481-1.html) CLOSED TREE Backed out changeset 2d5c4e71e258 (bug 1528712) Backed out changeset d981515b874b (bug 1528712)
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/canvas/CanvasRenderingContext2D.cpp
gfx/src/nsFont.cpp
gfx/src/nsFont.h
gfx/src/nsFontMetrics.cpp
gfx/src/nsFontMetrics.h
layout/base/PresShell.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/base/nsPresContext.cpp
layout/base/nsPresContext.h
layout/generic/MathMLTextRunFactory.cpp
layout/generic/nsPageFrame.cpp
layout/mathml/nsMathMLChar.cpp
layout/style/CSSMozDocumentRule.cpp
layout/style/CSSMozDocumentRule.h
layout/style/GeckoBindings.cpp
layout/style/GeckoBindings.h
layout/style/nsMediaFeatures.cpp
modules/libpref/init/StaticPrefList.h
servo/components/style/gecko/media_features.rs
servo/components/style/gecko/media_queries.rs
servo/components/style/gecko/values.rs
servo/components/style/properties/cascade.rs
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/longhands/color.mako.rs
servo/components/style/properties/longhands/font.mako.rs
servo/components/style/properties/properties.mako.rs
servo/components/style/stylesheets/document_rule.rs
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -2085,17 +2085,17 @@ bool nsContentUtils::ShouldResistFingerp
 bool nsContentUtils::ShouldResistFingerprinting(nsIDocShell* aDocShell) {
   if (!aDocShell) {
     return false;
   }
   return ShouldResistFingerprinting(aDocShell->GetDocument());
 }
 
 /* static */
-bool nsContentUtils::ShouldResistFingerprinting(const Document* aDoc) {
+bool nsContentUtils::ShouldResistFingerprinting(Document* aDoc) {
   if (!aDoc) {
     return false;
   }
   bool isChrome = nsContentUtils::IsChromeDoc(aDoc);
   return !isChrome && ShouldResistFingerprinting();
 }
 
 /* static */
@@ -6510,18 +6510,17 @@ nsContentUtils::FindInternalContentViewe
     }
     return docFactory.forget();
   }
 
   return nullptr;
 }
 
 static void ReportPatternCompileFailure(nsAString& aPattern,
-                                        const Document* aDocument,
-                                        JSContext* cx) {
+                                        Document* aDocument, JSContext* cx) {
   MOZ_ASSERT(JS_IsExceptionPending(cx));
 
   JS::RootedValue exn(cx);
   if (!JS_GetPendingException(cx, &exn)) {
     return;
   }
   if (!exn.isObject()) {
     // If pending exception is not an object, it should be OOM.
@@ -6550,17 +6549,17 @@ static void ReportPatternCompileFailure(
       nsIScriptError::errorFlag, NS_LITERAL_CSTRING("DOM"), aDocument,
       nsContentUtils::eDOM_PROPERTIES, "PatternAttributeCompileFailure",
       strings, ArrayLength(strings));
   savedExc.drop();
 }
 
 // static
 bool nsContentUtils::IsPatternMatching(nsAString& aValue, nsAString& aPattern,
-                                       const Document* aDocument) {
+                                       Document* aDocument) {
   NS_ASSERTION(aDocument, "aDocument should be a valid pointer (not null)");
 
   // The fact that we're using a JS regexp under the hood should not be visible
   // to things like window onerror handlers, so we don't initialize our JSAPI
   // with the document's window (which may not exist anyway).
   AutoJSAPI jsapi;
   jsapi.Init();
   JSContext* cx = jsapi.cx();
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -302,17 +302,17 @@ class nsContentUtils {
   static bool LookupBindingMember(
       JSContext* aCx, nsIContent* aContent, JS::Handle<jsid> aId,
       JS::MutableHandle<JS::PropertyDescriptor> aDesc);
 
   // Check whether we should avoid leaking distinguishing information to JS/CSS.
   // This function can be called both in the main thread and worker threads.
   static bool ShouldResistFingerprinting();
   static bool ShouldResistFingerprinting(nsIDocShell* aDocShell);
-  static bool ShouldResistFingerprinting(const Document* aDoc);
+  static bool ShouldResistFingerprinting(Document* aDoc);
 
   // Prevent system colors from being exposed to CSS or canvas.
   static bool UseStandinsForNativeColors();
 
   // A helper function to calculate the rounded window size for fingerprinting
   // resistance. The rounded size is based on the chrome UI size and available
   // screen size. If the inputWidth/Height is greater than the available content
   // size, this will report the available content size. Otherwise, it will
@@ -2541,17 +2541,17 @@ class nsContentUtils {
    * WARNING: This method mutates aPattern and aValue!
    *
    * @param aValue    the string to check.
    * @param aPattern  the string defining the pattern.
    * @param aDocument the owner document of the element.
    * @result          whether the given string is matches the pattern.
    */
   static bool IsPatternMatching(nsAString& aValue, nsAString& aPattern,
-                                const Document* aDocument);
+                                Document* aDocument);
 
   /**
    * Calling this adds support for
    * ontouch* event handler DOM attributes.
    */
   static void InitializeTouchEventTable();
 
   /**
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2640,17 +2640,16 @@ class CanvasUserSpaceMetrics : public Us
   }
 
   virtual float GetExLength() const override {
     nsDeviceContext* dc = mPresContext->DeviceContext();
     nsFontMetrics::Params params;
     params.language = mFontLanguage;
     params.explicitLanguage = mExplicitLanguage;
     params.textPerf = mPresContext->GetTextPerfMetrics();
-    params.featureValueLookup = mPresContext->GetFontFeatureValuesLookup();
     RefPtr<nsFontMetrics> fontMetrics = dc->GetMetricsFor(mFont, params);
     return NSAppUnitsToFloatPixels(fontMetrics->XHeight(),
                                    AppUnitsPerCSSPixel());
   }
 
   virtual gfx::Size GetSize() const override { return Size(mSize); }
 
  private:
--- a/gfx/src/nsFont.cpp
+++ b/gfx/src/nsFont.cpp
@@ -46,33 +46,35 @@ nsFont::MaxDifference nsFont::CalcDiffer
       (languageOverride != aOther.languageOverride) ||
       (variantAlternates != aOther.variantAlternates) ||
       (variantCaps != aOther.variantCaps) ||
       (variantEastAsian != aOther.variantEastAsian) ||
       (variantLigatures != aOther.variantLigatures) ||
       (variantNumeric != aOther.variantNumeric) ||
       (variantPosition != aOther.variantPosition) ||
       (variantWidth != aOther.variantWidth) ||
-      (alternateValues != aOther.alternateValues)) {
+      (alternateValues != aOther.alternateValues) ||
+      (featureValueLookup != aOther.featureValueLookup)) {
     return MaxDifference::eLayoutAffecting;
   }
 
   if ((smoothing != aOther.smoothing) ||
       (fontSmoothingBackgroundColor != aOther.fontSmoothingBackgroundColor)) {
     return MaxDifference::eVisual;
   }
 
   return MaxDifference::eNone;
 }
 
 nsFont& nsFont::operator=(const nsFont& aOther) = default;
 
 void nsFont::CopyAlternates(const nsFont& aOther) {
   variantAlternates = aOther.variantAlternates;
   alternateValues = aOther.alternateValues;
+  featureValueLookup = aOther.featureValueLookup;
 }
 
 // mapping from bitflag to font feature tag/value pair
 //
 // these need to be kept in sync with the constants listed
 // in gfxFontConstants.h (e.g. NS_FONT_VARIANT_EAST_ASIAN_JIS78)
 
 // NS_FONT_VARIANT_EAST_ASIAN_xxx values
@@ -179,16 +181,17 @@ void nsFont::AddFontFeaturesToStyle(gfxF
     setting.mValue = 1;
     setting.mTag = TRUETYPE_TAG('h', 'i', 's', 't');
     aStyle->featureSettings.AppendElement(setting);
   }
 
   // -- copy font-specific alternate info into style
   //    (this will be resolved after font-matching occurs)
   aStyle->alternateValues.AppendElements(alternateValues);
+  aStyle->featureValueLookup = featureValueLookup;
 
   // -- caps
   aStyle->variantCaps = variantCaps;
 
   // -- east-asian
   if (variantEastAsian) {
     AddFontFeaturesBitmask(variantEastAsian, NS_FONT_VARIANT_EAST_ASIAN_JIS78,
                            NS_FONT_VARIANT_EAST_ASIAN_RUBY, eastAsianDefaults,
--- a/gfx/src/nsFont.h
+++ b/gfx/src/nsFont.h
@@ -51,16 +51,19 @@ struct nsFont {
   nsTArray<gfxFontFeature> fontFeatureSettings;
 
   // Font variations from CSS font-variation-settings
   nsTArray<gfxFontVariation> fontVariationSettings;
 
   // -- list of value tags for font-specific alternate features
   nsTArray<gfxAlternateValue> alternateValues;
 
+  // -- object used to look these up once the font is matched
+  RefPtr<gfxFontFeatureValueSet> featureValueLookup;
+
   // The logical size of the font, in nscoord units
   nscoord size = 0;
 
   // The aspect-value (ie., the ratio actualsize:actualxheight) that any
   // actual physical font created from this font structure must have when
   // rendering or measuring a string. A value of -1.0 means no adjustment
   // needs to be done; otherwise the value must be nonnegative.
   float sizeAdjust = -1.0f;
--- a/gfx/src/nsFontMetrics.cpp
+++ b/gfx/src/nsFontMetrics.cpp
@@ -119,18 +119,16 @@ nsFontMetrics::nsFontMetrics(const nsFon
   gfxFontStyle style(
       aFont.style, aFont.weight, aFont.stretch, gfxFloat(aFont.size) / mP2A,
       aParams.language, aParams.explicitLanguage, aFont.sizeAdjust,
       aFont.systemFont, mDeviceContext->IsPrinterContext(),
       aFont.synthesis & NS_FONT_SYNTHESIS_WEIGHT,
       aFont.synthesis & NS_FONT_SYNTHESIS_STYLE, aFont.languageOverride);
 
   aFont.AddFontFeaturesToStyle(&style, mOrientation == gfxFont::eVertical);
-  style.featureValueLookup = aParams.featureValueLookup;
-
   aFont.AddFontVariationsToStyle(&style);
 
   gfxFloat devToCssSize = gfxFloat(mP2A) / gfxFloat(AppUnitsPerCSSPixel());
   mFontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(
       aFont.fontlist, &style, aParams.textPerf, aParams.userFontSet,
       devToCssSize);
 }
 
--- a/gfx/src/nsFontMetrics.h
+++ b/gfx/src/nsFontMetrics.h
@@ -49,17 +49,16 @@ class nsFontMetrics final {
   typedef mozilla::gfx::DrawTarget DrawTarget;
 
   struct MOZ_STACK_CLASS Params {
     nsAtom* language = nullptr;
     bool explicitLanguage = false;
     gfxFont::Orientation orientation = gfxFont::eHorizontal;
     gfxUserFontSet* userFontSet = nullptr;
     gfxTextPerfMetrics* textPerf = nullptr;
-    gfxFontFeatureValueSet* featureValueLookup = nullptr;
   };
 
   nsFontMetrics(const nsFont& aFont, const Params& aParams,
                 nsDeviceContext* aContext);
 
   // Used by stylo
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsFontMetrics)
 
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -9996,17 +9996,16 @@ void ReflowCountMgr::PaintCount(const ch
               devPixelOffset));
 
       // We don't care about the document language or user fonts here;
       // just get a default Latin font.
       nsFont font(eFamily_serif, nsPresContext::CSSPixelsToAppUnits(11));
       nsFontMetrics::Params params;
       params.language = nsGkAtoms::x_western;
       params.textPerf = aPresContext->GetTextPerfMetrics();
-      params.featureValueLookup = aPresContext->GetFontFeatureValuesLookup();
       RefPtr<nsFontMetrics> fm =
           aPresContext->DeviceContext()->GetMetricsFor(font, params);
 
       char buf[16];
       int len = SprintfLiteral(buf, "%d", counter->mCount);
       nscoord x = 0, y = fm->MaxAscent();
       nscoord width, height = fm->MaxHeight();
       fm->SetTextRunRTL(false);
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4446,17 +4446,16 @@ already_AddRefed<nsFontMetrics> nsLayout
   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.featureValueLookup = aPresContext->GetFontFeatureValuesLookup();
 
   // 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,
@@ -9551,23 +9550,24 @@ already_AddRefed<nsFontMetrics> nsLayout
       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();
-  params.featureValueLookup = aPresContext->GetFontFeatureValuesLookup();
   return aPresContext->DeviceContext()->GetMetricsFor(font, params);
 }
 
 /* static */ void nsLayoutUtils::FixupNoneGeneric(
-    nsFont* aFont, uint8_t aGenericFontID, const nsFont* aDefaultVariableFont) {
-  bool useDocumentFonts = StaticPrefs::browser_display_use_document_fonts();
+    nsFont* aFont, const nsPresContext* aPresContext, uint8_t aGenericFontID,
+    const nsFont* aDefaultVariableFont) {
+  bool useDocumentFonts =
+      aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts);
   if (aGenericFontID == kGenericFont_NONE ||
       (!useDocumentFonts && (aGenericFontID == kGenericFont_cursive ||
                              aGenericFontID == kGenericFont_fantasy))) {
     FontFamilyType defaultGeneric =
         aDefaultVariableFont->fontlist.GetDefaultFontType();
     MOZ_ASSERT(aDefaultVariableFont->fontlist.IsEmpty() &&
                (defaultGeneric == eFamily_serif ||
                 defaultGeneric == eFamily_sans_serif));
@@ -9582,30 +9582,30 @@ already_AddRefed<nsFontMetrics> nsLayout
         }
       }
     }
   } else {
     aFont->fontlist.SetDefaultFontType(eFamily_none);
   }
 }
 
-/* static */ void nsLayoutUtils::ApplyMinFontSize(nsStyleFont* aFont,
-                                                  const Document* aDocument,
-                                                  nscoord aMinFontSize) {
+/* static */ void nsLayoutUtils::ApplyMinFontSize(
+    nsStyleFont* aFont, const nsPresContext* aPresContext,
+    nscoord aMinFontSize) {
   nscoord fontSize = aFont->mSize;
 
   // enforce the user' specified minimum font-size on the value that we expose
   // (but don't change font-size:0, since that would unhide hidden text)
   if (fontSize > 0) {
     if (aMinFontSize < 0) {
       aMinFontSize = 0;
     } else {
       aMinFontSize = (aMinFontSize * aFont->mMinFontSizeRatio) / 100;
     }
-    if (fontSize < aMinFontSize && !nsContentUtils::IsChromeDoc(aDocument)) {
+    if (fontSize < aMinFontSize && !aPresContext->IsChrome()) {
       // override the minimum font-size constraint
       fontSize = aMinFontSize;
     }
   }
   aFont->mFont.size = fontSize;
 }
 
 /* static */ void nsLayoutUtils::ComputeSystemFont(
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2941,25 +2941,26 @@ class nsLayoutUtils {
   static already_AddRefed<nsFontMetrics> GetMetricsFor(
       nsPresContext* aPresContext, bool aIsVertical,
       const nsStyleFont* aStyleFont, nscoord aFontSize, bool aUseUserFontSet);
 
   /**
    * Appropriately add the correct font if we are using DocumentFonts or
    * overriding for XUL
    */
-  static void FixupNoneGeneric(nsFont* aFont, uint8_t aGenericFontID,
+  static void FixupNoneGeneric(nsFont* aFont, const nsPresContext* aPresContext,
+                               uint8_t aGenericFontID,
                                const nsFont* aDefaultVariableFont);
 
   /**
    * For an nsStyleFont with mSize set, apply minimum font size constraints
    * from preferences, as well as -moz-min-font-size-ratio.
    */
   static void ApplyMinFontSize(nsStyleFont* aFont,
-                               const mozilla::dom::Document*,
+                               const nsPresContext* aPresContext,
                                nscoord aMinFontSize);
 
   static void ComputeSystemFont(nsFont* aSystemFont,
                                 mozilla::LookAndFeel::FontID aFontID,
                                 const nsFont* aDefaultVariableFont);
 
   static void ComputeFontFeatures(const nsCSSValuePairList* aFeaturesList,
                                   nsTArray<gfxFontFeature>& aFeatureSettings);
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -189,16 +189,17 @@ nsPresContext::nsPresContext(dom::Docume
       mInterruptChecksToSkip(0),
       mElementsRestyled(0),
       mFramesConstructed(0),
       mFramesReflowed(0),
       mInteractionTimeEnabled(true),
       mHasPendingInterrupt(false),
       mPendingInterruptFromTest(false),
       mInterruptsEnabled(false),
+      mUseDocumentFonts(true),
       mUseDocumentColors(true),
       mUnderlineLinks(true),
       mSendAfterPaintToContent(false),
       mUseFocusColors(false),
       mFocusRingOnAnything(false),
       mFocusRingStyle(false),
       mDrawImageBackground(true),  // always draw the background
       mDrawColorBackground(true),
@@ -512,16 +513,20 @@ void nsPresContext::GetUserPreferences()
   mFocusRingOnAnything = Preferences::GetBool(
       "browser.display.focus_ring_on_anything", mFocusRingOnAnything);
 
   mFocusRingStyle =
       Preferences::GetInt("browser.display.focus_ring_style", mFocusRingStyle);
 
   mBodyTextColor = mDefaultColor;
 
+  // * use fonts?
+  mUseDocumentFonts =
+      Preferences::GetInt("browser.display.use_document_fonts") != 0;
+
   mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
 
   Document()->ResetLangPrefs();
 
   // * image animation
   nsAutoCString animatePref;
   Preferences::GetCString("image.animation_mode", animatePref);
   if (animatePref.EqualsLiteral("normal"))
--- a/layout/base/nsPresContext.h
+++ b/layout/base/nsPresContext.h
@@ -82,20 +82,20 @@ class LayerManager;
 }  // namespace layers
 namespace dom {
 class Document;
 class Element;
 }  // namespace dom
 }  // namespace mozilla
 
 // supported values for cached bool types
-//
-// FIXME(emilio): We have StaticPrefs now, probably all of these should be
-// migrated.
-enum nsPresContext_CachedBoolPrefType { kPresContext_UnderlineLinks = 1 };
+enum nsPresContext_CachedBoolPrefType {
+  kPresContext_UseDocumentFonts = 1,
+  kPresContext_UnderlineLinks
+};
 
 // supported values for cached integer pref types
 enum nsPresContext_CachedIntPrefType {
   kPresContext_ScrollbarSide = 1,
   kPresContext_BidiDirection
 };
 
 // IDs for the default variable and fixed fonts (not to be changed, see
@@ -360,16 +360,18 @@ class nsPresContext : public nsISupports
   void StopEmulatingMedium();
 
   /** Get a cached boolean pref, by its type */
   // *  - initially created for bugs 31816, 20760, 22963
   bool GetCachedBoolPref(nsPresContext_CachedBoolPrefType aPrefType) const {
     // If called with a constant parameter, the compiler should optimize
     // this switch statement away.
     switch (aPrefType) {
+      case kPresContext_UseDocumentFonts:
+        return mUseDocumentFonts;
       case kPresContext_UnderlineLinks:
         return mUnderlineLinks;
       default:
         NS_ERROR("Invalid arg passed to GetCachedBoolPref");
     }
 
     return false;
   }
@@ -1276,16 +1278,17 @@ class nsPresContext : public nsISupports
   bool mInteractionTimeEnabled;
 
   // last time we did a full style flush
   mozilla::TimeStamp mLastStyleUpdateForAllAnimations;
 
   unsigned mHasPendingInterrupt : 1;
   unsigned mPendingInterruptFromTest : 1;
   unsigned mInterruptsEnabled : 1;
+  unsigned mUseDocumentFonts : 1;
   unsigned mUseDocumentColors : 1;
   unsigned mUnderlineLinks : 1;
   unsigned mSendAfterPaintToContent : 1;
   unsigned mUseFocusColors : 1;
   unsigned mFocusRingOnAnything : 1;
   unsigned mFocusRingStyle : 1;
   unsigned mDrawImageBackground : 1;
   unsigned mDrawColorBackground : 1;
--- a/layout/generic/MathMLTextRunFactory.cpp
+++ b/layout/generic/MathMLTextRunFactory.cpp
@@ -635,17 +635,16 @@ void MathMLTextRunFactory::RebuildTextRu
   if (length) {
     font.size = NSToCoordRound(font.size * mFontInflation);
     nsPresContext* pc = styles[0]->mPresContext;
     nsFontMetrics::Params params;
     params.language = styles[0]->mLanguage;
     params.explicitLanguage = styles[0]->mExplicitLanguage;
     params.userFontSet = pc->GetUserFontSet();
     params.textPerf = pc->GetTextPerfMetrics();
-    params.featureValueLookup = pc->GetFontFeatureValuesLookup();
     RefPtr<nsFontMetrics> metrics =
         pc->DeviceContext()->GetMetricsFor(font, params);
     newFontGroup = metrics->GetThebesFontGroup();
   }
 
   if (!newFontGroup) {
     // If we can't get a new font group, fall back to the old one.  Rendering
     // will be incorrect, but not significantly so.
--- a/layout/generic/nsPageFrame.cpp
+++ b/layout/generic/nsPageFrame.cpp
@@ -580,17 +580,16 @@ void nsPageFrame::PaintHeaderFooter(gfxC
 
   DrawTargetAutoDisableSubpixelAntialiasing disable(
       aRenderingContext.GetDrawTarget(), aDisableSubpixelAA);
 
   // Get the FontMetrics to determine width.height of strings
   nsFontMetrics::Params params;
   params.userFontSet = pc->GetUserFontSet();
   params.textPerf = pc->GetTextPerfMetrics();
-  params.featureValueLookup = pc->GetFontFeatureValuesLookup();
   RefPtr<nsFontMetrics> fontMet =
       pc->DeviceContext()->GetMetricsFor(mPD->mHeadFootFont, params);
 
   nscoord ascent = 0;
   nscoord visibleHeight = 0;
   if (fontMet) {
     visibleHeight = fontMet->MaxHeight();
     ascent = fontMet->MaxAscent();
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -878,17 +878,16 @@ bool nsMathMLChar::SetFontFamily(nsPresC
     nsFont font = aFont;
     font.fontlist = familyList;
     const nsStyleFont* styleFont = mComputedStyle->StyleFont();
     nsFontMetrics::Params params;
     params.language = styleFont->mLanguage;
     params.explicitLanguage = styleFont->mExplicitLanguage;
     params.userFontSet = aPresContext->GetUserFontSet();
     params.textPerf = aPresContext->GetTextPerfMetrics();
-    params.featureValueLookup = aPresContext->GetFontFeatureValuesLookup();
     RefPtr<nsFontMetrics> fm =
         aPresContext->DeviceContext()->GetMetricsFor(font, params);
     // Set the font if it is an unicode table
     // or if the same family name has been found
     gfxFont* firstFont = fm->GetThebesFontGroup()->GetFirstValidFont();
     FontFamilyList firstFontList(firstFont->GetFontEntry()->FamilyName(),
                                  eUnquotedName);
     if (aGlyphTable == &gGlyphTableList->mUnicodeTable ||
--- a/layout/style/CSSMozDocumentRule.cpp
+++ b/layout/style/CSSMozDocumentRule.cpp
@@ -14,17 +14,17 @@ namespace dom {
 
 using namespace mozilla::css;
 
 /* virtual */ JSObject* CSSMozDocumentRule::WrapObject(
     JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
   return CSSMozDocumentRule_Binding::Wrap(aCx, this, aGivenProto);
 }
 
-bool CSSMozDocumentRule::Match(const Document* aDoc, nsIURI* aDocURI,
+bool CSSMozDocumentRule::Match(Document* aDoc, nsIURI* aDocURI,
                                const nsACString& aDocURISpec,
                                const nsACString& aPattern,
                                DocumentMatchingFunction aMatchingFunction) {
   switch (aMatchingFunction) {
     case DocumentMatchingFunction::MediaDocument: {
       auto kind = aDoc->MediaDocumentKind();
       if (aPattern.EqualsLiteral("all")) {
         return kind != Document::MediaDocumentKind::NotMedia;
--- a/layout/style/CSSMozDocumentRule.h
+++ b/layout/style/CSSMozDocumentRule.h
@@ -17,17 +17,17 @@ namespace dom {
 class CSSMozDocumentRule final : public css::ConditionRule {
  public:
   CSSMozDocumentRule(RefPtr<RawServoMozDocumentRule> aRawRule,
                      StyleSheet* aSheet, css::Rule* aParentRule, uint32_t aLine,
                      uint32_t aColumn);
 
   NS_DECL_ISUPPORTS_INHERITED
 
-  static bool Match(const Document*, nsIURI* aDocURI,
+  static bool Match(Document* aDoc, nsIURI* aDocURI,
                     const nsACString& aDocURISpec, const nsACString& aPattern,
                     css::DocumentMatchingFunction);
 
 #ifdef DEBUG
   void List(FILE* out = stdout, int32_t aIndent = 0) const final;
 #endif
 
   RawServoMozDocumentRule* Raw() const { return mRawRule; }
--- a/layout/style/GeckoBindings.cpp
+++ b/layout/style/GeckoBindings.cpp
@@ -96,24 +96,24 @@ SERVO_ARC_TYPE(ComputedStyle, ComputedSt
 #undef SERVO_ARC_TYPE
 
 // Definitions of the global traversal stats.
 bool ServoTraversalStatistics::sActive = false;
 ServoTraversalStatistics ServoTraversalStatistics::sSingleton;
 
 static RWLock* sServoFFILock = nullptr;
 
-static const nsFont* ThreadSafeGetDefaultFontHelper(const Document& aDocument,
-                                                    nsAtom* aLanguage,
-                                                    uint8_t aGenericId) {
+static const nsFont* ThreadSafeGetDefaultFontHelper(
+    const nsPresContext* aPresContext, nsAtom* aLanguage, uint8_t aGenericId) {
   bool needsCache = false;
   const nsFont* retval;
 
   auto GetDefaultFont = [&](bool* aNeedsToCache) {
-    auto* prefs = aDocument.GetFontPrefsForLang(aLanguage, aNeedsToCache);
+    auto* prefs =
+        aPresContext->Document()->GetFontPrefsForLang(aLanguage, aNeedsToCache);
     return prefs ? prefs->GetDefaultFont(aGenericId) : nullptr;
   };
 
   {
     AutoReadLock guard(*sServoFFILock);
     retval = GetDefaultFont(&needsCache);
   }
   if (!needsCache) {
@@ -705,18 +705,19 @@ void Gecko_FillAllImageLayers(nsStyleIma
   aLayers->FillAllLayers(aMaxLen);
 }
 
 bool Gecko_IsDocumentBody(RawGeckoElementBorrowed aElement) {
   Document* doc = aElement->GetUncomposedDoc();
   return doc && doc->GetBodyElement() == aElement;
 }
 
-nscolor Gecko_GetLookAndFeelSystemColor(int32_t aId, const Document* aDoc) {
-  bool useStandinsForNativeColors = !nsContentUtils::IsChromeDoc(aDoc);
+nscolor Gecko_GetLookAndFeelSystemColor(
+    int32_t aId, RawGeckoPresContextBorrowed aPresContext) {
+  bool useStandinsForNativeColors = aPresContext && !aPresContext->IsChrome();
   nscolor result;
   LookAndFeel::ColorID colorId = static_cast<LookAndFeel::ColorID>(aId);
   AutoWriteLock guard(*sServoFFILock);
   LookAndFeel::GetColor(colorId, useStandinsForNativeColors, &result);
   return result;
 }
 
 bool Gecko_MatchLang(RawGeckoElementBorrowed aElement, nsAtom* aOverrideLang,
@@ -1007,25 +1008,27 @@ size_t Gecko_SharedFontList_SizeOfInclud
 NS_IMPL_THREADSAFE_FFI_REFCOUNTING(mozilla::SharedFontList, SharedFontList);
 
 void Gecko_CopyFontFamilyFrom(nsFont* dst, const nsFont* src) {
   dst->fontlist = src->fontlist;
 }
 
 void Gecko_nsFont_InitSystem(nsFont* aDest, int32_t aFontId,
                              const nsStyleFont* aFont,
-                             const Document* aDocument) {
+                             RawGeckoPresContextBorrowed aPresContext) {
   const nsFont* defaultVariableFont = ThreadSafeGetDefaultFontHelper(
-      *aDocument, aFont->mLanguage, kPresContext_DefaultVariableFont_ID);
+      aPresContext, aFont->mLanguage, kPresContext_DefaultVariableFont_ID);
 
   // We have passed uninitialized memory to this function,
   // initialize it. We can't simply return an nsFont because then
   // we need to know its size beforehand. Servo cannot initialize nsFont
   // itself, so this will do.
-  new (aDest) nsFont(*defaultVariableFont);
+  nsFont* system = new (aDest) nsFont(*defaultVariableFont);
+
+  MOZ_RELEASE_ASSERT(system);
 
   *aDest = *defaultVariableFont;
   LookAndFeel::FontID fontID = static_cast<LookAndFeel::FontID>(aFontId);
 
   AutoWriteLock guard(*sServoFFILock);
   nsLayoutUtils::ComputeSystemFont(aDest, fontID, defaultVariableFont);
 }
 
@@ -1040,16 +1043,21 @@ nsTArray<unsigned int>* Gecko_AppendFeat
     uint32_t aAlternate, nsAtom* aName) {
   MOZ_ASSERT(NS_IsMainThread());
   static_assert(sizeof(unsigned int) == sizeof(uint32_t),
                 "sizeof unsigned int and uint32_t must be the same");
   return aFontFeatureValues->AppendFeatureValueHashEntry(
       nsAtomCString(aFamily), nsDependentAtomString(aName), aAlternate);
 }
 
+void Gecko_nsFont_SetFontFeatureValuesLookup(
+    nsFont* aFont, const RawGeckoPresContext* aPresContext) {
+  aFont->featureValueLookup = aPresContext->GetFontFeatureValuesLookup();
+}
+
 float Gecko_FontStretch_ToFloat(mozilla::FontStretch aStretch) {
   // Servo represents percentages with 1. being 100%.
   return aStretch.Percentage() / 100.0f;
 }
 
 void Gecko_FontStretch_SetFloat(mozilla::FontStretch* aStretch, float aFloat) {
   // Servo represents percentages with 1. being 100%.
   //
@@ -1083,33 +1091,39 @@ void Gecko_FontSlantStyle_Get(mozilla::F
 float Gecko_FontWeight_ToFloat(mozilla::FontWeight aWeight) {
   return aWeight.ToFloat();
 }
 
 void Gecko_FontWeight_SetFloat(mozilla::FontWeight* aWeight, float aFloat) {
   *aWeight = mozilla::FontWeight(aFloat);
 }
 
+void Gecko_nsFont_ResetFontFeatureValuesLookup(nsFont* aFont) {
+  aFont->featureValueLookup = nullptr;
+}
+
 void Gecko_ClearAlternateValues(nsFont* aFont, size_t aLength) {
   aFont->alternateValues.Clear();
   aFont->alternateValues.SetCapacity(aLength);
 }
 
 void Gecko_AppendAlternateValues(nsFont* aFont, uint32_t aAlternateName,
                                  nsAtom* aAtom) {
   aFont->alternateValues.AppendElement(
       gfxAlternateValue{aAlternateName, nsDependentAtomString(aAtom)});
 }
 
 void Gecko_CopyAlternateValuesFrom(nsFont* aDest, const nsFont* aSrc) {
   aDest->alternateValues.Clear();
   aDest->alternateValues.AppendElements(aSrc->alternateValues);
+  aDest->featureValueLookup = aSrc->featureValueLookup;
 }
 
-void Gecko_SetCounterStyleToName(CounterStylePtr* aPtr, nsAtom* aName) {
+void Gecko_SetCounterStyleToName(CounterStylePtr* aPtr, nsAtom* aName,
+                                 RawGeckoPresContextBorrowed aPresContext) {
   RefPtr<nsAtom> name = already_AddRefed<nsAtom>(aName);
   *aPtr = name.forget();
 }
 
 void Gecko_SetCounterStyleToSymbols(CounterStylePtr* aPtr, uint8_t aSymbolsType,
                                     nsACString const* const* aSymbols,
                                     uint32_t aSymbolsCount) {
   nsTArray<nsString> symbols(aSymbolsCount);
@@ -1888,63 +1902,63 @@ void Gecko_nsStyleFont_SetLang(nsStyleFo
   aFont->mExplicitLanguage = true;
 }
 
 void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont,
                                     const nsStyleFont* aSource) {
   aFont->mLanguage = aSource->mLanguage;
 }
 
-void Gecko_nsStyleFont_FixupNoneGeneric(nsStyleFont* aFont,
-                                        const Document* aDocument) {
+void Gecko_nsStyleFont_FixupNoneGeneric(
+    nsStyleFont* aFont, RawGeckoPresContextBorrowed aPresContext) {
   const nsFont* defaultVariableFont = ThreadSafeGetDefaultFontHelper(
-      *aDocument, aFont->mLanguage, kPresContext_DefaultVariableFont_ID);
-  nsLayoutUtils::FixupNoneGeneric(&aFont->mFont, aFont->mGenericID,
-                                  defaultVariableFont);
+      aPresContext, aFont->mLanguage, kPresContext_DefaultVariableFont_ID);
+  nsLayoutUtils::FixupNoneGeneric(&aFont->mFont, aPresContext,
+                                  aFont->mGenericID, defaultVariableFont);
 }
 
-void Gecko_nsStyleFont_PrefillDefaultForGeneric(nsStyleFont* aFont,
-                                                const Document* aDocument,
-                                                uint8_t aGenericId) {
-  const nsFont* defaultFont =
-      ThreadSafeGetDefaultFontHelper(*aDocument, aFont->mLanguage, aGenericId);
+void Gecko_nsStyleFont_PrefillDefaultForGeneric(
+    nsStyleFont* aFont, RawGeckoPresContextBorrowed aPresContext,
+    uint8_t aGenericId) {
+  const nsFont* defaultFont = ThreadSafeGetDefaultFontHelper(
+      aPresContext, aFont->mLanguage, aGenericId);
   // In case of just the language changing, the parent could have had no
   // generic, which Gecko just does regular cascading with. Do the same. This
   // can only happen in the case where the language changed but the family did
   // not
   if (aGenericId != kGenericFont_NONE) {
     aFont->mFont.fontlist = defaultFont->fontlist;
   } else {
     aFont->mFont.fontlist.SetDefaultFontType(
         defaultFont->fontlist.GetDefaultFontType());
   }
 }
 
-void Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* aFont,
-                                        const Document* aDocument) {
+void Gecko_nsStyleFont_FixupMinFontSize(
+    nsStyleFont* aFont, RawGeckoPresContextBorrowed aPresContext) {
   nscoord minFontSize;
   bool needsCache = false;
 
   auto MinFontSize = [&](bool* aNeedsToCache) {
-    auto* prefs =
-        aDocument->GetFontPrefsForLang(aFont->mLanguage, aNeedsToCache);
+    auto* prefs = aPresContext->Document()->GetFontPrefsForLang(
+        aFont->mLanguage, aNeedsToCache);
     return prefs ? prefs->mMinimumFontSize : 0;
   };
 
   {
     AutoReadLock guard(*sServoFFILock);
     minFontSize = MinFontSize(&needsCache);
   }
 
   if (needsCache) {
     AutoWriteLock guard(*sServoFFILock);
     minFontSize = MinFontSize(nullptr);
   }
 
-  nsLayoutUtils::ApplyMinFontSize(aFont, aDocument, minFontSize);
+  nsLayoutUtils::ApplyMinFontSize(aFont, aPresContext, minFontSize);
 }
 
 void FontSizePrefs::CopyFrom(const LangGroupFontPrefs& prefs) {
   mDefaultVariableSize = prefs.mDefaultVariableFont.size;
   mDefaultFixedSize = prefs.mDefaultFixedFont.size;
   mDefaultSerifSize = prefs.mDefaultSerifFont.size;
   mDefaultSansSerifSize = prefs.mDefaultSansSerifFont.size;
   mDefaultMonospaceSize = prefs.mDefaultMonospaceFont.size;
@@ -2039,16 +2053,22 @@ GeckoFontMetrics Gecko_GetFontMetrics(Ra
   gfxFloat zeroWidth = fm->GetThebesFontGroup()
                            ->GetFirstValidFont()
                            ->GetMetrics(fm->Orientation())
                            .zeroOrAveCharWidth;
   ret.mChSize = NS_round(aPresContext->AppUnitsPerDevPixel() * zeroWidth);
   return ret;
 }
 
+int32_t Gecko_GetAppUnitsPerPhysicalInch(
+    RawGeckoPresContextBorrowed aPresContext) {
+  nsPresContext* presContext = const_cast<nsPresContext*>(aPresContext);
+  return presContext->DeviceContext()->AppUnitsPerPhysicalInch();
+}
+
 NS_IMPL_THREADSAFE_FFI_REFCOUNTING(SheetLoadDataHolder, SheetLoadDataHolder);
 
 void Gecko_StyleSheet_FinishAsyncParse(
     SheetLoadDataHolder* aData, RawServoStyleSheetContentsStrong aSheetContents,
     StyleUseCountersOwned aUseCounters) {
   UniquePtr<StyleUseCounters> useCounters(aUseCounters);
   RefPtr<SheetLoadDataHolder> loadData = aData;
   RefPtr<RawServoStyleSheetContents> sheetContents = aSheetContents.Consume();
@@ -2167,19 +2187,19 @@ void Gecko_AddPropertyToSet(nsCSSPropert
                             nsCSSPropertyID aProperty) {
   aPropertySet->AddProperty(aProperty);
 }
 
 NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsCSSValueSharedList, CSSValueSharedList);
 
 #define STYLE_STRUCT(name)                                             \
                                                                        \
-  void Gecko_Construct_Default_nsStyle##name(nsStyle##name* ptr,       \
-                                             const Document* doc) {    \
-    new (ptr) nsStyle##name(*doc);                                     \
+  void Gecko_Construct_Default_nsStyle##name(                          \
+      nsStyle##name* ptr, const nsPresContext* pres_context) {         \
+    new (ptr) nsStyle##name(*pres_context->Document());                \
   }                                                                    \
                                                                        \
   void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr,           \
                                          const nsStyle##name* other) { \
     new (ptr) nsStyle##name(*other);                                   \
   }                                                                    \
                                                                        \
   void Gecko_Destroy_nsStyle##name(nsStyle##name* ptr) {               \
@@ -2188,29 +2208,30 @@ NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsCSS
 
 void Gecko_RegisterProfilerThread(const char* name) {
   PROFILER_REGISTER_THREAD(name);
 }
 
 void Gecko_UnregisterProfilerThread() { PROFILER_UNREGISTER_THREAD(); }
 
 bool Gecko_DocumentRule_UseForPresentation(
-    const Document* aDocument, const nsACString* aPattern,
+    RawGeckoPresContextBorrowed aPresContext, const nsACString* aPattern,
     css::DocumentMatchingFunction aMatchingFunction) {
   MOZ_ASSERT(NS_IsMainThread());
 
-  nsIURI* docURI = aDocument->GetDocumentURI();
+  Document* doc = aPresContext->Document();
+  nsIURI* docURI = doc->GetDocumentURI();
   nsAutoCString docURISpec;
   if (docURI) {
     // If GetSpec fails (due to OOM) just skip these URI-specific CSS rules.
     nsresult rv = docURI->GetSpec(docURISpec);
     NS_ENSURE_SUCCESS(rv, false);
   }
 
-  return CSSMozDocumentRule::Match(aDocument, docURI, docURISpec, *aPattern,
+  return CSSMozDocumentRule::Match(doc, docURI, docURISpec, *aPattern,
                                    aMatchingFunction);
 }
 
 void Gecko_SetJemallocThreadLocalArena(bool enabled) {
 #if defined(MOZ_MEMORY)
   jemalloc_thread_local_arena(enabled);
 #endif
 }
--- a/layout/style/GeckoBindings.h
+++ b/layout/style/GeckoBindings.h
@@ -273,27 +273,32 @@ size_t Gecko_SharedFontList_SizeOfInclud
     mozilla::SharedFontList* fontlist);
 
 NS_DECL_THREADSAFE_FFI_REFCOUNTING(mozilla::SharedFontList, SharedFontList);
 
 // will not run destructors on dst, give it uninitialized memory
 // font_id is LookAndFeel::FontID
 void Gecko_nsFont_InitSystem(nsFont* dst, int32_t font_id,
                              const nsStyleFont* font,
-                             const mozilla::dom::Document*);
+                             RawGeckoPresContextBorrowed pres_context);
 
 void Gecko_nsFont_Destroy(nsFont* dst);
 
 // The gfxFontFeatureValueSet returned from this function has zero reference.
 gfxFontFeatureValueSet* Gecko_ConstructFontFeatureValueSet();
 
 nsTArray<unsigned int>* Gecko_AppendFeatureValueHashEntry(
     gfxFontFeatureValueSet* value_set, nsAtom* family, uint32_t alternate,
     nsAtom* name);
 
+void Gecko_nsFont_SetFontFeatureValuesLookup(
+    nsFont* font, const RawGeckoPresContext* pres_context);
+
+void Gecko_nsFont_ResetFontFeatureValuesLookup(nsFont* font);
+
 // Font variant alternates
 void Gecko_ClearAlternateValues(nsFont* font, size_t length);
 
 void Gecko_AppendAlternateValues(nsFont* font, uint32_t alternate_name,
                                  nsAtom* atom);
 
 void Gecko_CopyAlternateValuesFrom(nsFont* dest, const nsFont* src);
 
@@ -303,17 +308,18 @@ void Gecko_SetImageOrientation(nsStyleVi
 
 void Gecko_SetImageOrientationAsFromImage(nsStyleVisibility* aVisibility);
 
 void Gecko_CopyImageOrientationFrom(nsStyleVisibility* aDst,
                                     const nsStyleVisibility* aSrc);
 
 // Counter style.
 // This function takes an already addrefed nsAtom
-void Gecko_SetCounterStyleToName(mozilla::CounterStylePtr* ptr, nsAtom* name);
+void Gecko_SetCounterStyleToName(mozilla::CounterStylePtr* ptr, nsAtom* name,
+                                 RawGeckoPresContextBorrowed pres_context);
 
 void Gecko_SetCounterStyleToSymbols(mozilla::CounterStylePtr* ptr,
                                     uint8_t symbols_type,
                                     nsACString const* const* symbols,
                                     uint32_t symbols_count);
 
 void Gecko_SetCounterStyleToString(mozilla::CounterStylePtr* ptr,
                                    const nsACString* symbol);
@@ -660,25 +666,25 @@ float Gecko_FontWeight_ToFloat(mozilla::
 
 void Gecko_FontWeight_SetFloat(mozilla::FontWeight* aWeight, float aFloatValue);
 
 void Gecko_nsStyleFont_SetLang(nsStyleFont* font, nsAtom* atom);
 
 void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont,
                                     const nsStyleFont* aSource);
 
-void Gecko_nsStyleFont_FixupNoneGeneric(nsStyleFont* font,
-                                        const mozilla::dom::Document*);
+void Gecko_nsStyleFont_FixupNoneGeneric(
+    nsStyleFont* font, RawGeckoPresContextBorrowed pres_context);
 
-void Gecko_nsStyleFont_PrefillDefaultForGeneric(nsStyleFont* font,
-                                                const mozilla::dom::Document*,
-                                                uint8_t generic_id);
+void Gecko_nsStyleFont_PrefillDefaultForGeneric(
+    nsStyleFont* font, RawGeckoPresContextBorrowed pres_context,
+    uint8_t generic_id);
 
-void Gecko_nsStyleFont_FixupMinFontSize(nsStyleFont* font,
-                                        const mozilla::dom::Document*);
+void Gecko_nsStyleFont_FixupMinFontSize(
+    nsStyleFont* font, RawGeckoPresContextBorrowed pres_context);
 
 mozilla::FontSizePrefs Gecko_GetBaseSize(nsAtom* lang);
 
 // XBL related functions.
 RawGeckoElementBorrowedOrNull Gecko_GetBindingParent(
     RawGeckoElementBorrowed aElement);
 
 RawServoAuthorStylesBorrowedOrNull Gecko_XBLBinding_GetRawServoStyles(
@@ -691,48 +697,51 @@ struct GeckoFontMetrics {
   nscoord mXSize;
 };
 
 GeckoFontMetrics Gecko_GetFontMetrics(RawGeckoPresContextBorrowed pres_context,
                                       bool is_vertical, const nsStyleFont* font,
                                       nscoord font_size,
                                       bool use_user_font_set);
 
+int32_t Gecko_GetAppUnitsPerPhysicalInch(
+    RawGeckoPresContextBorrowed pres_context);
+
 mozilla::StyleSheet* Gecko_StyleSheet_Clone(
     const mozilla::StyleSheet* aSheet,
     const mozilla::StyleSheet* aNewParentSheet);
 
 void Gecko_StyleSheet_AddRef(const mozilla::StyleSheet* aSheet);
 void Gecko_StyleSheet_Release(const mozilla::StyleSheet* aSheet);
 nsCSSKeyword Gecko_LookupCSSKeyword(const uint8_t* string, uint32_t len);
 const char* Gecko_CSSKeywordString(nsCSSKeyword keyword, uint32_t* len);
 bool Gecko_IsDocumentBody(RawGeckoElementBorrowed element);
 
 // We use an int32_t here instead of a LookAndFeel::ColorID
 // because forward-declaring a nested enum/struct is impossible
-nscolor Gecko_GetLookAndFeelSystemColor(int32_t color_id,
-                                        const mozilla::dom::Document*);
+nscolor Gecko_GetLookAndFeelSystemColor(
+    int32_t color_id, RawGeckoPresContextBorrowed pres_context);
 
 void Gecko_AddPropertyToSet(nsCSSPropertyIDSetBorrowedMut, nsCSSPropertyID);
 
 // Style-struct management.
-#define STYLE_STRUCT(name)                                                   \
-  void Gecko_Construct_Default_nsStyle##name(nsStyle##name* ptr,             \
-                                             const mozilla::dom::Document*); \
-  void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr,                 \
-                                         const nsStyle##name* other);        \
+#define STYLE_STRUCT(name)                                            \
+  void Gecko_Construct_Default_nsStyle##name(                         \
+      nsStyle##name* ptr, RawGeckoPresContextBorrowed pres_context);  \
+  void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr,          \
+                                         const nsStyle##name* other); \
   void Gecko_Destroy_nsStyle##name(nsStyle##name* ptr);
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
 
 void Gecko_RegisterProfilerThread(const char* name);
 void Gecko_UnregisterProfilerThread();
 
 bool Gecko_DocumentRule_UseForPresentation(
-    const mozilla::dom::Document*, const nsACString* aPattern,
+    RawGeckoPresContextBorrowed, const nsACString* aPattern,
     mozilla::css::DocumentMatchingFunction);
 
 // Allocator hinting.
 void Gecko_SetJemallocThreadLocalArena(bool enabled);
 void Gecko_AddBufferToCrashReport(const void* addr, size_t len);
 void Gecko_AnnotateCrashReport(uint32_t key, const char* value_str);
 
 // Pseudo-element flags.
@@ -776,39 +785,38 @@ bool Gecko_IsInServoTraversal();
 
 // Returns true if we're currently on the main thread.
 bool Gecko_IsMainThread();
 
 // Media feature helpers.
 //
 // Defined in nsMediaFeatures.cpp.
 mozilla::StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(
-    const mozilla::dom::Document*);
+    mozilla::dom::Document*);
 
-uint32_t Gecko_MediaFeatures_GetColorDepth(const mozilla::dom::Document*);
+uint32_t Gecko_MediaFeatures_GetColorDepth(mozilla::dom::Document*);
 
-void Gecko_MediaFeatures_GetDeviceSize(const mozilla::dom::Document*,
-                                       nscoord* width, nscoord* height);
+void Gecko_MediaFeatures_GetDeviceSize(mozilla::dom::Document*, nscoord* width,
+                                       nscoord* height);
 
-float Gecko_MediaFeatures_GetResolution(const mozilla::dom::Document*);
-bool Gecko_MediaFeatures_PrefersReducedMotion(const mozilla::dom::Document*);
+float Gecko_MediaFeatures_GetResolution(mozilla::dom::Document*);
+bool Gecko_MediaFeatures_PrefersReducedMotion(mozilla::dom::Document*);
 mozilla::StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme(
-    const mozilla::dom::Document*);
+    mozilla::dom::Document*);
 
 mozilla::PointerCapabilities Gecko_MediaFeatures_PrimaryPointerCapabilities(
-    const mozilla::dom::Document*);
+    mozilla::dom::Document*);
 
 mozilla::PointerCapabilities Gecko_MediaFeatures_AllPointerCapabilities(
-    const mozilla::dom::Document*);
+    mozilla::dom::Document*);
 
-float Gecko_MediaFeatures_GetDevicePixelRatio(const mozilla::dom::Document*);
+float Gecko_MediaFeatures_GetDevicePixelRatio(mozilla::dom::Document*);
 
-bool Gecko_MediaFeatures_HasSystemMetric(const mozilla::dom::Document*,
+bool Gecko_MediaFeatures_HasSystemMetric(mozilla::dom::Document*,
                                          nsAtom* metric,
                                          bool is_accessible_from_content);
 
-bool Gecko_MediaFeatures_IsResourceDocument(const mozilla::dom::Document*);
-nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(
-    const mozilla::dom::Document*);
+bool Gecko_MediaFeatures_IsResourceDocument(mozilla::dom::Document*);
+nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(mozilla::dom::Document*);
 
 }  // extern "C"
 
 #endif  // mozilla_GeckoBindings_h
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -20,17 +20,16 @@
 #include "mozilla/dom/Document.h"
 #include "nsIWidget.h"
 #include "nsContentUtils.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/GeckoBindings.h"
 
 using namespace mozilla;
-using mozilla::dom::Document;
 
 static nsTArray<const nsStaticAtom*>* sSystemMetrics = nullptr;
 
 #ifdef XP_WIN
 struct OperatingSystemVersionInfo {
   LookAndFeel::OperatingSystemVersion mId;
   nsStaticAtom* const mName;
 };
@@ -38,17 +37,17 @@ struct OperatingSystemVersionInfo {
 // Os version identities used in the -moz-os-version media query.
 const OperatingSystemVersionInfo kOsVersionStrings[] = {
     {LookAndFeel::eOperatingSystemVersion_Windows7, nsGkAtoms::windows_win7},
     {LookAndFeel::eOperatingSystemVersion_Windows8, nsGkAtoms::windows_win8},
     {LookAndFeel::eOperatingSystemVersion_Windows10, nsGkAtoms::windows_win10}};
 #endif
 
 // A helper for four features below
-static nsSize GetSize(const Document* aDocument) {
+static nsSize GetSize(Document* aDocument) {
   nsPresContext* pc = aDocument->GetPresContext();
 
   // Per spec, return a 0x0 viewport if we're not being rendered. See:
   //
   //  * https://github.com/w3c/csswg-drafts/issues/571
   //  * https://github.com/whatwg/html/issues/1813
   //
   if (!pc) {
@@ -60,26 +59,26 @@ static nsSize GetSize(const Document* aD
     //
     // FIXME(emilio, bug 1414600): Not quite!
     return pc->GetPageSize();
   }
 
   return pc->GetVisibleArea().Size();
 }
 
-static bool IsDeviceSizePageSize(const Document* aDocument) {
+static bool IsDeviceSizePageSize(Document* aDocument) {
   nsIDocShell* docShell = aDocument->GetDocShell();
   if (!docShell) {
     return false;
   }
   return docShell->GetDeviceSizeIsPageSize();
 }
 
 // A helper for three features below.
-static nsSize GetDeviceSize(const Document* aDocument) {
+static nsSize GetDeviceSize(Document* aDocument) {
   if (nsContentUtils::ShouldResistFingerprinting(aDocument) ||
       IsDeviceSizePageSize(aDocument)) {
     return GetSize(aDocument);
   }
 
   nsPresContext* pc = aDocument->GetPresContext();
   // NOTE(emilio): We should probably figure out how to return an appropriate
   // device size here, though in a multi-screen world that makes no sense
@@ -95,40 +94,40 @@ static nsSize GetDeviceSize(const Docume
     return pc->GetPageSize();
   }
 
   nsSize size;
   pc->DeviceContext()->GetDeviceSurfaceDimensions(size.width, size.height);
   return size;
 }
 
-bool Gecko_MediaFeatures_IsResourceDocument(const Document* aDocument) {
+bool Gecko_MediaFeatures_IsResourceDocument(Document* aDocument) {
   return aDocument->IsResourceDoc();
 }
 
-static nsDeviceContext* GetDeviceContextFor(const Document* aDocument) {
+static nsDeviceContext* GetDeviceContextFor(Document* aDocument) {
   nsPresContext* pc = aDocument->GetPresContext();
   if (!pc) {
     return nullptr;
   }
 
   // It would be nice to call nsLayoutUtils::GetDeviceContextForScreenInfo here,
   // except for two things:  (1) it can flush, and flushing is bad here, and (2)
   // it doesn't really get us consistency in multi-monitor situations *anyway*.
   return pc->DeviceContext();
 }
 
-void Gecko_MediaFeatures_GetDeviceSize(const Document* aDocument,
-                                       nscoord* aWidth, nscoord* aHeight) {
+void Gecko_MediaFeatures_GetDeviceSize(Document* aDocument, nscoord* aWidth,
+                                       nscoord* aHeight) {
   nsSize size = GetDeviceSize(aDocument);
   *aWidth = size.width;
   *aHeight = size.height;
 }
 
-uint32_t Gecko_MediaFeatures_GetColorDepth(const Document* aDocument) {
+uint32_t Gecko_MediaFeatures_GetColorDepth(Document* aDocument) {
   // Use depth of 24 when resisting fingerprinting, or when we're not being
   // rendered.
   uint32_t depth = 24;
 
   if (!nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     if (nsDeviceContext* dx = GetDeviceContextFor(aDocument)) {
       // FIXME: On a monochrome device, return 0!
       dx->GetDepth(depth);
@@ -136,17 +135,17 @@ uint32_t Gecko_MediaFeatures_GetColorDep
   }
 
   // The spec says to use bits *per color component*, so divide by 3,
   // and round down, since the spec says to use the smallest when the
   // color components differ.
   return depth / 3;
 }
 
-float Gecko_MediaFeatures_GetResolution(const Document* aDocument) {
+float Gecko_MediaFeatures_GetResolution(Document* aDocument) {
   // We're returning resolution in terms of device pixels per css pixel, since
   // that is the preferred unit for media queries of resolution. This avoids
   // introducing precision error from conversion to and from less-used
   // physical units like inches.
   nsPresContext* pc = aDocument->GetPresContext();
   if (!pc) {
     return 1.;
   }
@@ -158,26 +157,26 @@ float Gecko_MediaFeatures_GetResolution(
   if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return pc->DeviceContext()->GetFullZoom();
   }
   // Get the actual device pixel ratio, which also takes zoom into account.
   return float(AppUnitsPerCSSPixel()) /
          pc->DeviceContext()->AppUnitsPerDevPixel();
 }
 
-static const Document* TopDocument(const Document* aDocument) {
-  const Document* current = aDocument;
-  while (const Document* parent = current->GetParentDocument()) {
+static Document* TopDocument(Document* aDocument) {
+  Document* current = aDocument;
+  while (Document* parent = current->GetParentDocument()) {
     current = parent;
   }
   return current;
 }
 
-StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(const Document* aDocument) {
-  const Document* rootDocument = TopDocument(aDocument);
+StyleDisplayMode Gecko_MediaFeatures_GetDisplayMode(Document* aDocument) {
+  Document* rootDocument = TopDocument(aDocument);
 
   nsCOMPtr<nsISupports> container = rootDocument->GetContainer();
   if (nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container)) {
     nsCOMPtr<nsIWidget> mainWidget;
     baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
     if (mainWidget && mainWidget->SizeMode() == nsSizeMode_Fullscreen) {
       return StyleDisplayMode::Fullscreen;
     }
@@ -195,29 +194,28 @@ StyleDisplayMode Gecko_MediaFeatures_Get
 
   nsIDocShell* docShell = rootDocument->GetDocShell();
   if (!docShell) {
     return StyleDisplayMode::Browser;
   }
   return static_cast<StyleDisplayMode>(docShell->GetDisplayMode());
 }
 
-bool Gecko_MediaFeatures_HasSystemMetric(const Document* aDocument,
-                                         nsAtom* aMetric,
+bool Gecko_MediaFeatures_HasSystemMetric(Document* aDocument, nsAtom* aMetric,
                                          bool aIsAccessibleFromContent) {
   if (aIsAccessibleFromContent &&
       nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return false;
   }
 
   nsMediaFeatures::InitSystemMetrics();
   return sSystemMetrics->IndexOf(aMetric) != sSystemMetrics->NoIndex;
 }
 
-nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(const Document* aDocument) {
+nsAtom* Gecko_MediaFeatures_GetOperatingSystemVersion(Document* aDocument) {
   if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return nullptr;
   }
 
 #ifdef XP_WIN
   int32_t metricResult;
   if (NS_SUCCEEDED(LookAndFeel::GetInt(
           LookAndFeel::eIntID_OperatingSystemVersionIdentifier,
@@ -228,25 +226,25 @@ nsAtom* Gecko_MediaFeatures_GetOperating
       }
     }
   }
 #endif
 
   return nullptr;
 }
 
-bool Gecko_MediaFeatures_PrefersReducedMotion(const Document* aDocument) {
+bool Gecko_MediaFeatures_PrefersReducedMotion(Document* aDocument) {
   if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return false;
   }
   return LookAndFeel::GetInt(LookAndFeel::eIntID_PrefersReducedMotion, 0) == 1;
 }
 
 StylePrefersColorScheme Gecko_MediaFeatures_PrefersColorScheme(
-    const Document* aDocument) {
+    Document* aDocument) {
   if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return StylePrefersColorScheme::Light;
   }
   if (nsPresContext* pc = aDocument->GetPresContext()) {
     if (pc->IsPrintingOrPrintPreview()) {
       return StylePrefersColorScheme::Light;
     }
   }
@@ -261,17 +259,17 @@ StylePrefersColorScheme Gecko_MediaFeatu
       return StylePrefersColorScheme::NoPreference;
     default:
       // This only occurs if the user has set the ui.systemUsesDarkTheme pref to
       // an invalid value.
       return StylePrefersColorScheme::Light;
   }
 }
 
-static PointerCapabilities GetPointerCapabilities(const Document* aDocument,
+static PointerCapabilities GetPointerCapabilities(Document* aDocument,
                                                   LookAndFeel::IntID aID) {
   MOZ_ASSERT(aID == LookAndFeel::eIntID_PrimaryPointerCapabilities ||
              aID == LookAndFeel::eIntID_AllPointerCapabilities);
   MOZ_ASSERT(aDocument);
 
   if (nsIDocShell* docShell = aDocument->GetDocShell()) {
     // The touch-events-override happens only for the Responsive Design Mode so
     // that we don't need to care about ResistFingerprinting.
@@ -294,23 +292,23 @@ static PointerCapabilities GetPointerCap
   if (NS_FAILED(rv)) {
     return kDefaultCapabilities;
   }
 
   return static_cast<PointerCapabilities>(intValue);
 }
 
 PointerCapabilities Gecko_MediaFeatures_PrimaryPointerCapabilities(
-    const Document* aDocument) {
+    Document* aDocument) {
   return GetPointerCapabilities(aDocument,
                                 LookAndFeel::eIntID_PrimaryPointerCapabilities);
 }
 
 PointerCapabilities Gecko_MediaFeatures_AllPointerCapabilities(
-    const Document* aDocument) {
+    Document* aDocument) {
   return GetPointerCapabilities(aDocument,
                                 LookAndFeel::eIntID_AllPointerCapabilities);
 }
 
 /* static */ void nsMediaFeatures::InitSystemMetrics() {
   if (sSystemMetrics) return;
 
   MOZ_ASSERT(NS_IsMainThread());
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -544,22 +544,16 @@ VARCACHE_PREF(
   bool, true
 )
 
 //---------------------------------------------------------------------------
 // Graphics prefs
 //---------------------------------------------------------------------------
 
 VARCACHE_PREF(
-  "browser.display.use_document_fonts",
-   browser_display_use_document_fonts,
-  RelaxedAtomicBool, true
-)
-
-VARCACHE_PREF(
   "gfx.font_rendering.opentype_svg.enabled",
    gfx_font_rendering_opentype_svg_enabled,
   bool, true
 )
 
 VARCACHE_PREF(
   "gfx.offscreencanvas.enabled",
    gfx_offscreencanvas_enabled,
--- a/servo/components/style/gecko/media_features.rs
+++ b/servo/components/style/gecko/media_features.rs
@@ -456,17 +456,17 @@ fn eval_any_hover(device: &Device, query
     eval_hover_capabilities(query_value, all_pointer_capabilities(device))
 }
 
 fn eval_moz_is_glyph(
     device: &Device,
     query_value: Option<bool>,
     _: Option<RangeOrOperator>,
 ) -> bool {
-    let is_glyph = device.document().mIsSVGGlyphsDocument();
+    let is_glyph = unsafe { (*device.document()).mIsSVGGlyphsDocument() };
     query_value.map_or(is_glyph, |v| v == is_glyph)
 }
 
 fn eval_moz_is_resource_document(
     device: &Device,
     query_value: Option<bool>,
     _: Option<RangeOrOperator>,
 ) -> bool {
--- a/servo/components/style/gecko/media_queries.rs
+++ b/servo/components/style/gecko/media_queries.rs
@@ -80,17 +80,17 @@ unsafe impl Sync for Device {}
 unsafe impl Send for Device {}
 
 impl Device {
     /// Trivially constructs a new `Device`.
     pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
         assert!(!pres_context.is_null());
         Device {
             pres_context,
-            default_values: ComputedValues::default_values(unsafe { &*(*pres_context).mDocument.mRawPtr }),
+            default_values: ComputedValues::default_values(unsafe { &*pres_context }),
             // FIXME(bz): Seems dubious?
             root_font_size: AtomicIsize::new(FontSize::medium().size().0 as isize),
             body_text_color: AtomicUsize::new(unsafe { &*pres_context }.mDefaultColor as usize),
             used_root_font_size: AtomicBool::new(false),
             used_viewport_size: AtomicBool::new(false),
             environment: CssEnvironment,
         }
     }
@@ -157,23 +157,23 @@ impl Device {
     /// Gets the pres context associated with this document.
     #[inline]
     pub fn pres_context(&self) -> &nsPresContext {
         unsafe { &*self.pres_context }
     }
 
     /// Gets the document pointer.
     #[inline]
-    pub fn document(&self) -> &structs::Document {
-        unsafe { &*self.pres_context().mDocument.mRawPtr }
+    pub fn document(&self) -> *mut structs::Document {
+        self.pres_context().mDocument.mRawPtr
     }
 
     /// Recreates the default computed values.
     pub fn reset_computed_values(&mut self) {
-        self.default_values = ComputedValues::default_values(self.document());
+        self.default_values = ComputedValues::default_values(self.pres_context());
     }
 
     /// Rebuild all the cached data.
     pub fn rebuild_cached_data(&mut self) {
         self.reset_computed_values();
         self.used_root_font_size.store(false, Ordering::Relaxed);
         self.used_viewport_size.store(false, Ordering::Relaxed);
     }
--- a/servo/components/style/gecko/values.rs
+++ b/servo/components/style/gecko/values.rs
@@ -5,16 +5,17 @@
 #![allow(unsafe_code)]
 
 //! Different kind of helpers to interact with Gecko values.
 
 use crate::counter_style::{Symbol, Symbols};
 use crate::gecko_bindings::structs::{nsStyleCoord, CounterStylePtr};
 use crate::gecko_bindings::structs::{StyleGridTrackBreadth, StyleShapeRadius};
 use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
+use crate::media_queries::Device;
 use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
 use crate::values::computed::{Angle, Length, LengthPercentage};
 use crate::values::computed::{Number, NumberOrPercentage, Percentage};
 use crate::values::generics::basic_shape::ShapeRadius;
 use crate::values::generics::box_::Perspective;
 use crate::values::generics::gecko::ScrollSnapPoint;
 use crate::values::generics::grid::{TrackBreadth, TrackKeyword};
 use crate::values::generics::length::LengthPercentageOrAuto;
@@ -381,25 +382,26 @@ pub fn round_border_to_device_pixels(wid
             au_per_device_px,
             Au(width.0 / au_per_device_px.0 * au_per_device_px.0),
         )
     }
 }
 
 impl CounterStyleOrNone {
     /// Convert this counter style to a Gecko CounterStylePtr.
-    pub fn to_gecko_value(self, gecko_value: &mut CounterStylePtr) {
+    pub fn to_gecko_value(self, gecko_value: &mut CounterStylePtr, device: &Device) {
         use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToName as set_name;
         use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToSymbols as set_symbols;
+        let pres_context = device.pres_context();
         match self {
             CounterStyleOrNone::None => unsafe {
-                set_name(gecko_value, atom!("none").into_addrefed());
+                set_name(gecko_value, atom!("none").into_addrefed(), pres_context);
             },
             CounterStyleOrNone::Name(name) => unsafe {
-                set_name(gecko_value, name.0.into_addrefed());
+                set_name(gecko_value, name.0.into_addrefed(), pres_context);
             },
             CounterStyleOrNone::Symbols(symbols_type, symbols) => {
                 let symbols: Vec<_> = symbols
                     .0
                     .iter()
                     .map(|symbol| match *symbol {
                         Symbol::String(ref s) => nsCStr::from(s),
                         Symbol::Ident(_) => unreachable!("Should not have identifier in symbols()"),
--- a/servo/components/style/properties/cascade.rs
+++ b/servo/components/style/properties/cascade.rs
@@ -740,23 +740,23 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
                             // not skip cascading then.
                             _skip_font_family = true;
                         }
                     }
                 }
 
                 // FIXME(emilio): Why both setting the generic and passing it
                 // down?
-                let doc = self.context.builder.device.document();
+                let pres_context = self.context.builder.device.pres_context();
                 let gecko_font = self.context.builder.mutate_font().gecko_mut();
                 gecko_font.mGenericID = generic;
                 unsafe {
                     crate::gecko_bindings::bindings::Gecko_nsStyleFont_PrefillDefaultForGeneric(
                         gecko_font,
-                        doc,
+                        pres_context,
                         generic,
                     );
                 }
             }
         }
 
         // It is important that font-size is computed before the late
         // properties (for em units), but after font-family (for the
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -30,16 +30,17 @@ use crate::gecko_bindings::bindings::Gec
 use crate::gecko_bindings::bindings::Gecko_SetCursorImageValue;
 use crate::gecko_bindings::bindings::Gecko_NewCSSShadowArray;
 use crate::gecko_bindings::bindings::Gecko_nsStyleFont_SetLang;
 use crate::gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom;
 use crate::gecko_bindings::bindings::Gecko_SetListStyleImageNone;
 use crate::gecko_bindings::bindings::Gecko_SetListStyleImageImageValue;
 use crate::gecko_bindings::bindings::Gecko_SetNullImageValue;
 use crate::gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
+use crate::gecko_bindings::bindings::RawGeckoPresContextBorrowed;
 use crate::gecko_bindings::structs;
 use crate::gecko_bindings::structs::nsCSSPropertyID;
 use crate::gecko_bindings::structs::mozilla::CSSPseudoElementType;
 use crate::gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
 use crate::gecko_bindings::sugar::refptr::RefPtr;
 use crate::gecko::values::convert_nscolor_to_rgba;
 use crate::gecko::values::convert_rgba_to_nscolor;
 use crate::gecko::values::GeckoStyleCoordConvertible;
@@ -96,25 +97,25 @@ impl ComputedValues {
             rules,
             visited_style,
             % for style_struct in data.style_structs:
             ${style_struct.ident},
             % endfor
         ).to_outer(pseudo)
     }
 
-    pub fn default_values(doc: &structs::Document) -> Arc<Self> {
+    pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
         ComputedValuesInner::new(
             /* custom_properties = */ None,
             /* writing_mode = */ WritingMode::empty(), // FIXME(bz): This seems dubious
             ComputedValueFlags::empty(),
             /* rules = */ None,
             /* visited_style = */ None,
             % for style_struct in data.style_structs:
-            style_structs::${style_struct.name}::default(doc),
+            style_structs::${style_struct.name}::default(pres_context),
             % endfor
         ).to_outer(None)
     }
 
     pub fn pseudo(&self) -> Option<PseudoElement> {
         let atom = (self.0).mPseudoTag.mRawPtr;
         if atom.is_null() {
             return None;
@@ -1251,23 +1252,21 @@ pub fn clone_transform_from_list(
 
 <%def name="impl_logical(name, **kwargs)">
     ${helpers.logical_setter(name)}
 </%def>
 
 <%def name="impl_style_struct(style_struct)">
 impl ${style_struct.gecko_struct_name} {
     #[allow(dead_code, unused_variables)]
-    pub fn default(document: &structs::Document) -> Arc<Self> {
+    pub fn default(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
         let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });
         unsafe {
-            Gecko_Construct_Default_${style_struct.gecko_ffi_name}(
-                &mut Arc::get_mut(&mut result).unwrap().gecko,
-                document,
-            );
+            Gecko_Construct_Default_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko,
+                                                                   pres_context);
         }
         result
     }
     pub fn get_gecko(&self) -> &${style_struct.gecko_ffi_name} {
         &self.gecko
     }
 }
 impl Drop for ${style_struct.gecko_struct_name} {
@@ -2205,17 +2204,17 @@ fn static_assert() {
     // Negative numbers are invalid at parse time, but <integer> is still an
     // i32.
     <% impl_font_settings("font_feature_settings", "gfxFontFeature", "FeatureTagValue", "i32", "u32") %>
     <% impl_font_settings("font_variation_settings", "gfxFontVariation", "VariationValue", "f32", "f32") %>
 
     pub fn fixup_none_generic(&mut self, device: &Device) {
         self.gecko.mFont.systemFont = false;
         unsafe {
-            bindings::Gecko_nsStyleFont_FixupNoneGeneric(&mut self.gecko, device.document())
+            bindings::Gecko_nsStyleFont_FixupNoneGeneric(&mut self.gecko, device.pres_context())
         }
     }
 
     pub fn fixup_system(&mut self, default_font_type: structs::FontFamilyType) {
         self.gecko.mFont.systemFont = true;
         self.gecko.mGenericID = structs::kGenericFont_NONE;
         self.gecko.mFont.fontlist.mDefaultFontType = default_font_type;
     }
@@ -2321,17 +2320,17 @@ fn static_assert() {
         } else {
             self.gecko.mSize = v.size().0;
             self.fixup_font_min_size(device);
             Some(Au(parent.gecko.mScriptUnconstrainedSize).into())
         }
     }
 
     pub fn fixup_font_min_size(&mut self, device: &Device) {
-        unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.document()) }
+        unsafe { bindings::Gecko_nsStyleFont_FixupMinFontSize(&mut self.gecko, device.pres_context()) }
     }
 
     pub fn apply_unconstrained_font_size(&mut self, v: NonNegativeLength) {
         self.gecko.mScriptUnconstrainedSize = v.0.to_i32_au();
     }
 
     /// Calculates the constrained and unconstrained font sizes to be inherited
     /// from the parent.
@@ -2643,32 +2642,34 @@ fn static_assert() {
     #[allow(non_snake_case)]
     pub fn clone__x_text_zoom(&self) -> longhands::_x_text_zoom::computed_value::T {
         longhands::_x_text_zoom::computed_value::T(self.gecko.mAllowZoom)
     }
 
     ${impl_simple("_moz_script_level", "mScriptLevel")}
     <% impl_simple_type_with_conversion("font_language_override", "mFont.languageOverride") %>
 
-    pub fn set_font_variant_alternates(
-        &mut self,
-        v: values::computed::font::FontVariantAlternates,
-    ) {
+    pub fn set_font_variant_alternates(&mut self,
+                                       v: values::computed::font::FontVariantAlternates,
+                                       device: &Device) {
         use crate::gecko_bindings::bindings::{Gecko_ClearAlternateValues, Gecko_AppendAlternateValues};
+        use crate::gecko_bindings::bindings::Gecko_nsFont_ResetFontFeatureValuesLookup;
+        use crate::gecko_bindings::bindings::Gecko_nsFont_SetFontFeatureValuesLookup;
         % for value in "normal swash stylistic ornaments annotation styleset character_variant historical".split():
             use crate::gecko_bindings::structs::NS_FONT_VARIANT_ALTERNATES_${value.upper()};
         % endfor
         use crate::values::specified::font::VariantAlternates;
 
         unsafe {
             Gecko_ClearAlternateValues(&mut self.gecko.mFont, v.len());
         }
 
         if v.0.is_empty() {
             self.gecko.mFont.variantAlternates = NS_FONT_VARIANT_ALTERNATES_NORMAL as u16;
+            unsafe { Gecko_nsFont_ResetFontFeatureValuesLookup(&mut self.gecko.mFont); }
             return;
         }
 
         for val in v.0.iter() {
             match *val {
                 % for value in "Swash Stylistic Ornaments Annotation".split():
                     VariantAlternates::${value}(ref ident) => {
                         self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_${value.upper()} as u16;
@@ -2691,16 +2692,20 @@ fn static_assert() {
                         }
                     },
                 % endfor
                 VariantAlternates::HistoricalForms => {
                     self.gecko.mFont.variantAlternates |= NS_FONT_VARIANT_ALTERNATES_HISTORICAL as u16;
                 }
             }
         }
+
+        unsafe {
+            Gecko_nsFont_SetFontFeatureValuesLookup(&mut self.gecko.mFont, device.pres_context());
+        }
     }
 
     #[allow(non_snake_case)]
     pub fn copy_font_variant_alternates_from(&mut self, other: &Self) {
         use crate::gecko_bindings::bindings::Gecko_CopyAlternateValuesFrom;
 
         self.gecko.mFont.variantAlternates = other.gecko.mFont.variantAlternates;
         unsafe {
@@ -3953,22 +3958,22 @@ fn static_assert() {
         }
 
         unsafe {
             let ref gecko_image_request = *self.gecko.mListStyleImage.mRawPtr;
             UrlOrNone::Url(ComputedImageUrl::from_image_request(gecko_image_request))
         }
     }
 
-    pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T) {
+    pub fn set_list_style_type(&mut self, v: longhands::list_style_type::computed_value::T, device: &Device) {
         use crate::gecko_bindings::bindings::Gecko_SetCounterStyleToString;
         use nsstring::{nsACString, nsCStr};
         use self::longhands::list_style_type::computed_value::T;
         match v {
-            T::CounterStyle(s) => s.to_gecko_value(&mut self.gecko.mCounterStyle),
+            T::CounterStyle(s) => s.to_gecko_value(&mut self.gecko.mCounterStyle, device),
             T::String(s) => unsafe {
                 Gecko_SetCounterStyleToString(&mut self.gecko.mCounterStyle,
                                               &nsCStr::from(&s) as &nsACString)
             }
         }
     }
 
     pub fn copy_list_style_type_from(&mut self, other: &Self) {
@@ -5200,17 +5205,17 @@ clip-path
 </%self:impl_trait>
 
 <%self:impl_trait style_struct_name="Counters"
                   skip_longhands="content counter-increment counter-reset">
     pub fn ineffective_content_property(&self) -> bool {
         self.gecko.mContents.is_empty()
     }
 
-    pub fn set_content(&mut self, v: longhands::content::computed_value::T) {
+    pub fn set_content(&mut self, v: longhands::content::computed_value::T, device: &Device) {
         use crate::values::CustomIdent;
         use crate::values::generics::counters::{Content, ContentItem};
         use crate::values::generics::CounterStyleOrNone;
         use crate::gecko_bindings::structs::nsStyleContentData;
         use crate::gecko_bindings::structs::nsStyleContentAttr;
         use crate::gecko_bindings::structs::StyleContentType;
         use crate::gecko_bindings::bindings::Gecko_ClearAndResizeStyleContents;
 
@@ -5225,27 +5230,28 @@ clip-path
         }
 
         fn set_counter_function(
             data: &mut nsStyleContentData,
             content_type: StyleContentType,
             name: &CustomIdent,
             sep: &str,
             style: CounterStyleOrNone,
+            device: &Device,
         ) {
             debug_assert!(content_type == StyleContentType::Counter ||
                           content_type == StyleContentType::Counters);
             let counter_func = unsafe {
                 bindings::Gecko_SetCounterFunction(data, content_type).as_mut().unwrap()
             };
             counter_func.mIdent.assign(name.0.as_slice());
             if content_type == StyleContentType::Counters {
                 counter_func.mSeparator.assign_str(sep);
             }
-            style.to_gecko_value(&mut counter_func.mCounterStyle);
+            style.to_gecko_value(&mut counter_func.mCounterStyle, device);
         }
 
         match v {
             Content::None |
             Content::Normal => {
                 // Ensure destructors run, otherwise we could leak.
                 if !self.gecko.mContents.is_empty() {
                     unsafe {
@@ -5310,25 +5316,27 @@ clip-path
                             => self.gecko.mContents[i].mType = StyleContentType::NoCloseQuote,
                         ContentItem::Counter(ref name, ref style) => {
                             set_counter_function(
                                 &mut self.gecko.mContents[i],
                                 StyleContentType::Counter,
                                 &name,
                                 "",
                                 style.clone(),
+                                device,
                             );
                         }
                         ContentItem::Counters(ref name, ref sep, ref style) => {
                             set_counter_function(
                                 &mut self.gecko.mContents[i],
                                 StyleContentType::Counters,
                                 &name,
                                 &sep,
                                 style.clone(),
+                                device,
                             );
                         }
                         ContentItem::Url(ref url) => {
                             unsafe {
                                 bindings::Gecko_SetContentDataImageValue(
                                     &mut self.gecko.mContents[i],
                                     url.url_value_ptr(),
                                 )
--- a/servo/components/style/properties/longhands/color.mako.rs
+++ b/servo/components/style/properties/longhands/color.mako.rs
@@ -93,17 +93,17 @@ pub mod system_colors {
     impl ToComputedValue for SystemColor {
         type ComputedValue = u32; // nscolor
 
         #[inline]
         fn to_computed_value(&self, cx: &Context) -> Self::ComputedValue {
             unsafe {
                 Gecko_GetLookAndFeelSystemColor(
                     *self as i32,
-                    cx.device().document(),
+                    cx.device().pres_context(),
                 )
             }
         }
 
         #[inline]
         fn from_computed_value(_: &Self::ComputedValue) -> Self {
             unreachable!()
         }
--- a/servo/components/style/properties/longhands/font.mako.rs
+++ b/servo/components/style/properties/longhands/font.mako.rs
@@ -391,17 +391,17 @@ https://drafts.csswg.org/css-fonts-4/#lo
                 };
 
                 let mut system: nsFont = unsafe { mem::uninitialized() };
                 unsafe {
                     bindings::Gecko_nsFont_InitSystem(
                         &mut system,
                         id as i32,
                         cx.style().get_font().gecko(),
-                        cx.device().document()
+                        cx.device().pres_context()
                     )
                 }
                 let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight);
                 let font_stretch = FontStretch(NonNegative(Percentage(unsafe {
                     bindings::Gecko_FontStretch_ToFloat(system.stretch)
                 })));
                 let font_style = FontStyle::from_gecko(system.style);
                 let ret = ComputedSystemFont {
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -3502,21 +3502,24 @@ impl<'a> StyleBuilder<'a> {
     pub fn set_${property.ident}(
         &mut self,
         value: longhands::${property.ident}::computed_value::T
     ) {
         % if not property.style_struct.inherited:
         self.modified_reset = true;
         % endif
 
+        <% props_need_device = ["content", "list_style_type", "font_variant_alternates"] %>
         self.${property.style_struct.ident}.mutate()
             .set_${property.ident}(
                 value,
                 % if property.logical:
                 self.writing_mode,
+                % elif product == "gecko" and property.ident in props_need_device:
+                self.device,
                 % endif
             );
     }
     % endif
     % endif
     % endfor
     <% del property %>
 
--- a/servo/components/style/stylesheets/document_rule.rs
+++ b/servo/components/style/stylesheets/document_rule.rs
@@ -193,17 +193,17 @@ impl DocumentMatchingFunction {
             DocumentMatchingFunction::Regexp(ref pat) => pat,
             DocumentMatchingFunction::MediaDocument(kind) => match kind {
                 MediaDocumentKind::All => "all",
                 MediaDocumentKind::Image => "image",
                 MediaDocumentKind::Plugin => "plugin",
                 MediaDocumentKind::Video => "video",
             },
         });
-        unsafe { Gecko_DocumentRule_UseForPresentation(device.document(), &*pattern, func) }
+        unsafe { Gecko_DocumentRule_UseForPresentation(device.pres_context(), &*pattern, func) }
     }
 
     #[cfg(not(feature = "gecko"))]
     /// Evaluate a URL matching function.
     pub fn evaluate(&self, _: &Device) -> bool {
         false
     }
 }