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

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

Issue 1371723002: Devtools Animations: Add method to fetch CSS keyframed animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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 26 matching lines...) Expand all
37 #include "core/animation/ElementAnimations.h" 37 #include "core/animation/ElementAnimations.h"
38 #include "core/animation/InvalidatableStyleInterpolation.h" 38 #include "core/animation/InvalidatableStyleInterpolation.h"
39 #include "core/animation/KeyframeEffect.h" 39 #include "core/animation/KeyframeEffect.h"
40 #include "core/animation/StyleInterpolation.h" 40 #include "core/animation/StyleInterpolation.h"
41 #include "core/animation/animatable/AnimatableValue.h" 41 #include "core/animation/animatable/AnimatableValue.h"
42 #include "core/animation/css/CSSAnimatableValueFactory.h" 42 #include "core/animation/css/CSSAnimatableValueFactory.h"
43 #include "core/animation/css/CSSAnimations.h" 43 #include "core/animation/css/CSSAnimations.h"
44 #include "core/css/CSSCalculationValue.h" 44 #include "core/css/CSSCalculationValue.h"
45 #include "core/css/CSSDefaultStyleSheets.h" 45 #include "core/css/CSSDefaultStyleSheets.h"
46 #include "core/css/CSSFontSelector.h" 46 #include "core/css/CSSFontSelector.h"
47 #include "core/css/CSSImportRule.h"
47 #include "core/css/CSSKeyframeRule.h" 48 #include "core/css/CSSKeyframeRule.h"
48 #include "core/css/CSSKeyframesRule.h" 49 #include "core/css/CSSKeyframesRule.h"
49 #include "core/css/CSSReflectValue.h" 50 #include "core/css/CSSReflectValue.h"
50 #include "core/css/CSSRuleList.h" 51 #include "core/css/CSSRuleList.h"
51 #include "core/css/CSSSelector.h" 52 #include "core/css/CSSSelector.h"
52 #include "core/css/CSSStyleRule.h" 53 #include "core/css/CSSStyleRule.h"
53 #include "core/css/CSSValueList.h" 54 #include "core/css/CSSValueList.h"
54 #include "core/css/CSSValuePool.h" 55 #include "core/css/CSSValuePool.h"
55 #include "core/css/ElementRuleCollector.h" 56 #include "core/css/ElementRuleCollector.h"
56 #include "core/css/FontFace.h" 57 #include "core/css/FontFace.h"
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 collector.setMode(SelectorChecker::CollectingCSSRules); 874 collector.setMode(SelectorChecker::CollectingCSSRules);
874 collectPseudoRulesForElement(element, collector, pseudoId, rulesToInclude); 875 collectPseudoRulesForElement(element, collector, pseudoId, rulesToInclude);
875 return collector.matchedCSSRuleList(); 876 return collector.matchedCSSRuleList();
876 } 877 }
877 878
878 PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::cssRulesForElement(Element* e lement, unsigned rulesToInclude) 879 PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::cssRulesForElement(Element* e lement, unsigned rulesToInclude)
879 { 880 {
880 return pseudoCSSRulesForElement(element, NOPSEUDO, rulesToInclude); 881 return pseudoCSSRulesForElement(element, NOPSEUDO, rulesToInclude);
881 } 882 }
882 883
884 PassRefPtrWillBeRawPtr<CSSRuleList> StyleResolver::keyframesRulesForElement(Elem ent* element)
885 {
886 ASSERT(element);
887 RefPtrWillBeRawPtr<StaticCSSRuleList> ruleList = StaticCSSRuleList::create() ;
888
889 // TODO(samli): Repeat for all pseudo elements.
890 RefPtr<ComputedStyle> style = styleForElement(element);
891 if (!style)
892 return ruleList;
893 const CSSAnimationData* animationData = style->animations();
894 for (size_t i = 0; animationData && i < animationData->nameList().size(); ++ i) {
895 AtomicString animationName(animationData->nameList()[i]);
896 if (animationName == CSSAnimationData::initialName())
897 continue;
898 RefPtrWillBeRawPtr<CSSKeyframesRule> keyframesRule = findCSSKeyframesRul e(element, animationName);
alancutter (OOO until 2018) 2015/10/15 00:11:53 It seems like a lot of added complexity to find th
samli 2015/10/15 00:16:07 Yes but with one caveat. I think when we later hav
899 if (!keyframesRule)
900 continue;
901 ruleList->rules().append(keyframesRule);
902 }
903 return ruleList;
904 }
905
883 void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo llector& collector, PseudoId pseudoId, unsigned rulesToInclude) 906 void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo llector& collector, PseudoId pseudoId, unsigned rulesToInclude)
884 { 907 {
885 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); 908 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
886 909
887 if (rulesToInclude & UAAndUserCSSRules) 910 if (rulesToInclude & UAAndUserCSSRules)
888 matchUARules(collector); 911 matchUARules(collector);
889 912
890 if (rulesToInclude & AuthorCSSRules) { 913 if (rulesToInclude & AuthorCSSRules) {
891 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); 914 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
892 matchAuthorRules(element, collector, rulesToInclude & EmptyCSSRules); 915 matchAuthorRules(element, collector, rulesToInclude & EmptyCSSRules);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe solver()) 969 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe solver())
947 resolvers.append(scopedResolver); 970 resolvers.append(scopedResolver);
948 971
949 for (size_t i = 0; i < resolvers.size(); ++i) { 972 for (size_t i = 0; i < resolvers.size(); ++i) {
950 if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForA nimation(animationName.impl())) 973 if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForA nimation(animationName.impl()))
951 return keyframesRule; 974 return keyframesRule;
952 } 975 }
953 return nullptr; 976 return nullptr;
954 } 977 }
955 978
979 CSSKeyframesRule* StyleResolver::findCSSKeyframesRule(const Element* element, co nst AtomicString& animationName)
980 {
981 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers;
982 collectScopedResolversForHostedShadowTrees(element, resolvers);
983 if (ScopedStyleResolver* scopedResolver = element->treeScope().scopedStyleRe solver())
984 resolvers.append(scopedResolver);
985
986 for (size_t i = 0; i < resolvers.size(); ++i) {
987 if (StyleRuleKeyframes* keyframesRule = resolvers[i]->keyframeStylesForA nimation(animationName.impl())) {
988 CSSStyleSheet* styleSheet = resolvers[i]->styleSheetForAnimation(ani mationName.impl());
989 if (!styleSheet)
990 continue;
991 return findCSSKeyframesRule(styleSheet->cssRules(), keyframesRule);
992 }
993 }
994 return nullptr;
995 }
996
997 CSSKeyframesRule* StyleResolver::findCSSKeyframesRule(PassRefPtrWillBeRawPtr<CSS RuleList> cssRules, StyleRuleKeyframes* keyframesRule)
998 {
999 if (!cssRules)
1000 return nullptr;
1001 CSSKeyframesRule* result = 0;
1002 for (unsigned i = 0; i < cssRules->length() && !result; ++i) {
1003 CSSRule* cssRule = cssRules->item(i);
1004 CSSRule::Type cssRuleType = cssRule->type();
1005 if (cssRuleType == CSSRule::KEYFRAMES_RULE) {
1006 CSSKeyframesRule* cssKeyframesRule = toCSSKeyframesRule(cssRule);
1007 if (cssKeyframesRule->keyframesRule() == keyframesRule)
1008 return cssKeyframesRule;
1009 } else if (cssRuleType == CSSRule::IMPORT_RULE) {
1010 CSSImportRule* cssImportRule = toCSSImportRule(cssRule);
1011 result = findCSSKeyframesRule(cssImportRule->styleSheet()->cssRules( ), keyframesRule);
1012 } else if (cssRuleType != CSSRule::STYLE_RULE) {
1013 result = findCSSKeyframesRule(cssRule->cssRules(), keyframesRule);
1014 }
1015 }
1016 return result;
1017 }
1018
956 template <CSSPropertyPriority priority> 1019 template <CSSPropertyPriority priority>
957 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Act iveInterpolationsMap& activeInterpolationsMap) 1020 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Act iveInterpolationsMap& activeInterpolationsMap)
958 { 1021 {
959 for (const auto& interpolationsVectorEntry : activeInterpolationsMap) { 1022 for (const auto& interpolationsVectorEntry : activeInterpolationsMap) {
960 if (!interpolationsVectorEntry.key.isCSSProperty()) 1023 if (!interpolationsVectorEntry.key.isCSSProperty())
961 continue; 1024 continue;
962 CSSPropertyID property = interpolationsVectorEntry.key.cssProperty(); 1025 CSSPropertyID property = interpolationsVectorEntry.key.cssProperty();
963 if (!CSSPropertyPriorityData<priority>::propertyHasPriority(property)) 1026 if (!CSSPropertyPriorityData<priority>::propertyHasPriority(property))
964 continue; 1027 continue;
965 const Interpolation& interpolation = *interpolationsVectorEntry.value.fi rst(); 1028 const Interpolation& interpolation = *interpolationsVectorEntry.value.fi rst();
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 visitor->trace(m_watchedSelectorsRules); 1550 visitor->trace(m_watchedSelectorsRules);
1488 visitor->trace(m_treeBoundaryCrossingRules); 1551 visitor->trace(m_treeBoundaryCrossingRules);
1489 visitor->trace(m_styleResourceLoader); 1552 visitor->trace(m_styleResourceLoader);
1490 visitor->trace(m_styleSharingLists); 1553 visitor->trace(m_styleSharingLists);
1491 visitor->trace(m_pendingStyleSheets); 1554 visitor->trace(m_pendingStyleSheets);
1492 visitor->trace(m_document); 1555 visitor->trace(m_document);
1493 #endif 1556 #endif
1494 } 1557 }
1495 1558
1496 } // namespace blink 1559 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698