Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: Source/core/css/resolver/StyleResolver.cpp

Issue 21779003: Web Animations CSS: Snapshot missing start/end Keyframes and remove duplicates (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make it build. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/css/CSSAnimations.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled()); 768 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled());
769 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name); 769 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name);
770 if (!keyframesRule) 770 if (!keyframesRule)
771 return; 771 return;
772 772
773 // Construct and populate the style for each keyframe 773 // Construct and populate the style for each keyframe
774 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes(); 774 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes();
775 for (unsigned i = 0; i < styleKeyframes.size(); ++i) { 775 for (size_t i = 0; i < styleKeyframes.size(); ++i) {
776 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get(); 776 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get();
777 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe); 777 RefPtr<RenderStyle> keyframeStyle = styleForKeyframe(element, style, sty leKeyframe);
778
779 Vector<float> offsets; 778 Vector<float> offsets;
780 styleKeyframe->getKeys(offsets); 779 styleKeyframe->getKeys(offsets);
781 for (size_t j = 0; j < offsets.size(); ++j) { 780 for (size_t j = 0; j < offsets.size(); ++j) {
782 RefPtr<Keyframe> keyframe = Keyframe::create(); 781 RefPtr<Keyframe> keyframe = Keyframe::create();
783 keyframe->setOffset(offsets[j]); 782 keyframe->setOffset(offsets[j]);
784 const StylePropertySet* properties = styleKeyframe->properties(); 783 const StylePropertySet* properties = styleKeyframe->properties();
785 // FIXME: AnimatableValues should be shared between the keyframes at different offsets. 784 // FIXME: AnimatableValues should be shared between the keyframes at different offsets.
786 for (unsigned k = 0; k < properties->propertyCount(); k++) { 785 for (unsigned k = 0; k < properties->propertyCount(); k++) {
787 CSSPropertyID property = properties->propertyAt(k).id(); 786 CSSPropertyID property = properties->propertyAt(k).id();
788 // FIXME: CSSValue needs to be resolved.
789 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get()); 787 keyframe->setPropertyValue(property, CSSAnimatableValueFactory:: create(property, keyframeStyle.get()).get());
790 } 788 }
791 keyframes.append(keyframe); 789 keyframes.append(keyframe);
792 } 790 }
793 } 791 }
794 792
795 // FIXME: If the 0% keyframe is missing, create it (but only if there is at least one other keyframe) 793 if (keyframes.isEmpty())
796 // FIXME: If the 100% keyframe is missing, create it (but only if there is a t least one other keyframe) 794 return;
795
796 // Remove duplicate keyframes. In CSS the last keyframe at a given offset ta kes priority.
797 size_t targetIndex = 0;
798 for (size_t i = 1; i < keyframes.size(); i++) {
799 if (keyframes[i]->offset() != keyframes[targetIndex]->offset())
800 targetIndex++;
801 if (targetIndex != i)
802 keyframes[targetIndex] = keyframes[i];
803 }
804 keyframes.shrink(targetIndex + 1);
805
806 bool isStartKeyframeMissing = keyframes[0]->offset();
807 bool isEndKeyframeMissing = keyframes[keyframes.size() - 1]->offset() != 1;
808 if (!isStartKeyframeMissing && !isEndKeyframeMissing)
809 return;
810
811 HashSet<CSSPropertyID> allProperties;
812 for (size_t i = 0; i < styleKeyframes.size(); ++i) {
813 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get();
814 Vector<float> offsets;
815 styleKeyframe->getKeys(offsets);
816 const StylePropertySet* properties = styleKeyframe->properties();
817 for (unsigned j = 0; j < properties->propertyCount(); ++j) {
818 allProperties.add(properties->propertyAt(j).id());
819 }
820 }
821
822 if (isStartKeyframeMissing) {
823 RefPtr<Keyframe> keyframe = Keyframe::create();
824 keyframe->setOffset(0);
825 for (HashSet<CSSPropertyID>::const_iterator iter = allProperties.begin() ; iter != allProperties.end(); ++iter)
826 keyframe->setPropertyValue(*iter, CSSAnimatableValueFactory::create( *iter, style).get());
827 keyframes.prepend(keyframe);
828 }
829
830 if (isEndKeyframeMissing) {
831 RefPtr<Keyframe> keyframe = Keyframe::create();
832 keyframe->setOffset(1);
833 for (HashSet<CSSPropertyID>::const_iterator iter = allProperties.begin() ; iter != allProperties.end(); ++iter)
834 keyframe->setPropertyValue(*iter, CSSAnimatableValueFactory::create( *iter, style).get());
835 keyframes.append(keyframe);
836 }
797 } 837 }
798 838
799 const StylePropertySet* StyleResolver::firstKeyframeStyles(const Element* elemen t, const StringImpl* animationName) 839 const StylePropertySet* StyleResolver::firstKeyframeStyles(const Element* elemen t, const StringImpl* animationName)
800 { 840 {
801 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled()); 841 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled());
802 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, animationName); 842 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, animationName);
803 if (!keyframesRule) 843 if (!keyframesRule)
804 return 0; 844 return 0;
805 845
806 // Find the last keyframe at offset 0 846 // Find the last keyframe at offset 0
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); 1475 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che);
1436 1476
1437 fprintf(stderr, "Total:\n"); 1477 fprintf(stderr, "Total:\n");
1438 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, 1478 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); 1479 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache);
1440 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); 1480 fprintf(stderr, "----------------------------------------------------------- ---------------------\n");
1441 } 1481 }
1442 #endif 1482 #endif
1443 1483
1444 } // namespace WebCore 1484 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/css/CSSAnimations.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698