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

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

Issue 196943029: Web Animations API: Load resources referenced in element.animate() (reland) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
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 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 document.setDirectionSetOnDocumentElement(false); 622 document.setDirectionSetOnDocumentElement(false);
623 document.setWritingModeSetOnDocumentElement(false); 623 document.setWritingModeSetOnDocumentElement(false);
624 } 624 }
625 625
626 static void addContentAttrValuesToFeatures(const Vector<AtomicString>& contentAt trValues, RuleFeatureSet& features) 626 static void addContentAttrValuesToFeatures(const Vector<AtomicString>& contentAt trValues, RuleFeatureSet& features)
627 { 627 {
628 for (size_t i = 0; i < contentAttrValues.size(); ++i) 628 for (size_t i = 0; i < contentAttrValues.size(); ++i)
629 features.addAttributeInASelector(contentAttrValues[i]); 629 features.addAttributeInASelector(contentAttrValues[i]);
630 } 630 }
631 631
632 // Start loading resources referenced by this style.
633 void StyleResolver::loadPendingResources(StyleResolverState& state)
634 {
635 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
636 document().styleEngine()->fontSelector()->loadPendingFonts();
637 }
638
632 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior, 639 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior,
633 RuleMatchingBehavior matchingBehavior) 640 RuleMatchingBehavior matchingBehavior)
634 { 641 {
635 ASSERT(document().frame()); 642 ASSERT(document().frame());
636 ASSERT(documentSettings()); 643 ASSERT(documentSettings());
637 ASSERT(!hasPendingAuthorStyleSheets()); 644 ASSERT(!hasPendingAuthorStyleSheets());
638 ASSERT(!m_needCollectFeatures); 645 ASSERT(!m_needCollectFeatures);
639 646
640 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer 647 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer
641 // will vanish if a style recalc happens during loading. 648 // will vanish if a style recalc happens during loading.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 if (state.lineHeightValue()) 783 if (state.lineHeightValue())
777 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue()); 784 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
778 785
779 // Now do rest of the properties. 786 // Now do rest of the properties.
780 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly); 787 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly);
781 788
782 // If our font got dirtied by one of the non-essential font props, 789 // If our font got dirtied by one of the non-essential font props,
783 // go ahead and update it a second time. 790 // go ahead and update it a second time.
784 updateFont(state); 791 updateFont(state);
785 792
786 // Start loading resources referenced by this style. 793 loadPendingResources(state);
787 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
788 document().styleEngine()->fontSelector()->loadPendingFonts();
789 794
790 didAccess(); 795 didAccess();
791 796
792 return state.takeStyle(); 797 return state.takeStyle();
793 } 798 }
794 799
795 // This function is used by the WebAnimations JavaScript API method animate(). 800 // This function is used by the WebAnimations JavaScript API method animate().
796 // FIXME: Remove this when animate() switches away from resolution-dependent par sing. 801 // FIXME: Remove this when animate() switches away from resolution-dependent par sing.
797 PassRefPtrWillBeRawPtr<KeyframeEffectModel> StyleResolver::createKeyframeEffectM odel(Element& element, const WillBeHeapVector<RefPtrWillBeMember<MutableStylePro pertySet> >& propertySetVector, KeyframeEffectModel::KeyframeVector& keyframes) 802 PassRefPtrWillBeRawPtr<KeyframeEffectModel> StyleResolver::createKeyframeEffectM odel(Element& element, const WillBeHeapVector<RefPtrWillBeMember<MutableStylePro pertySet> >& propertySetVector, KeyframeEffectModel::KeyframeVector& keyframes)
798 { 803 {
799 ASSERT(propertySetVector.size() == keyframes.size()); 804 ASSERT(propertySetVector.size() == keyframes.size());
800 805
801 StyleResolverState state(element.document(), &element); 806 StyleResolverState state(element.document(), &element);
802 state.setStyle(RenderStyle::create()); 807 state.setStyle(RenderStyle::create());
803 state.fontBuilder().initForStyleResolve(state.document(), state.style(), sta te.useSVGZoomRules()); 808 state.fontBuilder().initForStyleResolve(state.document(), state.style(), sta te.useSVGZoomRules());
804 809
805 for (unsigned i = 0; i < propertySetVector.size(); ++i) { 810 for (unsigned i = 0; i < propertySetVector.size(); ++i) {
806 for (unsigned j = 0; j < propertySetVector[i]->propertyCount(); ++j) { 811 for (unsigned j = 0; j < propertySetVector[i]->propertyCount(); ++j) {
807 CSSPropertyID id = propertySetVector[i]->propertyAt(j).id(); 812 CSSPropertyID id = propertySetVector[i]->propertyAt(j).id();
808 StyleBuilder::applyProperty(id, state, propertySetVector[i]->getProp ertyCSSValue(id).get()); 813 StyleBuilder::applyProperty(id, state, propertySetVector[i]->getProp ertyCSSValue(id).get());
809 keyframes[i]->setPropertyValue(id, CSSAnimatableValueFactory::create (id, *state.style()).get()); 814 keyframes[i]->setPropertyValue(id, CSSAnimatableValueFactory::create (id, *state.style()).get());
810 } 815 }
811 } 816 }
817
812 return KeyframeEffectModel::create(keyframes); 818 return KeyframeEffectModel::create(keyframes);
813 } 819 }
814 820
815 PassRefPtr<PseudoElement> StyleResolver::createPseudoElementIfNeeded(Element& pa rent, PseudoId pseudoId) 821 PassRefPtr<PseudoElement> StyleResolver::createPseudoElementIfNeeded(Element& pa rent, PseudoId pseudoId)
816 { 822 {
817 RenderObject* parentRenderer = parent.renderer(); 823 RenderObject* parentRenderer = parent.renderer();
818 if (!parentRenderer) 824 if (!parentRenderer)
819 return nullptr; 825 return nullptr;
820 826
821 if (pseudoId < FIRST_INTERNAL_PSEUDOID && !parentRenderer->style()->hasPseud oStyle(pseudoId)) 827 if (pseudoId < FIRST_INTERNAL_PSEUDOID && !parentRenderer->style()->hasPseud oStyle(pseudoId))
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 updateFont(state); 955 updateFont(state);
950 956
951 // Line-height is set when we are sure we decided on the font-size. 957 // Line-height is set when we are sure we decided on the font-size.
952 if (state.lineHeightValue()) 958 if (state.lineHeightValue())
953 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue()); 959 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
954 960
955 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly); 961 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly);
956 962
957 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); 963 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features);
958 964
959 // Start loading resources referenced by this style. 965 loadPendingResources(state);
960 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
961 document().styleEngine()->fontSelector()->loadPendingFonts();
962 966
963 didAccess(); 967 didAccess();
964 968
965 // Now return the style. 969 // Now return the style.
966 return state.takeStyle(); 970 return state.takeStyle();
967 } 971 }
968 972
969 void StyleResolver::collectViewportRules() 973 void StyleResolver::collectViewportRules()
970 { 974 {
971 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( ); 975 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( );
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF orTransitions); 1083 applyAnimatedProperties<HighPriorityProperties>(state, activeInterpolationsF orTransitions);
1080 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rAnimations); 1084 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rAnimations);
1081 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions); 1085 applyAnimatedProperties<LowPriorityProperties>(state, activeInterpolationsFo rTransitions);
1082 1086
1083 // If the animations/transitions change opacity or transform, we need to upd ate 1087 // If the animations/transitions change opacity or transform, we need to upd ate
1084 // the style to impose the stacking rules. Note that this is also 1088 // the style to impose the stacking rules. Note that this is also
1085 // done in StyleResolver::adjustRenderStyle(). 1089 // done in StyleResolver::adjustRenderStyle().
1086 RenderStyle* style = state.style(); 1090 RenderStyle* style = state.style();
1087 if (style->hasAutoZIndex() && (style->opacity() < 1.0f || style->hasTransfor m())) 1091 if (style->hasAutoZIndex() && (style->opacity() < 1.0f || style->hasTransfor m()))
1088 style->setZIndex(0); 1092 style->setZIndex(0);
1093
1094 // Start loading resources used by animations.
1095 loadPendingResources(state);
1089 } 1096 }
1090 1097
1091 template <StyleResolver::StyleApplicationPass pass> 1098 template <StyleResolver::StyleApplicationPass pass>
1092 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Has hMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolations) 1099 void StyleResolver::applyAnimatedProperties(StyleResolverState& state, const Has hMap<CSSPropertyID, RefPtr<Interpolation> >& activeInterpolations)
1093 { 1100 {
1094 ASSERT(pass != AnimationProperties); 1101 ASSERT(pass != AnimationProperties);
1095 1102
1096 for (HashMap<CSSPropertyID, RefPtr<Interpolation> >::const_iterator iter = a ctiveInterpolations.begin(); iter != activeInterpolations.end(); ++iter) { 1103 for (HashMap<CSSPropertyID, RefPtr<Interpolation> >::const_iterator iter = a ctiveInterpolations.begin(); iter != activeInterpolations.end(); ++iter) {
1097 CSSPropertyID property = iter->key; 1104 CSSPropertyID property = iter->key;
1098 if (!isPropertyForPass<pass>(property)) 1105 if (!isPropertyForPass<pass>(property))
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 1329
1323 // Cache the UA properties to pass them to RenderTheme in adjustRenderStyle. 1330 // Cache the UA properties to pass them to RenderTheme in adjustRenderStyle.
1324 state.cacheUserAgentBorderAndBackground(); 1331 state.cacheUserAgentBorderAndBackground();
1325 1332
1326 // Now do the author and user normal priority properties and all the !import ant properties. 1333 // Now do the author and user normal priority properties and all the !import ant properties.
1327 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyI nheritedOnly); 1334 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyI nheritedOnly);
1328 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInherite dOnly); 1335 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInherite dOnly);
1329 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnl y); 1336 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnl y);
1330 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); 1337 applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matc hResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1331 1338
1332 // Start loading resources referenced by this style. 1339 loadPendingResources(state);
1333 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
1334 document().styleEngine()->fontSelector()->loadPendingFonts();
1335 1340
1336 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, state.style(), state.parentStyle())) { 1341 if (!cachedMatchedProperties && cacheHash && MatchedPropertiesCache::isCache able(element, state.style(), state.parentStyle())) {
1337 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded); 1342 INCREMENT_STYLE_STATS_COUNTER(*this, matchedPropertyCacheAdded);
1338 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa sh, matchResult); 1343 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHa sh, matchResult);
1339 } 1344 }
1340 1345
1341 ASSERT(!state.fontBuilder().fontDirty()); 1346 ASSERT(!state.fontBuilder().fontDirty());
1342 } 1347 }
1343 1348
1344 CSSPropertyValue::CSSPropertyValue(CSSPropertyID id, const StylePropertySet& pro pertySet) 1349 CSSPropertyValue::CSSPropertyValue(CSSPropertyID id, const StylePropertySet& pro pertySet)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 bool StyleResolver::mediaQueryAffectedByViewportChange() const 1413 bool StyleResolver::mediaQueryAffectedByViewportChange() const
1409 { 1414 {
1410 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) { 1415 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) {
1411 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result) 1416 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result)
1412 return true; 1417 return true;
1413 } 1418 }
1414 return false; 1419 return false;
1415 } 1420 }
1416 1421
1417 } // namespace WebCore 1422 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/css/resolver/StyleResourceLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698