Bug 1447367 - Remove files that are not built when MOZ_OLD_STYLE is not defined. r=emilio
authorJonathan Watt <jwatt@jwatt.org>
Wed, 07 Mar 2018 18:08:41 +0000
changeset 462796 797722641610dad674216f190a8f4d7a76af9b8c
parent 462795 c4d938fa8c8bc7cd2538dee686516004f0ffbf24
child 462797 8b721870d808f23a4f515e98516e76c3dc9e99b3
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1447367
milestone61.0a1
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
Bug 1447367 - Remove files that are not built when MOZ_OLD_STYLE is not defined. r=emilio MozReview-Commit-ID: D9bEPfTSw61
dom/animation/AnimValuesStyleRule.cpp
dom/animation/AnimValuesStyleRule.h
dom/animation/EffectCompositor.h
dom/animation/moz.build
layout/base/GeckoRestyleManager.cpp
layout/base/GeckoRestyleManager.h
layout/base/RestyleTracker.cpp
layout/base/moz.build
layout/style/CSSStyleSheet.cpp
layout/style/CSSStyleSheet.h
layout/style/CSSVariableDeclarations.cpp
layout/style/CSSVariableDeclarations.h
layout/style/CSSVariableResolver.cpp
layout/style/CSSVariableResolver.h
layout/style/CSSVariableValues.cpp
layout/style/CSSVariableValues.h
layout/style/Declaration.cpp
layout/style/Declaration.h
layout/style/GeckoStyleContext.cpp
layout/style/GeckoStyleContext.h
layout/style/ImportRule.h
layout/style/IncrementalClearCOMRuleArray.cpp
layout/style/IncrementalClearCOMRuleArray.h
layout/style/NameSpaceRule.h
layout/style/RuleNodeCacheConditions.cpp
layout/style/RuleProcessorCache.cpp
layout/style/RuleProcessorCache.h
layout/style/StyleRule.cpp
layout/style/StyleRule.h
layout/style/moz.build
layout/style/nsCSSDataBlock.cpp
layout/style/nsCSSParser.cpp
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsCSSRuleProcessor.h
layout/style/nsCSSRules.cpp
layout/style/nsIStyleRule.h
layout/style/nsIStyleRuleProcessor.h
layout/style/nsMediaList.cpp
layout/style/nsMediaList.h
layout/style/nsNthIndexCache.cpp
layout/style/nsRuleData.cpp
layout/style/nsRuleData.h
layout/style/nsRuleNode.cpp
layout/style/nsRuleNode.h
layout/style/nsRuleWalker.h
layout/style/nsStyleContext.cpp
layout/style/nsStyleSet.cpp
layout/style/nsStyleSet.h
toolkit/moz.configure
deleted file mode 100644
--- a/dom/animation/AnimValuesStyleRule.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "AnimValuesStyleRule.h"
-#include "mozilla/GeckoStyleContext.h"
-#include "nsRuleData.h"
-
-namespace mozilla {
-
-NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule)
-
-void
-AnimValuesStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  GeckoStyleContext* contextParent = aRuleData->mStyleContext->GetParent();
-  if (contextParent && contextParent->HasPseudoElementData()) {
-    // Don't apply transitions or animations to things inside of
-    // pseudo-elements.
-    // FIXME (Bug 522599): Add tests for this.
-
-    // Prevent structs from being cached on the rule node since we're inside
-    // a pseudo-element, as we could determine cacheability differently
-    // when walking the rule tree for a style context that is not inside
-    // a pseudo-element.  Note that nsRuleNode::GetStyle##name_ and GetStyleData
-    // will never look at cached structs when we're animating things inside
-    // a pseduo-element, so that we don't incorrectly return a struct that
-    // is only appropriate for non-pseudo-elements.
-    aRuleData->mConditions.SetUncacheable();
-    return;
-  }
-
-  for (auto iter = mAnimationValues.ConstIter(); !iter.Done(); iter.Next()) {
-    nsCSSPropertyID property = static_cast<nsCSSPropertyID>(iter.Key());
-    if (aRuleData->mSIDs & nsCachedStyleData::GetBitForSID(
-                             nsCSSProps::kSIDTable[property])) {
-      nsCSSValue *prop = aRuleData->ValueFor(property);
-      if (prop->GetUnit() == eCSSUnit_Null) {
-        DebugOnly<bool> ok =
-          StyleAnimationValue::UncomputeValue(property, iter.Data(),
-                                              *prop);
-        MOZ_ASSERT(ok, "could not store computed value");
-      }
-    }
-  }
-}
-
-bool
-AnimValuesStyleRule::MightMapInheritedStyleData()
-{
-  return mStyleBits & NS_STYLE_INHERITED_STRUCT_MASK;
-}
-
-bool
-AnimValuesStyleRule::GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
-                                                   nsCSSValue* aValue)
-{
-  MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet");
-  return false;
-}
-
-void
-AnimValuesStyleRule::AddValue(nsCSSPropertyID aProperty,
-                              const StyleAnimationValue &aValue)
-{
-  MOZ_ASSERT(aProperty != eCSSProperty_UNKNOWN,
-             "Unexpected css property");
-  mAnimationValues.Put(aProperty, aValue);
-  mStyleBits |=
-    nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
-}
-
-void
-AnimValuesStyleRule::AddValue(nsCSSPropertyID aProperty,
-                              StyleAnimationValue&& aValue)
-{
-  MOZ_ASSERT(aProperty != eCSSProperty_UNKNOWN,
-             "Unexpected css property");
-  mAnimationValues.Put(aProperty, Move(aValue));
-  mStyleBits |=
-    nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
-}
-
-bool
-AnimValuesStyleRule::GetValue(nsCSSPropertyID aProperty,
-                              StyleAnimationValue& aValue) const
-{
-  return mAnimationValues.Get(aProperty, &aValue);
-}
-
-#ifdef DEBUG
-void
-AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
-{
-  nsAutoCString str;
-  for (int32_t index = aIndent; --index >= 0; ) {
-    str.AppendLiteral("  ");
-  }
-  str.AppendLiteral("[anim values] { ");
-  for (auto iter = mAnimationValues.ConstIter(); !iter.Done(); iter.Next()) {
-    nsCSSPropertyID property = static_cast<nsCSSPropertyID>(iter.Key());
-    str.Append(nsCSSProps::GetStringValue(property));
-    str.AppendLiteral(": ");
-    nsAutoString value;
-    Unused <<
-      StyleAnimationValue::UncomputeValue(property, iter.Data(), value);
-    AppendUTF16toUTF8(value, str);
-    str.AppendLiteral("; ");
-  }
-  str.AppendLiteral("}\n");
-  fprintf_stderr(out, "%s", str.get());
-}
-#endif
-
-} // namespace mozilla
deleted file mode 100644
--- a/dom/animation/AnimValuesStyleRule.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_AnimValuesStyleRule_h
-#define mozilla_AnimValuesStyleRule_h
-
-#include "mozilla/StyleAnimationValue.h"
-#include "nsCSSPropertyID.h"
-#include "nsCSSPropertyIDSet.h"
-#include "nsDataHashtable.h"
-#include "nsHashKeys.h" // For nsUint32HashKey
-#include "nsIStyleRule.h"
-#include "nsISupportsImpl.h" // For NS_DECL_ISUPPORTS
-#include "nsRuleNode.h" // For nsCachedStyleData
-#include "nsTArray.h" // For nsTArray
-
-namespace mozilla {
-
-/**
- * A style rule that maps property-StyleAnimationValue pairs.
- */
-class AnimValuesStyleRule final : public nsIStyleRule
-{
-public:
-  AnimValuesStyleRule()
-    : mStyleBits(0) {}
-
-  // nsISupports implementation
-  NS_DECL_ISUPPORTS
-
-  // nsIStyleRule implementation
-  void MapRuleInfoInto(nsRuleData* aRuleData) override;
-  bool MightMapInheritedStyleData() override;
-  bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
-                                     nsCSSValue* aValue) override;
-#ifdef DEBUG
-  void List(FILE* out = stdout, int32_t aIndent = 0) const override;
-#endif
-
-  // For the following functions, it there is already a value for |aProperty| it
-  // will be replaced with |aValue|.
-  void AddValue(nsCSSPropertyID aProperty, const StyleAnimationValue &aValue);
-  void AddValue(nsCSSPropertyID aProperty, StyleAnimationValue&& aValue);
-
-  bool HasValue(nsCSSPropertyID aProperty) const {
-    return mAnimationValues.Contains(aProperty);
-  }
-  bool GetValue(nsCSSPropertyID aProperty, StyleAnimationValue& aValue) const;
-
-private:
-  ~AnimValuesStyleRule() {}
-
-  nsDataHashtable<nsUint32HashKey, StyleAnimationValue> mAnimationValues;
-
-  uint32_t mStyleBits;
-};
-
-} // namespace mozilla
-
-#endif // mozilla_AnimValuesStyleRule_h
--- a/dom/animation/EffectCompositor.h
+++ b/dom/animation/EffectCompositor.h
@@ -16,17 +16,16 @@
 #include "nsCSSPropertyID.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsDataHashtable.h"
 #include "nsTArray.h"
 
 class nsCSSPropertyIDSet;
 class nsAtom;
 class nsIFrame;
-class nsIStyleRule;
 class nsPresContext;
 class nsStyleContext;
 struct RawServoAnimationValueMap;
 typedef RawServoAnimationValueMap* RawServoAnimationValueMapBorrowedMut;
 
 namespace mozilla {
 
 class EffectSet;
--- a/dom/animation/moz.build
+++ b/dom/animation/moz.build
@@ -36,21 +36,16 @@ EXPORTS.mozilla += [
     'Keyframe.h',
     'KeyframeEffectParams.h',
     'KeyframeUtils.h',
     'PendingAnimationTracker.h',
     'PseudoElementHashEntry.h',
     'TimingParams.h',
 ]
 
-if CONFIG['MOZ_OLD_STYLE']:
-    EXPORTS.mozilla += [
-        'AnimValuesStyleRule.h',
-    ]
-
 UNIFIED_SOURCES += [
     'Animation.cpp',
     'AnimationEffectReadOnly.cpp',
     'AnimationEffectTiming.cpp',
     'AnimationEffectTimingReadOnly.cpp',
     'AnimationEventDispatcher.cpp',
     'AnimationPerformanceWarning.cpp',
     'AnimationTimeline.cpp',
@@ -62,20 +57,15 @@ UNIFIED_SOURCES += [
     'EffectSet.cpp',
     'KeyframeEffect.cpp',
     'KeyframeEffectReadOnly.cpp',
     'KeyframeUtils.cpp',
     'PendingAnimationTracker.cpp',
     'TimingParams.cpp',
 ]
 
-if CONFIG['MOZ_OLD_STYLE']:
-    UNIFIED_SOURCES += [
-        'AnimValuesStyleRule.cpp',
-    ]
-
 LOCAL_INCLUDES += [
     '/dom/base',
     '/layout/base',
     '/layout/style',
 ]
 
 FINAL_LIBRARY = 'xul'
deleted file mode 100644
--- a/layout/base/GeckoRestyleManager.cpp
+++ /dev/null
@@ -1,3775 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/**
- * Code responsible for managing style changes: tracking what style
- * changes need to happen, scheduling them, and doing them.
- */
-
-#include "mozilla/GeckoRestyleManager.h"
-
-#include <algorithm> // For std::max
-#include "gfxContext.h"
-#include "mozilla/EffectSet.h"
-#include "mozilla/GeckoStyleContext.h"
-#include "mozilla/EventStates.h"
-#include "mozilla/UndisplayedNode.h"
-#include "mozilla/ViewportFrame.h"
-#include "mozilla/css/StyleRule.h" // For nsCSSSelector
-#include "mozilla/dom/MutationEventBinding.h"
-#include "nsLayoutUtils.h"
-#include "AnimationCommon.h" // For GetLayerAnimationInfo
-#include "FrameLayerBuilder.h"
-#include "GeckoProfiler.h"
-#include "nsAutoPtr.h"
-#include "nsStyleChangeList.h"
-#include "nsRuleProcessorData.h"
-#include "nsStyleContextInlines.h"
-#include "nsStyleSet.h"
-#include "nsStyleUtil.h"
-#include "nsCSSFrameConstructor.h"
-#include "SVGObserverUtils.h"
-#include "nsCSSPseudoElements.h"
-#include "nsCSSRendering.h"
-#include "nsAnimationManager.h"
-#include "nsTransitionManager.h"
-#include "nsViewManager.h"
-#include "nsSVGIntegrationUtils.h"
-#include "nsCSSAnonBoxes.h"
-#include "nsContainerFrame.h"
-#include "nsPlaceholderFrame.h"
-#include "nsBlockFrame.h"
-#include "SVGTextFrame.h"
-#include "StickyScrollContainer.h"
-#include "nsIRootBox.h"
-#include "nsContentUtils.h"
-#include "nsIFrameInlines.h"
-#include "ActiveLayerTracker.h"
-#include "nsDisplayList.h"
-#include "RestyleTrackerInlines.h"
-#include "nsSMILAnimationController.h"
-#include "nsCSSRuleProcessor.h"
-#include "ChildIterator.h"
-
-#ifdef ACCESSIBILITY
-#include "nsAccessibilityService.h"
-#endif
-
-namespace mozilla {
-
-using namespace layers;
-using namespace dom;
-
-#define LOG_RESTYLE_CONTINUE(reason_, ...) \
-  LOG_RESTYLE("continuing restyle since " reason_, ##__VA_ARGS__)
-
-#ifdef RESTYLE_LOGGING
-static nsCString
-FrameTagToString(const nsIFrame* aFrame)
-{
-  nsCString result;
-  aFrame->ListTag(result);
-  return result;
-}
-
-static nsCString
-ElementTagToString(dom::Element* aElement)
-{
-  nsCString result;
-  nsDependentAtomString buf(aElement->NodeInfo()->NameAtom());
-  result.AppendPrintf("(%s@%p)", NS_ConvertUTF16toUTF8(buf).get(), aElement);
-  return result;
-}
-#endif
-
-GeckoRestyleManager::GeckoRestyleManager(nsPresContext* aPresContext)
-  : RestyleManager(StyleBackendType::Gecko, aPresContext)
-  , mDoRebuildAllStyleData(false)
-  , mInRebuildAllStyleData(false)
-  , mSkipAnimationRules(false)
-  , mHavePendingNonAnimationRestyles(false)
-  , mRebuildAllExtraHint(nsChangeHint(0))
-  , mRebuildAllRestyleHint(nsRestyleHint(0))
-  , mReframingStyleContexts(nullptr)
-  , mPendingRestyles(ELEMENT_HAS_PENDING_RESTYLE |
-                     ELEMENT_IS_POTENTIAL_RESTYLE_ROOT |
-                     ELEMENT_IS_CONDITIONAL_RESTYLE_ANCESTOR)
-  , mIsProcessingRestyles(false)
-#ifdef RESTYLE_LOGGING
-  , mLoggingDepth(0)
-#endif
-{
-  mPendingRestyles.Init(this);
-}
-
-static nsIFrame*
-GetNearestAncestorFrame(nsIContent* aContent)
-{
-  nsIFrame* ancestorFrame = nullptr;
-  for (nsIContent* ancestor = aContent->GetParent();
-       ancestor && !ancestorFrame;
-       ancestor = ancestor->GetParent()) {
-    ancestorFrame = ancestor->GetPrimaryFrame();
-  }
-  return ancestorFrame;
-}
-
-static nsIFrame*
-GetNextBlockInInlineSibling(nsIFrame* aFrame)
-{
-  NS_ASSERTION(!aFrame->GetPrevContinuation(),
-               "must start with the first continuation");
-  // Might we have ib-split siblings?
-  if (!(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
-    // nothing more to do here
-    return nullptr;
-  }
-
-  return aFrame->GetProperty(nsIFrame::IBSplitSibling());
-}
-
-/**
- * Get the next continuation or similar ib-split sibling (assuming
- * block/inline alternation), conditionally on it having the same style.
- *
- * Since this is used when deciding to copy the new style context, it
- * takes as an argument the old style context to check if the style is
- * the same.  When it is used in other contexts (i.e., where the next
- * continuation would already have the new style context), the current
- * style context should be passed.
- */
-static nsIFrame*
-GetNextContinuationWithSameStyle(nsIFrame* aFrame,
-                                 GeckoStyleContext* aOldStyleContext,
-                                 bool* aHaveMoreContinuations = nullptr)
-{
-  // See GetPrevContinuationWithSameStyle about {ib} splits.
-
-  nsIFrame* nextContinuation = aFrame->GetNextContinuation();
-  if (!nextContinuation &&
-      (aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
-    // We're the last continuation, so we have to hop back to the first
-    // before getting the frame property
-    nextContinuation =
-      aFrame->FirstContinuation()->GetProperty(nsIFrame::IBSplitSibling());
-    if (nextContinuation) {
-      nextContinuation =
-        nextContinuation->GetProperty(nsIFrame::IBSplitSibling());
-    }
-  }
-
-  if (!nextContinuation) {
-    return nullptr;
-  }
-
-  NS_ASSERTION(nextContinuation->GetContent() == aFrame->GetContent(),
-               "unexpected content mismatch");
-
-  GeckoStyleContext* nextStyle = nextContinuation->StyleContext()->AsGecko();
-  if (nextStyle != aOldStyleContext) {
-    NS_ASSERTION(aOldStyleContext->GetPseudo() != nextStyle->GetPseudo() ||
-                 aOldStyleContext->GetParent() != nextStyle->GetParent(),
-                 "continuations should have the same style context");
-    nextContinuation = nullptr;
-    if (aHaveMoreContinuations) {
-      *aHaveMoreContinuations = true;
-    }
-  }
-  return nextContinuation;
-}
-
-
-void
-GeckoRestyleManager::RestyleElement(Element*               aElement,
-                                    nsIFrame*              aPrimaryFrame,
-                                    nsChangeHint           aMinHint,
-                                    RestyleTracker&        aRestyleTracker,
-                                    nsRestyleHint          aRestyleHint,
-                                    const RestyleHintData& aRestyleHintData)
-{
-  MOZ_ASSERT(mReframingStyleContexts, "should have rsc");
-  NS_ASSERTION(aPrimaryFrame == aElement->GetPrimaryFrame(),
-               "frame/content mismatch");
-  if (aPrimaryFrame && aPrimaryFrame->GetContent() != aElement) {
-    // XXXbz this is due to image maps messing with the primary frame pointer
-    // of <area>s.  See bug 135040.  We can remove this block once that's fixed.
-    aPrimaryFrame = nullptr;
-  }
-  NS_ASSERTION(!aPrimaryFrame || aPrimaryFrame->GetContent() == aElement,
-               "frame/content mismatch");
-
-  // If we're restyling the root element and there are 'rem' units in
-  // use, handle dynamic changes to the definition of a 'rem' here.
-  if (PresContext()->UsesRootEMUnits() && aPrimaryFrame &&
-      !mInRebuildAllStyleData) {
-    GeckoStyleContext* oldContext = aPrimaryFrame->StyleContext()->AsGecko();
-    if (!oldContext->GetParent()) { // check that we're the root element
-      RefPtr<GeckoStyleContext> newContext = StyleSet()->
-        ResolveStyleFor(aElement, nullptr /* == oldContext->GetParent() */);
-      if (oldContext->StyleFont()->mFont.size !=
-          newContext->StyleFont()->mFont.size) {
-        // The basis for 'rem' units has changed.
-        mRebuildAllRestyleHint |= aRestyleHint;
-        if (aRestyleHint & eRestyle_SomeDescendants) {
-          mRebuildAllRestyleHint |= eRestyle_Subtree;
-        }
-        mRebuildAllExtraHint |= aMinHint;
-        StartRebuildAllStyleData(aRestyleTracker);
-        return;
-      }
-    }
-  }
-
-  if (aMinHint & nsChangeHint_ReconstructFrame) {
-    FrameConstructor()->RecreateFramesForContent(
-      aElement,
-      nsCSSFrameConstructor::InsertionKind::Sync);
-  } else if (aPrimaryFrame) {
-    ComputeAndProcessStyleChange(aPrimaryFrame, aMinHint, aRestyleTracker,
-                                 aRestyleHint, aRestyleHintData);
-  } else if (aRestyleHint & ~eRestyle_LaterSiblings) {
-    // We're restyling an element with no frame, so we should try to
-    // make one if its new style says it should have one.  But in order
-    // to try to honor the restyle hint (which we'd like to do so that,
-    // for example, an animation-only style flush doesn't flush other
-    // buffered style changes), we only do this if the restyle hint says
-    // we have *some* restyling for this frame.  This means we'll
-    // potentially get ahead of ourselves in that case, but not as much
-    // as we would if we didn't check the restyle hint.
-    nsStyleContext* newContext =
-      FrameConstructor()->MaybeRecreateFramesForElement(aElement);
-    if (newContext &&
-        newContext->StyleDisplay()->mDisplay == StyleDisplay::Contents) {
-      // Style change for a display:contents node that did not recreate frames.
-      ComputeAndProcessStyleChange(newContext->AsGecko(), aElement, aMinHint,
-                                   aRestyleTracker, aRestyleHint,
-                                   aRestyleHintData);
-    }
-  }
-}
-
-GeckoRestyleManager::ReframingStyleContexts
-                   ::ReframingStyleContexts(
-                       GeckoRestyleManager* aRestyleManager)
-  : mRestyleManager(aRestyleManager)
-  , mRestorePointer(mRestyleManager->mReframingStyleContexts)
-{
-  MOZ_ASSERT(!mRestyleManager->mReframingStyleContexts,
-             "shouldn't construct recursively");
-  mRestyleManager->mReframingStyleContexts = this;
-}
-
-GeckoRestyleManager::ReframingStyleContexts::~ReframingStyleContexts()
-{
-  // Before we go away, we need to flush out any frame construction that
-  // was enqueued, so that we initiate transitions.
-  // Note that this is a little bit evil in that we're calling into code
-  // that calls our member functions from our destructor, but it's at
-  // the beginning of our destructor, so it shouldn't be too bad.
-  mRestyleManager->PresContext()->FrameConstructor()->CreateNeededFrames();
-}
-
-static inline dom::Element*
-ElementForStyleContext(nsIContent* aParentContent,
-                       nsIFrame* aFrame,
-                       CSSPseudoElementType aPseudoType);
-
-// Forwarded nsIDocumentObserver method, to handle restyling (and
-// passing the notification to the frame).
-void
-GeckoRestyleManager::ContentStateChanged(nsIContent* aContent,
-                                         EventStates aStateMask)
-{
-  MOZ_ASSERT(!mInStyleRefresh);
-
-  // XXXbz it would be good if this function only took Elements, but
-  // we'd have to make ESM guarantee that usefully.
-  if (!aContent->IsElement()) {
-    return;
-  }
-
-  Element* aElement = aContent->AsElement();
-
-  nsChangeHint changeHint;
-  ContentStateChangedInternal(aElement, aStateMask, &changeHint);
-
-  // Assemble what we'll need to calculate the nsRestyleHint.
-  nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
-  CSSPseudoElementType pseudoType = CSSPseudoElementType::NotPseudo;
-  if (primaryFrame) {
-    pseudoType = primaryFrame->StyleContext()->GetPseudoType();
-  }
-
-  nsStyleSet* styleSet = PresContext()->StyleSet()->AsGecko();
-  MOZ_ASSERT(styleSet);
-
-  nsRestyleHint restyleHint;
-  if (pseudoType >= CSSPseudoElementType::Count) {
-    restyleHint = styleSet->HasStateDependentStyle(aElement, aStateMask);
-  } else if (nsCSSPseudoElements::PseudoElementSupportsUserActionState(
-               pseudoType)) {
-    // If aElement is a pseudo-element, we want to check to see whether there
-    // are any state-dependent rules applying to that pseudo.
-    Element* ancestor =
-      ElementForStyleContext(nullptr, primaryFrame, pseudoType);
-    restyleHint = styleSet->HasStateDependentStyle(ancestor, pseudoType,
-                                                   aElement, aStateMask);
-  } else {
-    restyleHint = nsRestyleHint(0);
-  }
-
-  if (aStateMask.HasState(NS_EVENT_STATE_HOVER) && restyleHint != 0) {
-    IncrementHoverGeneration();
-  }
-
-  PostRestyleEvent(aElement, restyleHint, changeHint);
-}
-
-// Forwarded nsIMutationObserver method, to handle restyling.
-void
-GeckoRestyleManager::AttributeWillChange(Element* aElement,
-                                         int32_t aNameSpaceID,
-                                         nsAtom* aAttribute,
-                                         int32_t aModType,
-                                         const nsAttrValue* aNewValue)
-{
-  MOZ_ASSERT(!mInStyleRefresh);
-
-  RestyleHintData rsdata;
-  nsRestyleHint rshint =
-    StyleSet()->HasAttributeDependentStyle(aElement,
-                                           aNameSpaceID,
-                                           aAttribute,
-                                           aModType,
-                                           false,
-                                           aNewValue,
-                                           rsdata);
-  PostRestyleEvent(aElement, rshint, nsChangeHint(0), &rsdata);
-}
-
-// Forwarded nsIMutationObserver method, to handle restyling (and
-// passing the notification to the frame).
-void
-GeckoRestyleManager::AttributeChanged(Element* aElement,
-                                      int32_t aNameSpaceID,
-                                      nsAtom* aAttribute,
-                                      int32_t aModType,
-                                      const nsAttrValue* aOldValue)
-{
-  MOZ_ASSERT(!mInStyleRefresh);
-
-  // Hold onto the PresShell to prevent ourselves from being destroyed.
-  // XXXbz how, exactly, would this attribute change cause us to be
-  // destroyed from inside this function?
-  nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
-  mozilla::Unused << shell; // Unused within this function
-
-  // Get the frame associated with the content which is the highest in the frame tree
-  nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
-
-#if 0
-  NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
-     ("RestyleManager::AttributeChanged: content=%p[%s] frame=%p",
-      aContent, ContentTag(aElement, 0), frame));
-#endif
-
-  // the style tag has its own interpretation based on aHint
-  nsChangeHint hint = aElement->GetAttributeChangeHint(aAttribute, aModType);
-
-  bool reframe = (hint & nsChangeHint_ReconstructFrame) != 0;
-
-#ifdef MOZ_XUL
-  // The following listbox widget trap prevents offscreen listbox widget
-  // content from being removed and re-inserted (which is what would
-  // happen otherwise).
-  if (!primaryFrame && !reframe) {
-    int32_t namespaceID;
-    nsAtom* tag = PresContext()->Document()->BindingManager()->
-                     ResolveTag(aElement, &namespaceID);
-
-    if (namespaceID == kNameSpaceID_XUL &&
-        (tag == nsGkAtoms::listitem ||
-         tag == nsGkAtoms::listcell))
-      return;
-  }
-#endif // MOZ_XUL
-
-  if (primaryFrame) {
-    // See if we have appearance information for a theme.
-    const nsStyleDisplay* disp = primaryFrame->StyleDisplay();
-    if (disp->mAppearance) {
-      nsITheme* theme = PresContext()->GetTheme();
-      if (theme && theme->ThemeSupportsWidget(PresContext(), primaryFrame, disp->mAppearance)) {
-        bool repaint = false;
-        theme->WidgetStateChanged(primaryFrame, disp->mAppearance, aAttribute,
-            &repaint, aOldValue);
-        if (repaint)
-          hint |= nsChangeHint_RepaintFrame;
-      }
-    }
-
-    // let the frame deal with it now, so we don't have to deal later
-    primaryFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
-    // XXXwaterson should probably check for IB split siblings
-    // here, and propagate the AttributeChanged notification to
-    // them, as well. Currently, inline frames don't do anything on
-    // this notification, so it's not that big a deal.
-  }
-
-  // See if we can optimize away the style re-resolution -- must be called after
-  // the frame's AttributeChanged() in case it does something that affects the style
-  RestyleHintData rsdata;
-  nsRestyleHint rshint =
-    StyleSet()->HasAttributeDependentStyle(aElement,
-                                           aNameSpaceID,
-                                           aAttribute,
-                                           aModType,
-                                           true,
-                                           aOldValue,
-                                           rsdata);
-  PostRestyleEvent(aElement, rshint, hint, &rsdata);
-}
-
-void
-GeckoRestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
-                                         nsRestyleHint aRestyleHint)
-{
-  NS_ASSERTION(!(aExtraHint & nsChangeHint_ReconstructFrame),
-               "Should not reconstruct the root of the frame tree.  "
-               "Use ReconstructDocElementHierarchy instead.");
-  MOZ_ASSERT(!(aRestyleHint & ~(eRestyle_Subtree | eRestyle_ForceDescendants)),
-             "the only bits allowed in aRestyleHint are eRestyle_Subtree and "
-             "eRestyle_ForceDescendants");
-
-  mRebuildAllExtraHint |= aExtraHint;
-  mRebuildAllRestyleHint |= aRestyleHint;
-
-  // Processing the style changes could cause a flush that propagates to
-  // the parent frame and thus destroys the pres shell, so we must hold
-  // a reference.
-  nsCOMPtr<nsIPresShell> presShell = PresContext()->GetPresShell();
-  if (!presShell || !presShell->GetRootFrame()) {
-    mDoRebuildAllStyleData = false;
-    return;
-  }
-
-  // Make sure that the viewmanager will outlive the presshell
-  RefPtr<nsViewManager> vm = presShell->GetViewManager();
-  mozilla::Unused << vm; // Not used within this function
-
-  // We may reconstruct frames below and hence process anything that is in the
-  // tree. We don't want to get notified to process those items again after.
-  presShell->GetDocument()->FlushPendingNotifications(FlushType::ContentAndNotify);
-
-  nsAutoScriptBlocker scriptBlocker;
-
-  mDoRebuildAllStyleData = true;
-
-  ProcessPendingRestyles();
-}
-
-void
-GeckoRestyleManager::StartRebuildAllStyleData(RestyleTracker& aRestyleTracker)
-{
-  MOZ_ASSERT(mIsProcessingRestyles);
-
-  nsIFrame* rootFrame = PresContext()->PresShell()->GetRootFrame();
-  if (!rootFrame) {
-    // No need to do anything.
-    return;
-  }
-
-  mInRebuildAllStyleData = true;
-
-  // Tell the style set to get the old rule tree out of the way
-  // so we can recalculate while maintaining rule tree immutability
-  nsresult rv = StyleSet()->BeginReconstruct();
-  if (NS_FAILED(rv)) {
-    MOZ_CRASH("unable to rebuild style data");
-  }
-
-  nsRestyleHint restyleHint = mRebuildAllRestyleHint;
-  nsChangeHint changeHint = mRebuildAllExtraHint;
-  mRebuildAllExtraHint = nsChangeHint(0);
-  mRebuildAllRestyleHint = nsRestyleHint(0);
-
-  restyleHint |= eRestyle_ForceDescendants;
-
-  if (!(restyleHint & eRestyle_Subtree) &&
-      (restyleHint & ~(eRestyle_Force | eRestyle_ForceDescendants))) {
-    // We want this hint to apply to the root node's primary frame
-    // rather than the root frame, since it's the primary frame that has
-    // the styles for the root element (rather than the ancestors of the
-    // primary frame whose mContent is the root node but which have
-    // different styles).  If we use up the hint for one of the
-    // ancestors that we hit first, then we'll fail to do the restyling
-    // we need to do.
-    Element* root = PresContext()->Document()->GetRootElement();
-    if (root) {
-      // If the root element is gone, dropping the hint on the floor
-      // should be fine.
-      aRestyleTracker.AddPendingRestyle(root, restyleHint, nsChangeHint(0));
-    }
-    restyleHint = nsRestyleHint(0);
-  }
-
-  // Recalculate all of the style contexts for the document, from the
-  // root frame.  We can't do this with a change hint, since we can't
-  // post a change hint for the root frame.
-  // Note that we can ignore the return value of ComputeStyleChangeFor
-  // because we never need to reframe the root frame.
-  // XXX Does it matter that we're passing aExtraHint to the real root
-  // frame and not the root node's primary frame?  (We could do
-  // roughly what we do for aRestyleHint above.)
-  ComputeAndProcessStyleChange(rootFrame,
-                               changeHint, aRestyleTracker, restyleHint,
-                               RestyleHintData());
-}
-
-void
-GeckoRestyleManager::FinishRebuildAllStyleData()
-{
-  MOZ_ASSERT(mInRebuildAllStyleData, "bad caller");
-
-  // Tell the style set it's safe to destroy the old rule tree.  We
-  // must do this after the ProcessRestyledFrames call in case the
-  // change list has frame reconstructs in it (since frames to be
-  // reconstructed will still have their old style context pointers
-  // until they are destroyed).
-  StyleSet()->EndReconstruct();
-
-  mInRebuildAllStyleData = false;
-}
-
-void
-GeckoRestyleManager::ProcessPendingRestyles()
-{
-  NS_PRECONDITION(PresContext()->Document(), "No document?  Pshaw!");
-  NS_PRECONDITION(!nsContentUtils::IsSafeToRunScript(),
-                  "Missing a script blocker!");
-  // NOTE(emilio): Gecko calls into here from RebuildAllStyleData synchronously,
-  // without ensuring that all the media-query state is up-to-date.
-  //
-  // That is slightly bogus on its own, but it's long-standing and working on
-  // not rebuilding the rule tree synchronously on the old style system at this
-  // point is probably not worth the effort. Note bug 1089417 comment 21, which
-  // may or may not be an issue here.
-  MOZ_ASSERT(!PresContext()->HasPendingMediaQueryUpdates() ||
-             mDoRebuildAllStyleData,
-             "Someone forgot to update media queries?");
-
-  // First do any queued-up frame creation.  (We should really
-  // merge this into the rest of the process, though; see bug 827239.)
-  PresContext()->FrameConstructor()->CreateNeededFrames();
-
-  // Process non-animation restyles...
-  MOZ_ASSERT(!mIsProcessingRestyles,
-             "Nesting calls to ProcessPendingRestyles?");
-  mIsProcessingRestyles = true;
-
-  // Before we process any restyles, we need to ensure that style
-  // resulting from any animations is up-to-date, so that if any style
-  // changes we cause trigger transitions, we have the correct old style
-  // for starting the transition.
-  bool haveNonAnimation =
-    mHavePendingNonAnimationRestyles || mDoRebuildAllStyleData;
-  if (haveNonAnimation) {
-    ++mAnimationGeneration;
-    UpdateOnlyAnimationStyles();
-  } else {
-    // If we don't have non-animation style updates, then we have queued
-    // up animation style updates from the refresh driver tick.  This
-    // doesn't necessarily include *all* animation style updates, since
-    // we might be suppressing main-thread updates for some animations,
-    // so we don't want to call UpdateOnlyAnimationStyles, which updates
-    // all animations.  In other words, the work that we're about to do
-    // to process the pending restyles queue is a *subset* of the work
-    // that UpdateOnlyAnimationStyles would do, since we're *not*
-    // updating transitions that are running on the compositor thread
-    // and suppressed on the main thread.
-    //
-    // But when we update those styles, we want to suppress updates to
-    // transitions just like we do in UpdateOnlyAnimationStyles.  So we
-    // want to tell the transition manager to act as though we're in
-    // UpdateOnlyAnimationStyles.
-    //
-    // FIXME: In the future, we might want to refactor the way the
-    // animation and transition manager do their refresh driver ticks so
-    // that we can use UpdateOnlyAnimationStyles, with a different
-    // boolean argument, for this update as well, instead of having them
-    // post style updates in their WillRefresh methods.
-    PresContext()->TransitionManager()->SetInAnimationOnlyStyleUpdate(true);
-  }
-
-  ProcessRestyles(mPendingRestyles);
-
-  if (!haveNonAnimation) {
-    PresContext()->TransitionManager()->SetInAnimationOnlyStyleUpdate(false);
-  }
-
-  mIsProcessingRestyles = false;
-
-  NS_ASSERTION(haveNonAnimation || !mHavePendingNonAnimationRestyles,
-               "should not have added restyles");
-  mHavePendingNonAnimationRestyles = false;
-
-  if (mDoRebuildAllStyleData) {
-    // We probably wasted a lot of work up above, but this seems safest
-    // and it should be rarely used.
-    // This might add us as a refresh observer again; that's ok.
-    ProcessPendingRestyles();
-
-    NS_ASSERTION(!mDoRebuildAllStyleData,
-                 "repeatedly setting mDoRebuildAllStyleData?");
-  }
-
-  MOZ_ASSERT(!mInRebuildAllStyleData,
-             "should have called FinishRebuildAllStyleData");
-}
-
-void
-GeckoRestyleManager::BeginProcessingRestyles(RestyleTracker& aRestyleTracker)
-{
-  mInStyleRefresh = true;
-
-  if (ShouldStartRebuildAllFor(aRestyleTracker)) {
-    mDoRebuildAllStyleData = false;
-    StartRebuildAllStyleData(aRestyleTracker);
-  }
-}
-
-void
-GeckoRestyleManager::EndProcessingRestyles()
-{
-  FlushOverflowChangedTracker();
-
-  MOZ_ASSERT(mAnimationsWithDestroyedFrame);
-  mAnimationsWithDestroyedFrame->
-    StopAnimationsForElementsWithoutFrames();
-
-  // Set mInStyleRefresh to false now, since the EndUpdate call might
-  // add more restyles.
-  mInStyleRefresh = false;
-
-  if (mInRebuildAllStyleData) {
-    FinishRebuildAllStyleData();
-  }
-
-#ifdef DEBUG
-  PresContext()->PresShell()->VerifyStyleTree();
-#endif
-}
-
-void
-GeckoRestyleManager::UpdateOnlyAnimationStyles()
-{
-  bool doCSS = PresContext()->EffectCompositor()->HasPendingStyleUpdates();
-
-  nsIDocument* document = PresContext()->Document();
-  nsSMILAnimationController* animationController =
-    document->HasAnimationController() ?
-    document->GetAnimationController() :
-    nullptr;
-  bool doSMIL = animationController &&
-                animationController->MightHavePendingStyleUpdates();
-
-  if (!doCSS && !doSMIL) {
-    return;
-  }
-
-  nsTransitionManager* transitionManager = PresContext()->TransitionManager();
-
-  transitionManager->SetInAnimationOnlyStyleUpdate(true);
-
-  RestyleTracker tracker(ELEMENT_HAS_PENDING_ANIMATION_ONLY_RESTYLE |
-                         ELEMENT_IS_POTENTIAL_ANIMATION_ONLY_RESTYLE_ROOT);
-  tracker.Init(this);
-
-  if (doCSS) {
-    PresContext()->EffectCompositor()->AddStyleUpdatesTo(tracker);
-  }
-
-  if (doSMIL) {
-    animationController->AddStyleUpdatesTo(tracker);
-  }
-
-  ProcessRestyles(tracker);
-
-  transitionManager->SetInAnimationOnlyStyleUpdate(false);
-}
-
-void
-GeckoRestyleManager::PostRestyleEventInternal()
-{
-  // Make sure we're not in a style refresh; if we are, we still have
-  // a call to ProcessPendingRestyles coming and there's no need to
-  // add ourselves as a refresh observer until then.
-  nsIPresShell* presShell = PresContext()->PresShell();
-  if (!mInStyleRefresh) {
-    presShell->ObserveStyleFlushes();
-  }
-
-  // Unconditionally flag our document as needing a flush.  The other
-  // option here would be a dedicated boolean to track whether we need
-  // to do so (set here and unset in ProcessPendingRestyles).
-  presShell->SetNeedStyleFlush();
-}
-
-
-void
-GeckoRestyleManager::PostRestyleEvent(Element* aElement,
-                                      nsRestyleHint aRestyleHint,
-                                      nsChangeHint aMinChangeHint,
-                                      const RestyleHintData* aRestyleHintData)
-{
-  if (MOZ_UNLIKELY(IsDisconnected()) ||
-      MOZ_UNLIKELY(PresContext()->PresShell()->IsDestroying())) {
-    return;
-  }
-
-  if (aRestyleHint == 0 && !aMinChangeHint) {
-    // Nothing to do here
-    return;
-  }
-
-  mPendingRestyles.AddPendingRestyle(aElement, aRestyleHint, aMinChangeHint,
-                                     aRestyleHintData);
-
-  // Set mHavePendingNonAnimationRestyles for any restyle that could
-  // possibly contain non-animation styles (i.e., those that require us
-  // to do an animation-only style flush before processing style changes
-  // to ensure correct initialization of CSS transitions).
-  if (aRestyleHint & ~eRestyle_AllHintsWithAnimations) {
-    mHavePendingNonAnimationRestyles = true;
-  }
-
-  PostRestyleEventInternal();
-}
-
-void
-GeckoRestyleManager::PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
-                                                  nsRestyleHint aRestyleHint)
-{
-  NS_ASSERTION(!(aExtraHint & nsChangeHint_ReconstructFrame),
-               "Should not reconstruct the root of the frame tree.  "
-               "Use ReconstructDocElementHierarchy instead.");
-  MOZ_ASSERT(!(aRestyleHint & eRestyle_SomeDescendants),
-             "PostRebuildAllStyleDataEvent does not handle "
-             "eRestyle_SomeDescendants");
-
-  mDoRebuildAllStyleData = true;
-  mRebuildAllExtraHint |= aExtraHint;
-  mRebuildAllRestyleHint |= aRestyleHint;
-
-  // Get a restyle event posted if necessary
-  PostRestyleEventInternal();
-}
-
-// aContent must be the content for the frame in question, which may be
-// :before/:after content
-/* static */ bool
-GeckoRestyleManager::TryInitiatingTransition(nsPresContext* aPresContext,
-                                             nsIContent* aContent,
-                                             GeckoStyleContext* aOldStyleContext,
-                                             RefPtr<GeckoStyleContext>*
-                                               aNewStyleContext /* inout */)
-{
-  if (!aContent || !aContent->IsElement()) {
-    return false;
-  }
-
-  // Notify the transition manager.  If it starts a transition,
-  // it might modify the new style context.
-  RefPtr<GeckoStyleContext> sc = *aNewStyleContext;
-  aPresContext->TransitionManager()->StyleContextChanged(
-    aContent->AsElement(), aOldStyleContext, aNewStyleContext);
-  return *aNewStyleContext != sc;
-}
-
-static dom::Element*
-ElementForStyleContext(nsIContent* aParentContent,
-                       nsIFrame* aFrame,
-                       CSSPseudoElementType aPseudoType)
-{
-  // We don't expect XUL tree stuff here.
-  NS_PRECONDITION(aPseudoType == CSSPseudoElementType::NotPseudo ||
-                  aPseudoType == CSSPseudoElementType::InheritingAnonBox ||
-                  aPseudoType == CSSPseudoElementType::NonInheritingAnonBox ||
-                  aPseudoType < CSSPseudoElementType::Count,
-                  "Unexpected pseudo");
-  // XXX see the comments about the various element confusion in
-  // ElementRestyler::Restyle.
-  if (aPseudoType == CSSPseudoElementType::NotPseudo) {
-    return aFrame->GetContent()->AsElement();
-  }
-
-  if (aPseudoType == CSSPseudoElementType::InheritingAnonBox ||
-      aPseudoType == CSSPseudoElementType::NonInheritingAnonBox) {
-    return nullptr;
-  }
-
-  if (aPseudoType == CSSPseudoElementType::firstLetter) {
-    NS_ASSERTION(aFrame->IsLetterFrame(),
-                 "firstLetter pseudoTag without a nsFirstLetterFrame");
-    nsBlockFrame* block = nsBlockFrame::GetNearestAncestorBlock(aFrame);
-    return block->GetContent()->AsElement();
-  }
-
-  if (aPseudoType == CSSPseudoElementType::mozColorSwatch) {
-    MOZ_ASSERT(aFrame->GetParent() &&
-               aFrame->GetParent()->GetParent(),
-               "Color swatch frame should have a parent & grandparent");
-
-    nsIFrame* grandparentFrame = aFrame->GetParent()->GetParent();
-    MOZ_ASSERT(grandparentFrame->IsColorControlFrame(),
-               "Color swatch's grandparent should be nsColorControlFrame");
-
-    return grandparentFrame->GetContent()->AsElement();
-  }
-
-  if (aPseudoType == CSSPseudoElementType::mozNumberText ||
-      aPseudoType == CSSPseudoElementType::mozNumberWrapper ||
-      aPseudoType == CSSPseudoElementType::mozNumberSpinBox ||
-      aPseudoType == CSSPseudoElementType::mozNumberSpinUp ||
-      aPseudoType == CSSPseudoElementType::mozNumberSpinDown) {
-    // Get content for nearest nsNumberControlFrame:
-    nsIFrame* f = aFrame->GetParent();
-    MOZ_ASSERT(f);
-    while (!f->IsNumberControlFrame()) {
-      f = f->GetParent();
-      MOZ_ASSERT(f);
-    }
-    return f->GetContent()->AsElement();
-  }
-
-  Element* frameElement = aFrame->GetContent()->AsElement();
-  if (frameElement->IsNativeAnonymous()) {
-    // NAC-implemented pseudos use the closest non-NAC element as their
-    // element to inherit from.
-    Element* originatingElement =
-      nsContentUtils::GetClosestNonNativeAnonymousAncestor(frameElement);
-    if (originatingElement) {
-      return originatingElement;
-    }
-  }
-
-  if (aParentContent) {
-    return aParentContent->AsElement();
-  }
-
-  MOZ_ASSERT(aFrame->GetContent()->GetParent(),
-             "should not have got here for the root element");
-  return aFrame->GetContent()->GetParent()->AsElement();
-}
-
-/**
- * Some pseudo-elements actually have a content node created for them,
- * whereas others have only a frame but not a content node.  In some
- * cases, we want to support style attributes or states on those
- * elements.  For those pseudo-elements, we need to pass the
- * anonymous pseudo-element content to selector matching processes in
- * addition to the element that the pseudo-element is for; in other
- * cases we should pass null instead.  This function returns the
- * pseudo-element content that we should pass.
- */
-static dom::Element*
-PseudoElementForStyleContext(nsIFrame* aFrame,
-                             CSSPseudoElementType aPseudoType)
-{
-  if (aPseudoType >= CSSPseudoElementType::Count) {
-    return nullptr;
-  }
-
-  if (nsCSSPseudoElements::PseudoElementSupportsStyleAttribute(aPseudoType) ||
-      nsCSSPseudoElements::PseudoElementSupportsUserActionState(aPseudoType)) {
-    return aFrame->GetContent()->AsElement();
-  }
-
-  return nullptr;
-}
-
-/**
- * FIXME: Temporary.  Should merge with following function.
- */
-static nsIFrame*
-GetPrevContinuationWithPossiblySameStyle(nsIFrame* aFrame)
-{
-  // Account for {ib} splits when looking for "prevContinuation".  In
-  // particular, for the first-continuation of a part of an {ib} split
-  // we want to use the previous ib-split sibling of the previous
-  // ib-split sibling of aFrame, which should have the same style
-  // context as aFrame itself.  In particular, if aFrame is the first
-  // continuation of an inline part of a block-in-inline split then its
-  // previous ib-split sibling is a block, and the previous ib-split
-  // sibling of _that_ is an inline, just like aFrame.  Similarly, if
-  // aFrame is the first continuation of a block part of an
-  // block-in-inline split (a block-in-inline wrapper block), then its
-  // previous ib-split sibling is an inline and the previous ib-split
-  // sibling of that is either another block-in-inline wrapper block box
-  // or null.
-  nsIFrame* prevContinuation = aFrame->GetPrevContinuation();
-  if (!prevContinuation &&
-      (aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
-    // We're the first continuation, so we can just get the frame
-    // property directly
-    prevContinuation =
-      aFrame->GetProperty(nsIFrame::IBSplitPrevSibling());
-    if (prevContinuation) {
-      prevContinuation =
-        prevContinuation->GetProperty(nsIFrame::IBSplitPrevSibling());
-    }
-  }
-
-  NS_ASSERTION(!prevContinuation ||
-               prevContinuation->GetContent() == aFrame->GetContent(),
-               "unexpected content mismatch");
-
-  return prevContinuation;
-}
-
-/**
- * Get the previous continuation or similar ib-split sibling (assuming
- * block/inline alternation), conditionally on it having the same style.
- * This assumes that we're not between resolving the two (i.e., that
- * they're both already resolved.
- */
-static nsIFrame*
-GetPrevContinuationWithSameStyle(nsIFrame* aFrame)
-{
-  nsIFrame* prevContinuation = GetPrevContinuationWithPossiblySameStyle(aFrame);
-  if (!prevContinuation) {
-    return nullptr;
-  }
-
-  GeckoStyleContext* prevStyle = prevContinuation->StyleContext()->AsGecko();
-  GeckoStyleContext* selfStyle = aFrame->StyleContext()->AsGecko();
-  if (prevStyle != selfStyle) {
-    NS_ASSERTION(prevStyle->GetPseudo() != selfStyle->GetPseudo() ||
-                 prevStyle->GetParent() != selfStyle->GetParent(),
-                 "continuations should have the same style context");
-    prevContinuation = nullptr;
-  }
-  return prevContinuation;
-}
-
-nsresult
-GeckoRestyleManager::ReparentStyleContext(nsIFrame* aFrame)
-{
-  LayoutFrameType frameType = aFrame->Type();
-  if (frameType == LayoutFrameType::Placeholder) {
-    // Also reparent the out-of-flow and all its continuations.
-    nsIFrame* outOfFlow =
-      nsPlaceholderFrame::GetRealFrameForPlaceholder(aFrame);
-    NS_ASSERTION(outOfFlow, "no out-of-flow frame");
-    do {
-      ReparentStyleContext(outOfFlow);
-    } while ((outOfFlow = outOfFlow->GetNextContinuation()));
-  } else if (frameType == LayoutFrameType::Backdrop) {
-    // Style context of backdrop frame has no parent style context, and
-    // thus we do not need to reparent it.
-    return NS_OK;
-  }
-
-  // DO NOT verify the style tree before reparenting.  The frame
-  // tree has already been changed, so this check would just fail.
-  GeckoStyleContext* oldContext = aFrame->StyleContext()->AsGecko();
-
-  RefPtr<GeckoStyleContext> newContext;
-  nsIFrame* providerFrame;
-  nsStyleContext* newParentContext =
-    aFrame->GetParentStyleContext(&providerFrame);
-  bool isChild = providerFrame && providerFrame->GetParent() == aFrame;
-  nsIFrame* providerChild = nullptr;
-  if (isChild) {
-    ReparentStyleContext(providerFrame);
-    // Get the style context again after ReparentStyleContext() which might have
-    // changed it.
-    newParentContext = providerFrame->StyleContext();
-    providerChild = providerFrame;
-  }
-
-#ifdef DEBUG
-  {
-    // Check that our assumption that continuations of the same
-    // pseudo-type and with the same style context parent have the
-    // same style context is valid before the reresolution.  (We need
-    // to check the pseudo-type and style context parent because of
-    // :first-letter and :first-line, where we create styled and
-    // unstyled letter/line frames distinguished by pseudo-type, and
-    // then need to distinguish their descendants based on having
-    // different parents.)
-    nsIFrame* nextContinuation = aFrame->GetNextContinuation();
-    if (nextContinuation) {
-      GeckoStyleContext* nextContinuationContext =
-        nextContinuation->StyleContext()->AsGecko();
-      NS_ASSERTION(oldContext == nextContinuationContext ||
-                   oldContext->GetPseudo() !=
-                     nextContinuationContext->GetPseudo() ||
-                   oldContext->GetParent() !=
-                     nextContinuationContext->GetParent(),
-                   "continuations should have the same style context");
-    }
-  }
-#endif
-
-  if (!newParentContext && !oldContext->GetParent()) {
-    // No need to do anything here for this frame, but we should still reparent
-    // its descendants, because those may have styles that inherit from the
-    // parent of this frame (e.g. non-anonymous columns in an anonymous
-    // colgroup).
-    MOZ_ASSERT(aFrame->StyleContext()->IsNonInheritingAnonBox(),
-               "Why did this frame not end up with a parent context?");
-    ReparentFrameDescendants(aFrame, providerChild);
-    return NS_OK;
-  }
-
-  NS_ASSERTION(newParentContext, "Reparenting something that has no usable"
-               " parent? Shouldn't happen!");
-  // XXX need to do something here to produce the correct style context for
-  // an IB split whose first inline part is inside a first-line frame.
-  // Currently the first IB anonymous block's style context takes the first
-  // part's style context as parent, which is wrong since first-line style
-  // should not apply to the anonymous block.
-
-  nsIFrame* prevContinuation =
-    GetPrevContinuationWithPossiblySameStyle(aFrame);
-  GeckoStyleContext* prevContinuationContext;
-  bool copyFromContinuation =
-    prevContinuation &&
-    (prevContinuationContext = prevContinuation->StyleContext()->AsGecko())
-      ->GetPseudo() == oldContext->GetPseudo() &&
-     prevContinuationContext->GetParent() == newParentContext;
-  if (copyFromContinuation) {
-    // Just use the style context from the frame's previous
-    // continuation (see assertion about aFrame->GetNextContinuation()
-    // above, which we would have previously hit for aFrame's previous
-    // continuation).
-    newContext = prevContinuationContext;
-  } else {
-    nsIFrame* parentFrame = aFrame->GetParent();
-    Element* element =
-      ElementForStyleContext(parentFrame ? parentFrame->GetContent() : nullptr,
-                             aFrame,
-                             oldContext->GetPseudoType());
-    newContext = StyleSet()->ReparentStyleContext(
-        oldContext, newParentContext->AsGecko(), element);
-  }
-
-  if (newContext) {
-    if (newContext != oldContext) {
-      // We probably don't want to initiate transitions from
-      // ReparentStyleContext, since we call it during frame
-      // construction rather than in response to dynamic changes.
-      // Also see the comment at the start of
-      // nsTransitionManager::ConsiderInitiatingTransition.
-#if 0
-      if (!copyFromContinuation) {
-        TryInitiatingTransition(mPresContext, aFrame->GetContent(),
-                                oldContext, &newContext);
-      }
-#endif
-
-      // Ensure the new context ends up resolving all the structs the old
-      // context resolved.
-      if (!copyFromContinuation) {
-        newContext->AsGecko()->EnsureSameStructsCached(oldContext);
-      }
-
-      aFrame->SetStyleContext(newContext);
-
-      ReparentFrameDescendants(aFrame, providerChild);
-
-      // If this frame is part of an IB split, then the style context of
-      // the next part of the split might be a child of our style context.
-      // Reparent its style context just in case one of our ancestors
-      // (split or not) hasn't done so already). It's not a problem to
-      // reparent the same frame twice because the "if (newContext !=
-      // oldContext)" check will prevent us from redoing work.
-      if ((aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT) &&
-          !aFrame->GetPrevContinuation()) {
-        nsIFrame* sib = aFrame->GetProperty(nsIFrame::IBSplitSibling());
-        if (sib) {
-          ReparentStyleContext(sib);
-        }
-      }
-
-      // do additional contexts
-      int32_t contextIndex = 0;
-      for (nsStyleContext* oldExtraContext;
-           (oldExtraContext = aFrame->GetAdditionalStyleContext(contextIndex));
-           ++contextIndex) {
-        RefPtr<GeckoStyleContext> newExtraContext;
-        newExtraContext = StyleSet()->
-                            ReparentStyleContext(oldExtraContext->AsGecko(),
-                                                 newContext, nullptr);
-        if (newExtraContext) {
-          if (newExtraContext != oldExtraContext) {
-            // Ensure the new context ends up resolving all the structs the old
-            // context resolved.
-            newContext->AsGecko()->EnsureSameStructsCached(oldContext);
-          }
-
-          aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);
-        }
-      }
-#ifdef DEBUG
-      DebugVerifyStyleTree(aFrame);
-#endif
-    }
-  }
-
-  return NS_OK;
-}
-
-void
-GeckoRestyleManager::ReparentFrameDescendants(nsIFrame* aFrame,
-                                              nsIFrame* aProviderChild)
-{
-  nsIFrame::ChildListIterator lists(aFrame);
-  for (; !lists.IsDone(); lists.Next()) {
-    for (nsIFrame* child : lists.CurrentList()) {
-      // only do frames that are in flow
-      if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
-          child != aProviderChild) {
-#ifdef DEBUG
-        if (child->IsPlaceholderFrame()) {
-          nsIFrame* outOfFlowFrame =
-            nsPlaceholderFrame::GetRealFrameForPlaceholder(child);
-          NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
-
-          NS_ASSERTION(outOfFlowFrame != aProviderChild,
-                       "Out of flow provider?");
-        }
-#endif
-        ReparentStyleContext(child);
-      }
-    }
-  }
-}
-
-ElementRestyler::ElementRestyler(nsPresContext* aPresContext,
-                                 nsIFrame* aFrame,
-                                 nsStyleChangeList* aChangeList,
-                                 nsChangeHint aHintsHandledByAncestors,
-                                 RestyleTracker& aRestyleTracker,
-                                 nsTArray<nsCSSSelector*>&
-                                   aSelectorsForDescendants,
-                                 TreeMatchContext& aTreeMatchContext,
-                                 nsTArray<nsIContent*>&
-                                   aVisibleKidsOfHiddenElement,
-                                 nsTArray<ContextToClear>& aContextsToClear,
-                                 nsTArray<RefPtr<GeckoStyleContext>>&
-                                   aSwappedStructOwners)
-  : mPresContext(aPresContext)
-  , mFrame(aFrame)
-  , mParentContent(nullptr)
-    // XXXldb Why does it make sense to use aParentContent?  (See
-    // comment above assertion at start of ElementRestyler::Restyle.)
-  , mContent(mFrame->GetContent() ? mFrame->GetContent() : mParentContent)
-  , mChangeList(aChangeList)
-  , mHintsHandledByAncestors(aHintsHandledByAncestors)
-  , mHintsHandledBySelf(nsChangeHint(0))
-  , mRestyleTracker(aRestyleTracker)
-  , mSelectorsForDescendants(aSelectorsForDescendants)
-  , mTreeMatchContext(aTreeMatchContext)
-  , mResolvedChild(nullptr)
-  , mContextsToClear(aContextsToClear)
-  , mSwappedStructOwners(aSwappedStructOwners)
-  , mIsRootOfRestyle(true)
-#ifdef ACCESSIBILITY
-  , mDesiredA11yNotifications(eSendAllNotifications)
-  , mKidsDesiredA11yNotifications(mDesiredA11yNotifications)
-  , mOurA11yNotification(eDontNotify)
-  , mVisibleKidsOfHiddenElement(aVisibleKidsOfHiddenElement)
-#endif
-#ifdef RESTYLE_LOGGING
-  , mLoggingDepth(aRestyleTracker.LoggingDepth() + 1)
-#endif
-{
-  MOZ_ASSERT(!mContent || !mContent->IsStyledByServo());
-  MOZ_ASSERT(!(mHintsHandledByAncestors & nsChangeHint_ReconstructFrame),
-             "why restyle descendants if we are reconstructing the frame for "
-             "an ancestor?");
-}
-
-ElementRestyler::ElementRestyler(const ElementRestyler& aParentRestyler,
-                                 nsIFrame* aFrame,
-                                 uint32_t aConstructorFlags)
-  : mPresContext(aParentRestyler.mPresContext)
-  , mFrame(aFrame)
-  , mParentContent(aParentRestyler.mContent)
-    // XXXldb Why does it make sense to use aParentContent?  (See
-    // comment above assertion at start of ElementRestyler::Restyle.)
-  , mContent(mFrame->GetContent() ? mFrame->GetContent() : mParentContent)
-  , mChangeList(aParentRestyler.mChangeList)
-  , mHintsHandledByAncestors(
-      // Note that when FOR_OUT_OF_FLOW_CHILD, the out-of-flow may not be a
-      // geometric descendant of the frame where we started the reresolve.
-      // Therefore, even if mHintsHandledByAncestors already includes
-      // nsChangeHint_AllReflowHints/ we don't want to pass that on to the
-      // out-of-flow reresolve, since that can lead to the out-of-flow not
-      // getting reflowed when it should be (eg a reresolve starting at <body>
-      // that involves reflowing the <body> would miss reflowing fixed-pos
-      // nodes that also need reflow).  In the cases when the out-of-flow _is_
-      // a geometric descendant of a frame we already have a reflow hint
-      // for, reflow coalescing should keep us from doing the work twice.
-      (aParentRestyler.mHintsHandledByAncestors |
-       aParentRestyler.mHintsHandledBySelf) &
-      ((aConstructorFlags & FOR_OUT_OF_FLOW_CHILD) ?
-       ~nsChangeHint_AllReflowHints : ~nsChangeHint(0)))
-  , mHintsHandledBySelf(nsChangeHint(0))
-  , mRestyleTracker(aParentRestyler.mRestyleTracker)
-  , mSelectorsForDescendants(aParentRestyler.mSelectorsForDescendants)
-  , mTreeMatchContext(aParentRestyler.mTreeMatchContext)
-  , mResolvedChild(nullptr)
-  , mContextsToClear(aParentRestyler.mContextsToClear)
-  , mSwappedStructOwners(aParentRestyler.mSwappedStructOwners)
-  , mIsRootOfRestyle(false)
-#ifdef ACCESSIBILITY
-  , mDesiredA11yNotifications(aParentRestyler.mKidsDesiredA11yNotifications)
-  , mKidsDesiredA11yNotifications(mDesiredA11yNotifications)
-  , mOurA11yNotification(eDontNotify)
-  , mVisibleKidsOfHiddenElement(aParentRestyler.mVisibleKidsOfHiddenElement)
-#endif
-#ifdef RESTYLE_LOGGING
-  , mLoggingDepth(aParentRestyler.mLoggingDepth + 1)
-#endif
-{
-  MOZ_ASSERT(!mContent || !mContent->IsStyledByServo());
-  MOZ_ASSERT(!(mHintsHandledByAncestors & nsChangeHint_ReconstructFrame),
-             "why restyle descendants if we are reconstructing the frame for "
-             "an ancestor?");
-}
-
-ElementRestyler::ElementRestyler(ParentContextFromChildFrame,
-                                 const ElementRestyler& aParentRestyler,
-                                 nsIFrame* aFrame)
-  : mPresContext(aParentRestyler.mPresContext)
-  , mFrame(aFrame)
-  , mParentContent(aParentRestyler.mParentContent)
-    // XXXldb Why does it make sense to use aParentContent?  (See
-    // comment above assertion at start of ElementRestyler::Restyle.)
-  , mContent(mFrame->GetContent() ? mFrame->GetContent() : mParentContent)
-  , mChangeList(aParentRestyler.mChangeList)
-  , mHintsHandledByAncestors(aParentRestyler.mHintsHandledByAncestors |
-                             aParentRestyler.mHintsHandledBySelf)
-  , mHintsHandledBySelf(nsChangeHint(0))
-  , mRestyleTracker(aParentRestyler.mRestyleTracker)
-  , mSelectorsForDescendants(aParentRestyler.mSelectorsForDescendants)
-  , mTreeMatchContext(aParentRestyler.mTreeMatchContext)
-  , mResolvedChild(nullptr)
-  , mContextsToClear(aParentRestyler.mContextsToClear)
-  , mSwappedStructOwners(aParentRestyler.mSwappedStructOwners)
-  , mIsRootOfRestyle(false)
-#ifdef ACCESSIBILITY
-  , mDesiredA11yNotifications(aParentRestyler.mDesiredA11yNotifications)
-  , mKidsDesiredA11yNotifications(mDesiredA11yNotifications)
-  , mOurA11yNotification(eDontNotify)
-  , mVisibleKidsOfHiddenElement(aParentRestyler.mVisibleKidsOfHiddenElement)
-#endif
-#ifdef RESTYLE_LOGGING
-  , mLoggingDepth(aParentRestyler.mLoggingDepth + 1)
-#endif
-{
-  MOZ_ASSERT(!mContent || !mContent->IsStyledByServo());
-
-  // We would assert here that we're not restyling a child provider frame if
-  // mHintsHandledByAncestors includes nsChangeHint_ReconstructFrame, but
-  // we do actually do this if the ReconstructFrame hint came from the
-  // RestyleTracker, rather than generated from CalcDifference.  (We could
-  // even try to avoid restyling the child provider frame, by returning
-  // early in ElementRestyler::Restyle if we grab out a ReconstructFrame
-  // hint from the RestyleTracker, but it's trickier to verify its correctness
-  // with all of the tree patching that happens currently, so for now we just
-  // skip the assertion.)
-}
-
-ElementRestyler::ElementRestyler(nsPresContext* aPresContext,
-                                 nsIContent* aContent,
-                                 nsStyleChangeList* aChangeList,
-                                 nsChangeHint aHintsHandledByAncestors,
-                                 RestyleTracker& aRestyleTracker,
-                                 nsTArray<nsCSSSelector*>& aSelectorsForDescendants,
-                                 TreeMatchContext& aTreeMatchContext,
-                                 nsTArray<nsIContent*>&
-                                   aVisibleKidsOfHiddenElement,
-                                 nsTArray<ContextToClear>& aContextsToClear,
-                                 nsTArray<RefPtr<GeckoStyleContext>>&
-                                   aSwappedStructOwners)
-  : mPresContext(aPresContext)
-  , mFrame(nullptr)
-  , mParentContent(nullptr)
-  , mContent(aContent)
-  , mChangeList(aChangeList)
-  , mHintsHandledByAncestors(aHintsHandledByAncestors)
-  , mHintsHandledBySelf(nsChangeHint(0))
-  , mRestyleTracker(aRestyleTracker)
-  , mSelectorsForDescendants(aSelectorsForDescendants)
-  , mTreeMatchContext(aTreeMatchContext)
-  , mResolvedChild(nullptr)
-  , mContextsToClear(aContextsToClear)
-  , mSwappedStructOwners(aSwappedStructOwners)
-  , mIsRootOfRestyle(true)
-#ifdef ACCESSIBILITY
-  , mDesiredA11yNotifications(eSendAllNotifications)
-  , mKidsDesiredA11yNotifications(mDesiredA11yNotifications)
-  , mOurA11yNotification(eDontNotify)
-  , mVisibleKidsOfHiddenElement(aVisibleKidsOfHiddenElement)
-#endif
-{
-  MOZ_ASSERT(!(mHintsHandledByAncestors & nsChangeHint_ReconstructFrame),
-             "why restyle descendants if we are reconstructing the frame for "
-             "an ancestor?");
-}
-
-void
-ElementRestyler::CaptureChange(GeckoStyleContext* aOldContext,
-                               GeckoStyleContext* aNewContext,
-                               nsChangeHint aChangeToAssume,
-                               uint32_t* aEqualStructs,
-                               uint32_t* aSamePointerStructs)
-{
-  static_assert(nsStyleStructID_Length <= 32,
-                "aEqualStructs is not big enough");
-
-  // Check some invariants about replacing one style context with another.
-  NS_ASSERTION(aOldContext->GetPseudo() == aNewContext->GetPseudo(),
-               "old and new style contexts should have the same pseudo");
-  NS_ASSERTION(aOldContext->GetPseudoType() == aNewContext->GetPseudoType(),
-               "old and new style contexts should have the same pseudo");
-
-  nsChangeHint ourChange =
-    aOldContext->CalcStyleDifference(aNewContext,
-                                     aEqualStructs,
-                                     aSamePointerStructs);
-  NS_ASSERTION(!(ourChange & nsChangeHint_AllReflowHints) ||
-               (ourChange & nsChangeHint_NeedReflow),
-               "Reflow hint bits set without actually asking for a reflow");
-
-  LOG_RESTYLE("CaptureChange, ourChange = %s, aChangeToAssume = %s",
-              GeckoRestyleManager::ChangeHintToString(ourChange).get(),
-              GeckoRestyleManager::ChangeHintToString(aChangeToAssume).get());
-  LOG_RESTYLE_INDENT();
-
-  // nsChangeHint_UpdateEffects is not handled for descendants, but it can be
-  // set due to changes in inherited properties (fill and stroke).  Avoid
-  // propagating it into text nodes.
-  if ((ourChange & nsChangeHint_UpdateEffects) &&
-      mContent && !mContent->IsElement()) {
-    ourChange &= ~nsChangeHint_UpdateEffects;
-  }
-
-  ourChange |= aChangeToAssume;
-
-  nsChangeHint changeToAppend =
-    NS_RemoveSubsumedHints(ourChange, mHintsHandledByAncestors);
-
-  // mHintsHandledBySelf starts off as nsChangeHint(0), when restyling a given
-  // frame, and accumulates change hints for each same-style-continuation and
-  // {ib}-split sibling following it.  Most of the time, any subsequent frames
-  // we restyle with this ElementRestyler will generate exactly the same
-  // |changeToAppend| that we have already stored in mHintsHandledBySelf.  If
-  // we generate some hints that weren't handled by an earler same-style-
-  // continuation or {ib}-split sibling, then we record the entire
-  // |changeToAppend| value.  (We could use something like
-  // NS_RemoveSubsumedHints, but aimed at removing hints handled only for the
-  // current element instead.  However, we should probably just fix these rare
-  // cases as part of bug 918064.)
-  if (!NS_IsHintSubset(changeToAppend, mHintsHandledBySelf)) {
-    mHintsHandledBySelf |= changeToAppend;
-    if (!(ourChange & nsChangeHint_ReconstructFrame) || mContent) {
-      LOG_RESTYLE("appending change %s",
-                  RestyleManager::ChangeHintToString(changeToAppend).get());
-      mChangeList->AppendChange(mFrame, mContent, changeToAppend);
-    } else {
-      LOG_RESTYLE("ignoring ReconstructFrame change with no content");
-    }
-  } else {
-    LOG_RESTYLE("change has already been handled");
-  }
-}
-
-class MOZ_RAII AutoSelectorArrayTruncater final
-{
-public:
-  explicit AutoSelectorArrayTruncater(
-        nsTArray<nsCSSSelector*>& aSelectorsForDescendants)
-    : mSelectorsForDescendants(aSelectorsForDescendants)
-    , mOriginalLength(aSelectorsForDescendants.Length())
-  {
-  }
-
-  ~AutoSelectorArrayTruncater()
-  {
-    mSelectorsForDescendants.TruncateLength(mOriginalLength);
-  }
-
-private:
-  nsTArray<nsCSSSelector*>& mSelectorsForDescendants;
-  size_t mOriginalLength;
-};
-
-/**
- * Called when we are stopping a restyle with eRestyle_SomeDescendants, to
- * search for descendants that match any of the selectors in
- * mSelectorsForDescendants.  If the element does match one of the selectors,
- * we cause it to be restyled with eRestyle_Self.
- *
- * We traverse down the frame tree (and through the flattened content tree
- * when we find undisplayed content) unless we find an element that (a) already
- * has a pending restyle, or (b) does not have a pending restyle but does match
- * one of the selectors in mSelectorsForDescendants.  For (a), we add the
- * current mSelectorsForDescendants into the existing restyle data, and for (b)
- * we add a new pending restyle with that array.  So in both cases, when we
- * come to restyling this element back up in ProcessPendingRestyles, we will
- * again find the eRestyle_SomeDescendants hint and its selectors array.
- *
- * This ensures that we don't visit descendant elements and check them
- * against mSelectorsForDescendants more than once.
- */
-void
-ElementRestyler::ConditionallyRestyleChildren()
-{
-  MOZ_ASSERT(mContent == mFrame->GetContent());
-
-  if (!mContent->IsElement() || mSelectorsForDescendants.IsEmpty()) {
-    return;
-  }
-
-  Element* element = mContent->AsElement();
-
-  LOG_RESTYLE("traversing descendants of frame %s (with element %s) to "
-              "propagate eRestyle_SomeDescendants for these %d selectors:",
-              FrameTagToString(mFrame).get(),
-              ElementTagToString(element).get(),
-              int(mSelectorsForDescendants.Length()));
-  LOG_RESTYLE_INDENT();
-#ifdef RESTYLE_LOGGING
-  for (nsCSSSelector* sel : mSelectorsForDescendants) {
-    LOG_RESTYLE("%s", sel->RestrictedSelectorToString().get());
-  }
-#endif
-
-  Element* restyleRoot = mRestyleTracker.FindClosestRestyleRoot(element);
-  ConditionallyRestyleChildren(mFrame, restyleRoot);
-}
-
-void
-ElementRestyler::ConditionallyRestyleChildren(nsIFrame* aFrame,
-                                              Element* aRestyleRoot)
-{
-  MOZ_ASSERT(aFrame->GetContent());
-  MOZ_ASSERT(aFrame->GetContent()->IsElement());
-  MOZ_ASSERT(!aFrame->GetContent()->IsStyledByServo());
-
-  ConditionallyRestyleUndisplayedDescendants(aFrame, aRestyleRoot);
-  ConditionallyRestyleContentChildren(aFrame, aRestyleRoot);
-}
-
-// The structure of this method parallels RestyleContentChildren.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::ConditionallyRestyleContentChildren(nsIFrame* aFrame,
-                                                     Element* aRestyleRoot)
-{
-  MOZ_ASSERT(aFrame->GetContent());
-  MOZ_ASSERT(aFrame->GetContent()->IsElement());
-  MOZ_ASSERT(!aFrame->GetContent()->IsStyledByServo());
-
-  if (aFrame->GetContent()->HasFlag(mRestyleTracker.RootBit())) {
-    aRestyleRoot = aFrame->GetContent()->AsElement();
-  }
-
-  for (nsIFrame* f = aFrame; f;
-       f = GetNextContinuationWithSameStyle(f, f->StyleContext()->AsGecko())) {
-    nsIFrame::ChildListIterator lists(f);
-    for (; !lists.IsDone(); lists.Next()) {
-      for (nsIFrame* child : lists.CurrentList()) {
-        // Out-of-flows are reached through their placeholders.  Continuations
-        // and block-in-inline splits are reached through those chains.
-        if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
-            !GetPrevContinuationWithSameStyle(child)) {
-          // only do frames that are in flow
-          if (child->IsPlaceholderFrame()) { // placeholder
-            // get out of flow frame and recur there
-            nsIFrame* outOfFlowFrame =
-              nsPlaceholderFrame::GetRealFrameForPlaceholder(child);
-
-            // |nsFrame::GetParentStyleContext| checks being out
-            // of flow so that this works correctly.
-            do {
-              if (GetPrevContinuationWithSameStyle(outOfFlowFrame)) {
-                continue;
-              }
-              if (!ConditionallyRestyle(outOfFlowFrame, aRestyleRoot)) {
-                ConditionallyRestyleChildren(outOfFlowFrame, aRestyleRoot);
-              }
-            } while ((outOfFlowFrame = outOfFlowFrame->GetNextContinuation()));
-          } else {  // regular child frame
-            if (child != mResolvedChild) {
-              if (!ConditionallyRestyle(child, aRestyleRoot)) {
-                ConditionallyRestyleChildren(child, aRestyleRoot);
-              }
-            }
-          }
-        }
-      }
-    }
-  }
-}
-
-// The structure of this method parallels RestyleUndisplayedDescendants.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::ConditionallyRestyleUndisplayedDescendants(
-    nsIFrame* aFrame,
-    Element* aRestyleRoot)
-{
-  nsIContent* undisplayedParent;
-  if (MustCheckUndisplayedContent(aFrame, undisplayedParent)) {
-    DoConditionallyRestyleUndisplayedDescendants(undisplayedParent,
-                                                 aRestyleRoot);
-  }
-}
-
-// The structure of this method parallels DoRestyleUndisplayedDescendants.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::DoConditionallyRestyleUndisplayedDescendants(
-    nsIContent* aParent,
-    Element* aRestyleRoot)
-{
-  nsCSSFrameConstructor* fc = mPresContext->FrameConstructor();
-  UndisplayedNode* nodes = fc->GetAllRegisteredDisplayNoneStylesIn(aParent);
-  ConditionallyRestyleUndisplayedNodes(nodes, aParent,
-                                       StyleDisplay::None, aRestyleRoot);
-  nodes = fc->GetAllRegisteredDisplayContentsStylesIn(aParent);
-  ConditionallyRestyleUndisplayedNodes(nodes, aParent,
-                                       StyleDisplay::Contents, aRestyleRoot);
-}
-
-// The structure of this method parallels RestyleUndisplayedNodes.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::ConditionallyRestyleUndisplayedNodes(
-    UndisplayedNode* aUndisplayed,
-    nsIContent* aUndisplayedParent,
-    const StyleDisplay aDisplay,
-    Element* aRestyleRoot)
-{
-  MOZ_ASSERT(aDisplay == StyleDisplay::None ||
-             aDisplay == StyleDisplay::Contents);
-  if (!aUndisplayed) {
-    return;
-  }
-
-  if (aUndisplayedParent &&
-      aUndisplayedParent->IsElement() &&
-      aUndisplayedParent->HasFlag(mRestyleTracker.RootBit())) {
-    MOZ_ASSERT(!aUndisplayedParent->IsStyledByServo());
-    aRestyleRoot = aUndisplayedParent->AsElement();
-  }
-
-  for (UndisplayedNode* undisplayed = aUndisplayed; undisplayed;
-       undisplayed = undisplayed->getNext()) {
-
-    if (!undisplayed->mContent->IsElement()) {
-      continue;
-    }
-
-    Element* element = undisplayed->mContent->AsElement();
-
-    if (!ConditionallyRestyle(element, aRestyleRoot)) {
-      if (aDisplay == StyleDisplay::None) {
-        ConditionallyRestyleContentDescendants(element, aRestyleRoot);
-      } else {  // StyleDisplay::Contents
-        DoConditionallyRestyleUndisplayedDescendants(element, aRestyleRoot);
-      }
-    }
-  }
-}
-
-void
-ElementRestyler::ConditionallyRestyleContentDescendants(Element* aElement,
-                                                        Element* aRestyleRoot)
-{
-  MOZ_ASSERT(!aElement->IsStyledByServo());
-  if (aElement->HasFlag(mRestyleTracker.RootBit())) {
-    aRestyleRoot = aElement;
-  }
-
-  FlattenedChildIterator it(aElement);
-  for (nsIContent* n = it.GetNextChild(); n; n = it.GetNextChild()) {
-    if (n->IsElement()) {
-      Element* e = n->AsElement();
-      if (!ConditionallyRestyle(e, aRestyleRoot)) {
-        ConditionallyRestyleContentDescendants(e, aRestyleRoot);
-      }
-    }
-  }
-}
-
-bool
-ElementRestyler::ConditionallyRestyle(nsIFrame* aFrame, Element* aRestyleRoot)
-{
-  MOZ_ASSERT(aFrame->GetContent());
-
-  if (!aFrame->GetContent()->IsElement()) {
-    return true;
-  }
-
-  return ConditionallyRestyle(aFrame->GetContent()->AsElement(), aRestyleRoot);
-}
-
-bool
-ElementRestyler::ConditionallyRestyle(Element* aElement, Element* aRestyleRoot)
-{
-  MOZ_ASSERT(!aElement->IsStyledByServo());
-  LOG_RESTYLE("considering element %s for eRestyle_SomeDescendants",
-              ElementTagToString(aElement).get());
-  LOG_RESTYLE_INDENT();
-
-  if (aElement->HasFlag(mRestyleTracker.RootBit())) {
-    aRestyleRoot = aElement;
-  }
-
-  if (mRestyleTracker.HasRestyleData(aElement)) {
-    nsRestyleHint rshint = eRestyle_SomeDescendants;
-    if (SelectorMatchesForRestyle(aElement)) {
-      LOG_RESTYLE("element has existing restyle data and matches a selector");
-      rshint |= eRestyle_Self;
-    } else {
-      LOG_RESTYLE("element has existing restyle data but doesn't match selectors");
-    }
-    RestyleHintData data;
-    data.mSelectorsForDescendants = mSelectorsForDescendants;
-    mRestyleTracker.AddPendingRestyle(aElement, rshint, nsChangeHint(0), &data,
-                                      Some(aRestyleRoot));
-    return true;
-  }
-
-  if (SelectorMatchesForRestyle(aElement)) {
-    LOG_RESTYLE("element has no restyle data but matches a selector");
-    RestyleHintData data;
-    data.mSelectorsForDescendants = mSelectorsForDescendants;
-    mRestyleTracker.AddPendingRestyle(aElement,
-                                      eRestyle_Self | eRestyle_SomeDescendants,
-                                      nsChangeHint(0), &data,
-                                      Some(aRestyleRoot));
-    return true;
-  }
-
-  return false;
-}
-
-bool
-ElementRestyler::MustCheckUndisplayedContent(nsIFrame* aFrame,
-                                             nsIContent*& aUndisplayedParent)
-{
-  // When the root element is display:none, we still construct *some*
-  // frames that have the root element as their mContent, down to the
-  // DocElementContainingBlock.
-  if (aFrame->StyleContext()->GetPseudo()) {
-    aUndisplayedParent = nullptr;
-    return aFrame == mPresContext->FrameConstructor()->
-                       GetDocElementContainingBlock();
-  }
-
-  aUndisplayedParent = aFrame->GetContent();
-  return !!aUndisplayedParent;
-}
-
-/**
- * Helper for MoveStyleContextsForChildren, below.  Appends the style
- * contexts to be moved to mFrame's current (new) style context to
- * aContextsToMove.
- */
-bool
-ElementRestyler::MoveStyleContextsForContentChildren(
-    nsIFrame* aParent,
-    GeckoStyleContext* aOldContext,
-    nsTArray<GeckoStyleContext*>& aContextsToMove)
-{
-  nsIFrame::ChildListIterator lists(aParent);
-  for (; !lists.IsDone(); lists.Next()) {
-    for (nsIFrame* child : lists.CurrentList()) {
-      // Bail out if we have out-of-flow frames.
-      // FIXME: It might be safe to just continue here instead of bailing out.
-      if (child->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
-        return false;
-      }
-      if (GetPrevContinuationWithSameStyle(child)) {
-        continue;
-      }
-      // Bail out if we have placeholder frames.
-      // FIXME: It is probably safe to just continue here instead of bailing out.
-      if (child->IsPlaceholderFrame()) {
-        return false;
-      }
-      GeckoStyleContext* sc = child->StyleContext()->AsGecko();
-      if (sc->GetParent() != aOldContext) {
-        return false;
-      }
-      LayoutFrameType type = child->Type();
-      if (type == LayoutFrameType::Letter || type == LayoutFrameType::Line) {
-        return false;
-      }
-      if (sc->HasChildThatUsesGrandancestorStyle()) {
-        // XXX Not sure if we need this?
-        return false;
-      }
-      nsAtom* pseudoTag = sc->GetPseudo();
-      if (pseudoTag && !nsCSSAnonBoxes::IsNonElement(pseudoTag)) {
-        return false;
-      }
-      aContextsToMove.AppendElement(sc);
-    }
-  }
-  return true;
-}
-
-/**
- * Traverses to child elements (through the current frame's same style
- * continuations, just like RestyleChildren does) and moves any style context
- * for those children to be parented under mFrame's current (new) style
- * context.
- *
- * False is returned if it encounters any conditions on the child elements'
- * frames and style contexts that means it is impossible to move a
- * style context.  If false is returned, no style contexts will have been
- * moved.
- */
-bool
-ElementRestyler::MoveStyleContextsForChildren(GeckoStyleContext* aOldContext)
-{
-  // Bail out if there are undisplayed or display:contents children.
-  // FIXME: We could get this to work if we need to.
-  nsIContent* undisplayedParent;
-  if (MustCheckUndisplayedContent(mFrame, undisplayedParent)) {
-    nsCSSFrameConstructor* fc = mPresContext->FrameConstructor();
-    if (fc->GetAllRegisteredDisplayNoneStylesIn(undisplayedParent) ||
-        fc->GetAllRegisteredDisplayContentsStylesIn(undisplayedParent)) {
-      return false;
-    }
-  }
-
-  nsTArray<GeckoStyleContext*> contextsToMove;
-
-  MOZ_ASSERT(!MustReframeForBeforePseudo(),
-             "shouldn't need to reframe ::before as we would have had "
-             "eRestyle_Subtree and wouldn't get in here");
-
-  DebugOnly<nsIFrame*> lastContinuation;
-  for (nsIFrame* f = mFrame; f;
-       f = GetNextContinuationWithSameStyle(f, f->StyleContext()->AsGecko())) {
-    lastContinuation = f;
-    if (!MoveStyleContextsForContentChildren(f, aOldContext, contextsToMove)) {
-      return false;
-    }
-  }
-
-  MOZ_ASSERT(!MustReframeForAfterPseudo(lastContinuation),
-             "shouldn't need to reframe ::after as we would have had "
-             "eRestyle_Subtree and wouldn't get in here");
-
-  GeckoStyleContext* newParent = mFrame->StyleContext()->AsGecko();
-  for (GeckoStyleContext* child : contextsToMove) {
-    // We can have duplicate entries in contextsToMove, so only move
-    // each style context once.
-    if (child->GetParent() != newParent) {
-      child->MoveTo(newParent);
-    }
-  }
-
-  return true;
-}
-
-/**
- * Recompute style for mFrame (which should not have a prev continuation
- * with the same style), all of its next continuations with the same
- * style, and all ib-split siblings of the same type (either block or
- * inline, skipping the intermediates of the other type) and accumulate
- * changes into mChangeList given that mHintsHandledByAncestors is already
- * accumulated for an ancestor.
- * mParentContent is the content node used to resolve the parent style
- * context.  This means that, for pseudo-elements, it is the content
- * that should be used for selector matching (rather than the fake
- * content node attached to the frame).
- */
-void
-ElementRestyler::Restyle(nsRestyleHint aRestyleHint)
-{
-  // It would be nice if we could make stronger assertions here; they
-  // would let us simplify the ?: expressions below setting |content|
-  // and |pseudoContent| in sensible ways as well as making what
-  // |content| and |pseudoContent| mean, and their relationship to
-  // |mFrame->GetContent()|, make more sense.  However, we can't,
-  // because of frame trees like the one in
-  // https://bugzilla.mozilla.org/show_bug.cgi?id=472353#c14 .  Once we
-  // fix bug 242277 we should be able to make this make more sense.
-  NS_ASSERTION(mFrame->GetContent() || !mParentContent ||
-               !mParentContent->GetParent(),
-               "frame must have content (unless at the top of the tree)");
-  MOZ_ASSERT(mPresContext == mFrame->PresContext(), "pres contexts match");
-
-  NS_ASSERTION(!GetPrevContinuationWithSameStyle(mFrame),
-               "should not be trying to restyle this frame separately");
-
-  MOZ_ASSERT(!(aRestyleHint & eRestyle_LaterSiblings),
-             "eRestyle_LaterSiblings must not be part of aRestyleHint");
-
-  AutoDisplayContentsAncestorPusher adcp(mTreeMatchContext, mPresContext,
-      mFrame->GetContent() ? mFrame->GetContent()->GetParent() : nullptr);
-
-  AutoSelectorArrayTruncater asat(mSelectorsForDescendants);
-
-  // List of descendant elements of mContent we know we will eventually need to
-  // restyle.  Before we return from this function, we call
-  // RestyleTracker::AddRestyleRootsIfAwaitingRestyle to ensure they get
-  // restyled in RestyleTracker::DoProcessRestyles.
-  nsTArray<RefPtr<Element>> descendants;
-
-  nsRestyleHint hintToRestore = nsRestyleHint(0);
-  RestyleHintData hintDataToRestore;
-  if (mContent && mContent->IsElement() &&
-      // If we're resolving from the root of the frame tree (which
-      // we do when mDoRebuildAllStyleData), we need to avoid getting the
-      // root's restyle data until we get to its primary frame, since
-      // it's the primary frame that has the styles for the root element
-      // (rather than the ancestors of the primary frame whose mContent
-      // is the root node but which have different styles).  If we use
-      // up the hint for one of the ancestors that we hit first, then
-      // we'll fail to do the restyling we need to do.
-      // Likewise, if we're restyling something with two nested frames,
-      // and we post a restyle from the transition manager while
-      // computing style for the outer frame (to be computed after the
-      // descendants have been resolved), we don't want to consume it
-      // for the inner frame.
-      mContent->GetPrimaryFrame() == mFrame) {
-    nsAutoPtr<RestyleTracker::RestyleData> restyleData;
-    if (mRestyleTracker.GetRestyleData(mContent->AsElement(), restyleData)) {
-      nsChangeHint changeToAppend =
-        NS_RemoveSubsumedHints(restyleData->mChangeHint,
-                               mHintsHandledByAncestors);
-      // See the comment in CaptureChange about why we use NS_IsHintSubset here.
-      if (!NS_IsHintSubset(changeToAppend, mHintsHandledBySelf)) {
-        mHintsHandledBySelf |= changeToAppend;
-        mChangeList->AppendChange(mFrame, mContent, changeToAppend);
-      }
-      mSelectorsForDescendants.AppendElements(
-          restyleData->mRestyleHintData.mSelectorsForDescendants);
-      hintToRestore = restyleData->mRestyleHint;
-      hintDataToRestore = Move(restyleData->mRestyleHintData);
-      aRestyleHint = nsRestyleHint(aRestyleHint | restyleData->mRestyleHint);
-      descendants.SwapElements(restyleData->mDescendants);
-    }
-  }
-
-  // If we are restyling this frame with eRestyle_Self or weaker hints,
-  // we restyle children with nsRestyleHint(0).  But we pass the
-  // eRestyle_ForceDescendants flag down too.
-  nsRestyleHint childRestyleHint =
-    nsRestyleHint(aRestyleHint & (eRestyle_SomeDescendants |
-                                  eRestyle_Subtree |
-                                  eRestyle_ForceDescendants));
-
-  RefPtr<GeckoStyleContext> oldContext = mFrame->StyleContext()->AsGecko();
-
-  nsTArray<SwapInstruction> swaps;
-
-  // TEMPORARY (until bug 918064):  Call RestyleSelf for each
-  // continuation or block-in-inline sibling.
-
-  // We must make a single decision on how to process this frame and
-  // its descendants, yet RestyleSelf might return different RestyleResult
-  // values for the different same-style continuations.  |result| is our
-  // overall decision.
-  RestyleResult result = RestyleResult::eNone;
-  uint32_t swappedStructs = 0;
-
-  nsRestyleHint thisRestyleHint = aRestyleHint;
-
-  bool haveMoreContinuations = false;
-  for (nsIFrame* f = mFrame; f; ) {
-    RestyleResult thisResult =
-      RestyleSelf(f, thisRestyleHint, &swappedStructs, swaps);
-
-    if (thisResult != RestyleResult::eStop) {
-      // Calls to RestyleSelf for later same-style continuations must not
-      // return RestyleResult::eStop, so pass eRestyle_Force in to them.
-      thisRestyleHint = nsRestyleHint(thisRestyleHint | eRestyle_Force);
-
-      if (result == RestyleResult::eStop) {
-        // We received RestyleResult::eStop for earlier same-style
-        // continuations, and RestyleResult::eStopWithStyleChange or
-        // RestyleResult::eContinue(AndForceDescendants) for this one; go
-        // back and force-restyle the earlier continuations.
-        result = thisResult;
-        f = mFrame;
-        continue;
-      }
-    }
-
-    if (thisResult > result) {
-      // We take the highest RestyleResult value when working out what to do
-      // with this frame and its descendants.  Higher RestyleResult values
-      // represent a superset of the work done by lower values.
-      result = thisResult;
-    }
-
-    f = GetNextContinuationWithSameStyle(
-          f, oldContext, &haveMoreContinuations);
-  }
-
-  // Some changes to animations don't affect the computed style and yet still
-  // require the layer to be updated. For example, pausing an animation via
-  // the Web Animations API won't affect an element's style but still
-  // requires to update the animation on the layer.
-  //
-  // Although we only expect this code path to be called when computed style
-  // is not changing, we can sometimes reach this at the end of a transition
-  // when the animated style is being removed. Since
-  // AddLayerChangesForAnimation checks if mFrame has a transform style or not,
-  // we need to call it *after* calling RestyleSelf to ensure the animated
-  // transform has been removed first.
-  RestyleManager::AddLayerChangesForAnimation(mFrame, mContent, *mChangeList);
-
-  if (haveMoreContinuations && hintToRestore) {
-    // If we have more continuations with different style (e.g., because
-    // we're inside a ::first-letter or ::first-line), put the restyle
-    // hint back.
-    mRestyleTracker.AddPendingRestyleToTable(mContent->AsElement(),
-                                             hintToRestore, nsChangeHint(0));
-  }
-
-  if (result == RestyleResult::eStop) {
-    MOZ_ASSERT(mFrame->StyleContext() == oldContext,
-               "frame should have been left with its old style context");
-
-    nsIFrame* unused;
-    GeckoStyleContext* newParent =
-      mFrame->GetParentStyleContext(&unused)->AsGecko();
-    if (oldContext->GetParent() != newParent) {
-      // If we received RestyleResult::eStop, then the old style context was
-      // left on mFrame.  Since we ended up restyling our parent, change
-      // this old style context to point to its new parent.
-      LOG_RESTYLE("moving style context %p from old parent %p to new parent %p",
-                  oldContext.get(), oldContext->GetParent(), newParent);
-      // We keep strong references to the new parent around until the end
-      // of the restyle, in case:
-      //   (a) we swapped structs between the old and new parent,
-      //   (b) some descendants of the old parent are not getting restyled
-      //       (which is the reason for the existence of
-      //       ClearCachedInheritedStyleDataOnDescendants),
-      //   (c) something under ProcessPendingRestyles (which notably is called
-      //       *before* ClearCachedInheritedStyleDataOnDescendants is called
-      //       on the old context) causes the new parent to be destroyed, thus
-      //       destroying its owned structs, and
-      //   (d) something under ProcessPendingRestyles then wants to use of those
-      //       now destroyed structs (through the old parent's descendants).
-      mSwappedStructOwners.AppendElement(newParent);
-      oldContext->MoveTo(newParent);
-    }
-
-    // Send the accessibility notifications that RestyleChildren otherwise
-    // would have sent.
-    if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-      InitializeAccessibilityNotifications(mFrame->StyleContext());
-      SendAccessibilityNotifications();
-    }
-
-    mRestyleTracker.AddRestyleRootsIfAwaitingRestyle(descendants);
-    if (aRestyleHint & eRestyle_SomeDescendants) {
-      ConditionallyRestyleChildren();
-    }
-    return;
-  }
-
-  if (result == RestyleResult::eStopWithStyleChange &&
-      !(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-    MOZ_ASSERT(mFrame->StyleContext() != oldContext,
-               "RestyleResult::eStopWithStyleChange should only be returned "
-               "if we got a new style context or we will reconstruct");
-    MOZ_ASSERT(swappedStructs == 0,
-               "should have ensured we didn't swap structs when "
-               "returning RestyleResult::eStopWithStyleChange");
-
-    // We need to ensure that all of the frames that inherit their style
-    // from oldContext are able to be moved across to newContext.
-    // MoveStyleContextsForChildren will check for certain conditions
-    // to ensure it is safe to move all of the relevant child style
-    // contexts to newContext.  If these conditions fail, it will
-    // return false, and we'll have to continue restyling.
-    const bool canStop = MoveStyleContextsForChildren(oldContext);
-
-    if (canStop) {
-      // Send the accessibility notifications that RestyleChildren otherwise
-      // would have sent.
-      if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-        InitializeAccessibilityNotifications(mFrame->StyleContext());
-        SendAccessibilityNotifications();
-      }
-
-      mRestyleTracker.AddRestyleRootsIfAwaitingRestyle(descendants);
-      if (aRestyleHint & eRestyle_SomeDescendants) {
-        ConditionallyRestyleChildren();
-      }
-      return;
-    }
-
-    // Turns out we couldn't stop restyling here.  Process the struct
-    // swaps that RestyleSelf would've done had we not returned
-    // RestyleResult::eStopWithStyleChange.
-    for (SwapInstruction& swap : swaps) {
-      LOG_RESTYLE("swapping style structs between %p and %p",
-                  swap.mOldContext.get(), swap.mNewContext.get());
-      swap.mOldContext->AsGecko()->SwapStyleData(swap.mNewContext->AsGecko(), swap.mStructsToSwap);
-      swappedStructs |= swap.mStructsToSwap;
-    }
-    swaps.Clear();
-  }
-
-  if (!swappedStructs) {
-    // If we swapped any structs from the old context, then we need to keep
-    // it alive until after the RestyleChildren call so that we can fix up
-    // its descendants' cached structs.
-    oldContext = nullptr;
-  }
-
-  if (result == RestyleResult::eContinueAndForceDescendants) {
-    childRestyleHint =
-      nsRestyleHint(childRestyleHint | eRestyle_ForceDescendants);
-  }
-
-  // No need to do this if we're planning to reframe already.
-  // It's also important to check mHintsHandledBySelf since we use
-  // mFrame->StyleContext(), which is out of date if mHintsHandledBySelf
-  // has a ReconstructFrame hint.  Using an out of date style
-  // context could trigger assertions about mismatched rule trees.
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-    RestyleChildren(childRestyleHint);
-  }
-
-  if (oldContext && !oldContext->HasSingleReference()) {
-    // If we swapped some structs out of oldContext in the RestyleSelf call
-    // and after the RestyleChildren call we still have other strong references
-    // to it, we need to make ensure its descendants don't cache any of the
-    // structs that were swapped out.
-    //
-    // Much of the time we will not get in here; we do for example when the
-    // style context is shared with a later IB split sibling (which we won't
-    // restyle until a bit later) or if other code is holding a strong reference
-    // to the style context (as is done by nsTransformedTextRun objects, which
-    // can be referenced by a text frame's mTextRun longer than the frame's
-    // mStyleContext).
-    //
-    // Also, we don't want this style context to get any more uses by being
-    // returned from GeckoStyleContext::FindChildWithRules, so we add the
-    // NS_STYLE_INELIGIBLE_FOR_SHARING bit to it.
-    oldContext->SetIneligibleForSharing();
-
-    ContextToClear* toClear = mContextsToClear.AppendElement();
-    toClear->mStyleContext = Move(oldContext);
-    toClear->mStructs = swappedStructs;
-  }
-
-  mRestyleTracker.AddRestyleRootsIfAwaitingRestyle(descendants);
-}
-
-/**
- * Depending on the details of the frame we are restyling or its old style
- * context, we may or may not be able to stop restyling after this frame if
- * we find we had no style changes.
- *
- * This function returns RestyleResult::eStop if it does not find any
- * conditions that would preclude stopping restyling, and
- * RestyleResult::eContinue if it does.
- */
-void
-ElementRestyler::ComputeRestyleResultFromFrame(nsIFrame* aSelf,
-                                               RestyleResult& aRestyleResult,
-                                               bool& aCanStopWithStyleChange)
-{
-  // We can't handle situations where the primary style context of a frame
-  // has not had any style data changes, but its additional style contexts
-  // have, so we don't considering stopping if this frame has any additional
-  // style contexts.
-  if (aSelf->GetAdditionalStyleContext(0)) {
-    LOG_RESTYLE_CONTINUE("there are additional style contexts");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  // Each NAC element inherits from the first non-NAC ancestor, so child
-  // NAC may inherit from our parent instead of us. That means we can't
-  // cull traversal if our style context didn't change.
-  if (aSelf->GetContent() && aSelf->GetContent()->IsNativeAnonymous()) {
-    LOG_RESTYLE_CONTINUE("native anonymous content");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  // Style changes might have moved children between the two nsLetterFrames
-  // (the one matching ::first-letter and the one containing the rest of the
-  // content).  Continue restyling to the children of the nsLetterFrame so
-  // that they get the correct style context parent.  Similarly for
-  // nsLineFrames.
-  LayoutFrameType type = aSelf->Type();
-
-  if (type == LayoutFrameType::Letter) {
-    LOG_RESTYLE_CONTINUE("frame is a letter frame");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  if (type == LayoutFrameType::Line) {
-    LOG_RESTYLE_CONTINUE("frame is a line frame");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  // Some style computations depend not on the parent's style, but a grandparent
-  // or one the grandparent's ancestors.  An example is an explicit 'inherit'
-  // value for align-self, where if the parent frame's value for the property is
-  // 'auto' we end up inheriting the computed value from the grandparent.  We
-  // can't stop the restyling process on this frame (the one with 'auto', in
-  // this example), as the grandparent's computed value might have changed
-  // and we need to recompute the child's 'inherit' to that new value.
-  GeckoStyleContext* oldContext = aSelf->StyleContext()->AsGecko();
-  if (oldContext->HasChildThatUsesGrandancestorStyle()) {
-    LOG_RESTYLE_CONTINUE("the old context uses grandancestor style");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  // We ignore all situations that involve :visited style.
-  if (oldContext->GetStyleIfVisited()) {
-    LOG_RESTYLE_CONTINUE("the old style context has StyleIfVisited");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  GeckoStyleContext* parentContext = oldContext->GetParent();
-  if (parentContext && parentContext->GetStyleIfVisited()) {
-    LOG_RESTYLE_CONTINUE("the old style context's parent has StyleIfVisited");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  // We also ignore frames for pseudos, as their style contexts have
-  // inheritance structures that do not match the frame inheritance
-  // structure.  To avoid enumerating and checking all of the cases
-  // where we have this kind of inheritance, we keep restyling past
-  // pseudos.
-  nsAtom* pseudoTag = oldContext->GetPseudo();
-  if (pseudoTag && !nsCSSAnonBoxes::IsNonElement(pseudoTag)) {
-    LOG_RESTYLE_CONTINUE("the old style context is for a pseudo");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  nsIFrame* parent = mFrame->GetParent();
-
-  if (parent) {
-    // Also if the parent has a pseudo, as this frame's style context will
-    // be inheriting from a grandparent frame's style context (or a further
-    // ancestor).
-    nsAtom* parentPseudoTag = parent->StyleContext()->GetPseudo();
-    if (parentPseudoTag &&
-        parentPseudoTag != nsCSSAnonBoxes::firstLetterContinuation) {
-      MOZ_ASSERT(parentPseudoTag != nsCSSAnonBoxes::mozText,
-                 "Style of text node should not be parent of anything");
-      MOZ_ASSERT(parentPseudoTag != nsCSSAnonBoxes::oofPlaceholder,
-                 "Style of placeholder should not be parent of anything");
-      LOG_RESTYLE_CONTINUE("the old style context's parent is for a pseudo");
-      aRestyleResult = RestyleResult::eContinue;
-      // Parent style context pseudo-ness doesn't affect whether we can
-      // return RestyleResult::eStopWithStyleChange.
-      //
-      // If we had later conditions to check in this function, we would
-      // continue to check them, in case we set aCanStopWithStyleChange to
-      // false.
-    }
-  }
-}
-
-void
-ElementRestyler::ComputeRestyleResultFromNewContext(nsIFrame* aSelf,
-                                                    GeckoStyleContext* aNewContext,
-                                                    RestyleResult& aRestyleResult,
-                                                    bool& aCanStopWithStyleChange)
-{
-  // If we've already determined that we must continue styling, we don't
-  // need to check anything.
-  if (aRestyleResult == RestyleResult::eContinue && !aCanStopWithStyleChange) {
-    return;
-  }
-
-  // Keep restyling if the new style context has any style-if-visted style, so
-  // that we can avoid the style context tree surgery having to deal to deal
-  // with visited styles.
-  if (aNewContext->GetStyleIfVisited()) {
-    LOG_RESTYLE_CONTINUE("the new style context has StyleIfVisited");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  // If link-related information has changed, or the pseudo for the frame has
-  // changed, or the new style context points to a different rule node, we can't
-  // leave the old style context on the frame.
-  GeckoStyleContext* oldContext = aSelf->StyleContext()->AsGecko();
-  if (oldContext->IsLinkContext() != aNewContext->IsLinkContext() ||
-      oldContext->RelevantLinkVisited() != aNewContext->RelevantLinkVisited() ||
-      oldContext->GetPseudo() != aNewContext->GetPseudo() ||
-      oldContext->GetPseudoType() != aNewContext->GetPseudoType()) {
-    LOG_RESTYLE_CONTINUE("the old and new style contexts have different link/"
-                         "visited/pseudo");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  if (oldContext->RuleNode() != aNewContext->RuleNode()) {
-    LOG_RESTYLE_CONTINUE("the old and new style contexts have different "
-                         "rulenodes");
-    aRestyleResult = RestyleResult::eContinue;
-    // Continue to check other conditions if aCanStopWithStyleChange might
-    // still need to be set to false.
-    if (!aCanStopWithStyleChange) {
-      return;
-    }
-  }
-
-  if (auto* position = oldContext->PeekStylePosition()) {
-    const bool wasLegacyJustifyItems =
-      position->mJustifyItems & NS_STYLE_JUSTIFY_LEGACY;
-    const auto newJustifyItems = aNewContext->StylePosition()->mJustifyItems;
-    const bool isLegacyJustifyItems =
-       newJustifyItems & NS_STYLE_JUSTIFY_LEGACY;
-
-    // Children with justify-items: legacy may depend on our value.
-    if (wasLegacyJustifyItems != isLegacyJustifyItems ||
-        (wasLegacyJustifyItems && position->mJustifyItems != newJustifyItems)) {
-      LOG_RESTYLE_CONTINUE("legacy justify-items changed between old and new"
-                           " style contexts");
-      aRestyleResult = RestyleResult::eContinue;
-      aCanStopWithStyleChange = false;
-      return;
-    }
-  }
-
-  // If the old and new style contexts differ in their
-  // NS_STYLE_HAS_TEXT_DECORATION_LINES or NS_STYLE_HAS_PSEUDO_ELEMENT_DATA
-  // bits, then we must keep restyling so that those new bit values are
-  // propagated.
-  if (oldContext->HasTextDecorationLines() !=
-        aNewContext->HasTextDecorationLines()) {
-    LOG_RESTYLE_CONTINUE("NS_STYLE_HAS_TEXT_DECORATION_LINES differs between old"
-                         " and new style contexts");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  if (oldContext->HasPseudoElementData() !=
-        aNewContext->HasPseudoElementData()) {
-    LOG_RESTYLE_CONTINUE("NS_STYLE_HAS_PSEUDO_ELEMENT_DATA differs between old"
-                         " and new style contexts");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  if (oldContext->ShouldSuppressLineBreak() !=
-        aNewContext->ShouldSuppressLineBreak()) {
-    LOG_RESTYLE_CONTINUE("NS_STYLE_SUPPRESS_LINEBREAK differs"
-                         "between old and new style contexts");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  if (oldContext->IsInDisplayNoneSubtree() !=
-        aNewContext->IsInDisplayNoneSubtree()) {
-    LOG_RESTYLE_CONTINUE("NS_STYLE_IN_DISPLAY_NONE_SUBTREE differs between old"
-                         " and new style contexts");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-
-  if (oldContext->IsTextCombined() != aNewContext->IsTextCombined()) {
-    LOG_RESTYLE_CONTINUE("NS_STYLE_IS_TEXT_COMBINED differs between "
-                         "old and new style contexts");
-    aRestyleResult = RestyleResult::eContinue;
-    aCanStopWithStyleChange = false;
-    return;
-  }
-}
-
-bool
-ElementRestyler::SelectorMatchesForRestyle(Element* aElement)
-{
-  if (!aElement) {
-    return false;
-  }
-  for (nsCSSSelector* selector : mSelectorsForDescendants) {
-    if (nsCSSRuleProcessor::RestrictedSelectorMatches(aElement, selector,
-                                                      mTreeMatchContext)) {
-      return true;
-    }
-  }
-  return false;
-}
-
-bool
-ElementRestyler::MustRestyleSelf(nsRestyleHint aRestyleHint,
-                                 Element* aElement)
-{
-  return (aRestyleHint & (eRestyle_Self | eRestyle_Subtree)) ||
-         ((aRestyleHint & eRestyle_SomeDescendants) &&
-          SelectorMatchesForRestyle(aElement));
-}
-
-bool
-ElementRestyler::CanReparentStyleContext(nsRestyleHint aRestyleHint)
-{
-  // If we had any restyle hints other than the ones listed below,
-  // which don't control whether the current frame/element needs
-  // a new style context by looking up a new rule node, or if
-  // we are reconstructing the entire rule tree, then we can't
-  // use ReparentStyleContext.
-  return !(aRestyleHint & ~(eRestyle_Force |
-                            eRestyle_ForceDescendants |
-                            eRestyle_SomeDescendants)) &&
-         !StyleSet()->IsInRuleTreeReconstruct();
-}
-
-// Returns true iff any rule node that is an ancestor-or-self of the
-// two specified rule nodes, but which is not an ancestor of both,
-// has any inherited style data.  If false is returned, then we know
-// that a change from one rule node to the other must not result in
-// any change in inherited style data.
-static bool
-CommonInheritedStyleData(nsRuleNode* aRuleNode1, nsRuleNode* aRuleNode2)
-{
-  if (aRuleNode1 == aRuleNode2) {
-    return true;
-  }
-
-  nsRuleNode* n1 = aRuleNode1->GetParent();
-  nsRuleNode* n2 = aRuleNode2->GetParent();
-
-  if (n1 == n2) {
-    // aRuleNode1 and aRuleNode2 sharing a parent is a common case, e.g.
-    // when modifying a style="" attribute.  (We must null check GetRule()'s
-    // result since although we know the two parents are the same, it might
-    // be null, as in the case of the two rule nodes being roots of two
-    // different rule trees.)
-    if (aRuleNode1->GetRule() &&
-        aRuleNode1->GetRule()->MightMapInheritedStyleData()) {
-      return false;
-    }
-    if (aRuleNode2->GetRule() &&
-        aRuleNode2->GetRule()->MightMapInheritedStyleData()) {
-      return false;
-    }
-    return true;
-  }
-
-  // Compute the depths of aRuleNode1 and aRuleNode2.
-  int d1 = 0, d2 = 0;
-  while (n1) {
-    ++d1;
-    n1 = n1->GetParent();
-  }
-  while (n2) {
-    ++d2;
-    n2 = n2->GetParent();
-  }
-
-  // Make aRuleNode1 be the deeper node.
-  if (d2 > d1) {
-    std::swap(d1, d2);
-    std::swap(aRuleNode1, aRuleNode2);
-  }
-
-  // Check all of the rule nodes in the deeper branch until we reach
-  // the same depth as the shallower branch.
-  n1 = aRuleNode1;
-  n2 = aRuleNode2;
-  while (d1 > d2) {
-    nsIStyleRule* rule = n1->GetRule();
-    MOZ_ASSERT(rule, "non-root rule node should have a rule");
-    if (rule->MightMapInheritedStyleData()) {
-      return false;
-    }
-    n1 = n1->GetParent();
-    --d1;
-  }
-
-  // Check both branches simultaneously until we reach a common ancestor.
-  while (n1 != n2) {
-    MOZ_ASSERT(n1);
-    MOZ_ASSERT(n2);
-    // As above, we must null check GetRule()'s result since we won't find
-    // a common ancestor if the two rule nodes come from different rule trees,
-    // and thus we might reach the root (which has a null rule).
-    if (n1->GetRule() && n1->GetRule()->MightMapInheritedStyleData()) {
-      return false;
-    }
-    if (n2->GetRule() && n2->GetRule()->MightMapInheritedStyleData()) {
-      return false;
-    }
-    n1 = n1->GetParent();
-    n2 = n2->GetParent();
-  }
-
-  return true;
-}
-
-ElementRestyler::RestyleResult
-ElementRestyler::RestyleSelf(nsIFrame* aSelf,
-                             nsRestyleHint aRestyleHint,
-                             uint32_t* aSwappedStructs,
-                             nsTArray<SwapInstruction>& aSwaps)
-{
-  MOZ_ASSERT(!(aRestyleHint & eRestyle_LaterSiblings),
-             "eRestyle_LaterSiblings must not be part of aRestyleHint");
-
-  // XXXldb get new context from prev-in-flow if possible, to avoid
-  // duplication.  (Or should we just let |GetContext| handle that?)
-  // Getting the hint would be nice too, but that's harder.
-
-  // XXXbryner we may be able to avoid some of the refcounting goop here.
-  // We do need a reference to oldContext for the lifetime of this function, and it's possible
-  // that the frame has the last reference to it, so AddRef it here.
-
-  LOG_RESTYLE("RestyleSelf %s, aRestyleHint = %s",
-              FrameTagToString(aSelf).get(),
-              RestyleManager::RestyleHintToString(aRestyleHint).get());
-  LOG_RESTYLE_INDENT();
-
-  // Initially assume that it is safe to stop restyling.
-  //
-  // Throughout most of this function, we update the following two variables
-  // independently.  |result| is set to RestyleResult::eContinue when we
-  // detect a condition that would not allow us to return RestyleResult::eStop.
-  // |canStopWithStyleChange| is set to false when we detect a condition
-  // that would not allow us to return RestyleResult::eStopWithStyleChange.
-  //
-  // Towards the end of this function, we reconcile these two variables --
-  // if |canStopWithStyleChange| is true, we convert |result| into
-  // RestyleResult::eStopWithStyleChange.
-  RestyleResult result = RestyleResult::eStop;
-  bool canStopWithStyleChange = true;
-
-  if (aRestyleHint & ~eRestyle_SomeDescendants) {
-    // If we are doing any restyling of the current element, or if we're
-    // forced to continue, we must.
-    result = RestyleResult::eContinue;
-
-    // If we have to restyle children, we can't return
-    // RestyleResult::eStopWithStyleChange.
-    if (aRestyleHint & (eRestyle_Subtree | eRestyle_Force |
-                        eRestyle_ForceDescendants)) {
-      canStopWithStyleChange = false;
-    }
-  }
-
-  // We only consider returning RestyleResult::eStopWithStyleChange if this
-  // is the root of the restyle.  (Otherwise, we would need to track the
-  // style changes of the ancestors we just restyled.)
-  if (!mIsRootOfRestyle) {
-    canStopWithStyleChange = false;
-  }
-
-  // Look at the frame and its current style context for conditions
-  // that would change our RestyleResult.
-  ComputeRestyleResultFromFrame(aSelf, result, canStopWithStyleChange);
-
-  nsChangeHint assumeDifferenceHint = nsChangeHint(0);
-  RefPtr<GeckoStyleContext> oldContext = aSelf->StyleContext()->AsGecko();
-  nsStyleSet* styleSet = StyleSet();
-
-#ifdef ACCESSIBILITY
-  mWasFrameVisible = nsIPresShell::IsAccessibilityActive() ?
-    oldContext->StyleVisibility()->IsVisible() : false;
-#endif
-
-  nsAtom* const pseudoTag = oldContext->GetPseudo();
-  const CSSPseudoElementType pseudoType = oldContext->GetPseudoType();
-
-  // Get the frame providing the parent style context.  If it is a
-  // child, then resolve the provider first.
-  nsIFrame* providerFrame;
-  nsStyleContext* parentContext_ = aSelf->GetParentStyleContext(&providerFrame);
-  bool isChild = providerFrame && providerFrame->GetParent() == aSelf;
-  if (isChild) {
-    MOZ_ASSERT(providerFrame->GetContent() == aSelf->GetContent(),
-               "Postcondition for GetParentStyleContext() violated. "
-               "That means we need to add the current element to the "
-               "ancestor filter.");
-
-    // resolve the provider here (before aSelf below).
-    LOG_RESTYLE("resolving child provider frame");
-
-    // assumeDifferenceHint forces the parent's change to be also
-    // applied to this frame, no matter what
-    // GeckoStyleContext::CalcStyleDifference says. CalcStyleDifference
-    // can't be trusted because it assumes any changes to the parent
-    // style context provider will be automatically propagated to
-    // the frame(s) with child style contexts.
-
-    ElementRestyler providerRestyler(PARENT_CONTEXT_FROM_CHILD_FRAME,
-                                     *this, providerFrame);
-    providerRestyler.Restyle(aRestyleHint);
-    assumeDifferenceHint = providerRestyler.HintsHandledForFrame();
-
-    // The provider's new context becomes the parent context of
-    // aSelf's context.
-    parentContext_ = providerFrame->StyleContext();
-    // Set |mResolvedChild| so we don't bother resolving the
-    // provider again.
-    mResolvedChild = providerFrame;
-    LOG_RESTYLE_CONTINUE("we had a provider frame");
-    // Continue restyling past the odd style context inheritance.
-    result = RestyleResult::eContinue;
-    canStopWithStyleChange = false;
-  }
-
-  auto* parentContext = parentContext_ ? parentContext_->AsGecko() : nullptr;
-  LOG_RESTYLE("parentContext = %p", parentContext);
-
-  // do primary context
-  RefPtr<GeckoStyleContext> newContext;
-  nsIFrame* prevContinuation =
-    GetPrevContinuationWithPossiblySameStyle(aSelf);
-  GeckoStyleContext* prevContinuationContext;
-  bool copyFromContinuation =
-    prevContinuation &&
-    (prevContinuationContext = prevContinuation->StyleContext()->AsGecko())
-      ->GetPseudo() == oldContext->GetPseudo() &&
-     prevContinuationContext->GetParent() == parentContext;
-  if (copyFromContinuation) {
-    // Just use the style context from the frame's previous
-    // continuation.
-    LOG_RESTYLE("using previous continuation's context");
-    newContext = prevContinuationContext;
-  } else if (pseudoTag == nsCSSAnonBoxes::mozText) {
-    MOZ_ASSERT(aSelf->IsTextFrame());
-    newContext =
-      styleSet->ResolveStyleForText(aSelf->GetContent(), parentContext);
-  } else if (pseudoTag == nsCSSAnonBoxes::firstLetterContinuation) {
-    newContext = styleSet->ResolveStyleForFirstLetterContinuation(parentContext);
-  } else if (pseudoTag == nsCSSAnonBoxes::oofPlaceholder) {
-    // We still need to ResolveStyleForPlaceholder() here, because we may be
-    // doing a ruletree reconstruct and hence actually changing our style
-    // context.
-    newContext = styleSet->ResolveStyleForPlaceholder();
-  } else if (pseudoType == CSSPseudoElementType::NonInheritingAnonBox) {
-    // We still need to ResolveNonInheritingAnonymousBoxStyle() here, because we
-    // may be doing a ruletree reconstruct and hence actually changing our style
-    // context.
-    newContext = styleSet->ResolveNonInheritingAnonymousBoxStyle(pseudoTag);
-  }
-  else {
-    Element* element = ElementForStyleContext(mParentContent, aSelf, pseudoType);
-    if (!MustRestyleSelf(aRestyleHint, element)) {
-      if (CanReparentStyleContext(aRestyleHint)) {
-        LOG_RESTYLE("reparenting style context");
-        newContext =
-          styleSet->ReparentStyleContext(oldContext, parentContext, element);
-      } else {
-        // Use ResolveStyleWithReplacement either for actual replacements
-        // or, with no replacements, as a substitute for
-        // ReparentStyleContext that rebuilds the path in the rule tree
-        // rather than reusing the rule node, as we need to do during a
-        // rule tree reconstruct.
-        Element* pseudoElement = PseudoElementForStyleContext(aSelf, pseudoType);
-        MOZ_ASSERT(!element || element != pseudoElement,
-                   "pseudo-element for selector matching should be "
-                   "the anonymous content node that we create, "
-                   "not the real element");
-        LOG_RESTYLE("resolving style with replacement");
-        nsRestyleHint rshint = aRestyleHint & ~eRestyle_SomeDescendants;
-        newContext =
-          styleSet->ResolveStyleWithReplacement(element, pseudoElement,
-                                                parentContext, oldContext,
-                                                rshint);
-      }
-    } else if (pseudoType == CSSPseudoElementType::InheritingAnonBox) {
-      newContext = styleSet->ResolveInheritingAnonymousBoxStyle(pseudoTag,
-                                                                parentContext);
-    }
-    else {
-      if (pseudoTag) {
-        if (pseudoTag == nsCSSPseudoElements::before ||
-            pseudoTag == nsCSSPseudoElements::after) {
-          // XXX what other pseudos do we need to treat like this?
-          newContext = styleSet->ProbePseudoElementStyle(element,
-                                                         pseudoType,
-                                                         parentContext,
-                                                         mTreeMatchContext);
-          if (!newContext) {
-            // This pseudo should no longer exist; gotta reframe
-            mHintsHandledBySelf |= nsChangeHint_ReconstructFrame;
-            mChangeList->AppendChange(aSelf, element,
-                                      nsChangeHint_ReconstructFrame);
-            // We're reframing anyway; just keep the same context
-            newContext = oldContext;
-#ifdef DEBUG
-            // oldContext's parent might have had its style structs swapped out
-            // with parentContext, so to avoid any assertions that might
-            // otherwise trigger in oldContext's parent's destructor, we set a
-            // flag on oldContext to skip it and its descendants in
-            // GeckoStyleContext::AssertStructsNotUsedElsewhere.
-            if (oldContext->GetParent() != parentContext) {
-              oldContext->AddStyleBit(NS_STYLE_IS_GOING_AWAY);
-            }
-#endif
-          }
-        } else {
-          // Don't expect XUL tree stuff here, since it needs a comparator and
-          // all.
-          NS_ASSERTION(pseudoType < CSSPseudoElementType::Count,
-                       "Unexpected pseudo type");
-          Element* pseudoElement =
-            PseudoElementForStyleContext(aSelf, pseudoType);
-          MOZ_ASSERT(element != pseudoElement,
-                     "pseudo-element for selector matching should be "
-                     "the anonymous content node that we create, "
-                     "not the real element");
-          newContext = styleSet->ResolvePseudoElementStyle(element,
-                                                           pseudoType,
-                                                           parentContext,
-                                                           pseudoElement);
-        }
-      }
-      else {
-        NS_ASSERTION(aSelf->GetContent(),
-                     "non pseudo-element frame without content node");
-        // Skip parent display based style fixup for anonymous subtrees:
-        TreeMatchContext::AutoParentDisplayBasedStyleFixupSkipper
-          parentDisplayBasedFixupSkipper(mTreeMatchContext,
-                                 element->IsRootOfNativeAnonymousSubtree());
-        newContext = styleSet->ResolveStyleFor(element, parentContext,
-                                               mTreeMatchContext);
-      }
-    }
-  }
-
-  MOZ_ASSERT(newContext);
-
-  if (!parentContext) {
-    if (oldContext->RuleNode() == newContext->RuleNode() &&
-        oldContext->IsLinkContext() == newContext->IsLinkContext() &&
-        oldContext->RelevantLinkVisited() ==
-          newContext->RelevantLinkVisited()) {
-      // We're the root of the style context tree and the new style
-      // context returned has the same rule node.  This means that
-      // we can use FindChildWithRules to keep a lot of the old
-      // style contexts around.  However, we need to start from the
-      // same root.
-      LOG_RESTYLE("restyling root and keeping old context");
-      LOG_RESTYLE_IF(this, result != RestyleResult::eContinue,
-                     "continuing restyle since this is the root");
-      newContext = oldContext;
-      // Never consider stopping restyling at the root.
-      result = RestyleResult::eContinue;
-      canStopWithStyleChange = false;
-    }
-  }
-
-  LOG_RESTYLE("oldContext = %p, newContext = %p%s",
-              oldContext.get(), newContext.get(),
-              oldContext == newContext ? (const char*) " (same)" :
-                                         (const char*) "");
-
-  if (newContext != oldContext) {
-    if (oldContext->IsShared()) {
-      // If the old style context was shared, then we can't return
-      // RestyleResult::eStop and patch its parent to point to the
-      // new parent style context, as that change might not be valid
-      // for the other frames sharing the style context.
-      LOG_RESTYLE_CONTINUE("the old style context is shared");
-      result = RestyleResult::eContinue;
-
-      // It is not safe to return RestyleResult::eStopWithStyleChange
-      // when oldContext is shared and newContext has different
-      // inherited style data, regardless of whether the oldContext has
-      // that inherited style data cached.  We can't simply rely on the
-      // samePointerStructs check later on, as the descendent style
-      // contexts just might not have had their inherited style data
-      // requested yet (which is possible for example if we flush style
-      // between resolving an initial style context for a frame and
-      // building its display list items).  Therefore we must compare
-      // the rule nodes of oldContext and newContext to see if the
-      // restyle results in new inherited style data.  If not, then
-      // we can continue assuming that RestyleResult::eStopWithStyleChange
-      // is safe.  Without this check, we could end up with style contexts
-      // shared between elements which should have different styles.
-      if (!CommonInheritedStyleData(oldContext->RuleNode(),
-                                    newContext->RuleNode())) {
-        canStopWithStyleChange = false;
-      }
-    }
-
-    // Look at some details of the new style context to see if it would
-    // be safe to stop restyling, if we discover it has the same style
-    // data as the old style context.
-    ComputeRestyleResultFromNewContext(aSelf, newContext,
-                                       result, canStopWithStyleChange);
-
-    uint32_t equalStructs = 0;
-    uint32_t samePointerStructs = 0;
-
-    if (copyFromContinuation) {
-      // In theory we should know whether there was any style data difference,
-      // since we would have calculated that in the previous call to
-      // RestyleSelf, so until we perform only one restyling per chain-of-
-      // same-style continuations (bug 918064), we need to check again here to
-      // determine whether it is safe to stop restyling.
-      if (result == RestyleResult::eStop) {
-        oldContext->CalcStyleDifference(newContext,
-                                        &equalStructs,
-                                        &samePointerStructs);
-        if (equalStructs != NS_STYLE_INHERIT_MASK) {
-          // At least one struct had different data in it, so we must
-          // continue restyling children.
-          LOG_RESTYLE_CONTINUE("there is different style data: %s",
-                      GeckoRestyleManager::StructNamesToString(
-                        ~equalStructs & NS_STYLE_INHERIT_MASK).get());
-          result = RestyleResult::eContinue;
-        }
-      }
-    } else {
-      bool changedStyle =
-        GeckoRestyleManager::TryInitiatingTransition(mPresContext,
-                                                     aSelf->GetContent(),
-                                                     oldContext, &newContext);
-      if (changedStyle) {
-        LOG_RESTYLE_CONTINUE("TryInitiatingTransition changed the new style "
-                             "context");
-        result = RestyleResult::eContinue;
-        canStopWithStyleChange = false;
-      }
-      CaptureChange(oldContext, newContext, assumeDifferenceHint,
-                    &equalStructs, &samePointerStructs);
-      if (equalStructs != NS_STYLE_INHERIT_MASK) {
-        // At least one struct had different data in it, so we must
-        // continue restyling children.
-        LOG_RESTYLE_CONTINUE("there is different style data: %s",
-                    GeckoRestyleManager::StructNamesToString(
-                      ~equalStructs & NS_STYLE_INHERIT_MASK).get());
-        result = RestyleResult::eContinue;
-      }
-    }
-
-    if (canStopWithStyleChange) {
-      // If any inherited struct pointers are different, or if any
-      // reset struct pointers are different and we have descendants
-      // that rely on those reset struct pointers, we can't return
-      // RestyleResult::eStopWithStyleChange.
-      if ((samePointerStructs & NS_STYLE_INHERITED_STRUCT_MASK) !=
-            NS_STYLE_INHERITED_STRUCT_MASK) {
-        LOG_RESTYLE("can't return RestyleResult::eStopWithStyleChange since "
-                    "there is different inherited data");
-        canStopWithStyleChange = false;
-      } else if ((samePointerStructs & NS_STYLE_RESET_STRUCT_MASK) !=
-                   NS_STYLE_RESET_STRUCT_MASK &&
-                 oldContext->HasChildThatUsesResetStyle()) {
-        LOG_RESTYLE("can't return RestyleResult::eStopWithStyleChange since "
-                    "there is different reset data and descendants use it");
-        canStopWithStyleChange = false;
-      }
-    }
-
-    if (result == RestyleResult::eStop) {
-      // Since we currently have RestyleResult::eStop, we know at this
-      // point that all of our style structs are equal in terms of styles.
-      // However, some of them might be different pointers.  Since our
-      // descendants might share those pointers, we have to continue to
-      // restyling our descendants.
-      //
-      // However, because of the swapping of equal structs we've done on
-      // ancestors (later in this function), we've ensured that for structs
-      // that cannot be stored in the rule tree, we keep the old equal structs
-      // around rather than replacing them with new ones.  This means that we
-      // only time we hit this deoptimization is either
-      //
-      // (a) when at least one of the (old or new) equal structs could be stored
-      //     in the rule tree, and those structs are then inherited (by pointer
-      //     sharing) to descendant style contexts; or
-      //
-      // (b) when we were unable to swap the structs on the parent because
-      //     either or both of the old parent and new parent are shared.
-      //
-      // FIXME This loop could be rewritten as bit operations on
-      //       oldContext->mBits and samePointerStructs.
-      for (nsStyleStructID sid = nsStyleStructID(0);
-           sid < nsStyleStructID_Length;
-           sid = nsStyleStructID(sid + 1)) {
-        if (oldContext->HasCachedDependentStyleData(sid) &&
-            !(samePointerStructs & nsCachedStyleData::GetBitForSID(sid))) {
-          LOG_RESTYLE_CONTINUE("there are different struct pointers");
-          result = RestyleResult::eContinue;
-          break;
-        }
-      }
-    }
-
-    // From this point we no longer do any assignments of
-    // RestyleResult::eContinue to |result|.  If canStopWithStyleChange is true,
-    // it means that we can convert |result| (whether it is
-    // RestyleResult::eContinue or RestyleResult::eStop) into
-    // RestyleResult::eStopWithStyleChange.
-    if (canStopWithStyleChange) {
-      LOG_RESTYLE("converting %s into RestyleResult::eStopWithStyleChange",
-                  RestyleResultToString(result).get());
-      result = RestyleResult::eStopWithStyleChange;
-    }
-
-    if (aRestyleHint & eRestyle_ForceDescendants) {
-      result = RestyleResult::eContinueAndForceDescendants;
-    }
-
-    if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-      // If the frame gets regenerated, let it keep its old context,
-      // which is important to maintain various invariants about
-      // frame types matching their style contexts.
-      // Note that this check even makes sense if we didn't call
-      // CaptureChange because of copyFromContinuation being true,
-      // since we'll have copied the existing context from the
-      // previous continuation, so newContext == oldContext.
-
-      if (result != RestyleResult::eStop) {
-        if (copyFromContinuation) {
-          LOG_RESTYLE("not swapping style structs, since we copied from a "
-                      "continuation");
-        } else if (oldContext->IsShared() && newContext->IsShared()) {
-          LOG_RESTYLE("not swapping style structs, since both old and contexts "
-                      "are shared");
-        } else if (oldContext->IsShared()) {
-          LOG_RESTYLE("not swapping style structs, since the old context is "
-                      "shared");
-        } else if (newContext->IsShared()) {
-          LOG_RESTYLE("not swapping style structs, since the new context is "
-                      "shared");
-        } else {
-          if (result == RestyleResult::eStopWithStyleChange) {
-            LOG_RESTYLE("recording a style struct swap between %p and %p to "
-                        "do if RestyleResult::eStopWithStyleChange fails",
-                        oldContext.get(), newContext.get());
-            SwapInstruction* swap = aSwaps.AppendElement();
-            swap->mOldContext = oldContext;
-            swap->mNewContext = newContext;
-            swap->mStructsToSwap = equalStructs;
-          } else {
-            LOG_RESTYLE("swapping style structs between %p and %p",
-                        oldContext.get(), newContext.get());
-            oldContext->AsGecko()->SwapStyleData(newContext->AsGecko(), equalStructs);
-            *aSwappedStructs |= equalStructs;
-          }
-#ifdef RESTYLE_LOGGING
-          uint32_t structs = GeckoRestyleManager::StructsToLog() & equalStructs;
-          if (structs) {
-            LOG_RESTYLE_INDENT();
-            LOG_RESTYLE("old style context now has: %s",
-                        oldContext->AsGecko()->GetCachedStyleDataAsString(structs).get());
-            LOG_RESTYLE("new style context now has: %s",
-                        newContext->AsGecko()->GetCachedStyleDataAsString(structs).get());
-          }
-#endif
-        }
-        LOG_RESTYLE("setting new style context");
-        aSelf->SetStyleContext(newContext);
-      }
-    } else {
-      LOG_RESTYLE("not setting new style context, since we'll reframe");
-      // We need to keep the new parent alive, in case it had structs
-      // swapped into it that our frame's style context still has cached.
-      // This is a similar scenario to the one described in the
-      // ElementRestyler::Restyle comment where we append to
-      // mSwappedStructOwners.
-      //
-      // We really only need to do this if we did swap structs on the
-      // parent, but we don't have that information here.
-      mSwappedStructOwners.AppendElement(newContext->GetParent());
-    }
-  } else {
-    if (aRestyleHint & eRestyle_ForceDescendants) {
-      result = RestyleResult::eContinueAndForceDescendants;
-    }
-  }
-  oldContext = nullptr;
-
-  // do additional contexts
-  // XXXbz might be able to avoid selector matching here in some
-  // cases; won't worry about it for now.
-  int32_t contextIndex = 0;
-  for (nsStyleContext* oldExtraContext;
-       (oldExtraContext = aSelf->GetAdditionalStyleContext(contextIndex));
-       ++contextIndex) {
-    LOG_RESTYLE("extra context %d", contextIndex);
-    LOG_RESTYLE_INDENT();
-    RefPtr<GeckoStyleContext> newExtraContext;
-    nsAtom* const extraPseudoTag = oldExtraContext->GetPseudo();
-    const CSSPseudoElementType extraPseudoType =
-      oldExtraContext->GetPseudoType();
-    NS_ASSERTION(extraPseudoTag &&
-                 !nsCSSAnonBoxes::IsNonElement(extraPseudoTag),
-                 "extra style context is not pseudo element");
-    Element* element =
-      (extraPseudoType != CSSPseudoElementType::InheritingAnonBox &&
-       extraPseudoType != CSSPseudoElementType::NonInheritingAnonBox)
-      ? mContent->AsElement() : nullptr;
-    if (extraPseudoType == CSSPseudoElementType::NonInheritingAnonBox) {
-      newExtraContext =
-        styleSet->ResolveNonInheritingAnonymousBoxStyle(extraPseudoTag);
-    } else if (!MustRestyleSelf(aRestyleHint, element)) {
-      if (CanReparentStyleContext(aRestyleHint)) {
-        newExtraContext =
-          styleSet->ReparentStyleContext(oldExtraContext->AsGecko(), newContext, element);
-      } else {
-        // Use ResolveStyleWithReplacement as a substitute for
-        // ReparentStyleContext that rebuilds the path in the rule tree
-        // rather than reusing the rule node, as we need to do during a
-        // rule tree reconstruct.
-        Element* pseudoElement =
-          PseudoElementForStyleContext(aSelf, extraPseudoType);
-        MOZ_ASSERT(!element || element != pseudoElement,
-                   "pseudo-element for selector matching should be "
-                   "the anonymous content node that we create, "
-                   "not the real element");
-        newExtraContext =
-          styleSet->ResolveStyleWithReplacement(element, pseudoElement,
-                                                newContext, oldExtraContext->AsGecko(),
-                                                nsRestyleHint(0));
-      }
-    } else if (extraPseudoType == CSSPseudoElementType::InheritingAnonBox) {
-      newExtraContext = styleSet->
-        ResolveInheritingAnonymousBoxStyle(extraPseudoTag, newContext);
-    } else {
-      // Don't expect XUL tree stuff here, since it needs a comparator and
-      // all.
-      NS_ASSERTION(extraPseudoType < CSSPseudoElementType::Count,
-                   "Unexpected type");
-      newExtraContext = styleSet->ResolvePseudoElementStyle(mContent->AsElement(),
-                                                            extraPseudoType,
-                                                            newContext,
-                                                            nullptr);
-    }
-
-    MOZ_ASSERT(newExtraContext);
-
-    LOG_RESTYLE("newExtraContext = %p", newExtraContext.get());
-
-    if (oldExtraContext != newExtraContext) {
-      uint32_t equalStructs;
-      uint32_t samePointerStructs;
-      CaptureChange(oldExtraContext->AsGecko(), newExtraContext, assumeDifferenceHint,
-                    &equalStructs, &samePointerStructs);
-      if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-        LOG_RESTYLE("setting new extra style context");
-        aSelf->SetAdditionalStyleContext(contextIndex, newExtraContext);
-      } else {
-        LOG_RESTYLE("not setting new extra style context, since we'll reframe");
-      }
-    }
-  }
-
-  LOG_RESTYLE("returning %s", RestyleResultToString(result).get());
-
-  return result;
-}
-
-void
-ElementRestyler::RestyleChildren(nsRestyleHint aChildRestyleHint)
-{
-  MOZ_ASSERT(!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame),
-             "No need to do this if we're planning to reframe already.");
-
-  // We'd like style resolution to be exact in the sense that an
-  // animation-only style flush flushes only the styles it requests
-  // flushing and doesn't update any other styles.  This means avoiding
-  // constructing new frames during such a flush.
-  //
-  // For a ::before or ::after, we'll do an eRestyle_Subtree due to
-  // RestyleHintForOp in nsCSSRuleProcessor.cpp (via its
-  // HasAttributeDependentStyle or HasStateDependentStyle), given that
-  // we store pseudo-elements in selectors like they were children.
-  //
-  // Also, it's faster to skip the work we do on undisplayed children
-  // and pseudo-elements when we can skip it.
-  bool mightReframePseudos = aChildRestyleHint & eRestyle_Subtree;
-
-  RestyleUndisplayedDescendants(aChildRestyleHint);
-
-  // Check whether we might need to create a new ::before frame.
-  // There's no need to do this if we're planning to reframe already
-  // or if we're not forcing restyles on kids.
-  // It's also important to check mHintsHandledBySelf since we use
-  // mFrame->StyleContext(), which is out of date if mHintsHandledBySelf
-  // has a ReconstructFrame hint.  Using an out of date style context could
-  // trigger assertions about mismatched rule trees.
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame) &&
-      mightReframePseudos) {
-    MaybeReframeForBeforePseudo();
-  }
-
-  // There is no need to waste time crawling into a frame's children
-  // on a frame change.  The act of reconstructing frames will force
-  // new style contexts to be resolved on all of this frame's
-  // descendants anyway, so we want to avoid wasting time processing
-  // style contexts that we're just going to throw away anyway. - dwh
-  // It's also important to check mHintsHandledBySelf since reresolving the
-  // kids would use mFrame->StyleContext(), which is out of date if
-  // mHintsHandledBySelf has a ReconstructFrame hint; doing this could
-  // trigger assertions about mismatched rule trees.
-  nsIFrame* lastContinuation;
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-    InitializeAccessibilityNotifications(mFrame->StyleContext());
-
-    for (nsIFrame* f = mFrame; f;
-         f = GetNextContinuationWithSameStyle(f, f->StyleContext()->AsGecko())) {
-      lastContinuation = f;
-      RestyleContentChildren(f, aChildRestyleHint);
-    }
-
-    SendAccessibilityNotifications();
-  }
-
-  // Check whether we might need to create a new ::after frame.
-  // See comments above regarding :before.
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame) &&
-      mightReframePseudos) {
-    MaybeReframeForAfterPseudo(lastContinuation);
-  }
-}
-
-void
-ElementRestyler::RestyleChildrenOfDisplayContentsElement(
-  nsIFrame*              aParentFrame,
-  GeckoStyleContext*        aNewContext,
-  nsChangeHint           aMinHint,
-  RestyleTracker&        aRestyleTracker,
-  nsRestyleHint          aRestyleHint,
-  const RestyleHintData& aRestyleHintData)
-{
-  MOZ_ASSERT(!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame),
-             "why call me?");
-
-  const bool mightReframePseudos = aRestyleHint & eRestyle_Subtree;
-  DoRestyleUndisplayedDescendants(nsRestyleHint(0), mContent, aNewContext);
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame) &&
-      mightReframePseudos) {
-    MaybeReframeForPseudo(CSSPseudoElementType::before,
-                          aParentFrame, nullptr, mContent, aNewContext);
-  }
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame) &&
-      mightReframePseudos) {
-    MaybeReframeForPseudo(CSSPseudoElementType::after,
-                          aParentFrame, nullptr, mContent, aNewContext);
-  }
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-    InitializeAccessibilityNotifications(aNewContext);
-
-    // Then process child frames for content that is a descendant of mContent.
-    // XXX perhaps it's better to walk child frames (before reresolving
-    // XXX undisplayed contexts above) and mark those that has a stylecontext
-    // XXX leading up to mContent's old context? (instead of the
-    // XXX ContentIsDescendantOf check below)
-    nsIFrame::ChildListIterator lists(aParentFrame);
-    for ( ; !lists.IsDone(); lists.Next()) {
-      for (nsIFrame* f : lists.CurrentList()) {
-        if (nsContentUtils::ContentIsDescendantOf(f->GetContent(), mContent) &&
-            !f->GetPrevContinuation()) {
-          if (!(f->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {
-            ComputeStyleChangeFor(f, mChangeList, aMinHint, aRestyleTracker,
-                                  aRestyleHint, aRestyleHintData,
-                                  mContextsToClear, mSwappedStructOwners);
-          }
-        }
-      }
-    }
-  }
-  if (!(mHintsHandledBySelf & nsChangeHint_ReconstructFrame)) {
-    SendAccessibilityNotifications();
-  }
-}
-
-void
-ElementRestyler::ComputeStyleChangeFor(nsIFrame*          aFrame,
-                                       nsStyleChangeList* aChangeList,
-                                       nsChangeHint       aMinChange,
-                                       RestyleTracker&    aRestyleTracker,
-                                       nsRestyleHint      aRestyleHint,
-                                       const RestyleHintData& aRestyleHintData,
-                                       nsTArray<ContextToClear>&
-                                         aContextsToClear,
-                                       nsTArray<RefPtr<GeckoStyleContext>>&
-                                         aSwappedStructOwners)
-{
-  AUTO_PROFILER_LABEL("ElementRestyler::ComputeStyleChangeFor", CSS);
-
-  nsIContent* content = aFrame->GetContent();
-  if (aMinChange) {
-    aChangeList->AppendChange(aFrame, content, aMinChange);
-  }
-
-  NS_ASSERTION(!aFrame->GetPrevContinuation(),
-               "must start with the first continuation");
-
-  // We want to start with this frame and walk all its next-in-flows,
-  // as well as all its ib-split siblings and their next-in-flows,
-  // reresolving style on all the frames we encounter in this walk that
-  // we didn't reach already.  In the normal case, this will mean only
-  // restyling the first two block-in-inline splits and no
-  // continuations, and skipping everything else.  However, when we have
-  // a style change targeted at an element inside a context where styles
-  // vary between continuations (e.g., a style change on an element that
-  // extends from inside a styled ::first-line to outside of that first
-  // line), we might restyle more than that.
-
-  nsPresContext* presContext = aFrame->PresContext();
-
-  TreeMatchContext treeMatchContext(true,
-                                    nsRuleWalker::eRelevantLinkUnvisited,
-                                    presContext->Document());
-  Element* parent =
-    content ? content->GetParentElementCrossingShadowRoot() : nullptr;
-  treeMatchContext.InitAncestors(parent);
-  nsTArray<nsCSSSelector*> selectorsForDescendants;
-  selectorsForDescendants.AppendElements(
-      aRestyleHintData.mSelectorsForDescendants);
-  nsTArray<nsIContent*> visibleKidsOfHiddenElement;
-  nsIFrame* nextIBSibling;
-  for (nsIFrame* ibSibling = aFrame; ibSibling; ibSibling = nextIBSibling) {
-    nextIBSibling = GetNextBlockInInlineSibling(ibSibling);
-
-    if (nextIBSibling) {
-      // Don't allow some ib-split siblings to be processed with
-      // RestyleResult::eStopWithStyleChange and others not.
-      aRestyleHint |= eRestyle_Force;
-    }
-
-    // Outer loop over ib-split siblings
-    for (nsIFrame* cont = ibSibling; cont; cont = cont->GetNextContinuation()) {
-      if (GetPrevContinuationWithSameStyle(cont)) {
-        // We already handled this element when dealing with its earlier
-        // continuation.
-        continue;
-      }
-
-      // Inner loop over next-in-flows of the current frame
-      ElementRestyler restyler(presContext, cont, aChangeList,
-                               aMinChange, aRestyleTracker,
-                               selectorsForDescendants,
-                               treeMatchContext,
-                               visibleKidsOfHiddenElement,
-                               aContextsToClear, aSwappedStructOwners);
-
-      restyler.Restyle(aRestyleHint);
-
-      if (restyler.HintsHandledForFrame() & nsChangeHint_ReconstructFrame) {
-        // If it's going to cause a framechange, then don't bother
-        // with the continuations or ib-split siblings since they'll be
-        // clobbered by the frame reconstruct anyway.
-        NS_ASSERTION(!cont->GetPrevContinuation(),
-                     "continuing frame had more severe impact than first-in-flow");
-        return;
-      }
-    }
-  }
-}
-
-// The structure of this method parallels ConditionallyRestyleUndisplayedDescendants.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::RestyleUndisplayedDescendants(nsRestyleHint aChildRestyleHint)
-{
-  nsIContent* undisplayedParent;
-  if (MustCheckUndisplayedContent(mFrame, undisplayedParent)) {
-    DoRestyleUndisplayedDescendants(aChildRestyleHint, undisplayedParent,
-                                    mFrame->StyleContext()->AsGecko());
-  }
-}
-
-// The structure of this method parallels DoConditionallyRestyleUndisplayedDescendants.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::DoRestyleUndisplayedDescendants(nsRestyleHint aChildRestyleHint,
-                                                 nsIContent* aParent,
-                                                 GeckoStyleContext* aParentContext)
-{
-  nsCSSFrameConstructor* fc = mPresContext->FrameConstructor();
-  UndisplayedNode* nodes = fc->GetAllRegisteredDisplayNoneStylesIn(aParent);
-  RestyleUndisplayedNodes(aChildRestyleHint, nodes, aParent,
-                          aParentContext, StyleDisplay::None);
-  nodes = fc->GetAllRegisteredDisplayContentsStylesIn(aParent);
-  RestyleUndisplayedNodes(aChildRestyleHint, nodes, aParent,
-                          aParentContext, StyleDisplay::Contents);
-}
-
-// The structure of this method parallels ConditionallyRestyleUndisplayedNodes.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::RestyleUndisplayedNodes(nsRestyleHint      aChildRestyleHint,
-                                         UndisplayedNode*   aUndisplayed,
-                                         nsIContent*        aUndisplayedParent,
-                                         GeckoStyleContext*    aParentContext,
-                                         const StyleDisplay aDisplay)
-{
-  nsIContent* undisplayedParent = aUndisplayedParent;
-  UndisplayedNode* undisplayed = aUndisplayed;
-  TreeMatchContext::AutoAncestorPusher pusher(&mTreeMatchContext);
-  if (undisplayed) {
-    pusher.PushAncestor(undisplayedParent);
-  }
-  for (; undisplayed; undisplayed = undisplayed->getNext()) {
-    NS_ASSERTION(undisplayedParent ||
-                 undisplayed->mContent ==
-                   mPresContext->Document()->GetRootElement(),
-                 "undisplayed node child of null must be root");
-    NS_ASSERTION(!undisplayed->mStyle->GetPseudo(),
-                 "Shouldn't have random pseudo style contexts in the "
-                 "undisplayed map");
-
-    LOG_RESTYLE("RestyleUndisplayedChildren: undisplayed->mContent = %p",
-                undisplayed->mContent.get());
-
-    // Get the parent of the undisplayed content and check if it is a XBL
-    // children element. Push the children element as an ancestor here because it does
-    // not have a frame and would not otherwise be pushed as an ancestor.
-    nsIContent* parent = undisplayed->mContent->GetParent();
-    TreeMatchContext::AutoAncestorPusher insertionPointPusher(&mTreeMatchContext);
-    if (parent && parent->IsActiveChildrenElement()) {
-      insertionPointPusher.PushAncestor(parent);
-    }
-
-    nsRestyleHint thisChildHint = aChildRestyleHint;
-    nsAutoPtr<RestyleTracker::RestyleData> undisplayedRestyleData;
-    Element* element = undisplayed->mContent->AsElement();
-    if (mRestyleTracker.GetRestyleData(element,
-                                       undisplayedRestyleData)) {
-      thisChildHint =
-        nsRestyleHint(thisChildHint | undisplayedRestyleData->mRestyleHint);
-    }
-    RefPtr<GeckoStyleContext> undisplayedContext;
-    nsStyleSet* styleSet = StyleSet();
-    if (MustRestyleSelf(thisChildHint, element)) {
-      undisplayedContext =
-        styleSet->ResolveStyleFor(element, aParentContext, mTreeMatchContext);
-    } else if (CanReparentStyleContext(thisChildHint)) {
-      undisplayedContext =
-        styleSet->ReparentStyleContext(undisplayed->mStyle->AsGecko(),
-                                       aParentContext,
-                                       element);
-    } else {
-      // Use ResolveStyleWithReplacement either for actual
-      // replacements, or as a substitute for ReparentStyleContext
-      // that rebuilds the path in the rule tree rather than reusing
-      // the rule node, as we need to do during a rule tree
-      // reconstruct.
-      nsRestyleHint rshint = thisChildHint & ~eRestyle_SomeDescendants;
-      undisplayedContext =
-        styleSet->ResolveStyleWithReplacement(element, nullptr,
-                                              aParentContext,
-                                              undisplayed->mStyle->AsGecko(),
-                                              rshint);
-    }
-    const nsStyleDisplay* display = undisplayedContext->StyleDisplay();
-    if (display->mDisplay != aDisplay) {
-      NS_ASSERTION(element, "Must have undisplayed content");
-      mChangeList->AppendChange(nullptr, element,
-                                nsChangeHint_ReconstructFrame);
-      // The node should be removed from the undisplayed map when
-      // we reframe it.
-    } else {
-      // update the undisplayed node with the new context
-      undisplayed->mStyle = undisplayedContext;
-
-      if (aDisplay == StyleDisplay::Contents) {
-        DoRestyleUndisplayedDescendants(aChildRestyleHint, element,
-                                        undisplayed->mStyle->AsGecko());
-      }
-    }
-  }
-}
-
-void
-ElementRestyler::MaybeReframeForBeforePseudo()
-{
-  MaybeReframeForPseudo(CSSPseudoElementType::before,
-                        mFrame, mFrame, mFrame->GetContent(),
-                        mFrame->StyleContext()->AsGecko());
-}
-
-/**
- * aFrame is the last continuation or block-in-inline sibling that this
- * ElementRestyler is restyling.
- */
-void
-ElementRestyler::MaybeReframeForAfterPseudo(nsIFrame* aFrame)
-{
-  MOZ_ASSERT(aFrame);
-  MaybeReframeForPseudo(CSSPseudoElementType::after,
-                        aFrame, aFrame, aFrame->GetContent(),
-                        aFrame->StyleContext()->AsGecko());
-}
-
-#ifdef DEBUG
-bool
-ElementRestyler::MustReframeForBeforePseudo()
-{
-  return MustReframeForPseudo(CSSPseudoElementType::before,
-                              mFrame, mFrame, mFrame->GetContent(),
-                              mFrame->StyleContext()->AsGecko());
-}
-
-bool
-ElementRestyler::MustReframeForAfterPseudo(nsIFrame* aFrame)
-{
-  MOZ_ASSERT(aFrame);
-  return MustReframeForPseudo(CSSPseudoElementType::after,
-                              aFrame, aFrame, aFrame->GetContent(),
-                              aFrame->StyleContext()->AsGecko());
-}
-#endif
-
-void
-ElementRestyler::MaybeReframeForPseudo(CSSPseudoElementType aPseudoType,
-                                       nsIFrame* aGenConParentFrame,
-                                       nsIFrame* aFrame,
-                                       nsIContent* aContent,
-                                       GeckoStyleContext* aStyleContext)
-{
-  if (MustReframeForPseudo(aPseudoType, aGenConParentFrame, aFrame, aContent,
-                           aStyleContext)) {
-    // Have to create the new ::before/::after frame.
-    LOG_RESTYLE("MaybeReframeForPseudo, appending "
-                "nsChangeHint_ReconstructFrame");
-    mHintsHandledBySelf |= nsChangeHint_ReconstructFrame;
-    mChangeList->AppendChange(aFrame, aContent, nsChangeHint_ReconstructFrame);
-  }
-}
-
-bool
-ElementRestyler::MustReframeForPseudo(CSSPseudoElementType aPseudoType,
-                                      nsIFrame* aGenConParentFrame,
-                                      nsIFrame* aFrame,
-                                      nsIContent* aContent,
-                                      GeckoStyleContext* aStyleContext)
-{
-  MOZ_ASSERT(aPseudoType == CSSPseudoElementType::before ||
-             aPseudoType == CSSPseudoElementType::after);
-
-  // Make sure not to do this for pseudo-frames...
-  if (aStyleContext->GetPseudo()) {
-    return false;
-  }
-
-  // ... or frames that can't have generated content.
-  if (!(aGenConParentFrame->GetStateBits() & NS_FRAME_MAY_HAVE_GENERATED_CONTENT)) {
-    // Our content insertion frame might have gotten flagged.
-    nsContainerFrame* cif = aGenConParentFrame->GetContentInsertionFrame();
-    if (!cif || !(cif->GetStateBits() & NS_FRAME_MAY_HAVE_GENERATED_CONTENT)) {
-      return false;
-    }
-  }
-
-  if (aPseudoType == CSSPseudoElementType::before) {
-    // Check for a ::before pseudo style and the absence of a ::before content,
-    // but only if aFrame is null or is the first continuation/ib-split.
-    if ((aFrame && !nsLayoutUtils::IsFirstContinuationOrIBSplitSibling(aFrame)) ||
-        nsLayoutUtils::GetBeforeFrame(aContent)) {
-      return false;
-    }
-  } else {
-    // Similarly for ::after, but check for being the last continuation/
-    // ib-split.
-    if ((aFrame && nsLayoutUtils::GetNextContinuationOrIBSplitSibling(aFrame)) ||
-        nsLayoutUtils::GetAfterFrame(aContent)) {
-      return false;
-    }
-  }
-
-  // Checking for a ::before frame (which we do above) is cheaper than getting
-  // the ::before style context here.
-  return nsLayoutUtils::HasPseudoStyle(aContent, aStyleContext, aPseudoType,
-                                       mPresContext);
-}
-
-void
-ElementRestyler::InitializeAccessibilityNotifications(nsStyleContext* aNewContext)
-{
-#ifdef ACCESSIBILITY
-  // Notify a11y for primary frame only if it's a root frame of visibility
-  // changes or its parent frame was hidden while it stays visible and
-  // it is not inside a {ib} split or is the first frame of {ib} split.
-  if (nsIPresShell::IsAccessibilityActive() &&
-      (!mFrame ||
-       (!mFrame->GetPrevContinuation() &&
-        !mFrame->FrameIsNonFirstInIBSplit()))) {
-    if (mDesiredA11yNotifications == eSendAllNotifications) {
-      bool isFrameVisible = aNewContext->StyleVisibility()->IsVisible();
-      if (isFrameVisible != mWasFrameVisible) {
-        if (isFrameVisible) {
-          // Notify a11y the element (perhaps with its children) was shown.
-          // We don't fall into this case if this element gets or stays shown
-          // while its parent becomes hidden.
-          mKidsDesiredA11yNotifications = eSkipNotifications;
-          mOurA11yNotification = eNotifyShown;
-        } else {
-          // The element is being hidden; its children may stay visible, or
-          // become visible after being hidden previously. If we'll find
-          // visible children then we should notify a11y about that as if
-          // they were inserted into tree. Notify a11y this element was
-          // hidden.
-          mKidsDesiredA11yNotifications = eNotifyIfShown;
-          mOurA11yNotification = eNotifyHidden;
-        }
-      }
-    } else if (mDesiredA11yNotifications == eNotifyIfShown &&
-               aNewContext->StyleVisibility()->IsVisible()) {
-      // Notify a11y that element stayed visible while its parent was hidden.
-      nsIContent* c = mFrame ? mFrame->GetContent() : mContent;
-      mVisibleKidsOfHiddenElement.AppendElement(c);
-      mKidsDesiredA11yNotifications = eSkipNotifications;
-    }
-  }
-#endif
-}
-
-// The structure of this method parallels ConditionallyRestyleContentChildren.
-// If you update this method, you probably want to update that one too.
-void
-ElementRestyler::RestyleContentChildren(nsIFrame* aParent,
-                                        nsRestyleHint aChildRestyleHint)
-{
-  LOG_RESTYLE("RestyleContentChildren");
-
-  nsIFrame::ChildListIterator lists(aParent);
-  TreeMatchContext::AutoAncestorPusher ancestorPusher(&mTreeMatchContext);
-  if (!lists.IsDone()) {
-    ancestorPusher.PushAncestor(mContent);
-  }
-  for (; !lists.IsDone(); lists.Next()) {
-    for (nsIFrame* child : lists.CurrentList()) {
-      // Out-of-flows are reached through their placeholders.  Continuations
-      // and block-in-inline splits are reached through those chains.
-      if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
-          !GetPrevContinuationWithSameStyle(child)) {
-        // Get the parent of the child frame's content and check if it
-        // is a XBL children element. Push the children element as an
-        // ancestor here because it does not have a frame and would not
-        // otherwise be pushed as an ancestor.
-
-        // Check if the frame has a content because |child| may be a
-        // nsPageFrame that does not have a content.
-        nsIContent* parent = child->GetContent() ? child->GetContent()->GetParent() : nullptr;
-        TreeMatchContext::AutoAncestorPusher insertionPointPusher(&mTreeMatchContext);
-        if (parent && parent->IsActiveChildrenElement()) {
-          insertionPointPusher.PushAncestor(parent);
-        }
-
-        // only do frames that are in flow
-        if (child->IsPlaceholderFrame()) { // placeholder
-          // get out of flow frame and recur there
-          nsIFrame* outOfFlowFrame =
-            nsPlaceholderFrame::GetRealFrameForPlaceholder(child);
-          NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");
-          NS_ASSERTION(outOfFlowFrame != mResolvedChild,
-                       "out-of-flow frame not a true descendant");
-
-          // |nsFrame::GetParentStyleContext| checks being out
-          // of flow so that this works correctly.
-          do {
-            if (GetPrevContinuationWithSameStyle(outOfFlowFrame)) {
-              // Later continuations are likely restyled as a result of
-              // the restyling of the previous continuation.
-              // (Currently that's always true, but it's likely to
-              // change if we implement overflow:fragments or similar.)
-              continue;
-            }
-            ElementRestyler oofRestyler(*this, outOfFlowFrame,
-                                        FOR_OUT_OF_FLOW_CHILD);
-            oofRestyler.Restyle(aChildRestyleHint);
-          } while ((outOfFlowFrame = outOfFlowFrame->GetNextContinuation()));
-
-          // reresolve placeholder's context under the same parent
-          // as the out-of-flow frame
-          ElementRestyler phRestyler(*this, child, 0);
-          phRestyler.Restyle(aChildRestyleHint);
-        }
-        else {  // regular child frame
-          if (child != mResolvedChild) {
-            ElementRestyler childRestyler(*this, child, 0);
-            childRestyler.Restyle(aChildRestyleHint);
-          }
-        }
-      }
-    }
-  }
-  // XXX need to do overflow frames???
-}
-
-void
-ElementRestyler::SendAccessibilityNotifications()
-{
-#ifdef ACCESSIBILITY
-  // Send notifications about visibility changes.
-  if (mOurA11yNotification == eNotifyShown) {
-    nsAccessibilityService* accService = nsIPresShell::AccService();
-    if (accService) {
-      nsIPresShell* presShell = mPresContext->GetPresShell();
-      nsIContent* content = mFrame ? mFrame->GetContent() : mContent;
-
-      accService->ContentRangeInserted(presShell, content->GetParent(),
-                                       content,
-                                       content->GetNextSibling());
-    }
-  } else if (mOurA11yNotification == eNotifyHidden) {
-    nsAccessibilityService* accService = nsIPresShell::AccService();
-    if (accService) {
-      nsIPresShell* presShell = mPresContext->GetPresShell();
-      nsIContent* content = mFrame ? mFrame->GetContent() : mContent;
-      accService->ContentRemoved(presShell, content);
-
-      // Process children staying shown.
-      uint32_t visibleContentCount = mVisibleKidsOfHiddenElement.Length();
-      for (uint32_t idx = 0; idx < visibleContentCount; idx++) {
-        nsIContent* childContent = mVisibleKidsOfHiddenElement[idx];
-        accService->ContentRangeInserted(presShell, childContent->GetParent(),
-                                         childContent,
-                                         childContent->GetNextSibling());
-      }
-      mVisibleKidsOfHiddenElement.Clear();
-    }
-  }
-#endif
-}
-
-static void
-ClearCachedInheritedStyleDataOnDescendants(
-    nsTArray<ElementRestyler::ContextToClear>& aContextsToClear)
-{
-  for (size_t i = 0; i < aContextsToClear.Length(); i++) {
-    auto& entry = aContextsToClear[i];
-    if (!entry.mStyleContext->HasSingleReference()) {
-      entry.mStyleContext->AsGecko()->ClearCachedInheritedStyleDataOnDescendants(
-          entry.mStructs);
-    }
-    entry.mStyleContext = nullptr;
-  }
-}
-
-void
-GeckoRestyleManager::ComputeAndProcessStyleChange(
-    nsIFrame*              aFrame,
-    nsChangeHint           aMinChange,
-    RestyleTracker&        aRestyleTracker,
-    nsRestyleHint          aRestyleHint,
-    const RestyleHintData& aRestyleHintData)
-{
-  MOZ_ASSERT(mReframingStyleContexts, "should have rsc");
-  nsStyleChangeList changeList(StyleBackendType::Gecko);
-  nsTArray<ElementRestyler::ContextToClear> contextsToClear;
-
-  // swappedStructOwners needs to be kept alive until after
-  // ProcessRestyledFrames and ClearCachedInheritedStyleDataOnDescendants
-  // calls; see comment in ElementRestyler::Restyle.
-  nsTArray<RefPtr<GeckoStyleContext>> swappedStructOwners;
-  ElementRestyler::ComputeStyleChangeFor(aFrame, &changeList, aMinChange,
-                                         aRestyleTracker, aRestyleHint,
-                                         aRestyleHintData,
-                                         contextsToClear, swappedStructOwners);
-  ProcessRestyledFrames(changeList);
-  ClearCachedInheritedStyleDataOnDescendants(contextsToClear);
-}
-
-void
-GeckoRestyleManager::ComputeAndProcessStyleChange(
-    GeckoStyleContext*        aNewContext,
-    Element*               aElement,
-    nsChangeHint           aMinChange,
-    RestyleTracker&        aRestyleTracker,
-    nsRestyleHint          aRestyleHint,
-    const RestyleHintData& aRestyleHintData)
-{
-  MOZ_ASSERT(mReframingStyleContexts, "should have rsc");
-  MOZ_ASSERT(aNewContext->StyleDisplay()->mDisplay == StyleDisplay::Contents);
-  nsIFrame* frame = GetNearestAncestorFrame(aElement);
-  MOZ_ASSERT(frame, "display:contents node in map although it's a "
-                    "display:none descendant?");
-  TreeMatchContext treeMatchContext(true,
-                                    nsRuleWalker::eRelevantLinkUnvisited,
-                                    frame->PresContext()->Document());
-  nsIContent* parent = aElement->GetParent();
-  Element* parentElement =
-    parent && parent->IsElement() ? parent->AsElement() : nullptr;
-  treeMatchContext.InitAncestors(parentElement);
-
-  nsTArray<nsCSSSelector*> selectorsForDescendants;
-  nsTArray<nsIContent*> visibleKidsOfHiddenElement;
-  nsTArray<ElementRestyler::ContextToClear> contextsToClear;
-
-  // swappedStructOwners needs to be kept alive until after
-  // ProcessRestyledFrames and ClearCachedInheritedStyleDataOnDescendants
-  // calls; see comment in ElementRestyler::Restyle.
-  nsTArray<RefPtr<GeckoStyleContext>> swappedStructOwners;
-  nsStyleChangeList changeList(StyleBackendType::Gecko);
-  ElementRestyler r(frame->PresContext(), aElement, &changeList, aMinChange,
-                    aRestyleTracker, selectorsForDescendants, treeMatchContext,
-                    visibleKidsOfHiddenElement, contextsToClear,
-                    swappedStructOwners);
-  r.RestyleChildrenOfDisplayContentsElement(frame, aNewContext, aMinChange,
-                                            aRestyleTracker,
-                                            aRestyleHint, aRestyleHintData);
-  ProcessRestyledFrames(changeList);
-  ClearCachedInheritedStyleDataOnDescendants(contextsToClear);
-}
-
-bool
-GeckoRestyleManager::HasPendingRestyles() const
-{
-  return mPendingRestyles.Count() != 0;
-}
-
-nsStyleSet*
-ElementRestyler::StyleSet() const
-{
-  MOZ_ASSERT(mPresContext->StyleSet()->IsGecko(),
-             "ElementRestyler should only be used with a Gecko-flavored "
-             "style backend");
-  return mPresContext->StyleSet()->AsGecko();
-}
-
-AutoDisplayContentsAncestorPusher::AutoDisplayContentsAncestorPusher(
-  TreeMatchContext& aTreeMatchContext, nsPresContext* aPresContext,
-  nsIContent* aParent)
-  : mTreeMatchContext(aTreeMatchContext)
-  , mPresContext(aPresContext)
-{
-  if (aParent) {
-    nsFrameManager* fm = mPresContext->FrameConstructor();
-    // Push display:contents mAncestors onto mTreeMatchContext.
-    for (nsIContent* p = aParent; p && fm->GetDisplayContentsStyleFor(p);
-         p = p->GetParent()) {
-      mAncestors.AppendElement(p->AsElement());
-    }
-    bool hasFilter = mTreeMatchContext.mAncestorFilter.HasFilter();
-    nsTArray<mozilla::dom::Element*>::size_type i = mAncestors.Length();
-    while (i--) {
-      if (hasFilter) {
-        mTreeMatchContext.mAncestorFilter.PushAncestor(mAncestors[i]);
-      }
-    }
-  }
-}
-
-AutoDisplayContentsAncestorPusher::~AutoDisplayContentsAncestorPusher()
-{
-  // Pop the ancestors we pushed in the CTOR, if any.
-  typedef nsTArray<mozilla::dom::Element*>::size_type sz;
-  sz len = mAncestors.Length();
-  bool hasFilter = mTreeMatchContext.mAncestorFilter.HasFilter();
-  for (sz i = 0; i < len; ++i) {
-    if (hasFilter) {
-      mTreeMatchContext.mAncestorFilter.PopAncestor();
-    }
-  }
-}
-
-#ifdef RESTYLE_LOGGING
-uint32_t
-GeckoRestyleManager::StructsToLog()
-{
-  static bool initialized = false;
-  static uint32_t structs;
-  if (!initialized) {
-    structs = 0;
-    const char* value = getenv("MOZ_DEBUG_RESTYLE_STRUCTS");
-    if (value) {
-      nsCString s(value);
-      while (!s.IsEmpty()) {
-        int32_t index = s.FindChar(',');
-        nsStyleStructID sid;
-        bool found;
-        if (index == -1) {
-          found = GeckoStyleContext::LookupStruct(s, sid);
-          s.Truncate();
-        } else {
-          found = nsStyleContext::LookupStruct(Substring(s, 0, index), sid);
-          s = Substring(s, index + 1);
-        }
-        if (found) {
-          structs |= nsCachedStyleData::GetBitForSID(sid);
-        }
-      }
-    }
-    initialized = true;
-  }
-  return structs;
-}
-#endif
-
-#ifdef DEBUG
-/* static */ nsCString
-GeckoRestyleManager::StructNamesToString(uint32_t aSIDs)
-{
-  nsCString result;
-  bool any = false;
-  for (nsStyleStructID sid = nsStyleStructID(0);
-       sid < nsStyleStructID_Length;
-       sid = nsStyleStructID(sid + 1)) {
-    if (aSIDs & nsCachedStyleData::GetBitForSID(sid)) {
-      if (any) {
-        result.AppendLiteral(",");
-      }
-      result.AppendPrintf("%s", nsStyleContext::StructName(sid));
-      any = true;
-    }
-  }
-  return result;
-}
-
-/* static */ nsCString
-ElementRestyler::RestyleResultToString(RestyleResult aRestyleResult)
-{
-  nsCString result;
-  switch (aRestyleResult) {
-    case RestyleResult::eStop:
-      result.AssignLiteral("RestyleResult::eStop");
-      break;
-    case RestyleResult::eStopWithStyleChange:
-      result.AssignLiteral("RestyleResult::eStopWithStyleChange");
-      break;
-    case RestyleResult::eContinue:
-      result.AssignLiteral("RestyleResult::eContinue");
-      break;
-    case RestyleResult::eContinueAndForceDescendants:
-      result.AssignLiteral("RestyleResult::eContinueAndForceDescendants");
-      break;
-    default:
-      MOZ_ASSERT(aRestyleResult == RestyleResult::eNone,
-                 "Unexpected RestyleResult");
-  }
-  return result;
-}
-#endif
-
-} // namespace mozilla
deleted file mode 100644
--- a/layout/base/GeckoRestyleManager.h
+++ /dev/null
@@ -1,770 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/**
- * Code responsible for managing style changes: tracking what style
- * changes need to happen, scheduling them, and doing them.
- */
-
-#ifndef mozilla_GeckoRestyleManager_h
-#define mozilla_GeckoRestyleManager_h
-
-#include "mozilla/RestyleLogging.h"
-#include "mozilla/RestyleManager.h"
-#include "nsISupportsImpl.h"
-#include "nsChangeHint.h"
-#include "RestyleTracker.h"
-#include "nsPresContext.h"
-#include "nsRefreshDriver.h"
-#include "nsRefPtrHashtable.h"
-#include "nsTransitionManager.h"
-
-class nsIFrame;
-class nsStyleChangeList;
-struct TreeMatchContext;
-
-namespace mozilla {
-  enum class CSSPseudoElementType : uint8_t;
-  class EventStates;
-  struct UndisplayedNode;
-
-namespace dom {
-  class Element;
-} // namespace dom
-
-class GeckoRestyleManager final : public RestyleManager
-{
-public:
-  typedef RestyleManager base_type;
-
-  friend class RestyleTracker;
-  friend class ElementRestyler;
-
-  explicit GeckoRestyleManager(nsPresContext* aPresContext);
-
-protected:
-  ~GeckoRestyleManager() override
-  {
-    MOZ_ASSERT(!mReframingStyleContexts,
-               "temporary member should be nulled out before destruction");
-  }
-
-public:
-  // Forwarded nsIDocumentObserver method, to handle restyling (and
-  // passing the notification to the frame).
-  void ContentStateChanged(nsIContent* aContent,
-                           EventStates aStateMask);
-
-  // Forwarded nsIMutationObserver method, to handle restyling.
-  void AttributeWillChange(Element* aElement,
-                           int32_t  aNameSpaceID,
-                           nsAtom* aAttribute,
-                           int32_t  aModType,
-                           const nsAttrValue* aNewValue);
-  // Forwarded nsIMutationObserver method, to handle restyling (and
-  // passing the notification to the frame).
-  void AttributeChanged(Element* aElement,
-                        int32_t  aNameSpaceID,
-                        nsAtom* aAttribute,
-                        int32_t  aModType,
-                        const nsAttrValue* aOldValue);
-
-  // Whether rule matching should skip styles associated with animation
-  bool SkipAnimationRules() const { return mSkipAnimationRules; }
-
-  void SetSkipAnimationRules(bool aSkipAnimationRules) {
-    mSkipAnimationRules = aSkipAnimationRules;
-  }
-
-  /**
-   * Reparent the style contexts of this frame subtree.  The parent frame of
-   * aFrame must be changed to the new parent before this function is called;
-   * the new parent style context will be automatically computed based on the
-   * new position in the frame tree.
-   *
-   * @param aFrame the root of the subtree to reparent.  Must not be null.
-   */
-  nsresult ReparentStyleContext(nsIFrame* aFrame);
-
-private:
-  /**
-   * Reparent the descendants of aFrame.  This is used by ReparentStyleContext
-   * and shouldn't be called by anyone else.  aProviderChild, if non-null, is a
-   * child that was the style parent for aFrame and hence shouldn't be
-   * reparented.
-   */
-  void ReparentFrameDescendants(nsIFrame* aFrame, nsIFrame* aProviderChild);
-
-public:
-  void ClearSelectors() {
-    mPendingRestyles.ClearSelectors();
-  }
-
-  void PostRestyleEventForLazyConstruction() { PostRestyleEventInternal(); }
-
-private:
-  void PostRestyleEventInternal();
-
-  // Used when restyling an element with a frame.
-  void ComputeAndProcessStyleChange(nsIFrame*              aFrame,
-                                    nsChangeHint           aMinChange,
-                                    RestyleTracker&        aRestyleTracker,
-                                    nsRestyleHint          aRestyleHint,
-                                    const RestyleHintData& aRestyleHintData);
-
-  // Used when restyling a display:contents element.
-  void ComputeAndProcessStyleChange(GeckoStyleContext*     aNewContext,
-                                    Element*               aElement,
-                                    nsChangeHint           aMinChange,
-                                    RestyleTracker&        aRestyleTracker,
-                                    nsRestyleHint          aRestyleHint,
-                                    const RestyleHintData& aRestyleHintData);
-
-public:
-
-  /**
-   * In order to start CSS transitions on elements that are being
-   * reframed, we need to stash their style contexts somewhere during
-   * the reframing process.
-   *
-   * In all cases, the content node in the hash table is the real
-   * content node, not the anonymous content node we create for ::before
-   * or ::after.  The content node passed to the Get and Put methods is,
-   * however, the content node to be associate with the frame's style
-   * context.
-   */
-  typedef nsRefPtrHashtable<nsRefPtrHashKey<nsIContent>, GeckoStyleContext>
-            ReframingStyleContextTable;
-  class MOZ_STACK_CLASS ReframingStyleContexts final {
-  public:
-    /**
-     * Construct a ReframingStyleContexts object.  The caller must
-     * ensure that aRestyleManager lives at least as long as the
-     * object.  (This is generally easy since the caller is typically a
-     * method of RestyleManager.)
-     */
-    explicit ReframingStyleContexts(GeckoRestyleManager* aRestyleManager);
-    ~ReframingStyleContexts();
-
-    void Put(nsIContent* aContent, GeckoStyleContext* aStyleContext) {
-      MOZ_ASSERT(aContent);
-      CSSPseudoElementType pseudoType = aStyleContext->GetPseudoType();
-      if (pseudoType == CSSPseudoElementType::NotPseudo) {
-        mElementContexts.Put(aContent, aStyleContext);
-      } else if (pseudoType == CSSPseudoElementType::before) {
-        MOZ_ASSERT(aContent->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentbefore);
-        mBeforePseudoContexts.Put(aContent->GetParent(), aStyleContext);
-      } else if (pseudoType == CSSPseudoElementType::after) {
-        MOZ_ASSERT(aContent->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentafter);
-        mAfterPseudoContexts.Put(aContent->GetParent(), aStyleContext);
-      }
-    }
-
-    GeckoStyleContext* Get(nsIContent* aContent,
-                        CSSPseudoElementType aPseudoType) {
-      MOZ_ASSERT(aContent);
-      if (aPseudoType == CSSPseudoElementType::NotPseudo) {
-        return mElementContexts.GetWeak(aContent);
-      }
-      if (aPseudoType == CSSPseudoElementType::before) {
-        MOZ_ASSERT(aContent->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentbefore);
-        return mBeforePseudoContexts.GetWeak(aContent->GetParent());
-      }
-      if (aPseudoType == CSSPseudoElementType::after) {
-        MOZ_ASSERT(aContent->NodeInfo()->NameAtom() == nsGkAtoms::mozgeneratedcontentafter);
-        return mAfterPseudoContexts.GetWeak(aContent->GetParent());
-      }
-      MOZ_ASSERT(false, "unexpected aPseudoType");
-      return nullptr;
-    }
-  private:
-    GeckoRestyleManager* mRestyleManager;
-    AutoRestore<ReframingStyleContexts*> mRestorePointer;
-    ReframingStyleContextTable mElementContexts;
-    ReframingStyleContextTable mBeforePseudoContexts;
-    ReframingStyleContextTable mAfterPseudoContexts;
-  };
-
-  /**
-   * Return the current ReframingStyleContexts struct, or null if we're
-   * not currently in a restyling operation.
-   */
-  ReframingStyleContexts* GetReframingStyleContexts() {
-    return mReframingStyleContexts;
-  }
-
-  /**
-   * Try initiating a transition for an element or a ::before or ::after
-   * pseudo-element, given an old and new style context.  This may
-   * change the new style context if a transition is started.  Returns
-   * true if it does change aNewStyleContext.
-   *
-   * For the pseudo-elements, aContent must be the anonymous content
-   * that we're creating for that pseudo-element, not the real element.
-   */
-  static bool
-  TryInitiatingTransition(nsPresContext* aPresContext, nsIContent* aContent,
-                          GeckoStyleContext* aOldStyleContext,
-                          RefPtr<GeckoStyleContext>* aNewStyleContext /* inout */);
-
-public:
-  // Process any pending restyles. This should be called after
-  // CreateNeededFrames.
-  // Note: It's the caller's responsibility to make sure to wrap a
-  // ProcessPendingRestyles call in a view update batch and a script blocker.
-  // This function does not call ProcessAttachedQueue() on the binding manager.
-  // If the caller wants that to happen synchronously, it needs to handle that
-  // itself.
-  void ProcessPendingRestyles();
-
-private:
-  // ProcessPendingRestyles calls into one of our RestyleTracker
-  // objects.  It then calls back to these functions at the beginning
-  // and end of its work.
-  void BeginProcessingRestyles(RestyleTracker& aRestyleTracker);
-  void EndProcessingRestyles();
-
-public:
-  // Update styles for animations that are running on the compositor and
-  // whose updating is suppressed on the main thread (to save
-  // unnecessary work), while leaving all other aspects of style
-  // out-of-date.
-  //
-  // Performs an animation-only style flush to make styles from
-  // throttled transitions up-to-date prior to processing an unrelated
-  // style change, so that any transitions triggered by that style
-  // change produce correct results.
-  //
-  // In more detail:  when we're able to run animations on the
-  // compositor, we sometimes "throttle" these animations by skipping
-  // updating style data on the main thread.  However, whenever we
-  // process a normal (non-animation) style change, any changes in
-  // computed style on elements that have transition-* properties set
-  // may need to trigger new transitions; this process requires knowing
-  // both the old and new values of the property.  To do this correctly,
-  // we need to have an up-to-date *old* value of the property on the
-  // primary frame.  So the purpose of the mini-flush is to update the
-  // style for all throttled transitions and animations to the current
-  // animation state without making any other updates, so that when we
-  // process the queued style updates we'll have correct old data to
-  // compare against.  When we do this, we don't bother touching frames
-  // other than primary frames.
-  void UpdateOnlyAnimationStyles();
-
-  // Rebuilds all style data by throwing out the old rule tree and
-  // building a new one, and additionally applying aExtraHint (which
-  // must not contain nsChangeHint_ReconstructFrame) to the root frame.
-  //
-  // aRestyleHint says which restyle hint to use for the computation;
-  // the only sensible values to use are eRestyle_Subtree (which says
-  // that the rebuild must run selector matching) and nsRestyleHint(0)
-  // (which says that rerunning selector matching is not required.  (The
-  // method adds eRestyle_ForceDescendants internally, and including it
-  // in the restyle hint is harmless; some callers (e.g.,
-  // nsPresContext::MediaFeatureValuesChanged) might do this for their
-  // own reasons.)
-  void RebuildAllStyleData(nsChangeHint aExtraHint,
-                           nsRestyleHint aRestyleHint);
-
-  /**
-   * Notify the frame constructor that an element needs to have its
-   * style recomputed.
-   * @param aElement: The element to be restyled.
-   * @param aRestyleHint: Which nodes need to have selector matching run
-   *                      on them.
-   * @param aMinChangeHint: A minimum change hint for aContent and its
-   *                        descendants.
-   * @param aRestyleHintData: Additional data to go with aRestyleHint.
-   */
-  void PostRestyleEvent(Element* aElement,
-                        nsRestyleHint aRestyleHint,
-                        nsChangeHint aMinChangeHint,
-                        const RestyleHintData* aRestyleHintData = nullptr);
-
-public:
-  /**
-   * Asynchronously clear style data from the root frame downwards and ensure
-   * it will all be rebuilt. This is safe to call anytime; it will schedule
-   * a restyle and take effect next time style changes are flushed.
-   * This method is used to recompute the style data when some change happens
-   * outside of any style rules, like a color preference change or a change
-   * in a system font size, or to fix things up when an optimization in the
-   * style data has become invalid. We assume that the root frame will not
-   * need to be reframed.
-   *
-   * For parameters, see RebuildAllStyleData.
-   */
-  void PostRebuildAllStyleDataEvent(nsChangeHint aExtraHint,
-                                    nsRestyleHint aRestyleHint);
-
-#ifdef DEBUG
-  bool InRebuildAllStyleData() const { return mInRebuildAllStyleData; }
-#endif
-
-#ifdef RESTYLE_LOGGING
-  /**
-   * Returns whether a restyle event currently being processed by this
-   * GeckoRestyleManager should be logged.
-   */
-  bool ShouldLogRestyle() {
-    return ShouldLogRestyle(PresContext());
-  }
-
-  /**
-   * Returns whether a restyle event currently being processed for the
-   * document with the specified nsPresContext should be logged.
-   */
-  static bool ShouldLogRestyle(nsPresContext* aPresContext) {
-    return aPresContext->RestyleLoggingEnabled() &&
-           (!aPresContext->TransitionManager()->
-               InAnimationOnlyStyleUpdate() ||
-            AnimationRestyleLoggingEnabled());
-  }
-
-  static bool RestyleLoggingInitiallyEnabled() {
-    static bool enabled = getenv("MOZ_DEBUG_RESTYLE") != 0;
-    return enabled;
-  }
-
-  static bool AnimationRestyleLoggingEnabled() {
-    static bool animations = getenv("MOZ_DEBUG_RESTYLE_ANIMATIONS") != 0;
-    return animations;
-  }
-
-  // Set MOZ_DEBUG_RESTYLE_STRUCTS to a comma-separated string of
-  // style struct names -- such as "Font,SVGReset" -- to log the style context
-  // tree and those cached struct pointers before each restyle.  This
-  // function returns a bitfield of the structs named in the
-  // environment variable.
-  static uint32_t StructsToLog();
-
-  static nsCString StructNamesToString(uint32_t aSIDs);
-  int32_t& LoggingDepth() { return mLoggingDepth; }
-#endif
-
-  bool IsProcessingRestyles() { return mIsProcessingRestyles; }
-  bool HasPendingRestyles() const;
-
-private:
-  inline nsStyleSet* StyleSet() const {
-    MOZ_ASSERT(PresContext()->StyleSet()->IsGecko(),
-               "GeckoRestyleManager should only be used with a Gecko-flavored "
-               "style backend");
-    return PresContext()->StyleSet()->AsGecko();
-  }
-
-  /* aMinHint is the minimal change that should be made to the element */
-  // XXXbz do we really need the aPrimaryFrame argument here?
-  void RestyleElement(Element*        aElement,
-                      nsIFrame*       aPrimaryFrame,
-                      nsChangeHint    aMinHint,
-                      RestyleTracker& aRestyleTracker,
-                      nsRestyleHint   aRestyleHint,
-                      const RestyleHintData& aRestyleHintData);
-
-  void StartRebuildAllStyleData(RestyleTracker& aRestyleTracker);
-  void FinishRebuildAllStyleData();
-
-  bool ShouldStartRebuildAllFor(RestyleTracker& aRestyleTracker) {
-    // When we process our primary restyle tracker and we have a pending
-    // rebuild-all, we need to process it.
-    return mDoRebuildAllStyleData &&
-           &aRestyleTracker == &mPendingRestyles;
-  }
-
-  void ProcessRestyles(RestyleTracker& aRestyleTracker) {
-    // Fast-path the common case (esp. for the animation restyle
-    // tracker) of not having anything to do.
-    if (aRestyleTracker.Count() || ShouldStartRebuildAllFor(aRestyleTracker)) {
-      IncrementRestyleGeneration();
-      aRestyleTracker.DoProcessRestyles();
-    }
-  }
-
-private:
-  // True if we need to reconstruct the rule tree the next time we
-  // process restyles.
-  bool mDoRebuildAllStyleData : 1;
-  // True if we're currently in the process of reconstructing the rule tree.
-  bool mInRebuildAllStyleData : 1;
-  // Whether rule matching should skip styles associated with animation
-  bool mSkipAnimationRules : 1;
-  bool mHavePendingNonAnimationRestyles : 1;
-
-  nsChangeHint mRebuildAllExtraHint;
-  nsRestyleHint mRebuildAllRestyleHint;
-
-  ReframingStyleContexts* mReframingStyleContexts;
-
-  RestyleTracker mPendingRestyles;
-
-  // Are we currently in the middle of a call to ProcessRestyles?
-  // This flag is used both as a debugging aid to assert that we are not
-  // performing nested calls to ProcessPendingRestyles, as well as to ignore
-  // redundant calls to IncrementAnimationGeneration.
-  bool mIsProcessingRestyles;
-
-#ifdef RESTYLE_LOGGING
-  int32_t mLoggingDepth;
-#endif
-};
-
-/**
- * An ElementRestyler is created for *each* element in a subtree that we
- * recompute styles for.
- */
-class ElementRestyler final
-{
-public:
-  typedef mozilla::dom::Element Element;
-
-  struct ContextToClear {
-    RefPtr<GeckoStyleContext> mStyleContext;
-    uint32_t mStructs;
-  };
-
-  // Construct for the root of the subtree that we're restyling.
-  ElementRestyler(nsPresContext* aPresContext,
-                  nsIFrame* aFrame,
-                  nsStyleChangeList* aChangeList,
-                  nsChangeHint aHintsHandledByAncestors,
-                  RestyleTracker& aRestyleTracker,
-                  nsTArray<nsCSSSelector*>& aSelectorsForDescendants,
-                  TreeMatchContext& aTreeMatchContext,
-                  nsTArray<nsIContent*>& aVisibleKidsOfHiddenElement,
-                  nsTArray<ContextToClear>& aContextsToClear,
-                  nsTArray<RefPtr<GeckoStyleContext>>& aSwappedStructOwners);
-
-  // Construct for an element whose parent is being restyled.
-  enum ConstructorFlags {
-    FOR_OUT_OF_FLOW_CHILD = 1<<0
-  };
-  ElementRestyler(const ElementRestyler& aParentRestyler,
-                  nsIFrame* aFrame,
-                  uint32_t aConstructorFlags);
-
-  // Construct for a frame whose parent is being restyled, but whose
-  // style context is the parent style context for its parent frame.
-  // (This is only used for table frames, whose style contexts are used
-  // as the parent style context for their table wrapper frame. We should
-  // probably try to get rid of this exception and have the inheritance go
-  // the other way.)
-  enum ParentContextFromChildFrame { PARENT_CONTEXT_FROM_CHILD_FRAME };
-  ElementRestyler(ParentContextFromChildFrame,
-                  const ElementRestyler& aParentFrameRestyler,
-                  nsIFrame* aFrame);
-
-  // For restyling undisplayed content only (mFrame==null).
-  ElementRestyler(nsPresContext* aPresContext,
-                  nsIContent* aContent,
-                  nsStyleChangeList* aChangeList,
-                  nsChangeHint aHintsHandledByAncestors,
-                  RestyleTracker& aRestyleTracker,
-                  nsTArray<nsCSSSelector*>& aSelectorsForDescendants,
-                  TreeMatchContext& aTreeMatchContext,
-                  nsTArray<nsIContent*>& aVisibleKidsOfHiddenElement,
-                  nsTArray<ContextToClear>& aContextsToClear,
-                  nsTArray<RefPtr<GeckoStyleContext>>& aSwappedStructOwners);
-
-  /**
-   * Restyle our frame's element and its subtree.
-   *
-   * Use eRestyle_Self for the aRestyleHint argument to mean
-   * "reresolve our style context but not kids", use eRestyle_Subtree
-   * to mean "reresolve our style context and kids", and use
-   * nsRestyleHint(0) to mean recompute a new style context for our
-   * current parent and existing rulenode, and the same for kids.
-   */
-  void Restyle(nsRestyleHint aRestyleHint);
-
-  /**
-   * mHintsHandledBySelf changes over time; it starts off as nsChangeHint(0),
-   * and by the end of Restyle it represents the hints that have been handled
-   * for this frame.  This method is intended to be called after Restyle, to
-   * find out what hints have been handled for this frame.
-   */
-  nsChangeHint HintsHandledForFrame() { return mHintsHandledBySelf; }
-
-  /**
-   * Called from GeckoRestyleManager::ComputeAndProcessStyleChange to restyle
-   * children of a display:contents element.
-   */
-  void RestyleChildrenOfDisplayContentsElement(nsIFrame*       aParentFrame,
-                                               GeckoStyleContext* aNewContext,
-                                               nsChangeHint    aMinHint,
-                                               RestyleTracker& aRestyleTracker,
-                                               nsRestyleHint   aRestyleHint,
-                                               const RestyleHintData&
-                                                 aRestyleHintData);
-
-  /**
-   * Re-resolve the style contexts for a frame tree, building aChangeList
-   * based on the resulting style changes, plus aMinChange applied to aFrame.
-   */
-  static void ComputeStyleChangeFor(nsIFrame*          aFrame,
-                                    nsStyleChangeList* aChangeList,
-                                    nsChangeHint       aMinChange,
-                                    RestyleTracker&    aRestyleTracker,
-                                    nsRestyleHint      aRestyleHint,
-                                    const RestyleHintData& aRestyleHintData,
-                                    nsTArray<ContextToClear>& aContextsToClear,
-                                    nsTArray<RefPtr<GeckoStyleContext>>&
-                                      aSwappedStructOwners);
-
-#ifdef RESTYLE_LOGGING
-  bool ShouldLogRestyle() {
-    return GeckoRestyleManager::ShouldLogRestyle(mPresContext);
-  }
-#endif
-
-private:
-  inline nsStyleSet* StyleSet() const;
-
-  // Enum class for the result of RestyleSelf, which indicates whether the
-  // restyle procedure should continue to the children, and how.
-  //
-  // These values must be ordered so that later values imply that all
-  // the work of the earlier values is also done.
-  enum class RestyleResult : uint8_t {
-    // default initial value
-    eNone,
-
-    // we left the old style context on the frame; do not restyle children
-    eStop,
-
-    // we got a new style context on this frame, but we know that children
-    // do not depend on the changed values; do not restyle children
-    eStopWithStyleChange,
-
-    // continue restyling children
-    eContinue,
-
-    // continue restyling children with eRestyle_ForceDescendants set
-    eContinueAndForceDescendants
-  };
-
-  struct SwapInstruction
-  {
-    RefPtr<GeckoStyleContext> mOldContext;
-    RefPtr<GeckoStyleContext> mNewContext;
-    uint32_t mStructsToSwap;
-  };
-
-  /**
-   * First half of Restyle().
-   */
-  RestyleResult RestyleSelf(nsIFrame* aSelf,
-                            nsRestyleHint aRestyleHint,
-                            uint32_t* aSwappedStructs,
-                            nsTArray<SwapInstruction>& aSwaps);
-
-  /**
-   * Restyle the children of this frame (and, in turn, their children).
-   *
-   * Second half of Restyle().
-   */
-  void RestyleChildren(nsRestyleHint aChildRestyleHint);
-
-  /**
-   * Returns true iff a selector in mSelectorsForDescendants matches aElement.
-   * This is called when processing a eRestyle_SomeDescendants restyle hint.
-   */
-  bool SelectorMatchesForRestyle(Element* aElement);
-
-  /**
-   * Returns true iff aRestyleHint indicates that we should be restyling.
-   * Specifically, this will return true when eRestyle_Self or
-   * eRestyle_Subtree is present, or if eRestyle_SomeDescendants is
-   * present and the specified element matches one of the selectors in
-   * mSelectorsForDescendants.
-   */
-  bool MustRestyleSelf(nsRestyleHint aRestyleHint, Element* aElement);
-
-  /**
-   * Returns true iff aRestyleHint indicates that we can call
-   * ReparentStyleContext rather than any other restyling method of
-   * nsStyleSet that looks up a new rule node, and if we are
-   * not in the process of reconstructing the whole rule tree.
-   * This is used to check whether it is appropriate to call
-   * ReparentStyleContext.
-   */
-  bool CanReparentStyleContext(nsRestyleHint aRestyleHint);
-
-  /**
-   * Helpers for Restyle().
-   */
-  bool MoveStyleContextsForContentChildren(nsIFrame* aParent,
-                                           GeckoStyleContext* aOldContext,
-                                           nsTArray<GeckoStyleContext*>& aContextsToMove);
-  bool MoveStyleContextsForChildren(GeckoStyleContext* aOldContext);
-
-  /**
-   * Helpers for RestyleSelf().
-   */
-  void CaptureChange(GeckoStyleContext* aOldContext,
-                     GeckoStyleContext* aNewContext,
-                     nsChangeHint aChangeToAssume,
-                     uint32_t* aEqualStructs,
-                     uint32_t* aSamePointerStructs);
-  void ComputeRestyleResultFromFrame(nsIFrame* aSelf,
-                                     RestyleResult& aRestyleResult,
-                                     bool& aCanStopWithStyleChange);
-  void ComputeRestyleResultFromNewContext(nsIFrame* aSelf,
-                                          GeckoStyleContext* aNewContext,
-                                          RestyleResult& aRestyleResult,
-                                          bool& aCanStopWithStyleChange);
-
-  // Helpers for RestyleChildren().
-  void RestyleUndisplayedDescendants(nsRestyleHint aChildRestyleHint);
-  bool MustCheckUndisplayedContent(nsIFrame* aFrame,
-                                   nsIContent*& aUndisplayedParent);
-
-  /**
-   * In the following two methods, aParentStyleContext is either
-   * mFrame->StyleContext() if we have a frame, or a display:contents
-   * style context if we don't.
-   */
-  void DoRestyleUndisplayedDescendants(nsRestyleHint aChildRestyleHint,
-                                       nsIContent* aParent,
-                                       GeckoStyleContext* aParentStyleContext);
-  void RestyleUndisplayedNodes(nsRestyleHint      aChildRestyleHint,
-                               UndisplayedNode*   aUndisplayed,
-                               nsIContent*        aUndisplayedParent,
-                               GeckoStyleContext*    aParentStyleContext,
-                               const StyleDisplay aDisplay);
-  void MaybeReframeForBeforePseudo();
-  void MaybeReframeForAfterPseudo(nsIFrame* aFrame);
-  void MaybeReframeForPseudo(CSSPseudoElementType aPseudoType,
-                             nsIFrame* aGenConParentFrame,
-                             nsIFrame* aFrame,
-                             nsIContent* aContent,
-                             GeckoStyleContext* aStyleContext);
-#ifdef DEBUG
-  bool MustReframeForBeforePseudo();
-  bool MustReframeForAfterPseudo(nsIFrame* aFrame);
-#endif
-  bool MustReframeForPseudo(CSSPseudoElementType aPseudoType,
-                            nsIFrame* aGenConParentFrame,
-                            nsIFrame* aFrame,
-                            nsIContent* aContent,
-                            GeckoStyleContext* aStyleContext);
-  void RestyleContentChildren(nsIFrame* aParent,
-                              nsRestyleHint aChildRestyleHint);
-  void InitializeAccessibilityNotifications(nsStyleContext* aNewContext);
-  void SendAccessibilityNotifications();
-
-  enum DesiredA11yNotifications {
-    eSkipNotifications,
-    eSendAllNotifications,
-    eNotifyIfShown
-  };
-
-  enum A11yNotificationType {
-    eDontNotify,
-    eNotifyShown,
-    eNotifyHidden
-  };
-
-  // These methods handle the eRestyle_SomeDescendants hint by traversing
-  // down the frame tree (and then when reaching undisplayed content,
-  // the flattened content tree) find elements that match a selector
-  // in mSelectorsForDescendants and call AddPendingRestyle for them.
-  void ConditionallyRestyleChildren();
-  void ConditionallyRestyleChildren(nsIFrame* aFrame,
-                                    Element* aRestyleRoot);
-  void ConditionallyRestyleContentChildren(nsIFrame* aFrame,
-                                           Element* aRestyleRoot);
-  void ConditionallyRestyleUndisplayedDescendants(nsIFrame* aFrame,
-                                                  Element* aRestyleRoot);
-  void DoConditionallyRestyleUndisplayedDescendants(nsIContent* aParent,
-                                                    Element* aRestyleRoot);
-  void ConditionallyRestyleUndisplayedNodes(UndisplayedNode* aUndisplayed,
-                                            nsIContent* aUndisplayedParent,
-                                            const StyleDisplay aDisplay,
-                                            Element* aRestyleRoot);
-  void ConditionallyRestyleContentDescendants(Element* aElement,
-                                              Element* aRestyleRoot);
-  bool ConditionallyRestyle(nsIFrame* aFrame, Element* aRestyleRoot);
-  bool ConditionallyRestyle(Element* aElement, Element* aRestyleRoot);
-
-#ifdef RESTYLE_LOGGING
-  int32_t& LoggingDepth() { return mLoggingDepth; }
-#endif
-
-#ifdef DEBUG
-  static nsCString RestyleResultToString(RestyleResult aRestyleResult);
-#endif
-
-private:
-  nsPresContext* const mPresContext;
-  nsIFrame* const mFrame;
-  nsIContent* const mParentContent;
-  // |mContent| is the node that we used for rule matching of
-  // normal elements (not pseudo-elements) and for which we generate
-  // framechange hints if we need them.
-  nsIContent* const mContent;
-  nsStyleChangeList* const mChangeList;
-  // Hints that we computed on an ancestor (and which we already have
-  // generated a change list entry for).  When we traverse to children
-  // after restyling an element, this field accumulates the hints
-  // generated for that element.
-  const nsChangeHint mHintsHandledByAncestors;
-  // Hints that we have computed so far the current node.  This is
-  // initially zero, and accumulates hints for each same-style continuation
-  // and {ib} split sibling we restyle for the node.
-  nsChangeHint mHintsHandledBySelf;
-  RestyleTracker& mRestyleTracker;
-  nsTArray<nsCSSSelector*>& mSelectorsForDescendants;
-  TreeMatchContext& mTreeMatchContext;
-  nsIFrame* mResolvedChild; // child that provides our parent style context
-  // Array of style context subtrees in which we need to clear out cached
-  // structs at the end of the restyle (after change hints have been
-  // processed).
-  nsTArray<ContextToClear>& mContextsToClear;
-  // Style contexts that had old structs swapped into it and which should
-  // stay alive until the end of the restyle.  (See comment in
-  // ElementRestyler::Restyle.)
-  nsTArray<RefPtr<GeckoStyleContext>>& mSwappedStructOwners;
-  // Whether this is the root of the restyle.
-  bool mIsRootOfRestyle;
-
-#ifdef ACCESSIBILITY
-  const DesiredA11yNotifications mDesiredA11yNotifications;
-  DesiredA11yNotifications mKidsDesiredA11yNotifications;
-  A11yNotificationType mOurA11yNotification;
-  nsTArray<nsIContent*>& mVisibleKidsOfHiddenElement;
-  bool mWasFrameVisible;
-#endif
-
-#ifdef RESTYLE_LOGGING
-  int32_t mLoggingDepth;
-#endif
-};
-
-/**
- * This pushes any display:contents nodes onto a TreeMatchContext.
- * Use it before resolving style for kids of aParent where aParent
- * (and further ancestors) may be display:contents nodes which have
- * not yet been pushed onto TreeMatchContext.
- */
-class MOZ_RAII AutoDisplayContentsAncestorPusher final
-{
- public:
-  typedef mozilla::dom::Element Element;
-  AutoDisplayContentsAncestorPusher(TreeMatchContext& aTreeMatchContext,
-                                    nsPresContext*    aPresContext,
-                                    nsIContent*       aParent);
-  ~AutoDisplayContentsAncestorPusher();
-  bool IsEmpty() const { return mAncestors.Length() == 0; }
-private:
-  TreeMatchContext& mTreeMatchContext;
-  nsPresContext* const mPresContext;
-  AutoTArray<mozilla::dom::Element*, 4> mAncestors;
-};
-
-} // namespace mozilla
-
-#endif /* mozilla_GeckoRestyleManager_h */
deleted file mode 100644
--- a/layout/base/RestyleTracker.cpp
+++ /dev/null
@@ -1,485 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/**
- * A class which manages pending restyles.  This handles keeping track
- * of what nodes restyles need to happen on and so forth.
- */
-
-#include "RestyleTracker.h"
-
-#include "GeckoProfiler.h"
-#include "nsCSSFrameConstructor.h"
-#include "nsIContentInlines.h"
-#include "nsIDocument.h"
-#include "nsStyleChangeList.h"
-#include "mozilla/dom/ElementInlines.h"
-#include "mozilla/GeckoRestyleManager.h"
-#include "RestyleTrackerInlines.h"
-#include "nsTransitionManager.h"
-#include "mozilla/AutoRestyleTimelineMarker.h"
-
-namespace mozilla {
-
-#ifdef RESTYLE_LOGGING
-static nsCString
-GetDocumentURI(nsIDocument* aDocument)
-{
-  nsCString result;
-  nsAutoString url;
-  nsresult rv = aDocument->GetDocumentURI(url);
-  if (NS_SUCCEEDED(rv)) {
-    result.Append(NS_ConvertUTF16toUTF8(url).get());
-  }
-
-  return result;
-}
-
-static nsCString
-FrameTagToString(dom::Element* aElement)
-{
-  nsCString result;
-  nsIFrame* frame = aElement->GetPrimaryFrame();
-  if (frame) {
-    nsFrame::ListTag(result, frame);
-  } else {
-    nsAutoString buf;
-    aElement->NodeInfo()->NameAtom()->ToString(buf);
-    result.AppendPrintf("(%s@%p)", NS_ConvertUTF16toUTF8(buf).get(), aElement);
-  }
-  return result;
-}
-#endif
-
-inline nsIDocument*
-RestyleTracker::Document() const {
-  return mRestyleManager->PresContext()->Document();
-}
-
-#define RESTYLE_ARRAY_STACKSIZE 128
-
-struct RestyleEnumerateData : RestyleTracker::Hints {
-  RefPtr<dom::Element> mElement;
-#ifdef MOZ_GECKO_PROFILER
-  UniqueProfilerBacktrace mBacktrace;
-#endif
-};
-
-inline void
-RestyleTracker::ProcessOneRestyle(Element* aElement,
-                                  nsRestyleHint aRestyleHint,
-                                  nsChangeHint aChangeHint,
-                                  const RestyleHintData& aRestyleHintData)
-{
-  NS_PRECONDITION((aRestyleHint & eRestyle_LaterSiblings) == 0,
-                  "Someone should have handled this before calling us");
-  NS_PRECONDITION(Document(), "Must have a document");
-  NS_PRECONDITION(aElement->GetComposedDoc() == Document(),
-                  "Element has unexpected document");
-
-  LOG_RESTYLE("aRestyleHint = %s, aChangeHint = %s",
-              GeckoRestyleManager::RestyleHintToString(aRestyleHint).get(),
-              GeckoRestyleManager::ChangeHintToString(aChangeHint).get());
-
-  nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
-
-  if (aRestyleHint & ~eRestyle_LaterSiblings) {
-#ifdef RESTYLE_LOGGING
-    if (ShouldLogRestyle() && primaryFrame &&
-        GeckoRestyleManager::StructsToLog() != 0) {
-      LOG_RESTYLE("style context tree before restyle:");
-      LOG_RESTYLE_INDENT();
-      primaryFrame->StyleContext()->AsGecko()->LogStyleContextTree(
-          LoggingDepth(), GeckoRestyleManager::StructsToLog());
-    }
-#endif
-    mRestyleManager->RestyleElement(aElement, primaryFrame, aChangeHint,
-                                    *this, aRestyleHint, aRestyleHintData);
-  } else if (aChangeHint &&
-             (primaryFrame ||
-              (aChangeHint & nsChangeHint_ReconstructFrame))) {
-    // Don't need to recompute style; just apply the hint
-    nsStyleChangeList changeList(StyleBackendType::Gecko);
-    changeList.AppendChange(primaryFrame, aElement, aChangeHint);
-    mRestyleManager->ProcessRestyledFrames(changeList);
-  }
-}
-
-void
-RestyleTracker::DoProcessRestyles()
-{
-#ifdef MOZ_GECKO_PROFILER
-  nsAutoCString docURL("N/A");
-  if (profiler_is_active()) {
-    nsIURI *uri = Document()->GetDocumentURI();
-    if (uri) {
-      docURL = uri->GetSpecOrDefault();
-    }
-  }
-  AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING(
-    "RestyleTracker::DoProcessRestyles", CSS, docURL);
-#endif
-
-  // Create a AnimationsWithDestroyedFrame during restyling process to
-  // stop animations and transitions on elements that have no frame at the end
-  // of the restyling process.
-  RestyleManager::AnimationsWithDestroyedFrame
-    animationsWithDestroyedFrame(mRestyleManager);
-
-  // Create a ReframingStyleContexts struct on the stack and put it in our
-  // mReframingStyleContexts for almost all of the remaining scope of
-  // this function.
-  //
-  // It needs to be *in* scope during BeginProcessingRestyles, which
-  // might (if mDoRebuildAllStyleData is true) do substantial amounts of
-  // restyle processing.
-  //
-  // However, it needs to be *out* of scope during
-  // EndProcessingRestyles, since we should release the style contexts
-  // it holds prior to any EndReconstruct call that
-  // EndProcessingRestyles makes.  This is because in EndReconstruct we
-  // try to destroy the old rule tree using the GC mechanism, which
-  // means it only gets destroyed if it's unreferenced (and if it's
-  // referenced, we assert).  So we want the ReframingStyleContexts
-  // (which holds old style contexts) to be destroyed before the
-  // EndReconstruct so those style contexts go away before
-  // EndReconstruct.
-  {
-    GeckoRestyleManager::ReframingStyleContexts
-      reframingStyleContexts(mRestyleManager);
-
-    mRestyleManager->BeginProcessingRestyles(*this);
-
-    LOG_RESTYLE("Processing %d pending %srestyles with %d restyle roots for %s",
-                mPendingRestyles.Count(),
-                mRestyleManager->PresContext()->TransitionManager()->
-                  InAnimationOnlyStyleUpdate()
-                  ? (const char*) "animation " : (const char*) "",
-                static_cast<int>(mRestyleRoots.Length()),
-                GetDocumentURI(Document()).get());
-    LOG_RESTYLE_INDENT();
-
-    // loop so that we process any restyle events generated by processing
-    while (mPendingRestyles.Count()) {
-      if (mHaveLaterSiblingRestyles) {
-        // Convert them to individual restyles on all the later siblings
-        AutoTArray<RefPtr<Element>, RESTYLE_ARRAY_STACKSIZE> laterSiblingArr;
-        for (auto iter = mPendingRestyles.Iter(); !iter.Done(); iter.Next()) {
-          auto element = static_cast<dom::Element*>(iter.Key());
-          MOZ_ASSERT(!element->IsStyledByServo(),
-                     "Should not have Servo-styled elements here");
-          // Only collect the entries that actually need restyling by us (and
-          // haven't, for example, already been restyled).
-          // It's important to not mess with the flags on entries not in our
-          // document.
-          if (element->GetComposedDoc() == Document() &&
-              element->HasFlag(RestyleBit()) &&
-              (iter.Data()->mRestyleHint & eRestyle_LaterSiblings)) {
-            laterSiblingArr.AppendElement(element);
-          }
-        }
-        for (uint32_t i = 0; i < laterSiblingArr.Length(); ++i) {
-          Element* element = laterSiblingArr[i];
-          MOZ_ASSERT(!element->IsStyledByServo());
-          for (nsIContent* sibling = element->GetNextSibling();
-               sibling;
-               sibling = sibling->GetNextSibling()) {
-            if (sibling->IsElement()) {
-              LOG_RESTYLE("adding pending restyle for %s due to "
-                          "eRestyle_LaterSiblings hint on %s",
-                          FrameTagToString(sibling->AsElement()).get(),
-                          FrameTagToString(element->AsElement()).get());
-              if (AddPendingRestyle(sibling->AsElement(), eRestyle_Subtree,
-                                    nsChangeHint(0))) {
-                  // Nothing else to do here; we'll handle the following
-                  // siblings when we get to |sibling| in laterSiblingArr.
-                break;
-              }
-            }
-          }
-        }
-
-        // Now remove all those eRestyle_LaterSiblings bits
-        for (uint32_t i = 0; i < laterSiblingArr.Length(); ++i) {
-          Element* element = laterSiblingArr[i];
-          NS_ASSERTION(element->HasFlag(RestyleBit()), "How did that happen?");
-          RestyleData* data;
-#ifdef DEBUG
-          bool found =
-#endif
-            mPendingRestyles.Get(element, &data);
-          NS_ASSERTION(found, "Where did our entry go?");
-          data->mRestyleHint =
-            nsRestyleHint(data->mRestyleHint & ~eRestyle_LaterSiblings);
-
-          if (Element* parent = element->GetFlattenedTreeParentElement()) {
-            parent->UnsetFlags(ELEMENT_HAS_CHILD_WITH_LATER_SIBLINGS_HINT);
-          }
-        }
-
-        LOG_RESTYLE("%d pending restyles after expanding out "
-                    "eRestyle_LaterSiblings", mPendingRestyles.Count());
-
-        mHaveLaterSiblingRestyles = false;
-      }
-
-      uint32_t rootCount;
-      while ((rootCount = mRestyleRoots.Length())) {
-        // Make sure to pop the element off our restyle root array, so
-        // that we can freely append to the array as we process this
-        // element.
-        RefPtr<Element> element;
-        element.swap(mRestyleRoots[rootCount - 1]);
-        mRestyleRoots.RemoveElementAt(rootCount - 1);
-
-        LOG_RESTYLE("processing style root %s at index %d",
-                    FrameTagToString(element).get(), rootCount - 1);
-        LOG_RESTYLE_INDENT();
-
-        // Do the document check before calling GetRestyleData, since we
-        // don't want to do the sibling-processing GetRestyleData does if
-        // the node is no longer relevant.
-        if (element->GetComposedDoc() != Document()) {
-          // Content node has been removed from our document; nothing else
-          // to do here
-          LOG_RESTYLE("skipping, no longer in the document");
-          continue;
-        }
-
-        nsAutoPtr<RestyleData> data;
-        if (!GetRestyleData(element, data)) {
-          LOG_RESTYLE("skipping, already restyled");
-          continue;
-        }
-
-        {
-          AutoRestyleTimelineMarker marker(
-            mRestyleManager->PresContext()->GetDocShell(),
-            data->mRestyleHint & eRestyle_AllHintsWithAnimations);
-#ifdef MOZ_GECKO_PROFILER
-          Maybe<AutoProfilerTracing> tracing;
-          if (profiler_feature_active(ProfilerFeature::Restyle)) {
-            tracing.emplace("Paint", "Styles", Move(data->mBacktrace));
-          }
-#endif
-          ProcessOneRestyle(element, data->mRestyleHint, data->mChangeHint,
-                            data->mRestyleHintData);
-          AddRestyleRootsIfAwaitingRestyle(data->mDescendants);
-        }
-      }
-
-      if (mHaveLaterSiblingRestyles) {
-        // Keep processing restyles for now
-        continue;
-      }
-
-      // Now we only have entries with change hints left.  To be safe in
-      // case of reentry from the handing of the change hint, use a
-      // scratch array instead of calling out to ProcessOneRestyle while
-      // enumerating the hashtable.  Use the stack if we can, otherwise
-      // fall back on heap-allocation.
-      AutoTArray<RestyleEnumerateData, RESTYLE_ARRAY_STACKSIZE> restyleArr;
-      RestyleEnumerateData* restylesToProcess =
-        restyleArr.AppendElements(mPendingRestyles.Count());
-      if (restylesToProcess) {
-        RestyleEnumerateData* restyle = restylesToProcess;
-#ifdef RESTYLE_LOGGING
-        uint32_t count = 0;
-#endif
-        for (auto iter = mPendingRestyles.Iter(); !iter.Done(); iter.Next()) {
-          auto element = static_cast<dom::Element*>(iter.Key());
-          RestyleTracker::RestyleData* data = iter.Data();
-
-          // Only collect the entries that actually need restyling by us (and
-          // haven't, for example, already been restyled).
-          // It's important to not mess with the flags on entries not in our
-          // document.
-          if (element->GetComposedDoc() != Document() ||
-              !element->HasFlag(RestyleBit())) {
-            LOG_RESTYLE("skipping pending restyle %s, already restyled or no "
-                        "longer in the document",
-                        FrameTagToString(element).get());
-            continue;
-          }
-
-          NS_ASSERTION(
-            !element->HasFlag(RootBit()) ||
-            // Maybe we're just not reachable via the frame tree?
-            (element->GetFlattenedTreeParent() &&
-             (!element->GetFlattenedTreeParent()->GetPrimaryFrame() ||
-              element->GetFlattenedTreeParent()->GetPrimaryFrame()->IsLeaf() ||
-              element->GetComposedDoc()->GetShell()->FrameConstructor()
-                ->GetDisplayContentsStyleFor(element))) ||
-            // Or not reachable due to an async reinsert we have
-            // pending?  If so, we'll have a reframe hint around.
-            // That incidentally makes it safe that we still have
-            // the bit, since any descendants that didn't get added
-            // to the roots list because we had the bits will be
-            // completely restyled in a moment.
-            (data->mChangeHint & nsChangeHint_ReconstructFrame),
-            "Why did this not get handled while processing mRestyleRoots?");
-
-          // Unset the restyle bits now, so if they get readded later as we
-          // process we won't clobber that adding of the bit.
-          element->UnsetFlags(RestyleBit() |
-                              RootBit() |
-                              ConditionalDescendantsBit());
-
-          restyle->mElement = element;
-          restyle->mRestyleHint = data->mRestyleHint;
-          restyle->mChangeHint = data->mChangeHint;
-          // We can move data since we'll be clearing mPendingRestyles after
-          // we finish enumerating it.
-          restyle->mRestyleHintData = Move(data->mRestyleHintData);
-#ifdef MOZ_GECKO_PROFILER
-          restyle->mBacktrace = Move(data->mBacktrace);
-#endif
-
-#ifdef RESTYLE_LOGGING
-          count++;
-#endif
-
-          // Increment to the next slot in the array
-          restyle++;
-        }
-
-        RestyleEnumerateData* lastRestyle = restyle;
-
-        // Clear the hashtable now that we don't need it anymore
-        mPendingRestyles.Clear();
-
-#ifdef RESTYLE_LOGGING
-        uint32_t index = 0;
-#endif
-        for (RestyleEnumerateData* currentRestyle = restylesToProcess;
-             currentRestyle != lastRestyle;
-             ++currentRestyle) {
-          LOG_RESTYLE("processing pending restyle %s at index %d/%d",
-                      FrameTagToString(currentRestyle->mElement).get(),
-                      index++, count);
-          LOG_RESTYLE_INDENT();
-
-#ifdef MOZ_GECKO_PROFILER
-          Maybe<AutoProfilerTracing> tracing;
-          if (profiler_feature_active(ProfilerFeature::Restyle)) {
-            tracing.emplace("Paint", "Styles",
-                            Move(currentRestyle->mBacktrace));
-          }
-#endif
-
-          {
-            AutoRestyleTimelineMarker marker(
-              mRestyleManager->PresContext()->GetDocShell(),
-              currentRestyle->mRestyleHint & eRestyle_AllHintsWithAnimations);
-            ProcessOneRestyle(currentRestyle->mElement,
-                              currentRestyle->mRestyleHint,
-                              currentRestyle->mChangeHint,
-                              currentRestyle->mRestyleHintData);
-          }
-        }
-      }
-    }
-  }
-
-  // mPendingRestyles is now empty.
-  mHaveSelectors = false;
-
-  mRestyleManager->EndProcessingRestyles();
-}
-
-bool
-RestyleTracker::GetRestyleData(Element* aElement, nsAutoPtr<RestyleData>& aData)
-{
-  NS_PRECONDITION(aElement->GetComposedDoc() == Document(),
-                  "Unexpected document; this will lead to incorrect behavior!");
-
-  if (!aElement->HasFlag(RestyleBit())) {
-    NS_ASSERTION(!aElement->HasFlag(RootBit()), "Bogus root bit?");
-    return false;
-  }
-
-  mPendingRestyles.Remove(aElement, &aData);
-  NS_ASSERTION(aData.get(), "Must have data if restyle bit is set");
-
-  if (aData->mRestyleHint & eRestyle_LaterSiblings) {
-    // Someone readded the eRestyle_LaterSiblings hint for this
-    // element.  Leave it around for now, but remove the other restyle
-    // hints and the change hint for it.  Also unset its root bit,
-    // since it's no longer a root with the new restyle data.
-
-    // During a normal restyle, we should have already processed the
-    // mDescendants array the last time we processed the restyle
-    // for this element.  But in RebuildAllStyleData, we don't initially
-    // expand out eRestyle_LaterSiblings, so we can get in here the
-    // first time we need to process a restyle for this element.  In that
-    // case, it's fine for us to have a non-empty mDescendants, since
-    // we know that RebuildAllStyleData adds eRestyle_ForceDescendants
-    // and we're guaranteed we'll restyle the entire tree.
-    NS_ASSERTION(mRestyleManager->InRebuildAllStyleData() ||
-                 aData->mDescendants.IsEmpty(),
-                 "expected descendants to be handled by now");
-
-    RestyleData* newData = new RestyleData;
-    newData->mChangeHint = nsChangeHint(0);
-    newData->mRestyleHint = eRestyle_LaterSiblings;
-    mPendingRestyles.Put(aElement, newData);
-    aElement->UnsetFlags(RootBit());
-    aData->mRestyleHint =
-      nsRestyleHint(aData->mRestyleHint & ~eRestyle_LaterSiblings);
-  } else {
-    aElement->UnsetFlags(mRestyleBits);
-  }
-
-  return true;
-}
-
-void
-RestyleTracker::AddRestyleRootsIfAwaitingRestyle(
-                                   const nsTArray<RefPtr<Element>>& aElements)
-{
-  // The RestyleData for a given element has stored in mDescendants
-  // the list of descendants we need to end up restyling.  Since we
-  // won't necessarily end up restyling them, due to the restyle
-  // process finishing early (see how RestyleResult::eStop is handled
-  // in ElementRestyler::Restyle), we add them to the list of restyle
-  // roots to handle the next time around the
-  // RestyleTracker::DoProcessRestyles loop.
-  //
-  // Note that aElements must maintain the same invariant
-  // that mRestyleRoots does, i.e. that ancestors appear after descendants.
-  // Since we call AddRestyleRootsIfAwaitingRestyle only after we have
-  // removed the restyle root we are currently processing from the end of
-  // mRestyleRoots, and the only elements we get here in aElements are
-  // descendants of that restyle root, we are safe to simply append to the
-  // end of mRestyleRoots to maintain its invariant.
-  for (size_t i = 0; i < aElements.Length(); i++) {
-    Element* element = aElements[i];
-    if (element->HasFlag(RestyleBit())) {
-      mRestyleRoots.AppendElement(element);
-    }
-  }
-}
-
-void
-RestyleTracker::ClearSelectors()
-{
-  if (!mHaveSelectors) {
-    return;
-  }
-  for (auto it = mPendingRestyles.Iter(); !it.Done(); it.Next()) {
-    RestyleData* data = it.Data();
-    if (data->mRestyleHint & eRestyle_SomeDescendants) {
-      data->mRestyleHint =
-        (data->mRestyleHint & ~eRestyle_SomeDescendants) | eRestyle_Subtree;
-      data->mRestyleHintData.mSelectorsForDescendants.Clear();
-    } else {
-      MOZ_ASSERT(data->mRestyleHintData.mSelectorsForDescendants.IsEmpty());
-    }
-  }
-  mHaveSelectors = false;
-}
-
-} // namespace mozilla
--- a/layout/base/moz.build
+++ b/layout/base/moz.build
@@ -83,21 +83,16 @@ EXPORTS.mozilla += [
     'RestyleManager.h',
     'RestyleManagerInlines.h',
     'ServoRestyleManager.h',
     'ShapeUtils.h',
     'StaticPresData.h',
     'UndisplayedNode.h',
 ]
 
-if CONFIG['MOZ_OLD_STYLE']:
-    EXPORTS.mozilla += [
-        'GeckoRestyleManager.h',
-    ]
-
 UNIFIED_SOURCES += [
     'AccessibleCaret.cpp',
     'AccessibleCaretEventHub.cpp',
     'AccessibleCaretManager.cpp',
     'GeometryUtils.cpp',
     'LayoutLogging.cpp',
     'MobileViewportManager.cpp',
     'nsBidi.cpp',
@@ -125,22 +120,16 @@ UNIFIED_SOURCES += [
     'ServoRestyleManager.cpp',
     'ShapeUtils.cpp',
     'StackArena.cpp',
     'StaticPresData.cpp',
     'TouchManager.cpp',
     'ZoomConstraintsClient.cpp',
 ]
 
-if CONFIG['MOZ_OLD_STYLE']:
-    UNIFIED_SOURCES += [
-        'GeckoRestyleManager.cpp',
-        'RestyleTracker.cpp',
-    ]
-
 # nsRefreshDriver.cpp needs to be built separately because of name clashes in the OS X headers
 SOURCES += [
     'nsRefreshDriver.cpp',
 ]
 
 if CONFIG['ENABLE_TESTS']:
     DIRS += ['gtest']
 
deleted file mode 100644
--- a/layout/style/CSSStyleSheet.cpp
+++ /dev/null
@@ -1,928 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* representation of a CSS style sheet */
-
-#include "mozilla/CSSStyleSheet.h"
-
-#include "nsAtom.h"
-#include "nsCSSRuleProcessor.h"
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/dom/Element.h"
-#include "mozilla/css/NameSpaceRule.h"
-#include "mozilla/css/GroupRule.h"
-#include "mozilla/css/ImportRule.h"
-#include "nsCSSRules.h"
-#include "nsMediaList.h"
-#include "nsIDocument.h"
-#include "nsPresContext.h"
-#include "nsGkAtoms.h"
-#include "nsQueryObject.h"
-#include "nsString.h"
-#include "nsStyleSet.h"
-#include "nsTArray.h"
-#include "mozilla/dom/CSSRuleList.h"
-#include "nsIDOMNode.h"
-#include "nsError.h"
-#include "nsCSSParser.h"
-#include "mozilla/css/Loader.h"
-#include "nsNameSpaceManager.h"
-#include "nsXMLNameSpaceMap.h"
-#include "nsCOMPtr.h"
-#include "nsContentUtils.h"
-#include "nsIScriptSecurityManager.h"
-#include "mozAutoDocUpdate.h"
-#include "nsMediaFeatures.h"
-#include "nsDOMClassInfoID.h"
-#include "mozilla/Likely.h"
-#include "nsComponentManagerUtils.h"
-#include "NullPrincipal.h"
-#include "mozilla/RuleProcessorCache.h"
-#include "nsIStyleSheetLinkingElement.h"
-#include "nsDOMWindowUtils.h"
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-// -------------------------------
-// Style Rule List for the DOM
-//
-class CSSRuleListImpl final : public CSSRuleList
-{
-public:
-  explicit CSSRuleListImpl(CSSStyleSheet *aStyleSheet);
-
-  virtual CSSStyleSheet* GetParentObject() override;
-
-  virtual css::Rule*
-  IndexedGetter(uint32_t aIndex, bool& aFound) override;
-  virtual uint32_t
-  Length() override;
-
-  void DropReference() { mStyleSheet = nullptr; }
-
-protected:
-  virtual ~CSSRuleListImpl();
-
-  CSSStyleSheet*  mStyleSheet;
-};
-
-CSSRuleListImpl::CSSRuleListImpl(CSSStyleSheet *aStyleSheet)
-{
-  // Not reference counted to avoid circular references.
-  // The style sheet will tell us when its going away.
-  mStyleSheet = aStyleSheet;
-}
-
-CSSRuleListImpl::~CSSRuleListImpl()
-{
-}
-
-CSSStyleSheet*
-CSSRuleListImpl::GetParentObject()
-{
-  return mStyleSheet;
-}
-
-uint32_t
-CSSRuleListImpl::Length()
-{
-  if (!mStyleSheet) {
-    return 0;
-  }
-
-  return AssertedCast<uint32_t>(mStyleSheet->StyleRuleCount());
-}
-
-css::Rule*
-CSSRuleListImpl::IndexedGetter(uint32_t aIndex, bool& aFound)
-{
-  aFound = false;
-
-  if (mStyleSheet) {
-    // ensure rules have correct parent
-    mStyleSheet->EnsureUniqueInner();
-    css::Rule* rule = mStyleSheet->GetStyleRuleAt(aIndex);
-    if (rule) {
-      aFound = true;
-      return rule;
-    }
-  }
-
-  // Per spec: "Return Value ... null if ... not a valid index."
-  return nullptr;
-}
-
-namespace mozilla {
-
-// -------------------------------
-// CSS Style Sheet Inner Data Container
-//
-
-
-CSSStyleSheetInner::CSSStyleSheetInner(CORSMode aCORSMode,
-                                       ReferrerPolicy aReferrerPolicy,
-                                       const SRIMetadata& aIntegrity)
-  : StyleSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity)
-{
-  MOZ_COUNT_CTOR(CSSStyleSheetInner);
-}
-
-bool
-CSSStyleSheet::RebuildChildList(css::Rule* aRule,
-                                ChildSheetListBuilder* aBuilder)
-{
-  int32_t type = aRule->GetType();
-  if (type < css::Rule::IMPORT_RULE) {
-    // Keep going till we get to the import rules.
-    return true;
-  }
-
-  if (type != css::Rule::IMPORT_RULE) {
-    // We're past all the import rules; stop the enumeration.
-    return false;
-  }
-
-  css::ImportRule* importRule = static_cast<css::ImportRule*>(aRule);
-  StyleSheet* sheet = importRule->GetStyleSheet();
-
-  if (!sheet) {
-    return true;
-  }
-
-  (*aBuilder->sheetSlot) = sheet;
-  aBuilder->SetParentLinks(*aBuilder->sheetSlot);
-  aBuilder->sheetSlot = &(*aBuilder->sheetSlot)->mNext;
-  return true;
-}
-
-size_t
-CSSStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
-{
-  size_t n = StyleSheet::SizeOfIncludingThis(aMallocSizeOf);
-  const CSSStyleSheet* s = this;
-  while (s) {
-    // Each inner can be shared by multiple sheets.  So we only count the inner
-    // if this sheet is the last one in the list of those sharing it.  As a
-    // result, the last such sheet takes all the blame for the memory
-    // consumption of the inner, which isn't ideal but it's better than
-    // double-counting the inner.  We use last instead of first since the first
-    // sheet may be held in the nsXULPrototypeCache and not used in a window at
-    // all.
-    if (s->Inner()->mSheets.LastElement() == s) {
-      n += s->Inner()->SizeOfIncludingThis(aMallocSizeOf);
-    }
-
-    // Measurement of the following members may be added later if DMD finds it
-    // is worthwhile:
-    // - s->mRuleCollection
-    // - s->mRuleProcessors
-    //
-    // The following members are not measured:
-    // - s->mOwnerRule, because it's non-owning
-
-    s = s->mNext ? s->mNext->AsGecko() : nullptr;
-  }
-  return n;
-}
-
-CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
-                                       CSSStyleSheet* aPrimarySheet)
-  : StyleSheetInfo(aCopy, aPrimarySheet)
-{
-  MOZ_COUNT_CTOR(CSSStyleSheetInner);
-  for (css::Rule* rule : aCopy.mOrderedRules) {
-    RefPtr<css::Rule> clone = rule->Clone();
-    mOrderedRules.AppendObject(clone);
-    clone->SetStyleSheet(aPrimarySheet);
-  }
-
-  StyleSheet::ChildSheetListBuilder builder = { &mFirstChild, aPrimarySheet };
-  for (css::Rule* rule : mOrderedRules) {
-    if (!CSSStyleSheet::RebuildChildList(rule, &builder)) {
-      break;
-    }
-  }
-
-  RebuildNameSpaces();
-}
-
-CSSStyleSheetInner::~CSSStyleSheetInner()
-{
-  MOZ_COUNT_DTOR(CSSStyleSheetInner);
-  for (css::Rule* rule : mOrderedRules) {
-    rule->SetStyleSheet(nullptr);
-  }
-}
-
-StyleSheetInfo*
-CSSStyleSheetInner::CloneFor(StyleSheet* aPrimarySheet)
-{
-  return new CSSStyleSheetInner(*this,
-                                static_cast<CSSStyleSheet*>(aPrimarySheet));
-}
-
-void
-CSSStyleSheetInner::RemoveSheet(StyleSheet* aSheet)
-{
-  if (aSheet == mSheets.ElementAt(0) && mSheets.Length() > 1) {
-    StyleSheet* sheet = mSheets[1];
-    for (css::Rule* rule : mOrderedRules) {
-      rule->SetStyleSheet(sheet);
-    }
-  }
-
-  // Don't do anything after this call, because superclass implementation
-  // may delete this.
-  StyleSheetInfo::RemoveSheet(aSheet);
-}
-
-static void
-AddNamespaceRuleToMap(css::Rule* aRule, nsXMLNameSpaceMap* aMap)
-{
-  NS_ASSERTION(aRule->GetType() == css::Rule::NAMESPACE_RULE, "Bogus rule type");
-
-  RefPtr<css::NameSpaceRule> nameSpaceRule = do_QueryObject(aRule);
-
-  nsAutoString  urlSpec;
-  nameSpaceRule->GetURLSpec(urlSpec);
-
-  aMap->AddPrefix(nameSpaceRule->GetPrefix(), urlSpec);
-}
-
-void
-CSSStyleSheetInner::RebuildNameSpaces()
-{
-  // Just nuke our existing namespace map, if any
-  if (NS_SUCCEEDED(CreateNamespaceMap())) {
-    for (css::Rule* rule : mOrderedRules) {
-      switch (rule->GetType()) {
-        case css::Rule::NAMESPACE_RULE:
-          AddNamespaceRuleToMap(rule, mNameSpaceMap);
-          continue;
-        case css::Rule::CHARSET_RULE:
-        case css::Rule::IMPORT_RULE:
-          continue;
-      }
-      break;
-    }
-  }
-}
-
-nsresult
-CSSStyleSheetInner::CreateNamespaceMap()
-{
-  mNameSpaceMap = nsXMLNameSpaceMap::Create(false);
-  NS_ENSURE_TRUE(mNameSpaceMap, NS_ERROR_OUT_OF_MEMORY);
-  // Override the default namespace map behavior for the null prefix to
-  // return the wildcard namespace instead of the null namespace.
-  mNameSpaceMap->AddPrefix(nullptr, kNameSpaceID_Unknown);
-  return NS_OK;
-}
-
-size_t
-CSSStyleSheetInner::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
-{
-  size_t n = aMallocSizeOf(this);
-  n += mOrderedRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
-  for (size_t i = 0; i < mOrderedRules.Length(); i++) {
-    n += mOrderedRules[i]->SizeOfIncludingThis(aMallocSizeOf);
-  }
-  n += mFirstChild ? mFirstChild->SizeOfIncludingThis(aMallocSizeOf) : 0;
-
-  // Measurement of the following members may be added later if DMD finds it is
-  // worthwhile:
-  // - mSheetURI
-  // - mOriginalSheetURI
-  // - mBaseURI
-  // - mPrincipal
-  // - mNameSpaceMap
-  //
-  // The following members are not measured:
-  // - mSheets, because it's non-owning
-
-  return n;
-}
-
-// -------------------------------
-// CSS Style Sheet
-//
-
-CSSStyleSheet::CSSStyleSheet(css::SheetParsingMode aParsingMode,
-                             CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy)
-  : StyleSheet(StyleBackendType::Gecko, aParsingMode),
-    mInRuleProcessorCache(false),
-    mRuleProcessors(nullptr)
-{
-  mInner = new CSSStyleSheetInner(aCORSMode, aReferrerPolicy,
-                                  SRIMetadata());
-  mInner->AddSheet(this);
-}
-
-CSSStyleSheet::CSSStyleSheet(css::SheetParsingMode aParsingMode,
-                             CORSMode aCORSMode,
-                             ReferrerPolicy aReferrerPolicy,
-                             const SRIMetadata& aIntegrity)
-  : StyleSheet(StyleBackendType::Gecko, aParsingMode),
-    mInRuleProcessorCache(false),
-    mRuleProcessors(nullptr)
-{
-  mInner = new CSSStyleSheetInner(aCORSMode, aReferrerPolicy,
-                                  aIntegrity);
-  mInner->AddSheet(this);
-}
-
-CSSStyleSheet::CSSStyleSheet(const CSSStyleSheet& aCopy,
-                             CSSStyleSheet* aParentToUse,
-                             dom::CSSImportRule* aOwnerRuleToUse,
-                             nsIDocument* aDocumentToUse,
-                             nsINode* aOwningNodeToUse)
-  : StyleSheet(aCopy,
-               aParentToUse,
-               aOwnerRuleToUse,
-               aDocumentToUse,
-               aOwningNodeToUse)
-  , mInRuleProcessorCache(false)
-  , mRuleProcessors(nullptr)
-{
-  if (HasForcedUniqueInner()) { // CSSOM's been there, force full copy now
-    NS_ASSERTION(mInner->mComplete,
-                 "Why have rules been accessed on an incomplete sheet?");
-    // FIXME: handle failure?
-    //
-    // NOTE: It's important to call this from the subclass, since it could
-    // access uninitialized members otherwise.
-    EnsureUniqueInner();
-  }
-}
-
-CSSStyleSheet::~CSSStyleSheet()
-{
-}
-
-void
-CSSStyleSheet::LastRelease()
-{
-  DropRuleCollection();
-  // XXX The document reference is not reference counted and should
-  // not be released. The document will let us know when it is going
-  // away.
-  if (mRuleProcessors) {
-    NS_ASSERTION(mRuleProcessors->Length() == 0, "destructing sheet with rule processor reference");
-    delete mRuleProcessors; // weak refs, should be empty here anyway
-    mRuleProcessors = nullptr;
-  }
-  if (mInRuleProcessorCache) {
-    RuleProcessorCache::RemoveSheet(this);
-  }
-}
-
-void
-CSSStyleSheet::DropRuleCollection()
-{
-  if (mRuleCollection) {
-    mRuleCollection->DropReference();
-    mRuleCollection = nullptr;
-  }
-}
-
-void
-CSSStyleSheet::UnlinkInner()
-{
-  // We can only have a cycle through our inner if we have a unique inner,
-  // because otherwise there are no JS wrappers for anything in the inner.
-  if (mInner->mSheets.Length() != 1) {
-    return;
-  }
-
-  for (css::Rule* rule : Inner()->mOrderedRules) {
-    rule->SetStyleSheet(nullptr);
-  }
-  Inner()->mOrderedRules.Clear();
-
-  StyleSheet::UnlinkInner();
-}
-
-void
-CSSStyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb)
-{
-  // We can only have a cycle through our inner if we have a unique inner,
-  // because otherwise there are no JS wrappers for anything in the inner.
-  if (mInner->mSheets.Length() != 1) {
-    return;
-  }
-
-  const nsCOMArray<css::Rule>& rules = Inner()->mOrderedRules;
-  for (int32_t i = 0, count = rules.Count(); i < count; ++i) {
-    if (!rules[i]->IsCCLeaf()) {
-      NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mOrderedRules[i]");
-      cb.NoteXPCOMChild(rules[i]);
-    }
-  }
-
-  StyleSheet::TraverseInner(cb);
-}
-
-// QueryInterface implementation for CSSStyleSheet
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSStyleSheet)
-  if (aIID.Equals(NS_GET_IID(CSSStyleSheet)))
-    foundInterface = reinterpret_cast<nsISupports*>(this);
-  else
-NS_INTERFACE_MAP_END_INHERITING(StyleSheet)
-
-NS_IMPL_ADDREF_INHERITED(CSSStyleSheet, StyleSheet)
-NS_IMPL_RELEASE_INHERITED(CSSStyleSheet, StyleSheet)
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(CSSStyleSheet)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSStyleSheet)
-  // We do not unlink mNext; our parent will handle that.  If we
-  // unlinked it here, our parent would not be able to walk its list
-  // of child sheets and null out the back-references to it, if we got
-  // unlinked before it does.
-  tmp->DropRuleCollection();
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(StyleSheet)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSStyleSheet, StyleSheet)
-  // We do not traverse mNext; our parent will handle that.  See
-  // comments in Unlink for why.
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleCollection)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-nsresult
-CSSStyleSheet::AddRuleProcessor(nsCSSRuleProcessor* aProcessor)
-{
-  if (! mRuleProcessors) {
-    mRuleProcessors = new AutoTArray<nsCSSRuleProcessor*, 8>();
-    if (!mRuleProcessors)
-      return NS_ERROR_OUT_OF_MEMORY;
-  }
-  NS_ASSERTION(mRuleProcessors->NoIndex == mRuleProcessors->IndexOf(aProcessor),
-               "processor already registered");
-  mRuleProcessors->AppendElement(aProcessor); // weak ref
-  return NS_OK;
-}
-
-nsresult
-CSSStyleSheet::DropRuleProcessor(nsCSSRuleProcessor* aProcessor)
-{
-  if (!mRuleProcessors)
-    return NS_ERROR_FAILURE;
-  return mRuleProcessors->RemoveElement(aProcessor)
-           ? NS_OK
-           : NS_ERROR_FAILURE;
-}
-
-bool
-CSSStyleSheet::UseForPresentation(nsPresContext* aPresContext,
-                                  nsMediaQueryResultCacheKey& aKey) const
-{
-  if (mMedia) {
-    MOZ_ASSERT(aPresContext);
-    auto media = static_cast<nsMediaList*>(mMedia.get());
-    return media->Matches(aPresContext, &aKey);
-  }
-  return true;
-}
-
-
-bool
-CSSStyleSheet::HasRules() const
-{
-  return StyleRuleCount() != 0;
-}
-
-void
-CSSStyleSheet::EnabledStateChangedInternal()
-{
-  ClearRuleCascades();
-}
-
-void
-CSSStyleSheet::AppendStyleRule(css::Rule* aRule)
-{
-  NS_PRECONDITION(nullptr != aRule, "null arg");
-
-  WillDirty();
-  Inner()->mOrderedRules.AppendObject(aRule);
-  aRule->SetStyleSheet(this);
-  DidDirty();
-
-  if (css::Rule::NAMESPACE_RULE == aRule->GetType()) {
-#ifdef DEBUG
-    nsresult rv =
-#endif
-      RegisterNamespaceRule(aRule);
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
-                         "RegisterNamespaceRule returned error");
-  }
-}
-
-int32_t
-CSSStyleSheet::StyleRuleCount() const
-{
-  return Inner()->mOrderedRules.Count();
-}
-
-css::Rule*
-CSSStyleSheet::GetStyleRuleAt(int32_t aIndex) const
-{
-  // Important: If this function is ever made scriptable, we must add
-  // a security check here. See GetCssRules below for an example.
-  return Inner()->mOrderedRules.SafeObjectAt(aIndex);
-}
-
-already_AddRefed<StyleSheet>
-CSSStyleSheet::Clone(StyleSheet* aCloneParent,
-                     dom::CSSImportRule* aCloneOwnerRule,
-                     nsIDocument* aCloneDocument,
-                     nsINode* aCloneOwningNode) const
-{
-  RefPtr<StyleSheet> clone = new CSSStyleSheet(*this,
-    static_cast<CSSStyleSheet*>(aCloneParent),
-    aCloneOwnerRule,
-    aCloneDocument,
-    aCloneOwningNode);
-  return clone.forget();
-}
-
-#ifdef DEBUG
-static void
-ListRules(const nsCOMArray<css::Rule>& aRules, FILE* aOut, int32_t aIndent)
-{
-  for (int32_t index = aRules.Count() - 1; index >= 0; --index) {
-    aRules.ObjectAt(index)->List(aOut, aIndent);
-  }
-}
-
-void
-CSSStyleSheet::List(FILE* out, int32_t aIndent) const
-{
-  StyleSheet::List(out, aIndent);
-
-  fprintf_stderr(out, "%s", "Rules in source order:\n");
-  ListRules(Inner()->mOrderedRules, out, aIndent);
-}
-#endif
-
-void
-CSSStyleSheet::ClearRuleCascades()
-{
-  // We might be in ClearRuleCascadesInternal because we had a modification
-  // to the sheet that resulted in an nsCSSSelector being destroyed.
-  // Tell the RestyleManager for each document we're used in
-  // so that they can drop any nsCSSSelector pointers (used for
-  // eRestyle_SomeDescendants) in their mPendingRestyles.
-  for (StyleSetHandle setHandle : mStyleSets) {
-    setHandle->AsGecko()->ClearSelectors();
-  }
-
-  bool removedSheetFromRuleProcessorCache = false;
-  if (mRuleProcessors) {
-    nsCSSRuleProcessor **iter = mRuleProcessors->Elements(),
-                       **end = iter + mRuleProcessors->Length();
-    for(; iter != end; ++iter) {
-      if (!removedSheetFromRuleProcessorCache && (*iter)->IsShared()) {
-        // Since the sheet has been modified, we need to remove all
-        // RuleProcessorCache entries that contain this sheet, as the
-        // list of @-moz-document rules might have changed.
-        RuleProcessorCache::RemoveSheet(this);
-        removedSheetFromRuleProcessorCache = true;
-      }
-      (*iter)->ClearRuleCascades();
-    }
-  }
-
-  if (mParent) {
-    static_cast<CSSStyleSheet*>(mParent)->ClearRuleCascades();
-  }
-}
-
-void
-CSSStyleSheet::DidDirty()
-{
-  MOZ_ASSERT(!mInner->mComplete || HasForcedUniqueInner(),
-             "caller must have called WillDirty()");
-  ClearRuleCascades();
-}
-
-nsresult
-CSSStyleSheet::RegisterNamespaceRule(css::Rule* aRule)
-{
-  if (!Inner()->mNameSpaceMap) {
-    nsresult rv = Inner()->CreateNamespaceMap();
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-
-  AddNamespaceRuleToMap(aRule, Inner()->mNameSpaceMap);
-  return NS_OK;
-}
-
-CSSRuleList*
-CSSStyleSheet::GetCssRulesInternal()
-{
-  if (!mRuleCollection) {
-    mRuleCollection = new CSSRuleListImpl(this);
-  }
-  return mRuleCollection;
-}
-
-uint32_t
-CSSStyleSheet::InsertRuleInternal(const nsAString& aRule,
-                                  uint32_t aIndex,
-                                  ErrorResult& aRv)
-{
-  MOZ_ASSERT(mInner->mComplete);
-
-  WillDirty();
-
-  if (aIndex > uint32_t(Inner()->mOrderedRules.Count())) {
-    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
-    return 0;
-  }
-
-  NS_ASSERTION(uint32_t(Inner()->mOrderedRules.Count()) <= INT32_MAX,
-               "Too many style rules!");
-
-  // Hold strong ref to the CSSLoader in case the document update
-  // kills the document
-  RefPtr<css::Loader> loader;
-  if (mDocument) {
-    loader = mDocument->CSSLoader();
-    NS_ASSERTION(loader, "Document with no CSS loader!");
-  }
-
-  nsCSSParser css(loader, this);
-
-  mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
-
-  RefPtr<css::Rule> rule;
-  aRv = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
-                      mInner->mPrincipal, getter_AddRefs(rule));
-  if (NS_WARN_IF(aRv.Failed())) {
-    return 0;
-  }
-
-  // Hierarchy checking.
-  int32_t newType = rule->GetType();
-
-  // check that we're not inserting before a charset rule
-  css::Rule* nextRule = Inner()->mOrderedRules.SafeObjectAt(aIndex);
-  if (nextRule) {
-    int32_t nextType = nextRule->GetType();
-    if (nextType == css::Rule::CHARSET_RULE) {
-      aRv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
-      return 0;
-    }
-
-    if (nextType == css::Rule::IMPORT_RULE &&
-        newType != css::Rule::CHARSET_RULE &&
-        newType != css::Rule::IMPORT_RULE) {
-      aRv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
-      return 0;
-    }
-
-    if (nextType == css::Rule::NAMESPACE_RULE &&
-        newType != css::Rule::CHARSET_RULE &&
-        newType != css::Rule::IMPORT_RULE &&
-        newType != css::Rule::NAMESPACE_RULE) {
-      aRv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
-      return 0;
-    }
-  }
-
-  if (aIndex != 0) {
-    // no inserting charset at nonzero position
-    if (newType == css::Rule::CHARSET_RULE) {
-      aRv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
-      return 0;
-    }
-
-    css::Rule* prevRule = Inner()->mOrderedRules.SafeObjectAt(aIndex - 1);
-    int32_t prevType = prevRule->GetType();
-
-    if (newType == css::Rule::IMPORT_RULE &&
-        prevType != css::Rule::CHARSET_RULE &&
-        prevType != css::Rule::IMPORT_RULE) {
-      aRv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
-      return 0;
-    }
-
-    if (newType == css::Rule::NAMESPACE_RULE &&
-        prevType != css::Rule::CHARSET_RULE &&
-        prevType != css::Rule::IMPORT_RULE &&
-        prevType != css::Rule::NAMESPACE_RULE) {
-      aRv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
-      return 0;
-    }
-  }
-
-  if (!Inner()->mOrderedRules.InsertObjectAt(rule, aIndex)) {
-    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
-    return 0;
-  }
-
-  DidDirty();
-
-  rule->SetStyleSheet(this);
-
-  int32_t type = rule->GetType();
-  if (type == css::Rule::NAMESPACE_RULE) {
-    // XXXbz does this screw up when inserting a namespace rule before
-    // another namespace rule that binds the same prefix to a different
-    // namespace?
-    aRv = RegisterNamespaceRule(rule);
-    if (NS_WARN_IF(aRv.Failed())) {
-      return 0;
-    }
-  }
-
-  // We don't notify immediately for @import rules, but rather when
-  // the sheet the rule is importing is loaded (see StyleSheetLoaded)
-  if (type != css::Rule::IMPORT_RULE || !RuleHasPendingChildSheet(rule)) {
-    RuleAdded(*rule);
-  }
-
-  return aIndex;
-}
-
-void
-CSSStyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv)
-{
-  // XXX TBI: handle @rule types
-  mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
-
-  WillDirty();
-
-  if (aIndex >= uint32_t(Inner()->mOrderedRules.Count())) {
-    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
-    return;
-  }
-
-  NS_ASSERTION(uint32_t(Inner()->mOrderedRules.Count()) <= INT32_MAX,
-               "Too many style rules!");
-
-  // Hold a strong ref to the rule so it doesn't die when we RemoveObjectAt
-  RefPtr<css::Rule> rule = Inner()->mOrderedRules.ObjectAt(aIndex);
-  if (rule) {
-    Inner()->mOrderedRules.RemoveObjectAt(aIndex);
-    rule->SetStyleSheet(nullptr);
-    RuleRemoved(*rule);
-  }
-}
-
-nsresult
-CSSStyleSheet::InsertRuleIntoGroupInternal(const nsAString& aRule,
-                                           css::GroupRule* aGroup,
-                                           uint32_t aIndex)
-{
-  // Hold strong ref to the CSSLoader in case the document update
-  // kills the document
-  RefPtr<css::Loader> loader;
-  if (mDocument) {
-    loader = mDocument->CSSLoader();
-    NS_ASSERTION(loader, "Document with no CSS loader!");
-  }
-
-  nsCSSParser css(loader, this);
-
-  RefPtr<css::Rule> rule;
-  nsresult result = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
-                                  mInner->mPrincipal, getter_AddRefs(rule));
-  if (NS_FAILED(result))
-    return result;
-
-  switch (rule->GetType()) {
-    case css::Rule::STYLE_RULE:
-    case css::Rule::MEDIA_RULE:
-    case css::Rule::FONT_FACE_RULE:
-    case css::Rule::PAGE_RULE:
-    case css::Rule::KEYFRAMES_RULE:
-    case css::Rule::COUNTER_STYLE_RULE:
-    case css::Rule::DOCUMENT_RULE:
-    case css::Rule::SUPPORTS_RULE:
-      // these types are OK to insert into a group
-      break;
-    case css::Rule::CHARSET_RULE:
-    case css::Rule::IMPORT_RULE:
-    case css::Rule::NAMESPACE_RULE:
-      // these aren't
-      return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
-    default:
-      NS_NOTREACHED("unexpected rule type");
-      return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
-  }
-
-  return aGroup->InsertStyleRuleAt(aIndex, rule);
-}
-
-// nsICSSLoaderObserver implementation
-NS_IMETHODIMP
-CSSStyleSheet::StyleSheetLoaded(StyleSheet* aSheet,
-                                bool aWasAlternate,
-                                nsresult aStatus)
-{
-  MOZ_ASSERT(aSheet->IsGecko(),
-             "why we were called back with a ServoStyleSheet?");
-
-  CSSStyleSheet* sheet = aSheet->AsGecko();
-
-  if (sheet->GetParentSheet() == nullptr) {
-    return NS_OK; // ignore if sheet has been detached already (see parseSheet)
-  }
-  NS_ASSERTION(this == sheet->GetParentSheet(),
-               "We are being notified of a sheet load for a sheet that is not our child!");
-
-  if (NS_SUCCEEDED(aStatus)) {
-    mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
-    RuleAdded(*sheet->GetOwnerRule());
-  }
-
-  return NS_OK;
-}
-
-nsresult
-CSSStyleSheet::ReparseSheet(const nsAString& aInput)
-{
-  // Not doing this if the sheet is not complete!
-  if (!mInner->mComplete) {
-    return NS_ERROR_DOM_INVALID_ACCESS_ERR;
-  }
-
-  // Hold strong ref to the CSSLoader in case the document update
-  // kills the document
-  RefPtr<css::Loader> loader;
-  if (mDocument) {
-    loader = mDocument->CSSLoader();
-    NS_ASSERTION(loader, "Document with no CSS loader!");
-  } else {
-    loader = new css::Loader(StyleBackendType::Gecko, nullptr);
-  }
-
-  mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
-
-  WillDirty();
-
-  // detach existing rules (including child sheets via import rules)
-  css::LoaderReusableStyleSheets reusableSheets;
-  int ruleCount;
-  while ((ruleCount = Inner()->mOrderedRules.Count()) != 0) {
-    RefPtr<css::Rule> rule = Inner()->mOrderedRules.ObjectAt(ruleCount - 1);
-    Inner()->mOrderedRules.RemoveObjectAt(ruleCount - 1);
-    rule->SetStyleSheet(nullptr);
-    if (rule->GetType() == css::Rule::IMPORT_RULE) {
-      auto importRule = static_cast<css::ImportRule*>(rule.get());
-      RefPtr<StyleSheet> sheet = importRule->GetStyleSheet();
-      if (sheet && sheet->GetOriginalURI()) {
-        reusableSheets.AddReusableSheet(sheet);
-      }
-    }
-    RuleRemoved(*rule);
-  }
-
-  // nuke child sheets list and current namespace map
-  for (StyleSheet* child = GetFirstChild(); child; ) {
-    NS_ASSERTION(child->mParent == this, "Child sheet is not parented to this!");
-    StyleSheet* next = child->mNext;
-    child->mParent = nullptr;
-    child->SetAssociatedDocument(nullptr, NotOwnedByDocument);
-    child->mNext = nullptr;
-    child = next;
-  }
-  SheetInfo().mFirstChild = nullptr;
-  Inner()->mNameSpaceMap = nullptr;
-
-  uint32_t lineNumber = 1;
-  if (mOwningNode) {
-    nsCOMPtr<nsIStyleSheetLinkingElement> link = do_QueryInterface(mOwningNode);
-    if (link) {
-      lineNumber = link->GetLineNumber();
-    }
-  }
-
-  nsCSSParser parser(loader, this);
-  nsresult rv = parser.ParseSheet(aInput, mInner->mSheetURI, mInner->mBaseURI,
-                                  mInner->mPrincipal, /* aLoadData = */ nullptr,
-                                  lineNumber, &reusableSheets);
-  DidDirty(); // we are always 'dirty' here since we always remove rules first
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // notify document of all new rules
-  for (int32_t index = 0; index < Inner()->mOrderedRules.Count(); ++index) {
-    RefPtr<css::Rule> rule = Inner()->mOrderedRules.ObjectAt(index);
-    if (rule->GetType() == css::Rule::IMPORT_RULE &&
-        RuleHasPendingChildSheet(rule)) {
-      continue; // notify when loaded (see StyleSheetLoaded)
-    }
-    RuleAdded(*rule);
-  }
-
-  // Our rules are no longer considered modified.
-  ClearModifiedRules();
-
-  return NS_OK;
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/layout/style/CSSStyleSheet.h
+++ /dev/null
@@ -1,204 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* representation of a CSS style sheet */
-
-#ifndef mozilla_CSSStyleSheet_h
-#define mozilla_CSSStyleSheet_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/IncrementalClearCOMRuleArray.h"
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/StyleSheet.h"
-#include "mozilla/StyleSheetInfo.h"
-#include "mozilla/css/SheetParsingMode.h"
-
-#include "nscore.h"
-#include "nsCOMPtr.h"
-#include "nsAutoPtr.h"
-#include "nsTArrayForwardDeclare.h"
-#include "nsStringFwd.h"
-#include "mozilla/CORSMode.h"
-#include "nsCycleCollectionParticipant.h"
-#include "mozilla/net/ReferrerPolicy.h"
-#include "mozilla/dom/SRIMetadata.h"
-
-class CSSRuleListImpl;
-class nsCSSRuleProcessor;
-class nsIURI;
-class nsMediaQueryResultCacheKey;
-class nsPresContext;
-class nsXMLNameSpaceMap;
-
-namespace mozilla {
-class CSSStyleSheet;
-struct ChildSheetListBuilder;
-
-namespace css {
-class GroupRule;
-} // namespace css
-namespace dom {
-class CSSRuleList;
-class Element;
-} // namespace dom
-
-  // -------------------------------
-// CSS Style Sheet Inner Data Container
-//
-
-struct CSSStyleSheetInner : public StyleSheetInfo
-{
-  CSSStyleSheetInner(CORSMode aCORSMode,
-                     ReferrerPolicy aReferrerPolicy,
-                     const dom::SRIMetadata& aIntegrity);
-  CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
-                     CSSStyleSheet* aPrimarySheet);
-  ~CSSStyleSheetInner();
-
-  StyleSheetInfo* CloneFor(StyleSheet* aPrimarySheet) override;
-  void RemoveSheet(StyleSheet* aSheet) override;
-
-  void RebuildNameSpaces();
-
-  // Create a new namespace map
-  nsresult CreateNamespaceMap();
-
-  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
-
-  IncrementalClearCOMRuleArray mOrderedRules;
-  nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
-};
-
-
-// -------------------------------
-// CSS Style Sheet
-//
-
-// CID for the CSSStyleSheet class
-// 7985c7ac-9ddc-444d-9899-0c86ec122f54
-#define NS_CSS_STYLE_SHEET_IMPL_CID     \
-{ 0x7985c7ac, 0x9ddc, 0x444d, \
-  { 0x98, 0x99, 0x0c, 0x86, 0xec, 0x12, 0x2f, 0x54 } }
-
-
-class CSSStyleSheet final : public StyleSheet
-{
-public:
-  typedef net::ReferrerPolicy ReferrerPolicy;
-  CSSStyleSheet(css::SheetParsingMode aParsingMode,
-                CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy);
-  CSSStyleSheet(css::SheetParsingMode aParsingMode,
-                CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy,
-                const dom::SRIMetadata& aIntegrity);
-
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CSSStyleSheet, StyleSheet)
-
-  NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID)
-
-  bool HasRules() const;
-
-#ifdef DEBUG
-  void List(FILE* out = stdout, int32_t aIndent = 0) const override;
-#endif
-
-  // XXX do these belong here or are they generic?
-  void AppendStyleRule(css::Rule* aRule);
-
-  int32_t StyleRuleCount() const;
-  css::Rule* GetStyleRuleAt(int32_t aIndex) const;
-
-  nsXMLNameSpaceMap* GetNameSpaceMap() const {
-    return Inner()->mNameSpaceMap;
-  }
-
-  already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
-    dom::CSSImportRule* aCloneOwnerRule,
-    nsIDocument* aCloneDocument,
-    nsINode* aCloneOwningNode) const final;
-
-  nsresult AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
-  nsresult DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
-
-  // nsICSSLoaderObserver interface
-  NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
-                              nsresult aStatus) override;
-
-  bool UseForPresentation(nsPresContext* aPresContext,
-                            nsMediaQueryResultCacheKey& aKey) const;
-
-  nsresult ReparseSheet(const nsAString& aInput);
-
-  void SetInRuleProcessorCache() { mInRuleProcessorCache = true; }
-
-  // Function used as a callback to rebuild our inner's child sheet
-  // list after we clone a unique inner for ourselves.
-  static bool RebuildChildList(css::Rule* aRule,
-                               ChildSheetListBuilder* aBuilder);
-
-  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
-
-  void DidDirty() override;
-
-private:
-  CSSStyleSheet(const CSSStyleSheet& aCopy,
-                CSSStyleSheet* aParentToUse,
-                dom::CSSImportRule* aOwnerRuleToUse,
-                nsIDocument* aDocumentToUse,
-                nsINode* aOwningNodeToUse);
-
-  CSSStyleSheet(const CSSStyleSheet& aCopy) = delete;
-  CSSStyleSheet& operator=(const CSSStyleSheet& aCopy) = delete;
-
-protected:
-  virtual ~CSSStyleSheet();
-
-  void LastRelease();
-
-  void ClearRuleCascades();
-
-  // Add the namespace mapping from this @namespace rule to our namespace map
-  nsresult RegisterNamespaceRule(css::Rule* aRule);
-
-  // Drop our reference to mRuleCollection
-  void DropRuleCollection();
-
-  CSSStyleSheetInner* Inner() const
-  {
-    return static_cast<CSSStyleSheetInner*>(mInner);
-  }
-
-  // Unlink our inner, if needed, for cycle collection
-  virtual void UnlinkInner() override;
-  // Traverse our inner, if needed, for cycle collection
-  virtual void TraverseInner(nsCycleCollectionTraversalCallback &) override;
-
-protected:
-  // Internal methods which do not have security check and completeness check.
-  dom::CSSRuleList* GetCssRulesInternal();
-  uint32_t InsertRuleInternal(const nsAString& aRule,
-                              uint32_t aIndex, ErrorResult& aRv);
-  void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
-  nsresult InsertRuleIntoGroupInternal(const nsAString& aRule,
-                                       css::GroupRule* aGroup,
-                                       uint32_t aIndex);
-
-  void EnabledStateChangedInternal();
-
-  RefPtr<CSSRuleListImpl> mRuleCollection;
-  bool                  mInRuleProcessorCache;
-
-  AutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
-
-  friend class mozilla::StyleSheet;
-  friend class ::nsCSSRuleProcessor;
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(CSSStyleSheet, NS_CSS_STYLE_SHEET_IMPL_CID)
-
-} // namespace mozilla
-
-#endif /* !defined(mozilla_CSSStyleSheet_h) */
deleted file mode 100644
--- a/layout/style/CSSVariableDeclarations.cpp
+++ /dev/null
@@ -1,194 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* CSS Custom Property assignments for a Declaration at a given priority */
-
-#include "CSSVariableDeclarations.h"
-
-#include "CSSVariableResolver.h"
-#include "nsCSSScanner.h"
-#include "nsRuleData.h"
-
-// These three special string values are used to represent specified values of
-// 'initial', 'inherit' and 'unset'.  (Note that none of these are valid
-// variable values.)
-#define INITIAL_VALUE "!"
-#define INHERIT_VALUE ";"
-#define UNSET_VALUE   ")"
-
-namespace mozilla {
-
-CSSVariableDeclarations::CSSVariableDeclarations()
-{
-  MOZ_COUNT_CTOR(CSSVariableDeclarations);
-}
-
-CSSVariableDeclarations::CSSVariableDeclarations(const CSSVariableDeclarations& aOther)
-{
-  MOZ_COUNT_CTOR(CSSVariableDeclarations);
-  CopyVariablesFrom(aOther);
-}
-
-#ifdef DEBUG
-CSSVariableDeclarations::~CSSVariableDeclarations()
-{
-  MOZ_COUNT_DTOR(CSSVariableDeclarations);
-}
-#endif
-
-CSSVariableDeclarations&
-CSSVariableDeclarations::operator=(const CSSVariableDeclarations& aOther)
-{
-  if (this == &aOther) {
-    return *this;
-  }
-
-  mVariables.Clear();
-  CopyVariablesFrom(aOther);
-  return *this;
-}
-
-void
-CSSVariableDeclarations::CopyVariablesFrom(const CSSVariableDeclarations& aOther)
-{
-  for (auto iter = aOther.mVariables.ConstIter(); !iter.Done(); iter.Next()) {
-    mVariables.Put(iter.Key(), iter.UserData());
-  }
-}
-
-bool
-CSSVariableDeclarations::Has(const nsAString& aName) const
-{
-  nsString value;
-  return mVariables.Get(aName, &value);
-}
-
-bool
-CSSVariableDeclarations::Get(const nsAString& aName,
-                             Type& aType,
-                             nsString& aTokenStream) const
-{
-  nsString value;
-  if (!mVariables.Get(aName, &value)) {
-    return false;
-  }
-  if (value.EqualsLiteral(INITIAL_VALUE)) {
-    aType = eInitial;
-    aTokenStream.Truncate();
-  } else if (value.EqualsLiteral(INHERIT_VALUE)) {
-    aType = eInherit;
-    aTokenStream.Truncate();
-  } else if (value.EqualsLiteral(UNSET_VALUE)) {
-    aType = eUnset;
-    aTokenStream.Truncate();
-  } else {
-    aType = eTokenStream;
-    aTokenStream = value;
-  }
-  return true;
-}
-
-void
-CSSVariableDeclarations::PutTokenStream(const nsAString& aName,
-                                        const nsString& aTokenStream)
-{
-  MOZ_ASSERT(!aTokenStream.EqualsLiteral(INITIAL_VALUE) &&
-             !aTokenStream.EqualsLiteral(INHERIT_VALUE) &&
-             !aTokenStream.EqualsLiteral(UNSET_VALUE));
-  mVariables.Put(aName, aTokenStream);
-}
-
-void
-CSSVariableDeclarations::PutInitial(const nsAString& aName)
-{
-  mVariables.Put(aName, NS_LITERAL_STRING(INITIAL_VALUE));
-}
-
-void
-CSSVariableDeclarations::PutInherit(const nsAString& aName)
-{
-  mVariables.Put(aName, NS_LITERAL_STRING(INHERIT_VALUE));
-}
-
-void
-CSSVariableDeclarations::PutUnset(const nsAString& aName)
-{
-  mVariables.Put(aName, NS_LITERAL_STRING(UNSET_VALUE));
-}
-
-void
-CSSVariableDeclarations::Remove(const nsAString& aName)
-{
-  mVariables.Remove(aName);
-}
-
-void
-CSSVariableDeclarations::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  if (!(aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Variables))) {
-    return;
-  }
-
-  if (!aRuleData->mVariables) {
-    aRuleData->mVariables = new CSSVariableDeclarations(*this);
-  } else {
-    for (auto iter = mVariables.Iter(); !iter.Done(); iter.Next()) {
-      nsDataHashtable<nsStringHashKey, nsString>& variables =
-        aRuleData->mVariables->mVariables;
-      const nsAString& aName = iter.Key();
-      variables.LookupForAdd(aName).OrInsert(
-        [&iter] () { return iter.UserData(); });
-    }
-  }
-}
-
-void
-CSSVariableDeclarations::AddVariablesToResolver(
-                                           CSSVariableResolver* aResolver) const
-{
-  for (auto iter = mVariables.ConstIter(); !iter.Done(); iter.Next()) {
-    const nsAString& name = iter.Key();
-    nsString value = iter.UserData();
-    if (value.EqualsLiteral(INITIAL_VALUE)) {
-      // Values of 'initial' are treated the same as an invalid value in the
-      // variable resolver.
-      aResolver->Put(name, EmptyString(),
-                     eCSSTokenSerialization_Nothing,
-                     eCSSTokenSerialization_Nothing,
-                     false);
-    } else if (value.EqualsLiteral(INHERIT_VALUE) ||
-               value.EqualsLiteral(UNSET_VALUE)) {
-      // Values of 'inherit' and 'unset' don't need any handling, since it means
-      // we just need to keep whatever value is currently in the resolver.  This
-      // is because the specified variable declarations already have only the
-      // winning declaration for the variable and no longer have any of the
-      // others.
-    } else {
-      // At this point, we don't know what token types are at the start and end
-      // of the specified variable value.  These will be determined later during
-      // the resolving process.
-      aResolver->Put(name, value,
-                     eCSSTokenSerialization_Nothing,
-                     eCSSTokenSerialization_Nothing,
-                     false);
-    }
-  }
-}
-
-size_t
-CSSVariableDeclarations::SizeOfIncludingThis(
-                                      mozilla::MallocSizeOf aMallocSizeOf) const
-{
-  size_t n = aMallocSizeOf(this);
-  n += mVariables.ShallowSizeOfExcludingThis(aMallocSizeOf);
-  for (auto iter = mVariables.ConstIter(); !iter.Done(); iter.Next()) {
-    n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
-    n += iter.Data().SizeOfExcludingThisIfUnshared(aMallocSizeOf);
-  }
-  return n;
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/layout/style/CSSVariableDeclarations.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* CSS Custom Property assignments for a Declaration at a given priority */
-
-#ifndef mozilla_CSSVariableDeclarations_h
-#define mozilla_CSSVariableDeclarations_h
-
-#include "nsDataHashtable.h"
-
-namespace mozilla {
-class CSSVariableResolver;
-} // namespace mozilla
-struct nsRuleData;
-
-namespace mozilla {
-
-class CSSVariableDeclarations
-{
-public:
-  CSSVariableDeclarations();
-  CSSVariableDeclarations(const CSSVariableDeclarations& aOther);
-#ifdef DEBUG
-  ~CSSVariableDeclarations();
-#endif
-  CSSVariableDeclarations& operator=(const CSSVariableDeclarations& aOther);
-
-  /**
-   * Returns whether this set of variable declarations includes a variable
-   * with a given name.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name).
-   */
-  bool Has(const nsAString& aName) const;
-
-  /**
-   * Represents the type of a variable value.
-   */
-  enum Type {
-    eTokenStream,  // a stream of CSS tokens (the usual type for variables)
-    eInitial,      // 'initial'
-    eInherit,      // 'inherit'
-    eUnset         // 'unset'
-  };
-
-  /**
-   * Gets the value of a variable in this set of variable declarations.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name).
-   * @param aType Out parameter into which the type of the variable value will
-   *   be stored.
-   * @param aValue Out parameter into which the value of the variable will
-   *   be stored.  If the variable is 'initial', 'inherit' or 'unset', this will
-   *   be the empty string.
-   * @return Whether a variable with the given name was found.  When false
-   *   is returned, aType and aValue will not be modified.
-   */
-  bool Get(const nsAString& aName, Type& aType, nsString& aValue) const;
-
-  /**
-   * Adds or modifies an existing entry in this set of variable declarations
-   * to have the value 'initial'.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name) whose value is to be set.
-   */
-  void PutInitial(const nsAString& aName);
-
-  /**
-   * Adds or modifies an existing entry in this set of variable declarations
-   * to have the value 'inherit'.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name) whose value is to be set.
-   */
-  void PutInherit(const nsAString& aName);
-
-  /**
-   * Adds or modifies an existing entry in this set of variable declarations
-   * to have the value 'unset'.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name) whose value is to be set.
-   */
-  void PutUnset(const nsAString& aName);
-
-  /**
-   * Adds or modifies an existing entry in this set of variable declarations
-   * to have a token stream value.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name) whose value is to be set.
-   * @param aTokenStream The CSS token stream.
-   */
-  void PutTokenStream(const nsAString& aName, const nsString& aTokenStream);
-
-  /**
-   * Removes an entry in this set of variable declarations.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name) whose entry is to be removed.
-   */
-  void Remove(const nsAString& aName);
-
-  /**
-   * Returns the number of entries in this set of variable declarations.
-   */
-  uint32_t Count() const { return mVariables.Count(); }
-
-  /**
-   * Copies each variable value from this object into aRuleData, unless that
-   * variable already exists on aRuleData.
-   */
-  void MapRuleInfoInto(nsRuleData* aRuleData);
-
-  /**
-   * Copies the variables from this object into aResolver, marking them as
-   * specified values.
-   */
-  void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
-
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
-
-private:
-  /**
-   * Adds all the variable declarations from aOther into this object.
-   */
-  void CopyVariablesFrom(const CSSVariableDeclarations& aOther);
-
-  nsDataHashtable<nsStringHashKey, nsString> mVariables;
-};
-
-} // namespace mozilla
-
-#endif
deleted file mode 100644
--- a/layout/style/CSSVariableResolver.cpp
+++ /dev/null
@@ -1,269 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* object that resolves CSS variables using specified and inherited variable
- * values
- */
-
-#include "CSSVariableResolver.h"
-
-#include "CSSVariableDeclarations.h"
-#include "CSSVariableValues.h"
-#include "mozilla/PodOperations.h"
-#include "mozilla/UniquePtr.h"
-#include <algorithm>
-
-namespace mozilla {
-
-/**
- * Data used by the EnumerateVariableReferences callback.  Reset must be called
- * on it before it is used.
- */
-class EnumerateVariableReferencesData
-{
-public:
-  explicit EnumerateVariableReferencesData(CSSVariableResolver& aResolver)
-    : mResolver(aResolver)
-    , mReferences(MakeUnique<bool[]>(aResolver.mVariables.Length()))
-  {
-  }
-
-  /**
-   * Resets the data so that it can be passed to another call of
-   * EnumerateVariableReferences for a different variable.
-   */
-  void Reset()
-  {
-    PodZero(mReferences.get(), mResolver.mVariables.Length());
-    mReferencesNonExistentVariable = false;
-  }
-
-  void RecordVariableReference(const nsAString& aVariableName)
-  {
-    size_t id;
-    if (mResolver.mVariableIDs.Get(aVariableName, &id)) {
-      mReferences[id] = true;
-    } else {
-      mReferencesNonExistentVariable = true;
-    }
-  }
-
-  bool HasReferenceToVariable(size_t aID) const
-  {
-    return mReferences[aID];
-  }
-
-  bool ReferencesNonExistentVariable() const
-  {
-   return mReferencesNonExistentVariable;
-  }
-
-private:
-  CSSVariableResolver& mResolver;
-
-  // Array of booleans, where each index is a variable ID.  If an element is
-  // true, it indicates that the variable we have called
-  // EnumerateVariableReferences for has a reference to the variable with
-  // that ID.
-  const UniquePtr<bool[]> mReferences;
-
-  // Whether the variable we have called EnumerateVariableReferences for
-  // references a variable that does not exist in the resolver.
-  bool mReferencesNonExistentVariable;
-};
-
-static void
-RecordVariableReference(const nsAString& aVariableName,
-                        void* aData)
-{
-  static_cast<EnumerateVariableReferencesData*>(aData)->
-    RecordVariableReference(aVariableName);
-}
-
-void
-CSSVariableResolver::RemoveCycles(size_t v)
-{
-  mVariables[v].mIndex = mNextIndex;
-  mVariables[v].mLowLink = mNextIndex;
-  mVariables[v].mInStack = true;
-  mStack.AppendElement(v);
-  mNextIndex++;
-
-  for (size_t i = 0, n = mReferences[v].Length(); i < n; i++) {
-    size_t w = mReferences[v][i];
-    if (!mVariables[w].mIndex) {
-      RemoveCycles(w);
-      mVariables[v].mLowLink = std::min(mVariables[v].mLowLink,
-                                        mVariables[w].mLowLink);
-    } else if (mVariables[w].mInStack) {
-      mVariables[v].mLowLink = std::min(mVariables[v].mLowLink,
-                                        mVariables[w].mIndex);
-    }
-  }
-
-  if (mVariables[v].mLowLink == mVariables[v].mIndex) {
-    if (mStack.LastElement() == v) {
-      // A strongly connected component consisting of a single variable is not
-      // necessarily invalid.  We handle variables that reference themselves
-      // earlier, in CSSVariableResolver::Resolve.
-      mVariables[mStack.LastElement()].mInStack = false;
-      mStack.TruncateLength(mStack.Length() - 1);
-    } else {
-      size_t w;
-      do {
-        w = mStack.LastElement();
-        mVariables[w].mValue.Truncate(0);
-        mVariables[w].mInStack = false;
-        mStack.TruncateLength(mStack.Length() - 1);
-      } while (w != v);
-    }
-  }
-}
-
-void
-CSSVariableResolver::ResolveVariable(size_t aID)
-{
-  if (mVariables[aID].mValue.IsEmpty() || mVariables[aID].mWasInherited) {
-    // The variable is invalid or was inherited.   We can just copy the value
-    // and its first/last token information across.
-    mOutput->Put(mVariables[aID].mVariableName,
-                 mVariables[aID].mValue,
-                 mVariables[aID].mFirstToken,
-                 mVariables[aID].mLastToken);
-  } else {
-    // Otherwise we need to resolve the variable references, after resolving
-    // all of our dependencies first.  We do this even for variables that we
-    // know do not reference other variables so that we can find their
-    // first/last token.
-    //
-    // XXX We might want to do this first/last token finding during
-    // EnumerateVariableReferences, so that we can avoid calling
-    // ResolveVariableValue and parsing the value again.
-    for (size_t i = 0, n = mReferences[aID].Length(); i < n; i++) {
-      size_t j = mReferences[aID][i];
-      if (aID != j && !mVariables[j].mResolved) {
-        ResolveVariable(j);
-      }
-    }
-    nsString resolvedValue;
-    nsCSSTokenSerializationType firstToken, lastToken;
-    if (mParser.ResolveVariableValue(mVariables[aID].mValue, mOutput,
-                                     resolvedValue, firstToken, lastToken)) {
-      mOutput->Put(mVariables[aID].mVariableName, resolvedValue,
-                   firstToken, lastToken);
-    } else {
-      mOutput->Put(mVariables[aID].mVariableName, EmptyString(),
-                   eCSSTokenSerialization_Nothing, eCSSTokenSerialization_Nothing);
-    }
-  }
-  mVariables[aID].mResolved = true;
-}
-
-void
-CSSVariableResolver::Resolve(const CSSVariableValues* aInherited,
-                             const CSSVariableDeclarations* aSpecified)
-{
-  MOZ_ASSERT(!mResolved);
-
-  // The only time we would be worried about having a null aInherited is
-  // for the root, but in that case nsRuleNode::ComputeVariablesData will
-  // happen to pass in whatever we're using as mOutput for aInherited,
-  // which will initially be empty.
-  MOZ_ASSERT(aInherited);
-  MOZ_ASSERT(aSpecified);
-
-  aInherited->AddVariablesToResolver(this);
-  aSpecified->AddVariablesToResolver(this);
-
-  // First we look at each variable's value and record which other variables
-  // it references.
-  size_t n = mVariables.Length();
-  mReferences.SetLength(n);
-  EnumerateVariableReferencesData data(*this);
-  for (size_t id = 0; id < n; id++) {
-    data.Reset();
-    if (!mVariables[id].mWasInherited &&
-        !mVariables[id].mValue.IsEmpty()) {
-      if (mParser.EnumerateVariableReferences(mVariables[id].mValue,
-                                              RecordVariableReference,
-                                              &data)) {
-        // Convert the boolean array of dependencies in |data| to a list
-        // of dependencies.
-        for (size_t i = 0; i < n; i++) {
-          if (data.HasReferenceToVariable(i)) {
-            mReferences[id].AppendElement(i);
-          }
-        }
-        // If a variable references itself, it is invalid.  (RemoveCycles
-        // does not check for cycles consisting of a single variable, so we
-        // check here.)
-        if (data.HasReferenceToVariable(id)) {
-          mVariables[id].mValue.Truncate();
-        }
-        // Also record whether it referenced any variables that don't exist
-        // in the resolver, so that we can ensure we still resolve its value
-        // in ResolveVariable, even though its mReferences list is empty.
-        mVariables[id].mReferencesNonExistentVariable =
-          data.ReferencesNonExistentVariable();
-      } else {
-        MOZ_ASSERT(false, "EnumerateVariableReferences should not have failed "
-                          "if we previously parsed the specified value");
-        mVariables[id].mValue.Truncate(0);
-      }
-    }
-  }
-
-  // Next we remove any cycles in variable references using Tarjan's strongly
-  // connected components finding algorithm, setting variables in cycles to
-  // have an invalid value.
-  mNextIndex = 1;
-  for (size_t id = 0; id < n; id++) {
-    if (!mVariables[id].mIndex) {
-      RemoveCycles(id);
-      MOZ_ASSERT(mStack.IsEmpty());
-    }
-  }
-
-  // Finally we construct the computed value for the variable by substituting
-  // any variable references.
-  for (size_t id = 0; id < n; id++) {
-    if (!mVariables[id].mResolved) {
-      ResolveVariable(id);
-    }
-  }
-
-#ifdef DEBUG
-  mResolved = true;
-#endif
-}
-
-void
-CSSVariableResolver::Put(const nsAString& aVariableName,
-                         nsString aValue,
-                         nsCSSTokenSerializationType aFirstToken,
-                         nsCSSTokenSerializationType aLastToken,
-                         bool aWasInherited)
-{
-  MOZ_ASSERT(!mResolved);
-
-  size_t id;
-  if (mVariableIDs.Get(aVariableName, &id)) {
-    MOZ_ASSERT(mVariables[id].mWasInherited && !aWasInherited,
-               "should only overwrite inherited variables with specified "
-               "variables");
-    mVariables[id].mValue = aValue;
-    mVariables[id].mFirstToken = aFirstToken;
-    mVariables[id].mLastToken = aLastToken;
-    mVariables[id].mWasInherited = aWasInherited;
-  } else {
-    id = mVariables.Length();
-    mVariableIDs.Put(aVariableName, id);
-    mVariables.AppendElement(Variable(aVariableName, aValue,
-                                      aFirstToken, aLastToken, aWasInherited));
-  }
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/layout/style/CSSVariableResolver.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* object that resolves CSS variables using specified and inherited variable
- * values
- */
-
-#ifndef mozilla_CSSVariableResolver_h
-#define mozilla_CSSVariableResolver_h
-
-#include "mozilla/DebugOnly.h"
-#include "nsCSSParser.h"
-#include "nsCSSScanner.h"
-#include "nsDataHashtable.h"
-#include "nsTArray.h"
-
-namespace mozilla {
-
-class CSSVariableDeclarations;
-class CSSVariableValues;
-class EnumerateVariableReferencesData;
-
-class CSSVariableResolver
-{
-  friend class CSSVariableDeclarations;
-  friend class CSSVariableValues;
-  friend class EnumerateVariableReferencesData;
-public:
-  /**
-   * Creates a new CSSVariableResolver that will output a set of resolved,
-   * computed variables into aOutput.
-   */
-  explicit CSSVariableResolver(CSSVariableValues* aOutput)
-    : mOutput(aOutput)
-#ifdef DEBUG
-    , mResolved(false)
-#endif
-  {
-    MOZ_ASSERT(aOutput);
-  }
-
-  /**
-   * Resolves the set of inherited variables from aInherited and the
-   * set of specified variables from aSpecified.  The resolved variables
-   * are written into mOutput.
-   */
-  void Resolve(const CSSVariableValues* aInherited,
-               const CSSVariableDeclarations* aSpecified);
-
-private:
-  struct Variable
-  {
-    Variable(const nsAString& aVariableName,
-             nsString aValue,
-             nsCSSTokenSerializationType aFirstToken,
-             nsCSSTokenSerializationType aLastToken,
-             bool aWasInherited)
-      : mVariableName(aVariableName)
-      , mValue(aValue)
-      , mFirstToken(aFirstToken)
-      , mLastToken(aLastToken)
-      , mWasInherited(aWasInherited)
-      , mResolved(false)
-      , mReferencesNonExistentVariable(false)
-      , mInStack(false)
-      , mIndex(0)
-      , mLowLink(0) { }
-
-    nsString mVariableName;
-    nsString mValue;
-    nsCSSTokenSerializationType mFirstToken;
-    nsCSSTokenSerializationType mLastToken;
-
-    // Whether this variable came from the set of inherited variables.
-    bool mWasInherited;
-
-    // Whether this variable has been resolved yet.
-    bool mResolved;
-
-    // Whether this variables includes any references to non-existent variables.
-    bool mReferencesNonExistentVariable;
-
-    // Bookkeeping for the cycle remover algorithm.
-    bool mInStack;
-    size_t mIndex;
-    size_t mLowLink;
-  };
-
-  /**
-   * Adds or modifies an existing entry in the set of variables to be resolved.
-   * This is intended to be called by the AddVariablesToResolver functions on
-   * the CSSVariableDeclarations and CSSVariableValues objects passed in to
-   * Resolve.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name) whose value is to be set.
-   * @param aValue The variable value.
-   * @param aFirstToken The type of token at the start of the variable value.
-   * @param aLastToken The type of token at the en of the variable value.
-   * @param aWasInherited Whether this variable came from the set of inherited
-   *   variables.
-   */
-  void Put(const nsAString& aVariableName,
-           nsString aValue,
-           nsCSSTokenSerializationType aFirstToken,
-           nsCSSTokenSerializationType aLastToken,
-           bool aWasInherited);
-
-  // Helper functions for Resolve.
-  void RemoveCycles(size_t aID);
-  void ResolveVariable(size_t aID);
-
-  // A mapping of variable names to an ID that indexes into mVariables
-  // and mReferences.
-  nsDataHashtable<nsStringHashKey, size_t> mVariableIDs;
-
-  // The set of variables.
-  nsTArray<Variable> mVariables;
-
-  // The list of variables that each variable references.
-  nsTArray<nsTArray<size_t> > mReferences;
-
-  // The next index to assign to a variable found during the cycle removing
-  // algorithm's traversal of the variable reference graph.
-  size_t mNextIndex;
-
-  // Stack of variable IDs that we push to as we traverse the variable reference
-  // graph while looking for cycles.  Variable::mInStack reflects whether a
-  // given variable has its ID in mStack.
-  nsTArray<size_t> mStack;
-
-  // CSS parser to use for parsing property values with variable references.
-  nsCSSParser mParser;
-
-  // The object to output the resolved variables into.
-  CSSVariableValues* mOutput;
-
-#ifdef DEBUG
-  // Whether Resolve has been called.
-  bool mResolved;
-#endif
-};
-
-} // namespace mozilla
-
-#endif
deleted file mode 100644
--- a/layout/style/CSSVariableValues.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* computed CSS Variable values */
-
-#include "CSSVariableValues.h"
-
-#include "CSSVariableResolver.h"
-
-namespace mozilla {
-
-CSSVariableValues::CSSVariableValues()
-{
-  MOZ_COUNT_CTOR(CSSVariableValues);
-}
-
-CSSVariableValues::CSSVariableValues(const CSSVariableValues& aOther)
-{
-  MOZ_COUNT_CTOR(CSSVariableValues);
-  CopyVariablesFrom(aOther);
-}
-
-#ifdef DEBUG
-CSSVariableValues::~CSSVariableValues()
-{
-  MOZ_COUNT_DTOR(CSSVariableValues);
-}
-#endif
-
-CSSVariableValues&
-CSSVariableValues::operator=(const CSSVariableValues& aOther)
-{
-  if (this == &aOther) {
-    return *this;
-  }
-
-  mVariableIDs.Clear();
-  mVariables.Clear();
-  CopyVariablesFrom(aOther);
-  return *this;
-}
-
-bool
-CSSVariableValues::operator==(const CSSVariableValues& aOther) const
-{
-  if (mVariables.Length() != aOther.mVariables.Length()) {
-    return false;
-  }
-
-  for (size_t thisIndex = 0; thisIndex < mVariables.Length(); ++thisIndex) {
-    size_t otherIndex;
-    if (!aOther.mVariableIDs.Get(mVariables[thisIndex].mVariableName,
-                                 &otherIndex)) {
-      return false;
-    }
-    const nsString& otherValue = aOther.mVariables[otherIndex].mValue;
-    if (!mVariables[thisIndex].mValue.Equals(otherValue)) {
-      return false;
-    }
-  }
-
-  return true;
-}
-
-size_t
-CSSVariableValues::Count() const
-{
-  return mVariables.Length();
-}
-
-bool
-CSSVariableValues::Get(const nsAString& aName, nsString& aValue) const
-{
-  size_t id;
-  if (!mVariableIDs.Get(aName, &id)) {
-    return false;
-  }
-  aValue = mVariables[id].mValue;
-  return true;
-}
-
-bool
-CSSVariableValues::Get(const nsAString& aName,
-                       nsString& aValue,
-                       nsCSSTokenSerializationType& aFirstToken,
-                       nsCSSTokenSerializationType& aLastToken) const
-{
-  size_t id;
-  if (!mVariableIDs.Get(aName, &id)) {
-    return false;
-  }
-  aValue = mVariables[id].mValue;
-  aFirstToken = mVariables[id].mFirstToken;
-  aLastToken = mVariables[id].mLastToken;
-  return true;
-}
-
-void
-CSSVariableValues::GetVariableAt(size_t aIndex, nsAString& aName) const
-{
-  aName = mVariables[aIndex].mVariableName;
-}
-
-void
-CSSVariableValues::Put(const nsAString& aName,
-                       nsString aValue,
-                       nsCSSTokenSerializationType aFirstToken,
-                       nsCSSTokenSerializationType aLastToken)
-{
-  size_t id;
-  if (mVariableIDs.Get(aName, &id)) {
-    mVariables[id].mValue = aValue;
-    mVariables[id].mFirstToken = aFirstToken;
-    mVariables[id].mLastToken = aLastToken;
-  } else {
-    id = mVariables.Length();
-    mVariableIDs.Put(aName, id);
-    mVariables.AppendElement(Variable(aName, aValue, aFirstToken, aLastToken));
-  }
-}
-
-void
-CSSVariableValues::CopyVariablesFrom(const CSSVariableValues& aOther)
-{
-  for (size_t i = 0, n = aOther.mVariables.Length(); i < n; i++) {
-    Put(aOther.mVariables[i].mVariableName,
-        aOther.mVariables[i].mValue,
-        aOther.mVariables[i].mFirstToken,
-        aOther.mVariables[i].mLastToken);
-  }
-}
-
-void
-CSSVariableValues::AddVariablesToResolver(CSSVariableResolver* aResolver) const
-{
-  for (size_t i = 0, n = mVariables.Length(); i < n; i++) {
-    aResolver->Put(mVariables[i].mVariableName,
-                   mVariables[i].mValue,
-                   mVariables[i].mFirstToken,
-                   mVariables[i].mLastToken,
-                   true);
-  }
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/layout/style/CSSVariableValues.h
+++ /dev/null
@@ -1,148 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* computed CSS Variable values */
-
-#ifndef mozilla_CSSVariableValues_h
-#define mozilla_CSSVariableValues_h
-
-#include "nsCSSScanner.h"
-#include "nsDataHashtable.h"
-#include "nsTArray.h"
-
-namespace mozilla {
-
-class CSSVariableResolver;
-
-class CSSVariableValues
-{
-public:
-  CSSVariableValues();
-  CSSVariableValues(const CSSVariableValues& aOther);
-#ifdef DEBUG
-  ~CSSVariableValues();
-#endif
-  CSSVariableValues& operator=(const CSSVariableValues& aOther);
-
-  bool operator==(const CSSVariableValues& aOther) const;
-  bool operator!=(const CSSVariableValues& aOther) const
-    { return !(*this == aOther); }
-
-  /**
-   * Gets the value of a variable in this set of computed variables.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name).
-   * @param aValue Out parameter into which the value of the variable will
-   *   be stored.
-   * @return Whether a variable with the given name was found.  When false
-   *   is returned, aValue will not be modified.
-   */
-  bool Get(const nsAString& aName, nsString& aValue) const;
-
-  /**
-   * Gets the value of a variable in this set of computed variables, along
-   * with information on the types of tokens that appear at the start and
-   * end of the token stream.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name).
-   * @param aValue Out parameter into which the value of the variable will
-   *   be stored.
-   * @param aFirstToken The type of token at the start of the variable value.
-   * @param aLastToken The type of token at the en of the variable value.
-   * @return Whether a variable with the given name was found.  When false
-   *   is returned, aValue, aFirstToken and aLastToken will not be modified.
-   */
-  bool Get(const nsAString& aName,
-           nsString& aValue,
-           nsCSSTokenSerializationType& aFirstToken,
-           nsCSSTokenSerializationType& aLastToken) const;
-
-  /**
-   * Gets the name of the variable at the given index.
-   *
-   * Variables on this object are ordered, and that order is just determined
-   * based on the order that they are added to the object.  A consistent
-   * ordering is required for CSSDeclaration objects in the DOM.
-   * CSSDeclarations expose property names as indexed properties, which need to
-   * be stable.
-   *
-   * @param aIndex The index of the variable to get.
-   * @param aName Out parameter into which the name of the variable will be
-   *   stored.
-   */
-  void GetVariableAt(size_t aIndex, nsAString& aName) const;
-
-  /**
-   * Gets the number of variables stored on this object.
-   */
-  size_t Count() const;
-
-  /**
-   * Adds or modifies an existing entry in this set of variable values.
-   *
-   * @param aName The variable name (not including any "--" prefix that would
-   *   be part of the custom property name) whose value is to be set.
-   * @param aValue The variable value.
-   * @param aFirstToken The type of token at the start of the variable value.
-   * @param aLastToken The type of token at the en of the variable value.
-   */
-  void Put(const nsAString& aName,
-           nsString aValue,
-           nsCSSTokenSerializationType aFirstToken,
-           nsCSSTokenSerializationType aLastToken);
-
-  /**
-   * Copies the variables from this object into aResolver, marking them as
-   * computed, inherited values.
-   */
-  void AddVariablesToResolver(CSSVariableResolver* aResolver) const;
-
-private:
-  struct Variable
-  {
-    Variable()
-      : mFirstToken(eCSSTokenSerialization_Nothing)
-      , mLastToken(eCSSTokenSerialization_Nothing)
-    {}
-
-    Variable(const nsAString& aVariableName,
-             nsString aValue,
-             nsCSSTokenSerializationType aFirstToken,
-             nsCSSTokenSerializationType aLastToken)
-      : mVariableName(aVariableName)
-      , mValue(aValue)
-      , mFirstToken(aFirstToken)
-      , mLastToken(aLastToken)
-    {}
-
-    nsString mVariableName;
-    nsString mValue;
-    nsCSSTokenSerializationType mFirstToken;
-    nsCSSTokenSerializationType mLastToken;
-  };
-
-  /**
-   * Adds all the variables from aOther into this object.
-   */
-  void CopyVariablesFrom(const CSSVariableValues& aOther);
-
-  /**
-   * Map of variable names to IDs.  Variable IDs are indexes into
-   * mVariables.
-   */
-  nsDataHashtable<nsStringHashKey, size_t> mVariableIDs;
-
-  /**
-   * Array of variables, indexed by variable ID.
-   */
-  nsTArray<Variable> mVariables;
-};
-
-} // namespace mozilla
-
-#endif
deleted file mode 100644
--- a/layout/style/Declaration.cpp
+++ /dev/null
@@ -1,1939 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/*
- * representation of a declaration block (or style attribute) in a CSS
- * stylesheet
- */
-
-#include "mozilla/css/Declaration.h"
-
-#include "mozilla/ArrayUtils.h"
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/ServoStyleSet.h"
-
-#include "mozilla/css/Rule.h"
-#include "nsPrintfCString.h"
-#include "gfxFontConstants.h"
-#include "nsStyleUtil.h"
-
-namespace mozilla {
-namespace css {
-
-NS_IMPL_QUERY_INTERFACE(ImportantStyleData, nsIStyleRule)
-NS_IMPL_ADDREF_USING_AGGREGATOR(ImportantStyleData, Declaration())
-NS_IMPL_RELEASE_USING_AGGREGATOR(ImportantStyleData, Declaration())
-
-/* virtual */ void
-ImportantStyleData::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  Declaration()->MapImportantRuleInfoInto(aRuleData);
-}
-
-/* virtual */ bool
-ImportantStyleData::MightMapInheritedStyleData()
-{
-  return Declaration()->MapsImportantInheritedStyleData();
-}
-
-/* virtual */ bool
-ImportantStyleData::GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
-                                                  nsCSSValue* aValue)
-{
-  return Declaration()->GetDiscretelyAnimatedCSSValue(aProperty, aValue);
-}
-
-
-#ifdef DEBUG
-/* virtual */ void
-ImportantStyleData::List(FILE* out, int32_t aIndent) const
-{
-  // Indent
-  nsAutoCString str;
-  for (int32_t index = aIndent; --index >= 0; ) {
-    str.AppendLiteral("  ");
-  }
-
-  str.AppendLiteral("! important rule\n");
-  fprintf_stderr(out, "%s", str.get());
-}
-#endif
-
-Declaration::Declaration(const Declaration& aCopy)
-  : DeclarationBlock(aCopy),
-    mOrder(aCopy.mOrder),
-    mVariableOrder(aCopy.mVariableOrder),
-    mData(aCopy.mData ? aCopy.mData->Clone() : nullptr),
-    mImportantData(aCopy.mImportantData ?
-                     aCopy.mImportantData->Clone() : nullptr),
-    mVariables(aCopy.mVariables ?
-        new CSSVariableDeclarations(*aCopy.mVariables) :
-        nullptr),
-    mImportantVariables(aCopy.mImportantVariables ?
-        new CSSVariableDeclarations(*aCopy.mImportantVariables) :
-        nullptr)
-{
-}
-
-Declaration::~Declaration()
-{
-}
-
-NS_INTERFACE_MAP_BEGIN(Declaration)
-  if (aIID.Equals(NS_GET_IID(mozilla::css::Declaration))) {
-    *aInstancePtr = this;
-    NS_ADDREF_THIS();
-    return NS_OK;
-  }
-  else
-  NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
-NS_INTERFACE_MAP_END
-
-NS_IMPL_ADDREF(Declaration)
-NS_IMPL_RELEASE(Declaration)
-
-/* virtual */ void
-Declaration::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  MOZ_ASSERT(mData, "must call only while compressed");
-  mData->MapRuleInfoInto(aRuleData);
-  if (mVariables) {
-    mVariables->MapRuleInfoInto(aRuleData);
-  }
-}
-
-/* virtual */ bool
-Declaration::MightMapInheritedStyleData()
-{
-  MOZ_ASSERT(mData, "must call only while compressed");
-  if (mVariables && mVariables->Count() != 0) {
-    return true;
-  }
-  return mData->HasInheritedStyleData();
-}
-
-/* virtual */ bool
-Declaration::GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
-                                           nsCSSValue* aValue)
-{
-  nsCSSCompressedDataBlock* data = GetPropertyIsImportantByID(aProperty)
-                                   ? mImportantData : mData;
-  const nsCSSValue* value = data->ValueFor(aProperty);
-  if (!value) {
-    return false;
-  }
-  *aValue = *value;
-  return true;
-}
-
-
-bool
-Declaration::MapsImportantInheritedStyleData() const
-{
-  MOZ_ASSERT(mData, "must call only while compressed");
-  MOZ_ASSERT(HasImportantData(), "must only be called for Declarations with "
-                                 "important data");
-  if (mImportantVariables && mImportantVariables->Count() != 0) {
-    return true;
-  }
-  return mImportantData ? mImportantData->HasInheritedStyleData() : false;
-}
-
-void
-Declaration::ValueAppended(nsCSSPropertyID aProperty)
-{
-  MOZ_ASSERT(!mData && !mImportantData,
-             "should only be called while expanded");
-  MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
-             "shorthands forbidden");
-  // order IS important for CSS, so remove and add to the end
-  mOrder.RemoveElement(static_cast<uint32_t>(aProperty));
-  mOrder.AppendElement(static_cast<uint32_t>(aProperty));
-}
-
-template<typename PropFunc, typename CustomPropFunc>
-inline void
-DispatchPropertyOperation(const nsAString& aProperty,
-                          PropFunc aPropFunc, CustomPropFunc aCustomPropFunc)
-{
-  nsCSSPropertyID propID =
-    nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
-  if (propID != eCSSProperty_UNKNOWN) {
-    if (propID != eCSSPropertyExtra_variable) {
-      aPropFunc(propID);
-    } else {
-      aCustomPropFunc(Substring(aProperty, CSS_CUSTOM_NAME_PREFIX_LENGTH));
-    }
-  }
-}
-
-void
-Declaration::GetPropertyValue(const nsAString& aProperty,
-                              nsAString& aValue) const
-{
-  DispatchPropertyOperation(aProperty,
-    [&](nsCSSPropertyID propID) { GetPropertyValueByID(propID, aValue); },
-    [&](const nsAString& name) { GetVariableValue(name, aValue); });
-}
-
-void
-Declaration::GetPropertyValueByID(nsCSSPropertyID aPropID,
-                                  nsAString& aValue) const
-{
-  GetPropertyValueInternal(aPropID, aValue);
-}
-
-bool
-Declaration::GetPropertyIsImportant(const nsAString& aProperty) const
-{
-  bool r = false;
-  DispatchPropertyOperation(aProperty,
-    [&](nsCSSPropertyID propID) { r = GetPropertyIsImportantByID(propID); },
-    [&](const nsAString& name) { r = GetVariableIsImportant(name); });
-  return r;
-}
-
-bool
-Declaration::RemoveProperty(const nsAString& aProperty)
-{
-  bool r = true;
-  DispatchPropertyOperation(aProperty,
-    [&](nsCSSPropertyID propID) { r = RemovePropertyByID(propID); },
-    [&](const nsAString& name) { r = RemoveVariable(name); });
-  return r;
-}
-
-bool
-Declaration::RemovePropertyByID(nsCSSPropertyID aProperty)
-{
-  MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT);
-
-  nsCSSExpandedDataBlock data;
-  ExpandTo(&data);
-  MOZ_ASSERT(!mData && !mImportantData, "Expand didn't null things out");
-
-  bool removed = false;
-  if (nsCSSProps::IsShorthand(aProperty)) {
-    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
-                                         CSSEnabledState::eForAllContent) {
-      data.ClearLonghandProperty(*p);
-      if (mOrder.RemoveElement(static_cast<uint32_t>(*p))) {
-        removed = true;
-      }
-    }
-  } else {
-    data.ClearLonghandProperty(aProperty);
-    removed = mOrder.RemoveElement(static_cast<uint32_t>(aProperty));
-  }
-
-  CompressFrom(&data);
-  return removed;
-}
-
-bool
-Declaration::HasProperty(nsCSSPropertyID aProperty) const
-{
-  MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_no_shorthands,
-             "property ID out of range");
-
-  nsCSSCompressedDataBlock *data = GetPropertyIsImportantByID(aProperty)
-                                      ? mImportantData : mData;
-  const nsCSSValue *val = data->ValueFor(aProperty);
-  return !!val;
-}
-
-bool
-Declaration::AppendValueToString(nsCSSPropertyID aProperty,
-                                 nsAString& aResult,
-                                 bool* aIsTokenStream) const
-{
-  MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_no_shorthands,
-             "property ID out of range");
-
-  nsCSSCompressedDataBlock *data = GetPropertyIsImportantByID(aProperty)
-                                      ? mImportantData : mData;
-  const nsCSSValue *val = data->ValueFor(aProperty);
-  if (!val) {
-    return false;
-  }
-
-  if (aIsTokenStream) {
-    *aIsTokenStream = val->GetUnit() == eCSSUnit_TokenStream;
-  }
-  val->AppendToString(aProperty, aResult);
-  return true;
-}
-
-static void
-AppendSingleImageLayerPositionValue(const nsCSSValue& aPositionX,
-                                    const nsCSSValue& aPositionY,
-                                    const nsCSSPropertyID aTable[],
-                                    nsAString& aValue)
-{
-  // We need to make sure that we don't serialize to an invalid 3-value form.
-  // The 3-value form is only valid if both edges are present.
-  const nsCSSValue &xEdge = aPositionX.GetArrayValue()->Item(0);
-  const nsCSSValue &xOffset = aPositionX.GetArrayValue()->Item(1);
-  const nsCSSValue &yEdge = aPositionY.GetArrayValue()->Item(0);
-  const nsCSSValue &yOffset = aPositionY.GetArrayValue()->Item(1);
-  bool xHasEdge = (eCSSUnit_Enumerated == xEdge.GetUnit());
-  bool xHasBoth = xHasEdge && (eCSSUnit_Null != xOffset.GetUnit());
-  bool yHasEdge = (eCSSUnit_Enumerated == yEdge.GetUnit());
-  bool yHasBoth = yHasEdge && (eCSSUnit_Null != yOffset.GetUnit());
-
-  if (yHasBoth && !xHasEdge) {
-    // Output 4-value form by adding the x edge.
-    aValue.AppendLiteral("left ");
-  }
-  aPositionX.AppendToString(aTable[nsStyleImageLayers::positionX],
-                            aValue);
-
-  aValue.Append(char16_t(' '));
-
-  if (xHasBoth && !yHasEdge) {
-    // Output 4-value form by adding the y edge.
-    aValue.AppendLiteral("top ");
-  }
-  aPositionY.AppendToString(aTable[nsStyleImageLayers::positionY],
-                            aValue);
-}
-
-void
-Declaration::GetImageLayerValue(
-                   nsCSSCompressedDataBlock *data,
-                   nsAString& aValue,
-                   const nsCSSPropertyID aTable[]) const
-{
-  // We know from our caller that all subproperties were specified.
-  // However, we still can't represent that in the shorthand unless
-  // they're all lists of the same length.  So if they're different
-  // lengths, we need to bail out.
-  // We also need to bail out if an item has background-clip and
-  // background-origin that are different and not the default
-  // values.  (We omit them if they're both default.)
-
-  // Common CSS properties for both background & mask layer.
-  const nsCSSValueList *image =
-    data->ValueFor(aTable[nsStyleImageLayers::image])->GetListValue();
-  const nsCSSValuePairList *repeat =
-    data->ValueFor(aTable[nsStyleImageLayers::repeat])->GetPairListValue();
-  const nsCSSValueList *positionX =
-    data->ValueFor(aTable[nsStyleImageLayers::positionX])->GetListValue();
-  const nsCSSValueList *positionY =
-    data->ValueFor(aTable[nsStyleImageLayers::positionY])->GetListValue();
-  const nsCSSValueList *clip =
-    data->ValueFor(aTable[nsStyleImageLayers::clip])->GetListValue();
-  const nsCSSValueList *origin =
-    data->ValueFor(aTable[nsStyleImageLayers::origin])->GetListValue();
-  const nsCSSValuePairList *size =
-    data->ValueFor(aTable[nsStyleImageLayers::size])->GetPairListValue();
-
-  // Background layer property.
-  const nsCSSValueList *attachment =
-    (aTable[nsStyleImageLayers::attachment] ==  eCSSProperty_UNKNOWN)?
-      nullptr :
-      data->ValueFor(aTable[nsStyleImageLayers::attachment])->GetListValue();
-
-  // Mask layer properties.
-  const nsCSSValueList *composite =
-    (aTable[nsStyleImageLayers::composite] ==  eCSSProperty_UNKNOWN)?
-      nullptr :
-      data->ValueFor(aTable[nsStyleImageLayers::composite])->GetListValue();
-  const nsCSSValueList *mode =
-    (aTable[nsStyleImageLayers::maskMode] ==  eCSSProperty_UNKNOWN)?
-      nullptr :
-      data->ValueFor(aTable[nsStyleImageLayers::maskMode])->GetListValue();
-
-  for (;;) {
-    // Serialize background-color at the beginning of the last item.
-    if (!image->mNext) {
-      if (aTable[nsStyleImageLayers::color] != eCSSProperty_UNKNOWN) {
-        AppendValueToString(aTable[nsStyleImageLayers::color], aValue);
-        aValue.Append(char16_t(' '));
-      }
-    }
-
-    image->mValue.AppendToString(aTable[nsStyleImageLayers::image], aValue);
-
-    aValue.Append(char16_t(' '));
-    repeat->mXValue.AppendToString(aTable[nsStyleImageLayers::repeat], aValue);
-    if (repeat->mYValue.GetUnit() != eCSSUnit_Null) {
-      repeat->mYValue.AppendToString(aTable[nsStyleImageLayers::repeat], aValue);
-    }
-
-    if (attachment) {
-      aValue.Append(char16_t(' '));
-          attachment->mValue.AppendToString(aTable[nsStyleImageLayers::attachment],
-                                            aValue);
-    }
-
-    aValue.Append(char16_t(' '));
-    AppendSingleImageLayerPositionValue(positionX->mValue, positionY->mValue,
-                                        aTable, aValue);
-
-    if (size->mXValue.GetUnit() != eCSSUnit_Auto ||
-        size->mYValue.GetUnit() != eCSSUnit_Auto) {
-      aValue.Append(char16_t(' '));
-      aValue.Append(char16_t('/'));
-      aValue.Append(char16_t(' '));
-      size->mXValue.AppendToString(aTable[nsStyleImageLayers::size], aValue);
-      aValue.Append(char16_t(' '));
-      size->mYValue.AppendToString(aTable[nsStyleImageLayers::size], aValue);
-    }
-
-    MOZ_ASSERT(clip->mValue.GetUnit() == eCSSUnit_Enumerated &&
-               origin->mValue.GetUnit() == eCSSUnit_Enumerated,
-               "should not have inherit/initial within list");
-
-    StyleGeometryBox originDefaultValue =
-      (aTable == nsStyleImageLayers::kBackgroundLayerTable)
-      ? StyleGeometryBox::PaddingBox : StyleGeometryBox::BorderBox;
-    if (static_cast<StyleGeometryBox>(clip->mValue.GetIntValue()) !=
-        StyleGeometryBox::BorderBox ||
-        static_cast<StyleGeometryBox>(origin->mValue.GetIntValue()) !=
-        originDefaultValue) {
-#ifdef DEBUG
-      const nsCSSProps::KTableEntry* originTable = nsCSSProps::kKeywordTableTable[aTable[nsStyleImageLayers::origin]];
-      const nsCSSProps::KTableEntry* clipTable = nsCSSProps::kKeywordTableTable[aTable[nsStyleImageLayers::clip]];
-      for (size_t i = 0; originTable[i].mValue != -1; i++) {
-        // For each keyword & value in kOriginKTable, ensure that
-        // kBackgroundKTable has a matching entry at the same position.
-        MOZ_ASSERT(originTable[i].mKeyword == clipTable[i].mKeyword);
-        MOZ_ASSERT(originTable[i].mValue == clipTable[i].mValue);
-      }
-#endif
-      aValue.Append(char16_t(' '));
-      origin->mValue.AppendToString(aTable[nsStyleImageLayers::origin], aValue);
-
-      if (clip->mValue != origin->mValue) {
-        aValue.Append(char16_t(' '));
-        clip->mValue.AppendToString(aTable[nsStyleImageLayers::clip], aValue);
-      }
-    }
-
-    if (composite) {
-      aValue.Append(char16_t(' '));
-      composite->mValue.AppendToString(aTable[nsStyleImageLayers::composite],
-                                       aValue);
-    }
-
-    if (mode) {
-      aValue.Append(char16_t(' '));
-      mode->mValue.AppendToString(aTable[nsStyleImageLayers::maskMode], aValue);
-    }
-
-    image = image->mNext;
-    repeat = repeat->mNext;
-    positionX = positionX->mNext;
-    positionY = positionY->mNext;
-    clip = clip->mNext;
-    origin = origin->mNext;
-    size = size->mNext;
-    attachment = attachment ? attachment->mNext : nullptr;
-    composite = composite ? composite->mNext : nullptr;
-    mode = mode ? mode->mNext : nullptr;
-
-    if (!image) {
-      // This layer is an background layer
-      if (aTable == nsStyleImageLayers::kBackgroundLayerTable) {
-        if (repeat || positionX || positionY || clip || origin || size ||
-            attachment) {
-          // Uneven length lists, so can't be serialized as shorthand.
-          aValue.Truncate();
-          return;
-        }
-      // This layer is an mask layer
-      } else {
-        MOZ_ASSERT(aTable == nsStyleImageLayers::kMaskLayerTable);
-        if (repeat || positionX || positionY || clip || origin || size ||
-            composite || mode) {
-          // Uneven length lists, so can't be serialized as shorthand.
-          aValue.Truncate();
-          return;
-        }
-      }
-      break;
-    }
-
-    // This layer is an background layer
-    if (aTable == nsStyleImageLayers::kBackgroundLayerTable) {
-      if (!repeat || !positionX || !positionY || !clip || !origin || !size ||
-          !attachment) {
-        // Uneven length lists, so can't be serialized as shorthand.
-        aValue.Truncate();
-        return;
-      }
-    // This layer is an mask layer
-    } else {
-      MOZ_ASSERT(aTable == nsStyleImageLayers::kMaskLayerTable);
-      if (!repeat || !positionX || !positionY || !clip || !origin || !size ||
-          !composite || !mode) {
-        // Uneven length lists, so can't be serialized as shorthand.
-        aValue.Truncate();
-        return;
-      }
-    }
-    aValue.Append(char16_t(','));
-    aValue.Append(char16_t(' '));
-  }
-}
-
-void
-Declaration::GetImageLayerPositionValue(
-                   nsCSSCompressedDataBlock *data,
-                   nsAString& aValue,
-                   const nsCSSPropertyID aTable[]) const
-{
-  // We know from above that all subproperties were specified.
-  // However, we still can't represent that in the shorthand unless
-  // they're all lists of the same length.  So if they're different
-  // lengths, we need to bail out.
-  const nsCSSValueList *positionX =
-    data->ValueFor(aTable[nsStyleImageLayers::positionX])->GetListValue();
-  const nsCSSValueList *positionY =
-    data->ValueFor(aTable[nsStyleImageLayers::positionY])->GetListValue();
-  for (;;) {
-    AppendSingleImageLayerPositionValue(positionX->mValue, positionY->mValue,
-                                        aTable, aValue);
-    positionX = positionX->mNext;
-    positionY = positionY->mNext;
-
-    if (!positionX || !positionY) {
-      if (positionX || positionY) {
-        // Uneven length lists, so can't be serialized as shorthand.
-        aValue.Truncate();
-      }
-      return;
-    }
-    aValue.Append(char16_t(','));
-    aValue.Append(char16_t(' '));
-  }
-}
-
-void
-Declaration::GetPropertyValueInternal(
-    nsCSSPropertyID aProperty, nsAString& aValue,
-    bool* aIsTokenStream) const
-{
-  aValue.Truncate(0);
-  if (aIsTokenStream) {
-    *aIsTokenStream = false;
-  }
-
-  // simple properties are easy.
-  if (!nsCSSProps::IsShorthand(aProperty)) {
-    AppendValueToString(aProperty, aValue, aIsTokenStream);
-    return;
-  }
-
-  // DOM Level 2 Style says (when describing CSS2Properties, although
-  // not CSSStyleDeclaration.getPropertyValue):
-  //   However, if there is no shorthand declaration that could be added
-  //   to the ruleset without changing in any way the rules already
-  //   declared in the ruleset (i.e., by adding longhand rules that were
-  //   previously not declared in the ruleset), then the empty string
-  //   should be returned for the shorthand property.
-  // This means we need to check a number of cases:
-  //   (1) Since a shorthand sets all sub-properties, if some of its
-  //       subproperties were not specified, we must return the empty
-  //       string.
-  //   (2) Since 'inherit', 'initial' and 'unset' can only be specified
-  //       as the values for entire properties, we need to return the
-  //       empty string if some but not all of the subproperties have one
-  //       of those values.
-  //   (3) Since a single value only makes sense with or without
-  //       !important, we return the empty string if some values are
-  //       !important and some are not.
-  // Since we're doing this check for 'inherit' and 'initial' up front,
-  // we can also simplify the property serialization code by serializing
-  // those values up front as well.
-  //
-  // Additionally, if a shorthand property was set using a value with a
-  // variable reference and none of its component longhand properties were
-  // then overridden on the declaration, we return the token stream
-  // assigned to the shorthand.
-  const nsCSSValue* tokenStream = nullptr;
-  uint32_t totalCount = 0, importantCount = 0,
-           initialCount = 0, inheritCount = 0, unsetCount = 0,
-           matchingTokenStreamCount = 0, nonMatchingTokenStreamCount = 0;
-  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
-                                       CSSEnabledState::eForAllContent) {
-    if (*p == eCSSProperty__x_system_font) {
-      // The system-font subproperty doesn't count.
-      continue;
-    }
-    ++totalCount;
-    const nsCSSValue *val = mData->ValueFor(*p);
-    MOZ_ASSERT(!val || !mImportantData || !mImportantData->ValueFor(*p),
-               "can't be in both blocks");
-    if (!val && mImportantData) {
-      ++importantCount;
-      val = mImportantData->ValueFor(*p);
-    }
-    if (!val) {
-      // Case (1) above: some subproperties not specified.
-      return;
-    }
-    if (val->GetUnit() == eCSSUnit_Inherit) {
-      ++inheritCount;
-    } else if (val->GetUnit() == eCSSUnit_Initial) {
-      ++initialCount;
-    } else if (val->GetUnit() == eCSSUnit_Unset) {
-      ++unsetCount;
-    } else if (val->GetUnit() == eCSSUnit_TokenStream) {
-      if (val->GetTokenStreamValue()->mShorthandPropertyID == aProperty) {
-        tokenStream = val;
-        ++matchingTokenStreamCount;
-      } else {
-        ++nonMatchingTokenStreamCount;
-      }
-    }
-  }
-  if (importantCount != 0 && importantCount != totalCount) {
-    // Case (3), no consistent importance.
-    return;
-  }
-  if (initialCount == totalCount) {
-    // Simplify serialization below by serializing initial up-front.
-    nsCSSValue(eCSSUnit_Initial).AppendToString(eCSSProperty_UNKNOWN, aValue);
-    return;
-  }
-  if (inheritCount == totalCount) {
-    // Simplify serialization below by serializing inherit up-front.
-    nsCSSValue(eCSSUnit_Inherit).AppendToString(eCSSProperty_UNKNOWN, aValue);
-    return;
-  }
-  if (unsetCount == totalCount) {
-    // Simplify serialization below by serializing unset up-front.
-    nsCSSValue(eCSSUnit_Unset).AppendToString(eCSSProperty_UNKNOWN, aValue);
-    return;
-  }
-  if (initialCount != 0 || inheritCount != 0 ||
-      unsetCount != 0 || nonMatchingTokenStreamCount != 0) {
-    // Case (2): partially initial, inherit, unset or token stream.
-    return;
-  }
-  if (tokenStream) {
-    if (matchingTokenStreamCount == totalCount) {
-      // Shorthand was specified using variable references and all of its
-      // longhand components were set by the shorthand.
-      if (aIsTokenStream) {
-        *aIsTokenStream = true;
-      }
-      aValue.Append(tokenStream->GetTokenStreamValue()->mTokenStream);
-    } else {
-      // In all other cases, serialize to the empty string.
-    }
-    return;
-  }
-
-  nsCSSCompressedDataBlock *data = importantCount ? mImportantData : mData;
-  switch (aProperty) {
-    case eCSSProperty_margin:
-    case eCSSProperty_padding:
-    case eCSSProperty_border_color:
-    case eCSSProperty_border_style:
-    case eCSSProperty_border_width: {
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      MOZ_ASSERT(nsCSSProps::GetStringValue(subprops[0]).Find("-top") !=
-                 kNotFound, "first subprop must be top");
-      MOZ_ASSERT(nsCSSProps::GetStringValue(subprops[1]).Find("-right") !=
-                 kNotFound, "second subprop must be right");
-      MOZ_ASSERT(nsCSSProps::GetStringValue(subprops[2]).Find("-bottom") !=
-                 kNotFound, "third subprop must be bottom");
-      MOZ_ASSERT(nsCSSProps::GetStringValue(subprops[3]).Find("-left") !=
-                 kNotFound, "fourth subprop must be left");
-      const nsCSSValue* vals[4] = {
-        data->ValueFor(subprops[0]),
-        data->ValueFor(subprops[1]),
-        data->ValueFor(subprops[2]),
-        data->ValueFor(subprops[3])
-      };
-      nsCSSValue::AppendSidesShorthandToString(subprops, vals, aValue);
-      break;
-    }
-    case eCSSProperty_border_radius:
-    case eCSSProperty__moz_outline_radius: {
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      const nsCSSValue* vals[4] = {
-        data->ValueFor(subprops[0]),
-        data->ValueFor(subprops[1]),
-        data->ValueFor(subprops[2]),
-        data->ValueFor(subprops[3])
-      };
-      nsCSSValue::AppendBasicShapeRadiusToString(subprops, vals, aValue);
-      break;
-    }
-    case eCSSProperty_border_image: {
-      // Even though there are some cases where we could omit
-      // 'border-image-source' (when it's none), it's probably not a
-      // good idea since it's likely to be confusing.  It would also
-      // require adding the extra check that we serialize *something*.
-      AppendValueToString(eCSSProperty_border_image_source, aValue);
-
-      bool sliceDefault = data->HasDefaultBorderImageSlice();
-      bool widthDefault = data->HasDefaultBorderImageWidth();
-      bool outsetDefault = data->HasDefaultBorderImageOutset();
-
-      if (!sliceDefault || !widthDefault || !outsetDefault) {
-        aValue.Append(char16_t(' '));
-        AppendValueToString(eCSSProperty_border_image_slice, aValue);
-        if (!widthDefault || !outsetDefault) {
-          aValue.AppendLiteral(" /");
-          if (!widthDefault) {
-            aValue.Append(char16_t(' '));
-            AppendValueToString(eCSSProperty_border_image_width, aValue);
-          }
-          if (!outsetDefault) {
-            aValue.AppendLiteral(" / ");
-            AppendValueToString(eCSSProperty_border_image_outset, aValue);
-          }
-        }
-      }
-
-      bool repeatDefault = data->HasDefaultBorderImageRepeat();
-      if (!repeatDefault) {
-        aValue.Append(char16_t(' '));
-        AppendValueToString(eCSSProperty_border_image_repeat, aValue);
-      }
-      break;
-    }
-    case eCSSProperty_border: {
-      // If we have a non-default value for any of the properties that
-      // this shorthand sets but cannot specify, we have to return the
-      // empty string.
-      if (data->ValueFor(eCSSProperty_border_image_source)->GetUnit() !=
-            eCSSUnit_None ||
-          !data->HasDefaultBorderImageSlice() ||
-          !data->HasDefaultBorderImageWidth() ||
-          !data->HasDefaultBorderImageOutset() ||
-          !data->HasDefaultBorderImageRepeat()) {
-        break;
-      }
-
-      const nsCSSPropertyID* subproptables[3] = {
-        nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color),
-        nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_style),
-        nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_width)
-      };
-      bool match = true;
-      for (const nsCSSPropertyID** subprops = subproptables,
-               **subprops_end = ArrayEnd(subproptables);
-           subprops < subprops_end; ++subprops) {
-        const nsCSSValue *firstSide = data->ValueFor((*subprops)[0]);
-        for (int32_t side = 1; side < 4; ++side) {
-          const nsCSSValue *otherSide =
-            data->ValueFor((*subprops)[side]);
-          if (*firstSide != *otherSide)
-            match = false;
-        }
-      }
-      if (!match) {
-        // We can't express what we have in the border shorthand
-        break;
-      }
-      // tweak aProperty and fall through
-      aProperty = eCSSProperty_border_top;
-      MOZ_FALLTHROUGH;
-    }
-    case eCSSProperty_border_top:
-    case eCSSProperty_border_right:
-    case eCSSProperty_border_bottom:
-    case eCSSProperty_border_left:
-    case eCSSProperty_border_inline_start:
-    case eCSSProperty_border_inline_end:
-    case eCSSProperty_border_block_start:
-    case eCSSProperty_border_block_end:
-    case eCSSProperty_column_rule:
-    case eCSSProperty_outline: {
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      MOZ_ASSERT(StringEndsWith(nsCSSProps::GetStringValue(subprops[2]),
-                                NS_LITERAL_CSTRING("-color")),
-                 "third subprop must be the color property");
-
-      bool ok = AppendValueToString(subprops[0], aValue);
-      if (ok) {
-        aValue.Append(u' ');
-        ok = AppendValueToString(subprops[1], aValue);
-        if (ok) {
-          const nsCSSValue *colorValue = data->ValueFor(subprops[2]);
-          bool isCurrentColor =
-            colorValue->GetUnit() == eCSSUnit_EnumColor &&
-            colorValue->GetIntValue() == NS_COLOR_CURRENTCOLOR;
-
-          // Don't output a third value when it's currentcolor.
-          if (!isCurrentColor) {
-            aValue.Append(u' ');
-            ok = AppendValueToString(subprops[2], aValue);
-          }
-        }
-      }
-
-      if (!ok) {
-        aValue.Truncate();
-      }
-      break;
-    }
-    case eCSSProperty_background: {
-      GetImageLayerValue(data, aValue,
-                         nsStyleImageLayers::kBackgroundLayerTable);
-      break;
-    }
-    case eCSSProperty_background_position: {
-      GetImageLayerPositionValue(data, aValue,
-                                 nsStyleImageLayers::kBackgroundLayerTable);
-      break;
-    }
-    case eCSSProperty_mask: {
-      GetImageLayerValue(data, aValue, nsStyleImageLayers::kMaskLayerTable);
-      break;
-    }
-    case eCSSProperty_mask_position: {
-      GetImageLayerPositionValue(data, aValue,
-                                 nsStyleImageLayers::kMaskLayerTable);
-      break;
-    }
-    case eCSSProperty_font: {
-      // systemFont might not be present; other values are guaranteed to be
-      // available based on the shorthand check at the beginning of the
-      // function, as long as the prop is enabled
-      const nsCSSValue *systemFont =
-        data->ValueFor(eCSSProperty__x_system_font);
-      const nsCSSValue *style =
-        data->ValueFor(eCSSProperty_font_style);
-      const nsCSSValue *weight =
-        data->ValueFor(eCSSProperty_font_weight);
-      const nsCSSValue *size =
-        data->ValueFor(eCSSProperty_font_size);
-      const nsCSSValue *lh =
-        data->ValueFor(eCSSProperty_line_height);
-      const nsCSSValue *family =
-        data->ValueFor(eCSSProperty_font_family);
-      const nsCSSValue *stretch =
-        data->ValueFor(eCSSProperty_font_stretch);
-      const nsCSSValue *sizeAdjust =
-        data->ValueFor(eCSSProperty_font_size_adjust);
-      const nsCSSValue *featureSettings =
-        data->ValueFor(eCSSProperty_font_feature_settings);
-      const nsCSSValue *languageOverride =
-        data->ValueFor(eCSSProperty_font_language_override);
-      const nsCSSValue *opticalSizing =
-        data->ValueFor(eCSSProperty_font_optical_sizing); // may be missing!
-      const nsCSSValue *fontKerning =
-        data->ValueFor(eCSSProperty_font_kerning);
-      const nsCSSValue *variationSettings =
-        data->ValueFor(eCSSProperty_font_variation_settings); // may be missing!
-      const nsCSSValue *fontVariantAlternates =
-        data->ValueFor(eCSSProperty_font_variant_alternates);
-      const nsCSSValue *fontVariantCaps =
-        data->ValueFor(eCSSProperty_font_variant_caps);
-      const nsCSSValue *fontVariantEastAsian =
-        data->ValueFor(eCSSProperty_font_variant_east_asian);
-      const nsCSSValue *fontVariantLigatures =
-        data->ValueFor(eCSSProperty_font_variant_ligatures);
-      const nsCSSValue *fontVariantNumeric =
-        data->ValueFor(eCSSProperty_font_variant_numeric);
-      const nsCSSValue *fontVariantPosition =
-        data->ValueFor(eCSSProperty_font_variant_position);
-
-      if (systemFont &&
-          systemFont->GetUnit() != eCSSUnit_None &&
-          systemFont->GetUnit() != eCSSUnit_Null) {
-        if (style->GetUnit() != eCSSUnit_System_Font ||
-            weight->GetUnit() != eCSSUnit_System_Font ||
-            size->GetUnit() != eCSSUnit_System_Font ||
-            lh->GetUnit() != eCSSUnit_System_Font ||
-            family->GetUnit() != eCSSUnit_System_Font ||
-            stretch->GetUnit() != eCSSUnit_System_Font ||
-            sizeAdjust->GetUnit() != eCSSUnit_System_Font ||
-            featureSettings->GetUnit() != eCSSUnit_System_Font ||
-            languageOverride->GetUnit() != eCSSUnit_System_Font ||
-            (opticalSizing && opticalSizing->GetUnit() != eCSSUnit_System_Font) ||
-            fontKerning->GetUnit() != eCSSUnit_System_Font ||
-            (variationSettings && variationSettings->GetUnit() != eCSSUnit_System_Font) ||
-            fontVariantAlternates->GetUnit() != eCSSUnit_System_Font ||
-            fontVariantCaps->GetUnit() != eCSSUnit_System_Font ||
-            fontVariantEastAsian->GetUnit() != eCSSUnit_System_Font ||
-            fontVariantLigatures->GetUnit() != eCSSUnit_System_Font ||
-            fontVariantNumeric->GetUnit() != eCSSUnit_System_Font ||
-            fontVariantPosition->GetUnit() != eCSSUnit_System_Font) {
-          // This can't be represented as a shorthand.
-          return;
-        }
-        systemFont->AppendToString(eCSSProperty__x_system_font, aValue);
-      } else {
-        // properties reset by this shorthand property to their
-        // initial values but not represented in its syntax
-        if (sizeAdjust->GetUnit() != eCSSUnit_None ||
-            featureSettings->GetUnit() != eCSSUnit_Normal ||
-            languageOverride->GetUnit() != eCSSUnit_Normal ||
-            (opticalSizing && opticalSizing->GetIntValue() != NS_FONT_OPTICAL_SIZING_AUTO) ||
-            fontKerning->GetIntValue() != NS_FONT_KERNING_AUTO ||
-            (variationSettings && variationSettings->GetUnit() != eCSSUnit_Normal) ||
-            fontVariantAlternates->GetUnit() != eCSSUnit_Normal ||
-            fontVariantEastAsian->GetUnit() != eCSSUnit_Normal ||
-            fontVariantLigatures->GetUnit() != eCSSUnit_Normal ||
-            fontVariantNumeric->GetUnit() != eCSSUnit_Normal ||
-            fontVariantPosition->GetUnit() != eCSSUnit_Normal) {
-          return;
-        }
-
-        // only a normal or small-caps values of font-variant-caps can
-        // be represented in the font shorthand
-        if (fontVariantCaps->GetUnit() != eCSSUnit_Normal &&
-            (fontVariantCaps->GetUnit() != eCSSUnit_Enumerated ||
-             fontVariantCaps->GetIntValue() != NS_FONT_VARIANT_CAPS_SMALLCAPS)) {
-          return;
-        }
-
-        if (style->GetUnit() != eCSSUnit_Enumerated ||
-            style->GetIntValue() != NS_FONT_STYLE_NORMAL) {
-          style->AppendToString(eCSSProperty_font_style, aValue);
-          aValue.Append(char16_t(' '));
-        }
-        if (fontVariantCaps->GetUnit() != eCSSUnit_Normal) {
-          fontVariantCaps->AppendToString(eCSSProperty_font_variant_caps,
-                                          aValue);
-          aValue.Append(char16_t(' '));
-        }
-        if (weight->GetUnit() != eCSSUnit_Enumerated ||
-            weight->GetIntValue() != NS_FONT_WEIGHT_NORMAL) {
-          weight->AppendToString(eCSSProperty_font_weight, aValue);
-          aValue.Append(char16_t(' '));
-        }
-        if (stretch->GetUnit() != eCSSUnit_Enumerated ||
-            stretch->GetIntValue() != NS_FONT_STRETCH_NORMAL) {
-          stretch->AppendToString(eCSSProperty_font_stretch, aValue);
-          aValue.Append(char16_t(' '));
-        }
-        size->AppendToString(eCSSProperty_font_size, aValue);
-        if (lh->GetUnit() != eCSSUnit_Normal) {
-          aValue.Append(char16_t('/'));
-          lh->AppendToString(eCSSProperty_line_height, aValue);
-        }
-        aValue.Append(char16_t(' '));
-        family->AppendToString(eCSSProperty_font_family, aValue);
-      }
-      break;
-    }
-    case eCSSProperty_font_variant: {
-      const nsCSSPropertyID *subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      const nsCSSValue *fontVariantLigatures =
-        data->ValueFor(eCSSProperty_font_variant_ligatures);
-
-      // all subproperty values normal? system font?
-      bool normalLigs = true, normalNonLigs = true, systemFont = true,
-           hasSystem = false;
-      for (const nsCSSPropertyID *sp = subprops; *sp != eCSSProperty_UNKNOWN; sp++) {
-        const nsCSSValue *spVal = data->ValueFor(*sp);
-        bool isNormal = (spVal->GetUnit() == eCSSUnit_Normal);
-        if (*sp == eCSSProperty_font_variant_ligatures) {
-          normalLigs = normalLigs && isNormal;
-        } else {
-          normalNonLigs = normalNonLigs && isNormal;
-        }
-        bool isSystem = (spVal->GetUnit() == eCSSUnit_System_Font);
-        systemFont = systemFont && isSystem;
-        hasSystem = hasSystem || isSystem;
-      }
-
-      bool ligsNone =
-        fontVariantLigatures->GetUnit() == eCSSUnit_None;
-
-      // normal, none, or system font ==> single value
-      if ((normalLigs && normalNonLigs) ||
-          (normalNonLigs && ligsNone) ||
-          systemFont) {
-        fontVariantLigatures->AppendToString(eCSSProperty_font_variant_ligatures,
-                                             aValue);
-      } else if (ligsNone || hasSystem) {
-        // ligatures none but other values are non-normal ==> empty
-        // at least one but not all values are system font ==> empty
-        return;
-      } else {
-        // iterate over and append non-normal values
-        bool appendSpace = false;
-        for (const nsCSSPropertyID *sp = subprops;
-             *sp != eCSSProperty_UNKNOWN; sp++) {
-          const nsCSSValue *spVal = data->ValueFor(*sp);
-          if (spVal && spVal->GetUnit() != eCSSUnit_Normal) {
-            if (appendSpace) {
-              aValue.Append(char16_t(' '));
-            } else {
-              appendSpace = true;
-            }
-            spVal->AppendToString(*sp, aValue);
-          }
-        }
-      }
-      break;
-    }
-    case eCSSProperty_list_style:
-      if (AppendValueToString(eCSSProperty_list_style_position, aValue)) {
-        aValue.Append(char16_t(' '));
-      }
-      if (AppendValueToString(eCSSProperty_list_style_image, aValue)) {
-        aValue.Append(char16_t(' '));
-      }
-      AppendValueToString(eCSSProperty_list_style_type, aValue);
-      break;
-    case eCSSProperty_overflow: {
-      const nsCSSValue &xValue =
-        *data->ValueFor(eCSSProperty_overflow_x);
-      const nsCSSValue &yValue =
-        *data->ValueFor(eCSSProperty_overflow_y);
-      if (xValue == yValue)
-        xValue.AppendToString(eCSSProperty_overflow_x, aValue);
-      break;
-    }
-    case eCSSProperty_text_decoration: {
-      const nsCSSValue *decorationColor =
-        data->ValueFor(eCSSProperty_text_decoration_color);
-      const nsCSSValue *decorationStyle =
-        data->ValueFor(eCSSProperty_text_decoration_style);
-
-      MOZ_ASSERT(decorationStyle->GetUnit() == eCSSUnit_Enumerated,
-                 "bad text-decoration-style unit");
-
-      AppendValueToString(eCSSProperty_text_decoration_line, aValue);
-      if (decorationStyle->GetIntValue() !=
-            NS_STYLE_TEXT_DECORATION_STYLE_SOLID) {
-        aValue.Append(char16_t(' '));
-        AppendValueToString(eCSSProperty_text_decoration_style, aValue);
-      }
-      if (decorationColor->GetUnit() != eCSSUnit_EnumColor ||
-          decorationColor->GetIntValue() != NS_COLOR_CURRENTCOLOR) {
-        aValue.Append(char16_t(' '));
-        AppendValueToString(eCSSProperty_text_decoration_color, aValue);
-      }
-      break;
-    }
-    case eCSSProperty_transition: {
-      const nsCSSValue *transProp =
-        data->ValueFor(eCSSProperty_transition_property);
-      const nsCSSValue *transDuration =
-        data->ValueFor(eCSSProperty_transition_duration);
-      const nsCSSValue *transTiming =
-        data->ValueFor(eCSSProperty_transition_timing_function);
-      const nsCSSValue *transDelay =
-        data->ValueFor(eCSSProperty_transition_delay);
-
-      MOZ_ASSERT(transDuration->GetUnit() == eCSSUnit_List ||
-                 transDuration->GetUnit() == eCSSUnit_ListDep,
-                 "bad t-duration unit");
-      MOZ_ASSERT(transTiming->GetUnit() == eCSSUnit_List ||
-                 transTiming->GetUnit() == eCSSUnit_ListDep,
-                 "bad t-timing unit");
-      MOZ_ASSERT(transDelay->GetUnit() == eCSSUnit_List ||
-                 transDelay->GetUnit() == eCSSUnit_ListDep,
-                 "bad t-delay unit");
-
-      const nsCSSValueList* dur = transDuration->GetListValue();
-      const nsCSSValueList* tim = transTiming->GetListValue();
-      const nsCSSValueList* del = transDelay->GetListValue();
-
-      if (transProp->GetUnit() == eCSSUnit_None ||
-          transProp->GetUnit() == eCSSUnit_All) {
-        // If any of the other three lists has more than one element,
-        // we can't use the shorthand.
-        if (!dur->mNext && !tim->mNext && !del->mNext) {
-          transProp->AppendToString(eCSSProperty_transition_property, aValue);
-          aValue.Append(char16_t(' '));
-          dur->mValue.AppendToString(eCSSProperty_transition_duration, aValue);
-          aValue.Append(char16_t(' '));
-          tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
-                                     aValue);
-          aValue.Append(char16_t(' '));
-          del->mValue.AppendToString(eCSSProperty_transition_delay, aValue);
-          aValue.Append(char16_t(' '));
-        } else {
-          aValue.Truncate();
-        }
-      } else {
-        MOZ_ASSERT(transProp->GetUnit() == eCSSUnit_List ||
-                   transProp->GetUnit() == eCSSUnit_ListDep,
-                   "bad t-prop unit");
-        const nsCSSValueList* pro = transProp->GetListValue();
-        for (;;) {
-          pro->mValue.AppendToString(eCSSProperty_transition_property, aValue);
-          aValue.Append(char16_t(' '));
-          dur->mValue.AppendToString(eCSSProperty_transition_duration, aValue);
-          aValue.Append(char16_t(' '));
-          tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
-                                     aValue);
-          aValue.Append(char16_t(' '));
-          del->mValue.AppendToString(eCSSProperty_transition_delay,
-                                     aValue);
-          pro = pro->mNext;
-          dur = dur->mNext;
-          tim = tim->mNext;
-          del = del->mNext;
-          if (!pro || !dur || !tim || !del) {
-            break;
-          }
-          aValue.AppendLiteral(", ");
-        }
-        if (pro || dur || tim || del) {
-          // Lists not all the same length, can't use shorthand.
-          aValue.Truncate();
-        }
-      }
-      break;
-    }
-    case eCSSProperty_animation: {
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(eCSSProperty_animation);
-      static const size_t numProps = 8;
-      MOZ_ASSERT(subprops[numProps] == eCSSProperty_UNKNOWN,
-                 "unexpected number of subproperties");
-      const nsCSSValue* values[numProps];
-      const nsCSSValueList* lists[numProps];
-
-      for (uint32_t i = 0; i < numProps; ++i) {
-        values[i] = data->ValueFor(subprops[i]);
-        MOZ_ASSERT(values[i]->GetUnit() == eCSSUnit_List ||
-                   values[i]->GetUnit() == eCSSUnit_ListDep,
-                   "bad a-duration unit");
-        lists[i] = values[i]->GetListValue();
-      }
-
-      for (;;) {
-        // We must serialize 'animation-name' last in case it has
-        // a value that conflicts with one of the other keyword properties.
-        MOZ_ASSERT(subprops[numProps - 1] == eCSSProperty_animation_name,
-                   "animation-name must be last");
-        bool done = false;
-        for (uint32_t i = 0;;) {
-          lists[i]->mValue.AppendToString(subprops[i], aValue);
-          lists[i] = lists[i]->mNext;
-          if (!lists[i]) {
-            done = true;
-          }
-          if (++i == numProps) {
-            break;
-          }
-          aValue.Append(char16_t(' '));
-        }
-        if (done) {
-          break;
-        }
-        aValue.AppendLiteral(", ");
-      }
-      for (uint32_t i = 0; i < numProps; ++i) {
-        if (lists[i]) {
-          // Lists not all the same length, can't use shorthand.
-          aValue.Truncate();
-          break;
-        }
-      }
-      break;
-    }
-    case eCSSProperty_marker: {
-      const nsCSSValue &endValue =
-        *data->ValueFor(eCSSProperty_marker_end);
-      const nsCSSValue &midValue =
-        *data->ValueFor(eCSSProperty_marker_mid);
-      const nsCSSValue &startValue =
-        *data->ValueFor(eCSSProperty_marker_start);
-      if (endValue == midValue && midValue == startValue)
-        AppendValueToString(eCSSProperty_marker_end, aValue);
-      break;
-    }
-    case eCSSProperty_columns: {
-      // Two values, column-count and column-width, separated by a space.
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      AppendValueToString(subprops[0], aValue);
-      aValue.Append(char16_t(' '));
-      AppendValueToString(subprops[1], aValue);
-      break;
-    }
-    case eCSSProperty_flex: {
-      // flex-grow, flex-shrink, flex-basis, separated by single space
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-
-      AppendValueToString(subprops[0], aValue);
-      aValue.Append(char16_t(' '));
-      AppendValueToString(subprops[1], aValue);
-      aValue.Append(char16_t(' '));
-      AppendValueToString(subprops[2], aValue);
-      break;
-    }
-    case eCSSProperty_flex_flow: {
-      // flex-direction, flex-wrap, separated by single space
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      MOZ_ASSERT(subprops[2] == eCSSProperty_UNKNOWN,
-                 "must have exactly two subproperties");
-
-      AppendValueToString(subprops[0], aValue);
-      aValue.Append(char16_t(' '));
-      AppendValueToString(subprops[1], aValue);
-      break;
-    }
-    case eCSSProperty_grid_row:
-    case eCSSProperty_grid_column: {
-      // grid-{row,column}-start, grid-{row,column}-end, separated by a slash
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      MOZ_ASSERT(subprops[2] == eCSSProperty_UNKNOWN,
-                 "must have exactly two subproperties");
-
-      // TODO: should we simplify when possible?
-      AppendValueToString(subprops[0], aValue);
-      aValue.AppendLiteral(" / ");
-      AppendValueToString(subprops[1], aValue);
-      break;
-    }
-    case eCSSProperty_grid_area: {
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      MOZ_ASSERT(subprops[4] == eCSSProperty_UNKNOWN,
-                 "must have exactly four subproperties");
-
-      // TODO: should we simplify when possible?
-      AppendValueToString(subprops[0], aValue);
-      aValue.AppendLiteral(" / ");
-      AppendValueToString(subprops[1], aValue);
-      aValue.AppendLiteral(" / ");
-      AppendValueToString(subprops[2], aValue);
-      aValue.AppendLiteral(" / ");
-      AppendValueToString(subprops[3], aValue);
-      break;
-    }
-
-    // The 'grid' shorthand has 3 different possibilities for syntax:
-    // #1 <'grid-template'>
-    // #2 <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?
-    // #3 [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>
-    case eCSSProperty_grid: {
-      const nsCSSValue& areasValue =
-        *data->ValueFor(eCSSProperty_grid_template_areas);
-      const nsCSSValue& columnsValue =
-        *data->ValueFor(eCSSProperty_grid_template_columns);
-      const nsCSSValue& rowsValue =
-        *data->ValueFor(eCSSProperty_grid_template_rows);
-
-      const nsCSSValue& autoFlowValue =
-        *data->ValueFor(eCSSProperty_grid_auto_flow);
-      const nsCSSValue& autoColumnsValue =
-        *data->ValueFor(eCSSProperty_grid_auto_columns);
-      const nsCSSValue& autoRowsValue =
-        *data->ValueFor(eCSSProperty_grid_auto_rows);
-
-      // grid-template-rows/areas:none + default grid-auto-columns +
-      // non-default row grid-auto-flow or grid-auto-rows.
-      // --> serialize as 'grid' syntax #3.
-      // (for default grid-auto-flow/rows we prefer to serialize to
-      // "none ['/' ...]" instead using syntax #2 or #1 below)
-      if (rowsValue.GetUnit() == eCSSUnit_None &&
-          areasValue.GetUnit() == eCSSUnit_None &&
-          autoColumnsValue.GetUnit() == eCSSUnit_Auto &&
-          autoFlowValue.GetUnit() == eCSSUnit_Enumerated &&
-          (autoFlowValue.GetIntValue() & NS_STYLE_GRID_AUTO_FLOW_ROW) &&
-          (autoFlowValue.GetIntValue() != NS_STYLE_GRID_AUTO_FLOW_ROW ||
-           autoRowsValue.GetUnit() != eCSSUnit_Auto)) {
-        aValue.AppendLiteral("auto-flow");
-        if (autoFlowValue.GetIntValue() & NS_STYLE_GRID_AUTO_FLOW_DENSE) {
-          aValue.AppendLiteral(" dense");
-        }
-        if (autoRowsValue.GetUnit() != eCSSUnit_Auto) {
-          aValue.Append(' ');
-          AppendValueToString(eCSSProperty_grid_auto_rows, aValue);
-        }
-        aValue.AppendLiteral(" / ");
-        AppendValueToString(eCSSProperty_grid_template_columns, aValue);
-        break;
-      }
-
-      // grid-template-columns/areas:none + column grid-auto-flow +
-      // default grid-auto-rows.
-      // --> serialize as 'grid' syntax #2.
-      if (columnsValue.GetUnit() == eCSSUnit_None &&
-          areasValue.GetUnit() == eCSSUnit_None &&
-          autoRowsValue.GetUnit() == eCSSUnit_Auto &&
-          autoFlowValue.GetUnit() == eCSSUnit_Enumerated &&
-          (autoFlowValue.GetIntValue() & NS_STYLE_GRID_AUTO_FLOW_COLUMN)) {
-        AppendValueToString(eCSSProperty_grid_template_rows, aValue);
-        aValue.AppendLiteral(" / auto-flow ");
-        if (autoFlowValue.GetIntValue() & NS_STYLE_GRID_AUTO_FLOW_DENSE) {
-          aValue.AppendLiteral("dense ");
-        }
-        AppendValueToString(eCSSProperty_grid_auto_columns, aValue);
-        break;
-      }
-
-      if (!(autoFlowValue.GetUnit() == eCSSUnit_Enumerated &&
-            autoFlowValue.GetIntValue() == NS_STYLE_GRID_AUTO_FLOW_ROW &&
-            autoColumnsValue.GetUnit() == eCSSUnit_Auto &&
-            autoRowsValue.GetUnit() == eCSSUnit_Auto)) {
-        // Not serializable, bail.
-        return;
-      }
-      // Fall through to eCSSProperty_grid_template (syntax #1)
-      MOZ_FALLTHROUGH;
-    }
-    case eCSSProperty_grid_template: {
-      const nsCSSValue& areasValue =
-        *data->ValueFor(eCSSProperty_grid_template_areas);
-      const nsCSSValue& columnsValue =
-        *data->ValueFor(eCSSProperty_grid_template_columns);
-      const nsCSSValue& rowsValue =
-        *data->ValueFor(eCSSProperty_grid_template_rows);
-      if (areasValue.GetUnit() == eCSSUnit_None) {
-        AppendValueToString(eCSSProperty_grid_template_rows, aValue);
-        aValue.AppendLiteral(" / ");
-        AppendValueToString(eCSSProperty_grid_template_columns, aValue);
-        break;
-      }
-      if (columnsValue.GetUnit() == eCSSUnit_List ||
-          columnsValue.GetUnit() == eCSSUnit_ListDep) {
-        const nsCSSValueList* columnsItem = columnsValue.GetListValue();
-        if (columnsItem->mValue.GetUnit() == eCSSUnit_Enumerated &&
-            columnsItem->mValue.GetIntValue() == NS_STYLE_GRID_TEMPLATE_SUBGRID) {
-          // We have "grid-template-areas:[something]; grid-template-columns:subgrid"
-          // which isn't a value that the shorthand can express. Bail.
-          return;
-        }
-      }
-      if (rowsValue.GetUnit() != eCSSUnit_List &&
-          rowsValue.GetUnit() != eCSSUnit_ListDep) {
-        // We have "grid-template-areas:[something]; grid-template-rows:none"
-        // which isn't a value that the shorthand can express. Bail.
-        return;
-      }
-      const nsCSSValueList* rowsItem = rowsValue.GetListValue();
-      if (rowsItem->mValue.GetUnit() == eCSSUnit_Enumerated &&
-          rowsItem->mValue.GetIntValue() == NS_STYLE_GRID_TEMPLATE_SUBGRID) {
-        // We have "grid-template-areas:[something]; grid-template-rows:subgrid"
-        // which isn't a value that the shorthand can express. Bail.
-        return;
-      }
-      const GridTemplateAreasValue* areas = areasValue.GetGridTemplateAreas();
-      uint32_t nRowItems = 0;
-      while (rowsItem) {
-        nRowItems++;
-        rowsItem = rowsItem->mNext;
-      }
-      MOZ_ASSERT(nRowItems % 2 == 1, "expected an odd number of items");
-      if ((nRowItems - 1) / 2 != areas->NRows()) {
-        // Not serializable, bail.
-        return;
-      }
-      rowsItem = rowsValue.GetListValue();
-      uint32_t row = 0;
-      for (;;) {
-        bool addSpaceSeparator = true;
-        nsCSSUnit unit = rowsItem->mValue.GetUnit();
-
-        if (unit == eCSSUnit_Null) {
-          // Empty or omitted <line-names>. Serializes to nothing.
-          addSpaceSeparator = false;  // Avoid a double space.
-
-        } else if (unit == eCSSUnit_List || unit == eCSSUnit_ListDep) {
-          // Non-empty <line-names>
-          aValue.Append('[');
-          rowsItem->mValue.AppendToString(eCSSProperty_grid_template_rows,
-                                          aValue);
-          aValue.Append(']');
-
-        } else {
-          nsStyleUtil::AppendEscapedCSSString(areas->mTemplates[row++], aValue);
-          aValue.Append(char16_t(' '));
-
-          // <track-size>
-          if (unit == eCSSUnit_Pair) {
-            // 'repeat()' isn't allowed with non-default 'grid-template-areas'.
-            aValue.Truncate();
-            return;
-          }
-          rowsItem->mValue.AppendToString(eCSSProperty_grid_template_rows,
-                                          aValue);
-          if (rowsItem->mNext &&
-              rowsItem->mNext->mValue.GetUnit() == eCSSUnit_Null &&
-              !rowsItem->mNext->mNext) {
-            // Break out of the loop early to avoid a trailing space.
-            break;
-          }
-        }
-
-        rowsItem = rowsItem->mNext;
-        if (!rowsItem) {
-          break;
-        }
-
-        if (addSpaceSeparator) {
-          aValue.Append(char16_t(' '));
-        }
-      }
-      if (columnsValue.GetUnit() != eCSSUnit_None) {
-        const nsCSSValueList* colsItem = columnsValue.GetListValue();
-        colsItem = colsItem->mNext; // first value is <line-names>
-        for (; colsItem; colsItem = colsItem->mNext) {
-          if (colsItem->mValue.GetUnit() == eCSSUnit_Pair) {
-            // 'repeat()' isn't allowed with non-default 'grid-template-areas'.
-            aValue.Truncate();
-            return;
-          }
-          colsItem = colsItem->mNext; // skip <line-names>
-        }
-        aValue.AppendLiteral(" / ");
-        AppendValueToString(eCSSProperty_grid_template_columns, aValue);
-      }
-      break;
-    }
-    case eCSSProperty_place_content:
-    case eCSSProperty_place_items:
-    case eCSSProperty_place_self: {
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      MOZ_ASSERT(subprops[2] == eCSSProperty_UNKNOWN,
-                 "must have exactly two subproperties");
-      auto IsSingleValue = [] (const nsCSSValue& aValue) {
-        switch (aValue.GetUnit()) {
-          case eCSSUnit_Auto:
-          case eCSSUnit_Inherit:
-          case eCSSUnit_Initial:
-          case eCSSUnit_Unset:
-            return true;
-          case eCSSUnit_Enumerated:
-            // return false if there is a fallback value or <overflow-position>
-            return aValue.GetIntValue() <= NS_STYLE_JUSTIFY_SPACE_EVENLY;
-          default:
-            MOZ_ASSERT_UNREACHABLE("Unexpected unit for CSS Align property val");
-            return false;
-        }
-      };
-      // Each value must be a single value (i.e. no fallback value and no
-      // <overflow-position>), otherwise it can't be represented as a shorthand
-      // value. ('first|last baseline' counts as a single value)
-      const nsCSSValue* align = data->ValueFor(subprops[0]);
-      const nsCSSValue* justify = data->ValueFor(subprops[1]);
-      if (!align || !IsSingleValue(*align) ||
-          !justify || !IsSingleValue(*justify)) {
-        return; // Not serializable, bail.
-      }
-      MOZ_FALLTHROUGH;
-    }
-    case eCSSProperty_overflow_clip_box:
-    case eCSSProperty_grid_gap: {
-      const nsCSSPropertyID* subprops =
-        nsCSSProps::SubpropertyEntryFor(aProperty);
-      MOZ_ASSERT(subprops[2] == eCSSProperty_UNKNOWN,
-                 "must have exactly two subproperties");
-
-      nsAutoString val1, val2;
-      AppendValueToString(subprops[0], val1);
-      AppendValueToString(subprops[1], val2);
-      if (val1 == val2) {
-        aValue.Append(val1);
-      } else {
-        aValue.Append(val1);
-        aValue.Append(' ');
-        aValue.Append(val2);
-      }
-      break;
-    }
-    case eCSSProperty_text_emphasis: {
-      const nsCSSValue* emphasisStyle =
-        data->ValueFor(eCSSProperty_text_emphasis_style);
-      const nsCSSValue* emphasisColor =
-        data->ValueFor(eCSSProperty_text_emphasis_color);
-      bool isDefaultColor = emphasisColor->GetUnit() == eCSSUnit_EnumColor &&
-        emphasisColor->GetIntValue() == NS_COLOR_CURRENTCOLOR;
-
-      if (emphasisStyle->GetUnit() != eCSSUnit_None || isDefaultColor) {
-        AppendValueToString(eCSSProperty_text_emphasis_style, aValue);
-        if (!isDefaultColor) {
-          aValue.Append(char16_t(' '));
-        }
-      }
-      if (!isDefaultColor) {
-        AppendValueToString(eCSSProperty_text_emphasis_color, aValue);
-      }
-      break;
-    }
-    case eCSSProperty_overscroll_behavior: {
-      const nsCSSValue& xValue =
-        *data->ValueFor(eCSSProperty_overscroll_behavior_x);
-      const nsCSSValue& yValue =
-        *data->ValueFor(eCSSProperty_overscroll_behavior_y);
-      AppendValueToString(eCSSProperty_overscroll_behavior_x, aValue);
-      if (yValue != xValue) {
-        aValue.Append(char16_t(' '));
-        AppendValueToString(eCSSProperty_overscroll_behavior_y, aValue);
-      }
-      break;
-    }
-    case eCSSProperty_scroll_snap_type: {
-      const nsCSSValue& xValue =
-        *data->ValueFor(eCSSProperty_scroll_snap_type_x);
-      const nsCSSValue& yValue =
-        *data->ValueFor(eCSSProperty_scroll_snap_type_y);
-      if (xValue == yValue) {
-        AppendValueToString(eCSSProperty_scroll_snap_type_x, aValue);
-      }
-      // If scroll-snap-type-x and scroll-snap-type-y are not equal,
-      // we don't have a shorthand that can express. Bail.
-      break;
-    }
-    case eCSSProperty__webkit_text_stroke: {
-      const nsCSSValue* strokeWidth =
-        data->ValueFor(eCSSProperty__webkit_text_stroke_width);
-      const nsCSSValue* strokeColor =
-        data->ValueFor(eCSSProperty__webkit_text_stroke_color);
-      bool isDefaultColor = strokeColor->GetUnit() == eCSSUnit_EnumColor &&
-        strokeColor->GetIntValue() == NS_COLOR_CURRENTCOLOR;
-
-      if (strokeWidth->GetUnit() != eCSSUnit_Integer ||
-          strokeWidth->GetIntValue() != 0 || isDefaultColor) {
-        AppendValueToString(eCSSProperty__webkit_text_stroke_width, aValue);
-        if (!isDefaultColor) {
-          aValue.Append(char16_t(' '));
-        }
-      }
-      if (!isDefaultColor) {
-        AppendValueToString(eCSSProperty__webkit_text_stroke_color, aValue);
-      }
-      break;
-    }
-    case eCSSProperty_all:
-      // If we got here, then we didn't have all "inherit" or "initial" or
-      // "unset" values for all of the longhand property components of 'all'.
-      // There is no other possible value that is valid for all properties,
-      // so serialize as the empty string.
-      break;
-    default:
-      MOZ_ASSERT(false, "no other shorthands");
-      break;
-  }
-}
-
-bool
-Declaration::GetPropertyIsImportantByID(nsCSSPropertyID aProperty) const
-{
-  if (!mImportantData)
-    return false;
-
-  // Calling ValueFor is inefficient, but we can assume '!important' is rare.
-
-  if (!nsCSSProps::IsShorthand(aProperty)) {
-    return mImportantData->ValueFor(aProperty) != nullptr;
-  }
-
-  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
-                                       CSSEnabledState::eForAllContent) {
-    if (*p == eCSSProperty__x_system_font) {
-      // The system_font subproperty doesn't count.
-      continue;
-    }
-    if (!mImportantData->ValueFor(*p)) {
-      return false;
-    }
-  }
-  return true;
-}
-
-void
-Declaration::AppendPropertyAndValueToString(nsCSSPropertyID aProperty,
-                                            nsAString& aResult,
-                                            nsAutoString& aValue,
-                                            bool aValueIsTokenStream) const
-{
-  MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT,
-             "property enum out of range");
-  MOZ_ASSERT((aProperty < eCSSProperty_COUNT_no_shorthands) == aValue.IsEmpty(),
-             "aValue should be given for shorthands but not longhands");
-  AppendASCIItoUTF16(nsCSSProps::GetStringValue(aProperty), aResult);
-  if (aValue.IsEmpty()) {
-    AppendValueToString(aProperty, aValue, &aValueIsTokenStream);
-  }
-  aResult.Append(':');
-  if (!aValueIsTokenStream) {
-    aResult.Append(' ');
-  }
-  aResult.Append(aValue);
-  if (GetPropertyIsImportantByID(aProperty)) {
-    if (!aValueIsTokenStream) {
-      aResult.Append(' ');
-    }
-    aResult.AppendLiteral("!important");
-  }
-  aResult.AppendLiteral("; ");
-}
-
-void
-Declaration::AppendVariableAndValueToString(const nsAString& aName,
-                                            nsAString& aResult) const
-{
-  nsAutoString localName;
-  localName.AppendLiteral("--");
-  localName.Append(aName);
-  nsStyleUtil::AppendEscapedCSSIdent(localName, aResult);
-  CSSVariableDeclarations::Type type;
-  nsString value;
-  bool important;
-
-  if (mImportantVariables && mImportantVariables->Get(aName, type, value)) {
-    important = true;
-  } else {
-    MOZ_ASSERT(mVariables);
-    MOZ_ASSERT(mVariables->Has(aName));
-    mVariables->Get(aName, type, value);
-    important = false;
-  }
-
-  bool isTokenStream = type == CSSVariableDeclarations::eTokenStream;
-  aResult.Append(':');
-  if (!isTokenStream) {
-    aResult.Append(' ');
-  }
-  switch (type) {
-    case CSSVariableDeclarations::eTokenStream:
-      aResult.Append(value);
-      break;
-
-    case CSSVariableDeclarations::eInitial:
-      aResult.AppendLiteral("initial");
-      break;
-
-    case CSSVariableDeclarations::eInherit:
-      aResult.AppendLiteral("inherit");
-      break;
-
-    case CSSVariableDeclarations::eUnset:
-      aResult.AppendLiteral("unset");
-      break;
-
-    default:
-      MOZ_ASSERT(false, "unexpected variable value type");
-  }
-
-  if (important) {
-    if (!isTokenStream) {
-      aResult.Append(' ');
-    }
-    aResult.AppendLiteral("!important");
-  }
-  aResult.AppendLiteral("; ");
-}
-