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

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

Issue 21012002: Web Animations: Trigger and update CSS Animations backed by the Web Animations model (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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/css/resolver/StyleResolver.h ('k') | Source/core/dom/Document.h » ('j') | 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 18 matching lines...) Expand all
29 #include "config.h" 29 #include "config.h"
30 #include "core/css/resolver/StyleResolver.h" 30 #include "core/css/resolver/StyleResolver.h"
31 31
32 #include "CSSPropertyNames.h" 32 #include "CSSPropertyNames.h"
33 #include "HTMLNames.h" 33 #include "HTMLNames.h"
34 #include "RuntimeEnabledFeatures.h" 34 #include "RuntimeEnabledFeatures.h"
35 #include "StylePropertyShorthand.h" 35 #include "StylePropertyShorthand.h"
36 #include "core/animation/AnimatableValue.h" 36 #include "core/animation/AnimatableValue.h"
37 #include "core/animation/Animation.h" 37 #include "core/animation/Animation.h"
38 #include "core/animation/DocumentTimeline.h" 38 #include "core/animation/DocumentTimeline.h"
39 #include "core/animation/css/CSSAnimations.h"
39 #include "core/css/CSSCalculationValue.h" 40 #include "core/css/CSSCalculationValue.h"
40 #include "core/css/CSSDefaultStyleSheets.h" 41 #include "core/css/CSSDefaultStyleSheets.h"
41 #include "core/css/CSSFontSelector.h" 42 #include "core/css/CSSFontSelector.h"
42 #include "core/css/CSSKeyframeRule.h" 43 #include "core/css/CSSKeyframeRule.h"
43 #include "core/css/CSSKeyframesRule.h" 44 #include "core/css/CSSKeyframesRule.h"
44 #include "core/css/CSSParser.h" 45 #include "core/css/CSSParser.h"
45 #include "core/css/CSSReflectValue.h" 46 #include "core/css/CSSReflectValue.h"
46 #include "core/css/CSSRuleList.h" 47 #include "core/css/CSSRuleList.h"
47 #include "core/css/CSSSelector.h" 48 #include "core/css/CSSSelector.h"
48 #include "core/css/CSSStyleRule.h" 49 #include "core/css/CSSStyleRule.h"
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 // FIXME: Shouldn't this be on RenderBody::styleDidChange? 617 // FIXME: Shouldn't this be on RenderBody::styleDidChange?
617 if (element->hasTagName(bodyTag)) 618 if (element->hasTagName(bodyTag))
618 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor)); 619 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor));
619 620
620 // Now return the style. 621 // Now return the style.
621 return state.takeStyle(); 622 return state.takeStyle();
622 } 623 }
623 624
624 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* e, const Render Style* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue ) 625 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* e, const Render Style* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue )
625 { 626 {
627 ASSERT(!RuntimeEnabledFeatures::webAnimationsCSSEnabled());
626 ASSERT(document()->frame()); 628 ASSERT(document()->frame());
627 ASSERT(documentSettings()); 629 ASSERT(documentSettings());
628 630
629 if (e == document()->documentElement()) 631 if (e == document()->documentElement())
630 resetDirectionAndWritingModeOnDocument(document()); 632 resetDirectionAndWritingModeOnDocument(document());
631 StyleResolverState state(document(), e); 633 StyleResolverState state(document(), e);
632 634
633 MatchResult result; 635 MatchResult result;
634 if (keyframe->properties()) 636 if (keyframe->properties())
635 result.addMatchedProperties(keyframe->properties()); 637 result.addMatchedProperties(keyframe->properties());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 if (stack.isEmpty()) 698 if (stack.isEmpty())
697 return 0; 699 return 0;
698 700
699 for (size_t i = 0; i < stack.size(); ++i) { 701 for (size_t i = 0; i < stack.size(); ++i) {
700 if (const StyleRuleKeyframes* keyframesRule = stack.at(i)->keyframeStyle sForAnimation(animationName)) 702 if (const StyleRuleKeyframes* keyframesRule = stack.at(i)->keyframeStyle sForAnimation(animationName))
701 return keyframesRule; 703 return keyframesRule;
702 } 704 }
703 return 0; 705 return 0;
704 } 706 }
705 707
708 void StyleResolver::keyframeStylesForAnimation(Element* element, const StringImp l* name, KeyframeAnimationEffect::KeyframeVector& keyframes)
dglazkov 2013/07/29 18:15:39 Not for this patch, but just curious: does this ha
dstockwell 2013/07/30 01:12:48 I think most of the logic can move out and I can w
709 {
710 ASSERT(RuntimeEnabledFeatures::webAnimationsCSSEnabled());
711
712 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(element, name);
713 if (!keyframesRule)
714 return;
715
716 // Construct and populate the style for each keyframe
717 const Vector<RefPtr<StyleKeyframe> >& styleKeyframes = keyframesRule->keyfra mes();
718 for (unsigned i = 0; i < styleKeyframes.size(); ++i) {
719 const StyleKeyframe* styleKeyframe = styleKeyframes[i].get();
720
721 Vector<float> offsets;
722 styleKeyframe->getKeys(offsets);
723 for (size_t j = 0; j < offsets.size(); ++j) {
724 RefPtr<Keyframe> keyframe = Keyframe::create();
725 keyframe->setOffset(offsets[j]);
726 const StylePropertySet* properties = styleKeyframe->properties();
727 // FIXME: AnimatableValues should be shared between the keyframes at different offsets.
728 for (unsigned k = 0; k < properties->propertyCount(); k++) {
729 CSSPropertyID property = properties->propertyAt(k).id();
730 // FIXME: CSSValue needs to be resolved.
731 keyframe->setPropertyValue(property, AnimatableValue::create(pro perties->getPropertyCSSValue(property).get()).get());
732 }
733 keyframes.append(keyframe);
734 }
735 }
736
737 // FIXME: If the 0% keyframe is missing, create it (but only if there is at least one other keyframe)
738 // FIXME: If the 100% keyframe is missing, create it (but only if there is a t least one other keyframe)
739 }
740
706 void StyleResolver::keyframeStylesForAnimation(Element* e, const RenderStyle* el ementStyle, KeyframeList& list) 741 void StyleResolver::keyframeStylesForAnimation(Element* e, const RenderStyle* el ementStyle, KeyframeList& list)
707 { 742 {
708 list.clear(); 743 list.clear();
709 744
710 // Get the keyframesRule for this name 745 // Get the keyframesRule for this name
711 if (!e || list.animationName().isEmpty()) 746 if (!e || list.animationName().isEmpty())
712 return; 747 return;
713 748
714 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(e, list.a nimationName().impl()); 749 const StyleRuleKeyframes* keyframesRule = matchScopedKeyframesRule(e, list.a nimationName().impl());
715 if (!keyframesRule) 750 if (!keyframesRule)
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size ); 1218 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size );
1184 } 1219 }
1185 1220
1186 void StyleResolver::invalidateMatchedPropertiesCache() 1221 void StyleResolver::invalidateMatchedPropertiesCache()
1187 { 1222 {
1188 m_matchedPropertiesCache.clear(); 1223 m_matchedPropertiesCache.clear();
1189 } 1224 }
1190 1225
1191 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult) 1226 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult)
1192 { 1227 {
1193 const Element* element = state.element(); 1228 Element* element = state.element();
dglazkov 2013/07/29 18:15:39 Whoops. This seems wrong. We _just_ did a pass at
dstockwell 2013/07/30 01:12:48 The only mutation here is the call to ensureActive
1194 ASSERT(element); 1229 ASSERT(element);
1195 STYLE_STATS_ADD_MATCHED_PROPERTIES_SEARCH(); 1230 STYLE_STATS_ADD_MATCHED_PROPERTIES_SEARCH();
1196 1231
1197 unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash( matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0; 1232 unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash( matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0;
1198 bool applyInheritedOnly = false; 1233 bool applyInheritedOnly = false;
1199 const CachedMatchedProperties* cachedMatchedProperties = 0; 1234 const CachedMatchedProperties* cachedMatchedProperties = 0;
1200 1235
1201 if (cacheHash && (cachedMatchedProperties = m_matchedPropertiesCache.find(ca cheHash, state, matchResult)) 1236 if (cacheHash && (cachedMatchedProperties = m_matchedPropertiesCache.find(ca cheHash, state, matchResult))
1202 && MatchedPropertiesCache::isCacheable(element, state.style(), state.par entStyle())) { 1237 && MatchedPropertiesCache::isCacheable(element, state.style(), state.par entStyle())) {
1203 STYLE_STATS_ADD_MATCHED_PROPERTIES_HIT(); 1238 STYLE_STATS_ADD_MATCHED_PROPERTIES_HIT();
(...skipping 20 matching lines...) Expand all
1224 applyMatchedProperties<VariableDefinitions>(state, matchResult, false, 0, ma tchResult.matchedProperties.size() - 1, applyInheritedOnly); 1259 applyMatchedProperties<VariableDefinitions>(state, matchResult, false, 0, ma tchResult.matchedProperties.size() - 1, applyInheritedOnly);
1225 applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchR esult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedO nly); 1260 applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchR esult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedO nly);
1226 applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchR esult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly) ; 1261 applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchR esult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly) ;
1227 applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchR esult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); 1262 applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchR esult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1228 1263
1229 // Apply animation properties in order to apply animation results and trigge r transitions below. 1264 // Apply animation properties in order to apply animation results and trigge r transitions below.
1230 applyMatchedProperties<AnimationProperties>(state, matchResult, false, 0, ma tchResult.matchedProperties.size() - 1, applyInheritedOnly); 1265 applyMatchedProperties<AnimationProperties>(state, matchResult, false, 0, ma tchResult.matchedProperties.size() - 1, applyInheritedOnly);
1231 applyMatchedProperties<AnimationProperties>(state, matchResult, true, matchR esult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedO nly); 1266 applyMatchedProperties<AnimationProperties>(state, matchResult, true, matchR esult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedO nly);
1232 applyMatchedProperties<AnimationProperties>(state, matchResult, true, matchR esult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly) ; 1267 applyMatchedProperties<AnimationProperties>(state, matchResult, true, matchR esult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly) ;
1233 applyMatchedProperties<AnimationProperties>(state, matchResult, true, matchR esult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); 1268 applyMatchedProperties<AnimationProperties>(state, matchResult, true, matchR esult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1234 // FIXME: animations should be triggered here 1269
1270 if (RuntimeEnabledFeatures::webAnimationsCSSEnabled()) {
1271 const CSSAnimationDataList* animations = state.style()->animations();
1272 EDisplay display = state.style()->display();
1273 if ((display != NONE && animations && animations->size()) || element->ha sActiveAnimations()) {
1274 element->ensureActiveAnimations()->cssAnimations()->update(element, display, this, animations);
dglazkov 2013/07/29 18:15:39 Curious: why does a DOM element hold information a
dstockwell 2013/07/30 01:12:48 I was going to store it in animation-land in a Map
dglazkov 2013/07/30 22:07:27 I just spoke with shans@ about this, and I think w
1275 }
1276 }
1235 1277
1236 // Now we have all of the matched rules in the appropriate order. Walk the r ules and apply 1278 // Now we have all of the matched rules in the appropriate order. Walk the r ules and apply
1237 // high-priority properties first, i.e., those properties that other propert ies depend on. 1279 // high-priority properties first, i.e., those properties that other propert ies depend on.
1238 // The order is (1) high-priority not important, (2) high-priority important , (3) normal not important 1280 // The order is (1) high-priority not important, (2) high-priority important , (3) normal not important
1239 // and (4) normal important. 1281 // and (4) normal important.
1240 state.setLineHeightValue(0); 1282 state.setLineHeightValue(0);
1241 applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly); 1283 applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
1242 // Animation contributions are processed here because CSS Animations are ove rridable by user !important rules. 1284 // Animation contributions are processed here because CSS Animations are ove rridable by user !important rules.
1243 if (RuntimeEnabledFeatures::webAnimationsEnabled()) 1285 if (RuntimeEnabledFeatures::webAnimationsEnabled())
1244 applyAnimatedProperties<HighPriorityProperties>(state, element, element- >document()->timeline()); 1286 applyAnimatedProperties<HighPriorityProperties>(state, element, element- >document()->timeline());
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); 1502 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che);
1461 1503
1462 fprintf(stderr, "Total:\n"); 1504 fprintf(stderr, "Total:\n");
1463 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, 1505 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing,
1464 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); 1506 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache);
1465 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); 1507 fprintf(stderr, "----------------------------------------------------------- ---------------------\n");
1466 } 1508 }
1467 #endif 1509 #endif
1468 1510
1469 } // namespace WebCore 1511 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/dom/Document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698