author | Xidorn Quan <me@upsuper.org> |
Tue, 17 Apr 2018 10:28:33 +1000 | |
changeset 413981 | 70235b1de25db413dd7b102768d66ad89b0f2074 |
parent 413980 | e5d9b47a10e0ba65b6908af9fe3eed955bdb0cf9 |
child 413982 | 6d609d7d44de2918a04c4dcd81e5b4db9421133b |
push id | 33853 |
push user | cbrindusan@mozilla.com |
push date | Tue, 17 Apr 2018 09:51:13 +0000 |
treeherder | mozilla-central@8b0ba3f7d099 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | hiro |
bugs | 1454524 |
milestone | 61.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
|
--- a/dom/animation/KeyframeUtils.cpp +++ b/dom/animation/KeyframeUtils.cpp @@ -43,206 +43,27 @@ namespace mozilla { // // ------------------------------------------------------------------ // For the aAllowList parameter of AppendStringOrStringSequence and // GetPropertyValuesPairs. enum class ListAllowance { eDisallow, eAllow }; /** - * A comparator to sort nsCSSPropertyID values such that longhands are sorted - * before shorthands, and shorthands with fewer components are sorted before - * shorthands with more components. - * - * Using this allows us to prioritize values specified by longhands (or smaller - * shorthand subsets) when longhands and shorthands are both specified - * on the one keyframe. - * - * Example orderings that result from this: - * - * margin-left, margin - * - * and: - * - * border-top-color, border-color, border-top, border - */ -class PropertyPriorityComparator -{ -public: - PropertyPriorityComparator() - : mSubpropertyCountInitialized(false) {} - - bool Equals(nsCSSPropertyID aLhs, nsCSSPropertyID aRhs) const - { - return aLhs == aRhs; - } - - bool LessThan(nsCSSPropertyID aLhs, - nsCSSPropertyID aRhs) const - { - bool isShorthandLhs = nsCSSProps::IsShorthand(aLhs); - bool isShorthandRhs = nsCSSProps::IsShorthand(aRhs); - - if (isShorthandLhs) { - if (isShorthandRhs) { - // First, sort shorthands by the number of longhands they have. - uint32_t subpropCountLhs = SubpropertyCount(aLhs); - uint32_t subpropCountRhs = SubpropertyCount(aRhs); - if (subpropCountLhs != subpropCountRhs) { - return subpropCountLhs < subpropCountRhs; - } - // Otherwise, sort by IDL name below. - } else { - // Put longhands before shorthands. - return false; - } - } else { - if (isShorthandRhs) { - // Put longhands before shorthands. - return true; - } - } - // For two longhand properties, or two shorthand with the same number - // of longhand components, sort by IDL name. - return nsCSSProps::PropertyIDLNameSortPosition(aLhs) < - nsCSSProps::PropertyIDLNameSortPosition(aRhs); - } - - uint32_t SubpropertyCount(nsCSSPropertyID aProperty) const - { - if (!mSubpropertyCountInitialized) { - PodZero(&mSubpropertyCount); - mSubpropertyCountInitialized = true; - } - if (mSubpropertyCount[aProperty] == 0) { - uint32_t count = 0; - CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES( - p, aProperty, CSSEnabledState::eForAllContent) { - ++count; - } - mSubpropertyCount[aProperty] = count; - } - return mSubpropertyCount[aProperty]; - } - -private: - // Cache of shorthand subproperty counts. - mutable RangedArray< - uint32_t, - eCSSProperty_COUNT_no_shorthands, - eCSSProperty_COUNT - eCSSProperty_COUNT_no_shorthands> mSubpropertyCount; - mutable bool mSubpropertyCountInitialized; -}; - -/** - * Adaptor for PropertyPriorityComparator to sort objects which have - * a mProperty member. - */ -template <typename T> -class TPropertyPriorityComparator : PropertyPriorityComparator -{ -public: - bool Equals(const T& aLhs, const T& aRhs) const - { - return PropertyPriorityComparator::Equals(aLhs.mProperty, aRhs.mProperty); - } - bool LessThan(const T& aLhs, const T& aRhs) const - { - return PropertyPriorityComparator::LessThan(aLhs.mProperty, aRhs.mProperty); - } -}; - -/** - * Iterator to walk through a PropertyValuePair array using the ordering - * provided by PropertyPriorityComparator. - */ -class PropertyPriorityIterator -{ -public: - explicit PropertyPriorityIterator( - const nsTArray<PropertyValuePair>& aProperties) - : mProperties(aProperties) - { - mSortedPropertyIndices.SetCapacity(mProperties.Length()); - for (size_t i = 0, len = mProperties.Length(); i < len; ++i) { - PropertyAndIndex propertyIndex = { mProperties[i].mProperty, i }; - mSortedPropertyIndices.AppendElement(propertyIndex); - } - mSortedPropertyIndices.Sort(PropertyAndIndex::Comparator()); - } - - class Iter - { - public: - explicit Iter(const PropertyPriorityIterator& aParent) - : mParent(aParent) - , mIndex(0) { } - - static Iter EndIter(const PropertyPriorityIterator &aParent) - { - Iter iter(aParent); - iter.mIndex = aParent.mSortedPropertyIndices.Length(); - return iter; - } - - bool operator!=(const Iter& aOther) const - { - return mIndex != aOther.mIndex; - } - - Iter& operator++() - { - MOZ_ASSERT(mIndex + 1 <= mParent.mSortedPropertyIndices.Length(), - "Should not seek past end iterator"); - mIndex++; - return *this; - } - - const PropertyValuePair& operator*() - { - MOZ_ASSERT(mIndex < mParent.mSortedPropertyIndices.Length(), - "Should not try to dereference an end iterator"); - return mParent.mProperties[mParent.mSortedPropertyIndices[mIndex].mIndex]; - } - - private: - const PropertyPriorityIterator& mParent; - size_t mIndex; - }; - - Iter begin() { return Iter(*this); } - Iter end() { return Iter::EndIter(*this); } - -private: - struct PropertyAndIndex - { - nsCSSPropertyID mProperty; - size_t mIndex; // Index of mProperty within mProperties - - typedef TPropertyPriorityComparator<PropertyAndIndex> Comparator; - }; - - const nsTArray<PropertyValuePair>& mProperties; - nsTArray<PropertyAndIndex> mSortedPropertyIndices; -}; - -/** * A property-values pair obtained from the open-ended properties * discovered on a regular keyframe or property-indexed keyframe object. * * Single values (as required by a regular keyframe, and as also supported * on property-indexed keyframes) are stored as the only element in * mValues. */ struct PropertyValuesPair { nsCSSPropertyID mProperty; nsTArray<nsString> mValues; - - typedef TPropertyPriorityComparator<PropertyValuesPair> Comparator; }; /** * An additional property (for a property-values pair) found on a * BaseKeyframe or BasePropertyIndexedKeyframe object. */ struct AdditionalProperty {