OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 hundredPercentKeyframe = StyleKeyframe::create().leakRef(); | 756 hundredPercentKeyframe = StyleKeyframe::create().leakRef(); |
757 hundredPercentKeyframe->setKeyText("100%"); | 757 hundredPercentKeyframe->setKeyText("100%"); |
758 } | 758 } |
759 KeyframeValue keyframeValue(1, 0); | 759 KeyframeValue keyframeValue(1, 0); |
760 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, hundredPercentK eyframe)); | 760 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, hundredPercentK eyframe)); |
761 keyframeValue.addProperties(hundredPercentKeyframe->properties()); | 761 keyframeValue.addProperties(hundredPercentKeyframe->properties()); |
762 list.insert(keyframeValue); | 762 list.insert(keyframeValue); |
763 } | 763 } |
764 } | 764 } |
765 | 765 |
766 bool compareOffsets(const RefPtr<Keyframe>& a, const RefPtr<Keyframe>& b) | |
767 { | |
768 return a->offset() < b->offset(); | |
769 } | |
Steve Block
2013/08/06 06:30:20
We already have this helper in KeyframeAnimationEf
dstockwell
2013/08/06 07:14:28
Done.
| |
770 | |
766 void StyleResolver::resolveKeyframes(Element* element, const RenderStyle* style, const StringImpl* name, KeyframeAnimationEffect::KeyframeVector& keyframes) | 771 void StyleResolver::resolveKeyframes(Element* element, const RenderStyle* style, const StringImpl* name, KeyframeAnimationEffect::KeyframeVector& keyframes) |
767 { | 772 { |
768 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name); | 773 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name); |
769 if (!keyframesRule) | 774 if (!keyframesRule) |
770 return; | 775 return; |
771 | 776 |
772 // Construct and populate the style for each keyframe | 777 // Construct and populate the style for each keyframe |
773 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); | 778 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); |
774 for (unsigned i = 0; i < styleKeyframes.size(); ++i) { | 779 for (unsigned i = 0; i < styleKeyframes.size(); ++i) { |
775 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); | 780 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); |
776 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe); | 781 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe); |
777 | |
778 Vector<float> offsets; | 782 Vector<float> offsets; |
779 styleKeyframe->getKeys(offsets); | 783 styleKeyframe->getKeys(offsets); |
780 for (size_t j = 0; j < offsets.size(); ++j) { | 784 for (size_t j = 0; j < offsets.size(); ++j) { |
781 RefPtr<Keyframe> keyframe = Keyframe::create(); | 785 RefPtr<Keyframe> keyframe = Keyframe::create(); |
782 keyframe->setOffset(offsets[j]); | 786 keyframe->setOffset(offsets[j]); |
783 const StylePropertySet* properties = styleKeyframe->properties(); | 787 const StylePropertySet* properties = styleKeyframe->properties(); |
784 // FIXME: AnimatableValues should be shared between the keyframes at different offsets. | 788 // FIXME: AnimatableValues should be shared between the keyframes at different offsets. |
785 for (unsigned k = 0; k < properties->propertyCount(); k++) { | 789 for (unsigned k = 0; k < properties->propertyCount(); k++) { |
786 CSSPropertyID property = properties->propertyAt(k).id(); | 790 CSSPropertyID property = properties->propertyAt(k).id(); |
787 // FIXME: CSSValue needs to be resolved. | |
788 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get()); | 791 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get()); |
789 } | 792 } |
790 keyframes.append(keyframe); | 793 keyframes.append(keyframe); |
791 } | 794 } |
792 } | 795 } |
793 | 796 |
794 // FIXME: If the 0% keyframe is missing, create it (but only if there is at least one other keyframe) | 797 if (keyframes.isEmpty()) |
795 // FIXME: If the 100% keyframe is missing, create it (but only if there is a t least one other keyframe) | 798 return; |
799 | |
800 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta kes priority. | |
801 std::stable_sort(keyframes.begin(), keyframes.end(), compareOffsets); | |
802 unsigned duplicates = 0; | |
Timothy Loh
2013/08/05 03:44:59
I think this should work:
keyframes.shrink(std
dstockwell
2013/08/05 05:52:18
Tim and I discussed off thread, and while somethin
Steve Block
2013/08/06 06:30:20
Does unique() work with reverse iterators?
| |
803 for (size_t i = 1; i < keyframes.size(); i++) { | |
804 if (keyframes[i]->offset() == keyframes[i - 1 - duplicates]->offset()) { | |
805 keyframes[i - 1 - duplicates] = keyframes[i]; | |
806 ++duplicates; | |
807 } else if (duplicates) { | |
808 keyframes[i - duplicates] = keyframes[i]; | |
Steve Block
2013/08/06 06:30:20
I think this would be easier to follow if you used
dstockwell
2013/08/06 07:14:28
Done.
| |
809 } | |
810 } | |
811 keyframes.shrink(keyframes.size() - duplicates); | |
812 | |
813 bool missingStartKeyframe = !keyframes[0]->offset; | |
Steve Block
2013/08/06 06:30:20
I think you have this inverted.
Also, this local
dstockwell
2013/08/06 07:14:28
Fixed. Be nice if we could write != 0 :)
| |
814 bool missingEndKeyframe = keyframes[keyframes.size() - 1]->offset != 1; | |
815 if (!missingStartKeyframe && !missingEndKeyframe) | |
816 return; | |
817 | |
818 HashSet<CSSPropertyID> allProperties; | |
819 for (unsigned i = 0; i < styleKeyframes.size(); ++i) { | |
Steve Block
2013/08/06 06:30:20
I think you should use size_t in loops like this,
dstockwell
2013/08/06 07:14:28
Done.
| |
820 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); | |
821 Vector<float> offsets; | |
822 styleKeyframe->getKeys(offsets); | |
823 const StylePropertySet* properties = styleKeyframe->properties(); | |
824 for (unsigned j = 0; j < properties->propertyCount(); ++j) { | |
825 allProperties.add(properties->propertyAt(j).id()); | |
826 } | |
827 } | |
828 | |
829 if (missingStartKeyframe) { | |
830 RefPtr<Keyframe> keyframe = Keyframe::create(); | |
831 keyframe->setOffset(0); | |
832 for (HashSet<CSSPropertyID>::const_iterator iter = allProperties.begin() ; iter != allProperties.end(); ++iter) | |
833 keyframe->setPropertyValue(*iter, CSSAnimatableValueFactory::create( *iter, style).get()); | |
834 keyframes.prepend(keyframe); | |
835 } | |
836 | |
837 if (missingEndKeyframe) { | |
838 RefPtr<Keyframe> keyframe = Keyframe::create(); | |
839 keyframe->setOffset(1); | |
840 for (HashSet<CSSPropertyID>::const_iterator iter = allProperties.begin() ; iter != allProperties.end(); ++iter) | |
841 keyframe->setPropertyValue(*iter, CSSAnimatableValueFactory::create( *iter, style).get()); | |
842 keyframes.append(keyframe); | |
843 } | |
796 } | 844 } |
797 | 845 |
798 const StylePropertySet* StyleResolver::firstKeyframeStyles(const Element* elemen t, const StringImpl* animationName) | 846 const StylePropertySet* StyleResolver::firstKeyframeStyles(const Element* elemen t, const StringImpl* animationName) |
799 { | 847 { |
800 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, animationName); | 848 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, animationName); |
801 if (!keyframesRule) | 849 if (!keyframesRule) |
802 return 0; | 850 return 0; |
803 | 851 |
804 // Find the last keyframe at offset 0 | 852 // Find the last keyframe at offset 0 |
805 const StyleKeyframe* firstKeyframe = 0; | 853 const StyleKeyframe* firstKeyframe = 0; |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1435 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); | 1483 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); |
1436 | 1484 |
1437 fprintf(stderr, "Total:\n"); | 1485 fprintf(stderr, "Total:\n"); |
1438 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, | 1486 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, |
1439 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); | 1487 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); |
1440 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); | 1488 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); |
1441 } | 1489 } |
1442 #endif | 1490 #endif |
1443 | 1491 |
1444 } // namespace WebCore | 1492 } // namespace WebCore |
OLD | NEW |