From f7522ae728c182ce1efe1c9b9aa645c13545960b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 20 Mar 2018 18:04:19 +0100 Subject: [PATCH] Bug 1447358: Unifdef the old style system code. r=jwatt Summary: This has been automatically generated using: http://dotat.at/prog/unifdef/ And: find $OBJDIR -type f -name '*.h' | while read FILE; do echo "$FILE" unifdef -m -DMOZ_STYLO -UMOZ_OLD_STYLE "$FILE"; done find $OBJDIR -type f -name '*.cpp' | while read FILE; do echo "$FILE" unifdef -m -DMOZ_STYLO -UMOZ_OLD_STYLE "$FILE"; done MozReview-Commit-ID: I4NdKqbMXzJ Reviewers: jwatt Bug #: 1447358 Differential Revision: https://phabricator.services.mozilla.com/D779 --- dom/animation/Animation.cpp | 7 - dom/animation/EffectCompositor.cpp | 325 - dom/animation/EffectCompositor.h | 106 - dom/animation/EffectSet.h | 21 - dom/animation/KeyframeEffectReadOnly.cpp | 320 - dom/animation/KeyframeEffectReadOnly.h | 63 - dom/animation/KeyframeUtils.cpp | 176 - dom/animation/TimingParams.cpp | 56 - dom/base/DOMIntersectionObserver.cpp | 21 - dom/base/DOMMatrix.cpp | 33 - dom/base/Element.cpp | 48 - dom/base/Element.h | 6 - dom/base/FragmentOrElement.cpp | 4 - dom/base/ResponsiveImageSelector.cpp | 38 - dom/base/ResponsiveImageSelector.h | 5 - dom/base/StyleSheetList.cpp | 3 - dom/base/nsAttrAndChildArray.cpp | 12 - dom/base/nsAttrAndChildArray.h | 3 - dom/base/nsAttrValue.cpp | 7 - dom/base/nsDOMWindowUtils.cpp | 36 - dom/base/nsDocument.cpp | 29 - dom/base/nsIDocument.h | 13 - dom/base/nsINode.cpp | 183 - dom/base/nsINode.h | 8 - dom/base/nsMappedAttributeElement.cpp | 8 - dom/base/nsMappedAttributeElement.h | 3 - dom/base/nsMappedAttributes.cpp | 61 - dom/base/nsMappedAttributes.h | 20 - dom/base/nsTreeSanitizer.cpp | 26 - dom/base/nsTreeSanitizer.h | 3 - dom/canvas/CanvasRenderingContext2D.cpp | 278 - dom/html/HTMLBodyElement.cpp | 3 - dom/html/HTMLBodyElement.h | 3 - dom/html/HTMLHRElement.h | 3 - dom/html/HTMLOptionsCollection.cpp | 3 - dom/html/HTMLSpanElement.h | 3 - dom/html/HTMLTableCellElement.cpp | 18 - dom/html/HTMLTableCellElement.h | 3 - dom/html/HTMLTrackElement.cpp | 3 - dom/html/nsGenericHTMLElement.cpp | 35 - dom/ipc/ContentParent.cpp | 4 - dom/mathml/nsMathMLElement.cpp | 3 - dom/smil/nsSMILCSSProperty.cpp | 8 - dom/smil/nsSMILCSSValueType.cpp | 265 - dom/svg/nsSVGElement.cpp | 49 - dom/svg/nsSVGElement.h | 4 - dom/xbl/nsBindingManager.cpp | 76 - dom/xbl/nsBindingManager.h | 9 - dom/xbl/nsXBLBinding.cpp | 12 - dom/xbl/nsXBLBinding.h | 6 - dom/xbl/nsXBLPrototypeBinding.cpp | 14 - dom/xbl/nsXBLPrototypeBinding.h | 3 - dom/xbl/nsXBLPrototypeResources.cpp | 38 - dom/xbl/nsXBLPrototypeResources.h | 14 - dom/xbl/nsXBLResourceLoader.cpp | 13 - dom/xul/nsXULElement.cpp | 19 - dom/xul/nsXULElement.h | 3 - editor/libeditor/CSSEditUtils.cpp | 3 - editor/libeditor/HTMLEditor.cpp | 4 - gfx/layers/AnimationHelper.cpp | 75 - gfx/layers/apz/util/ActiveElementManager.cpp | 3 - layout/base/PresShell.cpp | 53 - layout/base/PresShell.h | 3 - layout/base/RestyleLogging.h | 3 - layout/base/RestyleManager.cpp | 160 - layout/base/RestyleManagerInlines.h | 3 - layout/base/nsCSSFrameConstructor.cpp | 245 - layout/base/nsCSSFrameConstructor.h | 21 - layout/base/nsDocumentViewer.cpp | 4 - layout/base/nsLayoutUtils.cpp | 39 - layout/base/nsLayoutUtils.h | 21 - layout/base/nsPresArena.cpp | 3 - layout/base/nsPresContext.cpp | 73 - layout/base/nsRefreshDriver.cpp | 3 - layout/base/nsStyleSheetService.cpp | 36 - layout/base/nsStyleSheetService.h | 9 - layout/build/nsLayoutModule.cpp | 3 - layout/build/nsLayoutStatics.cpp | 19 - layout/forms/nsMeterFrame.cpp | 3 - layout/forms/nsNumberControlFrame.cpp | 3 - layout/forms/nsProgressFrame.cpp | 3 - layout/generic/nsFirstLetterFrame.cpp | 4 - layout/generic/nsFrame.cpp | 29 - layout/generic/nsGridContainerFrame.cpp | 3 - layout/inspector/InspectorFontFace.cpp | 3 - layout/inspector/InspectorUtils.cpp | 63 - layout/mathml/nsMathMLTokenFrame.cpp | 3 - layout/painting/nsDisplayList.cpp | 13 - layout/style/AnimationCollection.cpp | 9 - layout/style/AnimationCollection.h | 14 - layout/style/CSS.cpp | 13 - layout/style/CSSKeyframesRule.cpp | 9 - layout/style/CSSKeyframesRule.h | 4 - layout/style/CSSStyleSheet.cpp | 3 - layout/style/CounterStyleManager.cpp | 3 - layout/style/DeclarationBlockInlines.h | 12 - layout/style/FontFace.cpp | 14 - layout/style/FontFaceSet.cpp | 61 - layout/style/GenericSpecifiedValuesInlines.h | 25 - layout/style/GroupRule.cpp | 232 - layout/style/GroupRule.h | 81 - layout/style/Loader.cpp | 56 - layout/style/Loader.h | 7 - layout/style/MediaList.cpp | 10 - layout/style/RuleNodeCacheConditions.h | 145 - layout/style/ServoBindings.cpp | 15 - layout/style/ServoDocumentRule.cpp | 11 - layout/style/ServoDocumentRule.h | 4 - layout/style/ServoMediaRule.cpp | 11 - layout/style/ServoMediaRule.h | 4 - layout/style/ServoStyleContext.cpp | 3 - layout/style/ServoStyleSet.cpp | 3 - layout/style/ServoSupportsRule.cpp | 11 - layout/style/ServoSupportsRule.h | 4 - layout/style/ServoUtils.h | 36 - layout/style/StyleAnimationValue.cpp | 5328 ----------------- layout/style/StyleAnimationValue.h | 556 -- layout/style/StyleRule.h | 7 - layout/style/StyleSetHandle.h | 32 - layout/style/StyleSetHandleInlines.h | 60 - layout/style/StyleSheet.cpp | 29 - layout/style/StyleSheetInlines.h | 3 - layout/style/nsAnimationManager.cpp | 475 -- layout/style/nsAnimationManager.h | 12 - layout/style/nsCSSCounterStyleRule.cpp | 17 - layout/style/nsCSSParser.h | 347 -- layout/style/nsCSSValue.cpp | 3 - layout/style/nsComputedDOMStyle.cpp | 264 - layout/style/nsDOMCSSAttrDeclaration.cpp | 9 - layout/style/nsDOMCSSDeclaration.cpp | 51 - layout/style/nsFontFaceLoader.h | 3 - layout/style/nsHTMLCSSStyleSheet.cpp | 151 - layout/style/nsHTMLCSSStyleSheet.h | 40 - layout/style/nsHTMLStyleSheet.cpp | 429 -- layout/style/nsHTMLStyleSheet.h | 141 - layout/style/nsLayoutStylesheetCache.cpp | 9 - layout/style/nsMediaFeatures.cpp | 3 - layout/style/nsRuleProcessorData.h | 506 -- layout/style/nsStyleContext.cpp | 103 - layout/style/nsStyleContext.h | 19 - layout/style/nsStyleContextInlines.h | 68 - layout/style/nsStyleStruct.cpp | 3 - layout/style/nsStyleStruct.h | 6 - layout/style/nsStyleTransformMatrix.cpp | 26 - layout/style/nsTransitionManager.cpp | 259 - layout/style/nsTransitionManager.h | 46 - layout/style/test/gtest/StyloParsingBench.cpp | 25 - layout/svg/nsCSSClipPathInstance.cpp | 3 - layout/svg/nsSVGIntegrationUtils.cpp | 3 - layout/tables/nsTableColGroupFrame.cpp | 19 - layout/xul/nsSplitterFrame.cpp | 14 - layout/xul/tree/nsTreeBodyFrame.cpp | 3 - layout/xul/tree/nsTreeStyleCache.cpp | 3 - 153 files changed, 13321 deletions(-) diff --git a/dom/animation/Animation.cpp b/dom/animation/Animation.cpp index 9ce99c645811..afb728174c52 100644 --- a/dom/animation/Animation.cpp +++ b/dom/animation/Animation.cpp @@ -1657,13 +1657,6 @@ Animation::IsRunningOnCompositor() const mEffect->AsKeyframeEffect()->IsRunningOnCompositor(); } -#ifdef MOZ_OLD_STYLE -template -void -Animation::ComposeStyle&>( - RefPtr& aAnimationRule, - const nsCSSPropertyIDSet& aPropertiesToSkip); -#endif template void diff --git a/dom/animation/EffectCompositor.cpp b/dom/animation/EffectCompositor.cpp index 6f9b38419f51..67dc50248b9e 100644 --- a/dom/animation/EffectCompositor.cpp +++ b/dom/animation/EffectCompositor.cpp @@ -18,9 +18,6 @@ #include "mozilla/AnimationUtils.h" #include "mozilla/AutoRestore.h" #include "mozilla/EffectSet.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoStyleContext.h" -#endif #include "mozilla/LayerAnimationInfo.h" #include "mozilla/RestyleManager.h" #include "mozilla/RestyleManagerInlines.h" @@ -36,10 +33,6 @@ #include "nsIPresShell.h" #include "nsIPresShellInlines.h" #include "nsLayoutUtils.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" // For nsRuleNode::ComputePropertiesOverridingAnimation -#include "nsRuleProcessorData.h" // For ElementRuleProcessorData etc. -#endif #include "nsStyleContextInlines.h" #include "nsTArray.h" #include "PendingAnimationTracker.h" @@ -415,81 +408,6 @@ EffectCompositor::UpdateEffectProperties(StyleType* aStyleType, } } -#ifdef MOZ_OLD_STYLE -void -EffectCompositor::MaybeUpdateAnimationRule(dom::Element* aElement, - CSSPseudoElementType aPseudoType, - CascadeLevel aCascadeLevel, - nsStyleContext* aStyleContext) -{ - // First update cascade results since that may cause some elements to - // be marked as needing a restyle. - MaybeUpdateCascadeResults(StyleBackendType::Gecko, - aElement, aPseudoType, - aStyleContext); - - auto& elementsToRestyle = mElementsToRestyle[aCascadeLevel]; - PseudoElementHashEntry::KeyType key = { aElement, aPseudoType }; - - if (!elementsToRestyle.Contains(key)) { - return; - } - - ComposeAnimationRule(aElement, aPseudoType, aCascadeLevel); - - elementsToRestyle.Remove(key); -} - -nsIStyleRule* -EffectCompositor::GetAnimationRule(dom::Element* aElement, - CSSPseudoElementType aPseudoType, - CascadeLevel aCascadeLevel, - nsStyleContext* aStyleContext) -{ - // NOTE: We need to be careful about early returns in this method where - // we *don't* update mElementsToRestyle. When we get a call to - // RequestRestyle that results in a call to PostRestyleForAnimation, we - // will set a bool flag in mElementsToRestyle indicating that we've - // called PostRestyleForAnimation so we don't need to call it again - // until that restyle happens. During that restyle, if we arrive here - // and *don't* update mElementsToRestyle we'll continue to skip calling - // PostRestyleForAnimation from RequestRestyle. - - if (!mPresContext || !mPresContext->IsDynamic()) { - // For print or print preview, ignore animations. - return nullptr; - } - - MOZ_ASSERT(mPresContext->RestyleManager()->IsGecko(), - "stylo: Servo-backed style system should not be using " - "EffectCompositor"); - if (mPresContext->RestyleManager()->AsGecko()->SkipAnimationRules()) { - // We don't need to worry about updating mElementsToRestyle in this case - // since this is not the animation restyle we requested when we called - // PostRestyleForAnimation (see comment at start of this method). - return nullptr; - } - - MaybeUpdateAnimationRule(aElement, aPseudoType, aCascadeLevel, aStyleContext); - -#ifdef DEBUG - { - auto& elementsToRestyle = mElementsToRestyle[aCascadeLevel]; - PseudoElementHashEntry::KeyType key = { aElement, aPseudoType }; - MOZ_ASSERT(!elementsToRestyle.Contains(key), - "Element should no longer require a restyle after its " - "animation rule has been updated"); - } -#endif - - EffectSet* effectSet = EffectSet::GetEffectSet(aElement, aPseudoType); - if (!effectSet) { - return nullptr; - } - - return effectSet->AnimationRule(aCascadeLevel); -} -#endif namespace { class EffectCompositeOrderComparator { @@ -590,73 +508,6 @@ EffectCompositor::HasPendingStyleUpdates() const return false; } -#ifdef MOZ_OLD_STYLE -bool -EffectCompositor::HasThrottledStyleUpdates() const -{ - for (auto& elementSet : mElementsToRestyle) { - for (auto iter = elementSet.ConstIter(); !iter.Done(); iter.Next()) { - if (!iter.Data()) { - return true; - } - } - } - - return false; -} - -void -EffectCompositor::AddStyleUpdatesTo(RestyleTracker& aTracker) -{ - if (!mPresContext) { - return; - } - - for (size_t i = 0; i < kCascadeLevelCount; i++) { - CascadeLevel cascadeLevel = CascadeLevel(i); - auto& elementSet = mElementsToRestyle[cascadeLevel]; - - // Copy the list of elements to restyle to a separate array that we can - // iterate over. This is because we need to call MaybeUpdateCascadeResults - // on each element, but doing that can mutate elementSet. In this case - // it will only mutate the bool value associated with each element in the - // set but even doing that will cause assertions in PLDHashTable to fail - // if we are iterating over the hashtable at the same time. - nsTArray elementsToRestyle( - elementSet.Count()); - for (auto iter = elementSet.Iter(); !iter.Done(); iter.Next()) { - // Skip animations on elements that have been orphaned since they - // requested a restyle. - if (iter.Key().mElement->IsInComposedDoc()) { - elementsToRestyle.AppendElement(iter.Key()); - } - } - - for (auto& pseudoElem : elementsToRestyle) { - MaybeUpdateCascadeResults(StyleBackendType::Gecko, - pseudoElem.mElement, - pseudoElem.mPseudoType, - nullptr); - - ComposeAnimationRule(pseudoElem.mElement, - pseudoElem.mPseudoType, - cascadeLevel); - - dom::Element* elementToRestyle = - GetElementToRestyle(pseudoElem.mElement, pseudoElem.mPseudoType); - if (elementToRestyle) { - nsRestyleHint rshint = cascadeLevel == CascadeLevel::Transitions ? - eRestyle_CSSTransitions : - eRestyle_CSSAnimations; - aTracker.AddPendingRestyle(elementToRestyle, rshint, nsChangeHint(0)); - } - } - - elementSet.Clear(); - // Note: mElement pointers in elementsToRestyle might now dangle - } -} -#endif /* static */ bool EffectCompositor::HasAnimationsForCompositor(const nsIFrame* aFrame, @@ -749,47 +600,6 @@ EffectCompositor::GetAnimationElementAndPseudoForFrame(const nsIFrame* aFrame) return result; } -#ifdef MOZ_OLD_STYLE -/* static */ void -EffectCompositor::ComposeAnimationRule(dom::Element* aElement, - CSSPseudoElementType aPseudoType, - CascadeLevel aCascadeLevel) -{ - EffectSet* effects = EffectSet::GetEffectSet(aElement, aPseudoType); - if (!effects) { - return; - } - - // The caller is responsible for calling MaybeUpdateCascadeResults first. - MOZ_ASSERT(!effects->CascadeNeedsUpdate(), - "Animation cascade out of date when composing animation rule"); - - // Get a list of effects sorted by composite order. - nsTArray sortedEffectList(effects->Count()); - for (KeyframeEffectReadOnly* effect : *effects) { - sortedEffectList.AppendElement(effect); - } - sortedEffectList.Sort(EffectCompositeOrderComparator()); - - RefPtr& animRule = effects->AnimationRule(aCascadeLevel); - animRule = nullptr; - - // If multiple animations affect the same property, animations with higher - // composite order (priority) override or add or animations with lower - // priority except properties in propertiesToSkip. - const nsCSSPropertyIDSet& propertiesToSkip = - aCascadeLevel == CascadeLevel::Animations - ? effects->PropertiesForAnimationsLevel().Inverse() - : effects->PropertiesForAnimationsLevel(); - for (KeyframeEffectReadOnly* effect : sortedEffectList) { - effect->GetAnimation()->WillComposeStyle(); - effect->GetAnimation()->ComposeStyle(animRule, propertiesToSkip); - } - - MOZ_ASSERT(effects == EffectSet::GetEffectSet(aElement, aPseudoType), - "EffectSet should not change while composing style"); -} -#endif /* static */ nsCSSPropertyIDSet EffectCompositor::GetOverriddenProperties(StyleBackendType aBackendType, @@ -806,20 +616,7 @@ EffectCompositor::GetOverriddenProperties(StyleBackendType aBackendType, Element* elementToRestyle = GetElementToRestyle(aElement, aPseudoType); if (aBackendType == StyleBackendType::Gecko && !aStyleContext) { -#ifdef MOZ_OLD_STYLE - if (elementToRestyle) { - nsIFrame* frame = elementToRestyle->GetPrimaryFrame(); - if (frame) { - aStyleContext = frame->StyleContext(); - } - } - - if (!aStyleContext) { - return result; - } -#else MOZ_CRASH("old style system disabled"); -#endif } else if (aBackendType == StyleBackendType::Servo && !elementToRestyle) { return result; } @@ -855,13 +652,7 @@ EffectCompositor::GetOverriddenProperties(StyleBackendType aBackendType, &result); break; case StyleBackendType::Gecko: -#ifdef MOZ_OLD_STYLE - nsRuleNode::ComputePropertiesOverridingAnimation(propertiesToTrack, - aStyleContext->AsGecko(), - result); -#else MOZ_CRASH("old style system disabled"); -#endif break; default: @@ -1237,122 +1028,6 @@ EffectCompositor::PreTraverse(dom::Element* aElement, return found; } -#ifdef MOZ_OLD_STYLE -// --------------------------------------------------------- -// -// Nested class: AnimationStyleRuleProcessor -// -// --------------------------------------------------------- - -NS_IMPL_ISUPPORTS(EffectCompositor::AnimationStyleRuleProcessor, - nsIStyleRuleProcessor) - -nsRestyleHint -EffectCompositor::AnimationStyleRuleProcessor::HasStateDependentStyle( - StateRuleProcessorData* aData) -{ - return nsRestyleHint(0); -} - -nsRestyleHint -EffectCompositor::AnimationStyleRuleProcessor::HasStateDependentStyle( - PseudoElementStateRuleProcessorData* aData) -{ - return nsRestyleHint(0); -} - -bool -EffectCompositor::AnimationStyleRuleProcessor::HasDocumentStateDependentStyle( - StateRuleProcessorData* aData) -{ - return false; -} - -nsRestyleHint -EffectCompositor::AnimationStyleRuleProcessor::HasAttributeDependentStyle( - AttributeRuleProcessorData* aData, - RestyleHintData& aRestyleHintDataResult) -{ - return nsRestyleHint(0); -} - -bool -EffectCompositor::AnimationStyleRuleProcessor::MediumFeaturesChanged( - nsPresContext* aPresContext) -{ - return false; -} - -void -EffectCompositor::AnimationStyleRuleProcessor::RulesMatching( - ElementRuleProcessorData* aData) -{ - nsIStyleRule *rule = - mCompositor->GetAnimationRule(aData->mElement, - CSSPseudoElementType::NotPseudo, - mCascadeLevel, - nullptr); - if (rule) { - aData->mRuleWalker->Forward(rule); - aData->mRuleWalker->CurrentNode()->SetIsAnimationRule(); - } -} - -void -EffectCompositor::AnimationStyleRuleProcessor::RulesMatching( - PseudoElementRuleProcessorData* aData) -{ - if (aData->mPseudoType != CSSPseudoElementType::before && - aData->mPseudoType != CSSPseudoElementType::after) { - return; - } - - nsIStyleRule *rule = - mCompositor->GetAnimationRule(aData->mElement, - aData->mPseudoType, - mCascadeLevel, - nullptr); - if (rule) { - aData->mRuleWalker->Forward(rule); - aData->mRuleWalker->CurrentNode()->SetIsAnimationRule(); - } -} - -void -EffectCompositor::AnimationStyleRuleProcessor::RulesMatching( - AnonBoxRuleProcessorData* aData) -{ -} - -#ifdef MOZ_XUL -void -EffectCompositor::AnimationStyleRuleProcessor::RulesMatching( - XULTreeRuleProcessorData* aData) -{ -} -#endif - -size_t -EffectCompositor::AnimationStyleRuleProcessor::SizeOfExcludingThis( - MallocSizeOf aMallocSizeOf) const -{ - return 0; -} - -size_t -EffectCompositor::AnimationStyleRuleProcessor::SizeOfIncludingThis( - MallocSizeOf aMallocSizeOf) const -{ - return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); -} - -template -void -EffectCompositor::UpdateEffectProperties( - GeckoStyleContext* aStyleContext, - Element* aElement, - CSSPseudoElementType aPseudoType); -#endif template void diff --git a/dom/animation/EffectCompositor.h b/dom/animation/EffectCompositor.h index c0f5980bffb3..b63b65d68b5d 100644 --- a/dom/animation/EffectCompositor.h +++ b/dom/animation/EffectCompositor.h @@ -16,9 +16,6 @@ #include "nsCSSPropertyID.h" #include "nsCycleCollectionParticipant.h" #include "nsDataHashtable.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRuleProcessor.h" -#endif #include "nsTArray.h" class nsCSSPropertyIDSet; @@ -50,13 +47,6 @@ public: explicit EffectCompositor(nsPresContext* aPresContext) : mPresContext(aPresContext) { -#ifdef MOZ_OLD_STYLE - for (size_t i = 0; i < kCascadeLevelCount; i++) { - CascadeLevel cascadeLevel = CascadeLevel(i); - mRuleProcessors[cascadeLevel] = - new AnimationStyleRuleProcessor(this, cascadeLevel); - } -#endif } NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(EffectCompositor) @@ -134,36 +124,6 @@ public: dom::Element* aElement, CSSPseudoElementType aPseudoType); -#ifdef MOZ_OLD_STYLE - // Updates the animation rule stored on the EffectSet for the - // specified (pseudo-)element for cascade level |aLevel|. - // If the animation rule is not marked as needing an update, - // no work is done. - // |aStyleContext| is used for UpdateCascadingResults. - // |aStyleContext| can be nullptr if style context, which is associated with - // the primary frame of the specified (pseudo-)element, is the current style - // context. - // If we are resolving a new style context, we shoud pass the newly created - // style context, otherwise we may use an old style context, it will result - // unexpected cascading results. - void MaybeUpdateAnimationRule(dom::Element* aElement, - CSSPseudoElementType aPseudoType, - CascadeLevel aCascadeLevel, - nsStyleContext *aStyleContext); - - // We need to pass the newly resolved style context as |aStyleContext| when - // we call this function during resolving style context because this function - // calls UpdateCascadingResults with a style context if necessary, at the - // time, we end up using the previous style context if we don't pass the new - // style context. - // When we are not resolving style context, |aStyleContext| can be nullptr, we - // will use a style context associated with the primary frame of the specified - // (pseudo-)element. - nsIStyleRule* GetAnimationRule(dom::Element* aElement, - CSSPseudoElementType aPseudoType, - CascadeLevel aCascadeLevel, - nsStyleContext* aStyleContext); -#endif // Get animation rule for stylo. This is an equivalent of GetAnimationRule // and will be called from servo side. @@ -178,19 +138,6 @@ public: bool HasPendingStyleUpdates() const; -#ifdef MOZ_OLD_STYLE - bool HasThrottledStyleUpdates() const; - - // Tell the restyle tracker about all the animated styles that have - // pending updates so that it can update the animation rule for these - // elements. - void AddStyleUpdatesTo(RestyleTracker& aTracker); - - nsIStyleRuleProcessor* RuleProcessor(CascadeLevel aCascadeLevel) const - { - return mRuleProcessors[aCascadeLevel]; - } -#endif static bool HasAnimationsForCompositor(const nsIFrame* aFrame, nsCSSPropertyID aProperty); @@ -290,13 +237,6 @@ public: private: ~EffectCompositor() = default; -#ifdef MOZ_OLD_STYLE - // Rebuilds the animation rule corresponding to |aCascadeLevel| on the - // EffectSet associated with the specified (pseudo-)element. - static void ComposeAnimationRule(dom::Element* aElement, - CSSPseudoElementType aPseudoType, - CascadeLevel aCascadeLevel); -#endif // Get the properties in |aEffectSet| that we are able to animate on the // compositor but which are also specified at a higher level in the cascade @@ -332,52 +272,6 @@ private: bool mIsInPreTraverse = false; -#ifdef MOZ_OLD_STYLE - class AnimationStyleRuleProcessor final : public nsIStyleRuleProcessor - { - public: - AnimationStyleRuleProcessor(EffectCompositor* aCompositor, - CascadeLevel aCascadeLevel) - : mCompositor(aCompositor) - , mCascadeLevel(aCascadeLevel) - { - MOZ_ASSERT(aCompositor); - } - - NS_DECL_ISUPPORTS - - // nsIStyleRuleProcessor (parts) - nsRestyleHint HasStateDependentStyle( - StateRuleProcessorData* aData) override; - nsRestyleHint HasStateDependentStyle( - PseudoElementStateRuleProcessorData* aData) override; - bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override; - nsRestyleHint HasAttributeDependentStyle( - AttributeRuleProcessorData* aData, - RestyleHintData& aRestyleHintDataResult) override; - bool MediumFeaturesChanged(nsPresContext* aPresContext) override; - void RulesMatching(ElementRuleProcessorData* aData) override; - void RulesMatching(PseudoElementRuleProcessorData* aData) override; - void RulesMatching(AnonBoxRuleProcessorData* aData) override; -#ifdef MOZ_XUL - void RulesMatching(XULTreeRuleProcessorData* aData) override; -#endif - size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) - const MOZ_MUST_OVERRIDE override; - size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) - const MOZ_MUST_OVERRIDE override; - - private: - ~AnimationStyleRuleProcessor() = default; - - EffectCompositor* mCompositor; - CascadeLevel mCascadeLevel; - }; - - EnumeratedArray> - mRuleProcessors; -#endif }; } // namespace mozilla diff --git a/dom/animation/EffectSet.h b/dom/animation/EffectSet.h index 15adae10aad4..e1a082950a2c 100644 --- a/dom/animation/EffectSet.h +++ b/dom/animation/EffectSet.h @@ -7,9 +7,6 @@ #ifndef mozilla_EffectSet_h #define mozilla_EffectSet_h -#ifdef MOZ_OLD_STYLE -#include "mozilla/AnimValuesStyleRule.h" -#endif #include "mozilla/DebugOnly.h" #include "mozilla/EffectCompositor.h" #include "mozilla/EnumeratedArray.h" @@ -172,13 +169,6 @@ public: size_t Count() const { return mEffects.Count(); } -#ifdef MOZ_OLD_STYLE - RefPtr& - AnimationRule(EffectCompositor::CascadeLevel aCascadeLevel) - { - return mAnimationRule[aCascadeLevel]; - } -#endif const TimeStamp& LastTransformSyncTime() const { @@ -216,17 +206,6 @@ private: OwningEffectSet mEffects; -#ifdef MOZ_OLD_STYLE - // These style rules contain the style data for currently animating - // values. They only match when styling with animation. When we - // style without animation, we need to not use them so that we can - // detect any new changes; if necessary we restyle immediately - // afterwards with animation. - EnumeratedArray> mAnimationRule; -#endif // Refresh driver timestamp from the moment when transform animations in this // effect set were last updated and sent to the compositor. This is used for diff --git a/dom/animation/KeyframeEffectReadOnly.cpp b/dom/animation/KeyframeEffectReadOnly.cpp index 33c96eadd3a3..0e9932a0d7a1 100644 --- a/dom/animation/KeyframeEffectReadOnly.cpp +++ b/dom/animation/KeyframeEffectReadOnly.cpp @@ -12,16 +12,10 @@ // For UnrestrictedDoubleOrKeyframeAnimationOptions; #include "mozilla/dom/CSSPseudoElement.h" #include "mozilla/dom/KeyframeEffectBinding.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/AnimValuesStyleRule.h" -#endif #include "mozilla/AnimationUtils.h" #include "mozilla/AutoRestore.h" #include "mozilla/EffectSet.h" #include "mozilla/FloatingPoint.h" // For IsFinite -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoStyleContext.h" -#endif #include "mozilla/LayerAnimationInfo.h" #include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt #include "mozilla/KeyframeUtils.h" @@ -199,12 +193,7 @@ KeyframeEffectReadOnly::SetKeyframes(JSContext* aContext, RefPtr styleContext = GetTargetStyleContext(); if (styleContext) { if (styleContext->IsGecko()) { -#ifdef MOZ_OLD_STYLE - auto gecko = styleContext->AsGecko(); - SetKeyframes(Move(keyframes), gecko); -#else MOZ_CRASH("old style system disabled"); -#endif } else { SetKeyframes(Move(keyframes), styleContext->AsServo()); } @@ -215,14 +204,6 @@ KeyframeEffectReadOnly::SetKeyframes(JSContext* aContext, } } -#ifdef MOZ_OLD_STYLE -void -KeyframeEffectReadOnly::SetKeyframes(nsTArray&& aKeyframes, - GeckoStyleContext* aStyleContext) -{ - DoSetKeyframes(Move(aKeyframes), Move(aStyleContext)); -} -#endif void KeyframeEffectReadOnly::SetKeyframes( @@ -237,12 +218,6 @@ void KeyframeEffectReadOnly::DoSetKeyframes(nsTArray&& aKeyframes, StyleType* aStyle) { -#ifdef MOZ_OLD_STYLE - static_assert(IsSame::value || - IsSame::value, - "StyleType should be GeckoStyleContext* or " - "const ServoStyleContext*"); -#endif if (KeyframesEqualIgnoringComputedOffsets(aKeyframes, mKeyframes)) { return; @@ -327,13 +302,7 @@ KeyframeEffectReadOnly::UpdateProperties(nsStyleContext* aStyleContext) MOZ_ASSERT(aStyleContext); if (aStyleContext->IsGecko()) { -#ifdef MOZ_OLD_STYLE - auto gecko = aStyleContext->AsGecko(); - DoUpdateProperties(Move(gecko)); - return; -#else MOZ_CRASH("old style system disabled"); -#endif } UpdateProperties(aStyleContext->AsServo()); @@ -395,140 +364,6 @@ KeyframeEffectReadOnly::DoUpdateProperties(StyleType* aStyle) RequestRestyle(EffectCompositor::RestyleType::Layer); } -#ifdef MOZ_OLD_STYLE -/* static */ StyleAnimationValue -KeyframeEffectReadOnly::CompositeValue( - nsCSSPropertyID aProperty, - const StyleAnimationValue& aValueToComposite, - const StyleAnimationValue& aUnderlyingValue, - CompositeOperation aCompositeOperation) -{ - // Just return the underlying value if |aValueToComposite| is null - // (i.e. missing keyframe). - if (aValueToComposite.IsNull()) { - return aUnderlyingValue; - } - - switch (aCompositeOperation) { - case dom::CompositeOperation::Replace: - return aValueToComposite; - case dom::CompositeOperation::Add: { - StyleAnimationValue result(aValueToComposite); - return StyleAnimationValue::Add(aProperty, - aUnderlyingValue, - Move(result)); - } - case dom::CompositeOperation::Accumulate: { - StyleAnimationValue result(aValueToComposite); - return StyleAnimationValue::Accumulate(aProperty, - aUnderlyingValue, - Move(result)); - } - default: - MOZ_ASSERT_UNREACHABLE("Unknown compisite operation type"); - break; - } - return StyleAnimationValue(); -} - -StyleAnimationValue -KeyframeEffectReadOnly::GetUnderlyingStyle( - nsCSSPropertyID aProperty, - const RefPtr& aAnimationRule) -{ - StyleAnimationValue result; - - if (aAnimationRule && aAnimationRule->HasValue(aProperty)) { - // If we have already composed style for the property, we use the style - // as the underlying style. - DebugOnly success = aAnimationRule->GetValue(aProperty, result); - MOZ_ASSERT(success, "AnimValuesStyleRule::GetValue should not fail"); - } else { - // If we are composing with composite operation that is not 'replace' - // and we have not composed style for the property yet, we have to get - // the base style for the property. - result = BaseStyle(aProperty).mGecko; - } - - return result; -} - -StyleAnimationValue -KeyframeEffectReadOnly::CompositeValue( - nsCSSPropertyID aProperty, - const RefPtr& aAnimationRule, - const StyleAnimationValue& aValueToComposite, - CompositeOperation aCompositeOperation) -{ - MOZ_ASSERT(mTarget, "CompositeValue should be called with target element"); - MOZ_ASSERT(!mDocument->IsStyledByServo()); - - StyleAnimationValue underlyingValue = - GetUnderlyingStyle(aProperty, aAnimationRule); - - return CompositeValue(aProperty, - aValueToComposite, - underlyingValue, - aCompositeOperation); -} - -void -KeyframeEffectReadOnly::EnsureBaseStyles( - GeckoStyleContext* aStyleContext, - const nsTArray& aProperties) -{ - if (!mTarget) { - return; - } - - mBaseStyleValues.Clear(); - - RefPtr cachedBaseStyleContext; - - for (const AnimationProperty& property : aProperties) { - for (const AnimationPropertySegment& segment : property.mSegments) { - if (segment.HasReplaceableValues()) { - continue; - } - - EnsureBaseStyle(property.mProperty, - aStyleContext, - cachedBaseStyleContext); - break; - } - } -} - -void -KeyframeEffectReadOnly::EnsureBaseStyle( - nsCSSPropertyID aProperty, - GeckoStyleContext* aStyleContext, - RefPtr& aCachedBaseStyleContext) -{ - if (mBaseStyleValues.Contains(aProperty)) { - return; - } - - if (!aCachedBaseStyleContext) { - aCachedBaseStyleContext = - aStyleContext->PresContext()->StyleSet()->AsGecko()-> - ResolveStyleByRemovingAnimation(mTarget->mElement, - aStyleContext, - eRestyle_AllHintsWithAnimations); - } - - StyleAnimationValue result; - DebugOnly success = - StyleAnimationValue::ExtractComputedValue(aProperty, - aCachedBaseStyleContext, - result); - - MOZ_ASSERT(success, "Should be able to extract computed animation value"); - MOZ_ASSERT(!result.IsNull(), "Should have a valid StyleAnimationValue"); - - mBaseStyleValues.Put(aProperty, result); -} -#endif void KeyframeEffectReadOnly::EnsureBaseStyles( @@ -610,87 +445,6 @@ KeyframeEffectReadOnly::WillComposeStyle() mCurrentIterationOnLastCompose = computedTiming.mCurrentIteration; } -#ifdef MOZ_OLD_STYLE -void -KeyframeEffectReadOnly::ComposeStyleRule( - RefPtr& aStyleRule, - const AnimationProperty& aProperty, - const AnimationPropertySegment& aSegment, - const ComputedTiming& aComputedTiming) -{ - StyleAnimationValue fromValue = - CompositeValue(aProperty.mProperty, aStyleRule, - aSegment.mFromValue.mGecko, - aSegment.mFromComposite); - StyleAnimationValue toValue = - CompositeValue(aProperty.mProperty, aStyleRule, - aSegment.mToValue.mGecko, - aSegment.mToComposite); - if (fromValue.IsNull() || toValue.IsNull()) { - return; - } - - if (!aStyleRule) { - // Allocate the style rule now that we know we have animation data. - aStyleRule = new AnimValuesStyleRule(); - } - - // Iteration composition for accumulate - if (mEffectOptions.mIterationComposite == - IterationCompositeOperation::Accumulate && - aComputedTiming.mCurrentIteration > 0) { - const AnimationPropertySegment& lastSegment = - aProperty.mSegments.LastElement(); - // FIXME: Bug 1293492: Add a utility function to calculate both of - // below StyleAnimationValues. - StyleAnimationValue lastValue = lastSegment.mToValue.mGecko.IsNull() - ? GetUnderlyingStyle(aProperty.mProperty, aStyleRule) - : lastSegment.mToValue.mGecko; - fromValue = - StyleAnimationValue::Accumulate(aProperty.mProperty, - lastValue, - Move(fromValue), - aComputedTiming.mCurrentIteration); - toValue = - StyleAnimationValue::Accumulate(aProperty.mProperty, - lastValue, - Move(toValue), - aComputedTiming.mCurrentIteration); - } - - // Special handling for zero-length segments - if (aSegment.mToKey == aSegment.mFromKey) { - if (aComputedTiming.mProgress.Value() < 0) { - aStyleRule->AddValue(aProperty.mProperty, Move(fromValue)); - } else { - aStyleRule->AddValue(aProperty.mProperty, Move(toValue)); - } - return; - } - - double positionInSegment = - (aComputedTiming.mProgress.Value() - aSegment.mFromKey) / - (aSegment.mToKey - aSegment.mFromKey); - double valuePosition = - ComputedTimingFunction::GetPortion(aSegment.mTimingFunction, - positionInSegment, - aComputedTiming.mBeforeFlag); - - MOZ_ASSERT(IsFinite(valuePosition), "Position value should be finite"); - - StyleAnimationValue val; - if (StyleAnimationValue::Interpolate(aProperty.mProperty, - fromValue, - toValue, - valuePosition, val)) { - aStyleRule->AddValue(aProperty.mProperty, Move(val)); - } else if (valuePosition < 0.5) { - aStyleRule->AddValue(aProperty.mProperty, Move(fromValue)); - } else { - aStyleRule->AddValue(aProperty.mProperty, Move(toValue)); - } -} -#endif void KeyframeEffectReadOnly::ComposeStyleRule( @@ -978,12 +732,6 @@ template nsTArray KeyframeEffectReadOnly::BuildProperties(StyleType* aStyle) { -#ifdef MOZ_OLD_STYLE - static_assert(IsSame::value || - IsSame::value, - "StyleType should be GeckoStyleContext* or " - "const ServoStyleContext*"); -#endif MOZ_ASSERT(aStyle); @@ -1373,38 +1121,7 @@ KeyframeEffectReadOnly::GetKeyframes(JSContext*& aCx, } } } else { -#ifdef MOZ_OLD_STYLE - if (nsCSSProps::IsShorthand(propertyValue.mProperty)) { - // nsCSSValue::AppendToString does not accept shorthands properties but - // works with token stream values if we pass eCSSProperty_UNKNOWN as - // the property. - propertyValue.mValue.AppendToString( - eCSSProperty_UNKNOWN, stringValue); - } else { - nsCSSValue cssValue = propertyValue.mValue; - if (cssValue.GetUnit() == eCSSUnit_Null) { - // We use an uninitialized nsCSSValue to represent the - // "neutral value". We currently only do this for keyframes generated - // from CSS animations with missing 0%/100% keyframes. Furthermore, - // currently (at least until bug 1339334) keyframes generated from - // CSS animations only contain longhand properties so we only need to - // handle null nsCSSValues for longhand properties. - DebugOnly uncomputeResult = - StyleAnimationValue::UncomputeValue( - propertyValue.mProperty, - Move(BaseStyle(propertyValue.mProperty).mGecko), - cssValue); - - MOZ_ASSERT(uncomputeResult, - "Unable to get specified value from computed value"); - MOZ_ASSERT(cssValue.GetUnit() != eCSSUnit_Null, - "Got null computed value"); - } - cssValue.AppendToString(propertyValue.mProperty, stringValue); - } -#else MOZ_CRASH("old style system disabled"); -#endif } const char* name = nsCSSProps::PropertyIDLName(propertyValue.mProperty); @@ -1785,36 +1502,6 @@ KeyframeEffectReadOnly::SetPerformanceWarning( } } -#ifdef MOZ_OLD_STYLE -already_AddRefed -KeyframeEffectReadOnly::CreateStyleContextForAnimationValue( - nsCSSPropertyID aProperty, - const AnimationValue& aValue, - GeckoStyleContext* aBaseStyleContext) -{ - MOZ_ASSERT(aBaseStyleContext, - "CreateStyleContextForAnimationValue needs to be called " - "with a valid GeckoStyleContext"); - - RefPtr styleRule = new AnimValuesStyleRule(); - styleRule->AddValue(aProperty, aValue.mGecko); - - nsCOMArray rules; - rules.AppendObject(styleRule); - - nsStyleSet* styleSet = - aBaseStyleContext->PresContext()->StyleSet()->AsGecko(); - - RefPtr styleContext = - styleSet->ResolveStyleByAddingRules(aBaseStyleContext, rules); - - // We need to call StyleData to generate cached data for the style context. - // Otherwise CalcStyleDifference returns no meaningful result. - styleContext->StyleData(nsCSSProps::kSIDTable[aProperty]); - - return styleContext.forget(); -} -#endif already_AddRefed KeyframeEffectReadOnly::CreateStyleContextForAnimationValue( @@ -2055,13 +1742,6 @@ KeyframeEffectReadOnly::UpdateEffectSet(EffectSet* aEffectSet) const } } -#ifdef MOZ_OLD_STYLE -template -void -KeyframeEffectReadOnly::ComposeStyle&>( - RefPtr& aAnimationRule, - const nsCSSPropertyIDSet& aPropertiesToSkip); -#endif template void diff --git a/dom/animation/KeyframeEffectReadOnly.h b/dom/animation/KeyframeEffectReadOnly.h index 24709c904e52..3045b77b7dc1 100644 --- a/dom/animation/KeyframeEffectReadOnly.h +++ b/dom/animation/KeyframeEffectReadOnly.h @@ -165,10 +165,6 @@ public: void SetAnimation(Animation* aAnimation) override; void SetKeyframes(JSContext* aContext, JS::Handle aKeyframes, ErrorResult& aRv); -#ifdef MOZ_OLD_STYLE - void SetKeyframes(nsTArray&& aKeyframes, - GeckoStyleContext* aStyleContext); -#endif void SetKeyframes(nsTArray&& aKeyframes, const ServoStyleContext* aComputedValues); @@ -214,16 +210,6 @@ public: void ComposeStyle(ComposeAnimationResult&& aRestultContainer, const nsCSSPropertyIDSet& aPropertiesToSkip); -#ifdef MOZ_OLD_STYLE - // Composite |aValueToComposite| on |aUnderlyingValue| with - // |aCompositeOperation|. - // Returns |aValueToComposite| if |aCompositeOperation| is Replace. - static StyleAnimationValue CompositeValue( - nsCSSPropertyID aProperty, - const StyleAnimationValue& aValueToComposite, - const StyleAnimationValue& aUnderlyingValue, - CompositeOperation aCompositeOperation); -#endif // Returns true if at least one property is being animated on compositor. bool IsRunningOnCompositor() const; @@ -283,11 +269,7 @@ public: // then assign the raw pointer to a RefPtr. result.mServo = mBaseStyleValuesForServo.GetWeak(aProperty, &hasProperty); } else { -#ifdef MOZ_OLD_STYLE - hasProperty = mBaseStyleValues.Get(aProperty, &result.mGecko); -#else MOZ_CRASH("old style system disabled"); -#endif } MOZ_ASSERT(hasProperty || result.IsNull()); return result; @@ -355,39 +337,9 @@ protected: // target and its effectSet. void MarkCascadeNeedsUpdate(); -#ifdef MOZ_OLD_STYLE - // Composites |aValueToComposite| using |aCompositeOperation| onto the value - // for |aProperty| in |aAnimationRule|, or, if there is no suitable value in - // |aAnimationRule|, uses the base value for the property recorded on the - // target element's EffectSet. - StyleAnimationValue CompositeValue( - nsCSSPropertyID aProperty, - const RefPtr& aAnimationRule, - const StyleAnimationValue& aValueToComposite, - CompositeOperation aCompositeOperation); - - // Returns underlying style animation value for |aProperty|. - StyleAnimationValue GetUnderlyingStyle( - nsCSSPropertyID aProperty, - const RefPtr& aAnimationRule); - - // Ensure the base styles is available for any properties in |aProperties|. - void EnsureBaseStyles(GeckoStyleContext* aStyleContext, - const nsTArray& aProperties); -#endif void EnsureBaseStyles(const ServoStyleContext* aComputedValues, const nsTArray& aProperties); -#ifdef MOZ_OLD_STYLE - // If no base style is already stored for |aProperty|, resolves the base style - // for |aProperty| using |aStyleContext| and stores it in mBaseStyleValues. - // If |aCachedBaseStyleContext| is non-null, it will be used, otherwise the - // base style context will be resolved and stored in - // |aCachedBaseStyleContext|. - void EnsureBaseStyle(nsCSSPropertyID aProperty, - GeckoStyleContext* aStyleContext, - RefPtr& aCachedBaseStyleContext); -#endif // Stylo version of the above function that also first checks for an additive // value in |aProperty|'s list of segments. void EnsureBaseStyle(const AnimationProperty& aProperty, @@ -422,9 +374,6 @@ protected: // The non-animated values for properties in this effect that contain at // least one animation value that is composited with the underlying value // (i.e. it uses the additive or accumulate composite mode). -#ifdef MOZ_OLD_STYLE - nsDataHashtable mBaseStyleValues; -#endif nsRefPtrHashtable mBaseStyleValuesForServo; @@ -442,24 +391,12 @@ private: template void DoUpdateProperties(StyleType* aStyle); -#ifdef MOZ_OLD_STYLE - void ComposeStyleRule(RefPtr& aStyleRule, - const AnimationProperty& aProperty, - const AnimationPropertySegment& aSegment, - const ComputedTiming& aComputedTiming); -#endif void ComposeStyleRule(RawServoAnimationValueMap& aAnimationValues, const AnimationProperty& aProperty, const AnimationPropertySegment& aSegment, const ComputedTiming& aComputedTiming); -#ifdef MOZ_OLD_STYLE - already_AddRefed CreateStyleContextForAnimationValue( - nsCSSPropertyID aProperty, - const AnimationValue& aValue, - GeckoStyleContext* aBaseStyleContext); -#endif already_AddRefed CreateStyleContextForAnimationValue( nsCSSPropertyID aProperty, diff --git a/dom/animation/KeyframeUtils.cpp b/dom/animation/KeyframeUtils.cpp index 53475465d310..4f7265d4e76a 100644 --- a/dom/animation/KeyframeUtils.cpp +++ b/dom/animation/KeyframeUtils.cpp @@ -364,18 +364,8 @@ HasValidOffsets(const nsTArray& aKeyframes); static void MarkAsComputeValuesFailureKey(PropertyValuePair& aPair); -#ifdef MOZ_OLD_STYLE -static bool -IsComputeValuesFailureKey(const PropertyValuePair& aPair); -#endif #endif -#ifdef MOZ_OLD_STYLE -static nsTArray -GetComputedKeyframeValues(const nsTArray& aKeyframes, - dom::Element* aElement, - GeckoStyleContext* aStyleContext); -#endif static nsTArray GetComputedKeyframeValues(const nsTArray& aKeyframes, @@ -901,49 +891,7 @@ MakePropertyValuePair(nsCSSPropertyID aProperty, const nsAString& aStringValue, return result; } -#ifdef MOZ_OLD_STYLE - nsCSSValue value; - if (!nsCSSProps::IsShorthand(aProperty)) { - aParser.ParseLonghandProperty(aProperty, - aStringValue, - aDocument->GetDocumentURI(), - aDocument->GetDocumentURI(), - aDocument->NodePrincipal(), - value); - if (value.GetUnit() == eCSSUnit_Null) { - // Invalid property value, so return Nothing. - ReportInvalidPropertyValueToConsole(aProperty, aStringValue, aDocument); - return result; - } - } - - if (value.GetUnit() == eCSSUnit_Null) { - // If we have a shorthand, store the string value as a token stream. - nsCSSValueTokenStream* tokenStream = new nsCSSValueTokenStream; - tokenStream->mTokenStream = aStringValue; - - // We are about to convert a null value to a token stream value but - // by leaving the mPropertyID as unknown, we will be able to - // distinguish between shorthand values and valid token stream values - // (e.g. values with variable references). - MOZ_ASSERT(tokenStream->mPropertyID == eCSSProperty_UNKNOWN, - "The property of a token stream should be initialized" - " to unknown"); - - // By leaving mShorthandPropertyID as unknown, we ensure that when - // we call nsCSSValue::AppendToString we get back the string stored - // in mTokenStream. - MOZ_ASSERT(tokenStream->mShorthandPropertyID == eCSSProperty_UNKNOWN, - "The shorthand property of a token stream should be initialized" - " to unknown"); - value.SetTokenStreamValue(tokenStream); - } - - result.emplace(aProperty, Move(value)); - return result; -#else MOZ_CRASH("old style system disabled"); -#endif } /** @@ -988,113 +936,8 @@ MarkAsComputeValuesFailureKey(PropertyValuePair& aPair) aPair.mSimulateComputeValuesFailure = true; } -#ifdef MOZ_OLD_STYLE -/** - * Returns true if |aPair| is a property-value pair on which we have - * previously called MarkAsComputeValuesFailureKey (and hence we should - * simulate failure when calling StyleAnimationValue::ComputeValues using its - * value). - * - * @param aPair The property-value pair to test. - * @return True if |aPair| represents a failure value. - */ -static bool -IsComputeValuesFailureKey(const PropertyValuePair& aPair) -{ - return nsCSSProps::IsShorthand(aPair.mProperty) && - aPair.mSimulateComputeValuesFailure; -} -#endif #endif -#ifdef MOZ_OLD_STYLE -/** - * Calculate the StyleAnimationValues of properties of each keyframe. - * This involves expanding shorthand properties into longhand properties, - * removing the duplicated properties for each keyframe, and creating an - * array of |property:computed value| pairs for each keyframe. - * - * These computed values are used when computing the final set of - * per-property animation values (see GetAnimationPropertiesFromKeyframes). - * - * @param aKeyframes The input keyframes. - * @param aElement The context element. - * @param aStyleContext The style context to use when computing values. - * @return The set of ComputedKeyframeValues. The length will be the same as - * aFrames. - */ -static nsTArray -GetComputedKeyframeValues(const nsTArray& aKeyframes, - dom::Element* aElement, - GeckoStyleContext* aStyleContext) -{ - MOZ_ASSERT(aStyleContext); - MOZ_ASSERT(aElement); - - const size_t len = aKeyframes.Length(); - nsTArray result(len); - - for (const Keyframe& frame : aKeyframes) { - nsCSSPropertyIDSet propertiesOnThisKeyframe; - ComputedKeyframeValues* computedValues = result.AppendElement(); - for (const PropertyValuePair& pair : - PropertyPriorityIterator(frame.mPropertyValues)) { - MOZ_ASSERT(!pair.mServoDeclarationBlock, - "Animation values were parsed using Servo backend but target" - " element is not using Servo backend?"); - - // Expand each value into the set of longhands and produce - // a KeyframeValueEntry for each value. - nsTArray values; - - // For shorthands, we store the string as a token stream so we need to - // extract that first. - if (nsCSSProps::IsShorthand(pair.mProperty)) { - nsCSSValueTokenStream* tokenStream = pair.mValue.GetTokenStreamValue(); - if (!StyleAnimationValue::ComputeValues(pair.mProperty, - CSSEnabledState::eForAllContent, aElement, aStyleContext, - tokenStream->mTokenStream, /* aUseSVGMode */ false, values)) { - continue; - } - -#ifdef DEBUG - if (IsComputeValuesFailureKey(pair)) { - continue; - } -#endif - } else if (pair.mValue.GetUnit() == eCSSUnit_Null) { - // An uninitialized nsCSSValue represents the underlying value which - // we represent as an uninitialized AnimationValue so we just leave - // neutralPair->mValue as-is. - PropertyStyleAnimationValuePair* neutralPair = values.AppendElement(); - neutralPair->mProperty = pair.mProperty; - } else { - if (!StyleAnimationValue::ComputeValues(pair.mProperty, - CSSEnabledState::eForAllContent, aElement, aStyleContext, - pair.mValue, /* aUseSVGMode */ false, values)) { - continue; - } - MOZ_ASSERT(values.Length() == 1, - "Longhand properties should produce a single" - " StyleAnimationValue"); - } - - for (auto& value : values) { - // If we already got a value for this property on the keyframe, - // skip this one. - if (propertiesOnThisKeyframe.HasProperty(value.mProperty)) { - continue; - } - propertiesOnThisKeyframe.AddProperty(value.mProperty); - computedValues->AppendElement(Move(value)); - } - } - } - - MOZ_ASSERT(result.Length() == aKeyframes.Length(), "Array length mismatch"); - return result; -} -#endif /** * The variation of the above function. This is for Servo backend. @@ -1644,17 +1487,7 @@ RequiresAdditiveAnimation(const nsTArray& aKeyframes, for (const PropertyValuePair& pair : frame.mPropertyValues) { if (nsCSSProps::IsShorthand(pair.mProperty)) { if (styleBackend == StyleBackendType::Gecko) { -#ifdef MOZ_OLD_STYLE - nsCSSValueTokenStream* tokenStream = - pair.mValue.GetTokenStreamValue(); - nsCSSParser parser(aDocument->CSSLoader()); - if (!parser.IsValueValidForProperty(pair.mProperty, - tokenStream->mTokenStream)) { - continue; - } -#else MOZ_CRASH("old style system disabled"); -#endif } MOZ_ASSERT(styleBackend != StyleBackendType::Servo || @@ -1694,15 +1527,6 @@ DistributeRange(const Range& aRange) } } -#ifdef MOZ_OLD_STYLE -template -nsTArray -KeyframeUtils::GetAnimationPropertiesFromKeyframes( - const nsTArray& aKeyframes, - dom::Element* aElement, - GeckoStyleContext* aStyle, - dom::CompositeOperation aEffectComposite); -#endif template nsTArray diff --git a/dom/animation/TimingParams.cpp b/dom/animation/TimingParams.cpp index e7a743a24883..c53d1af96965 100644 --- a/dom/animation/TimingParams.cpp +++ b/dom/animation/TimingParams.cpp @@ -13,9 +13,6 @@ #include "mozilla/ServoCSSParser.h" #include "nsCSSParser.h" // For nsCSSParser #include "nsIDocument.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" -#endif namespace mozilla { @@ -134,60 +131,7 @@ TimingParams::ParseEasing(const nsAString& aEasing, return Some(ComputedTimingFunction(timingFunction)); } -#ifdef MOZ_OLD_STYLE - nsCSSValue value; - nsCSSParser parser; - parser.ParseLonghandProperty(eCSSProperty_animation_timing_function, - aEasing, - aDocument->GetDocumentURI(), - aDocument->GetDocumentURI(), - aDocument->NodePrincipal(), - value); - - switch (value.GetUnit()) { - case eCSSUnit_List: { - const nsCSSValueList* list = value.GetListValue(); - if (list->mNext) { - // don't support a list of timing functions - break; - } - switch (list->mValue.GetUnit()) { - case eCSSUnit_Enumerated: - // Return Nothing() if "linear" is passed in. - if (list->mValue.GetIntValue() == - NS_STYLE_TRANSITION_TIMING_FUNCTION_LINEAR) { - return Nothing(); - } - MOZ_FALLTHROUGH; - case eCSSUnit_Cubic_Bezier: - case eCSSUnit_Function: - case eCSSUnit_Steps: { - nsTimingFunction timingFunction; - nsRuleNode::ComputeTimingFunction(list->mValue, timingFunction); - return Some(ComputedTimingFunction(timingFunction)); - } - default: - MOZ_ASSERT_UNREACHABLE("unexpected animation-timing-function list " - "item unit"); - break; - } - break; - } - case eCSSUnit_Inherit: - case eCSSUnit_Initial: - case eCSSUnit_Unset: - case eCSSUnit_TokenStream: - case eCSSUnit_Null: - break; - default: - MOZ_ASSERT_UNREACHABLE("unexpected animation-timing-function unit"); - break; - } - - aRv.ThrowTypeError(aEasing); -#else MOZ_CRASH("old style system disabled"); -#endif return Nothing(); } diff --git a/dom/base/DOMIntersectionObserver.cpp b/dom/base/DOMIntersectionObserver.cpp index 54fb5a012d73..7f2154c79039 100644 --- a/dom/base/DOMIntersectionObserver.cpp +++ b/dom/base/DOMIntersectionObserver.cpp @@ -121,28 +121,7 @@ DOMIntersectionObserver::SetRootMargin(const nsAString& aString) &mRootMargin); } -#ifdef MOZ_OLD_STYLE - // By not passing a CSS Loader object we make sure we don't parse in quirks - // mode so that pixel/percent and unit-less values will be differentiated. - nsCSSParser parser(nullptr); - nsCSSValue value; - if (!parser.ParseMarginString(aString, nullptr, 0, value, true)) { - return false; - } - - mRootMargin = value.GetRectValue(); - - for (auto side : nsCSSRect::sides) { - nsCSSValue& value = mRootMargin.*side; - if (!(value.IsPixelLengthUnit() || value.IsPercentLengthUnit())) { - return false; - } - } - - return true; -#else MOZ_CRASH("old style system disabled"); -#endif } void diff --git a/dom/base/DOMMatrix.cpp b/dom/base/DOMMatrix.cpp index a0ef296fd2c4..33ae654e7f06 100644 --- a/dom/base/DOMMatrix.cpp +++ b/dom/base/DOMMatrix.cpp @@ -685,40 +685,7 @@ DOMMatrix::SetMatrixValue(const nsAString& aTransformList, ErrorResult& aRv) return nullptr; } } else { -#ifdef MOZ_OLD_STYLE - nsCSSValue value; - nsCSSParser parser; - bool parseSuccess = parser.ParseTransformProperty(aTransformList, - true, - value); - if (!parseSuccess) { - aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); - return nullptr; - } - - // A value of "none" results in a 2D identity matrix. - if (value.GetUnit() == eCSSUnit_None) { - mMatrix3D = nullptr; - mMatrix2D = new gfx::Matrix(); - return this; - } - - // A value other than a transform-list is a syntax error. - if (value.GetUnit() != eCSSUnit_SharedList) { - aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); - return nullptr; - } - - RuleNodeCacheConditions dummy; - nsStyleTransformMatrix::TransformReferenceBox dummyBox; - transform = nsStyleTransformMatrix::ReadTransforms( - value.GetSharedListValue()->mHead, - nullptr, nullptr, dummy, dummyBox, - nsPresContext::AppUnitsPerCSSPixel(), - &contains3dTransform); -#else MOZ_CRASH("old style system disabled"); -#endif } if (!contains3dTransform) { diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 36c73c82ad6d..bfb84b334572 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -112,11 +112,6 @@ #include "nsView.h" #include "nsViewManager.h" #include "nsIScrollableFrame.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */ -#include "nsCSSRuleProcessor.h" -#include "nsRuleProcessorData.h" -#endif #include "nsTextNode.h" #include "nsCycleCollectionParticipant.h" @@ -3498,30 +3493,7 @@ Element::Closest(const nsAString& aSelector, ErrorResult& aResult) return const_cast(Servo_SelectorList_Closest(this, aList)); }, [&](nsCSSSelectorList* aList) -> Element* { -#ifdef MOZ_OLD_STYLE - if (!aList) { - // Either we failed (and aError already has the exception), or this - // is a pseudo-element-only selector that matches nothing. - return nullptr; - } - TreeMatchContext matchingContext(false, - nsRuleWalker::eRelevantLinkUnvisited, - OwnerDoc(), - TreeMatchContext::eNeverMatchVisited); - matchingContext.SetHasSpecifiedScope(); - matchingContext.AddScopeElement(this); - for (nsINode* node = this; node; node = node->GetParentNode()) { - if (node->IsElement() && - nsCSSRuleProcessor::SelectorListMatches(node->AsElement(), - matchingContext, - aList)) { - return node->AsElement(); - } - } - return nullptr; -#else MOZ_CRASH("old style system disabled"); -#endif } ); } @@ -3539,23 +3511,7 @@ Element::Matches(const nsAString& aSelector, ErrorResult& aError) return Servo_SelectorList_Matches(this, aList); }, [&](nsCSSSelectorList* aList) { -#ifdef MOZ_OLD_STYLE - if (!aList) { - // Either we failed (and aError already has the exception), or this - // is a pseudo-element-only selector that matches nothing. - return false; - } - TreeMatchContext matchingContext(false, - nsRuleWalker::eRelevantLinkUnvisited, - OwnerDoc(), - TreeMatchContext::eNeverMatchVisited); - matchingContext.SetHasSpecifiedScope(); - matchingContext.AddScopeElement(this); - return nsCSSRuleProcessor::SelectorListMatches(this, matchingContext, - aList); -#else MOZ_CRASH("old style system disabled"); -#endif } ); } @@ -4356,7 +4312,6 @@ void Element::ClearServoData(nsIDocument* aDoc) { MOZ_ASSERT(IsStyledByServo()); MOZ_ASSERT(aDoc); -#ifdef MOZ_STYLO if (HasServoData()) { Servo_Element_ClearData(this); } else { @@ -4370,9 +4325,6 @@ Element::ClearServoData(nsIDocument* aDoc) { if (aDoc->GetServoRestyleRoot() == this) { aDoc->ClearServoRestyleRoot(); } -#else - MOZ_CRASH("Accessing servo node data in non-stylo build"); -#endif } void diff --git a/dom/base/Element.h b/dom/base/Element.h index bba901010957..d1a7c6295756 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -454,12 +454,6 @@ public: virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute, int32_t aModType) const; -#ifdef MOZ_OLD_STYLE - NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) - { - return NS_OK; - } -#endif inline Directionality GetDirectionality() const { if (HasFlag(NODE_HAS_DIRECTION_RTL)) { diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 951825193205..ac40fa539cf5 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -97,10 +97,6 @@ #include "nsViewManager.h" #include "nsIScrollableFrame.h" #include "ChildIterator.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" /* For nsCSSSelectorList */ -#include "nsRuleProcessorData.h" -#endif #include "nsTextNode.h" #include "mozilla/dom/NodeListBinding.h" diff --git a/dom/base/ResponsiveImageSelector.cpp b/dom/base/ResponsiveImageSelector.cpp index 92cce0edbbb1..41236bff5a73 100644 --- a/dom/base/ResponsiveImageSelector.cpp +++ b/dom/base/ResponsiveImageSelector.cpp @@ -13,11 +13,6 @@ #include "nsCSSParser.h" #include "nsCSSProps.h" -#ifdef MOZ_OLD_STYLE -#include "nsMediaList.h" -#include "nsRuleNode.h" -#include "nsRuleData.h" -#endif using namespace mozilla; using namespace mozilla::dom; @@ -251,17 +246,7 @@ ResponsiveImageSelector::SetSizesFromDescriptor(const nsAString & aSizes) return !!mServoSourceSizeList; } -#ifdef MOZ_OLD_STYLE - nsCSSParser cssParser; - - mSizeQueries.Clear(); - mSizeValues.Clear(); - - return cssParser.ParseSourceSizeList(aSizes, nullptr, 0, - mSizeQueries, mSizeValues); -#else MOZ_CRASH("old style system disabled"); -#endif } void @@ -464,30 +449,7 @@ ResponsiveImageSelector::ComputeFinalWidthForCurrentViewport(double *aWidth) effectiveWidth = presShell->StyleSet()->AsServo()->EvaluateSourceSizeList( mServoSourceSizeList.get()); } else { -#ifdef MOZ_OLD_STYLE - unsigned int numSizes = mSizeQueries.Length(); - MOZ_ASSERT(numSizes == mSizeValues.Length(), - "mSizeValues length differs from mSizeQueries"); - - unsigned int i; - for (i = 0; i < numSizes; i++) { - if (mSizeQueries[i]->Matches(pctx, nullptr)) { - break; - } - } - - if (i == numSizes) { - // No match defaults to 100% viewport - nsCSSValue defaultWidth(100.0f, eCSSUnit_ViewportWidth); - effectiveWidth = nsRuleNode::CalcLengthWithInitialFont(pctx, - defaultWidth); - } else { - effectiveWidth = nsRuleNode::CalcLengthWithInitialFont(pctx, - mSizeValues[i]); - } -#else MOZ_CRASH("old style system disabled"); -#endif } *aWidth = nsPresContext::AppUnitsToDoubleCSSPixels(std::max(effectiveWidth, 0)); diff --git a/dom/base/ResponsiveImageSelector.h b/dom/base/ResponsiveImageSelector.h index f3f4241cc3b8..f799ffb62fe7 100644 --- a/dom/base/ResponsiveImageSelector.h +++ b/dom/base/ResponsiveImageSelector.h @@ -125,11 +125,6 @@ private: // Servo bits. UniquePtr mServoSourceSizeList; -#ifdef MOZ_OLD_STYLE - // Gecko bits. - nsTArray< nsAutoPtr > mSizeQueries; - nsTArray mSizeValues; -#endif }; class ResponsiveImageCandidate { diff --git a/dom/base/StyleSheetList.cpp b/dom/base/StyleSheetList.cpp index a675a3f9534b..ada052bcc287 100644 --- a/dom/base/StyleSheetList.cpp +++ b/dom/base/StyleSheetList.cpp @@ -6,9 +6,6 @@ #include "mozilla/dom/StyleSheetList.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/CSSStyleSheet.h" -#endif #include "mozilla/dom/StyleSheetListBinding.h" namespace mozilla { diff --git a/dom/base/nsAttrAndChildArray.cpp b/dom/base/nsAttrAndChildArray.cpp index 1c771251f685..ef6bd740495e 100644 --- a/dom/base/nsAttrAndChildArray.cpp +++ b/dom/base/nsAttrAndChildArray.cpp @@ -18,9 +18,6 @@ #include "nsMappedAttributeElement.h" #include "nsString.h" #include "nsHTMLStyleSheet.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#endif #include "nsMappedAttributes.h" #include "nsUnicharUtils.h" #include "nsContentUtils.h" // nsAutoScriptBlocker @@ -631,15 +628,6 @@ nsAttrAndChildArray::DoSetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet) return MakeMappedUnique(mapped); } -#ifdef MOZ_OLD_STYLE -void -nsAttrAndChildArray::WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker) -{ - if (mImpl && mImpl->mMappedAttrs) { - aRuleWalker->Forward(mImpl->mMappedAttrs); - } -} -#endif void nsAttrAndChildArray::Compact() diff --git a/dom/base/nsAttrAndChildArray.h b/dom/base/nsAttrAndChildArray.h index 10f3fa3f9a3e..19c34a9630aa 100644 --- a/dom/base/nsAttrAndChildArray.h +++ b/dom/base/nsAttrAndChildArray.h @@ -125,9 +125,6 @@ public: } return DoSetMappedAttrStyleSheet(aSheet); } -#ifdef MOZ_OLD_STYLE - void WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker); -#endif void Compact(); diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp index 159a12d38334..c0e9c16c3882 100644 --- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -1747,14 +1747,7 @@ nsAttrValue::ParseStyleAttribute(const nsAString& aString, ownerDoc->GetCompatibilityMode(), ownerDoc->CSSLoader()); } else { -#ifdef MOZ_OLD_STYLE - css::Loader* cssLoader = ownerDoc->CSSLoader(); - nsCSSParser cssParser(cssLoader); - decl = cssParser.ParseStyleAttribute(aString, docURI, baseURI, - principal); -#else MOZ_CRASH("old style system disabled"); -#endif } if (!decl) { return false; diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 1c860d437db9..55307b90807b 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -2842,43 +2842,7 @@ nsDOMWindowUtils::GetUnanimatedComputedStyle(nsIDOMElement* aElement, return NS_OK; } -#ifdef MOZ_OLD_STYLE - StyleAnimationValue computedValue; - if (!StyleAnimationValue::ExtractComputedValue(propertyID, - styleContext->AsGecko(), - computedValue)) { - return NS_ERROR_FAILURE; - } - - // Note: ExtractComputedValue can return 'unset', 'initial', or 'inherit' in - // its "computedValue" outparam, even though these technically aren't valid - // computed values. (It has this behavior for discretely-animatable - // properties, e.g. 'align-content', when these keywords are explicitly - // specified or when there is no specified value.) But we need to return a - // valid computed value -- these keywords won't do. So we fall back to - // nsComputedDOMStyle in this case. - if (computedValue.GetUnit() == StyleAnimationValue::eUnit_DiscreteCSSValue && - (computedValue.GetCSSValueValue()->GetUnit() == eCSSUnit_Unset || - computedValue.GetCSSValueValue()->GetUnit() == eCSSUnit_Initial || - computedValue.GetCSSValueValue()->GetUnit() == eCSSUnit_Inherit)) { - RefPtr computedStyle = - NS_NewComputedDOMStyle( - element, aPseudoElement, shell, - nsComputedDOMStyle::StyleType::eAll, - nsComputedDOMStyle::AnimationFlag::eWithoutAnimation); - computedStyle->GetPropertyValue(propertyID, aResult); - return NS_OK; - } - - DebugOnly uncomputeResult = - StyleAnimationValue::UncomputeValue(propertyID, - Move(computedValue), aResult); - MOZ_ASSERT(uncomputeResult, - "Unable to get specified value from computed value"); - return NS_OK; -#else MOZ_CRASH("old style system disabled"); -#endif } nsresult diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 046f7b84b96f..de4f05f64450 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -230,9 +230,6 @@ #include "nsITextControlElement.h" #include "nsIDOMNSEditableElement.h" #include "nsIEditor.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" -#endif #include "nsIHttpChannelInternal.h" #include "nsISecurityConsoleMessage.h" #include "nsCharSeparatedTokenizer.h" @@ -1324,27 +1321,11 @@ nsIDocument::SelectorCache::SelectorList::Reset() } } else { if (mGecko) { -#ifdef MOZ_OLD_STYLE - delete mGecko; - mGecko = nullptr; -#else MOZ_CRASH("old style system disabled"); -#endif } } } -#ifdef MOZ_OLD_STYLE -// CacheList takes ownership of aSelectorList. -void nsIDocument::SelectorCache::CacheList(const nsAString& aSelector, - mozilla::UniquePtr&& aSelectorList) -{ - MOZ_ASSERT(NS_IsMainThread()); - SelectorCacheKey* key = new SelectorCacheKey(aSelector); - mTable.Put(key->mKey, SelectorList(Move(aSelectorList))); - AddObject(key); -} -#endif void nsIDocument::SelectorCache::CacheList( const nsAString& aSelector, @@ -1955,9 +1936,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument) } NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChannel) -#ifdef MOZ_OLD_STYLE - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStyleAttrStyleSheet) -#endif NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLayoutHistoryState) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOnloadBlocker) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFirstBaseNodeWithHref) @@ -3711,7 +3689,6 @@ nsIDocument::SetBaseURI(nsIURI* aURI) URLExtraData* nsIDocument::DefaultStyleAttrURLData() { -#ifdef MOZ_STYLO MOZ_ASSERT(NS_IsMainThread()); nsIURI* baseURI = GetDocBaseURI(); nsIURI* docURI = GetDocumentURI(); @@ -3723,10 +3700,6 @@ nsIDocument::DefaultStyleAttrURLData() mCachedURLData = new URLExtraData(baseURI, docURI, principal); } return mCachedURLData; -#else - MOZ_CRASH("Should not be called for non-stylo build"); - return nullptr; -#endif } void @@ -12644,12 +12617,10 @@ nsIDocument::UpdateStyleBackendType() // Assume Gecko by default. mStyleBackendType = StyleBackendType::Gecko; -#ifdef MOZ_STYLO if (nsLayoutUtils::StyloEnabled() && nsLayoutUtils::ShouldUseStylo(NodePrincipal())) { mStyleBackendType = StyleBackendType::Servo; } -#endif } void diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index eed1b6559dc5..de44542598a2 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1522,12 +1522,7 @@ public: mServo = aOther.mServo; aOther.mServo = nullptr; } else { -#ifdef MOZ_OLD_STYLE - mGecko = aOther.mGecko; - aOther.mGecko = nullptr; -#else MOZ_CRASH("old style system disabled"); -#endif } return *this; } @@ -1539,12 +1534,6 @@ public: , mServo(aList.release()) {} -#ifdef MOZ_OLD_STYLE - explicit SelectorList(mozilla::UniquePtr&& aList) - : mIsServo(false) - , mGecko(aList.release()) - {} -#endif ~SelectorList() { Reset(); @@ -3875,10 +3864,8 @@ protected: nsCOMPtr mDocumentBaseURI; nsCOMPtr mChromeXHRDocBaseURI; -#ifdef MOZ_STYLO // A lazily-constructed URL data for style system to resolve URL value. RefPtr mCachedURLData; -#endif nsWeakPtr mDocumentLoadGroup; diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index ea065fd51431..9a40f2c9baab 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -25,9 +25,6 @@ #include "mozilla/Telemetry.h" #include "mozilla/TextEditor.h" #include "mozilla/TimeStamp.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" -#endif #include "mozilla/dom/DocumentType.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/Event.h" @@ -87,9 +84,6 @@ #include "nsPIBoxObject.h" #include "nsPIDOMWindow.h" #include "nsPresContext.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleProcessorData.h" -#endif #include "nsString.h" #include "nsStyleConsts.h" #include "nsSVGUtils.h" @@ -99,9 +93,6 @@ #include "nsXBLPrototypeBinding.h" #include "mozilla/Preferences.h" #include "xpcpublic.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#endif #include "nsCSSParser.h" #include "HTMLLegendElement.h" #include "nsWrapperCacheInlines.h" @@ -2526,96 +2517,9 @@ nsINode::ParseServoSelectorList( return selectorList; } -#ifdef MOZ_OLD_STYLE -nsCSSSelectorList* -nsINode::ParseSelectorList(const nsAString& aSelectorString, - ErrorResult& aRv) -{ - nsIDocument* doc = OwnerDoc(); - nsIDocument::SelectorCache& cache = - doc->GetSelectorCache(mozilla::StyleBackendType::Gecko); - nsIDocument::SelectorCache::SelectorList* list = - cache.GetList(aSelectorString); - if (list) { - if (!*list) { - // Invalid selector. - aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR, - NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) + - NS_LITERAL_CSTRING("' is not a valid selector") - ); - return nullptr; - } - - return list->AsGecko(); - } - - nsCSSParser parser(doc->CSSLoader()); - - nsCSSSelectorList* selectorList = nullptr; - aRv = parser.ParseSelectorString(aSelectorString, - doc->GetDocumentURI(), - 0, // XXXbz get the line number! - &selectorList); - if (aRv.Failed()) { - // We hit this for syntax errors, which are quite common, so don't - // use NS_ENSURE_SUCCESS. (For example, jQuery has an extended set - // of selectors, but it sees if we can parse them first.) - MOZ_ASSERT(aRv.ErrorCodeIs(NS_ERROR_DOM_SYNTAX_ERR), - "Unexpected error, so cached version won't return it"); - - // Change the error message to match above. - aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR, - NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) + - NS_LITERAL_CSTRING("' is not a valid selector") - ); - - cache.CacheList(aSelectorString, UniquePtr()); - return nullptr; - } - - // Filter out pseudo-element selectors from selectorList - nsCSSSelectorList** slot = &selectorList; - do { - nsCSSSelectorList* cur = *slot; - if (cur->mSelectors->IsPseudoElement()) { - *slot = cur->mNext; - cur->mNext = nullptr; - delete cur; - } else { - slot = &cur->mNext; - } - } while (*slot); - - if (selectorList) { - NS_ASSERTION(selectorList->mSelectors, - "How can we not have any selectors?"); - cache.CacheList(aSelectorString, UniquePtr(selectorList)); - } else { - // This is the "only pseudo-element selectors" case, which is - // not common, so just don't worry about caching it. That way a - // null cached value can always indicate an invalid selector. - } - - return selectorList; -} - -static void -AddScopeElements(TreeMatchContext& aMatchContext, - nsINode* aMatchContextNode) -{ - if (aMatchContextNode->IsElement()) { - aMatchContext.SetHasSpecifiedScope(); - aMatchContext.AddScopeElement(aMatchContextNode->AsElement()); - } -} -#endif namespace { struct SelectorMatchInfo { -#ifdef MOZ_OLD_STYLE - nsCSSSelectorList* const mSelectorList; - TreeMatchContext& mMatchContext; -#endif }; } // namespace @@ -2652,11 +2556,6 @@ FindMatchingElementsWithId(const nsAString& aId, nsINode* aRoot, // We have an element with the right id and it's a strict descendant // of aRoot. Make sure it really matches the selector. if (!aMatchInfo -#ifdef MOZ_OLD_STYLE - || nsCSSRuleProcessor::SelectorListMatches(element, - aMatchInfo->mMatchContext, - aMatchInfo->mSelectorList) -#endif ) { aList.AppendElement(element); if (onlyFirstMatch) { @@ -2667,67 +2566,6 @@ FindMatchingElementsWithId(const nsAString& aId, nsINode* aRoot, } } -#ifdef MOZ_OLD_STYLE -// Actually find elements matching aSelectorList (which must not be -// null) and which are descendants of aRoot and put them in aList. If -// onlyFirstMatch, then stop once the first one is found. -template -MOZ_ALWAYS_INLINE static void -FindMatchingElements(nsINode* aRoot, nsCSSSelectorList* aSelectorList, T &aList, - ErrorResult& aRv) -{ - nsIDocument* doc = aRoot->OwnerDoc(); - - TreeMatchContext matchingContext(false, nsRuleWalker::eRelevantLinkUnvisited, - doc, TreeMatchContext::eNeverMatchVisited); - AddScopeElements(matchingContext, aRoot); - - // Fast-path selectors involving IDs. We can only do this if aRoot - // is in the document and the document is not in quirks mode, since - // ID selectors are case-insensitive in quirks mode. Also, only do - // this if aSelectorList only has one selector, because otherwise - // ordering the elements correctly is a pain. - NS_ASSERTION(aRoot->IsElement() || aRoot->IsNodeOfType(nsINode::eDOCUMENT) || - !aRoot->IsInUncomposedDoc(), - "The optimization below to check ContentIsDescendantOf only for " - "elements depends on aRoot being either an element or a " - "document if it's in the document."); - if (aRoot->IsInUncomposedDoc() && - doc->GetCompatibilityMode() != eCompatibility_NavQuirks && - !aSelectorList->mNext && - aSelectorList->mSelectors->mIDList) { - nsAtom* id = aSelectorList->mSelectors->mIDList->mAtom; - SelectorMatchInfo info = { aSelectorList, matchingContext }; - FindMatchingElementsWithId(nsDependentAtomString(id), - aRoot, &info, aList); - return; - } - - Collector results; - for (nsIContent* cur = aRoot->GetFirstChild(); - cur; - cur = cur->GetNextNode(aRoot)) { - if (cur->IsElement() && - nsCSSRuleProcessor::SelectorListMatches(cur->AsElement(), - matchingContext, - aSelectorList)) { - if (onlyFirstMatch) { - aList.AppendElement(cur->AsElement()); - return; - } - results.AppendElement(cur->AsElement()); - } - } - - const uint32_t len = results.Length(); - if (len) { - aList.SetCapacity(len); - for (uint32_t i = 0; i < len; ++i) { - aList.AppendElement(results.ElementAt(i)); - } - } -} -#endif struct ElementHolder { ElementHolder() : mElement(nullptr) {} @@ -2757,18 +2595,7 @@ nsINode::QuerySelector(const nsAString& aSelector, ErrorResult& aResult) Servo_SelectorList_QueryFirst(this, aList, useInvalidation)); }, [&](nsCSSSelectorList* aList) -> Element* { -#ifdef MOZ_OLD_STYLE - if (!aList) { - // Either we failed (and aResult already has the exception), or this - // is a pseudo-element-only selector that matches nothing. - return nullptr; - } - ElementHolder holder; - FindMatchingElements(this, aList, holder, aResult); - return holder.mElement; -#else MOZ_CRASH("old style system disabled"); -#endif } ); } @@ -2790,15 +2617,7 @@ nsINode::QuerySelectorAll(const nsAString& aSelector, ErrorResult& aResult) this, aList, contentList.get(), useInvalidation); }, [&](nsCSSSelectorList* aList) { -#ifdef MOZ_OLD_STYLE - if (!aList) { - return; - } - FindMatchingElements>( - this, aList, *contentList, aResult); -#else MOZ_CRASH("old style system disabled"); -#endif } ); @@ -2935,13 +2754,11 @@ nsINode::IsNodeApzAwareInternal() const return EventTarget::IsApzAware(); } -#ifdef MOZ_STYLO bool nsINode::IsStyledByServo() const { return OwnerDoc()->IsStyledByServo(); } -#endif DocGroup* nsINode::GetDocGroup() const diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 8c4cab81712e..3158a88ed9be 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -1043,11 +1043,7 @@ public: * Returns true if this is a node belonging to a document that uses the Servo * style system. */ -#ifdef MOZ_STYLO bool IsStyledByServo() const; -#else - bool IsStyledByServo() const { return false; } -#endif inline void UnsetRestyleFlagsIfGecko(); @@ -2083,11 +2079,7 @@ protected: if (IsStyledByServo()) { return aServoFunctor(ParseServoSelectorList(aSelectorString, aRv)); } -#ifdef MOZ_OLD_STYLE - return aGeckoFunctor(ParseSelectorList(aSelectorString, aRv)); -#else MOZ_CRASH("old style system disabled"); -#endif } public: diff --git a/dom/base/nsMappedAttributeElement.cpp b/dom/base/nsMappedAttributeElement.cpp index 1565e8bc1f17..ae9b08a630a0 100644 --- a/dom/base/nsMappedAttributeElement.cpp +++ b/dom/base/nsMappedAttributeElement.cpp @@ -7,14 +7,6 @@ #include "nsMappedAttributeElement.h" #include "nsIDocument.h" -#ifdef MOZ_OLD_STYLE -nsresult -nsMappedAttributeElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) -{ - mAttrsAndChildren.WalkMappedAttributeStyleRules(aRuleWalker); - return NS_OK; -} -#endif bool nsMappedAttributeElement::SetAndSwapMappedAttribute(nsAtom* aName, diff --git a/dom/base/nsMappedAttributeElement.h b/dom/base/nsMappedAttributeElement.h index 395a147a6b8f..a9ad760be7f0 100644 --- a/dom/base/nsMappedAttributeElement.h +++ b/dom/base/nsMappedAttributeElement.h @@ -39,9 +39,6 @@ public: static void MapNoAttributesInto(const nsMappedAttributes* aAttributes, mozilla::GenericSpecifiedValues* aGenericData); -#ifdef MOZ_OLD_STYLE - NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) override; -#endif virtual bool SetAndSwapMappedAttribute(nsAtom* aName, nsAttrValue& aValue, bool* aValueWasSet, diff --git a/dom/base/nsMappedAttributes.cpp b/dom/base/nsMappedAttributes.cpp index cc907a95cad0..9a8021f17e2d 100644 --- a/dom/base/nsMappedAttributes.cpp +++ b/dom/base/nsMappedAttributes.cpp @@ -11,10 +11,6 @@ #include "nsMappedAttributes.h" #include "nsHTMLStyleSheet.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleData.h" -#include "nsRuleWalker.h" -#endif #include "mozilla/GenericSpecifiedValues.h" #include "mozilla/HashFunctions.h" #include "mozilla/MemoryReporting.h" @@ -151,13 +147,6 @@ nsMappedAttributes::LastRelease() delete this; } -#ifdef MOZ_OLD_STYLE -NS_IMPL_ADDREF(nsMappedAttributes) -NS_IMPL_RELEASE_WITH_DESTROY(nsMappedAttributes, LastRelease()) - -NS_IMPL_QUERY_INTERFACE(nsMappedAttributes, - nsIStyleRule) -#endif void nsMappedAttributes::SetAndSwapAttr(nsAtom* aAttrName, nsAttrValue& aValue, @@ -258,56 +247,6 @@ nsMappedAttributes::SetStyleSheet(nsHTMLStyleSheet* aSheet) mSheet = aSheet; // not ref counted } -#ifdef MOZ_OLD_STYLE -/* virtual */ void -nsMappedAttributes::MapRuleInfoInto(nsRuleData* aRuleData) -{ - if (mRuleMapper) { - (*mRuleMapper)(this, aRuleData); - } -} - -/* virtual */ bool -nsMappedAttributes::MightMapInheritedStyleData() -{ - // Just assume that we do, rather than adding checks to all of the different - // kinds of attribute mapping functions we have. - return true; -} - -/* virtual */ bool -nsMappedAttributes::GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, - nsCSSValue* aValue) -{ - MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet"); - return false; -} - -#ifdef DEBUG -/* virtual */ void -nsMappedAttributes::List(FILE* out, int32_t aIndent) const -{ - nsAutoCString str; - nsAutoString tmp; - uint32_t i; - - for (i = 0; i < mAttrCount; ++i) { - int32_t indent; - for (indent = aIndent; indent > 0; --indent) { - str.AppendLiteral(" "); - } - - Attrs()[i].mName.GetQualifiedName(tmp); - LossyAppendUTF16toASCII(tmp, str); - - Attrs()[i].mValue.ToString(tmp); - LossyAppendUTF16toASCII(tmp, str); - str.Append('\n'); - fprintf_stderr(out, "%s", str.get()); - } -} -#endif -#endif void nsMappedAttributes::RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue) diff --git a/dom/base/nsMappedAttributes.h b/dom/base/nsMappedAttributes.h index 8b0b1cb65054..f9bd6a87fa46 100644 --- a/dom/base/nsMappedAttributes.h +++ b/dom/base/nsMappedAttributes.h @@ -14,9 +14,6 @@ #include "nsAttrAndChildArray.h" #include "nsMappedAttributeElement.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRule.h" -#endif #include "mozilla/Attributes.h" #include "mozilla/ServoBindingTypes.h" #include "mozilla/MemoryReporting.h" @@ -25,9 +22,6 @@ class nsAtom; class nsHTMLStyleSheet; class nsMappedAttributes final -#ifdef MOZ_OLD_STYLE - : public nsIStyleRule -#endif { public: nsMappedAttributes(nsHTMLStyleSheet* aSheet, @@ -37,11 +31,7 @@ public: void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW; nsMappedAttributes* Clone(bool aWillAddAttr); -#ifdef MOZ_OLD_STYLE - NS_DECL_ISUPPORTS -#else NS_INLINE_DECL_REFCOUNTING_WITH_DESTROY(nsMappedAttributes, LastRelease()) -#endif void SetAndSwapAttr(nsAtom* aAttrName, nsAttrValue& aValue, bool* aValueWasSet); @@ -99,16 +89,6 @@ public: mServoStyle = nullptr; } -#ifdef MOZ_OLD_STYLE - // nsIStyleRule - virtual void MapRuleInfoInto(nsRuleData* aRuleData) override; - virtual bool MightMapInheritedStyleData() override; - virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, - nsCSSValue* aValue) override; -#ifdef DEBUG - virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; -#endif -#endif size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; diff --git a/dom/base/nsTreeSanitizer.cpp b/dom/base/nsTreeSanitizer.cpp index 31e78009340c..8b7af4be8ac6 100644 --- a/dom/base/nsTreeSanitizer.cpp +++ b/dom/base/nsTreeSanitizer.cpp @@ -12,10 +12,6 @@ #include "mozilla/DeclarationBlockInlines.h" #include "mozilla/ServoDeclarationBlock.h" #include "mozilla/StyleSheetInlines.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/Declaration.h" -#include "mozilla/css/StyleRule.h" -#endif #include "mozilla/css/Rule.h" #include "mozilla/dom/CSSRuleList.h" #include "mozilla/dom/SRIMetadata.h" @@ -1100,12 +1096,7 @@ nsTreeSanitizer::SanitizeStyleSheet(const nsAString& aOriginal, CORS_NONE, aDocument->GetReferrerPolicy(), SRIMetadata()); } else { -#ifdef MOZ_OLD_STYLE - sheet = new CSSStyleSheet(mozilla::css::eAuthorSheetFeatures, - CORS_NONE, aDocument->GetReferrerPolicy()); -#else MOZ_CRASH("old style system disabled"); -#endif } sheet->SetURIs(aDocument->GetDocumentURI(), nullptr, aBaseURI); sheet->SetPrincipal(aDocument->NodePrincipal()); @@ -1115,15 +1106,7 @@ nsTreeSanitizer::SanitizeStyleSheet(const nsAString& aOriginal, aDocument->GetDocumentURI(), aBaseURI, aDocument->NodePrincipal(), /* aLoadData = */ nullptr, 0, aDocument->GetCompatibilityMode()); } else { -#ifdef MOZ_OLD_STYLE - // Create the CSS parser, and parse the CSS text. - nsCSSParser parser(nullptr, sheet->AsGecko()); - rv = parser.ParseSheet(aOriginal, aDocument->GetDocumentURI(), - aBaseURI, aDocument->NodePrincipal(), - /* aLoadData = */ nullptr, 0); -#else MOZ_CRASH("old style system disabled"); -#endif } NS_ENSURE_SUCCESS(rv, true); // Mark the sheet as complete. @@ -1206,16 +1189,7 @@ nsTreeSanitizer::SanitizeAttributes(mozilla::dom::Element* aElement, document->GetCompatibilityMode(), document->CSSLoader()); } else { -#ifdef MOZ_OLD_STYLE - // Pass the CSS Loader object to the parser, to allow parser error - // reports to include the outer window ID. - nsCSSParser parser(document->CSSLoader()); - decl = parser.ParseStyleAttribute(value, document->GetDocumentURI(), - aElement->GetBaseURIForStyleAttr(), - document->NodePrincipal()); -#else MOZ_CRASH("old style system disabled"); -#endif } if (decl) { if (SanitizeStyleDeclaration(decl)) { diff --git a/dom/base/nsTreeSanitizer.h b/dom/base/nsTreeSanitizer.h index 397d30e58cb1..ba6fff6a093b 100644 --- a/dom/base/nsTreeSanitizer.h +++ b/dom/base/nsTreeSanitizer.h @@ -5,9 +5,6 @@ #ifndef nsTreeSanitizer_h_ #define nsTreeSanitizer_h_ -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" -#endif #include "nsIPrincipal.h" #include "mozilla/dom/Element.h" diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 8666564b4d0c..9b9ab0d9342e 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -27,14 +27,7 @@ #include "nsCSSParser.h" #include "nsCSSPseudoElements.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" -#include "mozilla/css/Declaration.h" -#endif #include "nsComputedDOMStyle.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsPrintfCString.h" @@ -759,27 +752,13 @@ CanvasGradient::AddColorStop(float aOffset, const nsAString& aColorstr, ErrorRes : nullptr; bool useServoParser = -#ifdef MOZ_OLD_STYLE - servoStyleSet; -#else true; -#endif if (useServoParser) { ok = ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0), aColorstr, &color); } else { -#ifdef MOZ_OLD_STYLE - nsCSSValue value; - nsCSSParser parser; - - nsPresContext* presContext = shell ? shell->GetPresContext() : nullptr; - - ok = parser.ParseColorString(aColorstr, nullptr, 0, value) && - nsRuleNode::ComputeColor(value, presContext, nullptr, color); -#else MOZ_CRASH("old style system disabled"); -#endif } if (!ok) { @@ -1180,11 +1159,7 @@ CanvasRenderingContext2D::ParseColor(const nsAString& aString, css::Loader* loader = document ? document->CSSLoader() : nullptr; bool useServoParser = -#ifdef MOZ_OLD_STYLE - document && document->IsStyledByServo(); -#else true; -#endif if (useServoParser) { nsIPresShell* presShell = GetPresShell(); @@ -1210,36 +1185,7 @@ CanvasRenderingContext2D::ParseColor(const nsAString& aString, return true; } -#ifdef MOZ_OLD_STYLE - // Pass the CSS Loader object to the parser, to allow parser error - // reports to include the outer window ID. - nsCSSParser parser(loader); - nsCSSValue value; - if (!parser.ParseColorString(aString, nullptr, 0, value)) { - return false; - } - - if (value.IsNumericColorUnit()) { - // if we already have a color we can just use it directly - *aColor = value.GetColorValue(); - } else { - // otherwise resolve it - nsCOMPtr presShell = GetPresShell(); - RefPtr parentContext; - if (mCanvasElement && mCanvasElement->IsInComposedDoc()) { - // Inherit from the canvas element. - parentContext = - nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr); - } - - Unused << nsRuleNode::ComputeColor( - value, presShell ? presShell->GetPresContext() : nullptr, parentContext, - *aColor); - } - return true; -#else MOZ_CRASH("old style system disabled"); -#endif } nsresult @@ -2691,161 +2637,6 @@ CanvasRenderingContext2D::SetShadowColor(const nsAString& aShadowColor) // filters // -#ifdef MOZ_OLD_STYLE -static already_AddRefed -CreateDeclaration(nsINode* aNode, - const nsCSSPropertyID aProp1, const nsAString& aValue1, bool* aChanged1, - const nsCSSPropertyID aProp2, const nsAString& aValue2, bool* aChanged2) -{ - nsIPrincipal* principal = aNode->NodePrincipal(); - nsIDocument* document = aNode->OwnerDoc(); - - nsIURI* docURL = document->GetDocumentURI(); - nsIURI* baseURL = document->GetDocBaseURI(); - - // Pass the CSS Loader object to the parser, to allow parser error reports - // to include the outer window ID. - nsCSSParser parser(document->CSSLoader()); - - RefPtr declaration = - parser.ParseStyleAttribute(EmptyString(), docURL, baseURL, principal); - - if (aProp1 != eCSSProperty_UNKNOWN) { - parser.ParseProperty(aProp1, aValue1, docURL, baseURL, principal, - declaration, aChanged1, false); - } - - if (aProp2 != eCSSProperty_UNKNOWN) { - parser.ParseProperty(aProp2, aValue2, docURL, baseURL, principal, - declaration, aChanged2, false); - } - - declaration->SetImmutable(); - return declaration.forget(); -} - -static already_AddRefed -CreateFontDeclaration(const nsAString& aFont, - nsINode* aNode, - bool* aOutFontChanged) -{ - bool lineHeightChanged; - return CreateDeclaration(aNode, - eCSSProperty_font, aFont, aOutFontChanged, - eCSSProperty_line_height, NS_LITERAL_STRING("normal"), &lineHeightChanged); -} - -static already_AddRefed -GetFontParentStyleContext(Element* aElement, - nsIPresShell* aPresShell, - ErrorResult& aError) -{ - if (aElement && aElement->IsInComposedDoc()) { - // Inherit from the canvas element. - RefPtr result = - nsComputedDOMStyle::GetStyleContext(aElement, nullptr); - if (!result) { - aError.Throw(NS_ERROR_FAILURE); - return nullptr; - } - return GeckoStyleContext::TakeRef(result.forget()); - } - - // otherwise inherit from default (10px sans-serif) - - bool changed; - RefPtr parentRule = - CreateFontDeclaration(NS_LITERAL_STRING("10px sans-serif"), - aPresShell->GetDocument(), &changed); - - nsTArray> parentRules; - parentRules.AppendElement(parentRule); - - nsStyleSet* styleSet = aPresShell->StyleSet()->GetAsGecko(); - MOZ_RELEASE_ASSERT(styleSet); - - RefPtr result = - styleSet->ResolveStyleForRules(nullptr, parentRules); - - if (!result) { - aError.Throw(NS_ERROR_FAILURE); - return nullptr; - } - return result.forget(); -} - -static bool -PropertyIsInheritOrInitial(Declaration* aDeclaration, const nsCSSPropertyID aProperty) -{ - // We know the declaration is not !important, so we can use - // GetNormalBlock(). - const nsCSSValue* filterVal = - aDeclaration->GetNormalBlock()->ValueFor(aProperty); - return (!filterVal || (filterVal->GetUnit() == eCSSUnit_Unset || - filterVal->GetUnit() == eCSSUnit_Inherit || - filterVal->GetUnit() == eCSSUnit_Initial)); -} - -static already_AddRefed -GetFontStyleContext(Element* aElement, const nsAString& aFont, - nsIPresShell* aPresShell, - nsAString& aOutUsedFont, - ErrorResult& aError) -{ - bool fontParsedSuccessfully = false; - RefPtr decl = - CreateFontDeclaration(aFont, aPresShell->GetDocument(), - &fontParsedSuccessfully); - - if (!fontParsedSuccessfully) { - // We got a syntax error. The spec says this value must be ignored. - return nullptr; - } - - // In addition to unparseable values, the spec says we need to reject - // 'inherit' and 'initial'. The easiest way to check for this is to look - // at font-size-adjust, which the font shorthand resets to either 'none' or - // '-moz-system-font'. - if (PropertyIsInheritOrInitial(decl, eCSSProperty_font_size_adjust)) { - return nullptr; - } - - // have to get a parent style context for inherit-like relative - // values (2em, bolder, etc.) - RefPtr parentContext = - GetFontParentStyleContext(aElement, aPresShell, aError); - - if (aError.Failed()) { - aError.Throw(NS_ERROR_FAILURE); - return nullptr; - } - - MOZ_RELEASE_ASSERT(parentContext, - "GFX: GetFontParentStyleContext should have returned an error if it couldn't get a parent context."); - - MOZ_ASSERT(!aPresShell->IsDestroying(), - "GetFontParentStyleContext should have returned an error if the presshell is being destroyed."); - - nsTArray> rules; - rules.AppendElement(decl); - // add a rule to prevent text zoom from affecting the style - rules.AppendElement(new nsDisableTextZoomStyleRule); - - nsStyleSet* styleSet = aPresShell->StyleSet()->GetAsGecko(); - MOZ_RELEASE_ASSERT(styleSet); - - RefPtr sc = - styleSet->ResolveStyleForRules(parentContext, rules); - - // The font getter is required to be reserialized based on what we - // parsed (including having line-height removed). (Older drafts of - // the spec required font sizes be converted to pixels, but that no - // longer seems to be required.) - decl->GetPropertyValueByID(eCSSProperty_font, aOutUsedFont); - - return sc.forget(); -} -#endif static already_AddRefed CreateDeclarationForServo(nsCSSPropertyID aProperty, @@ -2955,52 +2746,6 @@ GetFontStyleForServo(Element* aElement, const nsAString& aFont, return sc.forget(); } -#ifdef MOZ_OLD_STYLE -static already_AddRefed -CreateFilterDeclaration(const nsAString& aFilter, - nsINode* aNode, - bool* aOutFilterChanged) -{ - bool dummy; - return CreateDeclaration(aNode, - eCSSProperty_filter, aFilter, aOutFilterChanged, - eCSSProperty_UNKNOWN, EmptyString(), &dummy); -} - -static already_AddRefed -ResolveFilterStyle(const nsAString& aFilterString, - nsIPresShell* aPresShell, - GeckoStyleContext* aParentContext, - ErrorResult& aError) -{ - nsIDocument* document = aPresShell->GetDocument(); - bool filterChanged = false; - RefPtr decl = - CreateFilterDeclaration(aFilterString, document, &filterChanged); - - if (!filterChanged) { - // Refuse to accept the filter, but do not throw an error. - return nullptr; - } - - // In addition to unparseable values, the spec says we need to reject - // 'inherit' and 'initial'. - if (PropertyIsInheritOrInitial(decl, eCSSProperty_filter)) { - return nullptr; - } - - nsTArray> rules; - rules.AppendElement(decl); - - nsStyleSet* styleSet = aPresShell->StyleSet()->GetAsGecko(); - MOZ_RELEASE_ASSERT(styleSet); - - RefPtr sc = - styleSet->ResolveStyleForRules(aParentContext, rules); - - return sc.forget(); -} -#endif static already_AddRefed CreateFilterDeclarationForServo(const nsAString& aFilter, @@ -3057,26 +2802,8 @@ CanvasRenderingContext2D::ParseFilter(const nsAString& aString, nsString usedFont; if (presShell->StyleSet()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - RefPtr parentContext = - GetFontStyleContext(mCanvasElement, GetFont(), - presShell, usedFont, aError); - if (!parentContext) { - aError.Throw(NS_ERROR_FAILURE); - return false; - } - RefPtr sc = - ResolveFilterStyle(aString, presShell, parentContext, aError); - - if (!sc) { - return false; - } - aFilterChain = sc->StyleEffects()->mFilters; - return true; -#else MOZ_CRASH("old style system disabled"); return false; -#endif } // For stylo @@ -4014,12 +3741,7 @@ CanvasRenderingContext2D::SetFontInternal(const nsAString& aFont, sc = GetFontStyleForServo(mCanvasElement, aFont, presShell, usedFont, aError); } else { -#ifdef MOZ_OLD_STYLE - sc = - GetFontStyleContext(mCanvasElement, aFont, presShell, usedFont, aError); -#else MOZ_CRASH("old style system disabled"); -#endif } if (!sc) { return false; diff --git a/dom/html/HTMLBodyElement.cpp b/dom/html/HTMLBodyElement.cpp index f059d44f14ed..6991b836e746 100644 --- a/dom/html/HTMLBodyElement.cpp +++ b/dom/html/HTMLBodyElement.cpp @@ -19,9 +19,6 @@ #include "nsHTMLStyleSheet.h" #include "nsMappedAttributes.h" #include "nsIDocShell.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#endif #include "nsGlobalWindow.h" NS_IMPL_NS_NEW_HTML_ELEMENT(Body) diff --git a/dom/html/HTMLBodyElement.h b/dom/html/HTMLBodyElement.h index fc5d2393e716..e1049135597a 100644 --- a/dom/html/HTMLBodyElement.h +++ b/dom/html/HTMLBodyElement.h @@ -8,9 +8,6 @@ #include "mozilla/Attributes.h" #include "nsGenericHTMLElement.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRule.h" -#endif namespace mozilla { diff --git a/dom/html/HTMLHRElement.h b/dom/html/HTMLHRElement.h index 3e9f550ee166..eb919ec0ae87 100644 --- a/dom/html/HTMLHRElement.h +++ b/dom/html/HTMLHRElement.h @@ -11,9 +11,6 @@ #include "nsGenericHTMLElement.h" #include "nsMappedAttributes.h" #include "nsAttrValueInlines.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleData.h" -#endif namespace mozilla { namespace dom { diff --git a/dom/html/HTMLOptionsCollection.cpp b/dom/html/HTMLOptionsCollection.cpp index d1f8d5094b68..3fadef34a2bf 100644 --- a/dom/html/HTMLOptionsCollection.cpp +++ b/dom/html/HTMLOptionsCollection.cpp @@ -26,9 +26,6 @@ #include "nsIListControlFrame.h" #include "nsLayoutUtils.h" #include "nsMappedAttributes.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleData.h" -#endif #include "nsServiceManagerUtils.h" #include "nsStyleConsts.h" #include "jsfriendapi.h" diff --git a/dom/html/HTMLSpanElement.h b/dom/html/HTMLSpanElement.h index 0f7474be9f8d..7dc0a39f7c48 100644 --- a/dom/html/HTMLSpanElement.h +++ b/dom/html/HTMLSpanElement.h @@ -12,9 +12,6 @@ #include "nsGkAtoms.h" #include "nsStyleConsts.h" #include "nsAtom.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleData.h" -#endif namespace mozilla { namespace dom { diff --git a/dom/html/HTMLTableCellElement.cpp b/dom/html/HTMLTableCellElement.cpp index 234f15c50cdd..5b8a7d90e3cc 100644 --- a/dom/html/HTMLTableCellElement.cpp +++ b/dom/html/HTMLTableCellElement.cpp @@ -10,9 +10,6 @@ #include "mozilla/GenericSpecifiedValuesInlines.h" #include "nsMappedAttributes.h" #include "nsAttrValueInlines.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#endif #include "celldata.h" #include "mozilla/dom/HTMLTableCellElementBinding.h" @@ -93,21 +90,6 @@ HTMLTableCellElement::CellIndex() const return -1; } -#ifdef MOZ_OLD_STYLE -NS_IMETHODIMP -HTMLTableCellElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) -{ - nsresult rv = nsGenericHTMLElement::WalkContentStyleRules(aRuleWalker); - NS_ENSURE_SUCCESS(rv, rv); - - if (nsMappedAttributes* tableInheritedAttributes = GetMappedAttributesInheritedFromTable()) { - if (tableInheritedAttributes) { - aRuleWalker->Forward(tableInheritedAttributes); - } - } - return NS_OK; -} -#endif nsMappedAttributes* HTMLTableCellElement::GetMappedAttributesInheritedFromTable() const diff --git a/dom/html/HTMLTableCellElement.h b/dom/html/HTMLTableCellElement.h index 11d5b7d8e0fd..8843653366f3 100644 --- a/dom/html/HTMLTableCellElement.h +++ b/dom/html/HTMLTableCellElement.h @@ -143,9 +143,6 @@ public: nsIPrincipal* aMaybeScriptedPrincipal, nsAttrValue& aResult) override; virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override; -#ifdef MOZ_OLD_STYLE - NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) override; -#endif NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; // Get mapped attributes of ancestor table, if any nsMappedAttributes* GetMappedAttributesInheritedFromTable() const; diff --git a/dom/html/HTMLTrackElement.cpp b/dom/html/HTMLTrackElement.cpp index 72b0c423ccba..a6eaaabda3ff 100644 --- a/dom/html/HTMLTrackElement.cpp +++ b/dom/html/HTMLTrackElement.cpp @@ -35,9 +35,6 @@ #include "nsISupportsPrimitives.h" #include "nsMappedAttributes.h" #include "nsNetUtil.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleData.h" -#endif #include "nsStyleConsts.h" #include "nsThreadUtils.h" #include "nsVideoFrame.h" diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 20de0562d20f..31857e273357 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -23,9 +23,6 @@ #include "nsQueryObject.h" #include "nsIContentInlines.h" #include "nsIContentViewer.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/Declaration.h" -#endif #include "nsIDocument.h" #include "nsIDocumentEncoder.h" #include "nsIDOMDocumentFragment.h" @@ -2966,39 +2963,7 @@ IsOrHasAncestorWithDisplayNone(Element* aElement, nsIPresShell* aPresShell) return !aElement->HasServoData() || Servo_Element_IsDisplayNone(aElement); } -#ifdef MOZ_OLD_STYLE - AutoTArray elementsToCheck; - // Style and layout work on the flattened tree, so this is what we need to - // check in order to figure out whether we're in a display: none subtree. - for (Element* e = aElement; e; e = e->GetFlattenedTreeParentElement()) { - if (e->GetPrimaryFrame()) { - // e definitely isn't display:none and doesn't have a display:none - // ancestor. - break; - } - elementsToCheck.AppendElement(e); - } - - if (elementsToCheck.IsEmpty()) { - return false; - } - - nsStyleSet* styleSet = aPresShell->StyleSet()->AsGecko(); - RefPtr sc; - for (auto* element : Reversed(elementsToCheck)) { - if (sc) { - sc = styleSet->ResolveStyleFor(element, sc, LazyComputeBehavior::Assert); - } else { - sc = nsComputedDOMStyle::GetStyleContextNoFlush(element, nullptr) - .downcast(); - } - if (sc->StyleDisplay()->mDisplay == StyleDisplay::None) { - return true; - } - } -#else MOZ_CRASH("Old style system disabled"); -#endif return false; } diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 4ce5c6bf23d5..c8d6e215b753 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2301,11 +2301,7 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority) // Content processes have no permission to access profile directory, so we // send the file URL instead. StyleBackendType backendType = -#ifdef MOZ_OLD_STYLE - StyleBackendType::Gecko; -#else StyleBackendType::Servo; -#endif StyleSheet* ucs = nsLayoutStylesheetCache::For(backendType)->UserContentSheet(); if (ucs) { SerializeURI(ucs->GetSheetURI(), xpcomInit.userContentSheetURL()); diff --git a/dom/mathml/nsMathMLElement.cpp b/dom/mathml/nsMathMLElement.cpp index 53fc99a0b5a6..63756b608f88 100644 --- a/dom/mathml/nsMathMLElement.cpp +++ b/dom/mathml/nsMathMLElement.cpp @@ -12,9 +12,6 @@ #include "nsITableCellLayout.h" // for MAX_COLSPAN / MAX_ROWSPAN #include "nsCRT.h" #include "nsLayoutStylesheetCache.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleData.h" -#endif #include "nsCSSValue.h" #include "nsCSSParser.h" #include "nsMappedAttributes.h" diff --git a/dom/smil/nsSMILCSSProperty.cpp b/dom/smil/nsSMILCSSProperty.cpp index 41761c8fa0e9..c772029b002b 100644 --- a/dom/smil/nsSMILCSSProperty.cpp +++ b/dom/smil/nsSMILCSSProperty.cpp @@ -75,15 +75,7 @@ nsSMILCSSProperty::GetBaseValue() const return baseValue; } } else { -#ifdef MOZ_OLD_STYLE - if (!StyleAnimationValue::ExtractComputedValue(mPropID, - mBaseStyleContext->AsGecko(), - computedValue.mGecko)) { - return baseValue; - } -#else MOZ_CRASH("old style system disabled"); -#endif } baseValue = diff --git a/dom/smil/nsSMILCSSValueType.cpp b/dom/smil/nsSMILCSSValueType.cpp index c3b45eef476f..e5120d6628ab 100644 --- a/dom/smil/nsSMILCSSValueType.cpp +++ b/dom/smil/nsSMILCSSValueType.cpp @@ -41,16 +41,8 @@ struct ValueWrapper { mServoValues.AppendElement(aValue.mServo); return; } -#ifdef MOZ_OLD_STYLE - mGeckoValue = aValue.mGecko; -#else MOZ_CRASH("old style system disabled"); -#endif } -#ifdef MOZ_OLD_STYLE - ValueWrapper(nsCSSPropertyID aPropID, const StyleAnimationValue& aValue) - : mPropID(aPropID), mGeckoValue(aValue) {} -#endif ValueWrapper(nsCSSPropertyID aPropID, const RefPtr& aValue) : mPropID(aPropID), mServoValues{(aValue)} {} @@ -77,11 +69,7 @@ struct ValueWrapper { return true; } -#ifdef MOZ_OLD_STYLE - return mGeckoValue == aOther.mGeckoValue; -#else MOZ_CRASH("old style system disabled"); -#endif } bool operator!=(const ValueWrapper& aOther) const @@ -91,42 +79,10 @@ struct ValueWrapper { nsCSSPropertyID mPropID; ServoAnimationValues mServoValues; -#ifdef MOZ_OLD_STYLE - StyleAnimationValue mGeckoValue; -#endif }; // Helper Methods // -------------- -#ifdef MOZ_OLD_STYLE -static const StyleAnimationValue* -GetZeroValueForUnit(StyleAnimationValue::Unit aUnit) -{ - static const StyleAnimationValue - sZeroCoord(0, StyleAnimationValue::CoordConstructor); - static const StyleAnimationValue - sZeroPercent(0.0f, StyleAnimationValue::PercentConstructor); - static const StyleAnimationValue - sZeroFloat(0.0f, StyleAnimationValue::FloatConstructor); - static const StyleAnimationValue - sZeroColor(NS_RGB(0,0,0), StyleAnimationValue::ColorConstructor); - - MOZ_ASSERT(aUnit != StyleAnimationValue::eUnit_Null, - "Need non-null unit for a zero value"); - switch (aUnit) { - case StyleAnimationValue::eUnit_Coord: - return &sZeroCoord; - case StyleAnimationValue::eUnit_Percent: - return &sZeroPercent; - case StyleAnimationValue::eUnit_Float: - return &sZeroFloat; - case StyleAnimationValue::eUnit_Color: - return &sZeroColor; - default: - return nullptr; - } -} -#endif // If one argument is null, this method updates it to point to "zero" // for the other argument's Unit (if applicable; otherwise, we return false). @@ -161,61 +117,6 @@ FinalizeServoAnimationValues(const RefPtr*& aValue1, return *aValue1 && *aValue2; } -#ifdef MOZ_OLD_STYLE -static bool -FinalizeStyleAnimationValues(const StyleAnimationValue*& aValue1, - const StyleAnimationValue*& aValue2) -{ - if (!aValue1 && !aValue2) { - return false; - } - - if (!aValue1) { - aValue1 = GetZeroValueForUnit(aValue2->GetUnit()); - return !!aValue1; // Fail if we have no zero value for this unit. - } - if (!aValue2) { - aValue2 = GetZeroValueForUnit(aValue1->GetUnit()); - return !!aValue2; // Fail if we have no zero value for this unit. - } - - // Ok, both values were specified. - // Need to handle a special-case, though: unitless nonzero length (parsed as - // eUnit_Float) mixed with unitless 0 length (parsed as eUnit_Coord). These - // won't interoperate in StyleAnimationValue, since their Units don't match. - // In this case, we replace the eUnit_Coord 0 value with eUnit_Float 0 value. - const StyleAnimationValue& zeroCoord = - *GetZeroValueForUnit(StyleAnimationValue::eUnit_Coord); - if (*aValue1 == zeroCoord && - aValue2->GetUnit() == StyleAnimationValue::eUnit_Float) { - aValue1 = GetZeroValueForUnit(StyleAnimationValue::eUnit_Float); - } else if (*aValue2 == zeroCoord && - aValue1->GetUnit() == StyleAnimationValue::eUnit_Float) { - aValue2 = GetZeroValueForUnit(StyleAnimationValue::eUnit_Float); - } - - return true; -} - -static void -InvertSign(StyleAnimationValue& aValue) -{ - switch (aValue.GetUnit()) { - case StyleAnimationValue::eUnit_Coord: - aValue.SetCoordValue(-aValue.GetCoordValue()); - break; - case StyleAnimationValue::eUnit_Percent: - aValue.SetPercentValue(-aValue.GetPercentValue()); - break; - case StyleAnimationValue::eUnit_Float: - aValue.SetFloatValue(-aValue.GetFloatValue()); - break; - default: - NS_NOTREACHED("Calling InvertSign with an unsupported unit"); - break; - } -} -#endif static ValueWrapper* ExtractValueWrapper(nsSMILValue& aValue) @@ -413,36 +314,7 @@ AddOrAccumulate(nsSMILValue& aDest, const nsSMILValue& aValueToAdd, aCount); } -#ifdef MOZ_OLD_STYLE - const StyleAnimationValue* valueToAdd = valueToAddWrapper ? - &valueToAddWrapper->mGeckoValue : nullptr; - const StyleAnimationValue* destValue = destWrapper ? - &destWrapper->mGeckoValue : nullptr; - if (!FinalizeStyleAnimationValues(valueToAdd, destValue)) { - return false; - } - // Did FinalizeStyleAnimationValues change destValue? - // If so, update outparam to use the new value. - if (destWrapper && &destWrapper->mGeckoValue != destValue) { - destWrapper->mGeckoValue = *destValue; - } - - // Handle barely-initialized "zero" destination. - if (!destWrapper) { - aDest.mU.mPtr = destWrapper = new ValueWrapper(property, *destValue); - } - - // For Gecko, we currently call Add for either composite mode. - // - // This is not ideal, but it doesn't make any difference for the set of - // properties we currently allow adding in SMIL and this code path will - // hopefully become obsolete before we expand that set. - return StyleAnimationValue::Add(property, - destWrapper->mGeckoValue, - *valueToAdd, aCount); -#else MOZ_CRASH("old style system disabled"); -#endif } nsresult @@ -519,52 +391,9 @@ nsSMILCSSValueType::ComputeDistance(const nsSMILValue& aFrom, return ComputeDistanceForServo(fromWrapper, *toWrapper, aDistance); } -#ifdef MOZ_OLD_STYLE - const StyleAnimationValue* fromCSSValue = fromWrapper ? - &fromWrapper->mGeckoValue : nullptr; - const StyleAnimationValue* toCSSValue = &toWrapper->mGeckoValue; - if (!FinalizeStyleAnimationValues(fromCSSValue, toCSSValue)) { - return NS_ERROR_FAILURE; - } - - return StyleAnimationValue::ComputeDistance(toWrapper->mPropID, - fromWrapper->mGeckoValue, - toWrapper->mGeckoValue, - nullptr, - aDistance) - ? NS_OK - : NS_ERROR_FAILURE; -#else MOZ_CRASH("old style system disabled"); -#endif } -#ifdef MOZ_OLD_STYLE -static nsresult -InterpolateForGecko(const ValueWrapper* aStartWrapper, - const ValueWrapper& aEndWrapper, - double aUnitDistance, - nsSMILValue& aResult) -{ - const StyleAnimationValue* startCSSValue = aStartWrapper - ? &aStartWrapper->mGeckoValue - : nullptr; - const StyleAnimationValue* endCSSValue = &aEndWrapper.mGeckoValue; - if (!FinalizeStyleAnimationValues(startCSSValue, endCSSValue)) { - return NS_ERROR_FAILURE; - } - - StyleAnimationValue resultValue; - if (StyleAnimationValue::Interpolate(aEndWrapper.mPropID, - *startCSSValue, - *endCSSValue, - aUnitDistance, resultValue)) { - aResult.mU.mPtr = new ValueWrapper(aEndWrapper.mPropID, resultValue); - return NS_OK; - } - return NS_ERROR_FAILURE; -} -#endif static nsresult InterpolateForServo(const ValueWrapper* aStartWrapper, @@ -644,14 +473,7 @@ nsSMILCSSValueType::Interpolate(const nsSMILValue& aStartVal, aResult); } -#ifdef MOZ_OLD_STYLE - return InterpolateForGecko(startWrapper, - *endWrapper, - aUnitDistance, - aResult); -#else MOZ_CRASH("old style system disabled"); -#endif } // Helper function to extract presContext @@ -668,65 +490,6 @@ GetPresContextForElement(Element* aElem) return doc->GetPresContext(); } -#ifdef MOZ_OLD_STYLE -static const nsDependentSubstring -GetNonNegativePropValue(const nsAString& aString, nsCSSPropertyID aPropID, - bool& aIsNegative) -{ - // If value is negative, we'll strip off the "-" so the CSS parser won't - // barf, and then manually make the parsed value negative. - // (This is a partial solution to let us accept some otherwise out-of-bounds - // CSS values. Bug 501188 will provide a more complete fix.) - aIsNegative = false; - uint32_t subStringBegin = 0; - - // NOTE: We need to opt-out 'stroke-dasharray' from the negative-number - // check. Its values might look negative (e.g. by starting with "-1"), but - // they're more complicated than our simple negation logic here can handle. - if (aPropID != eCSSProperty_stroke_dasharray) { - int32_t absValuePos = nsSMILParserUtils::CheckForNegativeNumber(aString); - if (absValuePos > 0) { - aIsNegative = true; - subStringBegin = (uint32_t)absValuePos; // Start parsing after '-' sign - } - } - - return Substring(aString, subStringBegin); -} - -// Helper function to parse a string into a StyleAnimationValue -static bool -ValueFromStringHelper(nsCSSPropertyID aPropID, - Element* aTargetElement, - nsPresContext* aPresContext, - mozilla::GeckoStyleContext* aStyleContext, - const nsAString& aString, - StyleAnimationValue& aStyleAnimValue, - bool* aIsContextSensitive) -{ - bool isNegative = false; - const nsDependentSubstring subString = - GetNonNegativePropValue(aString, aPropID, isNegative); - - if (!StyleAnimationValue::ComputeValue(aPropID, aTargetElement, aStyleContext, - subString, true, aStyleAnimValue, - aIsContextSensitive)) { - return false; - } - if (isNegative) { - InvertSign(aStyleAnimValue); - } - - if (aPropID == eCSSProperty_font_size) { - // Divide out text-zoom, since SVG is supposed to ignore it - MOZ_ASSERT(aStyleAnimValue.GetUnit() == StyleAnimationValue::eUnit_Coord, - "'font-size' value with unexpected style unit"); - aStyleAnimValue.SetCoordValue(aStyleAnimValue.GetCoordValue() / - aPresContext->EffectiveTextZoom()); - } - return true; -} -#endif static ServoAnimationValues ValueFromStringHelper(nsCSSPropertyID aPropID, @@ -809,17 +572,7 @@ nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID, return; } -#ifdef MOZ_OLD_STYLE - StyleAnimationValue parsedValue; - if (ValueFromStringHelper(aPropID, aTargetElement, presContext, - styleContext->AsGecko(), aString, parsedValue, - aIsContextSensitive)) { - sSingleton.Init(aValue); - aValue.mU.mPtr = new ValueWrapper(aPropID, parsedValue); - } -#else MOZ_CRASH("old style system disabled"); -#endif } // static @@ -864,15 +617,7 @@ nsSMILCSSValueType::ValueToString(const nsSMILValue& aValue, } if (wrapper->mServoValues.IsEmpty()) { -#ifdef MOZ_OLD_STYLE - DebugOnly uncomputeResult = - StyleAnimationValue::UncomputeValue(wrapper->mPropID, - wrapper->mGeckoValue, - aString); - return; -#else MOZ_CRASH("old style system disabled"); -#endif } if (nsCSSProps::IsShorthand(wrapper->mPropID)) { @@ -944,16 +689,6 @@ nsSMILCSSValueType::FinalizeValue(nsSMILValue& aValue, aValue.mU.mPtr = new ValueWrapper(valueToMatchWrapper->mPropID, Move(zeroValues)); } else { -#ifdef MOZ_OLD_STYLE - const StyleAnimationValue* zeroValue = - GetZeroValueForUnit(valueToMatchWrapper->mGeckoValue.GetUnit()); - if (!zeroValue) { - return; - } - aValue.mU.mPtr = new ValueWrapper(valueToMatchWrapper->mPropID, - *zeroValue); -#else MOZ_CRASH("old style system disabled"); -#endif } } diff --git a/dom/svg/nsSVGElement.cpp b/dom/svg/nsSVGElement.cpp index 8bdca15bfbd6..e25db7ab9d52 100644 --- a/dom/svg/nsSVGElement.cpp +++ b/dom/svg/nsSVGElement.cpp @@ -23,10 +23,6 @@ #include "nsError.h" #include "nsIPresShell.h" #include "nsGkAtoms.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#include "mozilla/css/Declaration.h" -#endif #include "nsCSSProps.h" #include "nsCSSParser.h" #include "mozilla/EventListenerManager.h" @@ -925,26 +921,6 @@ nsSVGElement::NodeInfoChanged(nsIDocument* aOldDoc) OwnerDoc()->ScheduleSVGForPresAttrEvaluation(this); } -#ifdef MOZ_OLD_STYLE -NS_IMETHODIMP -nsSVGElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) -{ -#ifdef DEBUG -// printf("nsSVGElement(%p)::WalkContentStyleRules()\n", this); -#endif - if (!mContentDeclarationBlock) { - UpdateContentDeclarationBlock(StyleBackendType::Gecko); - } - - if (mContentDeclarationBlock) { - css::Declaration* declaration = mContentDeclarationBlock->AsGecko(); - declaration->SetImmutable(); - aRuleWalker->Forward(declaration); - } - - return NS_OK; -} -#endif NS_IMETHODIMP_(bool) nsSVGElement::IsAttributeMapped(const nsAtom* name) const @@ -1186,9 +1162,6 @@ private: // MEMBER DATA // ----------- css::Loader* mLoader; -#ifdef MOZ_OLD_STYLE - nsCSSParser mParser; -#endif // Arguments for nsCSSParser::ParseProperty nsIURI* mDocURI; @@ -1209,9 +1182,6 @@ MappedAttrParser::MappedAttrParser(css::Loader* aLoader, nsSVGElement* aElement, StyleBackendType aBackend) : mLoader(aLoader) -#ifdef MOZ_OLD_STYLE - , mParser(aLoader) -#endif , mDocURI(aDocURI) , mBaseURI(aBaseURI) , mElement(aElement) @@ -1232,12 +1202,7 @@ MappedAttrParser::ParseMappedAttrValue(nsAtom* aMappedAttrName, { if (!mDecl) { if (mBackend == StyleBackendType::Gecko) { -#ifdef MOZ_OLD_STYLE - mDecl = new css::Declaration(); - mDecl->AsGecko()->InitializeEmpty(); -#else MOZ_CRASH("old style system disabled"); -#endif } else { mDecl = new ServoDeclarationBlock(); } @@ -1250,12 +1215,7 @@ MappedAttrParser::ParseMappedAttrValue(nsAtom* aMappedAttrName, if (propertyID != eCSSProperty_UNKNOWN) { bool changed = false; // outparam for ParseProperty. if (mBackend == StyleBackendType::Gecko) { -#ifdef MOZ_OLD_STYLE - mParser.ParseProperty(propertyID, aMappedAttrValue, mDocURI, mBaseURI, - mElement->NodePrincipal(), mDecl->AsGecko(), &changed, false, true); -#else MOZ_CRASH("old style system disabled"); -#endif } else { NS_ConvertUTF16toUTF8 value(aMappedAttrValue); // FIXME (bug 1343964): Figure out a better solution for sending the base uri to servo @@ -1292,16 +1252,7 @@ MappedAttrParser::ParseMappedAttrValue(nsAtom* aMappedAttrName, if (aMappedAttrName == nsGkAtoms::lang) { propertyID = eCSSProperty__x_lang; if (mBackend == StyleBackendType::Gecko) { -#ifdef MOZ_OLD_STYLE - nsCSSExpandedDataBlock block; - mDecl->AsGecko()->ExpandTo(&block); - nsCSSValue cssValue(PromiseFlatString(aMappedAttrValue), eCSSUnit_Ident); - block.AddLonghandProperty(propertyID, cssValue); - mDecl->AsGecko()->ValueAppended(propertyID); - mDecl->AsGecko()->CompressFrom(&block); -#else MOZ_CRASH("old style system disabled"); -#endif } else { RefPtr atom = NS_Atomize(aMappedAttrValue); Servo_DeclarationBlock_SetIdentStringValue(mDecl->AsServo()->Raw(), propertyID, atom); diff --git a/dom/svg/nsSVGElement.h b/dom/svg/nsSVGElement.h index 4962c76c09e5..61ae69894f27 100644 --- a/dom/svg/nsSVGElement.h +++ b/dom/svg/nsSVGElement.h @@ -112,10 +112,6 @@ public: */ virtual void NodeInfoChanged(nsIDocument* aOldDoc) override; -#ifdef MOZ_OLD_STYLE - NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) override; - void WalkAnimatedContentStyleRules(nsRuleWalker* aRuleWalker); -#endif NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; diff --git a/dom/xbl/nsBindingManager.cpp b/dom/xbl/nsBindingManager.cpp index 75fd37eaa4a9..00bc3983b865 100644 --- a/dom/xbl/nsBindingManager.cpp +++ b/dom/xbl/nsBindingManager.cpp @@ -36,10 +36,6 @@ #include "nsXULPrototypeCache.h" #endif -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRuleProcessor.h" -#include "nsRuleProcessorData.h" -#endif #include "nsIWeakReference.h" #include "nsWrapperCacheInlines.h" @@ -678,48 +674,6 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, return NS_NOINTERFACE; } -#ifdef MOZ_OLD_STYLE -nsresult -nsBindingManager::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, - ElementDependentRuleProcessorData* aData, - bool* aCutOffInheritance) -{ - *aCutOffInheritance = false; - - NS_ASSERTION(aData->mElement, "How did that happen?"); - - // Walk the binding scope chain, starting with the binding attached to our - // content, up till we run out of scopes or we get cut off. - nsIContent *content = aData->mElement; - - do { - nsXBLBinding *binding = content->GetXBLBinding(); - if (binding) { - binding->WalkRules(aFunc, aData); - // If we're not looking at our original content, allow the binding to cut - // off style inheritance - if (content != aData->mElement) { - if (!binding->InheritsStyle()) { - // Go no further; we're not inheriting style from anything above here - break; - } - } - } - - if (content->IsRootOfNativeAnonymousSubtree()) { - break; // Deliberately cut off style inheritance here. - } - - content = content->GetBindingParent(); - } while (content); - - // If "content" is non-null that means we cut off inheritance at some point - // in the loop. - *aCutOffInheritance = (content != nullptr); - - return NS_OK; -} -#endif bool nsBindingManager::EnumerateBoundContentBindings( @@ -750,44 +704,14 @@ nsBindingManager::EnumerateBoundContentBindings( return true; } -#ifdef MOZ_OLD_STYLE -void -nsBindingManager::WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc, - ElementDependentRuleProcessorData* aData) -{ - EnumerateBoundContentBindings([=](nsXBLBinding* aBinding) { - nsIStyleRuleProcessor* ruleProcessor = - aBinding->PrototypeBinding()->GetRuleProcessor(); - if (ruleProcessor) { - (*(aFunc))(ruleProcessor, aData); - } - return true; - }); -} -#endif bool nsBindingManager::MediumFeaturesChanged(nsPresContext* aPresContext, mozilla::MediaFeatureChangeReason aReason) { MOZ_ASSERT(!mDocument->IsStyledByServo()); -#ifdef MOZ_OLD_STYLE - bool rulesChanged = false; - RefPtr presContext = aPresContext; - EnumerateBoundContentBindings([=, &rulesChanged](nsXBLBinding* aBinding) { - nsIStyleRuleProcessor* ruleProcessor = - aBinding->PrototypeBinding()->GetRuleProcessor(); - if (ruleProcessor) { - bool thisChanged = ruleProcessor->MediumFeaturesChanged(presContext); - rulesChanged = rulesChanged || thisChanged; - } - return true; - }); - return rulesChanged; -#else MOZ_CRASH("old style system disabled"); return false; -#endif } void diff --git a/dom/xbl/nsBindingManager.h b/dom/xbl/nsBindingManager.h index 30f785a3cf64..bb076bd609c5 100644 --- a/dom/xbl/nsBindingManager.h +++ b/dom/xbl/nsBindingManager.h @@ -126,15 +126,6 @@ public: nsresult GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, void** aResult); -#ifdef MOZ_OLD_STYLE - // Style rule methods - nsresult WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, - ElementDependentRuleProcessorData* aData, - bool* aCutOffInheritance); - - void WalkAllRules(nsIStyleRuleProcessor::EnumFunc aFunc, - ElementDependentRuleProcessorData* aData); -#endif // Do any processing that needs to happen as a result of a change in the // characteristics of the medium, and return whether this rule processor's diff --git a/dom/xbl/nsXBLBinding.cpp b/dom/xbl/nsXBLBinding.cpp index 94d796666002..4de8a67da4b5 100644 --- a/dom/xbl/nsXBLBinding.cpp +++ b/dom/xbl/nsXBLBinding.cpp @@ -825,18 +825,6 @@ nsXBLBinding::InheritsStyle() const return true; } -#ifdef MOZ_OLD_STYLE -void -nsXBLBinding::WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData) -{ - if (mNextBinding) - mNextBinding->WalkRules(aFunc, aData); - - nsIStyleRuleProcessor *rules = mPrototypeBinding->GetRuleProcessor(); - if (rules) - (*aFunc)(rules, aData); -} -#endif const RawServoAuthorStyles* nsXBLBinding::GetServoStyles() const diff --git a/dom/xbl/nsXBLBinding.h b/dom/xbl/nsXBLBinding.h index bc3441c89715..0d86aab31dcd 100644 --- a/dom/xbl/nsXBLBinding.h +++ b/dom/xbl/nsXBLBinding.h @@ -10,9 +10,6 @@ #include "nsXBLService.h" #include "nsCOMPtr.h" #include "nsINodeList.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRuleProcessor.h" -#endif #include "nsClassHashtable.h" #include "nsTArray.h" #include "nsCycleCollectionParticipant.h" @@ -131,9 +128,6 @@ public: void ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocument); -#ifdef MOZ_OLD_STYLE - void WalkRules(nsIStyleRuleProcessor::EnumFunc aFunc, void* aData); -#endif const RawServoAuthorStyles* GetServoStyles() const; diff --git a/dom/xbl/nsXBLPrototypeBinding.cpp b/dom/xbl/nsXBLPrototypeBinding.cpp index f244596dac3d..d00a9297a8d9 100644 --- a/dom/xbl/nsXBLPrototypeBinding.cpp +++ b/dom/xbl/nsXBLPrototypeBinding.cpp @@ -39,9 +39,6 @@ #include "nsIInterfaceInfo.h" #include "nsIScriptError.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#endif #include "nsXBLResourceLoader.h" #include "mozilla/dom/CDATASection.h" #include "mozilla/dom/Comment.h" @@ -592,17 +589,6 @@ nsXBLPrototypeBinding::SetInitialAttributes( } } -#ifdef MOZ_OLD_STYLE -nsIStyleRuleProcessor* -nsXBLPrototypeBinding::GetRuleProcessor() -{ - if (mResources) { - return mResources->GetRuleProcessor(); - } - - return nullptr; -} -#endif void nsXBLPrototypeBinding::EnsureAttributeTable() diff --git a/dom/xbl/nsXBLPrototypeBinding.h b/dom/xbl/nsXBLPrototypeBinding.h index 3aa4a4cfa345..405b36f341a3 100644 --- a/dom/xbl/nsXBLPrototypeBinding.h +++ b/dom/xbl/nsXBLPrototypeBinding.h @@ -133,9 +133,6 @@ public: bool HasStyleSheets() const; void AppendStyleSheetsTo(nsTArray& aResult) const; -#ifdef MOZ_OLD_STYLE - nsIStyleRuleProcessor* GetRuleProcessor(); -#endif const RawServoAuthorStyles* GetServoStyles() const { diff --git a/dom/xbl/nsXBLPrototypeResources.cpp b/dom/xbl/nsXBLPrototypeResources.cpp index cd3fde4891e8..b205ac25b9be 100644 --- a/dom/xbl/nsXBLPrototypeResources.cpp +++ b/dom/xbl/nsXBLPrototypeResources.cpp @@ -4,9 +4,6 @@ * 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/. */ -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRuleProcessor.h" -#endif #include "nsIDocument.h" #include "nsIContent.h" #include "nsIServiceManager.h" @@ -17,10 +14,6 @@ #include "mozilla/css/Loader.h" #include "nsIURI.h" #include "nsLayoutCID.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#include "nsStyleSet.h" -#endif #include "mozilla/dom/URL.h" #include "mozilla/DebugOnly.h" #include "mozilla/StyleSheet.h" @@ -122,11 +115,7 @@ nsXBLPrototypeResources::FlushSkinSheets() ComputeServoStyles(*shell->StyleSet()->AsServo()); } } else { -#ifdef MOZ_OLD_STYLE - GatherRuleProcessor(); -#else MOZ_CRASH("old style system disabled"); -#endif } return NS_OK; @@ -146,9 +135,6 @@ nsXBLPrototypeResources::Traverse(nsCycleCollectionTraversalCallback &cb) NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "proto mResources mLoader"); cb.NoteXPCOMChild(mLoader); -#ifdef MOZ_OLD_STYLE - CycleCollectionNoteChild(cb, mRuleProcessor.get(), "mRuleProcessor"); -#endif ImplCycleCollectionTraverse(cb, mStyleSheetList, "mStyleSheetList"); } @@ -156,9 +142,6 @@ void nsXBLPrototypeResources::Unlink() { mStyleSheetList.Clear(); -#ifdef MOZ_OLD_STYLE - mRuleProcessor = nullptr; -#endif } void @@ -167,24 +150,6 @@ nsXBLPrototypeResources::ClearLoader() mLoader = nullptr; } -#ifdef MOZ_OLD_STYLE -void -nsXBLPrototypeResources::GatherRuleProcessor() -{ - nsTArray> sheets(mStyleSheetList.Length()); - for (StyleSheet* sheet : mStyleSheetList) { - MOZ_ASSERT(sheet->IsGecko(), - "GatherRuleProcessor must only be called for " - "nsXBLPrototypeResources objects with Gecko-flavored style " - "backends"); - sheets.AppendElement(sheet->AsGecko()); - } - mRuleProcessor = new nsCSSRuleProcessor(Move(sheets), - SheetType::Doc, - nullptr, - mRuleProcessor); -} -#endif void nsXBLPrototypeResources::SyncServoStyles() @@ -254,9 +219,6 @@ nsXBLPrototypeResources::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const for (const auto& sheet : mStyleSheetList) { n += sheet->SizeOfIncludingThis(aMallocSizeOf); } -#ifdef MOZ_OLD_STYLE - n += mRuleProcessor ? mRuleProcessor->SizeOfIncludingThis(aMallocSizeOf) : 0; -#endif n += mServoStyles ? Servo_AuthorStyles_SizeOfIncludingThis( ServoAuthorStylesMallocSizeOf, ServoAuthorStylesMallocEnclosingSizeOf, diff --git a/dom/xbl/nsXBLPrototypeResources.h b/dom/xbl/nsXBLPrototypeResources.h index 2003a8fde549..853d2132a6c0 100644 --- a/dom/xbl/nsXBLPrototypeResources.h +++ b/dom/xbl/nsXBLPrototypeResources.h @@ -67,16 +67,6 @@ public: void AppendStyleSheetsTo(nsTArray& aResult) const; -#ifdef MOZ_OLD_STYLE - /** - * Recreates mRuleProcessor to represent the current list of style sheets - * stored in mStyleSheetList. (Named GatherRuleProcessor to parallel - * nsStyleSet::GatherRuleProcessors.) - */ - void GatherRuleProcessor(); - - nsCSSRuleProcessor* GetRuleProcessor() const { return mRuleProcessor; } -#endif const RawServoAuthorStyles* GetServoStyles() const { @@ -104,10 +94,6 @@ private: // mServoStyles. nsTArray> mStyleSheetList; -#ifdef MOZ_OLD_STYLE - // The list of stylesheets converted to a rule processor. - RefPtr mRuleProcessor; -#endif // The result of cascading the XBL style sheets like mRuleProcessor, but // for the Servo style backend. diff --git a/dom/xbl/nsXBLResourceLoader.cpp b/dom/xbl/nsXBLResourceLoader.cpp index d04da5c2caf4..7cf069ddad42 100644 --- a/dom/xbl/nsXBLResourceLoader.cpp +++ b/dom/xbl/nsXBLResourceLoader.cpp @@ -7,9 +7,6 @@ #include "nsCSSFrameConstructor.h" #include "nsTArray.h" #include "nsString.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRuleProcessor.h" -#endif #include "nsIDocument.h" #include "nsIContent.h" #include "nsIPresShell.h" @@ -28,13 +25,7 @@ #include "nsGkAtoms.h" #include "nsStyleContext.h" #include "nsXBLPrototypeBinding.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#endif #include "nsContentUtils.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsIScriptSecurityManager.h" using namespace mozilla; @@ -192,11 +183,7 @@ nsXBLResourceLoader::StyleSheetLoaded(StyleSheet* aSheet, if (mPendingSheets == 0) { // All stylesheets are loaded. if (aSheet->IsGecko()) { -#ifdef MOZ_OLD_STYLE - mResources->GatherRuleProcessor(); -#else MOZ_CRASH("old style system disabled"); -#endif } else { mResources->ComputeServoStyles( *mBoundDocument->GetShell()->StyleSet()->AsServo()); diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index d7f9abd60bc8..2aac8f326673 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -36,9 +36,6 @@ #include "nsIScriptError.h" #include "nsIScriptSecurityManager.h" #include "nsIServiceManager.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" -#endif #include "nsIURL.h" #include "nsViewManager.h" #include "nsIWidget.h" @@ -52,9 +49,6 @@ #include "nsPIBoxObject.h" #include "XULDocument.h" #include "nsXULPopupListener.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#endif #include "nsCSSParser.h" #include "ListBoxObject.h" #include "nsContentUtils.h" @@ -1443,13 +1437,6 @@ nsXULElement::PreHandleEvent(EventChainVisitor& aVisitor) //---------------------------------------------------------------------- // Implementation methods -#ifdef MOZ_OLD_STYLE -NS_IMETHODIMP -nsXULElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker) -{ - return NS_OK; -} -#endif nsChangeHint nsXULElement::GetAttributeChangeHint(const nsAtom* aAttribute, @@ -2390,13 +2377,7 @@ nsXULPrototypeElement::SetAttrAt(uint32_t aPos, const nsAString& aValue, declaration = ServoDeclarationBlock::FromCssText( aValue, data, eCompatibility_FullStandards, nullptr); } else { -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - declaration = parser.ParseStyleAttribute(aValue, aDocumentURI, - aDocumentURI, principal); -#else MOZ_CRASH("old style system disabled"); -#endif } if (declaration) { mAttributes[aPos].mValue.SetTo(declaration.forget(), &aValue); diff --git a/dom/xul/nsXULElement.h b/dom/xul/nsXULElement.h index 16bf03e52861..a8ffdb87ac9b 100644 --- a/dom/xul/nsXULElement.h +++ b/dom/xul/nsXULElement.h @@ -389,9 +389,6 @@ public: virtual bool IsNodeOfType(uint32_t aFlags) const override; virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse) override; -#ifdef MOZ_OLD_STYLE - NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) override; -#endif virtual nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute, int32_t aModType) const override; NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; diff --git a/editor/libeditor/CSSEditUtils.cpp b/editor/libeditor/CSSEditUtils.cpp index 97f70b44a291..e2781bd17ae1 100644 --- a/editor/libeditor/CSSEditUtils.cpp +++ b/editor/libeditor/CSSEditUtils.cpp @@ -10,9 +10,6 @@ #include "mozilla/HTMLEditor.h" #include "mozilla/Preferences.h" #include "mozilla/DeclarationBlockInlines.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" -#endif #include "mozilla/dom/Element.h" #include "mozilla/mozalloc.h" #include "nsAString.h" diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 90ad5fefec3e..0ed8151609cd 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -3007,11 +3007,7 @@ HTMLEditor::EnableExistingStyleSheet(const nsAString& aURL) NS_ERROR("stylo: ServoStyleSheets can't be disabled yet"); return true; } -#ifdef MOZ_OLD_STYLE - sheet->AsGecko()->SetDisabled(false); -#else MOZ_CRASH("old style system disabled"); -#endif return true; } diff --git a/gfx/layers/AnimationHelper.cpp b/gfx/layers/AnimationHelper.cpp index 5be740565abb..be92580e3491 100644 --- a/gfx/layers/AnimationHelper.cpp +++ b/gfx/layers/AnimationHelper.cpp @@ -132,65 +132,6 @@ CompositorAnimationStorage::SetAnimations(uint64_t aId, const AnimationArray& aV mAnimations.Put(aId, value); } -#ifndef MOZ_STYLO -static StyleAnimationValue -SampleValue(double aPortion, const layers::Animation& aAnimation, - const AnimationPropertySegment&& aSegment, - const StyleAnimationValue& aLastValue, - uint64_t aCurrentIteration, - const StyleAnimationValue& aUnderlyingValue) -{ - NS_ASSERTION(aSegment.mFromValue.mGecko.IsNull() || - aSegment.mToValue.mGecko.IsNull() || - aSegment.mFromValue.mGecko.GetUnit() == - aSegment.mToValue.mGecko.GetUnit(), - "Must have same unit"); - - StyleAnimationValue startValue = - dom::KeyframeEffectReadOnly::CompositeValue(aAnimation.property(), - aSegment.mFromValue.mGecko, - aUnderlyingValue, - aSegment.mFromComposite); - StyleAnimationValue endValue = - dom::KeyframeEffectReadOnly::CompositeValue(aAnimation.property(), - aSegment.mToValue.mGecko, - aUnderlyingValue, - aSegment.mToComposite); - - // Iteration composition for accumulate - if (static_cast - (aAnimation.iterationComposite()) == - dom::IterationCompositeOperation::Accumulate && - aCurrentIteration > 0) { - // FIXME: Bug 1293492: Add a utility function to calculate both of - // below StyleAnimationValues. - startValue = - StyleAnimationValue::Accumulate(aAnimation.property(), - aLastValue.IsNull() - ? aUnderlyingValue - : aLastValue, - Move(startValue), - aCurrentIteration); - endValue = - StyleAnimationValue::Accumulate(aAnimation.property(), - aLastValue.IsNull() - ? aUnderlyingValue - : aLastValue, - Move(endValue), - aCurrentIteration); - } - - StyleAnimationValue interpolatedValue; - // This should never fail because we only pass transform and opacity values - // to the compositor and they should never fail to interpolate. - DebugOnly uncomputeResult = - StyleAnimationValue::Interpolate(aAnimation.property(), - startValue, endValue, - aPortion, interpolatedValue); - MOZ_ASSERT(uncomputeResult, "could not uncompute value"); - return interpolatedValue; -} -#endif bool AnimationHelper::SampleAnimationForEachNode( @@ -278,7 +219,6 @@ AnimationHelper::SampleAnimationForEachNode( static_cast(segment->endComposite()); // interpolate the property -#ifdef MOZ_STYLO dom::IterationCompositeOperation iterCompositeOperation = static_cast( animation.iterationComposite()); @@ -291,17 +231,6 @@ AnimationHelper::SampleAnimationForEachNode( iterCompositeOperation, portion, computedTiming.mCurrentIteration).Consume(); -#elif MOZ_OLD_STYLE - aAnimationValue.mGecko = - SampleValue(portion, - animation, - Move(animSegment), - animData.mEndValues.LastElement().mGecko, - computedTiming.mCurrentIteration, - aAnimationValue.mGecko); -#else - MOZ_CRASH("old style system disabled"); -#endif aHasInEffectAnimations = true; } @@ -480,11 +409,7 @@ CreateCSSValueList(const InfallibleTArray& aFunctions) static AnimationValue ToAnimationValue(const Animatable& aAnimatable) { -#ifdef MOZ_STYLO StyleBackendType backend = StyleBackendType::Servo; -#else - StyleBackendType backend = StyleBackendType::Gecko; -#endif AnimationValue result; switch (aAnimatable.type()) { diff --git a/gfx/layers/apz/util/ActiveElementManager.cpp b/gfx/layers/apz/util/ActiveElementManager.cpp index 03373ff2a520..48cbd9786226 100644 --- a/gfx/layers/apz/util/ActiveElementManager.cpp +++ b/gfx/layers/apz/util/ActiveElementManager.cpp @@ -14,9 +14,6 @@ #include "base/task.h" #include "mozilla/dom/Element.h" #include "nsIDocument.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #define AEM_LOG(...) // #define AEM_LOG(...) printf_stderr("AEM: " __VA_ARGS__) diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 72a9bf3f1205..fb9dce531b6e 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -183,9 +183,6 @@ #include "nsLayoutStylesheetCache.h" #include "mozilla/layers/InputAPZContext.h" #include "mozilla/layers/FocusTarget.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandleInlines.h" #include "mozilla/StyleSheet.h" @@ -612,12 +609,7 @@ VerifyStyleTree(nsPresContext* aPresContext, nsFrameManager* aFrameManager) NS_ERROR("stylo: cannot verify style tree with a ServoRestyleManager"); return; } -#ifdef MOZ_OLD_STYLE - nsIFrame* rootFrame = aFrameManager->GetRootFrame(); - aPresContext->RestyleManager()->AsGecko()->DebugVerifyStyleTree(rootFrame); -#else MOZ_CRASH("old style system disabled"); -#endif } } #define VERIFY_STYLE_TREE ::VerifyStyleTree(mPresContext, mFrameConstructor) @@ -4398,21 +4390,7 @@ PresShell::DocumentStatesChanged(nsIDocument* aDocument, EventStates aStateMask) if (mStyleSet->IsServo()) { mStyleSet->AsServo()->InvalidateStyleForDocumentStateChanges(aStateMask); } else { -#ifdef MOZ_OLD_STYLE - if (Element* rootElement = aDocument->GetRootElement()) { - const bool needRestyle = - mStyleSet->AsGecko()->HasDocumentStateDependentStyle( - rootElement, aStateMask); - if (needRestyle) { - mPresContext->RestyleManager()->PostRestyleEvent(rootElement, - eRestyle_Subtree, - nsChangeHint(0)); - VERIFY_STYLE_TREE; - } - } -#else MOZ_CRASH("old style system disabled"); -#endif } } @@ -9621,15 +9599,6 @@ CopySheetsIntoClone(StyleSetHandle aSet, StyleSetHandle aClone) } } -#ifdef MOZ_OLD_STYLE -nsStyleSet* -PresShell::CloneStyleSet(nsStyleSet* aSet) -{ - nsStyleSet* clone = new nsStyleSet(); - CopySheetsIntoClone(aSet, clone); - return clone; -} -#endif ServoStyleSet* PresShell::CloneStyleSet(ServoStyleSet* aSet) @@ -9689,27 +9658,16 @@ PresShell::VerifyIncrementalReflow() // Create a new presentation shell to view the document. Use the // exact same style information that this document has. -#ifdef MOZ_OLD_STYLE - nsAutoPtr newGeckoSet; -#endif nsAutoPtr newServoSet; StyleSetHandle newSet; if (mStyleSet->IsServo()) { newServoSet = CloneStyleSet(mStyleSet->AsServo()); newSet = newServoSet; } else { -#ifdef MOZ_OLD_STYLE - newGeckoSet = CloneStyleSet(mStyleSet->AsGecko()); - newSet = newGeckoSet; -#else MOZ_CRASH("old style system disabled"); -#endif } nsCOMPtr sh = mDocument->CreateShell(cx, vm, newSet); NS_ENSURE_TRUE(sh, false); -#ifdef MOZ_OLD_STYLE - newGeckoSet.forget(); -#endif newServoSet.forget(); // Note that after we create the shell, we must make sure to destroy it sh->SetVerifyReflowEnable(false); // turn off verify reflow while we're reflowing the test frame tree @@ -10439,11 +10397,7 @@ PresShell::AddSizeOfIncludingThis(nsWindowSizes& aSizes) const mFramesToDirty.ShallowSizeOfExcludingThis(mallocSizeOf); if (StyleSet()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - StyleSet()->AsGecko()->AddSizeOfIncludingThis(aSizes); -#else MOZ_CRASH("old style system disabled"); -#endif } else { StyleSet()->AsServo()->AddSizeOfIncludingThis(aSizes); } @@ -10644,14 +10598,7 @@ nsIPresShell::HasRuleProcessorUsedByMultipleStyleSets(uint32_t aSheetType, { *aRetVal = false; if (mStyleSet->IsGecko()) { -#ifdef MOZ_OLD_STYLE - nsStyleSet* styleSet = mStyleSet->AsGecko(); - // ServoStyleSets do not have rule processors. - SheetType type = ToSheetType(aSheetType); - *aRetVal = styleSet->HasRuleProcessorUsedByMultipleStyleSets(type); -#else MOZ_CRASH("old style system disabled"); -#endif } return NS_OK; } diff --git a/layout/base/PresShell.h b/layout/base/PresShell.h index 8b0798d437e3..df7e9690681b 100644 --- a/layout/base/PresShell.h +++ b/layout/base/PresShell.h @@ -508,9 +508,6 @@ private: bool mCaretEnabled; #ifdef DEBUG -#ifdef MOZ_OLD_STYLE - nsStyleSet* CloneStyleSet(nsStyleSet* aSet); -#endif ServoStyleSet* CloneStyleSet(ServoStyleSet* aSet); bool VerifyIncrementalReflow(); bool mInVerifyReflow; diff --git a/layout/base/RestyleLogging.h b/layout/base/RestyleLogging.h index b7f3624178ba..fffa963a683b 100644 --- a/layout/base/RestyleLogging.h +++ b/layout/base/RestyleLogging.h @@ -14,9 +14,6 @@ #include "mozilla/AutoRestore.h" #ifdef DEBUG -#ifdef MOZ_OLD_STYLE -#define RESTYLE_LOGGING -#endif #endif #ifdef RESTYLE_LOGGING diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index 556bc245b268..f83dfcb0c5fd 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -625,154 +625,6 @@ static bool gInApplyRenderingChangeToTree = false; #endif #ifdef DEBUG -#ifdef MOZ_OLD_STYLE -static void -DumpContext(nsIFrame* aFrame, nsStyleContext* aContext) -{ - if (aFrame) { - fputs("frame: ", stdout); - nsAutoString name; - aFrame->GetFrameName(name); - fputs(NS_LossyConvertUTF16toASCII(name).get(), stdout); - fprintf(stdout, " (%p)", static_cast(aFrame)); - } - if (aContext) { - fprintf(stdout, " style: %p ", static_cast(aContext)); - - nsAtom* pseudoTag = aContext->GetPseudo(); - if (pseudoTag) { - nsAutoString buffer; - pseudoTag->ToString(buffer); - fputs(NS_LossyConvertUTF16toASCII(buffer).get(), stdout); - fputs(" ", stdout); - } - fputs("{}\n", stdout); - } -} - -static void -VerifySameTree(GeckoStyleContext* aContext1, GeckoStyleContext* aContext2) -{ - GeckoStyleContext* top1 = aContext1; - GeckoStyleContext* top2 = aContext2; - GeckoStyleContext* parent; - for (;;) { - parent = top1->GetParent(); - if (!parent) - break; - top1 = parent; - } - for (;;) { - parent = top2->GetParent(); - if (!parent) - break; - top2 = parent; - } - NS_ASSERTION(top1 == top2, - "Style contexts are not in the same style context tree"); -} - -static void -VerifyContextParent(nsIFrame* aFrame, GeckoStyleContext* aContext, - GeckoStyleContext* aParentContext) -{ - // get the contexts not provided - if (!aContext) { - aContext = aFrame->StyleContext()->AsGecko(); - } - - if (!aParentContext) { - nsIFrame* providerFrame; - nsStyleContext* parent = aFrame->GetParentStyleContext(&providerFrame); - aParentContext = parent ? parent->AsGecko() : nullptr; - // aParentContext could still be null - } - - NS_ASSERTION(aContext, "Failure to get required contexts"); - GeckoStyleContext* actualParentContext = aContext->GetParent(); - - if (aParentContext) { - if (aParentContext != actualParentContext) { - DumpContext(aFrame, aContext); - if (aContext == aParentContext) { - NS_ERROR("Using parent's style context"); - } else { - NS_ERROR("Wrong parent style context"); - fputs("Wrong parent style context: ", stdout); - DumpContext(nullptr, actualParentContext); - fputs("should be using: ", stdout); - DumpContext(nullptr, aParentContext); - VerifySameTree(actualParentContext, aParentContext); - fputs("\n", stdout); - } - } - - } else { - if (actualParentContext) { - NS_ERROR("Have parent context and shouldn't"); - DumpContext(aFrame, aContext); - fputs("Has parent context: ", stdout); - DumpContext(nullptr, actualParentContext); - fputs("Should be null\n\n", stdout); - } - } - - GeckoStyleContext* childStyleIfVisited = aContext->GetStyleIfVisited(); - // Either childStyleIfVisited has aContext->GetParent()->GetStyleIfVisited() - // as the parent or it has a different rulenode from aContext _and_ has - // aContext->GetParent() as the parent. - if (childStyleIfVisited && - !((childStyleIfVisited->RuleNode() != aContext->RuleNode() && - childStyleIfVisited->GetParent() == aContext->GetParent()) || - childStyleIfVisited->GetParent() == - aContext->GetParent()->GetStyleIfVisited())) { - NS_ERROR("Visited style has wrong parent"); - DumpContext(aFrame, aContext); - fputs("\n", stdout); - } -} - -static void -VerifyStyleTree(nsIFrame* aFrame) -{ - GeckoStyleContext* context = aFrame->StyleContext()->AsGecko(); - VerifyContextParent(aFrame, context, nullptr); - - nsIFrame::ChildListIterator lists(aFrame); - for (; !lists.IsDone(); lists.Next()) { - for (nsIFrame* child : lists.CurrentList()) { - if (!(child->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) { - // only do frames that are in flow - if (child->IsPlaceholderFrame()) { - // placeholder: first recurse and verify the out of flow frame, - // then verify the placeholder's context - nsIFrame* outOfFlowFrame = - nsPlaceholderFrame::GetRealFrameForPlaceholder(child); - - // recurse to out of flow frame, letting the parent context get resolved - do { - VerifyStyleTree(outOfFlowFrame); - } while ((outOfFlowFrame = outOfFlowFrame->GetNextContinuation())); - - // verify placeholder using the parent frame's context as - // parent context - VerifyContextParent(child, nullptr, nullptr); - } else { // regular frame - VerifyStyleTree(child); - } - } - } - } - - // do additional contexts - int32_t contextIndex = 0; - for (nsStyleContext* extraContext; - (extraContext = aFrame->GetAdditionalStyleContext(contextIndex)); - ++contextIndex) { - VerifyContextParent(aFrame, extraContext->AsGecko(), context); - } -} -#endif void RestyleManager::DebugVerifyStyleTree(nsIFrame* aFrame) @@ -783,13 +635,7 @@ RestyleManager::DebugVerifyStyleTree(nsIFrame* aFrame) // we work out what we want to assert (bug 1322570). return; } -#ifdef MOZ_OLD_STYLE - if (aFrame) { - VerifyStyleTree(aFrame); - } -#else MOZ_CRASH("old style system disabled"); -#endif } #endif // DEBUG @@ -1905,13 +1751,7 @@ RestyleManager::IncrementAnimationGeneration() // ProcessPendingRestyles so we should ignore any subsequent (redundant) // calls that occur while we are still processing restyles. if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - if (AsGecko()->IsProcessingRestyles()) { - return; - } -#else MOZ_CRASH("old style system disabled"); -#endif } else { if (mInStyleRefresh) { return; diff --git a/layout/base/RestyleManagerInlines.h b/layout/base/RestyleManagerInlines.h index b0d5f0c40f7f..da1c74320def 100644 --- a/layout/base/RestyleManagerInlines.h +++ b/layout/base/RestyleManagerInlines.h @@ -7,9 +7,6 @@ #ifndef mozilla_RestyleManagerInlines_h #define mozilla_RestyleManagerInlines_h -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoRestyleManager.h" -#endif #include "mozilla/ServoRestyleManager.h" #include "mozilla/ServoUtils.h" diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 97eee4816f87..7508c2a4c13b 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -335,35 +335,6 @@ static int32_t FFWC_recursions=0; static int32_t FFWC_nextInFlows=0; #endif -#ifdef MOZ_OLD_STYLE - -// Wrapper class to handle stack-construction a TreeMatchContext only if we're -// using the Gecko style system. -class MOZ_STACK_CLASS TreeMatchContextHolder -{ -public: - explicit TreeMatchContextHolder(nsIDocument* aDocument) - { - if (!aDocument->IsStyledByServo()) { - mMaybeTreeMatchContext.emplace(aDocument, - TreeMatchContext::ForFrameConstruction); - } - } - - bool Exists() const { return mMaybeTreeMatchContext.isSome(); } - operator TreeMatchContext*() { return mMaybeTreeMatchContext.ptrOr(nullptr); } - - TreeMatchContext* operator ->() - { - MOZ_ASSERT(mMaybeTreeMatchContext.isSome()); - return mMaybeTreeMatchContext.ptr(); - } - -private: - Maybe mMaybeTreeMatchContext; -}; - -#else // Define this dummy class so there are fewer call sites to change when the old // style system code is compiled out. @@ -376,7 +347,6 @@ public: TreeMatchContext* operator->() { MOZ_CRASH("old style system disabled"); } }; -#endif // Returns true if aFrame is an anonymous flex/grid item. static inline bool @@ -896,11 +866,7 @@ public: bool HasAncestorFilter() { -#ifdef MOZ_OLD_STYLE - return mTreeMatchContext && mTreeMatchContext->mAncestorFilter.HasFilter(); -#else return false; -#endif } // Function to push the existing absolute containing block state and @@ -1048,7 +1014,6 @@ protected: PendingBinding* mCurrentPendingBindingInsertionPoint; }; -#ifndef MOZ_OLD_STYLE namespace mozilla { @@ -1063,7 +1028,6 @@ public: } // namespace mozilla -#endif nsFrameConstructorState::nsFrameConstructorState( nsIPresShell* aPresShell, @@ -1982,29 +1946,7 @@ nsCSSFrameConstructor::CreateGeneratedContentItem(nsFrameConstructorState& aStat styleSet->AsServo()->ResolveServoStyle(container); } } else { -#ifdef MOZ_OLD_STYLE - mozilla::GeckoRestyleManager* geckoRM = RestyleManager()->AsGecko(); - GeckoRestyleManager::ReframingStyleContexts* rsc = - geckoRM->GetReframingStyleContexts(); - - if (rsc) { - RefPtr newContext = - GeckoStyleContext::TakeRef(pseudoStyleContext.forget()); - if (auto* oldStyleContext = rsc->Get(container, aPseudoElement)) { - GeckoRestyleManager::TryInitiatingTransition(aState.mPresContext, - container, - oldStyleContext, - &newContext); - } else { - aState.mPresContext->TransitionManager()-> - PruneCompletedTransitions(aParentContent->AsElement(), - aPseudoElement, newContext); - } - pseudoStyleContext = newContext.forget(); - } -#else MOZ_CRASH("old style system disabled"); -#endif } uint32_t contentCount = pseudoStyleContext->StyleContent()->ContentCount(); @@ -5289,29 +5231,7 @@ nsCSSFrameConstructor::ResolveStyleContext(nsStyleContext* aParentStyleContext, // it probably won't need to track reframed style contexts to start // transitions correctly. if (RestyleManager()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - mozilla::GeckoRestyleManager* geckoRM = RestyleManager()->AsGecko(); - GeckoRestyleManager::ReframingStyleContexts* rsc = - geckoRM->GetReframingStyleContexts(); - if (rsc) { - GeckoStyleContext* oldStyleContext = - rsc->Get(aContent, CSSPseudoElementType::NotPseudo); - nsPresContext* presContext = mPresShell->GetPresContext(); - if (oldStyleContext) { - RefPtr newContext = - GeckoStyleContext::TakeRef(result.forget()); - GeckoRestyleManager::TryInitiatingTransition(presContext, aContent, - oldStyleContext, &newContext); - result = newContext.forget(); - } else if (aContent->IsElement()) { - presContext->TransitionManager()-> - PruneCompletedTransitions(aContent->AsElement(), - CSSPseudoElementType::NotPseudo, result->AsGecko()); - } - } -#else MOZ_CRASH("old style system disabled"); -#endif } return result.forget(); @@ -5994,13 +5914,7 @@ nsCSSFrameConstructor::AddFrameConstructionItemsInternal(nsFrameConstructorState styleContext = mPresShell->StyleSet()->AsServo()->ResolveServoStyle(aContent->AsElement()); } else { -#ifdef MOZ_OLD_STYLE - styleContext = - ResolveStyleContext(styleContext->AsGecko()->GetParent(), - aContent, &aState); -#else MOZ_CRASH("old style system disabled"); -#endif } } @@ -7287,16 +7201,7 @@ nsCSSFrameConstructor::MaybeConstructLazily(Operation aOperation, CheckBitsForLazyFrameConstruction(parent); if (RestyleManager()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - mozilla::GeckoRestyleManager* geckoRM = RestyleManager()->AsGecko(); - while (parent && !parent->HasFlag(NODE_DESCENDANTS_NEED_FRAMES)) { - parent->SetFlags(NODE_DESCENDANTS_NEED_FRAMES); - parent = parent->GetFlattenedTreeParent(); - } - geckoRM->PostRestyleEventForLazyConstruction(); -#else MOZ_CRASH("old style system disabled"); -#endif } else { parent->AsElement()->NoteDescendantsNeedFramesForServo(); } @@ -7304,103 +7209,6 @@ nsCSSFrameConstructor::MaybeConstructLazily(Operation aOperation, return true; } -#ifdef MOZ_OLD_STYLE -void -nsCSSFrameConstructor::CreateNeededFrames( - nsIContent* aContent, - TreeMatchContext& aTreeMatchContext) -{ - MOZ_ASSERT(!aContent->IsStyledByServo()); - NS_ASSERTION(!aContent->HasFlag(NODE_NEEDS_FRAME), - "shouldn't get here with a content node that has needs frame bit set"); - NS_ASSERTION(aContent->HasFlag(NODE_DESCENDANTS_NEED_FRAMES), - "should only get here with a content node that has descendants needing frames"); - MOZ_ASSERT(aTreeMatchContext.mAncestorFilter.HasFilter(), - "The whole point of having the tree match context is optimizing " - "the ancestor filter usage!"); - - aContent->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES); - - // We could either descend first (on nodes that don't have NODE_NEEDS_FRAME - // set) or issue content notifications for our kids first. In absence of - // anything definitive either way we'll go with the latter. - - // It might be better to use GetChildArray and scan it completely first and - // then issue all notifications. (We have to scan it completely first because - // constructing frames can set attributes, which can change the storage of - // child lists). - - // Scan the children of aContent to see what operations (if any) we need to - // perform. - bool inRun = false; - nsIContent* firstChildInRun = nullptr; - for (nsIContent* child = aContent->GetFirstChild(); - child; child = child->GetNextSibling()) { - if (child->HasFlag(NODE_NEEDS_FRAME)) { - NS_ASSERTION(!child->GetPrimaryFrame() || - child->GetPrimaryFrame()->GetContent() != child, - //XXX the child->GetPrimaryFrame()->GetContent() != child - // check is needed due to bug 135040. Remove it once that's - // fixed. - "NEEDS_FRAME set on a node that already has a frame?"); - if (!inRun) { - inRun = true; - firstChildInRun = child; - } - } else { - if (inRun) { - inRun = false; - // generate a ContentRangeInserted for [startOfRun,i) - ContentRangeInserted(aContent, firstChildInRun, child, nullptr, - InsertionKind::Sync, - &aTreeMatchContext); - } - } - } - - if (inRun) { - ContentAppended(aContent, firstChildInRun, - InsertionKind::Sync, - &aTreeMatchContext); - } - - // Now descend. - FlattenedChildIterator iter(aContent); - for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) { - if (child->HasFlag(NODE_DESCENDANTS_NEED_FRAMES)) { - TreeMatchContext::AutoAncestorPusher insertionPointPusher( - &aTreeMatchContext); - - // Handle stuff like xbl:children. - if (child->GetParent() != aContent && child->GetParent()->IsElement()) { - insertionPointPusher.PushAncestor(child->GetParent()->AsElement()); - } - - TreeMatchContext::AutoAncestorPusher pusher(&aTreeMatchContext); - pusher.PushAncestor(child); - - CreateNeededFrames(child, aTreeMatchContext); - } - } -} - -void -nsCSSFrameConstructor::CreateNeededFrames() -{ - NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(), - "Someone forgot a script blocker"); - - Element* rootElement = mDocument->GetRootElement(); - NS_ASSERTION(!rootElement || !rootElement->HasFlag(NODE_NEEDS_FRAME), - "root element should not have frame created lazily"); - if (rootElement && rootElement->HasFlag(NODE_DESCENDANTS_NEED_FRAMES)) { - TreeMatchContext treeMatchContext( - mDocument, TreeMatchContext::ForFrameConstruction); - treeMatchContext.InitAncestors(rootElement); - CreateNeededFrames(rootElement, treeMatchContext); - } -} -#endif void nsCSSFrameConstructor::IssueSingleInsertNofications(nsIContent* aContainer, @@ -9392,59 +9200,6 @@ nsCSSFrameConstructor::CaptureStateForFramesOf(nsIContent* aContent, } } -#ifdef MOZ_OLD_STYLE -static bool -DefinitelyEqualURIsAndPrincipal(mozilla::css::URLValue* aURI1, - mozilla::css::URLValue* aURI2) -{ - return aURI1 == aURI2 || - (aURI1 && aURI2 && aURI1->DefinitelyEqualURIsAndPrincipal(*aURI2)); -} - -nsStyleContext* -nsCSSFrameConstructor::MaybeRecreateFramesForElement(Element* aElement) -{ - RefPtr oldContext = GetDisplayNoneStyleFor(aElement); - StyleDisplay oldDisplay = StyleDisplay::None; - if (!oldContext) { - oldContext = GetDisplayContentsStyleFor(aElement); - if (!oldContext) { - return nullptr; - } - oldDisplay = StyleDisplay::Contents; - } - - // The parent has a frame, so try resolving a new context. - RefPtr newContext = mPresShell->StyleSet()-> - ResolveStyleFor(aElement, oldContext->AsGecko()->GetParent(), - LazyComputeBehavior::Assert); - - if (oldDisplay == StyleDisplay::None) { - ChangeRegisteredDisplayNoneStyleFor(aElement, newContext); - } else { - ChangeRegisteredDisplayContentsStyleFor(aElement, newContext); - } - - const nsStyleDisplay* disp = newContext->StyleDisplay(); - if (oldDisplay == disp->mDisplay) { - // We can skip trying to recreate frames here, but only if our style - // context does not have a binding URI that differs from our old one. - // Otherwise, we should try to recreate, because we may want to apply the - // new binding - if (!disp->mBinding) { - return newContext; - } - const nsStyleDisplay* oldDisp = oldContext->PeekStyleDisplay(); - if (oldDisp && - DefinitelyEqualURIsAndPrincipal(disp->mBinding, oldDisp->mBinding)) { - return newContext; - } - } - - RecreateFramesForContent(aElement, InsertionKind::Sync); - return nullptr; -} -#endif static bool IsWhitespaceFrame(nsIFrame* aFrame) diff --git a/layout/base/nsCSSFrameConstructor.h b/layout/base/nsCSSFrameConstructor.h index 4024b698a01f..579eb9bd4e57 100644 --- a/layout/base/nsCSSFrameConstructor.h +++ b/layout/base/nsCSSFrameConstructor.h @@ -100,20 +100,9 @@ public: void ReconstructDocElementHierarchy(InsertionKind); -#ifdef MOZ_OLD_STYLE - // Create frames for content nodes that are marked as needing frames. This - // should be called before ProcessPendingRestyles. - // Note: It's the caller's responsibility to make sure to wrap a - // CreateNeededFrames call in a view update batch and a script blocker. - void CreateNeededFrames(); -#endif private: -#ifdef MOZ_OLD_STYLE - void CreateNeededFrames(nsIContent* aContent, - TreeMatchContext& aTreeMatchContext); -#endif enum Operation { CONTENTAPPEND, @@ -1865,16 +1854,6 @@ private: PendingBinding* aPendingBinding, nsFrameItems& aFrameItems); -#ifdef MOZ_OLD_STYLE - /** - * ReResolve style for aElement then recreate frames if required. - * Do nothing for other types of style changes, except for undisplayed nodes - * (display:none/contents) which will have their style context updated in the - * frame manager undisplayed maps. - * @return null if frames were recreated, the new style context otherwise - */ - nsStyleContext* MaybeRecreateFramesForElement(Element* aElement); -#endif /** * Recreate frames for aContent. diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 491baef7dd32..fc548b9490b7 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -2321,11 +2321,7 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument) StyleSetHandle styleSet; if (backendType == StyleBackendType::Gecko) { -#ifdef MOZ_OLD_STYLE - styleSet = new nsStyleSet(); -#else MOZ_CRASH("old style system disabled"); -#endif } else { styleSet = new ServoStyleSet(); } diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index e60194ea1414..c6c7afde2bcc 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -196,9 +196,7 @@ typedef nsStyleTransformMatrix::TransformReferenceBox TransformReferenceBox; /* static */ bool nsLayoutUtils::sInterruptibleReflowEnabled; /* static */ bool nsLayoutUtils::sSVGTransformBoxEnabled; /* static */ bool nsLayoutUtils::sTextCombineUprightDigitsEnabled; -#ifdef MOZ_STYLO /* static */ bool nsLayoutUtils::sStyloEnabled; -#endif /* static */ uint32_t nsLayoutUtils::sIdlePeriodDeadlineLimit; /* static */ uint32_t nsLayoutUtils::sQuiescentFramesBeforeIdlePeriod; @@ -8282,20 +8280,7 @@ nsLayoutUtils::Initialize() "svg.transform-box.enabled"); Preferences::AddBoolVarCache(&sTextCombineUprightDigitsEnabled, "layout.css.text-combine-upright-digits.enabled"); -#ifdef MOZ_STYLO -#ifdef MOZ_OLD_STYLE - if (PR_GetEnv("STYLO_FORCE_ENABLED")) { - sStyloEnabled = true; - } else if (PR_GetEnv("STYLO_FORCE_DISABLED")) { - sStyloEnabled = false; - } else { - Preferences::AddBoolVarCache(&sStyloEnabled, - "layout.css.servo.enabled"); - } -#else sStyloEnabled = true; -#endif -#endif Preferences::AddUintVarCache(&sIdlePeriodDeadlineLimit, "layout.idle_period.time_limit", @@ -8328,21 +8313,10 @@ nsLayoutUtils::Shutdown() nsStyleList::Shutdown(); } -#ifdef MOZ_STYLO /* static */ bool nsLayoutUtils::ShouldUseStylo(nsIPrincipal* aPrincipal) { -#ifdef MOZ_OLD_STYLE - // Disable stylo for system principal because XUL hasn't been fully - // supported. Other principal aren't able to use XUL by default, and - // the back door to enable XUL is mostly just for testing, which means - // they don't matter, and we shouldn't respect them at the same time. - if (!StyloChromeEnabled() && - nsContentUtils::IsSystemPrincipal(aPrincipal)) { - return false; - } -#endif return true; } @@ -8350,21 +8324,8 @@ nsLayoutUtils::ShouldUseStylo(nsIPrincipal* aPrincipal) bool nsLayoutUtils::StyloChromeEnabled() { -#ifdef MOZ_OLD_STYLE - static bool sInitialized = false; - static bool sEnabled = false; - if (!sInitialized) { - // We intentionally don't allow dynamic toggling of this pref - // because it is rather risky to mix style backend in XUL. - sEnabled = Preferences::GetBool("layout.css.servo.chrome.enabled"); - sInitialized = true; - } - return sEnabled; -#else return true; -#endif } -#endif /* static */ void diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 9183260465cd..56cf1ff329e2 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -24,9 +24,6 @@ #include "nsStyleCoord.h" #include "nsStyleConsts.h" #include "nsGkAtoms.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" -#endif #include "imgIContainer.h" #include "mozilla/gfx/2D.h" #include "Units.h" @@ -2528,18 +2525,11 @@ public: // or disabled at compile-time. However, we provide the additional capability // to disable it dynamically in stylo-enabled builds via a pref. static bool StyloEnabled() { -#if defined(MOZ_STYLO) && defined(MOZ_OLD_STYLE) - return sStyloEnabled && StyloSupportedInCurrentProcess(); -#elif defined(MOZ_STYLO) return true; -#else - return false; -#endif } // Whether Stylo should be allowed to be enabled in this process. static bool StyloSupportedInCurrentProcess() { -#ifdef MOZ_STYLO if (XRE_IsContentProcess()) { return true; } @@ -2552,17 +2542,14 @@ public: // Otherwise we only use stylo on non-e10s parent. return !XRE_IsE10sParentProcess(); } -#endif // Stylo is not enabled for any other process. MOZ_DIAGNOSTIC_ASSERT(false, "We should not be creating any document " "in processes other than content and parent"); return false; } -#ifdef MOZ_STYLO // Whether Stylo should be used on chrome documents. static bool StyloChromeEnabled(); -#endif static uint32_t IdlePeriodDeadlineLimit() { return sIdlePeriodDeadlineLimit; @@ -2592,16 +2579,10 @@ public: static void Initialize(); static void Shutdown(); -#ifdef MOZ_STYLO /** * Return whether stylo should be used for a given document principal. */ static bool ShouldUseStylo(nsIPrincipal* aPrincipal); -#else - static bool ShouldUseStylo(nsIPrincipal* aPrincipal) { - return false; - } -#endif /** * Register an imgIRequest object with a refresh driver. @@ -3120,9 +3101,7 @@ private: static bool sInterruptibleReflowEnabled; static bool sSVGTransformBoxEnabled; static bool sTextCombineUprightDigitsEnabled; -#ifdef MOZ_STYLO static bool sStyloEnabled; -#endif static uint32_t sIdlePeriodDeadlineLimit; static uint32_t sQuiescentFramesBeforeIdlePeriod; diff --git a/layout/base/nsPresArena.cpp b/layout/base/nsPresArena.cpp index bf8649c51c4e..aa9431264916 100644 --- a/layout/base/nsPresArena.cpp +++ b/layout/base/nsPresArena.cpp @@ -12,9 +12,6 @@ #include "mozilla/Poison.h" #include "nsDebug.h" #include "nsPrintfCString.h" -#ifdef MOZ_OLD_STYLE -#include "GeckoStyleContext.h" -#endif #include "FrameLayerBuilder.h" #include "mozilla/ArrayUtils.h" #include "nsStyleContext.h" diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 0247d60409a1..b08bc309d9a1 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -38,20 +38,11 @@ #include "nsThreadUtils.h" #include "nsLayoutUtils.h" #include "nsViewManager.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoRestyleManager.h" -#endif #include "mozilla/RestyleManager.h" #include "mozilla/RestyleManagerInlines.h" #include "SurfaceCacheUtils.h" #include "nsMediaFeatures.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" -#endif #include "gfxPlatform.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRules.h" -#endif #include "nsFontFaceLoader.h" #include "mozilla/AnimationEventDispatcher.h" #include "mozilla/EffectCompositor.h" @@ -126,35 +117,6 @@ public: nsPresContext* mPresContext; }; -#ifdef MOZ_OLD_STYLE - -namespace { - -class CharSetChangingRunnable : public Runnable -{ -public: - CharSetChangingRunnable(nsPresContext* aPresContext, - NotNull aCharSet) - : Runnable("CharSetChangingRunnable"), - mPresContext(aPresContext), - mCharSet(aCharSet) - { - } - - NS_IMETHOD Run() override - { - mPresContext->DoChangeCharSet(mCharSet); - return NS_OK; - } - -private: - RefPtr mPresContext; - NotNull mCharSet; -}; - -} // namespace - -#endif nscolor nsPresContext::MakeColorPref(const nsString& aColor) @@ -167,24 +129,13 @@ nsPresContext::MakeColorPref(const nsString& aColor) : nullptr; bool useServoParser = -#ifdef MOZ_OLD_STYLE - servoStyleSet; -#else true; -#endif if (useServoParser) { ok = ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0), aColor, &result); } else { -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - nsCSSValue value; - ok = parser.ParseColorString(aColor, nullptr, 0, value) && - nsRuleNode::ComputeColor(value, this, nullptr, result); -#else MOZ_CRASH("old style system disabled"); -#endif } if (!ok) { @@ -1030,11 +981,7 @@ nsPresContext::AttachShell(nsIPresShell* aShell, StyleBackendType aBackendType) if (aBackendType == StyleBackendType::Servo) { mRestyleManager = new ServoRestyleManager(this); } else { -#ifdef MOZ_OLD_STYLE - mRestyleManager = new GeckoRestyleManager(this); -#else MOZ_CRASH("old style system disabled"); -#endif } // Since CounterStyleManager is also the name of a method of @@ -1169,14 +1116,6 @@ nsPresContext::UpdateCharSet(NotNull aCharSet) void nsPresContext::DispatchCharSetChange(NotNull aEncoding) { -#ifdef MOZ_OLD_STYLE - if (!Document()->IsStyledByServo()) { - RefPtr runnable = - new CharSetChangingRunnable(this, aEncoding); - Document()->Dispatch(TaskCategory::Other, runnable.forget()); - return; - } -#endif // In Servo RebuildAllStyleData is async, so no need to do the runnable dance. DoChangeCharSet(aEncoding); } @@ -2076,11 +2015,7 @@ nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint, mUsesRootEMUnits = false; mUsesExChUnits = false; if (mShell->StyleSet()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - mShell->StyleSet()->AsGecko()->SetUsesViewportUnits(false); -#else MOZ_CRASH("old style system disabled"); -#endif } // TODO(emilio): It's unclear to me why would these three calls below be @@ -2276,15 +2211,7 @@ nsPresContext::HasAuthorSpecifiedRules(const nsIFrame* aFrame, uint32_t aRuleTypeMask) const { if (aFrame->StyleContext()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - auto* geckoStyleContext = aFrame->StyleContext()->AsGecko(); - return - nsRuleNode::HasAuthorSpecifiedRules(geckoStyleContext, - aRuleTypeMask, - UseDocumentColors()); -#else MOZ_CRASH("old style system disabled"); -#endif } Element* elem = aFrame->GetContent()->AsElement(); diff --git a/layout/base/nsRefreshDriver.cpp b/layout/base/nsRefreshDriver.cpp index dbb984a45660..8c1e03371c86 100644 --- a/layout/base/nsRefreshDriver.cpp +++ b/layout/base/nsRefreshDriver.cpp @@ -50,9 +50,6 @@ #include "mozilla/dom/Performance.h" #include "mozilla/dom/Selection.h" #include "mozilla/dom/WindowBinding.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoRestyleManager.h" -#endif #include "mozilla/RestyleManager.h" #include "mozilla/RestyleManagerInlines.h" #include "Layers.h" diff --git a/layout/base/nsStyleSheetService.cpp b/layout/base/nsStyleSheetService.cpp index 3a3cfaa61c1d..826a797753ef 100644 --- a/layout/base/nsStyleSheetService.cpp +++ b/layout/base/nsStyleSheetService.cpp @@ -7,9 +7,6 @@ /* implementation of interface for managing user and user-agent style sheets */ #include "nsStyleSheetService.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/CSSStyleSheet.h" -#endif #include "mozilla/MemoryReporting.h" #include "mozilla/PreloadedStyleSheet.h" #include "mozilla/StyleSheet.h" @@ -177,9 +174,7 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI, // that a Servo sheet was also loaded. In both cases, the new sheets are // the last sheets in m{Gecko,Servo}Sheets[aSheetType] bool servoSheetWasAdded = false; -#ifdef MOZ_STYLO servoSheetWasAdded = nsLayoutUtils::StyloSupportedInCurrentProcess(); -#endif // Hold on to a copy of the registered PresShells. nsTArray> toNotify(mPresShells); @@ -250,17 +245,7 @@ nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI, } -#ifdef MOZ_OLD_STYLE - { - RefPtr geckoSheet; - nsresult rv = LoadSheet(aSheetURI, parsingMode, StyleBackendType::Gecko, &geckoSheet); - NS_ENSURE_SUCCESS(rv, rv); - MOZ_ASSERT(geckoSheet); - mGeckoSheets[aSheetType].AppendElement(geckoSheet); - } -#endif -#ifdef MOZ_STYLO if (nsLayoutUtils::StyloSupportedInCurrentProcess()) { RefPtr servoSheet; nsresult rv = LoadSheet(aSheetURI, parsingMode, StyleBackendType::Servo, &servoSheet); @@ -268,7 +253,6 @@ nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI, MOZ_ASSERT(servoSheet); mServoSheets[aSheetType].AppendElement(servoSheet); } -#endif return NS_OK; } @@ -285,11 +269,7 @@ nsStyleSheetService::SheetRegistered(nsIURI *sheetURI, // Check to see if we have the sheet. StyleBackendType backendType = -#ifdef MOZ_OLD_STYLE - StyleBackendType::Gecko; -#else StyleBackendType::Servo; -#endif *_retval = (FindSheetByURI(backendType, aSheetType, sheetURI) >= 0); return NS_OK; @@ -385,15 +365,6 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType) // We have to search for Gecko and Servo sheets separately. int32_t foundIndex; -#ifdef MOZ_OLD_STYLE - // Gecko first, which should always be present, if the old style system - // is enabled. - foundIndex = FindSheetByURI(StyleBackendType::Gecko, aSheetType, aSheetURI); - NS_ENSURE_TRUE(foundIndex >= 0, NS_ERROR_INVALID_ARG); - - RefPtr geckoSheet = mGeckoSheets[aSheetType][foundIndex]; - mGeckoSheets[aSheetType].RemoveElementAt(foundIndex); -#endif // Now search for Servo, which may or may not be present. RefPtr servoSheet; @@ -409,11 +380,7 @@ nsStyleSheetService::UnregisterSheet(nsIURI *aSheetURI, uint32_t aSheetType) for (nsIPresShell* presShell : toNotify) { if (presShell->StyleSet()) { StyleSheet* sheet = -#ifdef MOZ_OLD_STYLE - presShell->StyleSet()->IsGecko() ? geckoSheet : servoSheet; -#else servoSheet; -#endif if (sheet) { presShell->NotifyStyleSheetServiceSheetRemoved(sheet, aSheetType); } @@ -473,9 +440,6 @@ nsStyleSheetService::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) co { size_t n = aMallocSizeOf(this); for (auto* sheetArrays : { -#ifdef MOZ_OLD_STYLE - &mGeckoSheets, -#endif &mServoSheets, }) { for (auto& sheetArray : *sheetArrays) { diff --git a/layout/base/nsStyleSheetService.h b/layout/base/nsStyleSheetService.h index 835859e0626c..2692b26093d7 100644 --- a/layout/base/nsStyleSheetService.h +++ b/layout/base/nsStyleSheetService.h @@ -85,19 +85,10 @@ private: mozilla::Array& Sheets(mozilla::StyleBackendType aType) { -#ifdef MOZ_OLD_STYLE - if (aType == mozilla::StyleBackendType::Gecko) { - return mGeckoSheets; - } -#else MOZ_ASSERT(aType == mozilla::StyleBackendType::Servo); -#endif return mServoSheets; } -#ifdef MOZ_OLD_STYLE - mozilla::Array mGeckoSheets; -#endif mozilla::Array mServoSheets; // Registered PresShells that will be notified when sheets are added and diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 05c27b12d35b..28abeb64208e 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -40,9 +40,6 @@ #include "nsPlainTextSerializer.h" #include "nsXMLContentSerializer.h" #include "nsXHTMLContentSerializer.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" -#endif #include "nsContentAreaDragDrop.h" #include "nsBox.h" #include "nsIFrameTraversal.h" diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index 4acf76a10369..140350ac34f7 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -33,18 +33,12 @@ #include "nsGkAtoms.h" #include "nsImageFrame.h" #include "nsLayoutStylesheetCache.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/RuleProcessorCache.h" -#endif #include "nsRange.h" #include "nsRegion.h" #include "nsRepeatService.h" #include "nsFloatManager.h" #include "nsSprocketLayout.h" #include "nsStackLayout.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsTextControlFrame.h" #include "nsXBLService.h" #include "txMozillaXSLTProcessor.h" @@ -284,9 +278,6 @@ nsLayoutStatics::Initialize() ServiceWorkerRegistrar::Initialize(); #ifdef DEBUG -#ifdef MOZ_OLD_STYLE - GeckoStyleContext::Initialize(); -#endif mozilla::LayerAnimationInfo::Initialize(); #endif @@ -296,11 +287,9 @@ nsLayoutStatics::Initialize() mozilla::dom::WebCryptoThreadPool::Initialize(); -#ifdef MOZ_STYLO if (XRE_IsParentProcess() || XRE_IsContentProcess()) { InitializeServo(); } -#endif #ifndef MOZ_WIDGET_ANDROID // On Android, we instantiate it when constructing AndroidBridge. @@ -329,12 +318,10 @@ nsLayoutStatics::Shutdown() // Don't need to shutdown nsWindowMemoryReporter, that will be done by the // memory reporter manager. -#ifdef MOZ_STYLO if (XRE_IsParentProcess() || XRE_IsContentProcess()) { ShutdownServo(); URLExtraData::ReleaseDummy(); } -#endif nsMessageManagerScriptExecutor::Shutdown(); nsFocusManager::Shutdown(); @@ -346,9 +333,6 @@ nsLayoutStatics::Shutdown() Attr::Shutdown(); EventListenerManager::Shutdown(); IMEStateManager::Shutdown(); -#ifdef MOZ_OLD_STYLE - nsCSSParser::Shutdown(); -#endif nsMediaFeatures::Shutdown(); nsHTMLDNSPrefetch::Shutdown(); nsCSSRendering::Shutdown(); @@ -386,9 +370,6 @@ nsLayoutStatics::Shutdown() nsAttrValue::Shutdown(); nsContentUtils::Shutdown(); nsLayoutStylesheetCache::Shutdown(); -#ifdef MOZ_OLD_STYLE - RuleProcessorCache::Shutdown(); -#endif ShutdownJSEnvironment(); nsGlobalWindowInner::ShutDown(); diff --git a/layout/forms/nsMeterFrame.cpp b/layout/forms/nsMeterFrame.cpp index ac4d3750a07d..3c5a41c5626b 100644 --- a/layout/forms/nsMeterFrame.cpp +++ b/layout/forms/nsMeterFrame.cpp @@ -20,9 +20,6 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLMeterElement.h" #include "nsCSSPseudoElements.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandleInlines.h" #include "nsThemeConstants.h" diff --git a/layout/forms/nsNumberControlFrame.cpp b/layout/forms/nsNumberControlFrame.cpp index 2acce1c5eb6c..8b9fa7dd38af 100644 --- a/layout/forms/nsNumberControlFrame.cpp +++ b/layout/forms/nsNumberControlFrame.cpp @@ -21,9 +21,6 @@ #include "nsContentUtils.h" #include "nsContentCreatorFunctions.h" #include "nsCSSPseudoElements.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandleInlines.h" #include "nsThreadUtils.h" diff --git a/layout/forms/nsProgressFrame.cpp b/layout/forms/nsProgressFrame.cpp index 76b67fe7cfd9..ef9277c70a87 100644 --- a/layout/forms/nsProgressFrame.cpp +++ b/layout/forms/nsProgressFrame.cpp @@ -20,9 +20,6 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLProgressElement.h" #include "nsCSSPseudoElements.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandleInlines.h" #include "nsThemeConstants.h" diff --git a/layout/generic/nsFirstLetterFrame.cpp b/layout/generic/nsFirstLetterFrame.cpp index 9f86cd5ace48..0d45459b7003 100644 --- a/layout/generic/nsFirstLetterFrame.cpp +++ b/layout/generic/nsFirstLetterFrame.cpp @@ -80,10 +80,6 @@ nsFirstLetterFrame::SetInitialChildList(ChildListID aListID, for (nsIFrame* f : aChildList) { MOZ_ASSERT(f->GetParent() == this, "Unexpected parent"); MOZ_ASSERT(f->IsTextFrame(), "We should not have kids that are containers!"); -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT_IF(f->StyleContext()->IsGecko(), - f->StyleContext()->AsGecko()->GetParent() == StyleContext()); -#endif nsLayoutUtils::MarkDescendantsDirty(f); // Drops cached textruns } diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index a693b03e8fef..89ee896937ab 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -45,10 +45,6 @@ #include "mozilla/Sprintf.h" #include "nsLayoutUtils.h" #include "LayoutLogging.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoStyleContext.h" -#include "mozilla/GeckoRestyleManager.h" -#endif #include "mozilla/RestyleManager.h" #include "mozilla/RestyleManagerInlines.h" #include "nsInlineFrame.h" @@ -785,18 +781,7 @@ nsFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) // because what matters is whether the new style (not the old) // specifies CSS transitions. if (presContext->RestyleManager()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - // stylo: ServoRestyleManager does not handle transitions yet, and when - // it does it probably won't need to track reframed style contexts to - // initiate transitions correctly. - GeckoRestyleManager::ReframingStyleContexts* rsc = - presContext->RestyleManager()->AsGecko()->GetReframingStyleContexts(); - if (rsc) { - rsc->Put(mContent, mStyleContext->AsGecko()); - } -#else MOZ_CRASH("old style system disabled"); -#endif } } @@ -7808,20 +7793,6 @@ nsIFrame::ListGeneric(nsACString& aTo, const char* aPrefix, uint32_t aFlags) con pseudoTag->ToString(atomString); aTo += nsPrintfCString("%s", NS_LossyConvertUTF16toASCII(atomString).get()); } -#ifdef MOZ_OLD_STYLE - if (auto* geckoContext = mStyleContext->GetAsGecko()) { - if (!geckoContext->GetParent() || - (GetParent() && GetParent()->StyleContext() != geckoContext->GetParent())) { - aTo += nsPrintfCString("^%p", geckoContext->GetParent()); - if (geckoContext->GetParent()) { - aTo += nsPrintfCString("^%p", geckoContext->GetParent()->GetParent()); - if (geckoContext->GetParent()->GetParent()) { - aTo += nsPrintfCString("^%p", geckoContext->GetParent()->GetParent()->GetParent()); - } - } - } - } -#endif } aTo += "]"; } diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index d1806101b49e..6d61a12e9160 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -29,9 +29,6 @@ #include "nsIFrameInlines.h" #include "nsPresContext.h" #include "nsReadableUtils.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" -#endif #include "nsStyleContext.h" #include "nsTableWrapperFrame.h" diff --git a/layout/inspector/InspectorFontFace.cpp b/layout/inspector/InspectorFontFace.cpp index a70a4fe8ff7f..120595afbb7f 100644 --- a/layout/inspector/InspectorFontFace.cpp +++ b/layout/inspector/InspectorFontFace.cpp @@ -6,9 +6,6 @@ #include "InspectorFontFace.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRules.h" -#endif #include "gfxTextRun.h" #include "gfxUserFontSet.h" #include "nsFontFaceLoader.h" diff --git a/layout/inspector/InspectorUtils.cpp b/layout/inspector/InspectorUtils.cpp index f7c372c2423f..7cd0ef80ec6e 100644 --- a/layout/inspector/InspectorUtils.cpp +++ b/layout/inspector/InspectorUtils.cpp @@ -19,11 +19,6 @@ #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsIDOMDocument.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" -#include "nsIStyleRule.h" -#include "mozilla/css/StyleRule.h" -#endif #include "nsIDOMWindow.h" #include "nsXBLBinding.h" #include "nsXBLPrototypeBinding.h" @@ -37,13 +32,7 @@ #include "mozilla/StyleSheetInlines.h" #include "mozilla/dom/CharacterData.h" #include "mozilla/dom/Element.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#endif #include "nsCSSPseudoClasses.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#endif #include "mozilla/dom/CSSLexer.h" #include "mozilla/dom/InspectorUtilsBinding.h" #include "mozilla/dom/ToJSValue.h" @@ -189,31 +178,7 @@ InspectorUtils::GetCSSStyleRules(GlobalObject& aGlobalObject, if (styleContext->IsGecko()) { -#ifdef MOZ_OLD_STYLE - auto gecko = styleContext->AsGecko(); - nsRuleNode* ruleNode = gecko->RuleNode(); - if (!ruleNode) { - return; - } - - AutoTArray ruleNodes; - while (!ruleNode->IsRoot()) { - ruleNodes.AppendElement(ruleNode); - ruleNode = ruleNode->GetParent(); - } - - for (nsRuleNode* ruleNode : Reversed(ruleNodes)) { - RefPtr decl = do_QueryObject(ruleNode->GetRule()); - if (decl) { - css::Rule* owningRule = decl->GetOwningRule(); - if (owningRule) { - aResult.AppendElement(owningRule); - } - } - } -#else MOZ_CRASH("old style system disabled"); -#endif } else { nsIDocument* doc = aElement.OwnerDoc(); nsIPresShell* shell = doc->GetShell(); @@ -899,23 +864,11 @@ InspectorUtils::ColorToRGBA(GlobalObject& aGlobalObject, { nscolor color = NS_RGB(0, 0, 0); -#ifdef MOZ_STYLO if (!ServoCSSParser::ComputeColor(nullptr, NS_RGB(0, 0, 0), aColorString, &color)) { aResult.SetNull(); return; } -#else - nsCSSParser cssParser; - nsCSSValue cssValue; - - if (!cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true)) { - aResult.SetNull(); - return; - } - - nsRuleNode::ComputeColor(cssValue, nullptr, nullptr, color); -#endif InspectorRGBATuple& tuple = aResult.SetValue(); tuple.mR = NS_GET_R(color); @@ -928,13 +881,7 @@ InspectorUtils::ColorToRGBA(GlobalObject& aGlobalObject, InspectorUtils::IsValidCSSColor(GlobalObject& aGlobalObject, const nsAString& aColorString) { -#ifdef MOZ_STYLO return ServoCSSParser::IsValidCSSColor(aColorString); -#else - nsCSSParser cssParser; - nsCSSValue cssValue; - return cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true); -#endif } void @@ -1154,16 +1101,6 @@ InspectorUtils::ParseStyleSheet(GlobalObject& aGlobalObject, const nsAString& aInput, ErrorResult& aRv) { -#ifdef MOZ_OLD_STYLE - RefPtr geckoSheet = do_QueryObject(&aSheet); - if (geckoSheet) { - nsresult rv = geckoSheet->ReparseSheet(aInput); - if (NS_FAILED(rv)) { - aRv.Throw(rv); - } - return; - } -#endif RefPtr servoSheet = do_QueryObject(&aSheet); if (servoSheet) { diff --git a/layout/mathml/nsMathMLTokenFrame.cpp b/layout/mathml/nsMathMLTokenFrame.cpp index 3f060749860d..524c4afb498c 100644 --- a/layout/mathml/nsMathMLTokenFrame.cpp +++ b/layout/mathml/nsMathMLTokenFrame.cpp @@ -8,9 +8,6 @@ #include "nsPresContext.h" #include "nsContentUtils.h" #include "nsTextFrame.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoRestyleManager.h" -#endif #include using namespace mozilla; diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index 874d31e503fe..b2ad758d833c 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -78,9 +78,6 @@ #include "LayersLogging.h" #include "FrameLayerBuilder.h" #include "mozilla/EventStateManager.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoRestyleManager.h" -#endif #include "nsCaret.h" #include "nsISelection.h" #include "nsDOMTokenList.h" @@ -179,11 +176,7 @@ static void AddTransformFunctions(const nsCSSValueList* aList, } GeckoStyleContext* contextIfGecko = -#ifdef MOZ_OLD_STYLE - aContext ? aContext->GetAsGecko() : nullptr; -#else nullptr; -#endif for (const nsCSSValueList* curr = aList; curr; curr = curr->mNext) { const nsCSSValue& currElem = curr->mValue; @@ -487,13 +480,7 @@ SetAnimatable(nsCSSPropertyID aProperty, Servo_AnimationValue_GetTransform(aAnimationValue.mServo, &list); AddTransformFunctions(list, aFrame, aRefBox, aAnimatable); } else { -#ifdef MOZ_OLD_STYLE - nsCSSValueSharedList* list = - aAnimationValue.mGecko.GetCSSValueSharedListValue(); - AddTransformFunctions(list, aFrame, aRefBox, aAnimatable); -#else MOZ_CRASH("old style system disabled"); -#endif } break; } diff --git a/layout/style/AnimationCollection.cpp b/layout/style/AnimationCollection.cpp index 2f71d8f2c0ad..8bbd2df6495c 100644 --- a/layout/style/AnimationCollection.cpp +++ b/layout/style/AnimationCollection.cpp @@ -116,15 +116,6 @@ AnimationCollection::GetOrCreateAnimationCollection( return collection; } -#ifdef MOZ_OLD_STYLE -template -void -AnimationCollection::UpdateCheckGeneration( - nsPresContext* aPresContext) -{ - mCheckGeneration = aPresContext->RestyleManager()->GetAnimationGeneration(); -} -#endif template /*static*/ nsAtom* diff --git a/layout/style/AnimationCollection.h b/layout/style/AnimationCollection.h index a2d38385a8b6..f403463b433d 100644 --- a/layout/style/AnimationCollection.h +++ b/layout/style/AnimationCollection.h @@ -38,9 +38,6 @@ class AnimationCollection AnimationCollection(dom::Element* aElement, nsAtom* aElementProperty) : mElement(aElement) , mElementProperty(aElementProperty) -#ifdef MOZ_OLD_STYLE - , mCheckGeneration(0) -#endif #ifdef DEBUG , mCalledPropertyDtor(false) #endif @@ -98,17 +95,6 @@ public: InfallibleTArray> mAnimations; -#ifdef MOZ_OLD_STYLE - // For CSS transitions only, we record the most recent generation - // for which we've done the transition update, so that we avoid doing - // it more than once per style change. - // (Note that we also store an animation generation on each EffectSet in - // order to track when we need to update animations on layers.) - uint64_t mCheckGeneration; - - // Update mCheckGeneration to RestyleManager's count - void UpdateCheckGeneration(nsPresContext* aPresContext); -#endif private: static nsAtom* GetPropertyAtomForPseudoType( diff --git a/layout/style/CSS.cpp b/layout/style/CSS.cpp index 1c10f815fa6f..e40f1ddf927d 100644 --- a/layout/style/CSS.cpp +++ b/layout/style/CSS.cpp @@ -69,13 +69,7 @@ CSS::Supports(const GlobalObject& aGlobal, return Servo_CSSSupports2(&property, &value); } -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - return parser.EvaluateSupportsDeclaration(aProperty, aValue, info.mDocURI, - info.mBaseURI, info.mPrincipal); -#else MOZ_CRASH("old style system disabled"); -#endif } /* static */ bool @@ -96,15 +90,8 @@ CSS::Supports(const GlobalObject& aGlobal, return Servo_CSSSupports(&cond); } -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - return parser.EvaluateSupportsCondition(aCondition, info.mDocURI, - info.mBaseURI, info.mPrincipal, - css::SupportsParsingSettings::ImpliedParentheses); -#else MOZ_CRASH("old style system disabled"); return false; -#endif } /* static */ void diff --git a/layout/style/CSSKeyframesRule.cpp b/layout/style/CSSKeyframesRule.cpp index 0b60bd26116c..01cde2b81e9c 100644 --- a/layout/style/CSSKeyframesRule.cpp +++ b/layout/style/CSSKeyframesRule.cpp @@ -11,15 +11,6 @@ namespace mozilla { namespace dom { -#ifdef MOZ_OLD_STYLE -/* virtual */ bool -CSSKeyframesRule::UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) -{ - MOZ_ASSERT_UNREACHABLE("should not be called"); - return false; -} -#endif /* virtual */ JSObject* CSSKeyframesRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) diff --git a/layout/style/CSSKeyframesRule.h b/layout/style/CSSKeyframesRule.h index 68a0ff2094dc..4cb914529803 100644 --- a/layout/style/CSSKeyframesRule.h +++ b/layout/style/CSSKeyframesRule.h @@ -31,10 +31,6 @@ public: virtual void DeleteRule(const nsAString& aKey) = 0; virtual CSSKeyframeRule* FindRule(const nsAString& aKey) = 0; -#ifdef MOZ_OLD_STYLE - bool UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) final; -#endif size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override = 0; diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 25fcab0e720d..2e70fbaf6cdd 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -35,9 +35,6 @@ #include "nsContentUtils.h" #include "nsIScriptSecurityManager.h" #include "mozAutoDocUpdate.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleNode.h" -#endif #include "nsMediaFeatures.h" #include "nsDOMClassInfoID.h" #include "mozilla/Likely.h" diff --git a/layout/style/CounterStyleManager.cpp b/layout/style/CounterStyleManager.cpp index ca0d06ce7298..d894f467f603 100644 --- a/layout/style/CounterStyleManager.cpp +++ b/layout/style/CounterStyleManager.cpp @@ -14,9 +14,6 @@ #include "mozilla/WritingModes.h" #include "nsCSSCounterStyleRule.h" #include "nsString.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsTArray.h" #include "nsTHashtable.h" #include "nsUnicodeProperties.h" diff --git a/layout/style/DeclarationBlockInlines.h b/layout/style/DeclarationBlockInlines.h index 88b39184c261..2b3333e3e82e 100644 --- a/layout/style/DeclarationBlockInlines.h +++ b/layout/style/DeclarationBlockInlines.h @@ -7,9 +7,6 @@ #ifndef mozilla_DeclarationBlockInlines_h #define mozilla_DeclarationBlockInlines_h -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/Declaration.h" -#endif #include "mozilla/ServoDeclarationBlock.h" namespace mozilla { @@ -33,11 +30,7 @@ DeclarationBlock::Clone() const { RefPtr result; if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - result = new css::Declaration(*AsGecko()); -#else MOZ_CRASH("old style system disabled"); -#endif } else { result = new ServoDeclarationBlock(*AsServo()); } @@ -48,11 +41,6 @@ already_AddRefed DeclarationBlock::EnsureMutable() { #ifdef DEBUG -#ifdef MOZ_OLD_STYLE - if (IsGecko()) { - AsGecko()->AssertNotExpanded(); - } -#endif #endif if (IsServo() && !IsDirty()) { // In stylo, the old DeclarationBlock is stored in element's rule node tree diff --git a/layout/style/FontFace.cpp b/layout/style/FontFace.cpp index 372f6f51e8e1..b53b4f869011 100644 --- a/layout/style/FontFace.cpp +++ b/layout/style/FontFace.cpp @@ -542,21 +542,7 @@ FontFace::ParseDescriptor(nsCSSFontDesc aDescID, return ServoCSSParser::ParseFontDescriptor(aDescID, aString, url, aResult); } -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - if (!parser.ParseFontFaceDescriptor(aDescID, aString, - docURI, // aSheetURL - base, - principal, - aResult)) { - aResult.Reset(); - return false; - } - - return true; -#else MOZ_CRASH("old style system disabled"); -#endif } void diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index 280bf30d96aa..704468ec8155 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -9,9 +9,6 @@ #include "gfxFontConstants.h" #include "gfxFontSrcPrincipal.h" #include "gfxFontSrcURI.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/Declaration.h" -#endif #include "mozilla/css/Loader.h" #include "mozilla/dom/FontFaceSetBinding.h" #include "mozilla/dom/FontFaceSetIterator.h" @@ -50,9 +47,6 @@ #include "nsLayoutUtils.h" #include "nsPresContext.h" #include "nsPrintfCString.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsUTF8Utils.h" #include "nsDOMNavigationTiming.h" #include "StylePrefs.h" @@ -227,62 +221,7 @@ FontFaceSet::ParseFontShorthandForMatching( return; } -#ifdef MOZ_OLD_STYLE - // Parse aFont as a 'font' property value. - RefPtr declaration = new Declaration; - declaration->InitializeEmpty(); - - bool changed = false; - nsCSSParser parser; - parser.ParseProperty(eCSSProperty_font, - aFont, - mDocument->GetDocumentURI(), - mDocument->GetDocumentURI(), - mDocument->NodePrincipal(), - declaration, - &changed, - /* aIsImportant */ false); - - // All of the properties we are interested in should have been set at once. - MOZ_ASSERT(changed == (declaration->HasProperty(eCSSProperty_font_family) && - declaration->HasProperty(eCSSProperty_font_style) && - declaration->HasProperty(eCSSProperty_font_weight) && - declaration->HasProperty(eCSSProperty_font_stretch))); - - if (!changed) { - aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); - return; - } - - nsCSSCompressedDataBlock* data = declaration->GetNormalBlock(); - MOZ_ASSERT(!declaration->GetImportantBlock()); - - const nsCSSValue* family = data->ValueFor(eCSSProperty_font_family); - if (family->GetUnit() != eCSSUnit_FontFamilyList) { - // We got inherit, initial, unset, a system font, or a token stream. - aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); - return; - } - - aFamilyList = family->GetFontFamilyListValue(); - - int32_t weight = data->ValueFor(eCSSProperty_font_weight)->GetIntValue(); - - // Resolve relative font weights against the initial of font-weight - // (normal, which is equivalent to 400). - if (weight == NS_STYLE_FONT_WEIGHT_BOLDER) { - weight = NS_FONT_WEIGHT_BOLD; - } else if (weight == NS_STYLE_FONT_WEIGHT_LIGHTER) { - weight = NS_FONT_WEIGHT_THIN; - } - - aWeight = weight; - - aStretch = data->ValueFor(eCSSProperty_font_stretch)->GetIntValue(); - aStyle = data->ValueFor(eCSSProperty_font_style)->GetIntValue(); -#else MOZ_CRASH("old style system disabled"); -#endif } static bool diff --git a/layout/style/GenericSpecifiedValuesInlines.h b/layout/style/GenericSpecifiedValuesInlines.h index ea92c76ee785..c20e305236b2 100644 --- a/layout/style/GenericSpecifiedValuesInlines.h +++ b/layout/style/GenericSpecifiedValuesInlines.h @@ -14,9 +14,6 @@ #ifndef mozilla_GenericSpecifiedValuesInlines_h #define mozilla_GenericSpecifiedValuesInlines_h -#ifdef MOZ_OLD_STYLE -#include "nsRuleData.h" -#endif #include "mozilla/GenericSpecifiedValues.h" #include "mozilla/ServoSpecifiedValues.h" @@ -36,11 +33,7 @@ GenericSpecifiedValues::ShouldIgnoreColors() const return false; } -#ifdef MOZ_OLD_STYLE - return !AsGecko()->mPresContext->UseDocumentColors(); -#else MOZ_CRASH("old style system disabled"); -#endif } bool @@ -83,29 +76,11 @@ GenericSpecifiedValues::SetIdentAtomValueIfUnset(nsCSSPropertyID aId, void GenericSpecifiedValues::SetKeywordValue(nsCSSPropertyID aId, int32_t aValue) { -#ifdef MOZ_OLD_STYLE - // there are some static asserts in MOZ_STYLO_FORWARD which - // won't work with the overloaded SetKeywordValue function, - // so we copy its expansion and use SetIntValue for decltype - // instead - static_assert( - !mozilla::IsSame::value, - "Gecko subclass should define its own SetKeywordValue"); - static_assert( - !mozilla::IsSame::value, - "Servo subclass should define its own SetKeywordValue"); -#endif if (IsServo()) { return AsServo()->SetKeywordValue(aId, aValue); } -#ifdef MOZ_OLD_STYLE - return AsGecko()->SetKeywordValue(aId, aValue); -#else MOZ_CRASH("old style system disabled"); -#endif } void diff --git a/layout/style/GroupRule.cpp b/layout/style/GroupRule.cpp index 65e75d531934..c7d5b930c71c 100644 --- a/layout/style/GroupRule.cpp +++ b/layout/style/GroupRule.cpp @@ -18,190 +18,11 @@ using namespace mozilla::dom; namespace mozilla { namespace css { -#ifdef MOZ_OLD_STYLE -#define CALL_INNER(inner_, call_) \ - ((inner_).is() \ - ? (inner_).as().call_ \ - : (inner_).as().call_) -#else #define CALL_INNER(inner_, call_) \ ((inner_).is() \ ? (inner_).as().call_ \ : (inner_).as().call_) -#endif -#ifdef MOZ_OLD_STYLE -// ------------------------------- -// Style Rule List for group rules -// - -class GroupRuleRuleList final : public dom::CSSRuleList -{ -public: - explicit GroupRuleRuleList(GroupRule *aGroupRule); - - virtual CSSStyleSheet* GetParentObject() override; - - virtual Rule* - IndexedGetter(uint32_t aIndex, bool& aFound) override; - virtual uint32_t - Length() override; - - void DropReference() { mGroupRule = nullptr; } - -private: - ~GroupRuleRuleList(); - -private: - GroupRule* mGroupRule; -}; - -GroupRuleRuleList::GroupRuleRuleList(GroupRule *aGroupRule) -{ - // Not reference counted to avoid circular references. - // The rule will tell us when its going away. - mGroupRule = aGroupRule; -} - -GroupRuleRuleList::~GroupRuleRuleList() -{ -} - -CSSStyleSheet* -GroupRuleRuleList::GetParentObject() -{ - if (!mGroupRule) { - return nullptr; - } - StyleSheet* sheet = mGroupRule->GetStyleSheet(); - return sheet ? sheet->AsGecko() : nullptr; -} - -uint32_t -GroupRuleRuleList::Length() -{ - if (!mGroupRule) { - return 0; - } - - return AssertedCast(mGroupRule->StyleRuleCount()); -} - -Rule* -GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) -{ - aFound = false; - - if (mGroupRule) { - RefPtr rule = mGroupRule->GetStyleRuleAt(aIndex); - if (rule) { - aFound = true; - return rule; - } - } - - return nullptr; -} - -// ------------------------------- -// GeckoGroupRuleRules -// - -GeckoGroupRuleRules::GeckoGroupRuleRules() -{ -} - -GeckoGroupRuleRules::GeckoGroupRuleRules(GeckoGroupRuleRules&& aOther) - : mRules(Move(aOther.mRules)) - , mRuleCollection(Move(aOther.mRuleCollection)) -{ -} - -GeckoGroupRuleRules::GeckoGroupRuleRules(const GeckoGroupRuleRules& aCopy) -{ - for (const Rule* rule : aCopy.mRules) { - RefPtr clone = rule->Clone(); - mRules.AppendObject(clone); - } -} - -GeckoGroupRuleRules::~GeckoGroupRuleRules() -{ - for (Rule* rule : mRules) { - rule->SetParentRule(nullptr); - } - if (mRuleCollection) { - mRuleCollection->DropReference(); - } -} - -void -GeckoGroupRuleRules::Clear() -{ - mRules.Clear(); - if (mRuleCollection) { - mRuleCollection->DropReference(); - mRuleCollection = nullptr; - } -} - -void -GeckoGroupRuleRules::Traverse(nsCycleCollectionTraversalCallback& cb) -{ - IncrementalClearCOMRuleArray& rules = mRules; - for (int32_t i = 0, count = rules.Count(); i < count; ++i) { - if (!rules[i]->IsCCLeaf()) { - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]"); - cb.NoteXPCOMChild(rules[i]); - } - } - ImplCycleCollectionTraverse(cb, mRuleCollection, "mRuleCollection"); -} - -#ifdef DEBUG -void -GeckoGroupRuleRules::List(FILE* out, int32_t aIndent) const -{ - for (const Rule* rule : mRules) { - rule->List(out, aIndent + 1); - } -} -#endif - -nsresult -GeckoGroupRuleRules::DeleteStyleRuleAt(uint32_t aIndex) -{ - Rule* rule = mRules.SafeObjectAt(aIndex); - if (rule) { - rule->SetStyleSheet(nullptr); - rule->SetParentRule(nullptr); - } - return mRules.RemoveObjectAt(aIndex) ? NS_OK : NS_ERROR_ILLEGAL_VALUE; -} - -CSSRuleList* -GeckoGroupRuleRules::CssRules(GroupRule* aParentRule) -{ - if (!mRuleCollection) { - mRuleCollection = new GroupRuleRuleList(aParentRule); - } - return mRuleCollection; -} - -size_t -GeckoGroupRuleRules::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const -{ - size_t n = mRules.ShallowSizeOfExcludingThis(aMallocSizeOf); - for (const Rule* rule : mRules) { - n += rule->SizeOfIncludingThis(aMallocSizeOf); - } - - // Measurement of the following members may be added later if DMD finds it is - // worthwhile: - // - mRuleCollection - return n; -} -#endif // ------------------------------- // ServoGroupRuleRules @@ -235,11 +56,7 @@ ServoGroupRuleRules::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber) : Rule(aLineNumber, aColumnNumber) -#ifdef MOZ_OLD_STYLE - , mInner(GeckoGroupRuleRules()) -#else , mInner(DummyGroupRuleRules()) -#endif { } @@ -309,55 +126,6 @@ GroupRule::SetStyleSheet(StyleSheet* aSheet) } } -#ifdef MOZ_OLD_STYLE -void -GroupRule::AppendStyleRule(Rule* aRule) -{ - GeckoRules().AppendObject(aRule); - StyleSheet* sheet = GetStyleSheet(); - aRule->SetStyleSheet(sheet); - aRule->SetParentRule(this); - if (sheet) { - sheet->RuleChanged(this); - } -} - -bool -GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const -{ - for (const Rule* rule : GeckoRules()) { - if (!aFunc(const_cast(rule), aData)) { - return false; - } - } - return true; -} - -nsresult -GroupRule::InsertStyleRuleAt(uint32_t aIndex, Rule* aRule) -{ - aRule->SetStyleSheet(GetStyleSheet()); - aRule->SetParentRule(this); - if (!GeckoRules().InsertObjectAt(aRule, aIndex)) { - return NS_ERROR_FAILURE; - } - return NS_OK; -} - -void -GroupRule::AppendRulesToCssText(nsAString& aCssText) const -{ - aCssText.AppendLiteral(" {\n"); - for (const Rule* rule : GeckoRules()) { - nsAutoString cssText; - rule->GetCssText(cssText); - aCssText.AppendLiteral(" "); - aCssText.Append(cssText); - aCssText.Append('\n'); - } - aCssText.Append('}'); -} -#endif CSSRuleList* GroupRule::CssRules() diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index 8dcecad31da1..6eeb98394737 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -14,9 +14,6 @@ #include "mozilla/Attributes.h" #include "mozilla/ErrorResult.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/IncrementalClearCOMRuleArray.h" -#endif #include "mozilla/MemoryReporting.h" #include "mozilla/ServoCSSRuleList.h" #include "mozilla/Variant.h" @@ -39,47 +36,6 @@ namespace css { class GroupRule; class GroupRuleRuleList; -#ifdef MOZ_OLD_STYLE -struct GeckoGroupRuleRules -{ - GeckoGroupRuleRules(); - GeckoGroupRuleRules(GeckoGroupRuleRules&& aOther); - GeckoGroupRuleRules(const GeckoGroupRuleRules& aCopy); - ~GeckoGroupRuleRules(); - - void SetParentRule(GroupRule* aParentRule) { - for (Rule* rule : mRules) { - rule->SetParentRule(aParentRule); - } - } - void SetStyleSheet(StyleSheet* aSheet) { - for (Rule* rule : mRules) { - rule->SetStyleSheet(aSheet); - } - } - - void Clear(); - void Traverse(nsCycleCollectionTraversalCallback& cb); - -#ifdef DEBUG - void List(FILE* out, int32_t aIndent) const; -#endif - - int32_t StyleRuleCount() const { return mRules.Count(); } - Rule* GetStyleRuleAt(int32_t aIndex) const { - return mRules.SafeObjectAt(aIndex); - } - - nsresult DeleteStyleRuleAt(uint32_t aIndex); - - dom::CSSRuleList* CssRules(GroupRule* aParentRule); - - size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; - - IncrementalClearCOMRuleArray mRules; - RefPtr mRuleCollection; // lazily constructed -}; -#endif struct ServoGroupRuleRules { @@ -152,21 +108,12 @@ struct DummyGroupRuleRules size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { return 0; } }; -#ifdef MOZ_OLD_STYLE -#define REDIRECT_TO_INNER(call_) \ - if (mInner.is()) { \ - return mInner.as().call_; \ - } else { \ - return mInner.as().call_; \ - } -#else #define REDIRECT_TO_INNER(call_) \ if (mInner.is()) { \ return mInner.as().call_; \ } else { \ return mInner.as().call_; \ } -#endif // inherits from Rule so it can be shared between // MediaRule and DocumentRule @@ -192,9 +139,6 @@ public: virtual void SetStyleSheet(StyleSheet* aSheet) override; public: -#ifdef MOZ_OLD_STYLE - void AppendStyleRule(Rule* aRule); -#endif int32_t StyleRuleCount() const { REDIRECT_TO_INNER(StyleRuleCount()) @@ -203,10 +147,6 @@ public: REDIRECT_TO_INNER(GetStyleRuleAt(aIndex)) } -#ifdef MOZ_OLD_STYLE - typedef bool (*RuleEnumFunc)(Rule* aElement, void* aData); - bool EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const; -#endif /* * The next two methods should never be called unless you have first @@ -216,12 +156,6 @@ public: nsresult DeleteStyleRuleAt(uint32_t aIndex) { REDIRECT_TO_INNER(DeleteStyleRuleAt(aIndex)); } -#ifdef MOZ_OLD_STYLE - nsresult InsertStyleRuleAt(uint32_t aIndex, Rule* aRule); - - virtual bool UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) = 0; -#endif // non-virtual -- it is only called by subclasses size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { @@ -236,28 +170,13 @@ public: void DeleteRule(uint32_t aIndex, ErrorResult& aRv); protected: -#ifdef MOZ_OLD_STYLE - void AppendRulesToCssText(nsAString& aCssText) const; - - // Must only be called if this is a Gecko GroupRule. - IncrementalClearCOMRuleArray& GeckoRules() { - return mInner.as().mRules; - } - const IncrementalClearCOMRuleArray& GeckoRules() const { - return mInner.as().mRules; - } -#endif private: -#ifdef MOZ_OLD_STYLE - Variant mInner; -#else // This only reason for the DummyGroupRuleRules is that ServoKeyframesRule // inherits from CSSKeyframesRules (and thus GroupRule). Once // ServoKeyframesRule can be made to inherit from Rule, the // DummyGroupRuleRules can be removed. Variant mInner; -#endif }; #undef REDIRECT_TO_INNER diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 686e62be4546..f7c36fb8c59e 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -39,9 +39,6 @@ #include "nsIStyleSheetLinkingElement.h" #include "nsICSSLoaderObserver.h" #include "nsCSSParser.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/ImportRule.h" -#endif #include "nsThreadUtils.h" #include "nsGkAtoms.h" #include "nsIThreadInternal.h" @@ -1118,11 +1115,7 @@ Loader::CreateSheet(nsIURI* aURI, } if (GetStyleBackendType() == StyleBackendType::Gecko) { -#ifdef MOZ_OLD_STYLE - *aSheet = new CSSStyleSheet(aParsingMode, aCORSMode, aReferrerPolicy, sriMetadata); -#else MOZ_CRASH("old style system disabled"); -#endif } else { *aSheet = new ServoStyleSheet(aParsingMode, aCORSMode, aReferrerPolicy, sriMetadata); } @@ -1270,11 +1263,7 @@ Loader::InsertChildSheet(StyleSheet* aSheet, // cloned off of top-level sheets which were disabled aSheet->SetEnabled(true); if (aGeckoParentRule) { -#ifdef MOZ_OLD_STYLE - aGeckoParentRule->SetSheet(aSheet->AsGecko()); // This sets the ownerRule on the sheet -#else MOZ_CRASH("old style system disabled"); -#endif } aParentSheet->PrependStyleSheet(aSheet); @@ -1679,50 +1668,9 @@ Loader::ParseSheet(const nsAString& aUTF16, if (ServoStyleSheet* sheet = aLoadData->mSheet->GetAsServo()) { return DoParseSheetServo(sheet, aUTF16, aUTF8, aLoadData, aAllowAsync, aCompleted); } -#ifdef MOZ_OLD_STYLE - return DoParseSheetGecko(aLoadData->mSheet->AsGecko(), aUTF16, aUTF8, aLoadData, aCompleted); -#else MOZ_CRASH("old style system disabled"); -#endif } -#ifdef MOZ_OLD_STYLE -nsresult -Loader::DoParseSheetGecko(CSSStyleSheet* aSheet, - const nsAString& aUTF16, - Span aUTF8, - SheetLoadData* aLoadData, - bool& aCompleted) -{ - aLoadData->mIsBeingParsed = true; - nsCSSParser parser(this, aSheet); - nsresult rv = parser.ParseSheet(aUTF16, - aSheet->GetSheetURI(), - aSheet->GetBaseURI(), - aSheet->Principal(), - aLoadData, - aLoadData->mLineNumber); - aLoadData->mIsBeingParsed = false; - if (NS_FAILED(rv)) { - LOG_ERROR((" Low-level error in parser!")); - SheetComplete(aLoadData, rv); - return rv; - } - - NS_ASSERTION(aLoadData->mPendingChildren == 0 || !aLoadData->mSyncLoad, - "Sync load has leftover pending children!"); - - if (aLoadData->mPendingChildren == 0) { - LOG((" No pending kids from parse")); - aCompleted = true; - SheetComplete(aLoadData, NS_OK); - } - // Otherwise, the children are holding strong refs to the data and - // will call SheetComplete() on it when they complete. - - return NS_OK; -} -#endif nsresult Loader::DoParseSheetServo(ServoStyleSheet* aSheet, @@ -2293,11 +2241,7 @@ Loader::LoadChildSheet(StyleSheet* aParentSheet, StyleSheetState state; if (aReusableSheets && aReusableSheets->FindReusableStyleSheet(aURL, sheet)) { if (aParentSheet->IsGecko()) { -#ifdef MOZ_OLD_STYLE - aGeckoParentRule->SetSheet(sheet->AsGecko()); -#else MOZ_CRASH("old style system disabled"); -#endif } state = eSheetComplete; } else { diff --git a/layout/style/Loader.h b/layout/style/Loader.h index 02ed2fc89d71..cfd423659848 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -590,13 +590,6 @@ private: // -#ifdef MOZ_OLD_STYLE - nsresult DoParseSheetGecko(CSSStyleSheet* aSheet, - const nsAString& aUTF16, - Span aUTF8, - SheetLoadData* aLoadData, - bool& aCompleted); -#endif nsresult DoParseSheetServo(ServoStyleSheet* aSheet, const nsAString& aUTF16, diff --git a/layout/style/MediaList.cpp b/layout/style/MediaList.cpp index 68b797665fbf..f60a38080c79 100644 --- a/layout/style/MediaList.cpp +++ b/layout/style/MediaList.cpp @@ -13,9 +13,6 @@ #include "mozilla/ServoMediaList.h" #include "mozilla/StyleSheetInlines.h" #include "nsCSSParser.h" -#ifdef MOZ_OLD_STYLE -#include "nsMediaList.h" -#endif namespace mozilla { namespace dom { @@ -83,14 +80,7 @@ MediaList::Create( return mediaList.forget(); } -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - RefPtr mediaList = new nsMediaList(); - parser.ParseMediaList(aMedia, nullptr, 0, mediaList, aCallerType); - return mediaList.forget(); -#else MOZ_CRASH("old style system disabled"); -#endif } void diff --git a/layout/style/RuleNodeCacheConditions.h b/layout/style/RuleNodeCacheConditions.h index 34a038082a16..b617d7a97c41 100644 --- a/layout/style/RuleNodeCacheConditions.h +++ b/layout/style/RuleNodeCacheConditions.h @@ -13,150 +13,6 @@ #ifndef RuleNodeCacheConditions_h_ #define RuleNodeCacheConditions_h_ -#ifdef MOZ_OLD_STYLE - -#include "mozilla/Attributes.h" -#include "nsCoord.h" -#include "nsTArray.h" - -class nsStyleContext; - -namespace mozilla { - -/** - * nsRuleNodeCacheConditions is used to store information about whether - * we can store a style struct that we're computing in the rule tree. - * - * For inherited structs (i.e., structs with inherited properties), we - * cache the struct in the rule tree if it does not depend on any data - * in the style context tree, and otherwise store it in the style - * context tree. This means that for inherited structs, setting any - * conditions is equivalent to making the struct uncacheable. - * - * For reset structs (i.e., structs with non-inherited properties), we - * are also able to cache structs in the rule tree conditionally on - * certain common conditions. For these structs, setting conditions - * (SetFontSizeDependency, SetWritingModeDependency) instead causes the - * struct to be stored, with the condition, in the rule tree. - */ -class RuleNodeCacheConditions -{ -public: - RuleNodeCacheConditions() - : mFontSize(0) - , mBits(0) - , mWritingMode(0) - {} - - RuleNodeCacheConditions(const RuleNodeCacheConditions& aOther) - : mFontSize(aOther.mFontSize) - , mBits(aOther.mBits) - , mWritingMode(aOther.mWritingMode) - {} - - RuleNodeCacheConditions& operator=(const RuleNodeCacheConditions& aOther) - { - mFontSize = aOther.mFontSize; - mBits = aOther.mBits; - mWritingMode = aOther.mWritingMode; - return *this; - } - - bool operator==(const RuleNodeCacheConditions& aOther) const - { - return mFontSize == aOther.mFontSize && - mBits == aOther.mBits && - mWritingMode == aOther.mWritingMode; - } - - bool operator!=(const RuleNodeCacheConditions& aOther) const - { - return !(*this == aOther); - } - - bool Matches(nsStyleContext* aStyleContext) const; - - /** - * Record that the data being computed depend on the font-size - * property of the element for which they are being computed. - * - * Note that we sometimes actually call this when there is a - * dependency on the font-size property of the parent element, but we - * only do so while computing inherited structs (nsStyleFont), and we - * only store reset structs conditionally. - */ - void SetFontSizeDependency(nscoord aCoord) - { - MOZ_ASSERT(!(mBits & eHaveFontSize) || mFontSize == aCoord); - mFontSize = aCoord; - mBits |= eHaveFontSize; - } - - /** - * Record that the data being computed depend on the writing mode of - * the element for which they are being computed, which in turn - * depends on its 'writing-mode', 'direction', and 'text-orientation' - * properties. - */ - void SetWritingModeDependency(uint8_t aWritingMode) - { - MOZ_ASSERT(!(mBits & eHaveWritingMode) || mWritingMode == aWritingMode); - mWritingMode = aWritingMode; - mBits |= eHaveWritingMode; - } - - void SetUncacheable() - { - mBits |= eUncacheable; - } - - void Clear() - { - *this = RuleNodeCacheConditions(); - } - - bool Cacheable() const - { - return !(mBits & eUncacheable); - } - - bool CacheableWithDependencies() const - { - return Cacheable() && mBits; - } - - bool CacheableWithoutDependencies() const - { - // We're not uncacheable and we have don't have a font-size or - // writing mode value. - return mBits == 0; - } - -#ifdef DEBUG - void List() const; -#endif - -private: - enum { - eUncacheable = 1 << 0, - eHaveFontSize = 1 << 1, - eHaveWritingMode = 1 << 2, - }; - - // The font size from which em units are derived. - nscoord mFontSize; - - // Values in mBits: - // bit 0: are we set to "uncacheable"? - // bit 1: do we have a font size value? - // bit 2: do we have a writing mode value? - uint8_t mBits; - uint8_t mWritingMode; -}; - -} // namespace mozilla - -#else namespace mozilla { @@ -168,6 +24,5 @@ class RuleNodeCacheConditions } // namespace mozilla -#endif #endif // !defined(RuleNodeCacheConditions_h_) diff --git a/layout/style/ServoBindings.cpp b/layout/style/ServoBindings.cpp index f0c838e0746f..7bf2f0634b22 100644 --- a/layout/style/ServoBindings.cpp +++ b/layout/style/ServoBindings.cpp @@ -19,10 +19,6 @@ #include "nsCSSProps.h" #include "nsCSSParser.h" #include "nsCSSPseudoElements.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#include "nsCSSRules.h" -#endif #include "nsContentUtils.h" #include "nsDOMTokenList.h" #include "nsDeviceContext.h" @@ -56,9 +52,6 @@ #include "mozilla/EffectCompositor.h" #include "mozilla/EffectSet.h" #include "mozilla/EventStates.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoStyleContext.h" -#endif #include "mozilla/Keyframe.h" #include "mozilla/Mutex.h" #include "mozilla/Preferences.h" @@ -2706,14 +2699,6 @@ Gecko_SetJemallocThreadLocalArena(bool enabled) #undef STYLE_STRUCT -#ifndef MOZ_STYLO -#define SERVO_BINDING_FUNC(name_, return_, ...) \ - return_ name_(__VA_ARGS__) { \ - MOZ_CRASH("stylo: shouldn't be calling " #name_ "in a non-stylo build"); \ - } -#include "ServoBindingList.h" -#undef SERVO_BINDING_FUNC -#endif ErrorReporter* Gecko_CreateCSSErrorReporter(ServoStyleSheet* sheet, diff --git a/layout/style/ServoDocumentRule.cpp b/layout/style/ServoDocumentRule.cpp index 8ae3c585d64e..45904f736209 100644 --- a/layout/style/ServoDocumentRule.cpp +++ b/layout/style/ServoDocumentRule.cpp @@ -42,17 +42,6 @@ ServoDocumentRule::Clone() const return nullptr; } -#ifdef MOZ_OLD_STYLE -/* virtual */ bool -ServoDocumentRule::UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) -{ - // GroupRule::UseForPresentation is only used in nsCSSRuleProcessor, - // so this should never be called. - MOZ_ASSERT_UNREACHABLE("Shouldn't be calling UseForPresentation"); - return false; -} -#endif #ifdef DEBUG /* virtual */ void diff --git a/layout/style/ServoDocumentRule.h b/layout/style/ServoDocumentRule.h index d632217a70be..56fe7d14b479 100644 --- a/layout/style/ServoDocumentRule.h +++ b/layout/style/ServoDocumentRule.h @@ -23,10 +23,6 @@ public: NS_DECL_ISUPPORTS_INHERITED already_AddRefed Clone() const override; -#ifdef MOZ_OLD_STYLE - bool UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) final; -#endif #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; #endif diff --git a/layout/style/ServoMediaRule.cpp b/layout/style/ServoMediaRule.cpp index dd6d39f8b756..ff16485f6eac 100644 --- a/layout/style/ServoMediaRule.cpp +++ b/layout/style/ServoMediaRule.cpp @@ -59,17 +59,6 @@ ServoMediaRule::Clone() const return nullptr; } -#ifdef MOZ_OLD_STYLE -/* virtual */ bool -ServoMediaRule::UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) -{ - // GroupRule::UseForPresentation is only used in nsCSSRuleProcessor, - // so this should never be called. - MOZ_ASSERT_UNREACHABLE("Shouldn't be calling UseForPresentation"); - return false; -} -#endif /* virtual */ void ServoMediaRule::SetStyleSheet(StyleSheet* aSheet) diff --git a/layout/style/ServoMediaRule.h b/layout/style/ServoMediaRule.h index 1bba3958648a..5e0c25121084 100644 --- a/layout/style/ServoMediaRule.h +++ b/layout/style/ServoMediaRule.h @@ -26,10 +26,6 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoMediaRule, dom::CSSMediaRule) already_AddRefed Clone() const override; -#ifdef MOZ_OLD_STYLE - bool UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) final; -#endif void SetStyleSheet(StyleSheet* aSheet) override; #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; diff --git a/layout/style/ServoStyleContext.cpp b/layout/style/ServoStyleContext.cpp index bea639ca6378..c2226b1ef575 100644 --- a/layout/style/ServoStyleContext.cpp +++ b/layout/style/ServoStyleContext.cpp @@ -10,9 +10,6 @@ #include "nsStyleConsts.h" #include "nsStyleStruct.h" #include "nsPresContext.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#endif #include "mozilla/dom/HTMLBodyElement.h" #include "mozilla/ServoBindings.h" diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index e5c8978a89b0..79df7f01fd1b 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -33,9 +33,6 @@ #include "nsMediaFeatures.h" #include "nsPrintfCString.h" #include "nsSMILAnimationController.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleContext.h" -#endif #include "nsXBLPrototypeBinding.h" #include "gfxUserFontSet.h" #include "nsBindingManager.h" diff --git a/layout/style/ServoSupportsRule.cpp b/layout/style/ServoSupportsRule.cpp index c8c85e75b6fe..5092a754cf92 100644 --- a/layout/style/ServoSupportsRule.cpp +++ b/layout/style/ServoSupportsRule.cpp @@ -43,17 +43,6 @@ ServoSupportsRule::Clone() const return nullptr; } -#ifdef MOZ_OLD_STYLE -/* virtual */ bool -ServoSupportsRule::UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) -{ - // GroupRule::UseForPresentation is only used in nsCSSRuleProcessor, - // so this should never be called. - MOZ_ASSERT_UNREACHABLE("Shouldn't be calling UseForPresentation"); - return false; -} -#endif #ifdef DEBUG /* virtual */ void diff --git a/layout/style/ServoSupportsRule.h b/layout/style/ServoSupportsRule.h index 9cdaadff8ea4..ae8243307519 100644 --- a/layout/style/ServoSupportsRule.h +++ b/layout/style/ServoSupportsRule.h @@ -23,10 +23,6 @@ public: NS_DECL_ISUPPORTS_INHERITED already_AddRefed Clone() const override; -#ifdef MOZ_OLD_STYLE - bool UseForPresentation(nsPresContext* aPresContext, - nsMediaQueryResultCacheKey& aKey) final; -#endif #ifdef DEBUG void List(FILE* out = stdout, int32_t aIndent = 0) const final; #endif diff --git a/layout/style/ServoUtils.h b/layout/style/ServoUtils.h index 6f52e96e0623..2fa12bfad68d 100644 --- a/layout/style/ServoUtils.h +++ b/layout/style/ServoUtils.h @@ -35,19 +35,9 @@ inline bool IsInServoTraversal() } } // namespace mozilla -#if defined(MOZ_STYLO) && defined(MOZ_OLD_STYLE) -# define MOZ_DECL_STYLO_CHECK_METHODS \ - bool IsGecko() const { return !IsServo(); } \ - bool IsServo() const { return mType == StyleBackendType::Servo; } -#elif defined(MOZ_STYLO) # define MOZ_DECL_STYLO_CHECK_METHODS \ bool IsGecko() const { return false; } \ bool IsServo() const { return true; } -#else -# define MOZ_DECL_STYLO_CHECK_METHODS \ - bool IsGecko() const { return true; } \ - bool IsServo() const { return false; } -#endif #define MOZ_DECL_STYLO_CONVERT_METHODS_SERVO(servotype_) \ inline servotype_* AsServo(); \ @@ -61,14 +51,8 @@ inline bool IsInServoTraversal() inline geckotype_* GetAsGecko(); \ inline const geckotype_* GetAsGecko() const; -#ifdef MOZ_OLD_STYLE -#define MOZ_DECL_STYLO_CONVERT_METHODS(geckotype_, servotype_) \ - MOZ_DECL_STYLO_CONVERT_METHODS_SERVO(servotype_) \ - MOZ_DECL_STYLO_CONVERT_METHODS_GECKO(geckotype_) -#else #define MOZ_DECL_STYLO_CONVERT_METHODS(geckotype_, servotype_) \ MOZ_DECL_STYLO_CONVERT_METHODS_SERVO(servotype_) -#endif /** * Macro used in a base class of |geckotype_| and |servotype_|. @@ -116,14 +100,8 @@ inline bool IsInServoTraversal() * subclasses named |geckotype_| and |servotype_| correspondingly for * implementing the inline methods defined by MOZ_DECL_STYLO_METHODS. */ -#ifdef MOZ_OLD_STYLE -#define MOZ_DEFINE_STYLO_METHODS(type_, geckotype_, servotype_) \ - MOZ_DEFINE_STYLO_METHODS_SERVO(type_, servotype_) \ - MOZ_DEFINE_STYLO_METHODS_GECKO(type_, geckotype_) -#else #define MOZ_DEFINE_STYLO_METHODS(type_, geckotype_, servotype_) \ MOZ_DEFINE_STYLO_METHODS_SERVO(type_, servotype_) -#endif #define MOZ_STYLO_THIS_TYPE mozilla::RemovePointer::Type #define MOZ_STYLO_GECKO_TYPE mozilla::RemovePointer::Type @@ -134,22 +112,8 @@ inline bool IsInServoTraversal() * the Servo or Gecko implementation. The class of the method using it * should use MOZ_DECL_STYLO_METHODS to define basic stylo methods. */ -#ifdef MOZ_OLD_STYLE -#define MOZ_STYLO_FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \ - static_assert(!mozilla::IsSame \ - ::value, "Gecko subclass should define its own " #method_); \ - static_assert(!mozilla::IsSame \ - ::value, "Servo subclass should define its own " #method_); \ - if (IsServo()) { \ - return AsServo()->method_ servoargs_; \ - } \ - return AsGecko()->method_ geckoargs_; -#else #define MOZ_STYLO_FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \ return AsServo()->method_ servoargs_; -#endif #define MOZ_STYLO_FORWARD(method_, args_) \ MOZ_STYLO_FORWARD_CONCRETE(method_, args_, args_) diff --git a/layout/style/StyleAnimationValue.cpp b/layout/style/StyleAnimationValue.cpp index 2fb2e3adb96a..7e55ec139bc7 100644 --- a/layout/style/StyleAnimationValue.cpp +++ b/layout/style/StyleAnimationValue.cpp @@ -18,22 +18,12 @@ #include "mozilla/UniquePtr.h" #include "nsAutoPtr.h" #include "nsCOMArray.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRule.h" -#include "mozilla/css/StyleRule.h" -#endif #include "nsString.h" #include "nsStyleContext.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsComputedDOMStyle.h" #include "nsContentUtils.h" #include "nsCSSParser.h" #include "nsCSSPseudoElements.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/Declaration.h" -#endif #include "mozilla/dom/Element.h" #include "mozilla/FloatingPoint.h" #include "mozilla/Likely.h" @@ -53,147 +43,6 @@ using nsStyleTransformMatrix::Decompose2DMatrix; using nsStyleTransformMatrix::Decompose3DMatrix; using nsStyleTransformMatrix::ShearType; -#ifdef MOZ_OLD_STYLE -// HELPER METHODS -// -------------- -/* - * Given two units, this method returns a common unit that they can both be - * converted into, if possible. This is intended to facilitate - * interpolation, distance-computation, and addition between "similar" units. - * - * The ordering of the arguments should not affect the output of this method. - * - * If there's no sensible common unit, this method returns eUnit_Null. - * - * @param aFirstUnit One unit to resolve. - * @param aFirstUnit The other unit to resolve. - * @return A "common" unit that both source units can be converted into, or - * eUnit_Null if that's not possible. - */ -static -StyleAnimationValue::Unit -GetCommonUnit(nsCSSPropertyID aProperty, - StyleAnimationValue::Unit aFirstUnit, - StyleAnimationValue::Unit aSecondUnit) -{ - if (aFirstUnit != aSecondUnit) { - if (nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_STORES_CALC) && - (aFirstUnit == StyleAnimationValue::eUnit_Coord || - aFirstUnit == StyleAnimationValue::eUnit_Percent || - aFirstUnit == StyleAnimationValue::eUnit_Calc) && - (aSecondUnit == StyleAnimationValue::eUnit_Coord || - aSecondUnit == StyleAnimationValue::eUnit_Percent || - aSecondUnit == StyleAnimationValue::eUnit_Calc)) { - // We can use calc() as the common unit. - return StyleAnimationValue::eUnit_Calc; - } - if ((aFirstUnit == StyleAnimationValue::eUnit_Color || - aFirstUnit == StyleAnimationValue::eUnit_CurrentColor || - aFirstUnit == StyleAnimationValue::eUnit_ComplexColor) && - (aSecondUnit == StyleAnimationValue::eUnit_Color || - aSecondUnit == StyleAnimationValue::eUnit_CurrentColor || - aSecondUnit == StyleAnimationValue::eUnit_ComplexColor)) { - // We can use complex color as the common unit. - return StyleAnimationValue::eUnit_ComplexColor; - } - return StyleAnimationValue::eUnit_Null; - } - return aFirstUnit; -} - -static -nsCSSUnit -GetCommonUnit(nsCSSPropertyID aProperty, - nsCSSUnit aFirstUnit, - nsCSSUnit aSecondUnit) -{ - if (aFirstUnit != aSecondUnit) { - if (nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_STORES_CALC) && - (aFirstUnit == eCSSUnit_Pixel || - aFirstUnit == eCSSUnit_Percent || - aFirstUnit == eCSSUnit_Calc) && - (aSecondUnit == eCSSUnit_Pixel || - aSecondUnit == eCSSUnit_Percent || - aSecondUnit == eCSSUnit_Calc)) { - // We can use calc() as the common unit. - return eCSSUnit_Calc; - } - return eCSSUnit_Null; - } - return aFirstUnit; -} - -static nsCSSKeyword -ToPrimitive(nsCSSKeyword aKeyword) -{ - switch (aKeyword) { - case eCSSKeyword_translatex: - case eCSSKeyword_translatey: - case eCSSKeyword_translatez: - case eCSSKeyword_translate: - return eCSSKeyword_translate3d; - case eCSSKeyword_scalex: - case eCSSKeyword_scaley: - case eCSSKeyword_scalez: - case eCSSKeyword_scale: - return eCSSKeyword_scale3d; - default: - return aKeyword; - } -} - -static bool -HasAccumulateMatrix(const nsCSSValueList* aList) -{ - const nsCSSValueList *item = aList; - do { - nsCSSKeyword func = - nsStyleTransformMatrix::TransformFunctionOf(item->mValue.GetArrayValue()); - if (func == eCSSKeyword_accumulatematrix) { - return true; - } - item = item->mNext; - } while (item); - - return false; -} - -static bool -TransformFunctionsMatch(nsCSSKeyword func1, nsCSSKeyword func2) -{ - // Handle eCSSKeyword_accumulatematrix as different function to be calculated - // (decomposed and recomposed) them later. - if (func1 == eCSSKeyword_accumulatematrix || - func2 == eCSSKeyword_accumulatematrix) { - return false; - } - - return ToPrimitive(func1) == ToPrimitive(func2); -} - -static bool -TransformFunctionListsMatch(const nsCSSValueList *list1, - const nsCSSValueList *list2) -{ - const nsCSSValueList *item1 = list1, *item2 = list2; - do { - nsCSSKeyword func1 = nsStyleTransformMatrix::TransformFunctionOf( - item1->mValue.GetArrayValue()); - nsCSSKeyword func2 = nsStyleTransformMatrix::TransformFunctionOf( - item2->mValue.GetArrayValue()); - - if (!TransformFunctionsMatch(func1, func2)) { - return false; - } - - item1 = item1->mNext; - item2 = item2->mNext; - } while (item1 && item2); - - // Length match? - return !item1 && !item2; -} -#endif static already_AddRefed AppendFunction(nsCSSKeyword aTransformFunction) @@ -246,5085 +95,6 @@ AppendFunction(nsCSSKeyword aTransformFunction) return arr.forget(); } -#ifdef MOZ_OLD_STYLE -static already_AddRefed -ToPrimitive(nsCSSValue::Array* aArray) -{ - nsCSSKeyword tfunc = nsStyleTransformMatrix::TransformFunctionOf(aArray); - nsCSSKeyword primitive = ToPrimitive(tfunc); - RefPtr arr = AppendFunction(primitive); - - // FIXME: This would produce fewer calc() expressions if the - // zero were of compatible type (length vs. percent) when - // needed. - - nsCSSValue zero(0.0f, eCSSUnit_Pixel); - nsCSSValue one(1.0f, eCSSUnit_Number); - switch(tfunc) { - case eCSSKeyword_translate: - { - MOZ_ASSERT(aArray->Count() == 2 || aArray->Count() == 3, - "unexpected count"); - arr->Item(1) = aArray->Item(1); - arr->Item(2) = aArray->Count() == 3 ? aArray->Item(2) : zero; - arr->Item(3) = zero; - break; - } - case eCSSKeyword_translatex: - { - MOZ_ASSERT(aArray->Count() == 2, "unexpected count"); - arr->Item(1) = aArray->Item(1); - arr->Item(2) = zero; - arr->Item(3) = zero; - break; - } - case eCSSKeyword_translatey: - { - MOZ_ASSERT(aArray->Count() == 2, "unexpected count"); - arr->Item(1) = zero; - arr->Item(2) = aArray->Item(1); - arr->Item(3) = zero; - break; - } - case eCSSKeyword_translatez: - { - MOZ_ASSERT(aArray->Count() == 2, "unexpected count"); - arr->Item(1) = zero; - arr->Item(2) = zero; - arr->Item(3) = aArray->Item(1); - break; - } - case eCSSKeyword_scale: - { - MOZ_ASSERT(aArray->Count() == 2 || aArray->Count() == 3, - "unexpected count"); - arr->Item(1) = aArray->Item(1); - arr->Item(2) = aArray->Count() == 3 ? aArray->Item(2) : aArray->Item(1); - arr->Item(3) = one; - break; - } - case eCSSKeyword_scalex: - { - MOZ_ASSERT(aArray->Count() == 2, "unexpected count"); - arr->Item(1) = aArray->Item(1); - arr->Item(2) = one; - arr->Item(3) = one; - break; - } - case eCSSKeyword_scaley: - { - MOZ_ASSERT(aArray->Count() == 2, "unexpected count"); - arr->Item(1) = one; - arr->Item(2) = aArray->Item(1); - arr->Item(3) = one; - break; - } - case eCSSKeyword_scalez: - { - MOZ_ASSERT(aArray->Count() == 2, "unexpected count"); - arr->Item(1) = one; - arr->Item(2) = one; - arr->Item(3) = aArray->Item(1); - break; - } - default: - arr = aArray; - } - return arr.forget(); -} - -static void -AppendCSSShadowValue(const nsCSSShadowItem *aShadow, - nsCSSValueList **&aResultTail, - nsCSSPropertyID aProperty) -{ - MOZ_ASSERT(aShadow, "shadow expected"); - - // X, Y, Radius, Spread, Color, Inset - RefPtr arr = nsCSSValue::Array::Create(6); - arr->Item(0).SetIntegerCoordValue(aShadow->mXOffset); - arr->Item(1).SetIntegerCoordValue(aShadow->mYOffset); - arr->Item(2).SetIntegerCoordValue(aShadow->mRadius); - if (aProperty == eCSSProperty_box_shadow) { - arr->Item(3).SetIntegerCoordValue(aShadow->mSpread); - } - if (aShadow->mHasColor) { - arr->Item(4).SetColorValue(aShadow->mColor); - } - if (aShadow->mInset) { - arr->Item(5).SetEnumValue(StyleBoxShadowType::Inset); - } - - nsCSSValueList *resultItem = new nsCSSValueList; - resultItem->mValue.SetArrayValue(arr, eCSSUnit_Array); - *aResultTail = resultItem; - aResultTail = &resultItem->mNext; -} - -// Like nsStyleCoord::CalcValue, but with length in float pixels instead -// of nscoord. -struct PixelCalcValue -{ - float mLength, mPercent; - bool mHasPercent; -}; - -// Requires a canonical calc() value that we generated. -static PixelCalcValue -ExtractCalcValueInternal(const nsCSSValue& aValue) -{ - MOZ_ASSERT(aValue.GetUnit() == eCSSUnit_Calc, "unexpected unit"); - nsCSSValue::Array *arr = aValue.GetArrayValue(); - MOZ_ASSERT(arr->Count() == 1, "unexpected length"); - - const nsCSSValue &topval = arr->Item(0); - PixelCalcValue result; - if (topval.GetUnit() == eCSSUnit_Pixel) { - result.mLength = topval.GetFloatValue(); - result.mPercent = 0.0f; - result.mHasPercent = false; - } else { - MOZ_ASSERT(topval.GetUnit() == eCSSUnit_Calc_Plus, - "unexpected unit"); - nsCSSValue::Array *arr2 = topval.GetArrayValue(); - const nsCSSValue &len = arr2->Item(0); - const nsCSSValue &pct = arr2->Item(1); - MOZ_ASSERT(len.GetUnit() == eCSSUnit_Pixel, "unexpected unit"); - MOZ_ASSERT(pct.GetUnit() == eCSSUnit_Percent, "unexpected unit"); - result.mLength = len.GetFloatValue(); - result.mPercent = pct.GetPercentValue(); - result.mHasPercent = true; - } - - return result; -} - -// Requires a canonical calc() value that we generated. -static PixelCalcValue -ExtractCalcValue(const StyleAnimationValue& aValue) -{ - PixelCalcValue result; - if (aValue.GetUnit() == StyleAnimationValue::eUnit_Coord) { - result.mLength = - nsPresContext::AppUnitsToFloatCSSPixels(aValue.GetCoordValue()); - result.mPercent = 0.0f; - result.mHasPercent = false; - return result; - } - if (aValue.GetUnit() == StyleAnimationValue::eUnit_Percent) { - result.mLength = 0.0f; - result.mPercent = aValue.GetPercentValue(); - result.mHasPercent = true; - return result; - } - MOZ_ASSERT(aValue.GetUnit() == StyleAnimationValue::eUnit_Calc, - "unexpected unit"); - nsCSSValue *val = aValue.GetCSSValueValue(); - return ExtractCalcValueInternal(*val); -} - -static PixelCalcValue -ExtractCalcValue(const nsCSSValue& aValue) -{ - PixelCalcValue result; - if (aValue.GetUnit() == eCSSUnit_Pixel) { - result.mLength = aValue.GetFloatValue(); - result.mPercent = 0.0f; - result.mHasPercent = false; - return result; - } - if (aValue.GetUnit() == eCSSUnit_Percent) { - result.mLength = 0.0f; - result.mPercent = aValue.GetPercentValue(); - result.mHasPercent = true; - return result; - } - return ExtractCalcValueInternal(aValue); -} - -static void -CalcValueToCSSValue(const nsStyleCoord::CalcValue* aCalc, nsCSSValue& aValue) -{ - aValue.SetCalcValue(aCalc); -} - -static void -CalcValueToCSSValue(const PixelCalcValue& aCalc, nsCSSValue& aValue) -{ - RefPtr arr = nsCSSValue::Array::Create(1); - if (!aCalc.mHasPercent) { - arr->Item(0).SetFloatValue(aCalc.mLength, eCSSUnit_Pixel); - } else { - nsCSSValue::Array *arr2 = nsCSSValue::Array::Create(2); - arr->Item(0).SetArrayValue(arr2, eCSSUnit_Calc_Plus); - arr2->Item(0).SetFloatValue(aCalc.mLength, eCSSUnit_Pixel); - arr2->Item(1).SetPercentValue(aCalc.mPercent); - } - - aValue.SetArrayValue(arr, eCSSUnit_Calc); -} - -static double -CalcPositionSquareDistance(const nsCSSValue& aPos1, - const nsCSSValue& aPos2) -{ - NS_ASSERTION(aPos1.GetUnit() == eCSSUnit_Array && - aPos2.GetUnit() == eCSSUnit_Array, - "Expected two arrays"); - - PixelCalcValue calcVal[4]; - - nsCSSValue::Array* posArray = aPos1.GetArrayValue(); - MOZ_ASSERT(posArray->Count() == 4, "Invalid position value"); - NS_ASSERTION(posArray->Item(0).GetUnit() == eCSSUnit_Null && - posArray->Item(2).GetUnit() == eCSSUnit_Null, - "Invalid list used"); - for (int i = 0; i < 2; ++i) { - MOZ_ASSERT(posArray->Item(i*2+1).GetUnit() != eCSSUnit_Null, - "Invalid position value"); - calcVal[i] = ExtractCalcValue(posArray->Item(i*2+1)); - } - - posArray = aPos2.GetArrayValue(); - MOZ_ASSERT(posArray->Count() == 4, "Invalid position value"); - NS_ASSERTION(posArray->Item(0).GetUnit() == eCSSUnit_Null && - posArray->Item(2).GetUnit() == eCSSUnit_Null, - "Invalid list used"); - for (int i = 0; i < 2; ++i) { - MOZ_ASSERT(posArray->Item(i*2+1).GetUnit() != eCSSUnit_Null, - "Invalid position value"); - calcVal[i+2] = ExtractCalcValue(posArray->Item(i*2+1)); - } - - double squareDistance = 0.0; - for (int i = 0; i < 2; ++i) { - float difflen = calcVal[i+2].mLength - calcVal[i].mLength; - float diffpct = calcVal[i+2].mPercent - calcVal[i].mPercent; - squareDistance += difflen * difflen + diffpct * diffpct; - } - - return squareDistance; -} - -static PixelCalcValue -CalcBackgroundCoord(const nsCSSValue& aCoord) -{ - NS_ASSERTION(aCoord.GetUnit() == eCSSUnit_Array, - "Expected array"); - - nsCSSValue::Array* array = aCoord.GetArrayValue(); - MOZ_ASSERT(array->Count() == 2 && - array->Item(0).GetUnit() == eCSSUnit_Null && - array->Item(1).GetUnit() != eCSSUnit_Null, - "Invalid position value"); - return ExtractCalcValue(array->Item(1)); -} - -static double -CalcPositionCoordSquareDistance(const nsCSSValue& aPos1, - const nsCSSValue& aPos2) -{ - PixelCalcValue calcVal1 = CalcBackgroundCoord(aPos1); - PixelCalcValue calcVal2 = CalcBackgroundCoord(aPos2); - - float difflen = calcVal2.mLength - calcVal1.mLength; - float diffpct = calcVal2.mPercent - calcVal1.mPercent; - return difflen * difflen + diffpct * diffpct; -} - -// Ensure that a float/double value isn't NaN by returning zero instead -// (NaN doesn't have a sign) as a general restriction for floating point -// values in RestrictValue. -template -MOZ_ALWAYS_INLINE T -EnsureNotNan(T aValue) -{ - return aValue; -} -template<> -MOZ_ALWAYS_INLINE float -EnsureNotNan(float aValue) -{ - // This would benefit from a MOZ_FLOAT_IS_NaN if we had one. - return MOZ_LIKELY(!mozilla::IsNaN(aValue)) ? aValue : 0; -} -template<> -MOZ_ALWAYS_INLINE double -EnsureNotNan(double aValue) -{ - return MOZ_LIKELY(!mozilla::IsNaN(aValue)) ? aValue : 0; -} - -template -T -RestrictValue(uint32_t aRestrictions, T aValue) -{ - T result = EnsureNotNan(aValue); - switch (aRestrictions) { - case 0: - break; - case CSS_PROPERTY_VALUE_NONNEGATIVE: - if (result < 0) { - result = 0; - } - break; - case CSS_PROPERTY_VALUE_AT_LEAST_ONE: - if (result < 1) { - result = 1; - } - break; - default: - MOZ_ASSERT(false, "bad value restriction"); - break; - } - return result; -} - -template -T -RestrictValue(nsCSSPropertyID aProperty, T aValue) -{ - return RestrictValue(nsCSSProps::ValueRestrictions(aProperty), aValue); -} - -static void -AddCSSValueAngle(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult) -{ - if (aValue1.GetUnit() == aValue2.GetUnit()) { - // To avoid floating point error, if the units match, maintain the unit. - aResult.SetFloatValue( - EnsureNotNan(aCoeff1 * aValue1.GetFloatValue() + - aCoeff2 * aValue2.GetFloatValue()), - aValue1.GetUnit()); - } else { - aResult.SetFloatValue( - EnsureNotNan(aCoeff1 * aValue1.GetAngleValueInRadians() + - aCoeff2 * aValue2.GetAngleValueInRadians()), - eCSSUnit_Radian); - } -} - -static inline void -AddCSSValuePercent(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult, uint32_t aValueRestrictions = 0) -{ - MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Percent, "unexpected unit"); - MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Percent, "unexpected unit"); - aResult.SetPercentValue(RestrictValue(aValueRestrictions, - aCoeff1 * aValue1.GetPercentValue() + - aCoeff2 * aValue2.GetPercentValue())); -} - -// Add two canonical-form calc values (eUnit_Calc) to make another -// canonical-form calc value. -static void -AddCSSValueCanonicalCalc(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult) -{ - PixelCalcValue v1 = ExtractCalcValue(aValue1); - PixelCalcValue v2 = ExtractCalcValue(aValue2); - PixelCalcValue result; - result.mLength = aCoeff1 * v1.mLength + aCoeff2 * v2.mLength; - result.mPercent = aCoeff1 * v1.mPercent + aCoeff2 * v2.mPercent; - result.mHasPercent = v1.mHasPercent || v2.mHasPercent; - MOZ_ASSERT(result.mHasPercent || result.mPercent == 0.0f, - "can't have a nonzero percentage part without having percentages"); - CalcValueToCSSValue(result, aResult); -} - -static inline void -AddCSSValuePixel(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult, uint32_t aValueRestrictions = 0) -{ - MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Pixel, "unexpected unit"); - MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Pixel, "unexpected unit"); - aResult.SetFloatValue(RestrictValue(aValueRestrictions, - aCoeff1 * aValue1.GetFloatValue() + - aCoeff2 * aValue2.GetFloatValue()), - eCSSUnit_Pixel); -} - -static bool -AddCSSValuePixelPercentCalc(const uint32_t aValueRestrictions, - const nsCSSUnit aCommonUnit, - double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult) -{ - switch (aCommonUnit) { - case eCSSUnit_Pixel: - AddCSSValuePixel(aCoeff1, aValue1, - aCoeff2, aValue2, - aResult, aValueRestrictions); - break; - case eCSSUnit_Percent: - AddCSSValuePercent(aCoeff1, aValue1, - aCoeff2, aValue2, - aResult, aValueRestrictions); - break; - case eCSSUnit_Calc: - AddCSSValueCanonicalCalc(aCoeff1, aValue1, - aCoeff2, aValue2, - aResult); - break; - default: - return false; - } - - return true; -} - -static void -AddTransformTranslate(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult) -{ - // Only three possible units: eCSSUnit_Pixel, eCSSUnit_Percent, or - // eCSSUnit_Calc. - MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Percent || - aValue1.GetUnit() == eCSSUnit_Pixel || - aValue1.IsCalcUnit(), - "unexpected unit"); - MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Percent || - aValue2.GetUnit() == eCSSUnit_Pixel || - aValue2.IsCalcUnit(), - "unexpected unit"); - AddCSSValuePixelPercentCalc(0, - (aValue1.GetUnit() != aValue2.GetUnit() || - aValue1.IsCalcUnit()) - ? eCSSUnit_Calc - : aValue1.GetUnit(), - aCoeff1, aValue1, - aCoeff2, aValue2, - aResult); -} - -// Unclamped AddWeightedColors. -static RGBAColorData -AddWeightedColors(double aCoeff1, const RGBAColorData& aValue1, - double aCoeff2, const RGBAColorData& aValue2) -{ - float factor1 = aValue1.mA * aCoeff1; - float factor2 = aValue2.mA * aCoeff2; - float resultA = factor1 + factor2; - if (resultA <= 0.0) { - return {0, 0, 0, 0}; - } - - if (resultA > 1.0) { - resultA = 1.0; - } - - float resultFactor = 1.0f / resultA; - return RGBAColorData( - (aValue1.mR * factor1 + aValue2.mR * factor2) * resultFactor, - (aValue1.mG * factor1 + aValue2.mG * factor2) * resultFactor, - (aValue1.mB * factor1 + aValue2.mB * factor2) * resultFactor, - resultA); -} - -// CLASS METHODS -// ------------- - -static RGBAColorData -ExtractColor(const nsCSSValue& aValue) -{ - MOZ_ASSERT(aValue.IsNumericColorUnit(), "The unit should be color"); - // PercentageRGBColor and PercentageRGBAColor component value might be - // greater than 1.0 in case when the color value is accumulated, so we - // can't use nsCSSValue::GetColorValue() here because that function - // clamps its values. - if (aValue.GetUnit() == eCSSUnit_PercentageRGBColor || - aValue.GetUnit() == eCSSUnit_PercentageRGBAColor) { - nsCSSValueFloatColor* floatColor = aValue.GetFloatColorValue(); - return { - floatColor->Comp1(), - floatColor->Comp2(), - floatColor->Comp3(), - floatColor->Alpha() - }; - } - return RGBAColorData(aValue.GetColorValue()); -} - -static RGBAColorData -ExtractColor(const StyleAnimationValue& aValue) -{ - MOZ_ASSERT(aValue.GetUnit() == StyleAnimationValue::eUnit_Color); - nsCSSValue* value = aValue.GetCSSValueValue(); - MOZ_ASSERT(value, "CSS value must be valid"); - return ExtractColor(*value); -} - -static ComplexColorData -ExtractComplexColor(const StyleAnimationValue& aValue) -{ - switch (aValue.GetUnit()) { - case StyleAnimationValue::eUnit_Color: - return ComplexColorData(ExtractColor(aValue), 0.0f); - case StyleAnimationValue::eUnit_CurrentColor: - return ComplexColorData({0, 0, 0, 0}, 1.0f); - case StyleAnimationValue::eUnit_ComplexColor: - return ComplexColorData(aValue.GetComplexColorData()); - default: - MOZ_ASSERT_UNREACHABLE("Unknown unit"); - return ComplexColorData({0, 0, 0, 0}, 0.0f); - } -} - -StyleAnimationValue -StyleAnimationValue::Add(nsCSSPropertyID aProperty, - const StyleAnimationValue& aA, - StyleAnimationValue&& aB) -{ - StyleAnimationValue result(Move(aB)); - - Unit commonUnit = - GetCommonUnit(aProperty, result.GetUnit(), aA.GetUnit()); - switch (commonUnit) { - case eUnit_Color: { - RGBAColorData color1 = ExtractColor(result); - RGBAColorData color2 = ExtractColor(aA); - result.mValue.mCSSValue->SetRGBAColorValue( - AddWeightedColors(1.0, color1, 1, color2)); - break; - } - case eUnit_Filter: - case eUnit_Shadow: { - // If |aA| has no function list, don't concatinate anything, just return - // |aB| as the result. - if (!aA.GetCSSValueListValue() || - aA.GetCSSValueListValue()->mValue.GetUnit() == eCSSUnit_None) { - break; - } - UniquePtr resultList(aA.GetCSSValueListValue()->Clone()); - - // If |aB| has function list, concatinate it to |aA|, then return - // the concatinated list. - if (result.GetCSSValueListValue() && - result.GetCSSValueListValue()->mValue.GetUnit() != eCSSUnit_None) { - nsCSSValueList* listA = resultList.get(); - while (listA->mNext) { - listA = listA->mNext; - } - - listA->mNext = result.GetCSSValueListValue(); - } - result.mValue.mCSSValueList = resultList.release(); - break; - } - case eUnit_Transform: { - // If |aA| is 'transform:none', don't concatinate anything, just return - // |aB| as the result. - if (aA.GetCSSValueSharedListValue()->mHead->mValue.GetUnit() == - eCSSUnit_None) { - break; - } - - UniquePtr - resultList(aA.GetCSSValueSharedListValue()->mHead->Clone()); - - // If |aB| is not 'transform:none', concatinate it to |aA|, then return - // the concatinated list. - if (result.GetCSSValueSharedListValue()->mHead->mValue.GetUnit() != - eCSSUnit_None) { - nsCSSValueList* listA = resultList.get(); - while (listA->mNext) { - listA = listA->mNext; - } - - listA->mNext = result.GetCSSValueSharedListValue()->mHead->Clone(); - } - - result.SetTransformValue(new nsCSSValueSharedList(resultList.release())); - break; - } - default: - Unused << AddWeighted(aProperty, - 1.0, result, - 1, aA, - result); - break; - } - - return result; -} - -double -StyleAnimationValue::ComputeColorDistance(const RGBAColorData& aStartColor, - const RGBAColorData& aEndColor) -{ - // http://www.w3.org/TR/smil-animation/#animateColorElement says - // that we should use Euclidean RGB cube distance. However, we - // have to extend that to RGBA. For now, we'll just use the - // Euclidean distance in the (part of the) 4-cube of premultiplied - // colors. - double startA = aStartColor.mA; - double startR = aStartColor.mR * startA; - double startG = aStartColor.mG * startA; - double startB = aStartColor.mB * startA; - double endA = aEndColor.mA; - double endR = aEndColor.mR * endA; - double endG = aEndColor.mG * endA; - double endB = aEndColor.mB * endA; - - double diffA = startA - endA; - double diffR = startR - endR; - double diffG = startG - endG; - double diffB = startB - endB; - return sqrt(diffA * diffA + diffR * diffR + diffG * diffG + diffB * diffB); -} - -enum class ColorAdditionType { - Clamped, // Clamp each color channel after adding. - Unclamped // Do not clamp color channels after adding. -}; - -static UniquePtr -AddWeightedFilterFunction(double aCoeff1, const nsCSSValueList* aList1, - double aCoeff2, const nsCSSValueList* aList2, - ColorAdditionType aColorAdditionType); - -static inline float -GetNumberOrPercent(const nsCSSValue &aValue); - -static bool -ComputeSingleShadowSquareDistance(const nsCSSValueList* aShadow1, - const nsCSSValueList* aShadow2, - double& aSquareDistance, - nsCSSPropertyID aProperty) -{ - MOZ_ASSERT(aShadow1->mValue.GetUnit() == eCSSUnit_Array, "wrong unit"); - MOZ_ASSERT(aShadow2->mValue.GetUnit() == eCSSUnit_Array, "wrong unit"); - const nsCSSValue::Array* array1 = aShadow1->mValue.GetArrayValue(); - const nsCSSValue::Array* array2 = aShadow2->mValue.GetArrayValue(); - - double squareDistance = 0.0; - // X, Y, Radius, Spread - for (size_t i = 0; i < 4; ++i) { - // Spread value is not necessary on text-shadow, - // so we skip the computing distance. - if (i == 3 && (aProperty != eCSSProperty_box_shadow)) { - continue; - } - MOZ_ASSERT(array1->Item(i).GetUnit() == eCSSUnit_Pixel, - "unexpected unit"); - MOZ_ASSERT(array2->Item(i).GetUnit() == eCSSUnit_Pixel, - "unexpected unit"); - double diff = array1->Item(i).GetFloatValue() - - array2->Item(i).GetFloatValue(); - squareDistance += diff * diff; - } - - // Color, Inset - const nsCSSValue& color1 = array1->Item(4); - const nsCSSValue& color2 = array2->Item(4); - const nsCSSValue& inset1 = array1->Item(5); - const nsCSSValue& inset2 = array2->Item(5); - if ((color1.GetUnit() != color2.GetUnit() && - (!color1.IsNumericColorUnit() || - !color2.IsNumericColorUnit())) || - inset1 != inset2) { - // According to AddWeightedShadowItems, we don't know how to animate - // between color and no-color, or between inset and not-inset, - // so we cannot compute the distance either. - // Note: There are only two possible states of the inset value: - // (1) GetUnit() == eCSSUnit_Null - // (2) GetUnit() == eCSSUnit_Enumerated && - // GetIntValue() == NS_STYLE_BOX_SHADOW_INSET - return false; - } - - // We compute the distance of colors only if both are numeric color units. - if (color1.GetUnit() != eCSSUnit_Null) { - double colorDistance = - StyleAnimationValue::ComputeColorDistance(ExtractColor(color1), - ExtractColor(color2)); - squareDistance += colorDistance * colorDistance; - } - - aSquareDistance = squareDistance; - return true; -} - -// Return false if we cannot compute the distance between these filter -// functions. -static bool -ComputeFilterSquareDistance(const nsCSSValueList* aList1, - const nsCSSValueList* aList2, - double& aSquareDistance) -{ - MOZ_ASSERT(aList1, "expected filter list"); - MOZ_ASSERT(aList2, "expected filter list"); - MOZ_ASSERT(aList1->mValue.GetUnit() == eCSSUnit_Function, - "expected function"); - MOZ_ASSERT(aList2->mValue.GetUnit() == eCSSUnit_Function, - "expected function"); - - RefPtr a1 = aList1->mValue.GetArrayValue(); - RefPtr a2 = aList2->mValue.GetArrayValue(); - nsCSSKeyword filterFunction = a1->Item(0).GetKeywordValue(); - if (filterFunction != a2->Item(0).GetKeywordValue()) { - return false; - } - - const nsCSSValue& func1 = a1->Item(1); - const nsCSSValue& func2 = a2->Item(1); - switch (filterFunction) { - case eCSSKeyword_blur: { - nsCSSValue diff; - // In AddWeightedFilterFunctionImpl, blur may have different units, so we - // use eCSSUnit_Calc for that case. - if (!AddCSSValuePixelPercentCalc(0, - func1.GetUnit() == func2.GetUnit() - ? func1.GetUnit() - : eCSSUnit_Calc, - 1.0, func2, - -1.0, func1, - diff)) { - return false; - } - // ExtractCalcValue makes sure mHasPercent and mPercent are correct. - PixelCalcValue v = ExtractCalcValue(diff); - aSquareDistance = v.mLength * v.mLength + v.mPercent * v.mPercent; - break; - } - case eCSSKeyword_grayscale: - case eCSSKeyword_invert: - case eCSSKeyword_sepia: - case eCSSKeyword_brightness: - case eCSSKeyword_contrast: - case eCSSKeyword_opacity: - case eCSSKeyword_saturate: { - double diff = - EnsureNotNan(GetNumberOrPercent(func2) - GetNumberOrPercent(func1)); - aSquareDistance = diff * diff; - break; - } - case eCSSKeyword_hue_rotate: { - nsCSSValue v; - AddCSSValueAngle(1.0, func2, -1.0, func1, v); - double diff = v.GetAngleValueInRadians(); - aSquareDistance = diff * diff; - break; - } - case eCSSKeyword_drop_shadow: { - MOZ_ASSERT(!func1.GetListValue()->mNext && !func2.GetListValue()->mNext, - "drop-shadow filter func doesn't support lists"); - if (!ComputeSingleShadowSquareDistance(func1.GetListValue(), - func2.GetListValue(), - aSquareDistance, - eCSSProperty_filter)) { - return false; - } - break; - } - default: - MOZ_ASSERT_UNREACHABLE("unknown filter function"); - return false; - } - return true; -} - -static bool -ComputeFilterListDistance(const nsCSSValueList* aList1, - const nsCSSValueList* aList2, - double& aDistance) -{ - double squareDistance = 0.0; - while (aList1 || aList2) { - // Return false if one of the lists is neither none nor a function. - if ((aList1 && aList1->mValue.GetUnit() != eCSSUnit_Function) || - (aList2 && aList2->mValue.GetUnit() != eCSSUnit_Function)) { - return false; - } - - MOZ_ASSERT(aList1 || aList2, "one function list item must not be null"); - - double currentSquareDistance = 0.0; - if (!aList1) { - // This is a tricky to get an equivalent none filter function by 0.0 - // coefficients. Although we don't guarantee this function can get the - // correct default values, it can reuse the code from the interpolation. - UniquePtr none = - AddWeightedFilterFunction(0, aList2, 0, aList2, - ColorAdditionType::Clamped); - if (!ComputeFilterSquareDistance(none.get(), aList2, - currentSquareDistance)) { - return false; - } - aList2 = aList2->mNext; - } else if (!aList2) { - UniquePtr none = - AddWeightedFilterFunction(0, aList1, 0, aList1, - ColorAdditionType::Clamped); - if (!ComputeFilterSquareDistance(aList1, none.get(), - currentSquareDistance)) { - return false; - } - aList1 = aList1->mNext; - } else { - if (!ComputeFilterSquareDistance(aList1, aList2, - currentSquareDistance)) { - return false; - } - aList1 = aList1->mNext; - aList2 = aList2->mNext; - } - squareDistance += currentSquareDistance; - } - aDistance = sqrt(squareDistance); - return true; -} - -enum class Restrictions { - Enable, - Disable -}; - -static already_AddRefed -AddShapeFunction(nsCSSPropertyID aProperty, - double aCoeff1, const nsCSSValue::Array* aArray1, - double aCoeff2, const nsCSSValue::Array* aArray2, - Restrictions aRestriction = Restrictions::Enable); - -static bool -ComputeShapeDistance(nsCSSPropertyID aProperty, - const nsCSSValue::Array* aArray1, - const nsCSSValue::Array* aArray2, - double& aDistance) -{ - // Use AddShapeFunction to get the difference between two shape functions. - RefPtr diffShape = - AddShapeFunction(aProperty, 1.0, aArray2, -1.0, aArray1, - Restrictions::Disable); - if (!diffShape) { - return false; - } - - // A helper function to convert a calc() diff value into a double distance. - auto pixelCalcDistance = [](const PixelCalcValue& aValue) { - MOZ_ASSERT(aValue.mHasPercent || aValue.mPercent == 0.0f, - "can't have a nonzero percentage part without having percentages"); - return aValue.mLength * aValue.mLength + aValue.mPercent * aValue.mPercent; - }; - - double squareDistance = 0.0; - const nsCSSValue::Array* func = diffShape->Item(0).GetArrayValue(); - nsCSSKeyword shapeFuncName = func->Item(0).GetKeywordValue(); - switch (shapeFuncName) { - case eCSSKeyword_ellipse: - case eCSSKeyword_circle: { - // Skip the first element which is the function keyword. - // Also, skip the last element which is an array for - const size_t len = func->Count(); - for (size_t i = 1; i < len - 1; ++i) { - squareDistance += pixelCalcDistance(ExtractCalcValue(func->Item(i))); - } - // Only iterate over elements 1 and 3. The is 'uncomputed' to - // only those elements. See also the comment in SetPositionValue. - for (size_t i = 1; i < 4; i += 2) { - const nsCSSValue& value = func->Item(len - 1).GetArrayValue()->Item(i); - squareDistance += pixelCalcDistance(ExtractCalcValue(value)); - } - break; - } - case eCSSKeyword_polygon: { - // Don't care about the first element which is the function keyword, and - // the second element which is the fill rule. - const nsCSSValuePairList* list = func->Item(2).GetPairListValue(); - do { - squareDistance += pixelCalcDistance(ExtractCalcValue(list->mXValue)) + - pixelCalcDistance(ExtractCalcValue(list->mYValue)); - list = list->mNext; - } while (list); - break; - } - case eCSSKeyword_inset: { - // Items 1-4 are respectively the top, right, bottom and left offsets - // from the reference box. - for (size_t i = 1; i <= 4; ++i) { - const nsCSSValue& value = func->Item(i); - squareDistance += pixelCalcDistance(ExtractCalcValue(value)); - } - // Item 5 contains the radii of the rounded corners for the inset - // rectangle. - const nsCSSValue::Array* array = func->Item(5).GetArrayValue(); - const size_t len = array->Count(); - for (size_t i = 0; i < len; ++i) { - const nsCSSValuePair& pair = array->Item(i).GetPairValue(); - squareDistance += pixelCalcDistance(ExtractCalcValue(pair.mXValue)) + - pixelCalcDistance(ExtractCalcValue(pair.mYValue)); - } - break; - } - default: - MOZ_ASSERT_UNREACHABLE("Unknown shape type"); - } - aDistance = sqrt(squareDistance); - return true; -} - -static nsCSSValueList* -AddTransformLists(double aCoeff1, const nsCSSValueList* aList1, - double aCoeff2, const nsCSSValueList* aList2, - nsCSSKeyword aOperatorType = eCSSKeyword_interpolatematrix); - -static double -ComputeTransform2DMatrixDistance(const Matrix& aMatrix1, - const Matrix& aMatrix2) -{ - Point3D scale1(1, 1, 1); - Point3D translate1; - gfxQuaternion rotate1; - nsStyleTransformMatrix::ShearArray shear1{0.0f, 0.0f, 0.0f}; - Decompose2DMatrix(aMatrix1, scale1, shear1, rotate1, translate1); - - Point3D scale2(1, 1, 1); - Point3D translate2; - gfxQuaternion rotate2; - nsStyleTransformMatrix::ShearArray shear2{0.0f, 0.0f, 0.0f}; - Decompose2DMatrix(aMatrix2, scale2, shear2, rotate2, translate2); - - // Note: - // 1. Shear factor is the tangent value of shear angle, so we need to - // call atan() to get the angle. For 2D transform, we only have XYSHEAR. - // 2. The quaternion vector of the decomposed 2d matrix is got by - // "gfxQuaternion(0, 0, sin(rotate/2), cos(rotate/2))" - // ^^^^^^^^^^^^^ ^^^^^^^^^^^^^ - // z w - // Therefore, we can get the rotate angle by 2 * atan2f(z, w). - // - // However, we can also get the rotate angle by the inner product of - // two quaternion vectors, just as what we do for eCSSKeyword_rotate3d. - // e.g. - // rotate3d(0, 0, 1, 60deg) => rotate3d(0, 0, 1, 120deg); - // quaternion 1: (0, 0, sin(30deg), cos(30deg)) = (0, 0, 1/2, sqrt(3)/2) - // quaternion 2: (0, 0, sin(60deg), cos(60deg)) = (0, 0, sqrt(3)/2, 1/2) - // inner product: sqrt(3)/4 + sqrt(3)/4 = sqrt(3)/2 - // Finally, the rotate angle: 2 * acos(sqrt(3)/2) = 60deg - // - // I think doing atan() may be faster than doing inner product together - // with acos(), so let's adopt atan2f(). - const Point3D diffTranslate = translate2 - translate1; - const Point3D diffScale = scale2 - scale1; - const double diffShear = atan(shear2[ShearType::XYSHEAR]) - - atan(shear1[ShearType::XYSHEAR]); - const double diffRotate = 2.0 * (atan2f(rotate2.z, rotate2.w) - - atan2f(rotate1.z, rotate1.w)); - // Returns the sum of squares because we will take a square root in - // ComputeTransformListDistance. - return diffTranslate.DotProduct(diffTranslate) + - diffScale.DotProduct(diffScale) + - diffRotate * diffRotate + - diffShear * diffShear; -} - -static double -ComputeTransform3DMatrixDistance(const Matrix4x4& aMatrix1, - const Matrix4x4& aMatrix2) -{ - Point3D scale1(1, 1, 1); - Point3D translate1; - Point4D perspective1(0, 0, 0, 1); - gfxQuaternion rotate1; - nsStyleTransformMatrix::ShearArray shear1{0.0f, 0.0f, 0.0f}; - Decompose3DMatrix(aMatrix1, scale1, shear1, rotate1, translate1, - perspective1); - - Point3D scale2(1, 1, 1); - Point3D translate2; - Point4D perspective2(0, 0, 0, 1); - gfxQuaternion rotate2; - nsStyleTransformMatrix::ShearArray shear2{0.0f, 0.0f, 0.0f}; - Decompose3DMatrix(aMatrix2, scale2, shear2, rotate2, translate2, - perspective2); - - // Note: - // 1. Shear factor is the tangent value of shear angle, so we need to - // call atan() to get the angle. - // 2. We use the same way to get the rotate angle of two quaternion vectors as - // what we do for rotate3d. - const Point3D diffTranslate = translate2 - translate1; - const Point3D diffScale = scale2 - scale1; - const Point3D diffShear(atan(shear2[ShearType::XYSHEAR]) - - atan(shear1[ShearType::XYSHEAR]), - atan(shear2[ShearType::XZSHEAR]) - - atan(shear1[ShearType::XZSHEAR]), - atan(shear2[ShearType::YZSHEAR]) - - atan(shear1[ShearType::YZSHEAR])); - const Point4D diffPerspective = perspective2 - perspective1; - const double dot = clamped(rotate1.DotProduct(rotate2), -1.0, 1.0); - const double diffRotate = 2.0 * acos(dot); - // Returns the sum of squares because we will take a square root in - // ComputeTransformListDistance. - return diffTranslate.DotProduct(diffTranslate) + - diffScale.DotProduct(diffScale) + - diffPerspective.DotProduct(diffPerspective) + - diffShear.DotProduct(diffShear) + - diffRotate * diffRotate; -} - -static double -ComputeTransformDistance(nsCSSValue::Array* aArray1, - nsCSSValue::Array* aArray2) -{ - MOZ_ASSERT(aArray1, "aArray1 should be non-null."); - MOZ_ASSERT(aArray2, "aArray2 should be non-null."); - - // Normalize translate and scale functions to equivalent "translate3d" and - // "scale3d" functions. - RefPtr a1 = ToPrimitive(aArray1), - a2 = ToPrimitive(aArray2); - nsCSSKeyword tfunc = nsStyleTransformMatrix::TransformFunctionOf(a1); - MOZ_ASSERT(nsStyleTransformMatrix::TransformFunctionOf(a2) == tfunc); - - double distance = 0.0; - switch (tfunc) { - case eCSSKeyword_translate3d: { - MOZ_ASSERT(a1->Count() == 4, "unexpected count"); - MOZ_ASSERT(a2->Count() == 4, "unexpected count"); - - nsCSSValue x, y, z; - AddTransformTranslate(1.0, a2->Item(1), -1.0, a1->Item(1), x); - AddTransformTranslate(1.0, a2->Item(2), -1.0, a1->Item(2), y); - AddTransformTranslate(1.0, a2->Item(3), -1.0, a1->Item(3), z); - // Drop percent part because we only compute distance by computed values. - double c1 = ExtractCalcValue(x).mLength; - double c2 = ExtractCalcValue(y).mLength; - double c3 = z.GetFloatValue(); - distance = c1 * c1 + c2 * c2 + c3 * c3; - break; - } - case eCSSKeyword_scale3d: { - MOZ_ASSERT(a1->Count() == 4, "unexpected count"); - MOZ_ASSERT(a2->Count() == 4, "unexpected count"); - - auto ComputeScaleDiff = [](const nsCSSValue& aValue1, - const nsCSSValue& aValue2) { - float v1 = aValue1.GetFloatValue(); - float v2 = aValue2.GetFloatValue(); - return EnsureNotNan(v2 - v1); - }; - - double c1 = ComputeScaleDiff(a1->Item(1), a2->Item(1)); - double c2 = ComputeScaleDiff(a1->Item(2), a2->Item(2)); - double c3 = ComputeScaleDiff(a1->Item(3), a2->Item(3)); - distance = c1 * c1 + c2 * c2 + c3 * c3; - break; - } - case eCSSKeyword_skew: { - MOZ_ASSERT(a1->Count() == 2 || a1->Count() == 3, "unexpected count"); - MOZ_ASSERT(a2->Count() == 2 || a2->Count() == 3, "unexpected count"); - - const nsCSSValue zero(0.0f, eCSSUnit_Radian); - nsCSSValue x, y; - AddCSSValueAngle(1.0, a2->Item(1), -1.0, a1->Item(1), x); - AddCSSValueAngle(1.0, a2->Count() == 3 ? a2->Item(2) : zero, - -1.0, a1->Count() == 3 ? a1->Item(2) : zero, - y); - distance = x.GetAngleValueInRadians() * x.GetAngleValueInRadians() + - y.GetAngleValueInRadians() * y.GetAngleValueInRadians(); - break; - } - case eCSSKeyword_skewx: - case eCSSKeyword_skewy: - case eCSSKeyword_rotate: - case eCSSKeyword_rotatex: - case eCSSKeyword_rotatey: - case eCSSKeyword_rotatez: { - MOZ_ASSERT(a1->Count() == 2, "unexpected count"); - MOZ_ASSERT(a2->Count() == 2, "unexpected count"); - - nsCSSValue angle; - AddCSSValueAngle(1.0, a2->Item(1), -1.0, a1->Item(1), angle); - distance = angle.GetAngleValueInRadians() * - angle.GetAngleValueInRadians(); - break; - } - case eCSSKeyword_rotate3d: { - MOZ_ASSERT(a1->Count() == 5, "unexpected count"); - MOZ_ASSERT(a2->Count() == 5, "unexpected count"); - - Point3D vector1(a1->Item(1).GetFloatValue(), - a1->Item(2).GetFloatValue(), - a1->Item(3).GetFloatValue()); - double angle1 = a1->Item(4).GetAngleValueInRadians(); - - Point3D vector2(a2->Item(1).GetFloatValue(), - a2->Item(2).GetFloatValue(), - a2->Item(3).GetFloatValue()); - double angle2 = a2->Item(4).GetAngleValueInRadians(); - - auto normalizeVector = [](Point3D& vector, double& angle) { - if (vector.Length() > 0) { - vector.Normalize(); - } else { - vector.x = 0.0; - vector.y = 0.0; - vector.z = 1.0; - angle = 0.0; - } - }; - normalizeVector(vector1, angle1); - normalizeVector(vector2, angle2); - - if (vector1 == vector2) { - // Handle rotate3d with matched (normalized) vectors. - distance = EnsureNotNan(angle2 - angle1); - } else { - // Use quaternion vectors to get the angle difference. Both q1 and q2 - // are unit vectors, so we can get their angle difference by - // cos(theta/2) = (q1 dot q2) / (|q1| * |q2|) = q1 dot q2. - gfxQuaternion q1(vector1, angle1); - gfxQuaternion q2(vector2, angle2); - distance = - EnsureNotNan(2.0 * acos(clamped(q1.DotProduct(q2), -1.0, 1.0))); - } - distance = distance * distance; - break; - } - case eCSSKeyword_perspective: { - MOZ_ASSERT(a1->Count() == 2, "unexpected count"); - MOZ_ASSERT(a2->Count() == 2, "unexpected count"); - - // We convert a perspective function into an equivalent matrix3d, and - // then do matrix decomposition to get the distance. - // Why don't we just subtract one perspective depth from the other? - // I think it's better to follow the logic of our interpolation, - // which does linear interpolation between two decomposed perspective - // vectors. - // e.g. - // Do interpolation between perspective(100px) and perspective(1000px). - // 1) Convert them into matrix3d, and then do matrix decomposition: - // perspective vector 1: perspective(0, 0, -1/100, 1); - // perspective vector 2: perspective(0, 0, -1/1000, 1); - // 2) Do linear interpolation between these two vectors. - // Therefore, we use the same rule to get the distance as what we do for - // matrix3d. - - using nsStyleTransformMatrix::ApplyPerspectiveToMatrix; - Matrix4x4 m1; - ApplyPerspectiveToMatrix(m1, a1->Item(1).GetFloatValue()); - Matrix4x4 m2; - ApplyPerspectiveToMatrix(m2, a2->Item(1).GetFloatValue()); - - distance = ComputeTransform3DMatrixDistance(m1, m2); - break; - } - case eCSSKeyword_matrix: { - MOZ_ASSERT(a1->Count() == 7, "unexpected count"); - MOZ_ASSERT(a2->Count() == 7, "unexpected count"); - - distance = ComputeTransform2DMatrixDistance( - nsStyleTransformMatrix::CSSValueArrayTo2DMatrix(a1), - nsStyleTransformMatrix::CSSValueArrayTo2DMatrix(a2)); - break; - } - case eCSSKeyword_matrix3d: { - MOZ_ASSERT(a1->Count() == 17, "unexpected count"); - MOZ_ASSERT(a2->Count() == 17, "unexpected count"); - - distance = ComputeTransform3DMatrixDistance( - nsStyleTransformMatrix::CSSValueArrayTo3DMatrix(a1), - nsStyleTransformMatrix::CSSValueArrayTo3DMatrix(a2)); - break; - } - case eCSSKeyword_interpolatematrix: - case eCSSKeyword_accumulatematrix: - default: - MOZ_ASSERT_UNREACHABLE("Unsupported transform function"); - break; - } - return distance; -} - -static double -ComputeTransformListDistance(const nsCSSValueList* aList1, - const nsCSSValueList* aList2) -{ - MOZ_ASSERT(aList1, "aList1 should be non-null."); - MOZ_ASSERT(aList2, "aList2 should be non-null."); - - double distance = 0.0; - do { - distance += ComputeTransformDistance(aList1->mValue.GetArrayValue(), - aList2->mValue.GetArrayValue()); - aList1 = aList1->mNext; - aList2 = aList2->mNext; - MOZ_ASSERT(!aList1 == !aList2, - "aList1 and aList2 should have the same length."); - } while (aList1); - return sqrt(distance); -} - -static double -ComputeMismatchedTransfromListDistance(const nsCSSValueList* aList1, - const nsCSSValueList* aList2, - GeckoStyleContext* aStyleContext) -{ - // We need nsStyleContext and nsPresContext to compute calc() values while - // processing the translate part of transforms. - if (!aStyleContext) { - return 0.0; - } - - RuleNodeCacheConditions dontCare; - bool dontCareBool; - nsStyleTransformMatrix::TransformReferenceBox emptyRefBox; - - Matrix4x4 m1 = nsStyleTransformMatrix::ReadTransforms( - aList1, - aStyleContext, - aStyleContext->PresContext(), - dontCare, - emptyRefBox, - nsPresContext::AppUnitsPerCSSPixel(), - &dontCareBool); - Matrix4x4 m2 = nsStyleTransformMatrix::ReadTransforms( - aList2, - aStyleContext, - aStyleContext->PresContext(), - dontCare, - emptyRefBox, - nsPresContext::AppUnitsPerCSSPixel(), - &dontCareBool); - return sqrt(ComputeTransform3DMatrixDistance(m1, m2)); -} - -bool -StyleAnimationValue::ComputeDistance(nsCSSPropertyID aProperty, - const StyleAnimationValue& aStartValue, - const StyleAnimationValue& aEndValue, - GeckoStyleContext* aStyleContext, - double& aDistance) -{ - Unit commonUnit = - GetCommonUnit(aProperty, aStartValue.GetUnit(), aEndValue.GetUnit()); - - switch (commonUnit) { - case eUnit_Null: - case eUnit_Auto: - case eUnit_None: - case eUnit_Normal: - case eUnit_UnparsedString: - case eUnit_URL: - case eUnit_DiscreteCSSValue: - return false; - - case eUnit_Enumerated: - switch (aProperty) { - case eCSSProperty_font_stretch: { - // just like eUnit_Integer. - int32_t startInt = aStartValue.GetIntValue(); - int32_t endInt = aEndValue.GetIntValue(); - aDistance = Abs(endInt - startInt); - return true; - } - default: - return false; - } - case eUnit_Visibility: { - int32_t startEnum = aStartValue.GetIntValue(); - int32_t endEnum = aEndValue.GetIntValue(); - if (startEnum == endEnum) { - aDistance = 0; - return true; - } - if ((startEnum == NS_STYLE_VISIBILITY_VISIBLE) == - (endEnum == NS_STYLE_VISIBILITY_VISIBLE)) { - return false; - } - aDistance = 1; - return true; - } - case eUnit_Integer: { - int32_t startInt = aStartValue.GetIntValue(); - int32_t endInt = aEndValue.GetIntValue(); - aDistance = Abs(double(endInt) - double(startInt)); - return true; - } - case eUnit_Coord: { - nscoord startCoord = aStartValue.GetCoordValue(); - nscoord endCoord = aEndValue.GetCoordValue(); - aDistance = Abs(double(endCoord) - double(startCoord)); - return true; - } - case eUnit_Percent: { - float startPct = aStartValue.GetPercentValue(); - float endPct = aEndValue.GetPercentValue(); - aDistance = Abs(double(endPct) - double(startPct)); - return true; - } - case eUnit_Float: { - float startFloat = aStartValue.GetFloatValue(); - float endFloat = aEndValue.GetFloatValue(); - aDistance = Abs(double(endFloat) - double(startFloat)); - return true; - } - case eUnit_Color: { - aDistance = ComputeColorDistance(ExtractColor(aStartValue), - ExtractColor(aEndValue)); - return true; - } - case eUnit_CurrentColor: { - aDistance = 0; - return true; - } - case eUnit_ComplexColor: { - ComplexColorData color1 = ExtractComplexColor(aStartValue); - ComplexColorData color2 = ExtractComplexColor(aEndValue); - // Common case is interpolating between a color and a currentcolor - if (color1.IsNumericColor() && color2.IsCurrentColor()) { - double dist = ComputeColorDistance(color1.mColor, NS_RGBA(0, 0, 0, 0)); - aDistance = sqrt(dist * dist + 1); - return true; - } - if (color1.IsCurrentColor() && color2.IsNumericColor()) { - double dist = ComputeColorDistance(NS_RGBA(0, 0, 0, 0), color2.mColor); - aDistance = sqrt(dist * dist + 1); - return true; - } - // If we ever reach here, we may want to use the code in - // bug 1299741 comment 79 to compute it. - MOZ_ASSERT_UNREACHABLE("We shouldn't get here as we only call " - "ComputeDistance on pre-interpolation values"); - aDistance = 0.0; - return true; - } - case eUnit_Calc: { - PixelCalcValue v1 = ExtractCalcValue(aStartValue); - PixelCalcValue v2 = ExtractCalcValue(aEndValue); - float difflen = v2.mLength - v1.mLength; - float diffpct = v2.mPercent - v1.mPercent; - aDistance = sqrt(difflen * difflen + diffpct * diffpct); - return true; - } - case eUnit_ObjectPosition: { - const nsCSSValue* position1 = aStartValue.GetCSSValueValue(); - const nsCSSValue* position2 = aEndValue.GetCSSValueValue(); - double squareDistance = - CalcPositionSquareDistance(*position1, - *position2); - aDistance = sqrt(squareDistance); - return true; - } - case eUnit_CSSValuePair: { - const nsCSSValuePair *pair1 = aStartValue.GetCSSValuePairValue(); - const nsCSSValuePair *pair2 = aEndValue.GetCSSValuePairValue(); - nsCSSUnit unit[2]; - unit[0] = GetCommonUnit(aProperty, pair1->mXValue.GetUnit(), - pair2->mXValue.GetUnit()); - unit[1] = GetCommonUnit(aProperty, pair1->mYValue.GetUnit(), - pair2->mYValue.GetUnit()); - if (unit[0] == eCSSUnit_Null || unit[1] == eCSSUnit_Null || - unit[0] == eCSSUnit_URL || unit[0] == eCSSUnit_Enumerated) { - return false; - } - - double squareDistance = 0.0; - static nsCSSValue nsCSSValuePair::* const pairValues[2] = { - &nsCSSValuePair::mXValue, &nsCSSValuePair::mYValue - }; - for (uint32_t i = 0; i < 2; ++i) { - nsCSSValue nsCSSValuePair::*member = pairValues[i]; - double diffsquared; - switch (unit[i]) { - case eCSSUnit_Pixel: { - float diff = (pair1->*member).GetFloatValue() - - (pair2->*member).GetFloatValue(); - diffsquared = diff * diff; - break; - } - case eCSSUnit_Percent: { - float diff = (pair1->*member).GetPercentValue() - - (pair2->*member).GetPercentValue(); - diffsquared = diff * diff; - break; - } - case eCSSUnit_Calc: { - PixelCalcValue v1 = ExtractCalcValue(pair1->*member); - PixelCalcValue v2 = ExtractCalcValue(pair2->*member); - float difflen = v2.mLength - v1.mLength; - float diffpct = v2.mPercent - v1.mPercent; - diffsquared = difflen * difflen + diffpct * diffpct; - break; - } - default: - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - squareDistance += diffsquared; - } - - aDistance = sqrt(squareDistance); - return true; - } - case eUnit_CSSValueTriplet: { - const nsCSSValueTriplet *triplet1 = aStartValue.GetCSSValueTripletValue(); - const nsCSSValueTriplet *triplet2 = aEndValue.GetCSSValueTripletValue(); - nsCSSUnit unit[3]; - unit[0] = GetCommonUnit(aProperty, triplet1->mXValue.GetUnit(), - triplet2->mXValue.GetUnit()); - unit[1] = GetCommonUnit(aProperty, triplet1->mYValue.GetUnit(), - triplet2->mYValue.GetUnit()); - unit[2] = GetCommonUnit(aProperty, triplet1->mZValue.GetUnit(), - triplet2->mZValue.GetUnit()); - if (unit[0] == eCSSUnit_Null || unit[1] == eCSSUnit_Null || - unit[2] == eCSSUnit_Null) { - return false; - } - - double squareDistance = 0.0; - static nsCSSValue nsCSSValueTriplet::* const pairValues[3] = { - &nsCSSValueTriplet::mXValue, &nsCSSValueTriplet::mYValue, &nsCSSValueTriplet::mZValue - }; - for (uint32_t i = 0; i < 3; ++i) { - nsCSSValue nsCSSValueTriplet::*member = pairValues[i]; - double diffsquared; - switch (unit[i]) { - case eCSSUnit_Pixel: { - float diff = (triplet1->*member).GetFloatValue() - - (triplet2->*member).GetFloatValue(); - diffsquared = diff * diff; - break; - } - case eCSSUnit_Percent: { - float diff = (triplet1->*member).GetPercentValue() - - (triplet2->*member).GetPercentValue(); - diffsquared = diff * diff; - break; - } - case eCSSUnit_Calc: { - PixelCalcValue v1 = ExtractCalcValue(triplet1->*member); - PixelCalcValue v2 = ExtractCalcValue(triplet2->*member); - float difflen = v2.mLength - v1.mLength; - float diffpct = v2.mPercent - v1.mPercent; - diffsquared = difflen * difflen + diffpct * diffpct; - break; - } - case eCSSUnit_Null: - diffsquared = 0; - break; - default: - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - squareDistance += diffsquared; - } - - aDistance = sqrt(squareDistance); - return true; - } - case eUnit_CSSRect: { - const nsCSSRect *rect1 = aStartValue.GetCSSRectValue(); - const nsCSSRect *rect2 = aEndValue.GetCSSRectValue(); - if (rect1->mTop.GetUnit() != rect2->mTop.GetUnit() || - rect1->mRight.GetUnit() != rect2->mRight.GetUnit() || - rect1->mBottom.GetUnit() != rect2->mBottom.GetUnit() || - rect1->mLeft.GetUnit() != rect2->mLeft.GetUnit()) { - // At least until we have calc() - return false; - } - - double squareDistance = 0.0; - for (uint32_t i = 0; i < ArrayLength(nsCSSRect::sides); ++i) { - nsCSSValue nsCSSRect::*member = nsCSSRect::sides[i]; - MOZ_ASSERT((rect1->*member).GetUnit() == (rect2->*member).GetUnit(), - "should have returned above"); - double diff; - switch ((rect1->*member).GetUnit()) { - case eCSSUnit_Pixel: - diff = (rect1->*member).GetFloatValue() - - (rect2->*member).GetFloatValue(); - break; - case eCSSUnit_Auto: - diff = 0; - break; - default: - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - squareDistance += diff * diff; - } - - aDistance = sqrt(squareDistance); - return true; - } - case eUnit_Dasharray: { - // NOTE: This produces results on substantially different scales - // for length values and percentage values, which might even be - // mixed in the same property value. This means the result isn't - // particularly useful for paced animation. - - // Call AddWeighted to make us lists of the same length. - StyleAnimationValue normValue1, normValue2; - if (!AddWeighted(aProperty, 1.0, aStartValue, 0.0, aEndValue, - normValue1) || - !AddWeighted(aProperty, 0.0, aStartValue, 1.0, aEndValue, - normValue2)) { - return false; - } - - double squareDistance = 0.0; - const nsCSSValueList *list1 = normValue1.GetCSSValueListValue(); - const nsCSSValueList *list2 = normValue2.GetCSSValueListValue(); - - MOZ_ASSERT(!list1 == !list2, "lists should be same length"); - while (list1) { - const nsCSSValue &val1 = list1->mValue; - const nsCSSValue &val2 = list2->mValue; - - MOZ_ASSERT(val1.GetUnit() == val2.GetUnit(), - "unit match should be assured by AddWeighted"); - double diff; - switch (val1.GetUnit()) { - case eCSSUnit_Percent: - diff = val1.GetPercentValue() - val2.GetPercentValue(); - break; - case eCSSUnit_Number: - diff = val1.GetFloatValue() - val2.GetFloatValue(); - break; - default: - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - squareDistance += diff * diff; - - list1 = list1->mNext; - list2 = list2->mNext; - MOZ_ASSERT(!list1 == !list2, "lists should be same length"); - } - - aDistance = sqrt(squareDistance); - return true; - } - case eUnit_Shadow: { - // Call AddWeighted to make us lists of the same length. - StyleAnimationValue normValue1, normValue2; - if (!AddWeighted(aProperty, 1.0, aStartValue, 0.0, aEndValue, - normValue1) || - !AddWeighted(aProperty, 0.0, aStartValue, 1.0, aEndValue, - normValue2)) { - return false; - } - - const nsCSSValueList* shadow1 = normValue1.GetCSSValueListValue(); - const nsCSSValueList* shadow2 = normValue2.GetCSSValueListValue(); - - aDistance = 0.0; - MOZ_ASSERT(!shadow1 == !shadow2, "lists should be same length"); - while (shadow1) { - double squareDistance = 0.0; - if (!ComputeSingleShadowSquareDistance(shadow1, shadow2, - squareDistance, - aProperty)) { - NS_ERROR("Unexpected ComputeSingleShadowSquareDistance failure; " - "why didn't we fail earlier, in AddWeighted calls above?"); - } - aDistance += squareDistance; // cumulative distance^2; sqrt()'d below. - - shadow1 = shadow1->mNext; - shadow2 = shadow2->mNext; - MOZ_ASSERT(!shadow1 == !shadow2, "lists should be same length"); - } - aDistance = sqrt(aDistance); - return true; - } - case eUnit_Shape: - return ComputeShapeDistance(aProperty, - aStartValue.GetCSSValueArrayValue(), - aEndValue.GetCSSValueArrayValue(), - aDistance); - - case eUnit_Filter: - return ComputeFilterListDistance(aStartValue.GetCSSValueListValue(), - aEndValue.GetCSSValueListValue(), - aDistance); - - case eUnit_Transform: { - // FIXME: We don't have an official spec to define the distance of - // two transform lists, but paced spacing (defined in Web Animations API) - // needs this, so we implement this according to the concept of the - // interpolation of two transform lists. - // Issue: https://www.w3.org/TR/web-animations-1/#issue-789f9fd1 - - const nsCSSValueList* list1 = - aStartValue.GetCSSValueSharedListValue()->mHead; - const nsCSSValueList* list2 = - aEndValue.GetCSSValueSharedListValue()->mHead; - MOZ_ASSERT(list1); - MOZ_ASSERT(list2); - - if (list1->mValue.GetUnit() == eCSSUnit_None && - list2->mValue.GetUnit() == eCSSUnit_None) { - // Both none, nothing happens. - aDistance = 0.0; - } else if (list1->mValue.GetUnit() == eCSSUnit_None) { - nsAutoPtr none(AddTransformLists(0, list2, 0, list2)); - aDistance = ComputeTransformListDistance(none, list2); - } else if (list2->mValue.GetUnit() == eCSSUnit_None) { - nsAutoPtr none(AddTransformLists(0, list1, 0, list1)); - aDistance = ComputeTransformListDistance(list1, none); - } else if (TransformFunctionListsMatch(list1, list2)) { - aDistance = ComputeTransformListDistance(list1, list2); - } else { - aDistance = - ComputeMismatchedTransfromListDistance(list1, list2, aStyleContext); - } - return true; - } - case eUnit_BackgroundPositionCoord: { - const nsCSSValueList *position1 = aStartValue.GetCSSValueListValue(); - const nsCSSValueList *position2 = aEndValue.GetCSSValueListValue(); - - double squareDistance = 0.0; - MOZ_ASSERT(!position1 == !position2, "lists should be same length"); - - while (position1 && position2) { - squareDistance += CalcPositionCoordSquareDistance(position1->mValue, - position2->mValue); - position1 = position1->mNext; - position2 = position2->mNext; - } - // fail if lists differ in length. - if (position1 || position2) { - return false; - } - - aDistance = sqrt(squareDistance); - return true; - } - case eUnit_CSSValuePairList: { - const nsCSSValuePairList *list1 = aStartValue.GetCSSValuePairListValue(); - const nsCSSValuePairList *list2 = aEndValue.GetCSSValuePairListValue(); - double squareDistance = 0.0; - do { - static nsCSSValue nsCSSValuePairList::* const pairListValues[] = { - &nsCSSValuePairList::mXValue, - &nsCSSValuePairList::mYValue, - }; - for (uint32_t i = 0; i < ArrayLength(pairListValues); ++i) { - const nsCSSValue &v1 = list1->*(pairListValues[i]); - const nsCSSValue &v2 = list2->*(pairListValues[i]); - nsCSSUnit unit = - GetCommonUnit(aProperty, v1.GetUnit(), v2.GetUnit()); - if (unit == eCSSUnit_Null) { - return false; - } - double diffsquared = 0.0; - switch (unit) { - case eCSSUnit_Number: - case eCSSUnit_Pixel: { - float diff = v1.GetFloatValue() - v2.GetFloatValue(); - diffsquared = diff * diff; - break; - } - case eCSSUnit_Percent: { - float diff = v1.GetPercentValue() - v2.GetPercentValue(); - diffsquared = diff * diff; - break; - } - case eCSSUnit_Calc: { - PixelCalcValue val1 = ExtractCalcValue(v1); - PixelCalcValue val2 = ExtractCalcValue(v2); - float difflen = val2.mLength - val1.mLength; - float diffpct = val2.mPercent - val1.mPercent; - diffsquared = difflen * difflen + diffpct * diffpct; - break; - } - default: - if (v1 != v2) { - return false; - } - break; - } - squareDistance += diffsquared; - } - list1 = list1->mNext; - list2 = list2->mNext; - } while (list1 && list2); - if (list1 || list2) { - // We can't interpolate lists of different lengths. - return false; - } - aDistance = sqrt(squareDistance); - return true; - } - } - - MOZ_ASSERT(false, "Can't compute distance using the given common unit"); - return false; -} - -static inline void -AddCSSValueNumber(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult, uint32_t aValueRestrictions = 0) -{ - MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Number, "unexpected unit"); - MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Number, "unexpected unit"); - aResult.SetFloatValue(RestrictValue(aValueRestrictions, - aCoeff1 * aValue1.GetFloatValue() + - aCoeff2 * aValue2.GetFloatValue()), - eCSSUnit_Number); -} - -static inline float -GetNumberOrPercent(const nsCSSValue &aValue) -{ - nsCSSUnit unit = aValue.GetUnit(); - MOZ_ASSERT(unit == eCSSUnit_Number || unit == eCSSUnit_Percent, - "unexpected unit"); - return (unit == eCSSUnit_Number) ? - aValue.GetFloatValue() : aValue.GetPercentValue(); -} - -static inline void -AddCSSValuePercentNumber(const uint32_t aValueRestrictions, - double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult, float aInitialVal) -{ - float n1 = GetNumberOrPercent(aValue1); - float n2 = GetNumberOrPercent(aValue2); - - // Rather than interpolating aValue1 and aValue2 directly, we - // interpolate their *distances from aInitialVal* (the initial value, - // which is either 1 or 0 for "filter" functions). This matters in - // cases where aInitialVal is nonzero and the coefficients don't add - // up to 1. For example, if initialVal is 1, aCoeff1 is 0.5, and - // aCoeff2 is 0, then we'll return the value halfway between 1 and - // aValue1, rather than the value halfway between 0 and aValue1. - // Note that we do something similar in AddTransformScale(). - float result = (n1 - aInitialVal) * aCoeff1 + (n2 - aInitialVal) * aCoeff2; - aResult.SetFloatValue(RestrictValue(aValueRestrictions, result + aInitialVal), - eCSSUnit_Number); -} - -// Multiplies |aValue| color by |aDilutionRatio|. -static nscolor -DiluteColor(const RGBAColorData& aValue, double aDilutionRatio) -{ - float resultA = aValue.mA * aDilutionRatio; - return resultA <= 0.0 ? NS_RGBA(0, 0, 0, 0) - : aValue.WithAlpha(resultA).ToColor(); -} - -// Clamped AddWeightedColors. -static nscolor -AddWeightedColorsAndClamp(double aCoeff1, const RGBAColorData& aValue1, - double aCoeff2, const RGBAColorData& aValue2) -{ - // We are using AddWeighted() with a zero aCoeff2 for colors to - // pretend AddWeighted() against transparent color, i.e. rgba(0, 0, 0, 0). - // But unpremultiplication in AddWeightedColors() does not work well - // for such cases, so we use another function named DiluteColor() which - // has a similar logic to AddWeightedColors(). - return aCoeff2 == 0.0 - ? DiluteColor(aValue1, aCoeff1) - : AddWeightedColors(aCoeff1, aValue1, aCoeff2, aValue2).ToColor(); -} - -static void -AppendToCSSValueList(UniquePtr& aHead, - UniquePtr&& aValueToAppend, - nsCSSValueList** aTail) -{ - MOZ_ASSERT(!aHead == !*aTail, - "Can't have head w/o tail, & vice versa"); - - if (!aHead) { - aHead = Move(aValueToAppend); - *aTail = aHead.get(); - } else { - (*aTail) = (*aTail)->mNext = aValueToAppend.release(); - } -} - -static void -AppendToCSSValuePairList(UniquePtr& aHead, - UniquePtr&& aValueToAppend, - nsCSSValuePairList** aTail) -{ - MOZ_ASSERT(!aHead == !*aTail, - "Can't have head w/o tail, & vice versa"); - - if (!aHead) { - aHead = Move(aValueToAppend); - *aTail = aHead.get(); - } else { - (*aTail) = (*aTail)->mNext = aValueToAppend.release(); - } -} - -static UniquePtr -AddWeightedShadowItems(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - ColorAdditionType aColorAdditionType, - nsCSSPropertyID aProperty) -{ - // X, Y, Radius, Spread, Color, Inset - MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Array, - "wrong unit"); - MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Array, - "wrong unit"); - nsCSSValue::Array *array1 = aValue1.GetArrayValue(); - nsCSSValue::Array *array2 = aValue2.GetArrayValue(); - RefPtr resultArray = nsCSSValue::Array::Create(6); - - for (size_t i = 0; i < 4; ++i) { - // The text-shadow is not need to spread radius, - // So we skip this interpolation. - if (i == 3 && (aProperty != eCSSProperty_box_shadow)) continue; - AddCSSValuePixel(aCoeff1, array1->Item(i), aCoeff2, array2->Item(i), - resultArray->Item(i), - // blur radius must be nonnegative - (i == 2) ? CSS_PROPERTY_VALUE_NONNEGATIVE : 0); - } - - const nsCSSValue& colorValue1 = array1->Item(4); - const nsCSSValue& colorValue2 = array2->Item(4); - const nsCSSValue& inset1 = array1->Item(5); - const nsCSSValue& inset2 = array2->Item(5); - if ((colorValue1.GetUnit() != colorValue2.GetUnit() && - (!colorValue1.IsNumericColorUnit() || - !colorValue2.IsNumericColorUnit())) || - inset1.GetUnit() != inset2.GetUnit()) { - // We don't know how to animate between color and no-color, or - // between inset and not-inset. - // NOTE: In case when both colors' units are eCSSUnit_Null, that means - // neither color value was specified, so we can interpolate. - return nullptr; - } - - if (colorValue1.GetUnit() != eCSSUnit_Null) { - RGBAColorData color1 = ExtractColor(colorValue1); - RGBAColorData color2 = ExtractColor(colorValue2); - if (aColorAdditionType == ColorAdditionType::Clamped) { - resultArray->Item(4).SetColorValue( - AddWeightedColorsAndClamp(aCoeff1, color1, aCoeff2, color2)); - } else { - resultArray->Item(4).SetRGBAColorValue( - AddWeightedColors(aCoeff1, color1, aCoeff2, color2)); - } - } - - MOZ_ASSERT(inset1 == inset2, "should match"); - resultArray->Item(5) = inset1; - - auto resultItem = MakeUnique(); - resultItem->mValue.SetArrayValue(resultArray, eCSSUnit_Array); - return resultItem; -} - -static void -AddTransformScale(double aCoeff1, const nsCSSValue &aValue1, - double aCoeff2, const nsCSSValue &aValue2, - nsCSSValue &aResult) -{ - // Handle scale, and the two matrix components where identity is 1, by - // subtracting 1, multiplying by the coefficients, and then adding 1 - // back. This gets the right AddWeighted behavior and gets us the - // interpolation-against-identity behavior for free. - MOZ_ASSERT(aValue1.GetUnit() == eCSSUnit_Number, "unexpected unit"); - MOZ_ASSERT(aValue2.GetUnit() == eCSSUnit_Number, "unexpected unit"); - - float v1 = aValue1.GetFloatValue() - 1.0f, - v2 = aValue2.GetFloatValue() - 1.0f; - float result = v1 * aCoeff1 + v2 * aCoeff2; - aResult.SetFloatValue(EnsureNotNan(result + 1.0f), eCSSUnit_Number); -} - -static nsCSSValueList* -AddDifferentTransformLists(double aCoeff1, const nsCSSValueList* aList1, - double aCoeff2, const nsCSSValueList* aList2, - nsCSSKeyword aOperatorType) -{ - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - - RefPtr arr; - arr = AnimationValue::AppendTransformFunction(aOperatorType, resultTail); - - if (aCoeff1 == 0) { - // If the first coeffient is zero, we don't need to care about the first - // list at all. - arr->Item(1).Reset(); - } else if (aList1 == aList2) { - // If we have the same list, clear the first list, add the first coefficient - // into the second one so that we can simply multiply the second list by the - // second coefficient value. - arr->Item(1).Reset(); - aCoeff2 += aCoeff1; - } else { - MOZ_ASSERT((aOperatorType == eCSSKeyword_accumulatematrix && - aCoeff1 == 1.0) || - (aOperatorType == eCSSKeyword_interpolatematrix && - FuzzyEqualsAdditive(aCoeff1 + aCoeff2, 1.0)), - "|aCoeff1| should be 1.0 for accumulation, " - "|aCoeff1| + |aCoeff2| == 1.0 for interpolation"); - aList1->CloneInto(arr->Item(1).SetListValue()); - } - - aList2->CloneInto(arr->Item(2).SetListValue()); - arr->Item(3).SetPercentValue(aCoeff2); - - return result.forget(); -} - -static UniquePtr -AddWeightedFilterFunctionImpl(double aCoeff1, const nsCSSValueList* aList1, - double aCoeff2, const nsCSSValueList* aList2, - ColorAdditionType aColorAdditionType) -{ - // AddWeightedFilterFunction should be our only caller, and it should ensure - // that both args are non-null. - MOZ_ASSERT(aList1, "expected filter list"); - MOZ_ASSERT(aList2, "expected filter list"); - MOZ_ASSERT(aList1->mValue.GetUnit() == eCSSUnit_Function, - "expected function"); - MOZ_ASSERT(aList2->mValue.GetUnit() == eCSSUnit_Function, - "expected function"); - RefPtr a1 = aList1->mValue.GetArrayValue(), - a2 = aList2->mValue.GetArrayValue(); - nsCSSKeyword filterFunction = a1->Item(0).GetKeywordValue(); - if (filterFunction != a2->Item(0).GetKeywordValue()) { - return nullptr; // Can't add two filters of different types. - } - - auto resultList = MakeUnique(); - nsCSSValue::Array* result = - resultList->mValue.InitFunction(filterFunction, 1); - - // "hue-rotate" is the only filter-function that accepts negative values, and - // we don't use this "restrictions" variable in its clause below. - const uint32_t restrictions = CSS_PROPERTY_VALUE_NONNEGATIVE; - const nsCSSValue& funcArg1 = a1->Item(1); - const nsCSSValue& funcArg2 = a2->Item(1); - nsCSSValue& resultArg = result->Item(1); - float initialVal = 1.0f; - switch (filterFunction) { - case eCSSKeyword_blur: { - nsCSSUnit unit; - if (funcArg1.GetUnit() == funcArg2.GetUnit()) { - unit = funcArg1.GetUnit(); - } else { - // If units differ, we'll just combine them with calc(). - unit = eCSSUnit_Calc; - } - if (!AddCSSValuePixelPercentCalc(restrictions, - unit, - aCoeff1, funcArg1, - aCoeff2, funcArg2, - resultArg)) { - return nullptr; - } - break; - } - case eCSSKeyword_grayscale: - case eCSSKeyword_invert: - case eCSSKeyword_sepia: - initialVal = 0.0f; - MOZ_FALLTHROUGH; - case eCSSKeyword_brightness: - case eCSSKeyword_contrast: - case eCSSKeyword_opacity: - case eCSSKeyword_saturate: - AddCSSValuePercentNumber(restrictions, - aCoeff1, funcArg1, - aCoeff2, funcArg2, - resultArg, - initialVal); - break; - case eCSSKeyword_hue_rotate: - AddCSSValueAngle(aCoeff1, funcArg1, - aCoeff2, funcArg2, - resultArg); - break; - case eCSSKeyword_drop_shadow: { - MOZ_ASSERT(!funcArg1.GetListValue()->mNext && - !funcArg2.GetListValue()->mNext, - "drop-shadow filter func doesn't support lists"); - UniquePtr shadowValue = - AddWeightedShadowItems(aCoeff1, - funcArg1.GetListValue()->mValue, - aCoeff2, - funcArg2.GetListValue()->mValue, - aColorAdditionType, - eCSSProperty_filter); - if (!shadowValue) { - return nullptr; - } - resultArg.AdoptListValue(Move(shadowValue)); - break; - } - default: - MOZ_ASSERT(false, "unknown filter function"); - return nullptr; - } - - return resultList; -} - -static UniquePtr -AddWeightedFilterFunction(double aCoeff1, const nsCSSValueList* aList1, - double aCoeff2, const nsCSSValueList* aList2, - ColorAdditionType aColorAdditionType) -{ - MOZ_ASSERT(aList1 || aList2, - "one function list item must not be null"); - // Note that one of our arguments could be null, indicating that - // it's the initial value. Rather than adding special null-handling - // logic, we just check for null values and replace them with - // 0 * the other value. That way, AddWeightedFilterFunctionImpl can assume - // its args are non-null. - if (!aList1) { - return AddWeightedFilterFunctionImpl(aCoeff2, aList2, 0, aList2, - aColorAdditionType); - } - if (!aList2) { - return AddWeightedFilterFunctionImpl(aCoeff1, aList1, 0, aList1, - aColorAdditionType); - } - - return AddWeightedFilterFunctionImpl(aCoeff1, aList1, aCoeff2, aList2, - aColorAdditionType); -} - -static inline uint32_t -ShapeArgumentCount(nsCSSKeyword aShapeFunction) -{ - switch (aShapeFunction) { - case eCSSKeyword_circle: - return 2; // radius and center point - case eCSSKeyword_polygon: - return 2; // fill rule and a list of points - case eCSSKeyword_ellipse: - return 3; // two radii and center point - case eCSSKeyword_inset: - return 5; // four edge offsets and a list of corner radii - default: - MOZ_ASSERT_UNREACHABLE("Unknown shape type"); - return 0; - } -} - -static void -AddPositions(double aCoeff1, const nsCSSValue& aPos1, - double aCoeff2, const nsCSSValue& aPos2, - nsCSSValue& aResultPos) -{ - MOZ_ASSERT(aPos1.GetUnit() == eCSSUnit_Array && - aPos2.GetUnit() == eCSSUnit_Array, - "Args should be CSS s, encoded as arrays"); - - const nsCSSValue::Array* posArray1 = aPos1.GetArrayValue(); - const nsCSSValue::Array* posArray2 = aPos2.GetArrayValue(); - MOZ_ASSERT(posArray1->Count() == 4 && posArray2->Count() == 4, - "CSSParserImpl::ParsePositionValue creates an array of length " - "4 - how did we get here?"); - - nsCSSValue::Array* resultPosArray = nsCSSValue::Array::Create(4); - aResultPos.SetArrayValue(resultPosArray, eCSSUnit_Array); - - // Only iterate over elements 1 and 3. The is 'uncomputed' to - // only those elements. See also the comment in SetPositionValue. - for (size_t i = 1; i < 4; i += 2) { - const nsCSSValue& v1 = posArray1->Item(i); - const nsCSSValue& v2 = posArray2->Item(i); - nsCSSValue& vr = resultPosArray->Item(i); - AddCSSValueCanonicalCalc(aCoeff1, v1, - aCoeff2, v2, vr); - } -} - -static Maybe -AddCSSValuePair(nsCSSPropertyID aProperty, uint32_t aRestrictions, - double aCoeff1, const nsCSSValuePair* aPair1, - double aCoeff2, const nsCSSValuePair* aPair2) -{ - MOZ_ASSERT(aPair1, "expected pair"); - MOZ_ASSERT(aPair2, "expected pair"); - - Maybe result; - nsCSSUnit unit[2]; - unit[0] = GetCommonUnit(aProperty, aPair1->mXValue.GetUnit(), - aPair2->mXValue.GetUnit()); - unit[1] = GetCommonUnit(aProperty, aPair1->mYValue.GetUnit(), - aPair2->mYValue.GetUnit()); - if (unit[0] == eCSSUnit_Null || unit[1] == eCSSUnit_Null || - unit[0] == eCSSUnit_URL || unit[0] == eCSSUnit_Enumerated) { - return result; // Nothing() (returning |result| for RVO) - } - - result.emplace(); - - static nsCSSValue nsCSSValuePair::* const pairValues[2] = { - &nsCSSValuePair::mXValue, &nsCSSValuePair::mYValue - }; - for (uint32_t i = 0; i < 2; ++i) { - nsCSSValue nsCSSValuePair::*member = pairValues[i]; - if (!AddCSSValuePixelPercentCalc(aRestrictions, unit[i], - aCoeff1, aPair1->*member, - aCoeff2, aPair2->*member, - result.ref().*member) ) { - MOZ_ASSERT(false, "unexpected unit"); - result.reset(); - return result; // Nothing() (returning |result| for RVO) - } - } - - return result; -} - -static UniquePtr -AddCSSValuePairList(nsCSSPropertyID aProperty, - double aCoeff1, const nsCSSValuePairList* aList1, - double aCoeff2, const nsCSSValuePairList* aList2) -{ - MOZ_ASSERT(aList1, "Can't add a null list"); - MOZ_ASSERT(aList2, "Can't add a null list"); - - auto result = MakeUnique(); - nsCSSValuePairList* resultPtr = result.get(); - - do { - static nsCSSValue nsCSSValuePairList::* const pairListValues[] = { - &nsCSSValuePairList::mXValue, - &nsCSSValuePairList::mYValue, - }; - uint32_t restrictions = nsCSSProps::ValueRestrictions(aProperty); - for (uint32_t i = 0; i < ArrayLength(pairListValues); ++i) { - const nsCSSValue& v1 = aList1->*(pairListValues[i]); - const nsCSSValue& v2 = aList2->*(pairListValues[i]); - - nsCSSValue& vr = resultPtr->*(pairListValues[i]); - nsCSSUnit unit = - GetCommonUnit(aProperty, v1.GetUnit(), v2.GetUnit()); - if (unit == eCSSUnit_Null) { - return nullptr; - } - if (unit == eCSSUnit_Number) { - AddCSSValueNumber(aCoeff1, v1, - aCoeff2, v2, - vr, restrictions); - } else if (!AddCSSValuePixelPercentCalc(restrictions, unit, - aCoeff1, v1, - aCoeff2, v2, vr)) { - if (v1 != v2) { - return nullptr; - } - vr = v1; - } - } - aList1 = aList1->mNext; - aList2 = aList2->mNext; - if (!aList1 || !aList2) { - break; - } - resultPtr->mNext = new nsCSSValuePairList; - resultPtr = resultPtr->mNext; - } while (aList1 && aList2); - - if (aList1 || aList2) { - return nullptr; // We can't interpolate lists of different lengths - } - - return result; -} - -static already_AddRefed -AddShapeFunction(nsCSSPropertyID aProperty, - double aCoeff1, const nsCSSValue::Array* aArray1, - double aCoeff2, const nsCSSValue::Array* aArray2, - Restrictions aRestriction) -{ - MOZ_ASSERT(aArray1 && aArray1->Count() == 2, "expected shape function"); - MOZ_ASSERT(aArray2 && aArray2->Count() == 2, "expected shape function"); - MOZ_ASSERT(aArray1->Item(0).GetUnit() == eCSSUnit_Function, - "expected function"); - MOZ_ASSERT(aArray2->Item(0).GetUnit() == eCSSUnit_Function, - "expected function"); - MOZ_ASSERT(aArray1->Item(1).GetUnit() == eCSSUnit_Enumerated, - "expected geometry-box"); - MOZ_ASSERT(aArray2->Item(1).GetUnit() == eCSSUnit_Enumerated, - "expected geometry-box"); - - if (aArray1->Item(1).GetIntValue() != aArray2->Item(1).GetIntValue()) { - return nullptr; // Both shapes must use the same reference box. - } - - const nsCSSValue::Array* func1 = aArray1->Item(0).GetArrayValue(); - const nsCSSValue::Array* func2 = aArray2->Item(0).GetArrayValue(); - nsCSSKeyword shapeFuncName = func1->Item(0).GetKeywordValue(); - if (shapeFuncName != func2->Item(0).GetKeywordValue()) { - return nullptr; // Can't add two shapes of different types. - } - - RefPtr result = nsCSSValue::Array::Create(2); - - nsCSSValue::Array* resultFuncArgs = - result->Item(0).InitFunction(shapeFuncName, - ShapeArgumentCount(shapeFuncName)); - switch (shapeFuncName) { - case eCSSKeyword_ellipse: - // Add ellipses' |ry| values (but fail if we encounter an enum): - if (!AddCSSValuePixelPercentCalc(aRestriction == Restrictions::Enable - ? CSS_PROPERTY_VALUE_NONNEGATIVE - : 0, - GetCommonUnit(aProperty, - func1->Item(2).GetUnit(), - func2->Item(2).GetUnit()), - aCoeff1, func1->Item(2), - aCoeff2, func2->Item(2), - resultFuncArgs->Item(2))) { - return nullptr; - } - MOZ_FALLTHROUGH; // to handle rx and center point - case eCSSKeyword_circle: { - // Add circles' |r| (or ellipses' |rx|) values: - if (!AddCSSValuePixelPercentCalc(aRestriction == Restrictions::Enable - ? CSS_PROPERTY_VALUE_NONNEGATIVE - : 0, - GetCommonUnit(aProperty, - func1->Item(1).GetUnit(), - func2->Item(1).GetUnit()), - aCoeff1, func1->Item(1), - aCoeff2, func2->Item(1), - resultFuncArgs->Item(1))) { - return nullptr; - } - // Add center points (defined as a ). - size_t posIndex = shapeFuncName == eCSSKeyword_circle ? 2 : 3; - AddPositions(aCoeff1, func1->Item(posIndex), - aCoeff2, func2->Item(posIndex), - resultFuncArgs->Item(posIndex)); - break; - } - case eCSSKeyword_polygon: { - // Add polygons' corresponding points (if the fill rule matches): - int32_t fillRule = func1->Item(1).GetIntValue(); - if (fillRule != func2->Item(1).GetIntValue()) { - return nullptr; // can't interpolate between different fill rules - } - resultFuncArgs->Item(1).SetIntValue(fillRule, eCSSUnit_Enumerated); - - const nsCSSValuePairList* points1 = func1->Item(2).GetPairListValue(); - const nsCSSValuePairList* points2 = func2->Item(2).GetPairListValue(); - UniquePtr resultPoints = - AddCSSValuePairList(aProperty, aCoeff1, points1, aCoeff2, points2); - if (!resultPoints) { - return nullptr; - } - resultFuncArgs->Item(2).AdoptPairListValue(Move(resultPoints)); - break; - } - case eCSSKeyword_inset: { - MOZ_ASSERT(func1->Count() == 6 && func2->Count() == 6, - "Update for CSSParserImpl::ParseInsetFunction changes"); - // Items 1-4 are respectively the top, right, bottom and left offsets - // from the reference box. - for (size_t i = 1; i <= 4; ++i) { - if (!AddCSSValuePixelPercentCalc(aRestriction == Restrictions::Enable - ? CSS_PROPERTY_VALUE_NONNEGATIVE - : 0, - GetCommonUnit(aProperty, - func1->Item(i).GetUnit(), - func2->Item(i).GetUnit()), - aCoeff1, func1->Item(i), - aCoeff2, func2->Item(i), - resultFuncArgs->Item(i))) { - return nullptr; - } - } - // Item 5 contains the radii of the rounded corners for the inset - // rectangle. - MOZ_ASSERT(func1->Item(5).GetUnit() == eCSSUnit_Array && - func2->Item(5).GetUnit() == eCSSUnit_Array, - "Expected two arrays"); - const nsCSSValue::Array* radii1 = func1->Item(5).GetArrayValue(); - const nsCSSValue::Array* radii2 = func2->Item(5).GetArrayValue(); - MOZ_ASSERT(radii1->Count() == 4 && radii2->Count() == 4); - nsCSSValue::Array* resultRadii = nsCSSValue::Array::Create(4); - resultFuncArgs->Item(5).SetArrayValue(resultRadii, eCSSUnit_Array); - // We use an arbitrary border-radius property here to get the appropriate - // restrictions for radii since this is a value. - uint32_t restrictions = - aRestriction == Restrictions::Enable - ? nsCSSProps::ValueRestrictions(eCSSProperty_border_top_left_radius) - : 0; - for (size_t i = 0; i < 4; ++i) { - const nsCSSValuePair& pair1 = radii1->Item(i).GetPairValue(); - const nsCSSValuePair& pair2 = radii2->Item(i).GetPairValue(); - const Maybe pairResult = - AddCSSValuePair(aProperty, restrictions, - aCoeff1, &pair1, - aCoeff2, &pair2); - if (!pairResult) { - return nullptr; - } - resultRadii->Item(i).SetPairValue(pairResult.ptr()); - } - break; - } - default: - MOZ_ASSERT_UNREACHABLE("Unknown shape type"); - return nullptr; - } - - // set the geometry-box value - result->Item(1).SetIntValue(aArray1->Item(1).GetIntValue(), - eCSSUnit_Enumerated); - - return result.forget(); -} - -static nsCSSValueList* -AddTransformLists(double aCoeff1, const nsCSSValueList* aList1, - double aCoeff2, const nsCSSValueList* aList2, - nsCSSKeyword aOperatorType) -{ - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - - do { - RefPtr a1 = ToPrimitive(aList1->mValue.GetArrayValue()), - a2 = ToPrimitive(aList2->mValue.GetArrayValue()); - MOZ_ASSERT( - TransformFunctionsMatch(nsStyleTransformMatrix::TransformFunctionOf(a1), - nsStyleTransformMatrix::TransformFunctionOf(a2)), - "transform function mismatch"); - MOZ_ASSERT(!*resultTail, - "resultTail isn't pointing to the tail (may leak)"); - - nsCSSKeyword tfunc = nsStyleTransformMatrix::TransformFunctionOf(a1); - RefPtr arr; - if (tfunc != eCSSKeyword_matrix && - tfunc != eCSSKeyword_matrix3d && - tfunc != eCSSKeyword_interpolatematrix && - tfunc != eCSSKeyword_rotate3d && - tfunc != eCSSKeyword_perspective) { - arr = AnimationValue::AppendTransformFunction(tfunc, resultTail); - } - - switch (tfunc) { - case eCSSKeyword_translate3d: { - MOZ_ASSERT(a1->Count() == 4, "unexpected count"); - MOZ_ASSERT(a2->Count() == 4, "unexpected count"); - AddTransformTranslate(aCoeff1, a1->Item(1), aCoeff2, a2->Item(1), - arr->Item(1)); - AddTransformTranslate(aCoeff1, a1->Item(2), aCoeff2, a2->Item(2), - arr->Item(2)); - AddTransformTranslate(aCoeff1, a1->Item(3), aCoeff2, a2->Item(3), - arr->Item(3)); - break; - } - case eCSSKeyword_scale3d: { - MOZ_ASSERT(a1->Count() == 4, "unexpected count"); - MOZ_ASSERT(a2->Count() == 4, "unexpected count"); - - AddTransformScale(aCoeff1, a1->Item(1), aCoeff2, a2->Item(1), - arr->Item(1)); - AddTransformScale(aCoeff1, a1->Item(2), aCoeff2, a2->Item(2), - arr->Item(2)); - AddTransformScale(aCoeff1, a1->Item(3), aCoeff2, a2->Item(3), - arr->Item(3)); - - break; - } - // It would probably be nicer to animate skew in tangent space - // rather than angle space. However, it's easy to specify - // skews with infinite tangents, and behavior changes pretty - // drastically when crossing such skews (since the direction of - // animation flips), so interop is probably more important here. - case eCSSKeyword_skew: { - MOZ_ASSERT(a1->Count() == 2 || a1->Count() == 3, - "unexpected count"); - MOZ_ASSERT(a2->Count() == 2 || a2->Count() == 3, - "unexpected count"); - - nsCSSValue zero(0.0f, eCSSUnit_Radian); - // Add Y component of skew. - AddCSSValueAngle(aCoeff1, - a1->Count() == 3 ? a1->Item(2) : zero, - aCoeff2, - a2->Count() == 3 ? a2->Item(2) : zero, - arr->Item(2)); - - // Add X component of skew (which can be merged with case below - // in non-DEBUG). - AddCSSValueAngle(aCoeff1, a1->Item(1), aCoeff2, a2->Item(1), - arr->Item(1)); - - break; - } - case eCSSKeyword_skewx: - case eCSSKeyword_skewy: - case eCSSKeyword_rotate: - case eCSSKeyword_rotatex: - case eCSSKeyword_rotatey: - case eCSSKeyword_rotatez: { - MOZ_ASSERT(a1->Count() == 2, "unexpected count"); - MOZ_ASSERT(a2->Count() == 2, "unexpected count"); - - AddCSSValueAngle(aCoeff1, a1->Item(1), aCoeff2, a2->Item(1), - arr->Item(1)); - - break; - } - case eCSSKeyword_rotate3d: { - Point3D vector1(a1->Item(1).GetFloatValue(), - a1->Item(2).GetFloatValue(), - a1->Item(3).GetFloatValue()); - vector1.Normalize(); - Point3D vector2(a2->Item(1).GetFloatValue(), - a2->Item(2).GetFloatValue(), - a2->Item(3).GetFloatValue()); - vector2.Normalize(); - - // Handle rotate3d with matched (normalized) vectors, - // otherwise fallthrough to the next switch statement - // and do matrix decomposition. - if (vector1 == vector2) { - // We skipped appending a transform function above for rotate3d, - // so do it now. - arr = AnimationValue::AppendTransformFunction(tfunc, resultTail); - arr->Item(1).SetFloatValue(vector1.x, eCSSUnit_Number); - arr->Item(2).SetFloatValue(vector1.y, eCSSUnit_Number); - arr->Item(3).SetFloatValue(vector1.z, eCSSUnit_Number); - - AddCSSValueAngle(aCoeff1, a1->Item(4), aCoeff2, a2->Item(4), - arr->Item(4)); - break; - } - MOZ_FALLTHROUGH; - } - case eCSSKeyword_matrix: - case eCSSKeyword_matrix3d: - case eCSSKeyword_perspective: - if (aCoeff1 == 0.0 && aCoeff2 == 0.0) { - // Special case. If both coefficients are 0.0, we should apply an - // identity transform function. - arr = AnimationValue::AppendTransformFunction(tfunc, resultTail); - - if (tfunc == eCSSKeyword_rotate3d) { - arr->Item(1).SetFloatValue(0.0, eCSSUnit_Number); - arr->Item(2).SetFloatValue(0.0, eCSSUnit_Number); - arr->Item(3).SetFloatValue(1.0, eCSSUnit_Number); - arr->Item(4).SetFloatValue(0.0, eCSSUnit_Radian); - } else if (tfunc == eCSSKeyword_perspective) { - // The parameter of the identity perspective function is - // positive infinite. - arr->Item(1).SetFloatValue(std::numeric_limits::infinity(), - eCSSUnit_Pixel); - } else { - nsStyleTransformMatrix::SetIdentityMatrix(arr); - } - break; - } - MOZ_FALLTHROUGH; - case eCSSKeyword_interpolatematrix: { - // FIXME: If the matrix contains only numbers then we could decompose - // here. - - // Construct temporary lists with only this item in them. - nsCSSValueList tempList1, tempList2; - tempList1.mValue = aList1->mValue; - tempList2.mValue = aList2->mValue; - - if (aList1 == aList2) { - *resultTail = - AddDifferentTransformLists(aCoeff1, &tempList1, - aCoeff2, &tempList1, - aOperatorType); - } else { - *resultTail = - AddDifferentTransformLists(aCoeff1, &tempList1, - aCoeff2, &tempList2, - aOperatorType); - } - - // Now advance resultTail to point to the new tail slot. - while (*resultTail) { - resultTail = &(*resultTail)->mNext; - } - - break; - } - default: - MOZ_ASSERT_UNREACHABLE( - "unknown transform function or accumulatematrix"); - } - - aList1 = aList1->mNext; - aList2 = aList2->mNext; - } while (aList1); - MOZ_ASSERT(!aList2, "list length mismatch"); - MOZ_ASSERT(!*resultTail, - "resultTail isn't pointing to the tail"); - - return result.forget(); -} - -static void -AddPositionCoords(double aCoeff1, const nsCSSValue& aPos1, - double aCoeff2, const nsCSSValue& aPos2, - nsCSSValue& aResultPos) -{ - const nsCSSValue::Array* posArray1 = aPos1.GetArrayValue(); - const nsCSSValue::Array* posArray2 = aPos2.GetArrayValue(); - nsCSSValue::Array* resultPosArray = nsCSSValue::Array::Create(2); - aResultPos.SetArrayValue(resultPosArray, eCSSUnit_Array); - - /* Only compute element 1. The is - * 'uncomputed' to only that element. - */ - const nsCSSValue& v1 = posArray1->Item(1); - const nsCSSValue& v2 = posArray2->Item(1); - nsCSSValue& vr = resultPosArray->Item(1); - AddCSSValueCanonicalCalc(aCoeff1, v1, - aCoeff2, v2, vr); -} - -static UniquePtr -AddWeightedShadowList(double aCoeff1, - const nsCSSValueList* aShadow1, - double aCoeff2, - const nsCSSValueList* aShadow2, - ColorAdditionType aColorAdditionType, - nsCSSPropertyID aProperty) -{ - // This is implemented according to: - // http://dev.w3.org/csswg/css3-transitions/#animation-of-property-types- - // and the third item in the summary of: - // http://lists.w3.org/Archives/Public/www-style/2009Jul/0050.html - UniquePtr result; - nsCSSValueList* tail = nullptr; - while (aShadow1 && aShadow2) { - UniquePtr shadowValue = - AddWeightedShadowItems(aCoeff1, aShadow1->mValue, - aCoeff2, aShadow2->mValue, - aColorAdditionType, - aProperty); - if (!shadowValue) { - return nullptr; - } - aShadow1 = aShadow1->mNext; - aShadow2 = aShadow2->mNext; - AppendToCSSValueList(result, Move(shadowValue), &tail); - } - if (aShadow1 || aShadow2) { - const nsCSSValueList *longShadow; - double longCoeff; - if (aShadow1) { - longShadow = aShadow1; - longCoeff = aCoeff1; - } else { - longShadow = aShadow2; - longCoeff = aCoeff2; - } - - while (longShadow) { - // Passing coefficients that add to less than 1 produces the - // desired result of interpolating "0 0 0 transparent" with - // the current shadow. - UniquePtr shadowValue = - AddWeightedShadowItems(longCoeff, longShadow->mValue, - 0.0, longShadow->mValue, - aColorAdditionType, aProperty); - if (!shadowValue) { - return nullptr; - } - - longShadow = longShadow->mNext; - AppendToCSSValueList(result, Move(shadowValue), &tail); - } - } - return result; -} - -static UniquePtr -AddWeightedFilterList(double aCoeff1, const nsCSSValueList* aList1, - double aCoeff2, const nsCSSValueList* aList2, - ColorAdditionType aColorAdditionType) -{ - UniquePtr result; - nsCSSValueList* tail = nullptr; - while (aList1 || aList2) { - if ((aList1 && aList1->mValue.GetUnit() != eCSSUnit_Function) || - (aList2 && aList2->mValue.GetUnit() != eCSSUnit_Function)) { - // If we don't have filter-functions, we must have filter-URLs, which - // we can't add or interpolate. - return nullptr; - } - - UniquePtr resultFunction = - AddWeightedFilterFunction(aCoeff1, aList1, aCoeff2, aList2, - aColorAdditionType); - if (!resultFunction) { - // filter function mismatch - return nullptr; - } - - AppendToCSSValueList(result, Move(resultFunction), &tail); - - // move to next aList items - if (aList1) { - aList1 = aList1->mNext; - } - if (aList2) { - aList2 = aList2->mNext; - } - } - - return result; -} - -bool -StyleAnimationValue::AddWeighted(nsCSSPropertyID aProperty, - double aCoeff1, - const StyleAnimationValue& aValue1, - double aCoeff2, - const StyleAnimationValue& aValue2, - StyleAnimationValue& aResultValue) -{ - Unit commonUnit = - GetCommonUnit(aProperty, aValue1.GetUnit(), aValue2.GetUnit()); - // Maybe need a followup method to convert the inputs into the common - // unit-type, if they don't already match it. (Or would it make sense to do - // that in GetCommonUnit? in which case maybe ConvertToCommonUnit would be - // better.) - - switch (commonUnit) { - case eUnit_Null: - case eUnit_Auto: - case eUnit_None: - case eUnit_Normal: - case eUnit_UnparsedString: - case eUnit_URL: - case eUnit_DiscreteCSSValue: - return false; - - case eUnit_Enumerated: - switch (aProperty) { - case eCSSProperty_font_stretch: { - // https://drafts.csswg.org/css-fonts-3/#font-stretch-animation - double interpolatedValue = aCoeff1 * double(aValue1.GetIntValue()) + - aCoeff2 * double(aValue2.GetIntValue()); - int32_t result = floor(interpolatedValue + 0.5); - if (result < NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED) { - result = NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED; - } else if (result > NS_STYLE_FONT_STRETCH_ULTRA_EXPANDED) { - result = NS_STYLE_FONT_STRETCH_ULTRA_EXPANDED; - } - aResultValue.SetIntValue(result, eUnit_Enumerated); - return true; - } - default: - return false; - } - case eUnit_Visibility: { - int32_t enum1 = aValue1.GetIntValue(); - int32_t enum2 = aValue2.GetIntValue(); - if (enum1 == enum2) { - aResultValue.SetIntValue(enum1, eUnit_Visibility); - return true; - } - if ((enum1 == NS_STYLE_VISIBILITY_VISIBLE) == - (enum2 == NS_STYLE_VISIBILITY_VISIBLE)) { - return false; - } - int32_t val1 = enum1 == NS_STYLE_VISIBILITY_VISIBLE; - int32_t val2 = enum2 == NS_STYLE_VISIBILITY_VISIBLE; - double interp = aCoeff1 * val1 + aCoeff2 * val2; - int32_t result = interp > 0.0 ? NS_STYLE_VISIBILITY_VISIBLE - : (val1 ? enum2 : enum1); - aResultValue.SetIntValue(result, eUnit_Visibility); - return true; - } - case eUnit_Integer: { - // https://drafts.csswg.org/css-transitions/#animtype-integer - double interpolatedValue = aCoeff1 * double(aValue1.GetIntValue()) + - aCoeff2 * double(aValue2.GetIntValue()); - int32_t result = floor(interpolatedValue + 0.5); - if (aProperty == eCSSProperty_font_weight) { - // https://drafts.csswg.org/css-transitions/#animtype-font-weight - result += 50; - result -= result % 100; - result = Clamp(result, 100, 900); - } else { - result = RestrictValue(aProperty, result); - } - aResultValue.SetIntValue(result, eUnit_Integer); - return true; - } - case eUnit_Coord: { - aResultValue.SetCoordValue(RestrictValue(aProperty, NSToCoordRound( - aCoeff1 * aValue1.GetCoordValue() + - aCoeff2 * aValue2.GetCoordValue()))); - return true; - } - case eUnit_Percent: { - aResultValue.SetPercentValue(RestrictValue(aProperty, - aCoeff1 * aValue1.GetPercentValue() + - aCoeff2 * aValue2.GetPercentValue())); - return true; - } - case eUnit_Float: { - aResultValue.SetFloatValue(RestrictValue(aProperty, - aCoeff1 * aValue1.GetFloatValue() + - aCoeff2 * aValue2.GetFloatValue())); - return true; - } - case eUnit_Color: { - RGBAColorData color1 = ExtractColor(aValue1); - RGBAColorData color2 = ExtractColor(aValue2); - auto resultColor = MakeUnique(); - resultColor->SetColorValue( - AddWeightedColorsAndClamp(aCoeff1, color1, aCoeff2, color2)); - aResultValue.SetAndAdoptCSSValueValue(resultColor.release(), eUnit_Color); - return true; - } - case eUnit_CurrentColor: { - aResultValue.SetCurrentColorValue(); - return true; - } - case eUnit_ComplexColor: { - ComplexColorData color1 = ExtractComplexColor(aValue1); - ComplexColorData color2 = ExtractComplexColor(aValue2); - RefPtr result = new ComplexColorValue; - // Common case is interpolating between a color and a currentcolor. - if (color1.IsNumericColor() && color2.IsCurrentColor()) { - result->mColor = color1.mColor; - result->mForegroundRatio = aCoeff2; - } else if (color1.IsCurrentColor() && color2.IsNumericColor()) { - result->mColor = color2.mColor; - result->mForegroundRatio = aCoeff1; - } else { - float ratio1 = 1.0f - color1.mForegroundRatio; - float ratio2 = 1.0f - color2.mForegroundRatio; - float alpha1 = color1.mColor.mA * ratio1; - float alpha2 = color2.mColor.mA * ratio2; - RGBAColorData resultColor = - AddWeightedColors(aCoeff1, color1.mColor.WithAlpha(alpha1), - aCoeff2, color2.mColor.WithAlpha(alpha2)); - float resultRatio = color1.mForegroundRatio * aCoeff1 + - color2.mForegroundRatio * aCoeff2; - float resultAlpha = resultColor.mA / (1.0f - resultRatio); - result->mColor = resultColor.WithAlpha(resultAlpha); - result->mForegroundRatio = resultRatio; - } - aResultValue.SetComplexColorValue(result.forget()); - return true; - } - case eUnit_Calc: { - PixelCalcValue v1 = ExtractCalcValue(aValue1); - PixelCalcValue v2 = ExtractCalcValue(aValue2); - double len = aCoeff1 * v1.mLength + aCoeff2 * v2.mLength; - double pct = aCoeff1 * v1.mPercent + aCoeff2 * v2.mPercent; - bool hasPct = (aCoeff1 != 0.0 && v1.mHasPercent) || - (aCoeff2 != 0.0 && v2.mHasPercent); - nsCSSValue *val = new nsCSSValue(); - nsCSSValue::Array *arr = nsCSSValue::Array::Create(1); - val->SetArrayValue(arr, eCSSUnit_Calc); - if (hasPct) { - nsCSSValue::Array *arr2 = nsCSSValue::Array::Create(2); - arr2->Item(0).SetFloatValue(len, eCSSUnit_Pixel); - arr2->Item(1).SetPercentValue(pct); - arr->Item(0).SetArrayValue(arr2, eCSSUnit_Calc_Plus); - } else { - arr->Item(0).SetFloatValue(len, eCSSUnit_Pixel); - } - aResultValue.SetAndAdoptCSSValueValue(val, eUnit_Calc); - return true; - } - case eUnit_ObjectPosition: { - const nsCSSValue* position1 = aValue1.GetCSSValueValue(); - const nsCSSValue* position2 = aValue2.GetCSSValueValue(); - - nsAutoPtr result(new nsCSSValue); - AddPositions(aCoeff1, *position1, - aCoeff2, *position2, *result); - - aResultValue.SetAndAdoptCSSValueValue(result.forget(), - eUnit_ObjectPosition); - return true; - } - case eUnit_CSSValuePair: { - uint32_t restrictions = nsCSSProps::ValueRestrictions(aProperty); - Maybe result = - AddCSSValuePair(aProperty, restrictions, - aCoeff1, aValue1.GetCSSValuePairValue(), - aCoeff2, aValue2.GetCSSValuePairValue()); - if (!result) { - return false; - } - - // We need a heap allocated object to adopt here: - auto heapResult = MakeUnique(*result); - aResultValue.SetAndAdoptCSSValuePairValue(heapResult.release(), - eUnit_CSSValuePair); - return true; - } - case eUnit_CSSValueTriplet: { - nsCSSValueTriplet triplet1(*aValue1.GetCSSValueTripletValue()); - nsCSSValueTriplet triplet2(*aValue2.GetCSSValueTripletValue()); - - nsCSSUnit unit[3]; - unit[0] = GetCommonUnit(aProperty, triplet1.mXValue.GetUnit(), - triplet2.mXValue.GetUnit()); - unit[1] = GetCommonUnit(aProperty, triplet1.mYValue.GetUnit(), - triplet2.mYValue.GetUnit()); - unit[2] = GetCommonUnit(aProperty, triplet1.mZValue.GetUnit(), - triplet2.mZValue.GetUnit()); - if (unit[0] == eCSSUnit_Null || unit[1] == eCSSUnit_Null || - unit[2] == eCSSUnit_Null) { - return false; - } - - nsAutoPtr result(new nsCSSValueTriplet); - static nsCSSValue nsCSSValueTriplet::* const tripletValues[3] = { - &nsCSSValueTriplet::mXValue, &nsCSSValueTriplet::mYValue, &nsCSSValueTriplet::mZValue - }; - uint32_t restrictions = nsCSSProps::ValueRestrictions(aProperty); - for (uint32_t i = 0; i < 3; ++i) { - nsCSSValue nsCSSValueTriplet::*member = tripletValues[i]; - if (!AddCSSValuePixelPercentCalc(restrictions, unit[i], - aCoeff1, &triplet1->*member, - aCoeff2, &triplet2->*member, - result->*member) ) { - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - } - - aResultValue.SetAndAdoptCSSValueTripletValue(result.forget(), - eUnit_CSSValueTriplet); - return true; - } - case eUnit_CSSRect: { - MOZ_ASSERT(nsCSSProps::ValueRestrictions(aProperty) == 0, - "must add code for handling value restrictions"); - const nsCSSRect *rect1 = aValue1.GetCSSRectValue(); - const nsCSSRect *rect2 = aValue2.GetCSSRectValue(); - if (rect1->mTop.GetUnit() != rect2->mTop.GetUnit() || - rect1->mRight.GetUnit() != rect2->mRight.GetUnit() || - rect1->mBottom.GetUnit() != rect2->mBottom.GetUnit() || - rect1->mLeft.GetUnit() != rect2->mLeft.GetUnit()) { - // At least until we have calc() - return false; - } - - nsAutoPtr result(new nsCSSRect); - for (uint32_t i = 0; i < ArrayLength(nsCSSRect::sides); ++i) { - nsCSSValue nsCSSRect::*member = nsCSSRect::sides[i]; - MOZ_ASSERT((rect1->*member).GetUnit() == (rect2->*member).GetUnit(), - "should have returned above"); - switch ((rect1->*member).GetUnit()) { - case eCSSUnit_Pixel: - AddCSSValuePixel(aCoeff1, rect1->*member, aCoeff2, rect2->*member, - result->*member); - break; - case eCSSUnit_Auto: - if (float(aCoeff1 + aCoeff2) != 1.0f) { - // Interpolating between two auto values makes sense; - // adding in other ratios does not. - return false; - } - (result->*member).SetAutoValue(); - break; - default: - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - } - - aResultValue.SetAndAdoptCSSRectValue(result.forget(), eUnit_CSSRect); - return true; - } - case eUnit_Dasharray: { - const nsCSSValueList *list1 = aValue1.GetCSSValueListValue(); - const nsCSSValueList *list2 = aValue2.GetCSSValueListValue(); - - uint32_t len1 = 0, len2 = 0; - for (const nsCSSValueList *v = list1; v; v = v->mNext) { - ++len1; - } - for (const nsCSSValueList *v = list2; v; v = v->mNext) { - ++len2; - } - MOZ_ASSERT(len1 > 0 && len2 > 0, "unexpected length"); - - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - for (uint32_t i = 0, i_end = EuclidLCM(len1, len2); i != i_end; ++i) { - const nsCSSValue &v1 = list1->mValue; - const nsCSSValue &v2 = list2->mValue; - MOZ_ASSERT(v1.GetUnit() == eCSSUnit_Number || - v1.GetUnit() == eCSSUnit_Percent, "unexpected"); - MOZ_ASSERT(v2.GetUnit() == eCSSUnit_Number || - v2.GetUnit() == eCSSUnit_Percent, "unexpected"); - if (v1.GetUnit() != v2.GetUnit()) { - // Can't animate between lengths and percentages (until calc()). - return false; - } - - nsCSSValueList *item = new nsCSSValueList; - *resultTail = item; - resultTail = &item->mNext; - - if (v1.GetUnit() == eCSSUnit_Number) { - AddCSSValueNumber(aCoeff1, v1, aCoeff2, v2, item->mValue, - CSS_PROPERTY_VALUE_NONNEGATIVE); - } else { - AddCSSValuePercent(aCoeff1, v1, aCoeff2, v2, item->mValue, - CSS_PROPERTY_VALUE_NONNEGATIVE); - } - - list1 = list1->mNext; - if (!list1) { - list1 = aValue1.GetCSSValueListValue(); - } - list2 = list2->mNext; - if (!list2) { - list2 = aValue2.GetCSSValueListValue(); - } - } - - aResultValue.SetAndAdoptCSSValueListValue(result.forget(), - eUnit_Dasharray); - return true; - } - case eUnit_Shadow: { - UniquePtr result = - AddWeightedShadowList(aCoeff1, - aValue1.GetCSSValueListValue(), - aCoeff2, - aValue2.GetCSSValueListValue(), - ColorAdditionType::Clamped, - aProperty); - if (!result) { - return false; - } - aResultValue.SetAndAdoptCSSValueListValue(result.release(), eUnit_Shadow); - return true; - } - case eUnit_Shape: { - RefPtr result = - AddShapeFunction(aProperty, - aCoeff1, aValue1.GetCSSValueArrayValue(), - aCoeff2, aValue2.GetCSSValueArrayValue()); - if (!result) { - return false; - } - aResultValue.SetCSSValueArrayValue(result, eUnit_Shape); - return true; - } - case eUnit_Filter: { - UniquePtr result = - AddWeightedFilterList(aCoeff1, aValue1.GetCSSValueListValue(), - aCoeff2, aValue2.GetCSSValueListValue(), - ColorAdditionType::Clamped); - if (!result) { - return false; - } - - aResultValue.SetAndAdoptCSSValueListValue(result.release(), - eUnit_Filter); - return true; - } - - case eUnit_Transform: { - const nsCSSValueList* list1 = aValue1.GetCSSValueSharedListValue()->mHead; - const nsCSSValueList* list2 = aValue2.GetCSSValueSharedListValue()->mHead; - - MOZ_ASSERT(list1); - MOZ_ASSERT(list2); - - // We want to avoid the matrix decomposition when we can, since - // avoiding it can produce better results both for compound - // transforms and for skew and skewY (see below). We can do this - // in two cases: - // (1) if one of the transforms is 'none' - // (2) if the lists have the same length and the transform - // functions match - nsAutoPtr result; - if (list1->mValue.GetUnit() == eCSSUnit_None) { - if (list2->mValue.GetUnit() == eCSSUnit_None) { - result = new nsCSSValueList; - if (result) { - result->mValue.SetNoneValue(); - } - } else if (HasAccumulateMatrix(list2)) { - result = AddDifferentTransformLists(0, list2, aCoeff2, list2, - eCSSKeyword_interpolatematrix); - } else { - result = AddTransformLists(0, list2, aCoeff2, list2); - } - } else { - if (list2->mValue.GetUnit() == eCSSUnit_None) { - if (HasAccumulateMatrix(list1)) { - result = AddDifferentTransformLists(0, list1, - aCoeff1, list1, - eCSSKeyword_interpolatematrix); - } else { - result = AddTransformLists(0, list1, aCoeff1, list1); - } - } else if (TransformFunctionListsMatch(list1, list2)) { - result = AddTransformLists(aCoeff1, list1, aCoeff2, list2, - eCSSKeyword_interpolatematrix); - } else { - result = AddDifferentTransformLists(aCoeff1, list1, - aCoeff2, list2, - eCSSKeyword_interpolatematrix); - } - } - - aResultValue.SetTransformValue(new nsCSSValueSharedList(result.forget())); - return true; - } - case eUnit_BackgroundPositionCoord: { - const nsCSSValueList *position1 = aValue1.GetCSSValueListValue(); - const nsCSSValueList *position2 = aValue2.GetCSSValueListValue(); - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - while (position1 && position2) { - nsCSSValueList *item = new nsCSSValueList; - *resultTail = item; - resultTail = &item->mNext; - - AddPositionCoords(aCoeff1, position1->mValue, - aCoeff2, position2->mValue, item->mValue); - - position1 = position1->mNext; - position2 = position2->mNext; - } - - // Check for different lengths - if (position1 || position2) { - return false; - } - - aResultValue.SetAndAdoptCSSValueListValue(result.forget(), - eUnit_BackgroundPositionCoord); - return true; - } - case eUnit_CSSValuePairList: { - const nsCSSValuePairList *list1 = aValue1.GetCSSValuePairListValue(); - const nsCSSValuePairList *list2 = aValue2.GetCSSValuePairListValue(); - UniquePtr result = - AddCSSValuePairList(aProperty, aCoeff1, list1, aCoeff2, list2); - if (!result) { - return false; - } - aResultValue.SetAndAdoptCSSValuePairListValue(result.release()); - return true; - } - } - - MOZ_ASSERT(false, "Can't interpolate using the given common unit"); - return false; -} - -StyleAnimationValue -StyleAnimationValue::Accumulate(nsCSSPropertyID aProperty, - const StyleAnimationValue& aA, - StyleAnimationValue&& aB, - uint64_t aCount) -{ - StyleAnimationValue result(Move(aB)); - - if (aCount == 0) { - return result; - } - - Unit commonUnit = - GetCommonUnit(aProperty, result.GetUnit(), aA.GetUnit()); - switch (commonUnit) { - case eUnit_Filter: { - UniquePtr resultList = - AddWeightedFilterList(1.0, result.GetCSSValueListValue(), - aCount, aA.GetCSSValueListValue(), - ColorAdditionType::Unclamped); - if (resultList) { - result.SetAndAdoptCSSValueListValue(resultList.release(), eUnit_Filter); - } - break; - } - case eUnit_Shadow: { - UniquePtr resultList = - AddWeightedShadowList(1.0, result.GetCSSValueListValue(), - aCount, aA.GetCSSValueListValue(), - ColorAdditionType::Unclamped, - aProperty); - if (resultList) { - result.SetAndAdoptCSSValueListValue(resultList.release(), eUnit_Shadow); - } - break; - } - case eUnit_Color: { - RGBAColorData color1 = ExtractColor(result); - RGBAColorData color2 = ExtractColor(aA); - result.mValue.mCSSValue->SetRGBAColorValue( - AddWeightedColors(1.0, color1, aCount, color2)); - break; - } - case eUnit_Transform: { - const nsCSSValueList* listA = - aA.GetCSSValueSharedListValue()->mHead; - const nsCSSValueList* listB = - result.GetCSSValueSharedListValue()->mHead; - - MOZ_ASSERT(listA); - MOZ_ASSERT(listB); - - nsAutoPtr resultList; - if (listA->mValue.GetUnit() == eCSSUnit_None) { - // If |aA| is 'none' then we are calculating: - // - // none * |aCount| + |aB| - // = none + |aB| - // = |aB| - // - // Hence the result should just be |aB|, even if |aB| is also 'none'. - // Since |result| is already initialized to |aB|, we just return that. - break; - } else if (listB->mValue.GetUnit() == eCSSUnit_None) { - resultList = AddTransformLists(0.0, listA, aCount, listA, - eCSSKeyword_accumulatematrix); - } else if (TransformFunctionListsMatch(listA, listB)) { - resultList = AddTransformLists(1.0, listB, aCount, listA, - eCSSKeyword_accumulatematrix); - } else { - resultList = AddDifferentTransformLists(1.0, listB, - aCount, listA, - eCSSKeyword_accumulatematrix); - } - result.SetTransformValue(new nsCSSValueSharedList(resultList.forget())); - break; - } - default: - Unused << AddWeighted(aProperty, - 1.0, result, - aCount, aA, - result); - break; - } - return result; -} - -static already_AddRefed -BuildStyleRule(nsCSSPropertyID aProperty, - dom::Element* aTargetElement, - const nsAString& aSpecifiedValue, - bool aUseSVGMode) -{ - // Set up an empty CSS Declaration - RefPtr declaration(new css::Declaration()); - declaration->InitializeEmpty(); - - bool changed; // ignored, but needed as outparam for ParseProperty - nsIDocument* doc = aTargetElement->OwnerDoc(); - nsCOMPtr baseURI = aTargetElement->GetBaseURI(); - nsCSSParser parser(doc->CSSLoader()); - - nsCSSPropertyID propertyToCheck = nsCSSProps::IsShorthand(aProperty) ? - nsCSSProps::SubpropertyEntryFor(aProperty)[0] : aProperty; - - // Get a parser, parse the property, and check for CSS parsing errors. - // If this fails, we bail out and delete the declaration. - parser.ParseProperty(aProperty, aSpecifiedValue, doc->GetDocumentURI(), - baseURI, aTargetElement->NodePrincipal(), declaration, - &changed, false, aUseSVGMode); - - // check whether property parsed without CSS parsing errors - if (!declaration->HasNonImportantValueFor(propertyToCheck)) { - return nullptr; - } - - RefPtr rule = new css::StyleRule(nullptr, - declaration, - 0, 0); - return rule.forget(); -} - -static already_AddRefed -BuildStyleRule(nsCSSPropertyID aProperty, - dom::Element* aTargetElement, - const nsCSSValue& aSpecifiedValue, - bool aUseSVGMode) -{ - MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty), - "Should be a longhand property"); - - // Check if longhand failed to parse correctly. - if (aSpecifiedValue.GetUnit() == eCSSUnit_Null) { - return nullptr; - } - - // Set up an empty CSS Declaration - RefPtr declaration(new css::Declaration()); - declaration->InitializeEmpty(); - - // Add our longhand value - nsCSSExpandedDataBlock block; - declaration->ExpandTo(&block); - block.AddLonghandProperty(aProperty, aSpecifiedValue); - declaration->ValueAppended(aProperty); - declaration->CompressFrom(&block); - - RefPtr rule = new css::StyleRule(nullptr, declaration, 0, 0); - return rule.forget(); -} - -static bool -ComputeValuesFromStyleContext( - nsCSSPropertyID aProperty, - CSSEnabledState aEnabledState, - GeckoStyleContext* aStyleContext, - nsTArray& aValues) -{ - // Extract computed value of our property (or all longhand components, if - // aProperty is a shorthand) from the temporary style context - if (nsCSSProps::IsShorthand(aProperty)) { - CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty, aEnabledState) { - if (nsCSSProps::kAnimTypeTable[*p] == eStyleAnimType_None) { - // Skip non-animatable component longhands. - continue; - } - PropertyStyleAnimationValuePair* pair = aValues.AppendElement(); - pair->mProperty = *p; - if (!StyleAnimationValue::ExtractComputedValue(*p, aStyleContext, - pair->mValue.mGecko)) { - return false; - } - } - return true; - } - - PropertyStyleAnimationValuePair* pair = aValues.AppendElement(); - pair->mProperty = aProperty; - return StyleAnimationValue::ExtractComputedValue(aProperty, aStyleContext, - pair->mValue.mGecko); -} - -static bool -ComputeValuesFromStyleRule(nsCSSPropertyID aProperty, - CSSEnabledState aEnabledState, - GeckoStyleContext* aStyleContext, - css::StyleRule* aStyleRule, - nsTArray& aValues, - bool* aIsContextSensitive) -{ - MOZ_ASSERT(aStyleContext); - if (!nsCSSProps::IsEnabled(aProperty, aEnabledState)) { - return false; - } - - MOZ_ASSERT(aStyleContext->PresContext()->StyleSet()->IsGecko(), - "ServoStyleSet should not use StyleAnimationValue for animations"); - nsStyleSet* styleSet = aStyleContext->PresContext()->StyleSet()->AsGecko(); - - RefPtr tmpStyleContext; - if (aIsContextSensitive) { - MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty), - "to correctly set aIsContextSensitive for shorthand properties, " - "this code must be adjusted"); - - nsCOMArray ruleArray; - ruleArray.AppendObject(styleSet->InitialStyleRule()); - css::Declaration* declaration = aStyleRule->GetDeclaration(); - ruleArray.AppendObject(declaration); - declaration->SetImmutable(); - tmpStyleContext = - styleSet->ResolveStyleByAddingRules(aStyleContext, ruleArray); - if (!tmpStyleContext) { - return false; - } - - // Force walk of rule tree - nsStyleStructID sid = nsCSSProps::kSIDTable[aProperty]; - tmpStyleContext->StyleData(sid); - - // The rule node will have unconditional cached style data if the value is - // not context-sensitive. So if there's nothing cached, it's not context - // sensitive. - *aIsContextSensitive = - !tmpStyleContext->RuleNode()->NodeHasCachedUnconditionalData(sid); - } - - // If we're not concerned whether the property is context sensitive then just - // add the rule to a new temporary style context alongside the target - // element's style context. - // Also, if we previously discovered that this property IS context-sensitive - // then we need to throw the temporary style context out since the property's - // value may have been biased by the 'initial' values supplied. - if (!aIsContextSensitive || *aIsContextSensitive) { - nsCOMArray ruleArray; - css::Declaration* declaration = aStyleRule->GetDeclaration(); - ruleArray.AppendObject(declaration); - declaration->SetImmutable(); - tmpStyleContext = - styleSet->ResolveStyleByAddingRules(aStyleContext, ruleArray); - if (!tmpStyleContext) { - return false; - } - } - - return ComputeValuesFromStyleContext(aProperty, aEnabledState, - tmpStyleContext, aValues); -} - -/* static */ bool -StyleAnimationValue::ComputeValue(nsCSSPropertyID aProperty, - dom::Element* aTargetElement, - GeckoStyleContext* aStyleContext, - const nsAString& aSpecifiedValue, - bool aUseSVGMode, - StyleAnimationValue& aComputedValue, - bool* aIsContextSensitive) -{ - MOZ_ASSERT(aTargetElement, "null target element"); - - // Parse specified value into a temporary css::StyleRule - // Note: BuildStyleRule needs an element's OwnerDoc, BaseURI, and Principal. - // If it is a pseudo element, use its parent element's OwnerDoc, BaseURI, - // and Principal. - RefPtr styleRule = - BuildStyleRule(aProperty, aTargetElement, aSpecifiedValue, aUseSVGMode); - if (!styleRule) { - return false; - } - - if (nsCSSProps::IsShorthand(aProperty) || - nsCSSProps::kAnimTypeTable[aProperty] == eStyleAnimType_None) { - // Just capture the specified value - aComputedValue.SetUnparsedStringValue(nsString(aSpecifiedValue)); - if (aIsContextSensitive) { - // Since we're just returning the string as-is, aComputedValue isn't going - // to change depending on the context - *aIsContextSensitive = false; - } - return true; - } - - AutoTArray values; - bool ok = ComputeValuesFromStyleRule(aProperty, - CSSEnabledState::eIgnoreEnabledState, - aStyleContext, styleRule, - values, aIsContextSensitive); - if (!ok) { - return false; - } - - MOZ_ASSERT(values.Length() == 1); - MOZ_ASSERT(values[0].mProperty == aProperty); - - aComputedValue = values[0].mValue.mGecko; - return true; -} - -template -bool -ComputeValuesFromSpecifiedValue( - nsCSSPropertyID aProperty, - CSSEnabledState aEnabledState, - dom::Element* aTargetElement, - GeckoStyleContext* aStyleContext, - T& aSpecifiedValue, - bool aUseSVGMode, - nsTArray& aResult) -{ - MOZ_ASSERT(aTargetElement, "null target element"); - - // Parse specified value into a temporary css::StyleRule - // Note: BuildStyleRule needs an element's OwnerDoc, BaseURI, and Principal. - // If it is a pseudo element, use its parent element's OwnerDoc, BaseURI, - // and Principal. - RefPtr styleRule = - BuildStyleRule(aProperty, aTargetElement, aSpecifiedValue, aUseSVGMode); - if (!styleRule) { - return false; - } - - aResult.Clear(); - return ComputeValuesFromStyleRule(aProperty, aEnabledState, - aStyleContext, styleRule, aResult, - /* aIsContextSensitive */ nullptr); -} - -/* static */ bool -StyleAnimationValue::ComputeValues( - nsCSSPropertyID aProperty, - CSSEnabledState aEnabledState, - dom::Element* aTargetElement, - GeckoStyleContext* aStyleContext, - const nsAString& aSpecifiedValue, - bool aUseSVGMode, - nsTArray& aResult) -{ - return ComputeValuesFromSpecifiedValue(aProperty, aEnabledState, - aTargetElement, aStyleContext, - aSpecifiedValue, aUseSVGMode, - aResult); -} - -/* static */ bool -StyleAnimationValue::ComputeValues( - nsCSSPropertyID aProperty, - CSSEnabledState aEnabledState, - dom::Element* aTargetElement, - GeckoStyleContext* aStyleContext, - const nsCSSValue& aSpecifiedValue, - bool aUseSVGMode, - nsTArray& aResult) -{ - return ComputeValuesFromSpecifiedValue(aProperty, aEnabledState, - aTargetElement, aStyleContext, - aSpecifiedValue, aUseSVGMode, - aResult); -} - -bool -StyleAnimationValue::UncomputeValue(nsCSSPropertyID aProperty, - const StyleAnimationValue& aComputedValue, - nsCSSValue& aSpecifiedValue) -{ - Unit unit = aComputedValue.GetUnit(); - switch (unit) { - case eUnit_Normal: - aSpecifiedValue.SetNormalValue(); - break; - case eUnit_Auto: - aSpecifiedValue.SetAutoValue(); - break; - case eUnit_None: - aSpecifiedValue.SetNoneValue(); - break; - case eUnit_Enumerated: - case eUnit_Visibility: - aSpecifiedValue. - SetIntValue(aComputedValue.GetIntValue(), eCSSUnit_Enumerated); - break; - case eUnit_Integer: - aSpecifiedValue. - SetIntValue(aComputedValue.GetIntValue(), eCSSUnit_Integer); - break; - case eUnit_Coord: - aSpecifiedValue.SetIntegerCoordValue(aComputedValue.GetCoordValue()); - break; - case eUnit_Percent: - aSpecifiedValue.SetPercentValue(aComputedValue.GetPercentValue()); - break; - case eUnit_Float: - aSpecifiedValue. - SetFloatValue(aComputedValue.GetFloatValue(), eCSSUnit_Number); - break; - case eUnit_CurrentColor: - aSpecifiedValue.SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor); - break; - case eUnit_Calc: - case eUnit_Color: - case eUnit_ObjectPosition: - case eUnit_URL: - case eUnit_DiscreteCSSValue: { - nsCSSValue* val = aComputedValue.GetCSSValueValue(); - // Sanity-check that the underlying unit in the nsCSSValue is what we - // expect for our StyleAnimationValue::Unit: - MOZ_ASSERT((unit == eUnit_Calc && val->GetUnit() == eCSSUnit_Calc) || - (unit == eUnit_Color && - nsCSSValue::IsNumericColorUnit(val->GetUnit())) || - (unit == eUnit_ObjectPosition && - val->GetUnit() == eCSSUnit_Array) || - (unit == eUnit_URL && val->GetUnit() == eCSSUnit_URL) || - unit == eUnit_DiscreteCSSValue, - "unexpected unit"); - aSpecifiedValue = *val; - break; - } - case eUnit_ComplexColor: { - aSpecifiedValue.SetComplexColorValue( - do_AddRef(aComputedValue.mValue.mComplexColor)); - break; - } - case eUnit_CSSValuePair: { - // Rule node processing expects pair values to be collapsed to a - // single value if both halves would be equal, for most but not - // all properties. At present, all animatable properties that - // use pairs do expect collapsing. - const nsCSSValuePair* pair = aComputedValue.GetCSSValuePairValue(); - if (pair->mXValue == pair->mYValue) { - aSpecifiedValue = pair->mXValue; - } else { - aSpecifiedValue.SetPairValue(pair); - } - } break; - case eUnit_CSSValueTriplet: { - // Rule node processing expects triplet values to be collapsed to a - // single value if both halves would be equal, for most but not - // all properties. At present, all animatable properties that - // use pairs do expect collapsing. - const nsCSSValueTriplet* triplet = aComputedValue.GetCSSValueTripletValue(); - if (triplet->mXValue == triplet->mYValue && triplet->mYValue == triplet->mZValue) { - aSpecifiedValue = triplet->mXValue; - } else { - aSpecifiedValue.SetTripletValue(triplet); - } - } break; - case eUnit_CSSRect: { - nsCSSRect& rect = aSpecifiedValue.SetRectValue(); - rect = *aComputedValue.GetCSSRectValue(); - } break; - case eUnit_Dasharray: - case eUnit_Shadow: - case eUnit_Filter: - case eUnit_BackgroundPositionCoord: - { - nsCSSValueList* computedList = aComputedValue.GetCSSValueListValue(); - if (computedList) { - aSpecifiedValue.SetDependentListValue(computedList); - } else { - aSpecifiedValue.SetNoneValue(); - } - } - break; - case eUnit_Shape: { - nsCSSValue::Array* computedArray = aComputedValue.GetCSSValueArrayValue(); - aSpecifiedValue.SetArrayValue(computedArray, eCSSUnit_Array); - break; - } - case eUnit_Transform: - aSpecifiedValue. - SetSharedListValue(aComputedValue.GetCSSValueSharedListValue()); - break; - case eUnit_CSSValuePairList: - aSpecifiedValue. - SetDependentPairListValue(aComputedValue.GetCSSValuePairListValue()); - break; - default: - return false; - } - return true; -} - -bool -StyleAnimationValue::UncomputeValue(nsCSSPropertyID aProperty, - StyleAnimationValue&& aComputedValue, - nsCSSValue& aSpecifiedValue) -{ - Unit unit = aComputedValue.GetUnit(); - switch (unit) { - case eUnit_Dasharray: - case eUnit_Shadow: - case eUnit_Filter: - case eUnit_BackgroundPositionCoord: - { - UniquePtr computedList = - aComputedValue.TakeCSSValueListValue(); - if (computedList) { - aSpecifiedValue.AdoptListValue(Move(computedList)); - } else { - aSpecifiedValue.SetNoneValue(); - } - } - break; - case eUnit_CSSValuePairList: - { - UniquePtr computedList = - aComputedValue.TakeCSSValuePairListValue(); - MOZ_ASSERT(computedList, "Pair list should never be null"); - aSpecifiedValue.AdoptPairListValue(Move(computedList)); - } - break; - default: - return UncomputeValue(aProperty, aComputedValue, aSpecifiedValue); - } - return true; -} - -bool -StyleAnimationValue::UncomputeValue(nsCSSPropertyID aProperty, - const StyleAnimationValue& aComputedValue, - nsAString& aSpecifiedValue) -{ - aSpecifiedValue.Truncate(); // Clear outparam, if it's not already empty - - if (aComputedValue.GetUnit() == eUnit_UnparsedString) { - aComputedValue.GetStringValue(aSpecifiedValue); - return true; - } - nsCSSValue val; - if (!StyleAnimationValue::UncomputeValue(aProperty, aComputedValue, val)) { - return false; - } - - val.AppendToString(aProperty, aSpecifiedValue); - return true; -} - -template -inline const T& -StyleDataAtOffset(const void* aStyleStruct, ptrdiff_t aOffset) -{ - return *reinterpret_cast( - reinterpret_cast(aStyleStruct) + aOffset); -} - -static bool -StyleCoordToValue(const nsStyleCoord& aCoord, StyleAnimationValue& aValue) -{ - switch (aCoord.GetUnit()) { - case eStyleUnit_Normal: - aValue.SetNormalValue(); - break; - case eStyleUnit_Auto: - aValue.SetAutoValue(); - break; - case eStyleUnit_None: - aValue.SetNoneValue(); - break; - case eStyleUnit_Percent: - aValue.SetPercentValue(aCoord.GetPercentValue()); - break; - case eStyleUnit_Factor: - aValue.SetFloatValue(aCoord.GetFactorValue()); - break; - case eStyleUnit_Coord: - aValue.SetCoordValue(aCoord.GetCoordValue()); - break; - case eStyleUnit_Enumerated: - aValue.SetIntValue(aCoord.GetIntValue(), - StyleAnimationValue::eUnit_Enumerated); - break; - case eStyleUnit_Integer: - aValue.SetIntValue(aCoord.GetIntValue(), - StyleAnimationValue::eUnit_Integer); - break; - case eStyleUnit_Calc: { - nsAutoPtr val(new nsCSSValue); - CalcValueToCSSValue(aCoord.GetCalcValue(), *val); - aValue.SetAndAdoptCSSValueValue(val.forget(), - StyleAnimationValue::eUnit_Calc); - break; - } - default: - return false; - } - return true; -} - -static bool -StyleCoordToCSSValue(const nsStyleCoord& aCoord, nsCSSValue& aCSSValue) -{ - switch (aCoord.GetUnit()) { - case eStyleUnit_Coord: - aCSSValue.SetIntegerCoordValue(aCoord.GetCoordValue()); - break; - case eStyleUnit_Factor: - aCSSValue.SetFloatValue(aCoord.GetFactorValue(), eCSSUnit_Number); - break; - case eStyleUnit_Percent: - aCSSValue.SetPercentValue(aCoord.GetPercentValue()); - break; - case eStyleUnit_Calc: - CalcValueToCSSValue(aCoord.GetCalcValue(), aCSSValue); - break; - case eStyleUnit_Degree: - aCSSValue.SetFloatValue(aCoord.GetAngleValue(), eCSSUnit_Degree); - break; - case eStyleUnit_Grad: - aCSSValue.SetFloatValue(aCoord.GetAngleValue(), eCSSUnit_Grad); - break; - case eStyleUnit_Radian: - aCSSValue.SetFloatValue(aCoord.GetAngleValue(), eCSSUnit_Radian); - break; - case eStyleUnit_Turn: - aCSSValue.SetFloatValue(aCoord.GetAngleValue(), eCSSUnit_Turn); - break; - default: - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - return true; -} - -static void -SetPositionValue(const Position& aPos, nsCSSValue& aCSSValue) -{ - RefPtr posArray = nsCSSValue::Array::Create(4); - aCSSValue.SetArrayValue(posArray.get(), eCSSUnit_Array); - - // NOTE: Array entries #0 and #2 here are intentionally left untouched, with - // eCSSUnit_Null. The purpose of these entries in our specified-style - // representation is to store edge names. But for values - // extracted from computed style (which is what we're dealing with here), - // we'll just have a normalized "x,y" position, with no edge names needed. - nsCSSValue& xValue = posArray->Item(1); - nsCSSValue& yValue = posArray->Item(3); - - CalcValueToCSSValue(&aPos.mXPosition, xValue); - CalcValueToCSSValue(&aPos.mYPosition, yValue); -} - -static void -SetPositionCoordValue(const Position::Coord& aPosCoord, - nsCSSValue& aCSSValue) -{ - RefPtr posArray = nsCSSValue::Array::Create(2); - aCSSValue.SetArrayValue(posArray.get(), eCSSUnit_Array); - - // NOTE: Array entry #0 here is intentionally left untouched, with - // eCSSUnit_Null. The purpose of this entry in our specified-style - // representation is to store edge names. But for values - // extracted from computed style (which is what we're dealing with here), - // we'll just have a normalized "x"/"y" position, with no edge names needed. - nsCSSValue& value = posArray->Item(1); - - CalcValueToCSSValue(&aPosCoord, value); -} - -/* - * Assign |aOutput = aInput|, except with any non-pixel lengths - * replaced with the equivalent in pixels, and any non-canonical calc() - * expressions replaced with canonical ones. - */ -static void -SubstitutePixelValues(GeckoStyleContext* aStyleContext, - const nsCSSValue& aInput, nsCSSValue& aOutput) -{ - if (aInput.IsCalcUnit()) { - RuleNodeCacheConditions conditions; - nsRuleNode::ComputedCalc c = - nsRuleNode::SpecifiedCalcToComputedCalc(aInput, aStyleContext, - aStyleContext->PresContext(), - conditions); - nsStyleCoord::CalcValue c2; - c2.mLength = c.mLength; - c2.mPercent = c.mPercent; - c2.mHasPercent = true; // doesn't matter for transform translate - CalcValueToCSSValue(&c2, aOutput); - } else if (aInput.UnitHasArrayValue()) { - const nsCSSValue::Array *inputArray = aInput.GetArrayValue(); - RefPtr outputArray = - nsCSSValue::Array::Create(inputArray->Count()); - for (size_t i = 0, i_end = inputArray->Count(); i < i_end; ++i) { - SubstitutePixelValues(aStyleContext, - inputArray->Item(i), outputArray->Item(i)); - } - aOutput.SetArrayValue(outputArray, aInput.GetUnit()); - } else if (aInput.IsLengthUnit() && - aInput.GetUnit() != eCSSUnit_Pixel) { - RuleNodeCacheConditions conditions; - nscoord len = nsRuleNode::CalcLength(aInput, aStyleContext, - aStyleContext->PresContext(), - conditions); - aOutput.SetFloatValue(nsPresContext::AppUnitsToFloatCSSPixels(len), - eCSSUnit_Pixel); - } else { - aOutput = aInput; - } -} - -static void -ExtractImageLayerPositionXList(const nsStyleImageLayers& aLayer, - StyleAnimationValue& aComputedValue) -{ - MOZ_ASSERT(aLayer.mPositionXCount > 0, "unexpected count"); - - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - for (uint32_t i = 0, i_end = aLayer.mPositionXCount; i != i_end; ++i) { - nsCSSValueList *item = new nsCSSValueList; - *resultTail = item; - resultTail = &item->mNext; - SetPositionCoordValue(aLayer.mLayers[i].mPosition.mXPosition, - item->mValue); - } - - aComputedValue.SetAndAdoptCSSValueListValue(result.forget(), - StyleAnimationValue::eUnit_BackgroundPositionCoord); -} - -static void -ExtractImageLayerPositionYList(const nsStyleImageLayers& aLayer, - StyleAnimationValue& aComputedValue) -{ - MOZ_ASSERT(aLayer.mPositionYCount > 0, "unexpected count"); - - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - for (uint32_t i = 0, i_end = aLayer.mPositionYCount; i != i_end; ++i) { - nsCSSValueList *item = new nsCSSValueList; - *resultTail = item; - resultTail = &item->mNext; - SetPositionCoordValue(aLayer.mLayers[i].mPosition.mYPosition, - item->mValue); - } - - aComputedValue.SetAndAdoptCSSValueListValue(result.forget(), - StyleAnimationValue::eUnit_BackgroundPositionCoord); -} - -static void -ExtractImageLayerSizePairList(const nsStyleImageLayers& aLayer, - StyleAnimationValue& aComputedValue) -{ - MOZ_ASSERT(aLayer.mSizeCount > 0, "unexpected count"); - - nsAutoPtr result; - nsCSSValuePairList **resultTail = getter_Transfers(result); - for (uint32_t i = 0, i_end = aLayer.mSizeCount; i != i_end; ++i) { - nsCSSValuePairList *item = new nsCSSValuePairList; - *resultTail = item; - resultTail = &item->mNext; - - const nsStyleImageLayers::Size &size = aLayer.mLayers[i].mSize; - switch (size.mWidthType) { - case nsStyleImageLayers::Size::eContain: - case nsStyleImageLayers::Size::eCover: - item->mXValue.SetIntValue(size.mWidthType, - eCSSUnit_Enumerated); - break; - case nsStyleImageLayers::Size::eAuto: - item->mXValue.SetAutoValue(); - break; - case nsStyleImageLayers::Size::eLengthPercentage: - // XXXbz is there a good reason we can't just - // CalcValueToCSSValue(&size.mWidth, item->mXValue) here? - if (!size.mWidth.mHasPercent && - // negative values must have come from calc() - size.mWidth.mLength >= 0) { - MOZ_ASSERT(size.mWidth.mPercent == 0.0f, - "Shouldn't have mPercent"); - item->mXValue.SetIntegerCoordValue(size.mWidth.mLength); - } else if (size.mWidth.mLength == 0 && - // negative values must have come from calc() - size.mWidth.mPercent >= 0.0f) { - item->mXValue.SetPercentValue(size.mWidth.mPercent); - } else { - CalcValueToCSSValue(&size.mWidth, item->mXValue); - } - break; - } - - switch (size.mHeightType) { - case nsStyleImageLayers::Size::eContain: - case nsStyleImageLayers::Size::eCover: - // leave it null - break; - case nsStyleImageLayers::Size::eAuto: - item->mYValue.SetAutoValue(); - break; - case nsStyleImageLayers::Size::eLengthPercentage: - // XXXbz is there a good reason we can't just - // CalcValueToCSSValue(&size.mHeight, item->mYValue) here? - if (!size.mHeight.mHasPercent && - // negative values must have come from calc() - size.mHeight.mLength >= 0) { - MOZ_ASSERT(size.mHeight.mPercent == 0.0f, - "Shouldn't have mPercent"); - item->mYValue.SetIntegerCoordValue(size.mHeight.mLength); - } else if (size.mHeight.mLength == 0 && - // negative values must have come from calc() - size.mHeight.mPercent >= 0.0f) { - item->mYValue.SetPercentValue(size.mHeight.mPercent); - } else { - CalcValueToCSSValue(&size.mHeight, item->mYValue); - } - break; - } - } - - aComputedValue.SetAndAdoptCSSValuePairListValue(result.forget()); -} - -static bool -StyleShapeSourceToCSSArray(const StyleShapeSource& aShapeSource, - nsCSSValue::Array* aResult) -{ - MOZ_ASSERT(aResult->Count() == 2, - "Expected array to be presized for a function and the sizing-box"); - - const UniquePtr& shape = aShapeSource.GetBasicShape(); - nsCSSKeyword functionName = shape->GetShapeTypeName(); - RefPtr functionArray; - switch (shape->GetShapeType()) { - case StyleBasicShapeType::Circle: - case StyleBasicShapeType::Ellipse: { - const nsTArray& coords = shape->Coordinates(); - MOZ_ASSERT(coords.Length() == ShapeArgumentCount(functionName) - 1, - "Unexpected radii count"); - // The "+1" is for the center point: - functionArray = aResult->Item(0).InitFunction(functionName, - coords.Length() + 1); - for (size_t i = 0; i < coords.Length(); ++i) { - if (coords[i].GetUnit() == eStyleUnit_Enumerated) { - functionArray->Item(i + 1).SetIntValue(coords[i].GetIntValue(), - eCSSUnit_Enumerated); - } else if (!StyleCoordToCSSValue(coords[i], - functionArray->Item(i + 1))) { - return false; - } - } - // Set functionArray's last item to the circle or ellipse's center point: - SetPositionValue(shape->GetPosition(), - functionArray->Item(functionArray->Count() - 1)); - break; - } - case StyleBasicShapeType::Polygon: { - functionArray = - aResult->Item(0).InitFunction(functionName, - ShapeArgumentCount(functionName)); - functionArray->Item(1).SetEnumValue(shape->GetFillRule()); - nsCSSValuePairList* list = functionArray->Item(2).SetPairListValue(); - const nsTArray& coords = shape->Coordinates(); - MOZ_ASSERT((coords.Length() % 2) == 0); - for (size_t i = 0; i < coords.Length(); i += 2) { - if (i > 0) { - list->mNext = new nsCSSValuePairList; - list = list->mNext; - } - if (!StyleCoordToCSSValue(coords[i], list->mXValue) || - !StyleCoordToCSSValue(coords[i + 1], list->mYValue)) { - return false; - } - } - break; - } - case StyleBasicShapeType::Inset: { - const nsTArray& coords = shape->Coordinates(); - MOZ_ASSERT(coords.Length() == ShapeArgumentCount(functionName) - 1, - "Unexpected offset count"); - functionArray = - aResult->Item(0).InitFunction(functionName, coords.Length() + 1); - for (size_t i = 0; i < coords.Length(); ++i) { - if (!StyleCoordToCSSValue(coords[i], functionArray->Item(i + 1))) { - return false; - } - } - RefPtr radiusArray = nsCSSValue::Array::Create(4); - const nsStyleCorners& radii = shape->GetRadius(); - NS_FOR_CSS_FULL_CORNERS(corner) { - auto pair = MakeUnique(); - if (!StyleCoordToCSSValue(radii.Get(FullToHalfCorner(corner, false)), - pair->mXValue) || - !StyleCoordToCSSValue(radii.Get(FullToHalfCorner(corner, true)), - pair->mYValue)) { - return false; - } - radiusArray->Item(corner).SetPairValue(pair.get()); - } - // Set the last item in functionArray to the radius array: - functionArray->Item(functionArray->Count() - 1). - SetArrayValue(radiusArray, eCSSUnit_Array); - break; - } - default: - MOZ_ASSERT_UNREACHABLE("Unknown shape type"); - return false; - } - aResult->Item(1).SetEnumValue(aShapeSource.GetReferenceBox()); - return true; -} - -static bool -ExtractComputedValueFromShapeSource(const StyleShapeSource& aShapeSource, - StyleAnimationValue& aComputedValue) -{ - const StyleShapeSourceType type = aShapeSource.GetType(); - - if (type == StyleShapeSourceType::URL) { - auto result = MakeUnique(); - result->SetURLValue(aShapeSource.GetURL()); - aComputedValue.SetAndAdoptCSSValueValue(result.release(), - StyleAnimationValue::eUnit_URL); - } else if (type == StyleShapeSourceType::Box) { - aComputedValue.SetEnumValue(aShapeSource.GetReferenceBox()); - } else if (type == StyleShapeSourceType::Shape) { - RefPtr result = nsCSSValue::Array::Create(2); - if (!StyleShapeSourceToCSSArray(aShapeSource, result)) { - return false; - } - aComputedValue.SetCSSValueArrayValue(result, - StyleAnimationValue::eUnit_Shape); - - } else if (type == StyleShapeSourceType::Image) { - // XXX: Won't implement because Gecko style system will be removed. - return false; - } else { - MOZ_ASSERT(type == StyleShapeSourceType::None, "unknown type"); - aComputedValue.SetNoneValue(); - } - - return true; -} - -static void -SetFallbackValue(nsCSSValuePair* aPair, const nsStyleSVGPaint& aPaint) -{ - if (aPaint.GetFallbackType() == eStyleSVGFallbackType_Color) { - aPair->mYValue.SetColorValue(aPaint.GetFallbackColor()); - } else { - aPair->mYValue.SetNoneValue(); - } -} - -bool -StyleAnimationValue::ExtractComputedValue(nsCSSPropertyID aProperty, - GeckoStyleContext* aStyleContext, - StyleAnimationValue& aComputedValue) -{ - MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_no_shorthands, - "bad property"); - const void* styleStruct = - aStyleContext->StyleData(nsCSSProps::kSIDTable[aProperty]); - ptrdiff_t ssOffset = nsCSSProps::kStyleStructOffsetTable[aProperty]; - nsStyleAnimType animType = nsCSSProps::kAnimTypeTable[aProperty]; - MOZ_ASSERT(0 <= ssOffset || - animType == eStyleAnimType_Custom || - animType == eStyleAnimType_Discrete, - "all animation types other than Custom and Discrete must " \ - "specify a style struct offset to extract values from"); - switch (animType) { - case eStyleAnimType_Custom: - switch (aProperty) { - // For border-width, ignore the border-image business (which - // only exists until we update our implementation to the current - // spec) and use GetComputedBorder - - #define BORDER_WIDTH_CASE(prop_, side_) \ - case prop_: \ - aComputedValue.SetCoordValue( \ - static_cast(styleStruct)-> \ - GetComputedBorder().side_); \ - break; - BORDER_WIDTH_CASE(eCSSProperty_border_bottom_width, bottom) - BORDER_WIDTH_CASE(eCSSProperty_border_left_width, left) - BORDER_WIDTH_CASE(eCSSProperty_border_right_width, right) - BORDER_WIDTH_CASE(eCSSProperty_border_top_width, top) - #undef BORDER_WIDTH_CASE - - case eCSSProperty_column_rule_width: - aComputedValue.SetCoordValue( - static_cast(styleStruct)-> - GetComputedColumnRuleWidth()); - break; - - case eCSSProperty_column_count: { - const nsStyleColumn *styleColumn = - static_cast(styleStruct); - if (styleColumn->mColumnCount == NS_STYLE_COLUMN_COUNT_AUTO) { - aComputedValue.SetAutoValue(); - } else { - aComputedValue.SetIntValue(styleColumn->mColumnCount, - eUnit_Integer); - } - break; - } - - case eCSSProperty_order: { - const nsStylePosition *stylePosition = - static_cast(styleStruct); - aComputedValue.SetIntValue(stylePosition->mOrder, - eUnit_Integer); - break; - } - - case eCSSProperty_border_spacing: { - const nsStyleTableBorder *styleTableBorder = - static_cast(styleStruct); - nsAutoPtr pair(new nsCSSValuePair); - pair->mXValue.SetIntegerCoordValue(styleTableBorder->mBorderSpacingCol); - pair->mYValue.SetIntegerCoordValue(styleTableBorder->mBorderSpacingRow); - aComputedValue.SetAndAdoptCSSValuePairValue(pair.forget(), - eUnit_CSSValuePair); - break; - } - - case eCSSProperty_transform_origin: { - const nsStyleDisplay *styleDisplay = - static_cast(styleStruct); - nsAutoPtr triplet(new nsCSSValueTriplet); - if (!StyleCoordToCSSValue(styleDisplay->mTransformOrigin[0], - triplet->mXValue) || - !StyleCoordToCSSValue(styleDisplay->mTransformOrigin[1], - triplet->mYValue) || - !StyleCoordToCSSValue(styleDisplay->mTransformOrigin[2], - triplet->mZValue)) { - return false; - } - aComputedValue.SetAndAdoptCSSValueTripletValue(triplet.forget(), - eUnit_CSSValueTriplet); - break; - } - - case eCSSProperty_perspective_origin: { - const nsStyleDisplay *styleDisplay = - static_cast(styleStruct); - nsAutoPtr pair(new nsCSSValuePair); - if (!StyleCoordToCSSValue(styleDisplay->mPerspectiveOrigin[0], - pair->mXValue) || - !StyleCoordToCSSValue(styleDisplay->mPerspectiveOrigin[1], - pair->mYValue)) { - return false; - } - aComputedValue.SetAndAdoptCSSValuePairValue(pair.forget(), - eUnit_CSSValuePair); - break; - } - - case eCSSProperty__moz_window_transform_origin: { - const nsStyleUIReset *styleUIReset = - static_cast(styleStruct); - nsAutoPtr pair(new nsCSSValuePair); - if (!StyleCoordToCSSValue(styleUIReset->mWindowTransformOrigin[0], - pair->mXValue) || - !StyleCoordToCSSValue(styleUIReset->mWindowTransformOrigin[1], - pair->mYValue)) { - return false; - } - aComputedValue.SetAndAdoptCSSValuePairValue(pair.forget(), - eUnit_CSSValuePair); - break; - } - - case eCSSProperty_stroke_dasharray: { - const nsStyleSVG *svg = static_cast(styleStruct); - if (!svg->mStrokeDasharray.IsEmpty()) { - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - for (uint32_t i = 0, i_end = svg->mStrokeDasharray.Length(); - i != i_end; ++i) { - nsCSSValueList *item = new nsCSSValueList; - *resultTail = item; - resultTail = &item->mNext; - - const nsStyleCoord &coord = svg->mStrokeDasharray[i]; - nsCSSValue &value = item->mValue; - switch (coord.GetUnit()) { - case eStyleUnit_Coord: - // Number means the same thing as length; we want to - // animate them the same way. Normalize both to number - // since it has more accuracy (float vs nscoord). - value.SetFloatValue(nsPresContext:: - AppUnitsToFloatCSSPixels(coord.GetCoordValue()), - eCSSUnit_Number); - break; - case eStyleUnit_Factor: - value.SetFloatValue(coord.GetFactorValue(), - eCSSUnit_Number); - break; - case eStyleUnit_Percent: - value.SetPercentValue(coord.GetPercentValue()); - break; - default: - MOZ_ASSERT(false, "unexpected unit"); - return false; - } - } - aComputedValue.SetAndAdoptCSSValueListValue(result.forget(), - eUnit_Dasharray); - } else if (svg->StrokeDasharrayFromObject()) { - // An empty dasharray with StrokeDasharrayFromObject() == true - // corresponds to the "context-value" keyword. - aComputedValue.SetIntValue(NS_STYLE_STROKE_PROP_CONTEXT_VALUE, - eUnit_Enumerated); - } else { - // Otherwise, an empty dasharray corresponds to the "none" keyword. - aComputedValue.SetNoneValue(); - } - break; - } - - case eCSSProperty_font_stretch: { - int16_t stretch = - static_cast(styleStruct)->mFont.stretch; - static_assert(NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED == -4 && - NS_STYLE_FONT_STRETCH_ULTRA_EXPANDED == 4, - "font stretch constants not as expected"); - if (stretch < NS_STYLE_FONT_STRETCH_ULTRA_CONDENSED || - stretch > NS_STYLE_FONT_STRETCH_ULTRA_EXPANDED) { - return false; - } - aComputedValue.SetIntValue(stretch, eUnit_Enumerated); - return true; - } - - case eCSSProperty_font_weight: { - uint16_t weight = - static_cast(styleStruct)->mFont.weight; - if (weight % 100 != 0) { - return false; - } - aComputedValue.SetIntValue(weight, eUnit_Integer); - return true; - } - - case eCSSProperty__moz_image_region: { - const nsStyleList *list = - static_cast(styleStruct); - const nsRect &srect = list->mImageRegion; - if (srect.IsEmpty()) { - aComputedValue.SetAutoValue(); - break; - } - - nsCSSRect *vrect = new nsCSSRect; - vrect->mLeft.SetIntegerCoordValue(srect.x); - vrect->mTop.SetIntegerCoordValue(srect.y); - vrect->mRight.SetIntegerCoordValue(srect.XMost()); - vrect->mBottom.SetIntegerCoordValue(srect.YMost()); - aComputedValue.SetAndAdoptCSSRectValue(vrect, eUnit_CSSRect); - break; - } - - case eCSSProperty_clip: { - const nsStyleEffects* effects = - static_cast(styleStruct); - if (!(effects->mClipFlags & NS_STYLE_CLIP_RECT)) { - aComputedValue.SetAutoValue(); - } else { - nsCSSRect *vrect = new nsCSSRect; - const nsRect &srect = effects->mClip; - if (effects->mClipFlags & NS_STYLE_CLIP_TOP_AUTO) { - vrect->mTop.SetAutoValue(); - } else { - vrect->mTop.SetIntegerCoordValue(srect.y); - } - if (effects->mClipFlags & NS_STYLE_CLIP_RIGHT_AUTO) { - vrect->mRight.SetAutoValue(); - } else { - vrect->mRight.SetIntegerCoordValue(srect.XMost()); - } - if (effects->mClipFlags & NS_STYLE_CLIP_BOTTOM_AUTO) { - vrect->mBottom.SetAutoValue(); - } else { - vrect->mBottom.SetIntegerCoordValue(srect.YMost()); - } - if (effects->mClipFlags & NS_STYLE_CLIP_LEFT_AUTO) { - vrect->mLeft.SetAutoValue(); - } else { - vrect->mLeft.SetIntegerCoordValue(srect.x); - } - aComputedValue.SetAndAdoptCSSRectValue(vrect, eUnit_CSSRect); - } - break; - } - - case eCSSProperty_object_position: { - const nsStylePosition* stylePos = - static_cast(styleStruct); - - nsAutoPtr val(new nsCSSValue); - SetPositionValue(stylePos->mObjectPosition, *val); - - aComputedValue.SetAndAdoptCSSValueValue(val.forget(), - eUnit_ObjectPosition); - break; - } - - case eCSSProperty_background_position_x: { - const nsStyleImageLayers& layers = - static_cast(styleStruct)->mImage; - ExtractImageLayerPositionXList(layers, aComputedValue); - break; - } - case eCSSProperty_background_position_y: { - const nsStyleImageLayers& layers = - static_cast(styleStruct)->mImage; - ExtractImageLayerPositionYList(layers, aComputedValue); - break; - } - - case eCSSProperty_mask_position_x: { - const nsStyleImageLayers& layers = - static_cast(styleStruct)->mMask; - ExtractImageLayerPositionXList(layers, aComputedValue); - break; - } - - case eCSSProperty_mask_position_y: { - const nsStyleImageLayers& layers = - static_cast(styleStruct)->mMask; - ExtractImageLayerPositionYList(layers, aComputedValue); - - break; - } - - case eCSSProperty_background_size: { - const nsStyleImageLayers& layers = - static_cast(styleStruct)->mImage; - ExtractImageLayerSizePairList(layers, aComputedValue); - break; - } - - case eCSSProperty_mask_size: { - const nsStyleImageLayers& layers = - static_cast(styleStruct)->mMask; - ExtractImageLayerSizePairList(layers, aComputedValue); - break; - } - - case eCSSProperty_clip_path: { - const nsStyleSVGReset* svgReset = - static_cast(styleStruct); - if (!ExtractComputedValueFromShapeSource(svgReset->mClipPath, - aComputedValue)) { - return false; - } - break; - } - - case eCSSProperty_shape_outside: { - const nsStyleDisplay* styleDisplay = - static_cast(styleStruct); - if (!ExtractComputedValueFromShapeSource(styleDisplay->mShapeOutside, - aComputedValue)) { - return false; - }; - break; - } - - case eCSSProperty_filter: { - const nsStyleEffects* effects = - static_cast(styleStruct); - const nsTArray& filters = effects->mFilters; - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - for (uint32_t i = 0; i < filters.Length(); ++i) { - nsCSSValueList *item = new nsCSSValueList; - *resultTail = item; - resultTail = &item->mNext; - const nsStyleFilter& filter = filters[i]; - int32_t type = filter.GetType(); - if (type == NS_STYLE_FILTER_URL) { - item->mValue.SetURLValue(filter.GetURL()); - } else { - nsCSSKeyword functionName = - nsCSSProps::ValueToKeywordEnum(type, - nsCSSProps::kFilterFunctionKTable); - nsCSSValue::Array* filterArray = - item->mValue.InitFunction(functionName, 1); - if (type >= NS_STYLE_FILTER_BLUR && type <= NS_STYLE_FILTER_HUE_ROTATE) { - if (!StyleCoordToCSSValue( - filter.GetFilterParameter(), - filterArray->Item(1))) { - return false; - } - } else if (type == NS_STYLE_FILTER_DROP_SHADOW) { - nsCSSValueList* shadowResult = filterArray->Item(1).SetListValue(); - nsAutoPtr tmpShadowValue; - nsCSSValueList **tmpShadowResultTail = getter_Transfers(tmpShadowValue); - nsCSSShadowArray* shadowArray = filter.GetDropShadow(); - MOZ_ASSERT(shadowArray->Length() == 1, - "expected exactly one shadow"); - AppendCSSShadowValue(shadowArray->ShadowAt(0), - tmpShadowResultTail, aProperty); - *shadowResult = *tmpShadowValue; - } else { - // We checked all possible nsStyleFilter types but - // NS_STYLE_FILTER_NULL before. We should never enter this path. - NS_NOTREACHED("no other filter functions defined"); - return false; - } - } - } - - aComputedValue.SetAndAdoptCSSValueListValue(result.forget(), - eUnit_Filter); - break; - } - - case eCSSProperty_transform: { - const nsStyleDisplay *display = - static_cast(styleStruct); - nsAutoPtr result; - RefPtr transformList = display->GetCombinedTransform(); - if (transformList) { - // Clone, and convert all lengths (not percents) to pixels. - nsCSSValueList **resultTail = getter_Transfers(result); - for (const nsCSSValueList *l = transformList->mHead; - l; l = l->mNext) { - nsCSSValueList *clone = new nsCSSValueList; - *resultTail = clone; - resultTail = &clone->mNext; - - SubstitutePixelValues(aStyleContext, l->mValue, clone->mValue); - } - } else { - result = new nsCSSValueList(); - result->mValue.SetNoneValue(); - } - - aComputedValue.SetTransformValue( - new nsCSSValueSharedList(result.forget())); - break; - } - - case eCSSProperty__moz_window_transform: { - const nsStyleUIReset *uiReset = - static_cast(styleStruct); - nsAutoPtr result; - if (uiReset->mSpecifiedWindowTransform) { - // Clone, and convert all lengths (not percents) to pixels. - nsCSSValueList **resultTail = getter_Transfers(result); - for (const nsCSSValueList *l = uiReset->mSpecifiedWindowTransform->mHead; - l; l = l->mNext) { - nsCSSValueList *clone = new nsCSSValueList; - *resultTail = clone; - resultTail = &clone->mNext; - - SubstitutePixelValues(aStyleContext, l->mValue, clone->mValue); - } - } else { - result = new nsCSSValueList(); - result->mValue.SetNoneValue(); - } - - aComputedValue.SetTransformValue( - new nsCSSValueSharedList(result.forget())); - break; - } - - case eCSSProperty_font_variation_settings: { - auto font = static_cast(styleStruct); - UniquePtr result; - if (!font->mFont.fontVariationSettings.IsEmpty()) { - // Make a new list that clones the current settings - nsCSSValuePairList* tail = nullptr; - for (auto v : font->mFont.fontVariationSettings) { - auto clone = MakeUnique(); - // OpenType font tags are stored in nsFont as 32-bit unsigned - // values, but represented in CSS as 4-character ASCII strings, - // beginning with the high byte of the value. So to clone the - // tag here, we append each of its 4 bytes to a string. - nsAutoString tagString; - tagString.Append(char(v.mTag >> 24)); - tagString.Append(char(v.mTag >> 16)); - tagString.Append(char(v.mTag >> 8)); - tagString.Append(char(v.mTag)); - clone->mXValue.SetStringValue(tagString, eCSSUnit_String); - clone->mYValue.SetFloatValue(v.mValue, eCSSUnit_Number); - AppendToCSSValuePairList(result, Move(clone), &tail); - } - aComputedValue.SetAndAdoptCSSValuePairListValue(result.release()); - } else { - aComputedValue.SetNormalValue(); - } - break; - } - - default: - MOZ_ASSERT(false, "missing property implementation"); - return false; - }; - return true; - case eStyleAnimType_Coord: { - const nsStyleCoord& coord = - StyleDataAtOffset(styleStruct, ssOffset); - if (nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_NUMBERS_ARE_PIXELS) && - coord.GetUnit() == eStyleUnit_Coord) { - // For SVG properties where number means the same thing as length, - // we want to animate them the same way. Normalize both to number - // since it has more accuracy (float vs nscoord). - aComputedValue.SetFloatValue(nsPresContext:: - AppUnitsToFloatCSSPixels(coord.GetCoordValue())); - return true; - } - return StyleCoordToValue(coord, aComputedValue); - } - case eStyleAnimType_Sides_Top: - case eStyleAnimType_Sides_Right: - case eStyleAnimType_Sides_Bottom: - case eStyleAnimType_Sides_Left: { - static_assert( - eSideTop == eStyleAnimType_Sides_Top -eStyleAnimType_Sides_Top && - eSideRight == eStyleAnimType_Sides_Right -eStyleAnimType_Sides_Top && - eSideBottom == eStyleAnimType_Sides_Bottom-eStyleAnimType_Sides_Top && - eSideLeft == eStyleAnimType_Sides_Left -eStyleAnimType_Sides_Top, - "box side constants out of sync with animation side constants"); - - const nsStyleCoord &coord = - StyleDataAtOffset(styleStruct, ssOffset). - Get(mozilla::Side(animType - eStyleAnimType_Sides_Top)); - return StyleCoordToValue(coord, aComputedValue); - } - case eStyleAnimType_Corner_TopLeft: - case eStyleAnimType_Corner_TopRight: - case eStyleAnimType_Corner_BottomRight: - case eStyleAnimType_Corner_BottomLeft: { - static_assert( - eCornerTopLeft == eStyleAnimType_Corner_TopLeft - - eStyleAnimType_Corner_TopLeft && - eCornerTopRight == eStyleAnimType_Corner_TopRight - - eStyleAnimType_Corner_TopLeft && - eCornerBottomRight == eStyleAnimType_Corner_BottomRight - - eStyleAnimType_Corner_TopLeft && - eCornerBottomLeft == eStyleAnimType_Corner_BottomLeft - - eStyleAnimType_Corner_TopLeft, - "box corner constants out of sync with animation corner constants"); - - const nsStyleCorners& corners = - StyleDataAtOffset(styleStruct, ssOffset); - Corner fullCorner = Corner(animType - eStyleAnimType_Corner_TopLeft); - const nsStyleCoord &horiz = - corners.Get(FullToHalfCorner(fullCorner, false)); - const nsStyleCoord &vert = - corners.Get(FullToHalfCorner(fullCorner, true)); - nsAutoPtr pair(new nsCSSValuePair); - if (!StyleCoordToCSSValue(horiz, pair->mXValue) || - !StyleCoordToCSSValue(vert, pair->mYValue)) { - return false; - } - aComputedValue.SetAndAdoptCSSValuePairValue(pair.forget(), - eUnit_CSSValuePair); - return true; - } - case eStyleAnimType_nscoord: - aComputedValue.SetCoordValue( - StyleDataAtOffset(styleStruct, ssOffset)); - return true; - case eStyleAnimType_float: - aComputedValue.SetFloatValue( - StyleDataAtOffset(styleStruct, ssOffset)); - if (aProperty == eCSSProperty_font_size_adjust && - aComputedValue.GetFloatValue() == -1.0f) { - // In nsStyleFont, we set mFont.sizeAdjust to -1.0 to represent - // font-size-adjust: none. Here, we have to treat this as a keyword - // instead of a float value, to make sure we don't end up doing - // interpolation with it. - aComputedValue.SetNoneValue(); - } - return true; - case eStyleAnimType_Color: - aComputedValue.SetColorValue( - StyleDataAtOffset(styleStruct, ssOffset)); - return true; - case eStyleAnimType_ComplexColor: { - auto& color = StyleDataAtOffset(styleStruct, ssOffset); - if (color.mIsAuto) { - aComputedValue.SetAutoValue(); - } else { - aComputedValue.SetComplexColorValue(color); - } - return true; - } - case eStyleAnimType_PaintServer: { - const nsStyleSVGPaint& paint = - StyleDataAtOffset(styleStruct, ssOffset); - switch (paint.Type()) { - case eStyleSVGPaintType_Color: - aComputedValue.SetColorValue(paint.GetColor()); - return true; - case eStyleSVGPaintType_Server: { - css::URLValue* url = paint.GetPaintServer(); - if (!url) { - NS_WARNING("Null paint server"); - return false; - } - if (paint.GetFallbackType() != eStyleSVGFallbackType_NotSet) { - nsAutoPtr pair(new nsCSSValuePair); - pair->mXValue.SetURLValue(url); - SetFallbackValue(pair, paint); - aComputedValue.SetAndAdoptCSSValuePairValue(pair.forget(), - eUnit_CSSValuePair); - } else { - auto result = MakeUnique(); - result->SetURLValue(url); - aComputedValue.SetAndAdoptCSSValueValue( - result.release(), eUnit_URL); - } - return true; - } - case eStyleSVGPaintType_ContextFill: - case eStyleSVGPaintType_ContextStroke: { - int32_t value = paint.Type() == eStyleSVGPaintType_ContextFill ? - NS_COLOR_CONTEXT_FILL : NS_COLOR_CONTEXT_STROKE; - if (paint.GetFallbackType() != eStyleSVGFallbackType_NotSet) { - nsAutoPtr pair(new nsCSSValuePair); - pair->mXValue.SetIntValue(value, eCSSUnit_Enumerated); - SetFallbackValue(pair, paint); - aComputedValue.SetAndAdoptCSSValuePairValue(pair.forget(), - eUnit_CSSValuePair); - } else { - aComputedValue.SetIntValue(value, eUnit_Enumerated); - } - return true; - } - default: - MOZ_ASSERT(paint.Type() == eStyleSVGPaintType_None, - "Unexpected SVG paint type"); - aComputedValue.SetNoneValue(); - return true; - } - } - case eStyleAnimType_Shadow: { - const nsCSSShadowArray* shadowArray = - StyleDataAtOffset>(styleStruct, ssOffset); - if (!shadowArray) { - aComputedValue.SetAndAdoptCSSValueListValue(nullptr, eUnit_Shadow); - return true; - } - nsAutoPtr result; - nsCSSValueList **resultTail = getter_Transfers(result); - for (uint32_t i = 0, i_end = shadowArray->Length(); i < i_end; ++i) { - AppendCSSShadowValue(shadowArray->ShadowAt(i), resultTail, aProperty); - } - aComputedValue.SetAndAdoptCSSValueListValue(result.forget(), - eUnit_Shadow); - return true; - } - case eStyleAnimType_Discrete: { - if (aProperty == eCSSProperty_visibility) { - aComputedValue.SetIntValue( - static_cast(styleStruct)->mVisible, - eUnit_Visibility); - return true; - } - if (aStyleContext->IsServo()) { - NS_ERROR("stylo: extracting discretely animated values not supported"); - return false; - } - auto cssValue = MakeUnique(eCSSUnit_Unset); - aStyleContext->RuleNode()->GetDiscretelyAnimatedCSSValue(aProperty, - cssValue.get()); - aComputedValue.SetAndAdoptCSSValueValue(cssValue.release(), - eUnit_DiscreteCSSValue); - return true; - } - case eStyleAnimType_None: - NS_NOTREACHED("shouldn't use on non-animatable properties"); - } - return false; -} - -Size -StyleAnimationValue::GetScaleValue(const nsIFrame* aForFrame) const -{ - MOZ_ASSERT(GetUnit() == StyleAnimationValue::eUnit_Transform); - - nsCSSValueSharedList* list = GetCSSValueSharedListValue(); - return nsStyleTransformMatrix::GetScaleValue(list, aForFrame); -} - -StyleAnimationValue::StyleAnimationValue(int32_t aInt, Unit aUnit, - IntegerConstructorType) -{ - NS_ASSERTION(IsIntUnit(aUnit), "unit must be of integer type"); - mUnit = aUnit; - mValue.mInt = aInt; -} - -StyleAnimationValue::StyleAnimationValue(nscoord aLength, CoordConstructorType) -{ - mUnit = eUnit_Coord; - mValue.mCoord = aLength; -} - -StyleAnimationValue::StyleAnimationValue(float aPercent, - PercentConstructorType) -{ - mUnit = eUnit_Percent; - mValue.mFloat = aPercent; - MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat)); -} - -StyleAnimationValue::StyleAnimationValue(float aFloat, FloatConstructorType) -{ - mUnit = eUnit_Float; - mValue.mFloat = aFloat; - MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat)); -} - -StyleAnimationValue::StyleAnimationValue(nscolor aColor, ColorConstructorType) -{ - mUnit = eUnit_Color; - mValue.mCSSValue = new nsCSSValue(); - mValue.mCSSValue->SetColorValue(aColor); -} - -StyleAnimationValue& -StyleAnimationValue::operator=(const StyleAnimationValue& aOther) -{ - if (this == &aOther) { - return *this; - } - - FreeValue(); - - mUnit = aOther.mUnit; - switch (mUnit) { - case eUnit_Null: - case eUnit_Normal: - case eUnit_Auto: - case eUnit_None: - case eUnit_CurrentColor: - break; - case eUnit_Enumerated: - case eUnit_Visibility: - case eUnit_Integer: - mValue.mInt = aOther.mValue.mInt; - break; - case eUnit_Coord: - mValue.mCoord = aOther.mValue.mCoord; - break; - case eUnit_Percent: - case eUnit_Float: - mValue.mFloat = aOther.mValue.mFloat; - MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat)); - break; - case eUnit_Calc: - case eUnit_Color: - case eUnit_ObjectPosition: - case eUnit_URL: - case eUnit_DiscreteCSSValue: - MOZ_ASSERT(IsCSSValueUnit(mUnit), - "This clause is for handling nsCSSValue-backed units"); - MOZ_ASSERT(aOther.mValue.mCSSValue, "values may not be null"); - mValue.mCSSValue = new nsCSSValue(*aOther.mValue.mCSSValue); - break; - case eUnit_CSSValuePair: - MOZ_ASSERT(aOther.mValue.mCSSValuePair, - "value pairs may not be null"); - mValue.mCSSValuePair = new nsCSSValuePair(*aOther.mValue.mCSSValuePair); - break; - case eUnit_CSSValueTriplet: - MOZ_ASSERT(aOther.mValue.mCSSValueTriplet, - "value triplets may not be null"); - mValue.mCSSValueTriplet = new nsCSSValueTriplet(*aOther.mValue.mCSSValueTriplet); - break; - case eUnit_CSSRect: - MOZ_ASSERT(aOther.mValue.mCSSRect, "rects may not be null"); - mValue.mCSSRect = new nsCSSRect(*aOther.mValue.mCSSRect); - break; - case eUnit_Dasharray: - case eUnit_Shadow: - case eUnit_Filter: - case eUnit_BackgroundPositionCoord: - MOZ_ASSERT(mUnit == eUnit_Shadow || mUnit == eUnit_Filter || - aOther.mValue.mCSSValueList, - "value lists other than shadows and filters may not be null"); - if (aOther.mValue.mCSSValueList) { - mValue.mCSSValueList = aOther.mValue.mCSSValueList->Clone(); - } else { - mValue.mCSSValueList = nullptr; - } - break; - case eUnit_Shape: - MOZ_ASSERT(aOther.mValue.mCSSValueArray, - "value arrays may not be null"); - mValue.mCSSValueArray = aOther.mValue.mCSSValueArray; - mValue.mCSSValueArray->AddRef(); - break; - case eUnit_Transform: - mValue.mCSSValueSharedList = aOther.mValue.mCSSValueSharedList; - mValue.mCSSValueSharedList->AddRef(); - break; - case eUnit_CSSValuePairList: - MOZ_ASSERT(aOther.mValue.mCSSValuePairList, - "value pair lists may not be null"); - mValue.mCSSValuePairList = aOther.mValue.mCSSValuePairList->Clone(); - break; - case eUnit_UnparsedString: - MOZ_ASSERT(aOther.mValue.mString, "expecting non-null string"); - mValue.mString = aOther.mValue.mString; - mValue.mString->AddRef(); - break; - case eUnit_ComplexColor: - MOZ_ASSERT(aOther.mValue.mComplexColor); - mValue.mComplexColor = aOther.mValue.mComplexColor; - mValue.mComplexColor->AddRef(); - break; - } - - return *this; -} - -void -StyleAnimationValue::SetNormalValue() -{ - FreeValue(); - mUnit = eUnit_Normal; -} - -void -StyleAnimationValue::SetAutoValue() -{ - FreeValue(); - mUnit = eUnit_Auto; -} - -void -StyleAnimationValue::SetNoneValue() -{ - FreeValue(); - mUnit = eUnit_None; -} - -void -StyleAnimationValue::SetIntValue(int32_t aInt, Unit aUnit) -{ - NS_ASSERTION(IsIntUnit(aUnit), "unit must be of integer type"); - FreeValue(); - mUnit = aUnit; - mValue.mInt = aInt; -} - -void -StyleAnimationValue::SetCoordValue(nscoord aLength) -{ - FreeValue(); - mUnit = eUnit_Coord; - mValue.mCoord = aLength; -} - -void -StyleAnimationValue::SetPercentValue(float aPercent) -{ - FreeValue(); - mUnit = eUnit_Percent; - mValue.mFloat = aPercent; - MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat)); -} - -void -StyleAnimationValue::SetFloatValue(float aFloat) -{ - FreeValue(); - mUnit = eUnit_Float; - mValue.mFloat = aFloat; - MOZ_ASSERT(!mozilla::IsNaN(mValue.mFloat)); -} - -void -StyleAnimationValue::SetColorValue(nscolor aColor) -{ - FreeValue(); - mUnit = eUnit_Color; - mValue.mCSSValue = new nsCSSValue(); - mValue.mCSSValue->SetColorValue(aColor); -} - -void -StyleAnimationValue::SetCurrentColorValue() -{ - FreeValue(); - mUnit = eUnit_CurrentColor; -} - -void -StyleAnimationValue::SetComplexColorValue(const StyleComplexColor& aColor) -{ - if (aColor.mIsAuto) { - SetAutoValue(); - } else if (aColor.IsCurrentColor()) { - SetCurrentColorValue(); - } else if (aColor.IsNumericColor()) { - SetColorValue(aColor.mColor); - } else { - SetComplexColorValue(do_AddRef(new ComplexColorValue(aColor))); - } -} - -void -StyleAnimationValue::SetComplexColorValue( - already_AddRefed aValue) -{ - FreeValue(); - mUnit = eUnit_ComplexColor; - mValue.mComplexColor = aValue.take(); -} - -void -StyleAnimationValue::SetUnparsedStringValue(const nsString& aString) -{ - FreeValue(); - mUnit = eUnit_UnparsedString; - mValue.mString = nsCSSValue::BufferFromString(aString).take(); -} - -void -StyleAnimationValue::SetAndAdoptCSSValueValue(nsCSSValue *aValue, - Unit aUnit) -{ - FreeValue(); - MOZ_ASSERT(IsCSSValueUnit(aUnit), "bad unit"); - MOZ_ASSERT(aValue != nullptr, "values may not be null"); - mUnit = aUnit; - mValue.mCSSValue = aValue; // take ownership -} - -void -StyleAnimationValue::SetAndAdoptCSSValuePairValue(nsCSSValuePair *aValuePair, - Unit aUnit) -{ - FreeValue(); - MOZ_ASSERT(IsCSSValuePairUnit(aUnit), "bad unit"); - MOZ_ASSERT(aValuePair != nullptr, "value pairs may not be null"); - mUnit = aUnit; - mValue.mCSSValuePair = aValuePair; // take ownership -} - -void -StyleAnimationValue::SetAndAdoptCSSValueTripletValue( - nsCSSValueTriplet *aValueTriplet, Unit aUnit) -{ - FreeValue(); - MOZ_ASSERT(IsCSSValueTripletUnit(aUnit), "bad unit"); - MOZ_ASSERT(aValueTriplet != nullptr, "value pairs may not be null"); - mUnit = aUnit; - mValue.mCSSValueTriplet = aValueTriplet; // take ownership -} - -void -StyleAnimationValue::SetAndAdoptCSSRectValue(nsCSSRect *aRect, Unit aUnit) -{ - FreeValue(); - MOZ_ASSERT(IsCSSRectUnit(aUnit), "bad unit"); - MOZ_ASSERT(aRect != nullptr, "value pairs may not be null"); - mUnit = aUnit; - mValue.mCSSRect = aRect; // take ownership -} - -void -StyleAnimationValue::SetCSSValueArrayValue(nsCSSValue::Array* aValue, - Unit aUnit) -{ - FreeValue(); - MOZ_ASSERT(IsCSSValueArrayUnit(aUnit), "bad unit"); - MOZ_ASSERT(aValue != nullptr, - "not currently expecting any arrays to be null"); - mUnit = aUnit; - mValue.mCSSValueArray = aValue; - mValue.mCSSValueArray->AddRef(); -} - -void -StyleAnimationValue::SetAndAdoptCSSValueListValue(nsCSSValueList *aValueList, - Unit aUnit) -{ - FreeValue(); - MOZ_ASSERT(IsCSSValueListUnit(aUnit), "bad unit"); - MOZ_ASSERT(aUnit == eUnit_Shadow || aUnit == eUnit_Filter || - aValueList != nullptr, - "value lists other than shadows and filters may not be null"); - mUnit = aUnit; - mValue.mCSSValueList = aValueList; // take ownership -} - -void -StyleAnimationValue::SetTransformValue(nsCSSValueSharedList* aList) -{ - FreeValue(); - mUnit = eUnit_Transform; - mValue.mCSSValueSharedList = aList; - mValue.mCSSValueSharedList->AddRef(); -} - -void -StyleAnimationValue::SetAndAdoptCSSValuePairListValue( - nsCSSValuePairList *aValuePairList) -{ - FreeValue(); - MOZ_ASSERT(aValuePairList, "may not be null"); - mUnit = eUnit_CSSValuePairList; - mValue.mCSSValuePairList = aValuePairList; // take ownership -} - -void -StyleAnimationValue::FreeValue() -{ - if (IsCSSValueUnit(mUnit)) { - delete mValue.mCSSValue; - } else if (IsCSSValueListUnit(mUnit)) { - delete mValue.mCSSValueList; - } else if (IsCSSValueSharedListValue(mUnit)) { - mValue.mCSSValueSharedList->Release(); - } else if (IsCSSValuePairUnit(mUnit)) { - delete mValue.mCSSValuePair; - } else if (IsCSSValueTripletUnit(mUnit)) { - delete mValue.mCSSValueTriplet; - } else if (IsCSSRectUnit(mUnit)) { - delete mValue.mCSSRect; - } else if (IsCSSValuePairListUnit(mUnit)) { - delete mValue.mCSSValuePairList; - } else if (IsCSSValueArrayUnit(mUnit)) { - mValue.mCSSValueArray->Release(); - } else if (IsStringUnit(mUnit)) { - MOZ_ASSERT(mValue.mString, "expecting non-null string"); - mValue.mString->Release(); - } else if (mUnit == eUnit_ComplexColor) { - mValue.mComplexColor->Release(); - } -} - -bool -StyleAnimationValue::operator==(const StyleAnimationValue& aOther) const -{ - if (mUnit != aOther.mUnit) { - return false; - } - - switch (mUnit) { - case eUnit_Null: - case eUnit_Normal: - case eUnit_Auto: - case eUnit_None: - case eUnit_CurrentColor: - return true; - case eUnit_Enumerated: - case eUnit_Visibility: - case eUnit_Integer: - return mValue.mInt == aOther.mValue.mInt; - case eUnit_Coord: - return mValue.mCoord == aOther.mValue.mCoord; - case eUnit_Percent: - case eUnit_Float: - return mValue.mFloat == aOther.mValue.mFloat; - case eUnit_Calc: - case eUnit_Color: - case eUnit_ObjectPosition: - case eUnit_URL: - case eUnit_DiscreteCSSValue: - MOZ_ASSERT(IsCSSValueUnit(mUnit), - "This clause is for handling nsCSSValue-backed units"); - return *mValue.mCSSValue == *aOther.mValue.mCSSValue; - case eUnit_CSSValuePair: - return *mValue.mCSSValuePair == *aOther.mValue.mCSSValuePair; - case eUnit_CSSValueTriplet: - return *mValue.mCSSValueTriplet == *aOther.mValue.mCSSValueTriplet; - case eUnit_CSSRect: - return *mValue.mCSSRect == *aOther.mValue.mCSSRect; - case eUnit_Dasharray: - case eUnit_Shadow: - case eUnit_Filter: - case eUnit_BackgroundPositionCoord: - return nsCSSValueList::Equal(mValue.mCSSValueList, - aOther.mValue.mCSSValueList); - case eUnit_Shape: - return *mValue.mCSSValueArray == *aOther.mValue.mCSSValueArray; - case eUnit_Transform: - return *mValue.mCSSValueSharedList == *aOther.mValue.mCSSValueSharedList; - case eUnit_CSSValuePairList: - return nsCSSValuePairList::Equal(mValue.mCSSValuePairList, - aOther.mValue.mCSSValuePairList); - case eUnit_UnparsedString: - return (NS_strcmp(GetStringBufferValue(), - aOther.GetStringBufferValue()) == 0); - case eUnit_ComplexColor: - return *mValue.mComplexColor == *aOther.mValue.mComplexColor; - } - - NS_NOTREACHED("incomplete case"); - return false; -} -#endif // AnimationValue Implementation @@ -5332,20 +102,11 @@ StyleAnimationValue::operator==(const StyleAnimationValue& aOther) const bool AnimationValue::operator==(const AnimationValue& aOther) const { -#ifdef MOZ_OLD_STYLE - // It is possible to compare an empty AnimationValue with others, so both - // mServo and mGecko could be null while comparing. - MOZ_ASSERT(!mServo || mGecko.IsNull()); -#endif if (mServo && aOther.mServo) { return Servo_AnimationValue_DeepEqual(mServo, aOther.mServo); } if (!mServo && !aOther.mServo) { -#ifdef MOZ_OLD_STYLE - return mGecko == aOther.mGecko; -#else return true; -#endif } return false; } @@ -5359,44 +120,23 @@ AnimationValue::operator!=(const AnimationValue& aOther) const float AnimationValue::GetOpacity() const { -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(!mServo != mGecko.IsNull()); - MOZ_ASSERT(mServo || mGecko.GetUnit() == StyleAnimationValue::eUnit_Float, - "Should have the correct unit on Gecko backend"); -#else MOZ_ASSERT(mServo); -#endif if (mServo) { return Servo_AnimationValue_GetOpacity(mServo); } -#ifdef MOZ_OLD_STYLE - return mGecko.GetFloatValue(); -#else MOZ_CRASH("old style system disabled"); -#endif } already_AddRefed AnimationValue::GetTransformList() const { -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(!mServo != mGecko.IsNull()); - MOZ_ASSERT(mServo || mGecko.GetUnit() == StyleAnimationValue::eUnit_Transform, - "The unit of interpolated value for transform should be " - "transform on Gecko backend"); -#else MOZ_ASSERT(mServo); -#endif RefPtr transform; if (mServo) { Servo_AnimationValue_GetTransform(mServo, &transform); } else { -#ifdef MOZ_OLD_STYLE - transform = mGecko.GetCSSValueSharedListValue(); -#else MOZ_CRASH("old style system disabled"); -#endif } return transform.forget(); } @@ -5404,46 +144,28 @@ AnimationValue::GetTransformList() const Size AnimationValue::GetScaleValue(const nsIFrame* aFrame) const { -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(!mServo != mGecko.IsNull()); -#else MOZ_ASSERT(mServo); -#endif if (mServo) { RefPtr list; Servo_AnimationValue_GetTransform(mServo, &list); return nsStyleTransformMatrix::GetScaleValue(list, aFrame); } -#ifdef MOZ_OLD_STYLE - return mGecko.GetScaleValue(aFrame); -#else MOZ_CRASH("old style system disabled"); -#endif } void AnimationValue::SerializeSpecifiedValue(nsCSSPropertyID aProperty, nsAString& aString) const { -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(!mServo != mGecko.IsNull()); -#else MOZ_ASSERT(mServo); -#endif if (mServo) { Servo_AnimationValue_Serialize(mServo, aProperty, &aString); return; } -#ifdef MOZ_OLD_STYLE - DebugOnly uncomputeResult = - StyleAnimationValue::UncomputeValue(aProperty, mGecko, aString); - MOZ_ASSERT(uncomputeResult, "failed to uncompute StyleAnimationValue"); -#else MOZ_CRASH("old style system disabled"); -#endif } bool @@ -5454,29 +176,14 @@ AnimationValue::IsInterpolableWith(nsCSSPropertyID aProperty, return false; } -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(!mServo != mGecko.IsNull()); - MOZ_ASSERT(mGecko.IsNull() == aToValue.mGecko.IsNull() && - !mServo == !aToValue.mServo, - "Animation values should have the same style engine"); -#else MOZ_ASSERT(mServo); MOZ_ASSERT(aToValue.mServo); -#endif if (mServo) { return Servo_AnimationValues_IsInterpolable(mServo, aToValue.mServo); } -#ifdef MOZ_OLD_STYLE - // If this is ever a performance problem, we could add a - // StyleAnimationValue::IsInterpolatable method, but it seems fine for now. - StyleAnimationValue dummy; - return StyleAnimationValue::Interpolate( - aProperty, mGecko, aToValue.mGecko, 0.5, dummy); -#else MOZ_CRASH("old style system disabled"); -#endif } double @@ -5488,15 +195,8 @@ AnimationValue::ComputeDistance(nsCSSPropertyID aProperty, return 0.0; } -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(!mServo != mGecko.IsNull()); - MOZ_ASSERT(mGecko.IsNull() == aOther.mGecko.IsNull() && - !mServo == !aOther.mServo, - "Animation values should have the same style engine"); -#else MOZ_ASSERT(mServo); MOZ_ASSERT(aOther.mServo); -#endif double distance= 0.0; if (mServo) { @@ -5506,17 +206,7 @@ AnimationValue::ComputeDistance(nsCSSPropertyID aProperty, : distance; } -#ifdef MOZ_OLD_STYLE - return StyleAnimationValue::ComputeDistance(aProperty, - mGecko, - aOther.mGecko, - aStyleContext->AsGecko(), - distance) - ? distance - : 0.0; -#else MOZ_CRASH("old style system disabled"); -#endif } /* static */ AnimationValue @@ -5560,17 +250,7 @@ AnimationValue::FromString(nsCSSPropertyID aProperty, return result; } -#ifdef MOZ_OLD_STYLE - if (!StyleAnimationValue::ComputeValue(aProperty, aElement, - styleContext->AsGecko(), - aValue, false /* |aUseSVGMode| */, - result.mGecko)) { - MOZ_ASSERT(result.IsNull()); - } - return result; -#else MOZ_CRASH("old style system disabled"); -#endif } /* static */ AnimationValue @@ -5583,11 +263,7 @@ AnimationValue::Opacity(StyleBackendType aBackendType, float aOpacity) result.mServo = Servo_AnimationValue_Opacity(aOpacity).Consume(); break; case StyleBackendType::Gecko: -#ifdef MOZ_OLD_STYLE - result.mGecko.SetFloatValue(aOpacity); -#else MOZ_CRASH("old style system disabled"); -#endif break; default: MOZ_ASSERT_UNREACHABLE("Unsupported style backend"); @@ -5606,11 +282,7 @@ AnimationValue::Transform(StyleBackendType aBackendType, result.mServo = Servo_AnimationValue_Transform(aList).Consume(); break; case StyleBackendType::Gecko: -#ifdef MOZ_OLD_STYLE - result.mGecko.SetTransformValue(&aList); -#else MOZ_CRASH("old style system disabled"); -#endif break; default: MOZ_ASSERT_UNREACHABLE("Unsupported style backend"); diff --git a/layout/style/StyleAnimationValue.h b/layout/style/StyleAnimationValue.h index e1a32acb6e7e..67a54768b8a3 100644 --- a/layout/style/StyleAnimationValue.h +++ b/layout/style/StyleAnimationValue.h @@ -42,565 +42,21 @@ enum class CSSPseudoElementType : uint8_t; enum class StyleBackendType : uint8_t; struct PropertyStyleAnimationValuePair; -#ifdef MOZ_OLD_STYLE -/** - * Utility class to handle animated style values - */ -class StyleAnimationValue { -public: - // Mathematical methods - // -------------------- - /** - * Adds |aCount| copies of |aValueToAdd| to |aDest|. The result of this - * addition is stored in aDest. - * - * Note that if |aCount| is 0, then |aDest| will be unchanged. Also, if - * this method fails, then |aDest| will be unchanged. - * - * @param aDest The value to add to. - * @param aValueToAdd The value to add. - * @param aCount The number of times to add aValueToAdd. - * @return true on success, false on failure. - */ - static MOZ_MUST_USE bool - Add(nsCSSPropertyID aProperty, StyleAnimationValue& aDest, - const StyleAnimationValue& aValueToAdd, uint32_t aCount) { - return AddWeighted(aProperty, 1.0, aDest, aCount, aValueToAdd, aDest); - } - - /** - * Alternative version of Add that reflects the naming used in Web Animations - * and which returns the result using the return value. - */ - static StyleAnimationValue - Add(nsCSSPropertyID aProperty, - const StyleAnimationValue& aA, - StyleAnimationValue&& aB); - - /** - * Calculates a measure of 'distance' between two colors. - * - * @param aStartColor The start of the interval for which the distance - * should be calculated. - * @param aEndColor The end of the interval for which the distance - * should be calculated. - * @return the result of the calculation. - */ - static double ComputeColorDistance(const css::RGBAColorData& aStartColor, - const css::RGBAColorData& aEndColor); - - /** - * Calculates a measure of 'distance' between two values. - * - * This measure of Distance is guaranteed to be proportional to - * portions passed to Interpolate, Add, or AddWeighted. However, for - * some types of StyleAnimationValue it may not produce sensible results - * for paced animation. - * - * If this method succeeds, the returned distance value is guaranteed to be - * non-negative. - * - * @param aStartValue The start of the interval for which the distance - * should be calculated. - * @param aEndValue The end of the interval for which the distance - * should be calculated. - * @param aStyleContext The style context to use for processing the - * translate part of transforms. - * @param aDistance The result of the calculation. - * @return true on success, false on failure. - */ - static MOZ_MUST_USE bool - ComputeDistance(nsCSSPropertyID aProperty, - const StyleAnimationValue& aStartValue, - const StyleAnimationValue& aEndValue, - GeckoStyleContext* aStyleContext, - double& aDistance); - - /** - * Calculates an interpolated value that is the specified |aPortion| between - * the two given values. - * - * This really just does the following calculation: - * aResultValue = (1.0 - aPortion) * aStartValue + aPortion * aEndValue - * - * @param aStartValue The value defining the start of the interval of - * interpolation. - * @param aEndValue The value defining the end of the interval of - * interpolation. - * @param aPortion A number in the range [0.0, 1.0] defining the - * distance of the interpolated value in the interval. - * @param [out] aResultValue The resulting interpolated value. - * @return true on success, false on failure. - */ - static MOZ_MUST_USE bool - Interpolate(nsCSSPropertyID aProperty, - const StyleAnimationValue& aStartValue, - const StyleAnimationValue& aEndValue, - double aPortion, - StyleAnimationValue& aResultValue) { - return AddWeighted(aProperty, 1.0 - aPortion, aStartValue, - aPortion, aEndValue, aResultValue); - } - - /** - * Does the calculation: - * aResultValue = aCoeff1 * aValue1 + aCoeff2 * aValue2 - * - * @param [out] aResultValue The resulting interpolated value. May be - * the same as aValue1 or aValue2. - * @return true on success, false on failure. - * - * NOTE: Current callers always pass aCoeff1 and aCoeff2 >= 0. They - * are currently permitted to be negative; however, if, as we add - * support more value types types, we find that this causes - * difficulty, we might change this to restrict them to being - * positive. - */ - static MOZ_MUST_USE bool - AddWeighted(nsCSSPropertyID aProperty, - double aCoeff1, const StyleAnimationValue& aValue1, - double aCoeff2, const StyleAnimationValue& aValue2, - StyleAnimationValue& aResultValue); - - /** - * Accumulates |aA| onto |aA| (|aCount| - 1) times then accumulates |aB| onto - * the result. - * If |aCount| is zero or no accumulation or addition procedure is defined - * for |aProperty|, the result will be |aB|. - */ - static StyleAnimationValue - Accumulate(nsCSSPropertyID aProperty, - const StyleAnimationValue& aA, - StyleAnimationValue&& aB, - uint64_t aCount = 1); - - // Type-conversion methods - // ----------------------- - /** - * Creates a computed value for the given specified value - * (property ID + string). A style context is needed in case the - * specified value depends on inherited style or on the values of other - * properties. - * - * @param aProperty The property whose value we're computing. - * @param aTargetElement The content node to which our computed value is - * applicable. For pseudo-elements, this is the parent - * element to which the pseudo is attached, not the - * generated content node. - * @param aStyleContext The style context used to compute values from the - * specified value. For pseudo-elements, this should - * be the style context corresponding to the pseudo - * element. - * @param aSpecifiedValue The specified value, from which we'll build our - * computed value. - * @param aUseSVGMode A flag to indicate whether we should parse - * |aSpecifiedValue| in SVG mode. - * @param [out] aComputedValue The resulting computed value. - * @param [out] aIsContextSensitive - * Set to true if |aSpecifiedValue| may produce - * a different |aComputedValue| depending on other CSS - * properties on |aTargetElement| or its ancestors. - * false otherwise. - * Note that the operation of this method is - * significantly faster when |aIsContextSensitive| is - * nullptr. - * @return true on success, false on failure. - */ - static MOZ_MUST_USE bool - ComputeValue(nsCSSPropertyID aProperty, - mozilla::dom::Element* aTargetElement, - mozilla::GeckoStyleContext* aStyleContext, - const nsAString& aSpecifiedValue, - bool aUseSVGMode, - StyleAnimationValue& aComputedValue, - bool* aIsContextSensitive = nullptr); - - /** - * Like ComputeValue, but returns an array of StyleAnimationValues. - * - * On success, when aProperty is a longhand, aResult will have a single - * value in it. When aProperty is a shorthand, aResult will be filled with - * values for all of aProperty's longhand components. aEnabledState - * is used to filter the longhand components that will be appended - * to aResult. On failure, aResult might still have partial results - * in it. - */ - static MOZ_MUST_USE bool - ComputeValues(nsCSSPropertyID aProperty, - mozilla::CSSEnabledState aEnabledState, - mozilla::dom::Element* aTargetElement, - mozilla::GeckoStyleContext* aStyleContext, - const nsAString& aSpecifiedValue, - bool aUseSVGMode, - nsTArray& aResult); - - /** - * A variant on ComputeValues that takes an nsCSSValue as the specified - * value. Only longhand properties are supported. - */ - static MOZ_MUST_USE bool - ComputeValues(nsCSSPropertyID aProperty, - mozilla::CSSEnabledState aEnabledState, - mozilla::dom::Element* aTargetElement, - mozilla::GeckoStyleContext* aStyleContext, - const nsCSSValue& aSpecifiedValue, - bool aUseSVGMode, - nsTArray& aResult); - - /** - * Creates a specified value for the given computed value. - * - * The first two overloads fill in an nsCSSValue object; the third - * produces a string. For the overload that takes a const - * StyleAnimationValue& reference, the nsCSSValue result may depend on - * objects owned by the |aComputedValue| object, so users of that variant - * must keep |aComputedValue| alive longer than |aSpecifiedValue|. - * The overload that takes an rvalue StyleAnimationValue reference - * transfers ownership for some resources such that the |aComputedValue| - * does not depend on the lifetime of |aSpecifiedValue|. - * - * @param aProperty The property whose value we're uncomputing. - * @param aComputedValue The computed value to be converted. - * @param [out] aSpecifiedValue The resulting specified value. - * @return true on success, false on failure. - */ - static MOZ_MUST_USE bool - UncomputeValue(nsCSSPropertyID aProperty, - const StyleAnimationValue& aComputedValue, - nsCSSValue& aSpecifiedValue); - static MOZ_MUST_USE bool - UncomputeValue(nsCSSPropertyID aProperty, - StyleAnimationValue&& aComputedValue, - nsCSSValue& aSpecifiedValue); - static MOZ_MUST_USE bool - UncomputeValue(nsCSSPropertyID aProperty, - const StyleAnimationValue& aComputedValue, - nsAString& aSpecifiedValue); - - /** - * Gets the computed value for the given property from the given style - * context. - * - * Obtaining the computed value allows us to animate properties when the - * content author has specified a value like "inherit" or "initial" or some - * other keyword that isn't directly interpolatable, but which *computes* to - * something interpolatable. - * - * @param aProperty The property whose value we're looking up. - * @param aStyleContext The style context to check for the computed value. - * @param [out] aComputedValue The resulting computed value. - * @return true on success, false on failure. - */ - static MOZ_MUST_USE bool ExtractComputedValue( - nsCSSPropertyID aProperty, - mozilla::GeckoStyleContext* aStyleContext, - StyleAnimationValue& aComputedValue); - - /** - * The types and values for the values that we extract and animate. - */ - enum Unit { - eUnit_Null, // not initialized - eUnit_Normal, - eUnit_Auto, - eUnit_None, - eUnit_Enumerated, - eUnit_Visibility, // special case for transitions (which converts - // Enumerated to Visibility as needed) - eUnit_Integer, - eUnit_Coord, - eUnit_Percent, - eUnit_Float, - eUnit_Color, // nsCSSValue* (never null), always with an nscolor or - // an nsCSSValueFloatColor - eUnit_CurrentColor, - eUnit_ComplexColor, // ComplexColorValue* (never null) - eUnit_Calc, // nsCSSValue* (never null), always with a single - // calc() expression that's either length or length+percent - eUnit_ObjectPosition, // nsCSSValue* (never null), always with a - // 4-entry nsCSSValue::Array - eUnit_URL, // nsCSSValue* (never null), always with a css::URLValue - eUnit_DiscreteCSSValue, // nsCSSValue* (never null) - eUnit_CSSValuePair, // nsCSSValuePair* (never null) - eUnit_CSSValueTriplet, // nsCSSValueTriplet* (never null) - eUnit_CSSRect, // nsCSSRect* (never null) - eUnit_Dasharray, // nsCSSValueList* (never null) - eUnit_Shadow, // nsCSSValueList* (may be null) - eUnit_Shape, // nsCSSValue::Array* (never null) - eUnit_Filter, // nsCSSValueList* (may be null) - eUnit_Transform, // nsCSSValueList* (never null) - eUnit_BackgroundPositionCoord, // nsCSSValueList* (never null) - eUnit_CSSValuePairList, // nsCSSValuePairList* (never null) - eUnit_UnparsedString // nsStringBuffer* (never null) - }; - -private: - Unit mUnit; - union { - int32_t mInt; - nscoord mCoord; - float mFloat; - nsCSSValue* mCSSValue; - nsCSSValuePair* mCSSValuePair; - nsCSSValueTriplet* mCSSValueTriplet; - nsCSSRect* mCSSRect; - nsCSSValue::Array* mCSSValueArray; - nsCSSValueList* mCSSValueList; - nsCSSValueSharedList* mCSSValueSharedList; - nsCSSValuePairList* mCSSValuePairList; - nsStringBuffer* mString; - css::ComplexColorValue* mComplexColor; - } mValue; - -public: - Unit GetUnit() const { - NS_ASSERTION(mUnit != eUnit_Null, "uninitialized"); - return mUnit; - } - - // Accessor to let us verify assumptions about presence of null unit, - // without tripping the assertion in GetUnit(). - bool IsNull() const { - return mUnit == eUnit_Null; - } - - int32_t GetIntValue() const { - NS_ASSERTION(IsIntUnit(mUnit), "unit mismatch"); - return mValue.mInt; - } - nscoord GetCoordValue() const { - NS_ASSERTION(mUnit == eUnit_Coord, "unit mismatch"); - return mValue.mCoord; - } - float GetPercentValue() const { - NS_ASSERTION(mUnit == eUnit_Percent, "unit mismatch"); - return mValue.mFloat; - } - float GetFloatValue() const { - NS_ASSERTION(mUnit == eUnit_Float, "unit mismatch"); - return mValue.mFloat; - } - nsCSSValue* GetCSSValueValue() const { - NS_ASSERTION(IsCSSValueUnit(mUnit), "unit mismatch"); - return mValue.mCSSValue; - } - nsCSSValuePair* GetCSSValuePairValue() const { - NS_ASSERTION(IsCSSValuePairUnit(mUnit), "unit mismatch"); - return mValue.mCSSValuePair; - } - nsCSSValueTriplet* GetCSSValueTripletValue() const { - NS_ASSERTION(IsCSSValueTripletUnit(mUnit), "unit mismatch"); - return mValue.mCSSValueTriplet; - } - nsCSSRect* GetCSSRectValue() const { - NS_ASSERTION(IsCSSRectUnit(mUnit), "unit mismatch"); - return mValue.mCSSRect; - } - nsCSSValue::Array* GetCSSValueArrayValue() const { - NS_ASSERTION(IsCSSValueArrayUnit(mUnit), "unit mismatch"); - return mValue.mCSSValueArray; - } - nsCSSValueList* GetCSSValueListValue() const { - NS_ASSERTION(IsCSSValueListUnit(mUnit), "unit mismatch"); - return mValue.mCSSValueList; - } - nsCSSValueSharedList* GetCSSValueSharedListValue() const { - NS_ASSERTION(IsCSSValueSharedListValue(mUnit), "unit mismatch"); - return mValue.mCSSValueSharedList; - } - nsCSSValuePairList* GetCSSValuePairListValue() const { - NS_ASSERTION(IsCSSValuePairListUnit(mUnit), "unit mismatch"); - return mValue.mCSSValuePairList; - } - const char16_t* GetStringBufferValue() const { - NS_ASSERTION(IsStringUnit(mUnit), "unit mismatch"); - return GetBufferValue(mValue.mString); - } - - void GetStringValue(nsAString& aBuffer) const { - NS_ASSERTION(IsStringUnit(mUnit), "unit mismatch"); - aBuffer.Truncate(); - uint32_t len = NS_strlen(GetBufferValue(mValue.mString)); - mValue.mString->ToString(len, aBuffer); - } - - /// @return the scale for this value, calculated with reference to @aForFrame. - mozilla::gfx::Size GetScaleValue(const nsIFrame* aForFrame) const; - - const css::ComplexColorData& GetComplexColorData() const { - MOZ_ASSERT(mUnit == eUnit_ComplexColor, "unit mismatch"); - return *mValue.mComplexColor; - } - StyleComplexColor GetStyleComplexColorValue() const { - return GetComplexColorData().ToComplexColor(); - } - - UniquePtr TakeCSSValueListValue() { - nsCSSValueList* list = GetCSSValueListValue(); - mValue.mCSSValueList = nullptr; - mUnit = eUnit_Null; - return UniquePtr(list); - } - UniquePtr TakeCSSValuePairListValue() { - nsCSSValuePairList* list = GetCSSValuePairListValue(); - mValue.mCSSValuePairList = nullptr; - mUnit = eUnit_Null; - return UniquePtr(list); - } - - explicit StyleAnimationValue(Unit aUnit = eUnit_Null) : mUnit(aUnit) { - NS_ASSERTION(aUnit == eUnit_Null || aUnit == eUnit_Normal || - aUnit == eUnit_Auto || aUnit == eUnit_None, - "must be valueless unit"); - } - StyleAnimationValue(const StyleAnimationValue& aOther) - : mUnit(eUnit_Null) { *this = aOther; } - StyleAnimationValue(StyleAnimationValue&& aOther) - : mUnit(aOther.mUnit) - , mValue(aOther.mValue) - { - aOther.mUnit = eUnit_Null; - } - enum IntegerConstructorType { IntegerConstructor }; - StyleAnimationValue(int32_t aInt, Unit aUnit, IntegerConstructorType); - enum CoordConstructorType { CoordConstructor }; - StyleAnimationValue(nscoord aLength, CoordConstructorType); - enum PercentConstructorType { PercentConstructor }; - StyleAnimationValue(float aPercent, PercentConstructorType); - enum FloatConstructorType { FloatConstructor }; - StyleAnimationValue(float aFloat, FloatConstructorType); - enum ColorConstructorType { ColorConstructor }; - StyleAnimationValue(nscolor aColor, ColorConstructorType); - - ~StyleAnimationValue() { FreeValue(); } - - void SetNormalValue(); - void SetAutoValue(); - void SetNoneValue(); - void SetIntValue(int32_t aInt, Unit aUnit); - template::value>::type> - void SetEnumValue(T aInt) - { - static_assert(mozilla::EnumTypeFitsWithin::value, - "aValue must be an enum that fits within mValue.mInt"); - SetIntValue(static_cast(aInt), eUnit_Enumerated); - } - void SetCoordValue(nscoord aCoord); - void SetPercentValue(float aPercent); - void SetFloatValue(float aFloat); - void SetColorValue(nscolor aColor); - void SetCurrentColorValue(); - void SetComplexColorValue(const StyleComplexColor& aColor); - void SetComplexColorValue(already_AddRefed aValue); - void SetUnparsedStringValue(const nsString& aString); - void SetCSSValueArrayValue(nsCSSValue::Array* aValue, Unit aUnit); - - // These setters take ownership of |aValue|, and are therefore named - // "SetAndAdopt*". - void SetAndAdoptCSSValueValue(nsCSSValue *aValue, Unit aUnit); - void SetAndAdoptCSSValuePairValue(nsCSSValuePair *aValue, Unit aUnit); - void SetAndAdoptCSSValueTripletValue(nsCSSValueTriplet *aValue, Unit aUnit); - void SetAndAdoptCSSRectValue(nsCSSRect *aValue, Unit aUnit); - void SetAndAdoptCSSValueListValue(nsCSSValueList *aValue, Unit aUnit); - void SetAndAdoptCSSValuePairListValue(nsCSSValuePairList *aValue); - - void SetTransformValue(nsCSSValueSharedList* aList); - - StyleAnimationValue& operator=(const StyleAnimationValue& aOther); - StyleAnimationValue& operator=(StyleAnimationValue&& aOther) - { - MOZ_ASSERT(this != &aOther, "Do not move itself"); - if (this != &aOther) { - FreeValue(); - mUnit = aOther.mUnit; - mValue = aOther.mValue; - aOther.mUnit = eUnit_Null; - } - return *this; - } - - bool operator==(const StyleAnimationValue& aOther) const; - bool operator!=(const StyleAnimationValue& aOther) const - { return !(*this == aOther); } - -private: - void FreeValue(); - - static const char16_t* GetBufferValue(nsStringBuffer* aBuffer) { - return static_cast(aBuffer->Data()); - } - - static bool IsIntUnit(Unit aUnit) { - return aUnit == eUnit_Enumerated || aUnit == eUnit_Visibility || - aUnit == eUnit_Integer; - } - static bool IsCSSValueUnit(Unit aUnit) { - return aUnit == eUnit_Color || - aUnit == eUnit_Calc || - aUnit == eUnit_ObjectPosition || - aUnit == eUnit_URL || - aUnit == eUnit_DiscreteCSSValue; - } - static bool IsCSSValuePairUnit(Unit aUnit) { - return aUnit == eUnit_CSSValuePair; - } - static bool IsCSSValueTripletUnit(Unit aUnit) { - return aUnit == eUnit_CSSValueTriplet; - } - static bool IsCSSRectUnit(Unit aUnit) { - return aUnit == eUnit_CSSRect; - } - static bool IsCSSValueArrayUnit(Unit aUnit) { - return aUnit == eUnit_Shape; - } - static bool IsCSSValueListUnit(Unit aUnit) { - return aUnit == eUnit_Dasharray || aUnit == eUnit_Filter || - aUnit == eUnit_Shadow || - aUnit == eUnit_BackgroundPositionCoord; - } - static bool IsCSSValueSharedListValue(Unit aUnit) { - return aUnit == eUnit_Transform; - } - static bool IsCSSValuePairListUnit(Unit aUnit) { - return aUnit == eUnit_CSSValuePairList; - } - static bool IsStringUnit(Unit aUnit) { - return aUnit == eUnit_UnparsedString; - } -}; -#endif struct AnimationValue { -#ifdef MOZ_OLD_STYLE - explicit AnimationValue(const StyleAnimationValue& aValue) - : mGecko(aValue) { } -#endif explicit AnimationValue(const RefPtr& aValue) : mServo(aValue) { } AnimationValue() = default; AnimationValue(const AnimationValue& aOther) -#ifdef MOZ_OLD_STYLE - : mGecko(aOther.mGecko) - , mServo(aOther.mServo) { } -#else : mServo(aOther.mServo) { } -#endif AnimationValue(AnimationValue&& aOther) -#ifdef MOZ_OLD_STYLE - : mGecko(Move(aOther.mGecko)), mServo(Move(aOther.mServo)) { } -#else : mServo(Move(aOther.mServo)) { } -#endif AnimationValue& operator=(const AnimationValue& aOther) { if (this != &aOther) { -#ifdef MOZ_OLD_STYLE - mGecko = aOther.mGecko; -#endif mServo = aOther.mServo; } return *this; @@ -609,9 +65,6 @@ struct AnimationValue { MOZ_ASSERT(this != &aOther, "Do not move itself"); if (this != &aOther) { -#ifdef MOZ_OLD_STYLE - mGecko = Move(aOther.mGecko); -#endif mServo = Move(aOther.mServo); } return *this; @@ -622,11 +75,6 @@ struct AnimationValue bool IsNull() const { -#ifdef MOZ_OLD_STYLE - if (!mGecko.IsNull()) { - return false; - } -#endif return !mServo; } @@ -676,15 +124,11 @@ struct AnimationValue // FIXME: After obsoleting StyleAnimationValue, we should remove mGecko, and // make AnimationValue a wrapper of RawServoAnimationValue to hide these // FFIs. -#ifdef MOZ_OLD_STYLE - StyleAnimationValue mGecko; -#else // Ideally we would use conditional compilation based on MOZ_OLD_STYLE in the // Servo code that wants to initialize mGecko, but that seems tricky. So for // now, just define a dummy member variable that its initialization code will // work on, even when the old style system is compiled out. uintptr_t mGecko; -#endif RefPtr mServo; }; diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index b0f39dea8719..8328632d4f44 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -359,13 +359,6 @@ public: int32_t GetType() const override; -#ifdef MOZ_OLD_STYLE - CSSStyleSheet* GetStyleSheet() const - { - StyleSheet* sheet = Rule::GetStyleSheet(); - return sheet ? sheet->AsGecko() : nullptr; - } -#endif already_AddRefed Clone() const override; diff --git a/layout/style/StyleSetHandle.h b/layout/style/StyleSetHandle.h index 69bf2c91b647..833d2b9de3f4 100644 --- a/layout/style/StyleSetHandle.h +++ b/layout/style/StyleSetHandle.h @@ -64,21 +64,13 @@ public: bool IsGecko() const { -#ifdef MOZ_OLD_STYLE - return !IsServo(); -#else return false; -#endif } bool IsServo() const { MOZ_ASSERT(mValue, "StyleSetHandle null pointer dereference"); -#ifdef MOZ_STYLO return mValue & SERVO_BIT; -#else - return false; -#endif } StyleBackendType BackendType() const @@ -87,13 +79,6 @@ public: StyleBackendType::Servo; } -#ifdef MOZ_OLD_STYLE - nsStyleSet* AsGecko() - { - MOZ_ASSERT(IsGecko()); - return reinterpret_cast(mValue); - } -#endif ServoStyleSet* AsServo() { @@ -101,17 +86,8 @@ public: return reinterpret_cast(mValue & ~SERVO_BIT); } -#ifdef MOZ_OLD_STYLE - nsStyleSet* GetAsGecko() { return IsGecko() ? AsGecko() : nullptr; } -#endif ServoStyleSet* GetAsServo() { return IsServo() ? AsServo() : nullptr; } -#ifdef MOZ_OLD_STYLE - const nsStyleSet* AsGecko() const - { - return const_cast(this)->AsGecko(); - } -#endif const ServoStyleSet* AsServo() const { @@ -119,9 +95,6 @@ public: return const_cast(this)->AsServo(); } -#ifdef MOZ_OLD_STYLE - const nsStyleSet* GetAsGecko() const { return IsGecko() ? AsGecko() : nullptr; } -#endif const ServoStyleSet* GetAsServo() const { return IsServo() ? AsServo() : nullptr; } // These inline methods are defined in StyleSetHandleInlines.h. @@ -238,16 +211,11 @@ public: StyleSetHandle& operator=(ServoStyleSet* aStyleSet) { -#ifdef MOZ_STYLO MOZ_ASSERT(!(reinterpret_cast(aStyleSet) & SERVO_BIT), "least significant bit shouldn't be set; we use it for state"); mPtr.mValue = aStyleSet ? (reinterpret_cast(aStyleSet) | SERVO_BIT) : 0; return *this; -#else - MOZ_CRASH("should not have a ServoStyleSet object when MOZ_STYLO is " - "disabled"); -#endif } // Make StyleSetHandle usable in boolean contexts. diff --git a/layout/style/StyleSetHandleInlines.h b/layout/style/StyleSetHandleInlines.h index c888f8b6d5a3..4321a21b0526 100644 --- a/layout/style/StyleSetHandleInlines.h +++ b/layout/style/StyleSetHandleInlines.h @@ -10,31 +10,8 @@ #include "mozilla/StyleSheetInlines.h" #include "mozilla/ServoStyleContext.h" #include "mozilla/ServoStyleSet.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoStyleContext.h" -#include "nsStyleSet.h" -#endif #include "nsStyleContext.h" -#ifdef MOZ_OLD_STYLE - -#define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \ - if (IsGecko()) { \ - return AsGecko()->method_ geckoargs_; \ - } else { \ - return AsServo()->method_ servoargs_; \ - } - -#define FORWARD_WITH_PARENT(method_, parent_, args_) \ - if (IsGecko()) { \ - auto* parent = parent_ ? parent_->AsGecko() : nullptr; \ - return AsGecko()->method_ args_; \ - } else { \ - auto* parent = parent_ ? parent_->AsServo() : nullptr; \ - return AsServo()->method_ args_; \ - } - -#else #define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \ return AsServo()->method_ servoargs_; @@ -43,7 +20,6 @@ auto* parent = parent_ ? parent_->AsServo() : nullptr; \ return AsServo()->method_ args_; -#endif #define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_) @@ -54,12 +30,7 @@ StyleSetHandle::Ptr::Delete() { if (mValue) { if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - delete AsGecko(); - return; -#else MOZ_CRASH("old style system disabled"); -#endif } delete AsServo(); } @@ -123,13 +94,7 @@ StyleSetHandle::Ptr::ResolveStyleFor(dom::Element* aElement, TreeMatchContext* aTreeMatchContext) { if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(aTreeMatchContext); - auto* parent = aParentContext ? aParentContext->AsGecko() : nullptr; - return AsGecko()->ResolveStyleFor(aElement, parent, aMayCompute, *aTreeMatchContext); -#else MOZ_CRASH("old style system disabled"); -#endif } auto* parent = aParentContext ? aParentContext->AsServo() : nullptr; @@ -216,15 +181,7 @@ StyleSetHandle::Ptr::ReplaceSheets(SheetType aType, const nsTArray>& aNewSheets) { if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - nsTArray> newSheets(aNewSheets.Length()); - for (auto& sheet : aNewSheets) { - newSheets.AppendElement(sheet->AsGecko()); - } - return AsGecko()->ReplaceSheets(aType, newSheets); -#else MOZ_CRASH("old style system disabled"); -#endif } nsTArray> newSheets(aNewSheets.Length()); @@ -345,14 +302,7 @@ StyleSetHandle::Ptr::ProbePseudoElementStyle(dom::Element* aParentElement, TreeMatchContext* aTreeMatchContext) { if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - MOZ_ASSERT(aTreeMatchContext); - auto* parent = aParentContext ? aParentContext->AsGecko() : nullptr; - return AsGecko()->ProbePseudoElementStyle(aParentElement, aType, parent, - *aTreeMatchContext); -#else MOZ_CRASH("old style system disabled"); -#endif } auto* parent = aParentContext ? aParentContext->AsServo() : nullptr; @@ -363,12 +313,7 @@ void StyleSetHandle::Ptr::RootStyleContextAdded() { if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - AsGecko()->RootStyleContextAdded(); - return; -#else MOZ_CRASH("old style system disabled"); -#endif } // Not needed. @@ -378,12 +323,7 @@ void StyleSetHandle::Ptr::RootStyleContextRemoved() { if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - AsGecko()->RootStyleContextRemoved(); - return; -#else MOZ_CRASH("old style system disabled"); -#endif } // Not needed. diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index ca56adfbb8c4..50f4028dfd46 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -19,9 +19,6 @@ #include "mozilla/ServoStyleSheet.h" #include "mozilla/StyleSetHandleInlines.h" #include "mozilla/StyleSheetInlines.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/CSSStyleSheet.h" -#endif #include "mozAutoDocUpdate.h" #include "NullPrincipal.h" @@ -84,11 +81,7 @@ StyleSheet::LastRelease() UnparentChildren(); if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - AsGecko()->LastRelease(); -#else MOZ_CRASH("old style system disabled"); -#endif } else { AsServo()->LastRelease(); } @@ -405,17 +398,7 @@ StyleSheet::EnsureUniqueInner() mInner = clone; if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - // Ensure we're using the new rules. - // - // NOTE: In Servo, all kind of changes that change the set of selectors or - // rules we match are covered by the PresShell notifications. In Gecko - // that's true too, but this is probably needed because selectors are not - // refcounted and can become stale. - AsGecko()->ClearRuleCascades(); -#else MOZ_CRASH("old style system disabled"); -#endif } else { // Fixup the child lists and parent links in the Servo sheet. This is done // here instead of in StyleSheetInner::CloneFor, because it's just more @@ -441,19 +424,11 @@ StyleSheet::AppendAllChildSheets(nsTArray& aArray) // WebIDL CSSStyleSheet API -#ifdef MOZ_OLD_STYLE -#define FORWARD_INTERNAL(method_, args_) \ - if (IsServo()) { \ - return AsServo()->method_ args_; \ - } \ - return AsGecko()->method_ args_; -#else #define FORWARD_INTERNAL(method_, args_) \ if (IsServo()) { \ return AsServo()->method_ args_; \ } \ MOZ_CRASH("old style system disabled"); -#endif dom::CSSRuleList* StyleSheet::GetCssRules(nsIPrincipal& aSubjectPrincipal, @@ -629,11 +604,7 @@ StyleSheet::InsertRuleIntoGroup(const nsAString& aRule, nsresult result; if (IsGecko()) { -#ifdef MOZ_OLD_STYLE - result = AsGecko()->InsertRuleIntoGroupInternal(aRule, aGroup, aIndex); -#else MOZ_CRASH("old style system disabled"); -#endif } else { result = AsServo()->InsertRuleIntoGroupInternal(aRule, aGroup, aIndex); } diff --git a/layout/style/StyleSheetInlines.h b/layout/style/StyleSheetInlines.h index 1d668091dd86..5639389ae006 100644 --- a/layout/style/StyleSheetInlines.h +++ b/layout/style/StyleSheetInlines.h @@ -9,9 +9,6 @@ #include "mozilla/StyleSheetInfo.h" #include "mozilla/ServoStyleSheet.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/CSSStyleSheet.h" -#endif #include "nsINode.h" namespace mozilla { diff --git a/layout/style/nsAnimationManager.cpp b/layout/style/nsAnimationManager.cpp index a0bfa48f5d4f..a9c25f91bf70 100755 --- a/layout/style/nsAnimationManager.cpp +++ b/layout/style/nsAnimationManager.cpp @@ -20,15 +20,8 @@ #include "mozilla/dom/KeyframeEffectReadOnly.h" #include "nsPresContext.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsStyleChangeList.h" #include "nsContentUtils.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRules.h" -#include "mozilla/GeckoRestyleManager.h" -#endif #include "nsLayoutUtils.h" #include "nsIFrame.h" #include "nsIDocument.h" @@ -355,52 +348,6 @@ PopExistingAnimation(const nsAtom* aName, return nullptr; } -#ifdef MOZ_OLD_STYLE -class ResolvedStyleCache { -public: - ResolvedStyleCache() : mCache() {} - GeckoStyleContext* Get(nsPresContext* aPresContext, - GeckoStyleContext* aParentStyleContext, - Declaration* aKeyframeDeclaration); - -private: - nsRefPtrHashtable, GeckoStyleContext> mCache; -}; - -GeckoStyleContext* -ResolvedStyleCache::Get(nsPresContext* aPresContext, - GeckoStyleContext* aParentStyleContext, - Declaration* aKeyframeDeclaration) -{ - // FIXME (spec): The css3-animations spec isn't very clear about how - // properties are resolved when they have values that depend on other - // properties (e.g., values in 'em'). I presume that they're resolved - // relative to the other styles of the element. The question is - // whether they are resolved relative to other animations: I assume - // that they're not, since that would prevent us from caching a lot of - // data that we'd really like to cache (in particular, the - // StyleAnimationValue values in AnimationPropertySegment). - GeckoStyleContext* result = mCache.GetWeak(aKeyframeDeclaration); - if (!result) { - aKeyframeDeclaration->SetImmutable(); - // The spec says that !important declarations should just be ignored - MOZ_ASSERT(!aKeyframeDeclaration->HasImportantData(), - "Keyframe rule has !important data"); - - nsCOMArray rules; - rules.AppendObject(aKeyframeDeclaration); - MOZ_ASSERT(aPresContext->StyleSet()->IsGecko(), - "ServoStyleSet should not use nsAnimationManager for " - "animations"); - RefPtr resultStrong = - aPresContext->StyleSet()->AsGecko()-> - ResolveStyleByAddingRules(aParentStyleContext, rules); - mCache.Put(aKeyframeDeclaration, resultStrong); - result = resultStrong; - } - return result; -} -#endif class MOZ_STACK_CLASS ServoCSSAnimationBuilder final { public: @@ -470,58 +417,6 @@ private: const ServoStyleContext* mStyleContext; }; -#ifdef MOZ_OLD_STYLE -class MOZ_STACK_CLASS GeckoCSSAnimationBuilder final { -public: - GeckoCSSAnimationBuilder(GeckoStyleContext* aStyleContext, - const NonOwningAnimationTarget& aTarget) - : mStyleContext(aStyleContext) - , mTarget(aTarget) - { - MOZ_ASSERT(aStyleContext); - MOZ_ASSERT(aTarget.mElement); - } - - bool BuildKeyframes(nsPresContext* aPresContext, - nsAtom* aName, - const nsTimingFunction& aTimingFunction, - nsTArray& aKeyframs); - void SetKeyframes(KeyframeEffectReadOnly& aEffect, - nsTArray&& aKeyframes) - { - aEffect.SetKeyframes(Move(aKeyframes), mStyleContext); - } - - void NotifyNewOrRemovedAnimation(const Animation&) {} - -private: - nsTArray BuildAnimationFrames(nsPresContext* aPresContext, - const nsTimingFunction& aTimingFunction, - const nsCSSKeyframesRule* aRule); - Maybe GetKeyframeTimingFunction( - nsPresContext* aPresContext, - nsCSSKeyframeRule* aKeyframeRule, - const Maybe& aInheritedTimingFunction); - nsTArray GetKeyframePropertyValues( - nsPresContext* aPresContext, - nsCSSKeyframeRule* aKeyframeRule, - nsCSSPropertyIDSet& aAnimatedProperties); - void FillInMissingKeyframeValues( - nsCSSPropertyIDSet aAnimatedProperties, - nsCSSPropertyIDSet aPropertiesSetAtStart, - nsCSSPropertyIDSet aPropertiesSetAtEnd, - const Maybe& aInheritedTimingFunction, - nsTArray& aKeyframes); - - RefPtr mStyleContext; - NonOwningAnimationTarget mTarget; - - ResolvedStyleCache mResolvedStyles; -}; - -static Maybe -ConvertTimingFunction(const nsTimingFunction& aTimingFunction); -#endif template static void @@ -659,353 +554,6 @@ BuildAnimation(nsPresContext* aPresContext, return animation.forget(); } -#ifdef MOZ_OLD_STYLE -bool -GeckoCSSAnimationBuilder::BuildKeyframes(nsPresContext* aPresContext, - nsAtom* aName, - const nsTimingFunction& aTimingFunction, - nsTArray& aKeyframes) -{ - MOZ_ASSERT(aPresContext); - MOZ_ASSERT(aPresContext->StyleSet()->IsGecko()); - - nsCSSKeyframesRule* rule = - aPresContext->StyleSet()->AsGecko()->KeyframesRuleForName(aName); - if (!rule) { - return false; - } - - aKeyframes = BuildAnimationFrames(aPresContext, aTimingFunction, rule); - - return true; -} - -nsTArray -GeckoCSSAnimationBuilder::BuildAnimationFrames( - nsPresContext* aPresContext, - const nsTimingFunction& aTimingFunction, - const nsCSSKeyframesRule* aRule) -{ - // Ideally we'd like to build up a set of Keyframe objects that more-or-less - // reflect the keyframes as-specified in the @keyframes rule(s) so that - // authors get something intuitive when they call anim.effect.getKeyframes(). - // - // That, however, proves to be difficult because the way CSS declarations are - // processed differs from how we are able to represent keyframes as - // JavaScript objects in the Web Animations API. - // - // For example, - // - // { margin: 10px; margin-left: 20px } - // - // could be represented as: - // - // { margin: '10px', marginLeft: '20px' } - // - // BUT: - // - // { margin-left: 20px; margin: 10px } - // - // would be represented as: - // - // { margin: '10px' } - // - // Likewise, - // - // { margin-left: 20px; margin-left: 30px } - // - // would be represented as: - // - // { marginLeft: '30px' } - // - // As such, the mapping between source @keyframes and the Keyframe objects - // becomes obscured. The deviation is even more significant when we consider - // cascading between @keyframes rules and variable references in shorthand - // properties. - // - // We could, perhaps, produce a mapping that makes sense most of the time - // but it would be complex and need to be specified and implemented - // interoperably. Instead, for now, for CSS Animations (and CSS Transitions, - // for that matter) we resolve values on @keyframes down to computed values - // (thereby expanding shorthands and variable references) and then pick up the - // last value for each longhand property at each offset. - - // FIXME: There is a pending spec change to make multiple @keyframes - // rules with the same name cascade but we don't support that yet. - - Maybe inheritedTimingFunction = - ConvertTimingFunction(aTimingFunction); - - // First, make up Keyframe objects for each rule - nsTArray keyframes; - nsCSSPropertyIDSet animatedProperties; - - for (auto ruleIdx = 0, ruleEnd = aRule->StyleRuleCount(); - ruleIdx != ruleEnd; ++ruleIdx) { - css::Rule* cssRule = aRule->GetStyleRuleAt(ruleIdx); - MOZ_ASSERT(cssRule, "must have rule"); - MOZ_ASSERT(cssRule->GetType() == css::Rule::KEYFRAME_RULE, - "must be keyframe rule"); - nsCSSKeyframeRule* keyframeRule = static_cast(cssRule); - - const nsTArray& keys = keyframeRule->GetKeys(); - for (float key : keys) { - if (key < 0.0f || key > 1.0f) { - continue; - } - - Keyframe keyframe; - keyframe.mOffset.emplace(key); - keyframe.mTimingFunction = - GetKeyframeTimingFunction(aPresContext, keyframeRule, - inheritedTimingFunction); - keyframe.mPropertyValues = - GetKeyframePropertyValues(aPresContext, keyframeRule, - animatedProperties); - - keyframes.AppendElement(Move(keyframe)); - } - } - - // Next, stable sort by offset - std::stable_sort(keyframes.begin(), keyframes.end(), - [](const Keyframe& a, const Keyframe& b) - { - return a.mOffset < b.mOffset; - }); - - // Then walk backwards through the keyframes and drop overridden properties. - nsCSSPropertyIDSet propertiesSetAtCurrentOffset; - nsCSSPropertyIDSet propertiesSetAtStart; - nsCSSPropertyIDSet propertiesSetAtEnd; - double currentOffset = -1.0; - for (size_t keyframeIdx = keyframes.Length(); - keyframeIdx > 0; - --keyframeIdx) { - Keyframe& keyframe = keyframes[keyframeIdx - 1]; - MOZ_ASSERT(keyframe.mOffset, "Should have filled in the offset"); - - if (keyframe.mOffset.value() != currentOffset) { - propertiesSetAtCurrentOffset.Empty(); - currentOffset = keyframe.mOffset.value(); - } - - // Get the set of properties from this keyframe that have not - // already been set at this offset. - nsTArray uniquePropertyValues; - uniquePropertyValues.SetCapacity(keyframe.mPropertyValues.Length()); - for (const PropertyValuePair& pair : keyframe.mPropertyValues) { - if (!propertiesSetAtCurrentOffset.HasProperty(pair.mProperty)) { - uniquePropertyValues.AppendElement(pair); - propertiesSetAtCurrentOffset.AddProperty(pair.mProperty); - - if (currentOffset == 0.0) { - propertiesSetAtStart.AddProperty(pair.mProperty); - } else if (currentOffset == 1.0) { - propertiesSetAtEnd.AddProperty(pair.mProperty); - } - } - } - - // If we have a keyframe at the same offset with the same timing - // function we should merge our (unique) values into it. - // Otherwise, we should update the existing keyframe with only the - // unique properties. - // - // Bug 1293490: We should also match composite modes here. - Keyframe* existingKeyframe = nullptr; - // Don't bother searching for an existing keyframe if we don't - // have anything to contribute to it. - if (!uniquePropertyValues.IsEmpty()) { - for (size_t i = keyframeIdx; i < keyframes.Length(); i++) { - Keyframe& kf = keyframes[i]; - if (kf.mOffset.value() != currentOffset) { - break; - } - if (kf.mTimingFunction == keyframe.mTimingFunction) { - existingKeyframe = &kf; - break; - } - } - } - - if (existingKeyframe) { - existingKeyframe-> - mPropertyValues.AppendElements(Move(uniquePropertyValues)); - keyframe.mPropertyValues.Clear(); - } else { - keyframe.mPropertyValues.SwapElements(uniquePropertyValues); - } - - // Check for a now-empty keyframe - if (keyframe.mPropertyValues.IsEmpty()) { - keyframes.RemoveElementAt(keyframeIdx - 1); - // existingKeyframe might dangle now - } - } - - // Finally, we need to look for any animated properties that have an - // implicit 'to' or 'from' value and fill in the appropriate keyframe - // with the current computed style. - FillInMissingKeyframeValues(animatedProperties, propertiesSetAtStart, - propertiesSetAtEnd, inheritedTimingFunction, - keyframes); - - return keyframes; -} - -Maybe -GeckoCSSAnimationBuilder::GetKeyframeTimingFunction( - nsPresContext* aPresContext, - nsCSSKeyframeRule* aKeyframeRule, - const Maybe& aInheritedTimingFunction) -{ - Maybe result; - - if (aKeyframeRule->Declaration() && - aKeyframeRule->Declaration()->HasProperty( - eCSSProperty_animation_timing_function)) { - RefPtr keyframeRuleContext = - mResolvedStyles.Get(aPresContext, mStyleContext, - aKeyframeRule->Declaration()); - const nsTimingFunction& tf = keyframeRuleContext->StyleDisplay()-> - mAnimations[0].GetTimingFunction(); - result = ConvertTimingFunction(tf); - } else { - result = aInheritedTimingFunction; - } - - return result; -} - -static Maybe -ConvertTimingFunction(const nsTimingFunction& aTimingFunction) -{ - Maybe result; - - if (aTimingFunction.mType != nsTimingFunction::Type::Linear) { - result.emplace(); - result->Init(aTimingFunction); - } - - return result; -} - -nsTArray -GeckoCSSAnimationBuilder::GetKeyframePropertyValues( - nsPresContext* aPresContext, - nsCSSKeyframeRule* aKeyframeRule, - nsCSSPropertyIDSet& aAnimatedProperties) -{ - nsTArray result; - RefPtr styleContext = - mResolvedStyles.Get(aPresContext, mStyleContext, - aKeyframeRule->Declaration()); - - for (nsCSSPropertyID prop = nsCSSPropertyID(0); - prop < eCSSProperty_COUNT_no_shorthands; - prop = nsCSSPropertyID(prop + 1)) { - if (nsCSSProps::kAnimTypeTable[prop] == eStyleAnimType_None || - !aKeyframeRule->Declaration()->HasNonImportantValueFor(prop)) { - continue; - } - - StyleAnimationValue computedValue; - if (!StyleAnimationValue::ExtractComputedValue(prop, styleContext, - computedValue)) { - continue; - } - - nsCSSValue propertyValue; - DebugOnly uncomputeResult = - StyleAnimationValue::UncomputeValue(prop, Move(computedValue), - propertyValue); - MOZ_ASSERT(uncomputeResult, - "Unable to get specified value from computed value"); - MOZ_ASSERT(propertyValue.GetUnit() != eCSSUnit_Null, - "Not expecting to read invalid properties"); - - result.AppendElement(Move(PropertyValuePair(prop, Move(propertyValue)))); - aAnimatedProperties.AddProperty(prop); - } - - return result; -} - -void -GeckoCSSAnimationBuilder::FillInMissingKeyframeValues( - nsCSSPropertyIDSet aAnimatedProperties, - nsCSSPropertyIDSet aPropertiesSetAtStart, - nsCSSPropertyIDSet aPropertiesSetAtEnd, - const Maybe& aInheritedTimingFunction, - nsTArray& aKeyframes) -{ - static const size_t kNotSet = static_cast(-1); - - // Find/create the keyframe to add start values to - size_t startKeyframeIndex = kNotSet; - if (!aAnimatedProperties.Equals(aPropertiesSetAtStart) && - !nsAnimationManager::FindMatchingKeyframe(aKeyframes, - 0.0, - aInheritedTimingFunction, - startKeyframeIndex)) { - Keyframe newKeyframe; - newKeyframe.mOffset.emplace(0.0); - newKeyframe.mTimingFunction = aInheritedTimingFunction; - aKeyframes.InsertElementAt(startKeyframeIndex, Move(newKeyframe)); - } - - // Find/create the keyframe to add end values to - size_t endKeyframeIndex = kNotSet; - if (!aAnimatedProperties.Equals(aPropertiesSetAtEnd)) { - if (!nsAnimationManager::FindMatchingKeyframe(Reversed(aKeyframes), - 1.0, - aInheritedTimingFunction, - endKeyframeIndex)) { - Keyframe newKeyframe; - newKeyframe.mOffset.emplace(1.0); - newKeyframe.mTimingFunction = aInheritedTimingFunction; - aKeyframes.AppendElement(Move(newKeyframe)); - endKeyframeIndex = aKeyframes.Length() - 1; - } else { - // endKeyframeIndex is currently a count from the end of the array - // so we need to reverse it. - endKeyframeIndex = aKeyframes.Length() - 1 - endKeyframeIndex; - } - } - - if (startKeyframeIndex == kNotSet && endKeyframeIndex == kNotSet) { - return; - } - - // Now that we have finished manipulating aKeyframes, it is safe to - // take pointers to its elements. - Keyframe* startKeyframe = startKeyframeIndex == kNotSet - ? nullptr : &aKeyframes[startKeyframeIndex]; - Keyframe* endKeyframe = endKeyframeIndex == kNotSet - ? nullptr : &aKeyframes[endKeyframeIndex]; - - // Iterate through all properties and fill-in missing values - for (nsCSSPropertyID prop = nsCSSPropertyID(0); - prop < eCSSProperty_COUNT_no_shorthands; - prop = nsCSSPropertyID(prop + 1)) { - if (!aAnimatedProperties.HasProperty(prop)) { - continue; - } - - if (startKeyframe && !aPropertiesSetAtStart.HasProperty(prop)) { - // An uninitialized nsCSSValue represents the underlying value. - PropertyValuePair propertyValue(prop, Move(nsCSSValue())); - startKeyframe->mPropertyValues.AppendElement(Move(propertyValue)); - } - if (endKeyframe && !aPropertiesSetAtEnd.HasProperty(prop)) { - // An uninitialized nsCSSValue represents the underlying value. - PropertyValuePair propertyValue(prop, Move(nsCSSValue())); - endKeyframe->mPropertyValues.AppendElement(Move(propertyValue)); - } - } -} -#endif template static nsAnimationManager::OwningCSSAnimationPtrArray @@ -1046,29 +594,6 @@ BuildAnimations(nsPresContext* aPresContext, return result; } -#ifdef MOZ_OLD_STYLE -void -nsAnimationManager::UpdateAnimations(GeckoStyleContext* aStyleContext, - mozilla::dom::Element* aElement) -{ - MOZ_ASSERT(mPresContext->IsDynamic(), - "Should not update animations for print or print preview"); - MOZ_ASSERT(aElement->IsInComposedDoc(), - "Should not update animations that are not attached to the " - "document tree"); - - if (aStyleContext->IsInDisplayNoneSubtree()) { - StopAnimationsForElement(aElement, aStyleContext->GetPseudoType()); - return; - } - - NonOwningAnimationTarget target(aElement, aStyleContext->GetPseudoType()); - GeckoCSSAnimationBuilder builder(aStyleContext, target); - - const nsStyleDisplay* disp = aStyleContext->StyleDisplay(); - DoUpdateAnimations(target, *disp, builder); -} -#endif void nsAnimationManager::UpdateAnimations( diff --git a/layout/style/nsAnimationManager.h b/layout/style/nsAnimationManager.h index e7a0276363d7..0bce341c8131 100644 --- a/layout/style/nsAnimationManager.h +++ b/layout/style/nsAnimationManager.h @@ -290,18 +290,6 @@ public: typedef nsTArray> OwningCSSAnimationPtrArray; -#ifdef MOZ_OLD_STYLE - /** - * Update the set of animations on |aElement| based on |aStyleContext|. - * If necessary, this will notify the corresponding EffectCompositor so - * that it can update its animation rule. - * - * aStyleContext may be a style context for aElement or for its - * :before or :after pseudo-element. - */ - void UpdateAnimations(mozilla::GeckoStyleContext* aStyleContext, - mozilla::dom::Element* aElement); -#endif /** * This function does the same thing as the above UpdateAnimations() diff --git a/layout/style/nsCSSCounterStyleRule.cpp b/layout/style/nsCSSCounterStyleRule.cpp index 045aec30f351..f1c65c4000c3 100644 --- a/layout/style/nsCSSCounterStyleRule.cpp +++ b/layout/style/nsCSSCounterStyleRule.cpp @@ -130,12 +130,7 @@ nsCSSCounterStyleRule::SetName(const nsAString& aName) if (!doc || doc->IsStyledByServo()) { name = ServoCSSParser::ParseCounterStyleName(aName); } else { -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - name = parser.ParseCounterStyleName(aName, nullptr); -#else MOZ_CRASH("old style system disabled"); -#endif } if (name) { @@ -405,26 +400,14 @@ nsCSSCounterStyleRule::SetDescriptor(nsCSSCounterDesc aDescID, StyleSheet* sheet = GetStyleSheet(); -#ifdef MOZ_STYLO bool useServo = !sheet || sheet->IsServo(); -#else - bool useServo = false; -#endif if (useServo) { URLExtraData* data = sheet ? sheet->AsServo()->URLData() : nullptr; ok = ServoCSSParser::ParseCounterStyleDescriptor(aDescID, aValue, data, value); } else { -#ifdef MOZ_OLD_STYLE - nsCSSParser parser; - nsIURI* baseURL = sheet ? sheet->GetBaseURI() : nullptr; - nsIPrincipal* principal = sheet ? sheet->Principal() : nullptr; - ok = parser.ParseCounterDescriptor(aDescID, aValue, nullptr, - baseURL, principal, value); -#else MOZ_CRASH("old style system disabled"); -#endif } if (ok && CheckDescValue(GetSystem(), aDescID, value)) { diff --git a/layout/style/nsCSSParser.h b/layout/style/nsCSSParser.h index f854000b8c8f..131776719b66 100644 --- a/layout/style/nsCSSParser.h +++ b/layout/style/nsCSSParser.h @@ -9,352 +9,6 @@ #ifndef nsCSSParser_h___ #define nsCSSParser_h___ -#ifdef MOZ_OLD_STYLE - -#include "mozilla/Attributes.h" -#include "mozilla/css/Loader.h" -#include "mozilla/css/SheetLoadData.h" - -#include "nsCSSPropertyID.h" -#include "nsCSSScanner.h" -#include "nsCOMPtr.h" -#include "nsAutoPtr.h" -#include "nsStringFwd.h" -#include "nsTArrayForwardDeclare.h" - -class nsIPrincipal; -class nsIURI; -struct nsCSSSelectorList; -class nsMediaList; -class nsMediaQuery; -class nsCSSKeyframeRule; -class nsCSSValue; -struct nsRuleData; - -namespace mozilla { -class CSSStyleSheet; -class CSSVariableValues; -namespace css { -class Rule; -class Declaration; -class StyleRule; - -enum class SupportsParsingSettings { - Normal, - ImpliedParentheses -}; - -} // namespace css -} // namespace mozilla - -// Interface to the css parser. - -class MOZ_STACK_CLASS nsCSSParser { -public: - explicit nsCSSParser(mozilla::css::Loader* aLoader = nullptr, - mozilla::CSSStyleSheet* aSheet = nullptr); - ~nsCSSParser(); - - static void Shutdown(); - -private: - nsCSSParser(nsCSSParser const&) = delete; - nsCSSParser& operator=(nsCSSParser const&) = delete; - -public: - /** - * Parse aInput into the stylesheet that was previously passed to the - * constructor. Calling this method on an nsCSSParser that had nullptr - * passed in as the style sheet is an error. - * - * @param aInput the data to parse - * @param aSheetURL the URI to use as the sheet URI (for error reporting). - * This must match the URI of the sheet passed to - * the constructor. - * @param aBaseURI the URI to use for relative URI resolution - * @param aSheetPrincipal the principal of the stylesheet. This must match - * the principal of the sheet passed to the - * constructor. - * @param aLoadData the SheetLoadData for this sheet, if applicable. - * @param aLineNumber the line number of the first line of the sheet. - * @param aReusableSheets style sheets that can be reused by an @import. - * This can be nullptr. - */ - nsresult ParseSheet(const nsAString& aInput, - nsIURI* aSheetURL, - nsIURI* aBaseURI, - nsIPrincipal* aSheetPrincipal, - mozilla::css::SheetLoadData* aLoadData, - uint32_t aLineNumber, - mozilla::css::LoaderReusableStyleSheets* aReusableSheets = - nullptr); - - // Parse HTML style attribute or its equivalent in other markup - // languages. aBaseURL is the base url to use for relative links in - // the declaration. - already_AddRefed - ParseStyleAttribute(const nsAString& aAttributeValue, - nsIURI* aDocURL, - nsIURI* aBaseURL, - nsIPrincipal* aNodePrincipal); - - // Parse the body of a declaration block. Very similar to - // ParseStyleAttribute, but used under different circumstances. - // The contents of aDeclaration will be erased and replaced with the - // results of parsing; aChanged will be set true if the aDeclaration - // argument was modified. - nsresult ParseDeclarations(const nsAString& aBuffer, - nsIURI* aSheetURL, - nsIURI* aBaseURL, - nsIPrincipal* aSheetPrincipal, - mozilla::css::Declaration* aDeclaration, - bool* aChanged); - - nsresult ParseRule(const nsAString& aRule, - nsIURI* aSheetURL, - nsIURI* aBaseURL, - nsIPrincipal* aSheetPrincipal, - mozilla::css::Rule** aResult); - - // Parse the value of a single CSS property, and add or replace that - // property in aDeclaration. - // - // SVG "mapped attributes" (which correspond directly to CSS - // properties) are parsed slightly differently from regular CSS; in - // particular, units may be omitted from . The 'aIsSVGMode' - // argument controls this quirk. Note that this *only* applies to - // mapped attributes, not inline styles or full style sheets in SVG. - void ParseProperty(const nsCSSPropertyID aPropID, - const nsAString& aPropValue, - nsIURI* aSheetURL, - nsIURI* aBaseURL, - nsIPrincipal* aSheetPrincipal, - mozilla::css::Declaration* aDeclaration, - bool* aChanged, - bool aIsImportant, - bool aIsSVGMode = false); - - // Same as ParseProperty but returns an nsCSSValue in aResult - // rather than storing the property in a Declaration. aPropID - // must be a longhand property. - void ParseLonghandProperty(const nsCSSPropertyID aPropID, - const nsAString& aPropValue, - nsIURI* aSheetURL, - nsIURI* aBaseURL, - nsIPrincipal* aSheetPrincipal, - nsCSSValue& aResult); - - // Parse the value of a CSS transform property. Returns - // whether the value was successfully parsed. If - // aDisallowRelativeValues is true then this method will - // only successfully parse if all values are numbers or - // have non-relative dimensions. - bool ParseTransformProperty(const nsAString& aPropValue, - bool aDisallowRelativeValues, - nsCSSValue& aResult); - - // The same as ParseProperty but for a variable. - void ParseVariable(const nsAString& aVariableName, - const nsAString& aPropValue, - nsIURI* aSheetURL, - nsIURI* aBaseURL, - nsIPrincipal* aSheetPrincipal, - mozilla::css::Declaration* aDeclaration, - bool* aChanged, - bool aIsImportant); - /** - * Parse aBuffer into a media list |aMediaList|, which must be non-null, - * replacing its current contents. |aURL| and |aLineNumber| are used for error - * reporting. - */ - void ParseMediaList(const nsAString& aBuffer, - nsIURI* aURL, - uint32_t aLineNumber, - nsMediaList* aMediaList, - mozilla::dom::CallerType aCallerType = - mozilla::dom::CallerType::NonSystem); - - /* - * Parse aBuffer into a list of media queries and their associated values, - * according to grammar: - * = #? - * = ? - * - * Note that this grammar is top-level: The function expects to consume the - * entire input buffer. - * - * Output arrays overwritten (not appended) and are cleared in case of parse - * failure. - */ - bool ParseSourceSizeList(const nsAString& aBuffer, - nsIURI* aURI, // for error reporting - uint32_t aLineNumber, // for error reporting - InfallibleTArray< nsAutoPtr >& aQueries, - InfallibleTArray& aValues); - - /** - * Parse aBuffer into a nsCSSValue |aValue|. Will return false - * if aBuffer is not a valid font family list. - */ - bool ParseFontFamilyListString(const nsAString& aBuffer, - nsIURI* aURL, - uint32_t aLineNumber, - nsCSSValue& aValue); - - /** - * Parse aBuffer into a nsCSSValue |aValue|. Will return false - * if aBuffer is not a valid CSS color specification. - * One can use nsRuleNode::ComputeColor to compute an nscolor from - * the returned nsCSSValue. - */ - bool ParseColorString(const nsAString& aBuffer, - nsIURI* aURL, - uint32_t aLineNumber, - nsCSSValue& aValue, - bool aSuppressErrors = false); - - /** - * Parse aBuffer into a nsCSSValue |aValue|. Will return false - * if aBuffer is not a valid CSS margin specification. - * One can use nsRuleNode::GetRectValue to compute an nsCSSRect from - * the returned nsCSSValue. - */ - bool ParseMarginString(const nsAString& aBuffer, - nsIURI* aURL, - uint32_t aLineNumber, - nsCSSValue& aValue, - bool aSuppressErrors = false); - - /** - * Parse aBuffer into a selector list. On success, caller must - * delete *aSelectorList when done with it. - */ - nsresult ParseSelectorString(const nsAString& aSelectorString, - nsIURI* aURL, - uint32_t aLineNumber, - nsCSSSelectorList** aSelectorList); - - /* - * Parse a keyframe rule (which goes inside an @keyframes rule). - * Return it if the parse was successful. - */ - already_AddRefed - ParseKeyframeRule(const nsAString& aBuffer, - nsIURI* aURL, - uint32_t aLineNumber); - - /* - * Parse a selector list for a keyframe rule. Return whether - * the parse succeeded. - */ - bool ParseKeyframeSelectorString(const nsAString& aSelectorString, - nsIURI* aURL, - uint32_t aLineNumber, - InfallibleTArray& aSelectorList); - - /** - * Parse a property and value and return whether the property/value pair - * is supported. - */ - bool EvaluateSupportsDeclaration(const nsAString& aProperty, - const nsAString& aValue, - nsIURI* aDocURL, - nsIURI* aBaseURL, - nsIPrincipal* aDocPrincipal); - - /** - * Parse an @supports condition and returns the result of evaluating the - * condition. - * - * The one-argument CSS.supports() allows for providing a parentheses-less - * @supports condition, i.e. the parentheses are "implied". In such a case, - * aSettings can be set to ImpliedParentheses. - */ - bool EvaluateSupportsCondition(const nsAString& aCondition, - nsIURI* aDocURL, - nsIURI* aBaseURL, - nsIPrincipal* aDocPrincipal, - mozilla::css::SupportsParsingSettings aSettings - = mozilla::css::SupportsParsingSettings::Normal); - - typedef void (*VariableEnumFunc)(const nsAString&, void*); - - /** - * Parses aPropertyValue as a property value and calls aFunc for each - * variable reference that is found. Returns false if there was - * a syntax error in the use of variable references. - */ - bool EnumerateVariableReferences(const nsAString& aPropertyValue, - VariableEnumFunc aFunc, - void* aData); - - /** - * Parses aPropertyValue as a property value and resolves variable references - * using the values in aVariables. - */ - bool ResolveVariableValue(const nsAString& aPropertyValue, - const mozilla::CSSVariableValues* aVariables, - nsString& aResult, - nsCSSTokenSerializationType& aFirstToken, - nsCSSTokenSerializationType& aLastToken); - - /** - * Parses a string as a CSS token stream value for particular property, - * resolving any variable references. The parsed property value is stored - * in the specified nsRuleData object. If aShorthandPropertyID has a value - * other than eCSSProperty_UNKNOWN, this is the property that will be parsed; - * otherwise, aPropertyID will be parsed. Either way, only aPropertyID, - * a longhand property, will be copied over to the rule data. - * - * If the property cannot be parsed, it will be treated as if 'initial' or - * 'inherit' were specified, for non-inherited and inherited properties - * respectively. - */ - void ParsePropertyWithVariableReferences( - nsCSSPropertyID aPropertyID, - nsCSSPropertyID aShorthandPropertyID, - const nsAString& aValue, - const mozilla::CSSVariableValues* aVariables, - nsRuleData* aRuleData, - nsIURI* aDocURL, - nsIURI* aBaseURL, - nsIPrincipal* aDocPrincipal, - mozilla::CSSStyleSheet* aSheet, - uint32_t aLineNumber, - uint32_t aLineOffset); - - /** - * Parses a string as a counter-style name. Returns nullptr if fails. - */ - already_AddRefed ParseCounterStyleName(const nsAString& aBuffer, - nsIURI* aURL); - - bool ParseCounterDescriptor(nsCSSCounterDesc aDescID, - const nsAString& aBuffer, - nsIURI* aSheetURL, - nsIURI* aBaseURL, - nsIPrincipal* aSheetPrincipal, - nsCSSValue& aValue); - - bool ParseFontFaceDescriptor(nsCSSFontDesc aDescID, - const nsAString& aBuffer, - nsIURI* aSheetURL, - nsIURI* aBaseURL, - nsIPrincipal* aSheetPrincipal, - nsCSSValue& aValue); - - // Check whether a given value can be applied to a property. - bool IsValueValidForProperty(const nsCSSPropertyID aPropID, - const nsAString& aPropValue); - -protected: - // This is a CSSParserImpl*, but if we expose that type name in this - // header, we can't put the type definition (in nsCSSParser.cpp) in - // the anonymous namespace. - void* mImpl; -}; - -#else namespace mozilla { namespace css { @@ -370,6 +24,5 @@ public: explicit nsCSSParser(mozilla::css::Loader* aLoader = nullptr) {} }; -#endif #endif /* nsCSSParser_h___ */ diff --git a/layout/style/nsCSSValue.cpp b/layout/style/nsCSSValue.cpp index 9efb8c7b15d1..0b186688614c 100644 --- a/layout/style/nsCSSValue.cpp +++ b/layout/style/nsCSSValue.cpp @@ -27,9 +27,6 @@ #include "nsPresContext.h" #include "nsStyleUtil.h" #include "nsDeviceContext.h" -#ifdef MOZ_OLD_STYLE -#include "nsStyleSet.h" -#endif #include "nsContentUtils.h" using namespace mozilla; diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 493ff7bfa547..ef1ea3b70a9c 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -39,9 +39,6 @@ #include "mozilla/IntegerRange.h" #include "mozilla/StyleSetHandle.h" #include "mozilla/StyleSetHandleInlines.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/GeckoRestyleManager.h" -#endif #include "mozilla/ServoRestyleManager.h" #include "mozilla/RestyleManagerInlines.h" #include "imgIRequest.h" @@ -107,35 +104,6 @@ GetBackgroundList(T nsStyleImageLayers::Layer::* aMember, return valueList.forget(); } -#ifdef MOZ_OLD_STYLE -// Whether there is any pending restyle for the element or any of its ancestors. -static bool -ContentNeedsRestyle(nsIContent* aContent) -{ - MOZ_ASSERT(aContent); - nsIContent* node = aContent; - while (node) { - if (node->IsElement()) { - MOZ_ASSERT(!node->IsGeneratedContentContainerForAfter() && - !node->IsGeneratedContentContainerForBefore()); - if (EffectSet::GetEffectSet(node->AsElement(), - CSSPseudoElementType::NotPseudo)) { - return true; - } - } - - // Check if the element has any flag for restyling. For Gecko, we also need - // another flag to know if there is any child has LaterSiblings restyle - // hint. - if (node->HasFlag(ELEMENT_ALL_RESTYLE_FLAGS | - ELEMENT_HAS_CHILD_WITH_LATER_SIBLINGS_HINT)) { - return true; - } - node = node->GetFlattenedTreeParent(); - } - return false; -} -#endif // Whether aDocument needs to restyle for aElement static bool @@ -204,20 +172,7 @@ DocumentNeedsRestyle( return restyleManager->HasPendingRestyleAncestor(aElement); } -#ifdef MOZ_OLD_STYLE - // For Gecko, first check if there is any pending restyle, then we check if - // any ancestor has dirty bits for restyle. - GeckoRestyleManager* restyleManager = - presContext->RestyleManager()->AsGecko(); - if (!presContext->EffectCompositor()->HasPendingStyleUpdates() && - !restyleManager->HasPendingRestyles()) { - return false; - } - - return ContentNeedsRestyle(aElement); -#else MOZ_CRASH("old style system disabled"); -#endif } /** @@ -473,11 +428,7 @@ nsComputedDOMStyle::Length() if (mStyleContext->IsServo()) { length += Servo_GetCustomPropertiesCount(mStyleContext->AsServo()); } else { -#ifdef MOZ_OLD_STYLE - length += StyleVariables()->mVariables.Count(); -#else MOZ_CRASH("old style system disabled"); -#endif } } @@ -527,126 +478,6 @@ nsComputedDOMStyle::GetStyleContext(Element* aElement, return GetStyleContextNoFlush(aElement, aPseudo, aStyleType); } -#ifdef MOZ_OLD_STYLE -namespace { -class MOZ_STACK_CLASS StyleResolver final -{ -public: - StyleResolver(nsPresContext* aPresContext, - nsComputedDOMStyle::AnimationFlag aAnimationFlag) - : mAnimationFlag(aAnimationFlag) - { - MOZ_ASSERT(aPresContext); - - // Nothing to do if we are going to resolve style *with* animation. - if (mAnimationFlag == nsComputedDOMStyle::eWithAnimation) { - return; - } - - // Set SkipAnimationRules flag if we are going to resolve style without - // animation. - if (aPresContext->RestyleManager()->IsGecko()) { - mRestyleManager = aPresContext->RestyleManager()->AsGecko(); - - mOldSkipAnimationRules = mRestyleManager->SkipAnimationRules(); - mRestyleManager->SetSkipAnimationRules(true); - } else { - NS_WARNING("stylo: can't skip animaition rules yet"); - } - } - - already_AddRefed - ResolveWithAnimation(nsStyleSet* aStyleSet, - Element* aElement, - CSSPseudoElementType aType, - GeckoStyleContext* aParentContext, - nsComputedDOMStyle::StyleType aStyleType, - bool aInDocWithShell) - { - MOZ_ASSERT(mAnimationFlag == nsComputedDOMStyle::eWithAnimation, - "AnimationFlag should be eWithAnimation"); - - RefPtr result; - - if (aType != CSSPseudoElementType::NotPseudo) { - nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement); - Element* pseudoElement = - frame && aInDocWithShell ? frame->GetPseudoElement(aType) : nullptr; - result = aStyleSet->ResolvePseudoElementStyle(aElement, aType, - aParentContext, - pseudoElement); - } else { - result = aStyleSet->ResolveStyleFor(aElement, aParentContext, - LazyComputeBehavior::Allow); - } - if (aStyleType == nsComputedDOMStyle::StyleType::eDefaultOnly) { - // We really only want the user and UA rules. Filter out the other ones. - nsTArray< nsCOMPtr > rules; - for (nsRuleNode* ruleNode = result->RuleNode(); - !ruleNode->IsRoot(); - ruleNode = ruleNode->GetParent()) { - if (ruleNode->GetLevel() == SheetType::Agent || - ruleNode->GetLevel() == SheetType::User) { - rules.AppendElement(ruleNode->GetRule()); - } - } - - // We want to build a list of user/ua rules that is in order from least to - // most important, so we have to reverse the list. - // Integer division to get "stop" is purposeful here: if length is odd, we - // don't have to do anything with the middle element of the array. - for (uint32_t i = 0, length = rules.Length(), stop = length / 2; - i < stop; ++i) { - rules[i].swap(rules[length - i - 1]); - } - - result = aStyleSet->ResolveStyleForRules(aParentContext, rules); - } - return result.forget(); - } - - already_AddRefed - ResolveWithoutAnimation(nsStyleSet* aStyleSet, - Element* aElement, - CSSPseudoElementType aType, - GeckoStyleContext* aParentContext, - bool aInDocWithShell) - { - MOZ_ASSERT(mAnimationFlag == nsComputedDOMStyle::eWithoutAnimation, - "AnimationFlag should be eWithoutAnimation"); - - RefPtr result; - - if (aType != CSSPseudoElementType::NotPseudo) { - nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement); - Element* pseudoElement = - frame && aInDocWithShell ? frame->GetPseudoElement(aType) : nullptr; - result = - aStyleSet->ResolvePseudoElementStyleWithoutAnimation( - aElement, aType, - aParentContext, - pseudoElement); - } else { - result = - aStyleSet->ResolveStyleWithoutAnimation(aElement, aParentContext); - } - return result.forget(); - } - - ~StyleResolver() - { - if (mRestyleManager) { - mRestyleManager->SetSkipAnimationRules(mOldSkipAnimationRules); - } - } - -private: - GeckoRestyleManager* mRestyleManager = nullptr; - bool mOldSkipAnimationRules = false; - nsComputedDOMStyle::AnimationFlag mAnimationFlag; -}; -} -#endif /** * The following function checks whether we need to explicitly resolve the style @@ -669,12 +500,7 @@ MustReresolveStyle(const nsStyleContext* aContext) return true; } -#ifdef MOZ_OLD_STYLE - return aContext->AsGecko()->GetParent() && - aContext->AsGecko()->GetParent()->HasPseudoElementData(); -#else MOZ_CRASH("old style system disabled"); -#endif } return false; @@ -756,14 +582,7 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement, nsPresContext* presContext = presShell->GetPresContext(); MOZ_ASSERT(presContext, "Should have a prescontext if we have a frame"); if (presContext && presContext->StyleSet()->IsGecko()) { -#ifdef MOZ_OLD_STYLE - nsStyleSet* styleSet = presContext->StyleSet()->AsGecko(); - return styleSet->ResolveStyleByRemovingAnimation( - aElement, result->AsGecko(), - eRestyle_AllHintsWithAnimations); -#else MOZ_CRASH("old style system disabled"); -#endif } else { Element* elementOrPseudoElement = EffectCompositor::GetElementToRestyle(aElement, pseudoType); @@ -815,35 +634,7 @@ nsComputedDOMStyle::DoGetStyleContextNoFlush(Element* aElement, result); } -#ifdef MOZ_OLD_STYLE - RefPtr parentContext; - nsIContent* parent = aPseudo ? aElement : aElement->GetParent(); - // Don't resolve parent context for document fragments. - if (parent && parent->IsElement()) { - RefPtr p = - DoGetStyleContextNoFlush(parent->AsElement(), nullptr, - aPresShell, aStyleType, eWithAnimation); - MOZ_ASSERT(p && p->IsGecko()); - parentContext = GeckoStyleContext::TakeRef(p.forget()); - } - - StyleResolver styleResolver(presContext, aAnimationFlag); - - if (aAnimationFlag == eWithAnimation) { - return styleResolver.ResolveWithAnimation(styleSet->AsGecko(), - aElement, pseudoType, - parentContext, - aStyleType, - inDocWithShell); - } - - return styleResolver.ResolveWithoutAnimation(styleSet->AsGecko(), - aElement, pseudoType, - parentContext, - inDocWithShell); -#else MOZ_CRASH("old style system disabled"); -#endif } nsMargin @@ -1196,29 +987,7 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush) if (!mStyleContext || MustReresolveStyle(mStyleContext)) { #ifdef DEBUG if (mStyleContext && mStyleContext->IsGecko()) { -#ifdef MOZ_OLD_STYLE - // We want to check that going through this path because of - // HasPseudoElementData is rare, because it slows us down a good - // bit. So check that we're really inside something associated - // with a pseudo-element that contains elements. (We also allow - // the element to be NAC, just in case some chrome JS calls - // getComputedStyle on a NAC-implemented pseudo.) - GeckoStyleContext* topWithPseudoElementData = mStyleContext->AsGecko(); - while (topWithPseudoElementData->GetParent()->HasPseudoElementData()) { - topWithPseudoElementData = topWithPseudoElementData->GetParent(); - } - CSSPseudoElementType pseudo = topWithPseudoElementData->GetPseudoType(); - nsAtom* pseudoAtom = nsCSSPseudoElements::GetPseudoAtom(pseudo); - nsAutoString assertMsg( - NS_LITERAL_STRING("we should be in a pseudo-element that is expected to contain elements (")); - assertMsg.Append(nsDependentString(pseudoAtom->GetUTF16String())); - assertMsg.Append(')'); - NS_ASSERTION(nsCSSPseudoElements::PseudoElementContainsElements(pseudo) || - mContent->IsNativeAnonymous(), - NS_LossyConvertUTF16toASCII(assertMsg).get()); -#else MOZ_CRASH("old style system disabled"); -#endif } #endif // Need to resolve a style context @@ -1248,19 +1017,7 @@ nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush) } if (mAnimationFlag == eWithoutAnimation) { -#ifdef MOZ_OLD_STYLE - // We will support Servo in bug 1311257. - MOZ_ASSERT(mPresShell->StyleSet()->IsGecko(), - "eWithoutAnimationRules support Gecko only"); - nsStyleSet* styleSet = mPresShell->StyleSet()->AsGecko(); - RefPtr unanimatedStyleContext = - styleSet->ResolveStyleByRemovingAnimation( - mContent->AsElement(), mStyleContext->AsGecko(), - eRestyle_AllHintsWithAnimations); - SetResolvedStyleContext(Move(unanimatedStyleContext), currentGeneration); -#else MOZ_CRASH("old style system disabled"); -#endif } // mExposeVisitedStyle is set to true only by testing APIs that @@ -1414,21 +1171,12 @@ nsComputedDOMStyle::IndexedGetter(uint32_t aIndex, bool isServo = mStyleContext->IsServo(); -#ifdef MOZ_OLD_STYLE - const nsStyleVariables* variables = isServo - ? nullptr - : StyleVariables(); -#endif uint32_t count; if (isServo) { count = Servo_GetCustomPropertiesCount(mStyleContext->AsServo()); } else { -#ifdef MOZ_OLD_STYLE - count = variables->mVariables.Count(); -#else MOZ_CRASH("old style system disabled"); -#endif } const uint32_t index = aIndex - length; @@ -1438,11 +1186,7 @@ nsComputedDOMStyle::IndexedGetter(uint32_t aIndex, if (isServo) { Servo_GetCustomPropertyNameAt(mStyleContext->AsServo(), index, &varName); } else { -#ifdef MOZ_OLD_STYLE - variables->mVariables.GetVariableAt(index, varName); -#else MOZ_CRASH("old style system disabled"); -#endif } aPropName.AssignLiteral("--"); aPropName.Append(varName); @@ -1950,11 +1694,7 @@ nsComputedDOMStyle::DoGetTranslate() return ReadIndividualTransformValue(StyleDisplay()->mSpecifiedTranslate, [self](const nsCSSValue::Array* aData, nsString& aResult) { GeckoStyleContext* contextIfGecko = -#ifdef MOZ_OLD_STYLE - self->mStyleContext ? self->mStyleContext->GetAsGecko() : nullptr; -#else nullptr; -#endif TransformReferenceBox refBox(self->mInnerFrame, nsSize(0, 0)); RuleNodeCacheConditions dummy; @@ -7494,11 +7234,7 @@ nsComputedDOMStyle::DoGetCustomProperty(const nsAString& aPropertyName) present = Servo_GetCustomPropertyValue(mStyleContext->AsServo(), &name, &variableValue); } else { -#ifdef MOZ_OLD_STYLE - present = StyleVariables()->mVariables.Get(name, variableValue); -#else MOZ_CRASH("old style system disabled"); -#endif } if (!present) { return nullptr; diff --git a/layout/style/nsDOMCSSAttrDeclaration.cpp b/layout/style/nsDOMCSSAttrDeclaration.cpp index 0880f35468c2..7ea18c9b5e38 100644 --- a/layout/style/nsDOMCSSAttrDeclaration.cpp +++ b/layout/style/nsDOMCSSAttrDeclaration.cpp @@ -8,10 +8,6 @@ #include "nsDOMCSSAttrDeclaration.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/Declaration.h" -#include "mozilla/css/StyleRule.h" -#endif #include "mozilla/DeclarationBlock.h" #include "mozilla/DeclarationBlockInlines.h" #include "mozilla/dom/Element.h" @@ -146,12 +142,7 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(Operation aOperation) if (mElement->IsStyledByServo()) { decl = new ServoDeclarationBlock(); } else { -#ifdef MOZ_OLD_STYLE - decl = new css::Declaration(); - decl->AsGecko()->InitializeEmpty(); -#else MOZ_CRASH("old style system disabled"); -#endif } // this *can* fail (inside SetAttrAndNotify, at least). diff --git a/layout/style/nsDOMCSSDeclaration.cpp b/layout/style/nsDOMCSSDeclaration.cpp index 4efff9a7178e..bab0a9cc7892 100644 --- a/layout/style/nsDOMCSSDeclaration.cpp +++ b/layout/style/nsDOMCSSDeclaration.cpp @@ -133,33 +133,7 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText, newdecl = ServoDeclarationBlock::FromCssText(aCssText, servoEnv.mUrlExtraData, servoEnv.mCompatMode, servoEnv.mLoader); } else { -#ifdef MOZ_OLD_STYLE - CSSParsingEnvironment geckoEnv; - GetCSSParsingEnvironment(geckoEnv, aSubjectPrincipal); - if (!geckoEnv.mPrincipal) { - aRv.Throw(NS_ERROR_NOT_AVAILABLE); - return; - } - - RefPtr decl(new css::Declaration()); - decl->InitializeEmpty(); - nsCSSParser cssParser(geckoEnv.mCSSLoader); - bool changed; - nsresult result = cssParser.ParseDeclarations(aCssText, geckoEnv.mSheetURI, - geckoEnv.mBaseURI, geckoEnv.mPrincipal, - decl, &changed); - if (NS_FAILED(result)) { - aRv.Throw(result); - return; - } - - if (!changed) { - return; - } - newdecl = decl.forget(); -#else MOZ_CRASH("old style system disabled"); -#endif } aRv = SetCSSDeclaration(newdecl); @@ -322,17 +296,7 @@ nsDOMCSSDeclaration::ModifyDeclaration(nsIPrincipal* aSubjectPrincipal, bool changed; if (decl->IsGecko()) { -#ifdef MOZ_OLD_STYLE - CSSParsingEnvironment geckoEnv; - GetCSSParsingEnvironment(geckoEnv, aSubjectPrincipal); - if (!geckoEnv.mPrincipal) { - return NS_ERROR_NOT_AVAILABLE; - } - - aGeckoFunc(decl->AsGecko(), geckoEnv, &changed); -#else MOZ_CRASH("old style system disabled"); -#endif } else { ServoCSSParsingEnvironment servoEnv = GetServoCSSParsingEnvironment( aSubjectPrincipal); @@ -359,14 +323,7 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSPropertyID aPropID, return ModifyDeclaration( aSubjectPrincipal, [&](css::Declaration* decl, CSSParsingEnvironment& env, bool* changed) { -#ifdef MOZ_OLD_STYLE - nsCSSParser cssParser(env.mCSSLoader); - cssParser.ParseProperty(aPropID, aPropValue, - env.mSheetURI, env.mBaseURI, env.mPrincipal, - decl, changed, aIsImportant); -#else MOZ_CRASH("old style system disabled"); -#endif }, [&](ServoDeclarationBlock* decl, ServoCSSParsingEnvironment& env) { NS_ConvertUTF16toUTF8 value(aPropValue); @@ -386,15 +343,7 @@ nsDOMCSSDeclaration::ParseCustomPropertyValue(const nsAString& aPropertyName, return ModifyDeclaration( aSubjectPrincipal, [&](css::Declaration* decl, CSSParsingEnvironment& env, bool* changed) { -#ifdef MOZ_OLD_STYLE - nsCSSParser cssParser(env.mCSSLoader); - auto propName = Substring(aPropertyName, CSS_CUSTOM_NAME_PREFIX_LENGTH); - cssParser.ParseVariable(propName, aPropValue, env.mSheetURI, - env.mBaseURI, env.mPrincipal, decl, - changed, aIsImportant); -#else MOZ_CRASH("old style system disabled"); -#endif }, [&](ServoDeclarationBlock* decl, ServoCSSParsingEnvironment& env) { NS_ConvertUTF16toUTF8 property(aPropertyName); diff --git a/layout/style/nsFontFaceLoader.h b/layout/style/nsFontFaceLoader.h index 309ed7dbe4bb..36ec752cc5f0 100644 --- a/layout/style/nsFontFaceLoader.h +++ b/layout/style/nsFontFaceLoader.h @@ -19,9 +19,6 @@ #include "gfxUserFontSet.h" #include "nsHashKeys.h" #include "nsTHashtable.h" -#ifdef MOZ_OLD_STYLE -#include "nsCSSRules.h" -#endif class nsIPrincipal; diff --git a/layout/style/nsHTMLCSSStyleSheet.cpp b/layout/style/nsHTMLCSSStyleSheet.cpp index 864d4a121372..39923d8c6e7f 100644 --- a/layout/style/nsHTMLCSSStyleSheet.cpp +++ b/layout/style/nsHTMLCSSStyleSheet.cpp @@ -10,18 +10,8 @@ #include "nsHTMLCSSStyleSheet.h" #include "mozilla/MemoryReporting.h" -#ifdef MOZ_OLD_STYLE -#include "mozilla/css/StyleRule.h" -#endif #include "mozilla/DeclarationBlockInlines.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRuleProcessor.h" -#endif #include "nsPresContext.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#include "nsRuleProcessorData.h" -#endif #include "mozilla/dom/Element.h" #include "nsAttrValue.h" #include "nsAttrValueInlines.h" @@ -57,147 +47,6 @@ nsHTMLCSSStyleSheet::~nsHTMLCSSStyleSheet() } } -#ifdef MOZ_OLD_STYLE -NS_IMPL_ISUPPORTS(nsHTMLCSSStyleSheet, nsIStyleRuleProcessor) - -/* virtual */ void -nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData) -{ - ElementRulesMatching(aData->mPresContext, aData->mElement, - aData->mRuleWalker); -} - -void -nsHTMLCSSStyleSheet::ElementRulesMatching(nsPresContext* aPresContext, - Element* aElement, - nsRuleWalker* aRuleWalker) -{ - // just get the one and only style rule from the content's STYLE attribute - DeclarationBlock* declaration = aElement->GetInlineStyleDeclaration(); - if (declaration) { - declaration->SetImmutable(); - aRuleWalker->Forward(declaration->AsGecko()); - } - - declaration = aElement->GetSMILOverrideStyleDeclaration(); - if (declaration) { - MOZ_ASSERT(aPresContext->RestyleManager()->IsGecko(), - "stylo: ElementRulesMatching must not be called when we have " - "a Servo-backed style system"); - GeckoRestyleManager* restyleManager = - aPresContext->RestyleManager()->AsGecko(); - if (!restyleManager->SkipAnimationRules()) { - // Animation restyle (or non-restyle traversal of rules) - // Now we can walk SMIL overrride style, without triggering transitions. - declaration->SetImmutable(); - aRuleWalker->Forward(declaration->AsGecko()); - } - } -} - -void -nsHTMLCSSStyleSheet::PseudoElementRulesMatching(Element* aPseudoElement, - CSSPseudoElementType - aPseudoType, - nsRuleWalker* aRuleWalker) -{ - MOZ_ASSERT(nsCSSPseudoElements:: - PseudoElementSupportsStyleAttribute(aPseudoType)); - MOZ_ASSERT(aPseudoElement); - - // just get the one and only style rule from the content's STYLE attribute - DeclarationBlock* declaration = aPseudoElement->GetInlineStyleDeclaration(); - if (declaration) { - declaration->SetImmutable(); - aRuleWalker->Forward(declaration->AsGecko()); - } -} - -/* virtual */ void -nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData) -{ - if (nsCSSPseudoElements::PseudoElementSupportsStyleAttribute(aData->mPseudoType) && - aData->mPseudoElement) { - PseudoElementRulesMatching(aData->mPseudoElement, aData->mPseudoType, - aData->mRuleWalker); - } -} - -/* virtual */ void -nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData) -{ -} - -#ifdef MOZ_XUL -/* virtual */ void -nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData) -{ -} -#endif - -// Test if style is dependent on content state -/* virtual */ nsRestyleHint -nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData) -{ - return nsRestyleHint(0); -} - -/* virtual */ nsRestyleHint -nsHTMLCSSStyleSheet::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) -{ - return nsRestyleHint(0); -} - -/* virtual */ bool -nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData) -{ - return false; -} - -// Test if style is dependent on attribute -/* virtual */ nsRestyleHint -nsHTMLCSSStyleSheet::HasAttributeDependentStyle( - AttributeRuleProcessorData* aData, - RestyleHintData& aRestyleHintDataResult) -{ - // Perhaps should check that it's XUL, SVG, (or HTML) namespace, but - // it doesn't really matter. - if (aData->mAttrHasChanged && aData->mAttribute == nsGkAtoms::style) { - return eRestyle_StyleAttribute; - } - - return nsRestyleHint(0); -} - -/* virtual */ bool -nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext) -{ - return false; -} - -/* virtual */ size_t -nsHTMLCSSStyleSheet::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const -{ - // The size of mCachedStyleAttrs's mTable member (a PLDHashTable) is - // significant in itself, but more significant is the size of the nsString - // members of the nsStringHashKeys. - size_t n = 0; - n += mCachedStyleAttrs.ShallowSizeOfExcludingThis(aMallocSizeOf); - for (auto iter = mCachedStyleAttrs.ConstIter(); !iter.Done(); iter.Next()) { - // We don't own the MiscContainers (the hash table values) so we don't - // count them. We do care about the size of the nsString members in the - // keys though. - n += iter.Key().SizeOfExcludingThisIfUnshared(aMallocSizeOf); - } - return n; -} - -/* virtual */ size_t -nsHTMLCSSStyleSheet::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const -{ - return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); -} -#endif void nsHTMLCSSStyleSheet::CacheStyleAttr(const nsAString& aSerialized, diff --git a/layout/style/nsHTMLCSSStyleSheet.h b/layout/style/nsHTMLCSSStyleSheet.h index 17e156142eea..0c620fe0ea9e 100644 --- a/layout/style/nsHTMLCSSStyleSheet.h +++ b/layout/style/nsHTMLCSSStyleSheet.h @@ -15,9 +15,6 @@ #include "mozilla/MemoryReporting.h" #include "nsDataHashtable.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRuleProcessor.h" -#endif class nsRuleWalker; struct MiscContainer; @@ -30,48 +27,11 @@ class Element; } // namespace mozilla class nsHTMLCSSStyleSheet final -#ifdef MOZ_OLD_STYLE - : public nsIStyleRuleProcessor -#endif { public: nsHTMLCSSStyleSheet(); -#ifdef MOZ_OLD_STYLE - NS_DECL_ISUPPORTS - - // nsIStyleRuleProcessor - virtual void RulesMatching(ElementRuleProcessorData* aData) override; - virtual void RulesMatching(PseudoElementRuleProcessorData* aData) override; - virtual void RulesMatching(AnonBoxRuleProcessorData* aData) override; -#ifdef MOZ_XUL - virtual void RulesMatching(XULTreeRuleProcessorData* aData) override; -#endif - virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override; - virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override; - virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override; - virtual nsRestyleHint - HasAttributeDependentStyle(AttributeRuleProcessorData* aData, - mozilla::RestyleHintData& aRestyleHintDataResult) override; - virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) override; - virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) - const MOZ_MUST_OVERRIDE override; - virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) - const MOZ_MUST_OVERRIDE override; - - // Variants of RulesMatching method above that is specific to this - // rule processor. - void ElementRulesMatching(nsPresContext* aPresContext, - mozilla::dom::Element* aElement, - nsRuleWalker* aRuleWalker); - // aPseudoElement here is the content node for the pseudo-element, not - // its corresponding real element. - void PseudoElementRulesMatching(mozilla::dom::Element* aPseudoElement, - mozilla::CSSPseudoElementType aPseudoType, - nsRuleWalker* aRuleWalker); -#else NS_INLINE_DECL_REFCOUNTING(nsHTMLCSSStyleSheet) -#endif void CacheStyleAttr(const nsAString& aSerialized, MiscContainer* aValue); void EvictStyleAttr(const nsAString& aSerialized, MiscContainer* aValue); diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 8ff733c9b5fa..9e13015c5fc4 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -17,15 +17,7 @@ #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsStyleConsts.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleWalker.h" -#include "nsRuleData.h" -#endif #include "nsError.h" -#ifdef MOZ_OLD_STYLE -#include "nsRuleProcessorData.h" -#include "nsCSSRuleProcessor.h" -#endif #include "mozilla/MemoryReporting.h" #include "mozilla/dom/Element.h" #include "nsHashKeys.h" @@ -37,157 +29,6 @@ using namespace mozilla; using namespace mozilla::dom; -#ifdef MOZ_OLD_STYLE -NS_IMPL_ISUPPORTS(nsHTMLStyleSheet::HTMLColorRule, nsIStyleRule) - -/* virtual */ void -nsHTMLStyleSheet::HTMLColorRule::MapRuleInfoInto(nsRuleData* aRuleData) -{ - if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) { - nsCSSValue* color = aRuleData->ValueForColor(); - if (color->GetUnit() == eCSSUnit_Null && - aRuleData->mPresContext->UseDocumentColors()) - color->SetColorValue(mColor); - } -} - -/* virtual */ bool -nsHTMLStyleSheet::HTMLColorRule::MightMapInheritedStyleData() -{ - return true; -} - -/* virtual */ bool -nsHTMLStyleSheet::HTMLColorRule:: -GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue) -{ - MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet"); - return false; -} - -#ifdef DEBUG -/* virtual */ void -nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, int32_t aIndent) const -{ - nsAutoCString indentStr; - for (int32_t index = aIndent; --index >= 0; ) { - indentStr.AppendLiteral(" "); - } - fprintf_stderr(out, "%s[html color rule] {}\n", indentStr.get()); -} -#endif - - -NS_IMPL_ISUPPORTS(nsHTMLStyleSheet::GenericTableRule, nsIStyleRule) - -#ifdef DEBUG -/* virtual */ void -nsHTMLStyleSheet::GenericTableRule::List(FILE* out, int32_t aIndent) const -{ - nsAutoCString indentStr; - for (int32_t index = aIndent; --index >= 0; ) { - indentStr.AppendLiteral(" "); - } - fprintf_stderr(out, "%s[generic table rule] {}\n", indentStr.get()); -} -#endif - -/* virtual */ void -nsHTMLStyleSheet::TableTHRule::MapRuleInfoInto(nsRuleData* aRuleData) -{ - if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) { - nsCSSValue* textAlign = aRuleData->ValueForTextAlign(); - if (textAlign->GetUnit() == eCSSUnit_Null) { - textAlign->SetIntValue(NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT, - eCSSUnit_Enumerated); - } - } -} - -/* virtual */ bool -nsHTMLStyleSheet::TableTHRule::MightMapInheritedStyleData() -{ - return true; -} - -/* virtual */ bool -nsHTMLStyleSheet::TableTHRule:: -GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue) -{ - MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet"); - return false; -} - -/* virtual */ void -nsHTMLStyleSheet::TableQuirkColorRule::MapRuleInfoInto(nsRuleData* aRuleData) -{ - if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) { - nsCSSValue* color = aRuleData->ValueForColor(); - // We do not check UseDocumentColors() here, because we want to - // use the body color no matter what. - if (color->GetUnit() == eCSSUnit_Null) - color->SetIntValue(NS_STYLE_COLOR_INHERIT_FROM_BODY, - eCSSUnit_Enumerated); - } -} - -/* virtual */ bool -nsHTMLStyleSheet::TableQuirkColorRule::MightMapInheritedStyleData() -{ - return true; -} - -/* virtual */ bool -nsHTMLStyleSheet::TableQuirkColorRule:: -GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue) -{ - MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet"); - return false; -} - -NS_IMPL_ISUPPORTS(nsHTMLStyleSheet::LangRule, nsIStyleRule) - -/* virtual */ void -nsHTMLStyleSheet::LangRule::MapRuleInfoInto(nsRuleData* aRuleData) -{ - if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Font)) { - nsCSSValue* lang = aRuleData->ValueForLang(); - if (lang->GetUnit() == eCSSUnit_Null) { - RefPtr langAtom = mLang; - lang->SetAtomIdentValue(langAtom.forget()); - } - } -} - -/* virtual */ bool -nsHTMLStyleSheet::LangRule::MightMapInheritedStyleData() -{ - return true; -} - -/* virtual */ bool -nsHTMLStyleSheet::LangRule:: -GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, nsCSSValue* aValue) -{ - MOZ_ASSERT(false, "GetDiscretelyAnimatedCSSValue is not implemented yet"); - return false; -} - -#ifdef DEBUG -/* virtual */ void -nsHTMLStyleSheet::LangRule::List(FILE* out, int32_t aIndent) const -{ - nsAutoCString str; - for (int32_t index = aIndent; --index >= 0; ) { - str.AppendLiteral(" "); - } - str.AppendLiteral("[lang rule] { language: \""); - AppendUTF16toUTF8(nsDependentAtomString(mLang), str); - str.AppendLiteral("\" }\n"); - fprintf_stderr(out, "%s", str.get()); -} -#endif -#endif // ----------------------------------------------------------- @@ -234,243 +75,17 @@ static const PLDHashTableOps MappedAttrTable_Ops = { // ----------------------------------------------------------- -#ifdef MOZ_OLD_STYLE -struct LangRuleTableEntry : public PLDHashEntryHdr { - RefPtr mRule; -}; - -static PLDHashNumber -LangRuleTable_HashKey(const void *key) -{ - auto* lang = static_cast(key); - return lang->hash(); -} - -static void -LangRuleTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr) -{ - LangRuleTableEntry *entry = static_cast(hdr); - - entry->~LangRuleTableEntry(); - memset(entry, 0, sizeof(LangRuleTableEntry)); -} - -static bool -LangRuleTable_MatchEntry(const PLDHashEntryHdr *hdr, const void *key) -{ - auto* lang = static_cast(key); - const LangRuleTableEntry *entry = static_cast(hdr); - - return entry->mRule->mLang == lang; -} - -static void -LangRuleTable_InitEntry(PLDHashEntryHdr *hdr, const void *key) -{ - auto* lang = static_cast(key); - - LangRuleTableEntry* entry = new (KnownNotNull, hdr) LangRuleTableEntry(); - - // Create the unique rule for this language - entry->mRule = new nsHTMLStyleSheet::LangRule(const_cast(lang)); -} - -static const PLDHashTableOps LangRuleTable_Ops = { - LangRuleTable_HashKey, - LangRuleTable_MatchEntry, - PLDHashTable::MoveEntryStub, - LangRuleTable_ClearEntry, - LangRuleTable_InitEntry -}; -#endif // ----------------------------------------------------------- nsHTMLStyleSheet::nsHTMLStyleSheet(nsIDocument* aDocument) : mDocument(aDocument) -#ifdef MOZ_OLD_STYLE - , mTableQuirkColorRule(new TableQuirkColorRule()) - , mTableTHRule(new TableTHRule()) -#endif , mMappedAttrTable(&MappedAttrTable_Ops, sizeof(MappedAttrTableEntry)) , mMappedAttrsDirty(false) -#ifdef MOZ_OLD_STYLE - , mLangRuleTable(&LangRuleTable_Ops, sizeof(LangRuleTableEntry)) -#endif { MOZ_ASSERT(aDocument); } -#ifdef MOZ_OLD_STYLE -NS_IMPL_ISUPPORTS(nsHTMLStyleSheet, nsIStyleRuleProcessor) - -/* virtual */ void -nsHTMLStyleSheet::RulesMatching(ElementRuleProcessorData* aData) -{ - nsRuleWalker *ruleWalker = aData->mRuleWalker; - if (!ruleWalker->AuthorStyleDisabled()) { - // if we have anchor colors, check if this is an anchor with an href - if (aData->mElement->IsHTMLElement(nsGkAtoms::a)) { - if (mLinkRule || mVisitedRule || mActiveRule) { - EventStates state = - nsCSSRuleProcessor::GetContentStateForVisitedHandling( - aData->mElement, - aData->mTreeMatchContext.VisitedHandling(), - // If the node being matched is a link, - // it's the relevant link. - nsCSSRuleProcessor::IsLink(aData->mElement)); - if (mLinkRule && state.HasState(NS_EVENT_STATE_UNVISITED)) { - ruleWalker->Forward(mLinkRule); - aData->mTreeMatchContext.SetHaveRelevantLink(); - } - else if (mVisitedRule && state.HasState(NS_EVENT_STATE_VISITED)) { - ruleWalker->Forward(mVisitedRule); - aData->mTreeMatchContext.SetHaveRelevantLink(); - } - - // No need to add to the active rule if it's not a link - if (mActiveRule && nsCSSRuleProcessor::IsLink(aData->mElement) && - state.HasState(NS_EVENT_STATE_ACTIVE)) { - ruleWalker->Forward(mActiveRule); - } - } // end link/visited/active rules - } // end A tag - // add the rule to handle text-align for a - else if (aData->mElement->IsHTMLElement(nsGkAtoms::th)) { - ruleWalker->Forward(mTableTHRule); - } - else if (aData->mElement->IsHTMLElement(nsGkAtoms::table)) { - if (aData->mTreeMatchContext.mCompatMode == eCompatibility_NavQuirks) { - ruleWalker->Forward(mTableQuirkColorRule); - } - } - } // end html element - - // just get the style rules from the content. For SVG we do this even if - // author style is disabled, because SVG presentational hints aren't - // considered style. - if (!ruleWalker->AuthorStyleDisabled() || aData->mElement->IsSVGElement()) { - aData->mElement->WalkContentStyleRules(ruleWalker); - } - - // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#language - // says that the xml:lang attribute overrides HTML's lang attribute, - // so we need to do this after WalkContentStyleRules. - const nsAttrValue* langAttr = - aData->mElement->GetParsedAttr(nsGkAtoms::lang, kNameSpaceID_XML); - if (langAttr) { - MOZ_ASSERT(langAttr->Type() == nsAttrValue::eAtom); - ruleWalker->Forward(LangRuleFor(langAttr->GetAtomValue())); - } - - // Set the language to "x-math" on the element, so that appropriate - // font settings are used for MathML. - if (aData->mElement->IsMathMLElement(nsGkAtoms::math)) { - ruleWalker->Forward(LangRuleFor(nsGkAtoms::x_math)); - } -} - -// Test if style is dependent on content state -/* virtual */ nsRestyleHint -nsHTMLStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData) -{ - if (aData->mElement->IsHTMLElement(nsGkAtoms::a) && - nsCSSRuleProcessor::IsLink(aData->mElement) && - ((mActiveRule && aData->mStateMask.HasState(NS_EVENT_STATE_ACTIVE)) || - (mLinkRule && aData->mStateMask.HasState(NS_EVENT_STATE_VISITED)) || - (mVisitedRule && aData->mStateMask.HasState(NS_EVENT_STATE_VISITED)))) { - return eRestyle_Self; - } - - return nsRestyleHint(0); -} - -/* virtual */ nsRestyleHint -nsHTMLStyleSheet::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) -{ - return nsRestyleHint(0); -} - -/* virtual */ bool -nsHTMLStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData) -{ - return false; -} - -/* virtual */ nsRestyleHint -nsHTMLStyleSheet::HasAttributeDependentStyle( - AttributeRuleProcessorData* aData, - RestyleHintData& aRestyleHintDataResult) -{ - // Do nothing on before-change checks - if (!aData->mAttrHasChanged) { - return nsRestyleHint(0); - } - - // Note: no need to worry about whether some states changed with this - // attribute here, because we handle that under HasStateDependentStyle() as - // needed. - - // Result is true for |href| changes on HTML links if we have link rules. - Element *element = aData->mElement; - if (aData->mAttribute == nsGkAtoms::href && - (mLinkRule || mVisitedRule || mActiveRule) && - element->IsHTMLElement(nsGkAtoms::a)) { - return eRestyle_Self; - } - - // Don't worry about the mDocumentColorRule since it only applies - // to descendants of body, when we're already reresolving. - - // Handle the content style rules. - if (element->IsAttributeMapped(aData->mAttribute)) { - // cellpadding on tables is special and requires reresolving all - // the cells in the table - if (aData->mAttribute == nsGkAtoms::cellpadding && - element->IsHTMLElement(nsGkAtoms::table)) { - return eRestyle_Subtree; - } - return eRestyle_Self; - } - - return nsRestyleHint(0); -} - -/* virtual */ bool -nsHTMLStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext) -{ - return false; -} - -/* virtual */ size_t -nsHTMLStyleSheet::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const -{ - return 0; // nsHTMLStyleSheets are charged to the DOM, not layout -} - -/* virtual */ size_t -nsHTMLStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const -{ - return 0; // nsHTMLStyleSheets are charged to the DOM, not layout -} - -/* virtual */ void -nsHTMLStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData) -{ -} - -/* virtual */ void -nsHTMLStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData) -{ -} - -#ifdef MOZ_XUL -/* virtual */ void -nsHTMLStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData) -{ -} -#endif -#endif void nsHTMLStyleSheet::SetOwningDocument(nsIDocument* aDocument) @@ -481,28 +96,17 @@ nsHTMLStyleSheet::SetOwningDocument(nsIDocument* aDocument) void nsHTMLStyleSheet::Reset() { -#ifdef MOZ_OLD_STYLE - mLinkRule = nullptr; - mVisitedRule = nullptr; - mActiveRule = nullptr; -#endif mServoUnvisitedLinkDecl = nullptr; mServoVisitedLinkDecl = nullptr; mServoActiveLinkDecl = nullptr; -#ifdef MOZ_OLD_STYLE - mLangRuleTable.Clear(); -#endif mMappedAttrTable.Clear(); mMappedAttrsDirty = false; } nsresult nsHTMLStyleSheet::ImplLinkColorSetter( -#ifdef MOZ_OLD_STYLE - RefPtr& aRule, -#endif RefPtr& aDecl, nscolor aColor) { @@ -518,18 +122,7 @@ nsHTMLStyleSheet::ImplLinkColorSetter( Servo_DeclarationBlock_SetColorValue(aDecl.get(), eCSSProperty_color, aColor); } else { -#ifdef MOZ_OLD_STYLE - if (aRule && aRule->mColor == aColor) { - return NS_OK; - } - - aRule = new HTMLColorRule(aColor); - if (!aRule) { - return NS_ERROR_OUT_OF_MEMORY; - } -#else MOZ_CRASH("old style system disabled"); -#endif } // Now make sure we restyle any links that might need it. This @@ -545,9 +138,6 @@ nsresult nsHTMLStyleSheet::SetLinkColor(nscolor aColor) { return ImplLinkColorSetter( -#ifdef MOZ_OLD_STYLE - mLinkRule, -#endif mServoUnvisitedLinkDecl, aColor); } @@ -556,9 +146,6 @@ nsresult nsHTMLStyleSheet::SetActiveLinkColor(nscolor aColor) { return ImplLinkColorSetter( -#ifdef MOZ_OLD_STYLE - mActiveRule, -#endif mServoActiveLinkDecl, aColor); } @@ -567,9 +154,6 @@ nsresult nsHTMLStyleSheet::SetVisitedLinkColor(nscolor aColor) { return ImplLinkColorSetter( -#ifdef MOZ_OLD_STYLE - mVisitedRule, -#endif mServoVisitedLinkDecl, aColor); } @@ -616,19 +200,6 @@ nsHTMLStyleSheet::CalculateMappedServoDeclarations() } } -#ifdef MOZ_OLD_STYLE -nsIStyleRule* -nsHTMLStyleSheet::LangRuleFor(const nsAtom* aLanguage) -{ - auto entry = - static_cast(mLangRuleTable.Add(aLanguage, fallible)); - if (!entry) { - NS_ASSERTION(false, "out of memory"); - return nullptr; - } - return entry->mRule; -} -#endif size_t nsHTMLStyleSheet::DOMSizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const diff --git a/layout/style/nsHTMLStyleSheet.h b/layout/style/nsHTMLStyleSheet.h index ffef974223c1..5cf15a3d3a19 100644 --- a/layout/style/nsHTMLStyleSheet.h +++ b/layout/style/nsHTMLStyleSheet.h @@ -15,10 +15,6 @@ #include "nsColor.h" #include "nsCOMPtr.h" #include "nsAtom.h" -#ifdef MOZ_OLD_STYLE -#include "nsIStyleRule.h" -#include "nsIStyleRuleProcessor.h" -#endif #include "PLDHashTable.h" #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" @@ -29,41 +25,13 @@ class nsMappedAttributes; struct RawServoDeclarationBlock; class nsHTMLStyleSheet final -#ifdef MOZ_OLD_STYLE - : public nsIStyleRuleProcessor -#endif { public: explicit nsHTMLStyleSheet(nsIDocument* aDocument); void SetOwningDocument(nsIDocument* aDocument); -#ifdef MOZ_OLD_STYLE - NS_DECL_ISUPPORTS - - // nsIStyleRuleProcessor API - virtual void RulesMatching(ElementRuleProcessorData* aData) override; - virtual void RulesMatching(PseudoElementRuleProcessorData* aData) override; - virtual void RulesMatching(AnonBoxRuleProcessorData* aData) override; -#ifdef MOZ_XUL - virtual void RulesMatching(XULTreeRuleProcessorData* aData) override; -#endif - virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override; - virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override; - virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override; - virtual nsRestyleHint - HasAttributeDependentStyle(AttributeRuleProcessorData* aData, - mozilla::RestyleHintData& aRestyleHintDataResult) override; - virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) override; - virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) - const MOZ_MUST_OVERRIDE override; - virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) - const MOZ_MUST_OVERRIDE override; - - nsIStyleRule* LangRuleFor(const nsAtom* aLanguage); -#else NS_INLINE_DECL_REFCOUNTING(nsHTMLStyleSheet) -#endif size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; @@ -97,135 +65,26 @@ private: ~nsHTMLStyleSheet() {} -#ifdef MOZ_OLD_STYLE - class HTMLColorRule; - friend class HTMLColorRule; - class HTMLColorRule final : public nsIStyleRule { - private: - ~HTMLColorRule() {} - public: - explicit HTMLColorRule(nscolor aColor) - : mColor(aColor) - {} - - NS_DECL_ISUPPORTS - - // nsIStyleRule interface - virtual void MapRuleInfoInto(nsRuleData* aRuleData) override; - virtual bool MightMapInheritedStyleData() override; - virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, - nsCSSValue* aValue) override; - #ifdef DEBUG - virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; - #endif - - nscolor mColor; - }; - - class GenericTableRule; - friend class GenericTableRule; - class GenericTableRule : public nsIStyleRule { - protected: - virtual ~GenericTableRule() {} - public: - GenericTableRule() {} - - NS_DECL_ISUPPORTS - - // nsIStyleRule interface - virtual void MapRuleInfoInto(nsRuleData* aRuleData) override = 0; - virtual bool MightMapInheritedStyleData() override = 0; - virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, - nsCSSValue* aValue) override = 0; - #ifdef DEBUG - virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; - #endif - }; - - // this rule handles inheritance - class TableTHRule; - friend class TableTHRule; - class TableTHRule final : public GenericTableRule { - public: - TableTHRule() {} - - virtual void MapRuleInfoInto(nsRuleData* aRuleData) override; - virtual bool MightMapInheritedStyleData() override; - virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, - nsCSSValue* aValue) override; - }; - - // Rule to handle quirk table colors - class TableQuirkColorRule final : public GenericTableRule { - public: - TableQuirkColorRule() {} - - virtual void MapRuleInfoInto(nsRuleData* aRuleData) override; - virtual bool MightMapInheritedStyleData() override; - virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, - nsCSSValue* aValue) override; - }; -#endif // Implementation of SetLink/VisitedLink/ActiveLinkColor nsresult ImplLinkColorSetter( -#ifdef MOZ_OLD_STYLE - RefPtr& aRule, -#endif RefPtr& aDecl, nscolor aColor); public: // for mLangRuleTable structures only -#ifdef MOZ_OLD_STYLE - // Rule to handle xml:lang attributes, of which we have exactly one - // per language string, maintained in mLangRuleTable. - // We also create one extra rule for the "x-math" language string, used on - // elements. - class LangRule final : public nsIStyleRule { - private: - ~LangRule() {} - public: - explicit LangRule(nsAtom* aLang) : mLang(aLang) {} - - NS_DECL_ISUPPORTS - - // nsIStyleRule interface - virtual void MapRuleInfoInto(nsRuleData* aRuleData) override; - virtual bool MightMapInheritedStyleData() override; - virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty, - nsCSSValue* aValue) override; - #ifdef DEBUG - virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; - #endif - - RefPtr mLang; - }; -#endif private: nsIDocument* mDocument; -#ifdef MOZ_OLD_STYLE - RefPtr mLinkRule; - RefPtr mVisitedRule; - RefPtr mActiveRule; -#endif RefPtr mServoUnvisitedLinkDecl; RefPtr mServoVisitedLinkDecl; RefPtr mServoActiveLinkDecl; -#ifdef MOZ_OLD_STYLE - RefPtr mTableQuirkColorRule; - RefPtr mTableTHRule; -#endif PLDHashTable mMappedAttrTable; // Whether or not the mapped attributes table // has been changed since the last call to // CalculateMappedServoDeclarations() bool mMappedAttrsDirty; -#ifdef MOZ_OLD_STYLE - PLDHashTable mLangRuleTable; -#endif }; #endif /* !defined(nsHTMLStyleSheet_h_) */ diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index 4c3c278f3acb..99a524326bdf 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -899,12 +899,7 @@ nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr* aSheet, nsPresContext* aPresContext) { if (mBackendType == StyleBackendType::Gecko) { -#ifdef MOZ_OLD_STYLE - *aSheet = new CSSStyleSheet(eAgentSheetFeatures, CORS_NONE, - mozilla::net::RP_Unset); -#else MOZ_CRASH("old style system disabled"); -#endif } else { *aSheet = new ServoStyleSheet(eAgentSheetFeatures, CORS_NONE, mozilla::net::RP_Unset, dom::SRIMetadata()); @@ -1004,11 +999,7 @@ nsLayoutStylesheetCache::BuildPreferenceSheet(RefPtr* aSheet, "sheet without reallocation"); if (sheet->IsGecko()) { -#ifdef MOZ_OLD_STYLE - sheet->AsGecko()->ReparseSheet(NS_ConvertUTF8toUTF16(sheetText)); -#else MOZ_CRASH("old style system disabled"); -#endif } else { ServoStyleSheet* servoSheet = sheet->AsServo(); // NB: The pref sheet never has @import rules. diff --git a/layout/style/nsMediaFeatures.cpp b/layout/style/nsMediaFeatures.cpp index d6aad9cd8053..b3b5b88800ce 100644 --- a/layout/style/nsMediaFeatures.cpp +++ b/layout/style/nsMediaFeatures.cpp @@ -15,9 +15,6 @@ #ifdef XP_WIN #include "mozilla/LookAndFeel.h" #endif -#ifdef MOZ_OLD_STYLE -#include "nsCSSRuleProcessor.h" -#endif #include "nsDeviceContext.h" #include "nsIBaseWindow.h" #include "nsIDocShell.h" diff --git a/layout/style/nsRuleProcessorData.h b/layout/style/nsRuleProcessorData.h index 27d2ee6d38ae..ee99820158f2 100644 --- a/layout/style/nsRuleProcessorData.h +++ b/layout/style/nsRuleProcessorData.h @@ -12,511 +12,6 @@ #ifndef nsRuleProcessorData_h_ #define nsRuleProcessorData_h_ -#ifdef MOZ_OLD_STYLE - -#include "nsAutoPtr.h" -#include "nsChangeHint.h" -#include "nsCompatibility.h" -#include "nsCSSPseudoElements.h" -#include "nsRuleWalker.h" -#include "nsNthIndexCache.h" -#include "nsILoadContext.h" -#include "nsIDocument.h" -#include "mozilla/AutoRestore.h" -#include "mozilla/AtomArray.h" -#include "mozilla/BloomFilter.h" -#include "mozilla/EventStates.h" -#include "mozilla/GuardObjects.h" -#include "mozilla/dom/Element.h" - -class nsAtom; -class nsIContent; -class nsICSSPseudoComparator; -struct TreeMatchContext; - -/** - * An AncestorFilter is used to keep track of ancestors so that we can - * quickly tell that a particular selector is not relevant to a given - * element. - */ -class MOZ_STACK_CLASS AncestorFilter { - friend struct TreeMatchContext; - public: - /* Maintenance of our ancestor state */ - void PushAncestor(mozilla::dom::Element *aElement); - void PopAncestor(); - - /* Check whether we might have an ancestor matching one of the given - atom hashes. |hashes| must have length hashListLength */ - template - bool MightHaveMatchingAncestor(const uint32_t* aHashes) const - { - MOZ_ASSERT(mFilter); - for (size_t i = 0; i < hashListLength && aHashes[i]; ++i) { - if (!mFilter->mightContain(aHashes[i])) { - return false; - } - } - - return true; - } - - bool HasFilter() const { return mFilter; } - -#ifdef DEBUG - void AssertHasAllAncestors(mozilla::dom::Element *aElement) const; -#endif - - private: - // Using 2^12 slots makes the Bloom filter a nice round page in - // size, so let's do that. We get a false positive rate of 1% or - // less even with several hundred things in the filter. Note that - // we allocate the filter lazily, because not all tree match - // contexts can use one effectively. - typedef mozilla::BloomFilter<12, nsAtom> Filter; - nsAutoPtr mFilter; - - // Stack of indices to pop to. These are indices into mHashes. - // 16 is chosen because it's enough to avoid most allocations for the - // Speedometer 2 benchmark, and also it covers many cases in some casual - // local browsing tests performed. Higher values in the range of tens - // were observed while testing through local browsing but they were rare. - AutoTArray mPopTargets; - - // List of hashes; this is what we pop using mPopTargets. We store - // hashes of our ancestor element tag names, ids, and classes in - // here. - // 50 is chosen to be the same as the preallocated buffer size used in - // TreeMatchContext::InitAncestors(). This value seems to be large - // enough for Speedometer 2, although some casual testing browsing real - // sites suggested they can easily require values much larger (in the - // range of hundreds.) - AutoTArray mHashes; - - // A debug-only stack of Elements for use in assertions -#ifdef DEBUG - nsTArray mElements; -#endif -}; - -/** - * A |TreeMatchContext| has data about a matching operation. The - * data are not node-specific but are invariants of the DOM tree the - * nodes being matched against are in. - * - * Most of the members are in parameters to selector matching. The - * one out parameter is mHaveRelevantLink. Consumers that use a - * TreeMatchContext for more than one matching operation and care - * about :visited and mHaveRelevantLink need to - * ResetForVisitedMatching() and ResetForUnvisitedMatching() as - * needed. - */ -struct MOZ_STACK_CLASS TreeMatchContext { - // Reset this context for matching for the style-if-:visited. - void ResetForVisitedMatching() { - NS_PRECONDITION(mForStyling, "Why is this being called?"); - mHaveRelevantLink = false; - mVisitedHandling = nsRuleWalker::eRelevantLinkVisited; - } - - void ResetForUnvisitedMatching() { - NS_PRECONDITION(mForStyling, "Why is this being called?"); - mHaveRelevantLink = false; - mVisitedHandling = nsRuleWalker::eRelevantLinkUnvisited; - } - - void SetHaveRelevantLink() { mHaveRelevantLink = true; } - bool HaveRelevantLink() const { return mHaveRelevantLink; } - - nsRuleWalker::VisitedHandlingType VisitedHandling() const - { - return mVisitedHandling; - } - - void AddScopeElement(mozilla::dom::Element* aElement) { - NS_PRECONDITION(mHaveSpecifiedScope, - "Should be set before calling AddScopeElement()"); - mScopes.AppendElement(aElement); - } - bool IsScopeElement(mozilla::dom::Element* aElement) const { - return mScopes.Contains(aElement); - } - void SetHasSpecifiedScope() { - mHaveSpecifiedScope = true; - } - bool HasSpecifiedScope() const { - return mHaveSpecifiedScope; - } - - /** - * Initialize the ancestor filter and list of style scopes. If aElement is - * not null, it and all its ancestors will be passed to - * mAncestorFilter.PushAncestor, starting from the root and - * going down the tree. Must only be called for elements in a document. - */ - void InitAncestors(mozilla::dom::Element *aElement); - - /* - * Helper class for maintaining the ancestor state. - * - * This class does nothing if aTreeMatchContext is null, which is the case for - * the Servo style system. - */ - class MOZ_RAII AutoAncestorPusher { - public: - explicit AutoAncestorPusher(TreeMatchContext* aTreeMatchContext - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : mPushedAncestor(false) - , mTreeMatchContext(aTreeMatchContext) - , mElement(nullptr) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - } - - void PushAncestor(mozilla::dom::Element* aElement) { - if (!mTreeMatchContext) { - MOZ_ASSERT(!aElement || aElement->IsStyledByServo()); - return; - } - - MOZ_ASSERT(!mElement); - if (aElement) { - mElement = aElement; - mPushedAncestor = true; - mTreeMatchContext->mAncestorFilter.PushAncestor(aElement); - } - } - - void PushAncestor(nsIContent* aContent) { - if (!mTreeMatchContext) { - MOZ_ASSERT(!aContent || aContent->IsStyledByServo()); - return; - } - - if (aContent && aContent->IsElement()) { - PushAncestor(aContent->AsElement()); - } - } - - ~AutoAncestorPusher() { - if (mPushedAncestor) { - mTreeMatchContext->mAncestorFilter.PopAncestor(); - } - } - - private: - bool mPushedAncestor; - TreeMatchContext* mTreeMatchContext; - mozilla::dom::Element* mElement; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - }; - - /* Helper class for tracking whether we're skipping the ApplyStyleFixups - * code for special cases where child element style is modified based on - * parent display value. - * - * The optional second parameter aSkipParentDisplayBasedStyleFixup allows - * this class to be instantiated but only conditionally activated (e.g. - * in cases where we may or may not want to be skipping flex/grid-item - * style fixup for a particular chunk of code). - */ - class MOZ_RAII AutoParentDisplayBasedStyleFixupSkipper { - public: - explicit AutoParentDisplayBasedStyleFixupSkipper(TreeMatchContext& aTreeMatchContext, - bool aSkipParentDisplayBasedStyleFixup = true - MOZ_GUARD_OBJECT_NOTIFIER_PARAM) - : mAutoRestorer(aTreeMatchContext.mSkippingParentDisplayBasedStyleFixup) - { - MOZ_GUARD_OBJECT_NOTIFIER_INIT; - if (aSkipParentDisplayBasedStyleFixup) { - aTreeMatchContext.mSkippingParentDisplayBasedStyleFixup = true; - } - } - - private: - mozilla::AutoRestore mAutoRestorer; - MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER - }; - - // Is this matching operation for the creation of a style context? - // (If it is, we need to set slow selector bits on nodes indicating - // that certain restyling needs to happen.) - const bool mForStyling; - - private: - // When mVisitedHandling is eRelevantLinkUnvisited, this is set to true if a - // relevant link (see explanation in definition of VisitedHandling enum) was - // encountered during the matching process, which means that matching needs - // to be rerun with eRelevantLinkVisited. Otherwise, its behavior is - // undefined (it might get set appropriately, or might not). - bool mHaveRelevantLink; - - // If true, then our contextual reference element set is specified, - // and is given by mScopes. - bool mHaveSpecifiedScope; - - // How matching should be performed. See the documentation for - // nsRuleWalker::VisitedHandlingType. - nsRuleWalker::VisitedHandlingType mVisitedHandling; - - // For matching :scope - AutoTArray mScopes; - public: - // The document we're working with. - nsIDocument* const mDocument; - - // Whether our document is HTML (as opposed to XML of some sort, - // including XHTML). - // XXX XBL2 issue: Should we be caching this? What should it be for XBL2? - const bool mIsHTMLDocument; - - // Possibly remove use of mCompatMode in SelectorMatches? - // XXX XBL2 issue: Should we be caching this? What should it be for XBL2? - const nsCompatibility mCompatMode; - - // The nth-index cache we should use - nsNthIndexCache mNthIndexCache; - - // An ancestor filter - AncestorFilter mAncestorFilter; - - // Whether this document is using PB mode - bool mUsingPrivateBrowsing; - - // Whether we're currently skipping the part of ApplyStyleFixups that changes - // style of child elements based on their parent's display value - // (e.g. for children of elements that have a mandatory frame-type for which - // we ignore "display:flex/grid"). - bool mSkippingParentDisplayBasedStyleFixup; - - // An enum that communicates the consumer's intensions for this - // TreeMatchContext in terms of :visited handling. eNeverMatchVisited means - // that this TreeMatchContext's VisitedHandlingType will always be - // eRelevantLinkUnvisited (in other words, this value will be passed to the - // constructor and ResetForVisitedMatching() will never be called). - // eMatchVisitedDefault doesn't communicate any information about the current - // or future VisitedHandlingType of this TreeMatchContext. - enum MatchVisited { - eNeverMatchVisited, - eMatchVisitedDefault - }; - - // List of ancestor elements that define a style scope (due to having a - //