Bug 1171817 part 13 - Add override of HasLowerCompositeOrderThan for CSS transitions; r=dbaron
authorBrian Birtles <birtles@gmail.com>
Tue, 09 Jun 2015 11:13:54 +0900
changeset 283640 30804bf4a909146d613c2d0f90ca21fa2c583348
parent 283639 80a09a5d4ae4237be8a532cef788a46611c92cad
child 283641 6a5491acd59ccdeaa0baf2ca3b4329dcf677f8dd
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1171817
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1171817 part 13 - Add override of HasLowerCompositeOrderThan for CSS transitions; r=dbaron This patch is quite similar to the code added for CSS animations. We'll factor out some the common code in a subsequent patch in this series.
layout/style/nsTransitionManager.cpp
layout/style/nsTransitionManager.h
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -127,16 +127,74 @@ CSSTransition::TransitionProperty() cons
   // we'll need to store the original transition property so we keep
   // returning the same value in that case.
   dom::KeyframeEffectReadOnly* effect = GetEffect();
   MOZ_ASSERT(effect && effect->AsTransition(),
              "Transition should have a transition effect");
   return effect->AsTransition()->TransitionProperty();
 }
 
+bool
+CSSTransition::HasLowerCompositeOrderThan(const Animation& aOther) const
+{
+  // 0. Object-equality case
+  if (&aOther == this) {
+    return false;
+  }
+
+  // 1. Transitions sort lowest
+  const CSSTransition* otherTransition = aOther.AsCSSTransition();
+  if (!otherTransition) {
+    return true;
+  }
+
+  // 2. CSS transitions that correspond to a transition-property property sort
+  // lower than CSS transitions owned by script.
+  if (!IsUsingCustomCompositeOrder()) {
+    return !aOther.IsUsingCustomCompositeOrder() ?
+           Animation::HasLowerCompositeOrderThan(aOther) :
+           false;
+  }
+  if (!aOther.IsUsingCustomCompositeOrder()) {
+    return true;
+  }
+
+  // 3. Sort by document order
+  Element* ourElement;
+  nsCSSPseudoElements::Type ourPseudoType;
+  GetOwningElement(ourElement, ourPseudoType);
+
+  Element* otherElement;
+  nsCSSPseudoElements::Type otherPseudoType;
+  otherTransition->GetOwningElement(otherElement, otherPseudoType);
+  MOZ_ASSERT(ourElement && otherElement,
+             "Transitions using custom composite order should have an "
+             "owning element");
+
+  if (ourElement != otherElement) {
+    return nsContentUtils::PositionIsBefore(ourElement, otherElement);
+  }
+
+  // 3b. Sort by pseudo: (none) < before < after
+  if (ourPseudoType != otherPseudoType) {
+    return ourPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ||
+           (ourPseudoType == nsCSSPseudoElements::ePseudo_before &&
+            otherPseudoType == nsCSSPseudoElements::ePseudo_after);
+  }
+
+  // 4. (Same element and pseudo): Sort by transition generation
+  if (mSequenceNum != otherTransition->mSequenceNum) {
+    return mSequenceNum < otherTransition->mSequenceNum;
+  }
+
+  // 5. (Same transition generation): Sort by transition property
+  return nsCSSProps::GetStringValue(TransitionProperty()) <
+         nsCSSProps::GetStringValue(otherTransition->TransitionProperty());
+}
+
 /*****************************************************************************
  * nsTransitionManager                                                       *
  *****************************************************************************/
 
 void
 nsTransitionManager::StyleContextChanged(dom::Element *aElement,
                                          nsStyleContext *aOldStyleContext,
                                          nsRefPtr<nsStyleContext>* aNewStyleContext /* inout */)
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -115,16 +115,17 @@ public:
     mOwningPseudoType = nsCSSPseudoElements::ePseudo_NotPseudoElement;
 
     Animation::CancelFromStyle();
     MOZ_ASSERT(mSequenceNum == kUnsequenced);
   }
 
   nsCSSProperty TransitionProperty() const;
 
+  bool HasLowerCompositeOrderThan(const Animation& aOther) const override;
   bool IsUsingCustomCompositeOrder() const override { return !!mOwningElement; }
 
   void SetCreationSequence(uint64_t aIndex)
   {
     MOZ_ASSERT(IsUsingCustomCompositeOrder());
     mSequenceNum = aIndex;
   }