Chromium Code Reviews| 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 } | 764 } |
| 765 | 765 |
| 766 void StyleResolver::resolveKeyframes(Element* element, const RenderStyle* style, const StringImpl* name, KeyframeAnimationEffect::KeyframeVector& keyframes) | 766 void StyleResolver::resolveKeyframes(Element* element, const RenderStyle* style, const StringImpl* name, KeyframeAnimationEffect::KeyframeVector& keyframes) |
| 767 { | 767 { |
| 768 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name); | 768 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name); |
| 769 if (!keyframesRule) | 769 if (!keyframesRule) |
| 770 return; | 770 return; |
| 771 | 771 |
| 772 // Construct and populate the style for each keyframe | 772 // Construct and populate the style for each keyframe |
| 773 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); | 773 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); |
| 774 for (unsigned i = 0; i < styleKeyframes.size(); ++i) { | 774 for (size_t i = 0; i < styleKeyframes.size(); ++i) { |
| 775 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); | 775 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); |
| 776 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe); | 776 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe); |
| 777 | |
| 778 Vector<float> offsets; | 777 Vector<float> offsets; |
| 779 styleKeyframe->getKeys(offsets); | 778 styleKeyframe->getKeys(offsets); |
| 780 for (size_t j = 0; j < offsets.size(); ++j) { | 779 for (size_t j = 0; j < offsets.size(); ++j) { |
| 781 RefPtr<Keyframe> keyframe = Keyframe::create(); | 780 RefPtr<Keyframe> keyframe = Keyframe::create(); |
| 782 keyframe->setOffset(offsets[j]); | 781 keyframe->setOffset(offsets[j]); |
| 783 const StylePropertySet* properties = styleKeyframe->properties(); | 782 const StylePropertySet* properties = styleKeyframe->properties(); |
| 784 // FIXME: AnimatableValues should be shared between the keyframes at different offsets. | 783 // FIXME: AnimatableValues should be shared between the keyframes at different offsets. |
| 785 for (unsigned k = 0; k < properties->propertyCount(); k++) { | 784 for (unsigned k = 0; k < properties->propertyCount(); k++) { |
| 786 CSSPropertyID property = properties->propertyAt(k).id(); | 785 CSSPropertyID property = properties->propertyAt(k).id(); |
| 787 // FIXME: CSSValue needs to be resolved. | |
| 788 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get()); | 786 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get()); |
| 789 } | 787 } |
| 790 keyframes.append(keyframe); | 788 keyframes.append(keyframe); |
| 791 } | 789 } |
| 792 } | 790 } |
| 793 | 791 |
| 794 // FIXME: If the 0% keyframe is missing, create it (but only if there is at least one other keyframe) | 792 if (keyframes.isEmpty()) |
| 795 // FIXME: If the 100% keyframe is missing, create it (but only if there is a t least one other keyframe) | 793 return; |
| 794 | |
| 795 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta kes priority. | |
| 796 std::stable_sort(keyframes.begin(), keyframes.end(), Keyframe::compareOffset s); | |
| 797 size_t targetIndex = 1; | |
| 798 for (size_t i = 1; i < keyframes.size(); i++, targetIndex++) { | |
| 799 size_t previousIndex = targetIndex - 1; | |
| 800 if (keyframes[i]->offset() == keyframes[previousIndex]->offset()) | |
| 801 targetIndex = previousIndex; | |
|
Steve Block
2013/08/07 01:50:45
Might be easier to read if you increment targetInd
dstockwell
2013/08/07 03:40:22
Done.
| |
| 802 if (targetIndex != i) | |
| 803 keyframes[targetIndex] = keyframes[i]; | |
| 804 } | |
| 805 keyframes.shrink(targetIndex); | |
| 806 | |
| 807 bool isMissingStartKeyframe = keyframes[0]->offset; | |
|
Steve Block
2013/08/07 01:50:45
Yeah, the lack of '== 0' and '!= 0' is my least fa
dstockwell
2013/08/07 03:40:22
Done.
| |
| 808 bool isMissingEndKeyframe = keyframes[keyframes.size() - 1]->offset != 1; | |
| 809 if (!isMissingStartKeyframe && !isMissingEndKeyframe) | |
| 810 return; | |
| 811 | |
| 812 HashSet<CSSPropertyID> allProperties; | |
| 813 for (size_t i = 0; i < styleKeyframes.size(); ++i) { | |
| 814 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); | |
| 815 Vector<float> offsets; | |
| 816 styleKeyframe->getKeys(offsets); | |
| 817 const StylePropertySet* properties = styleKeyframe->properties(); | |
| 818 for (unsigned j = 0; j < properties->propertyCount(); ++j) { | |
| 819 allProperties.add(properties->propertyAt(j).id()); | |
| 820 } | |
| 821 } | |
| 822 | |
| 823 if (isMissingStartKeyframe) { | |
| 824 RefPtr<Keyframe> keyframe = Keyframe::create(); | |
| 825 keyframe->setOffset(0); | |
| 826 for (HashSet<CSSPropertyID>::const_iterator iter = allProperties.begin() ; iter != allProperties.end(); ++iter) | |
| 827 keyframe->setPropertyValue(*iter, CSSAnimatableValueFactory::create( *iter, style).get()); | |
| 828 keyframes.prepend(keyframe); | |
| 829 } | |
| 830 | |
| 831 if (isMissingEndKeyframe) { | |
| 832 RefPtr<Keyframe> keyframe = Keyframe::create(); | |
| 833 keyframe->setOffset(1); | |
| 834 for (HashSet<CSSPropertyID>::const_iterator iter = allProperties.begin() ; iter != allProperties.end(); ++iter) | |
| 835 keyframe->setPropertyValue(*iter, CSSAnimatableValueFactory::create( *iter, style).get()); | |
| 836 keyframes.append(keyframe); | |
| 837 } | |
| 796 } | 838 } |
| 797 | 839 |
| 798 const StylePropertySet* StyleResolver::firstKeyframeStyles(const Element* elemen t, const StringImpl* animationName) | 840 const StylePropertySet* StyleResolver::firstKeyframeStyles(const Element* elemen t, const StringImpl* animationName) |
| 799 { | 841 { |
| 800 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, animationName); | 842 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, animationName); |
| 801 if (!keyframesRule) | 843 if (!keyframesRule) |
| 802 return 0; | 844 return 0; |
| 803 | 845 |
| 804 // Find the last keyframe at offset 0 | 846 // Find the last keyframe at offset 0 |
| 805 const StyleKeyframe* firstKeyframe = 0; | 847 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); | 1477 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); |
| 1436 | 1478 |
| 1437 fprintf(stderr, "Total:\n"); | 1479 fprintf(stderr, "Total:\n"); |
| 1438 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, | 1480 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); | 1481 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); |
| 1440 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); | 1482 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); |
| 1441 } | 1483 } |
| 1442 #endif | 1484 #endif |
| 1443 | 1485 |
| 1444 } // namespace WebCore | 1486 } // namespace WebCore |
| OLD | NEW |