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

Side by Side Diff: Source/core/frame/animation/CompositeAnimation.cpp

Issue 57643004: Pass RenderStyle / RenderObject by reference in more places (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase on master Created 7 years, 1 month 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) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (!m_keyframeAnimations.isEmpty()) { 63 if (!m_keyframeAnimations.isEmpty()) {
64 AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.en d(); 64 AnimationNameMap::const_iterator animationsEnd = m_keyframeAnimations.en d();
65 for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) { 65 for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != animationsEnd; ++it) {
66 KeyframeAnimation* anim = it->value.get(); 66 KeyframeAnimation* anim = it->value.get();
67 animationController()->animationWillBeRemoved(anim); 67 animationController()->animationWillBeRemoved(anim);
68 anim->clear(); 68 anim->clear();
69 } 69 }
70 } 70 }
71 } 71 }
72 72
73 void CompositeAnimation::updateTransitions(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle) 73 void CompositeAnimation::updateTransitions(RenderObject& renderer, RenderStyle* currentStyle, RenderStyle& targetStyle)
74 { 74 {
75 // If currentStyle is null or there are no old or new transitions, just skip it 75 // If currentStyle is null or there are no old or new transitions, just skip it
76 if (!currentStyle || (!targetStyle->transitions() && m_transitions.isEmpty() )) 76 if (!currentStyle || (!targetStyle.transitions() && m_transitions.isEmpty()) )
77 return; 77 return;
78 78
79 // Mark all existing transitions as no longer active. We will mark the still active ones 79 // Mark all existing transitions as no longer active. We will mark the still active ones
80 // in the next loop and then toss the ones that didn't get marked. 80 // in the next loop and then toss the ones that didn't get marked.
81 CSSPropertyTransitionsMap::const_iterator end = m_transitions.end(); 81 CSSPropertyTransitionsMap::const_iterator end = m_transitions.end();
82 for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); i t != end; ++it) 82 for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); i t != end; ++it)
83 it->value->setActive(false); 83 it->value->setActive(false);
84 84
85 RefPtr<RenderStyle> modifiedCurrentStyle; 85 RefPtr<RenderStyle> modifiedCurrentStyle;
86 86
87 // Check to see if we need to update the active transitions 87 // Check to see if we need to update the active transitions
88 if (targetStyle->transitions()) { 88 if (targetStyle.transitions()) {
89 for (size_t i = 0; i < targetStyle->transitions()->size(); ++i) { 89 for (size_t i = 0; i < targetStyle.transitions()->size(); ++i) {
90 const CSSAnimationData* anim = targetStyle->transitions()->animation (i); 90 const CSSAnimationData* anim = targetStyle.transitions()->animation( i);
91 bool isActiveTransition = anim->duration() || anim->delay() > 0; 91 bool isActiveTransition = anim->duration() || anim->delay() > 0;
92 92
93 CSSAnimationData::AnimationMode mode = anim->animationMode(); 93 CSSAnimationData::AnimationMode mode = anim->animationMode();
94 if (mode == CSSAnimationData::AnimateNone) 94 if (mode == CSSAnimationData::AnimateNone)
95 continue; 95 continue;
96 96
97 CSSPropertyID prop = anim->property(); 97 CSSPropertyID prop = anim->property();
98 98
99 bool all = mode == CSSAnimationData::AnimateAll; 99 bool all = mode == CSSAnimationData::AnimateAll;
100 100
(...skipping 29 matching lines...) Expand all
130 130
131 // This might be a transition that is just finishing. That w ould be the case 131 // This might be a transition that is just finishing. That w ould be the case
132 // if it were postActive. But we still need to check for equ ality because 132 // if it were postActive. But we still need to check for equ ality because
133 // it could be just finishing AND changing to a new goal sta te. 133 // it could be just finishing AND changing to a new goal sta te.
134 // 134 //
135 // This implAnim might also not be an already running transi tion. It might be 135 // This implAnim might also not be an already running transi tion. It might be
136 // newly added to the list in a previous iteration. This wou ld happen if 136 // newly added to the list in a previous iteration. This wou ld happen if
137 // you have both an explicit transition-property and 'all' i n the same 137 // you have both an explicit transition-property and 'all' i n the same
138 // list. In this case, the latter one overrides the earlier one, so we 138 // list. In this case, the latter one overrides the earlier one, so we
139 // behave as though this is a running animation being replac ed. 139 // behave as though this is a running animation being replac ed.
140 if (!implAnim->isTargetPropertyEqual(prop, targetStyle)) { 140 if (!implAnim->isTargetPropertyEqual(prop, &targetStyle)) {
141 // For accelerated animations we need to return a new Re nderStyle with the _current_ value 141 // For accelerated animations we need to return a new Re nderStyle with the _current_ value
142 // of the property, so that restarted transitions use th e correct starting point. 142 // of the property, so that restarted transitions use th e correct starting point.
143 if (CSSPropertyAnimation::animationOfPropertyIsAccelerat ed(prop) && implAnim->isAccelerated()) { 143 if (CSSPropertyAnimation::animationOfPropertyIsAccelerat ed(prop) && implAnim->isAccelerated()) {
144 if (!modifiedCurrentStyle) 144 if (!modifiedCurrentStyle)
145 modifiedCurrentStyle = RenderStyle::clone(curren tStyle); 145 modifiedCurrentStyle = RenderStyle::clone(curren tStyle);
146 146
147 implAnim->blendPropertyValueInStyle(prop, modifiedCu rrentStyle.get()); 147 implAnim->blendPropertyValueInStyle(prop, modifiedCu rrentStyle.get());
148 } 148 }
149 animationController()->animationWillBeRemoved(implAnim); 149 animationController()->animationWillBeRemoved(implAnim);
150 m_transitions.remove(prop); 150 m_transitions.remove(prop);
151 equal = false; 151 equal = false;
152 } 152 }
153 } else { 153 } else {
154 // We need to start a transition if it is active and the pro perties don't match 154 // We need to start a transition if it is active and the pro perties don't match
155 equal = !isActiveTransition || CSSPropertyAnimation::propert iesEqual(prop, fromStyle, targetStyle); 155 equal = !isActiveTransition || CSSPropertyAnimation::propert iesEqual(prop, fromStyle, &targetStyle);
156 } 156 }
157 157
158 // We can be in this loop with an inactive transition (!isActive Transition). We need 158 // We can be in this loop with an inactive transition (!isActive Transition). We need
159 // to do that to check to see if we are canceling a transition. But we don't want to 159 // to do that to check to see if we are canceling a transition. But we don't want to
160 // start one of the inactive transitions. So short circuit that here. (See 160 // start one of the inactive transitions. So short circuit that here. (See
161 // <https://bugs.webkit.org/show_bug.cgi?id=24787> 161 // <https://bugs.webkit.org/show_bug.cgi?id=24787>
162 if (!equal && isActiveTransition) { 162 if (!equal && isActiveTransition) {
163 // Add the new transition 163 // Add the new transition
164 m_transitions.set(prop, ImplicitAnimation::create(const_cast <CSSAnimationData*>(anim), prop, renderer, this, modifiedCurrentStyle ? modified CurrentStyle.get() : fromStyle)); 164 m_transitions.set(prop, ImplicitAnimation::create(const_cast <CSSAnimationData*>(anim), prop, renderer, this, modifiedCurrentStyle ? modified CurrentStyle.get() : fromStyle));
165 } 165 }
(...skipping 14 matching lines...) Expand all
180 animationController()->animationWillBeRemoved(anim); 180 animationController()->animationWillBeRemoved(anim);
181 toBeRemoved.append(anim->animatingProperty()); 181 toBeRemoved.append(anim->animatingProperty());
182 } 182 }
183 } 183 }
184 184
185 // Now remove the transitions from the list 185 // Now remove the transitions from the list
186 for (size_t j = 0; j < toBeRemoved.size(); ++j) 186 for (size_t j = 0; j < toBeRemoved.size(); ++j)
187 m_transitions.remove(toBeRemoved[j]); 187 m_transitions.remove(toBeRemoved[j]);
188 } 188 }
189 189
190 void CompositeAnimation::updateKeyframeAnimations(RenderObject* renderer, Render Style* currentStyle, RenderStyle* targetStyle) 190 void CompositeAnimation::updateKeyframeAnimations(RenderObject& renderer, Render Style* currentStyle, RenderStyle& targetStyle)
191 { 191 {
192 // Nothing to do if we don't have any animations, and didn't have any before 192 // Nothing to do if we don't have any animations, and didn't have any before
193 if (m_keyframeAnimations.isEmpty() && !targetStyle->hasAnimations()) 193 if (m_keyframeAnimations.isEmpty() && !targetStyle.hasAnimations())
194 return; 194 return;
195 195
196 AnimationNameMap::const_iterator kfend = m_keyframeAnimations.end(); 196 AnimationNameMap::const_iterator kfend = m_keyframeAnimations.end();
197 197
198 if (currentStyle && currentStyle->hasAnimations() && targetStyle->hasAnimati ons() && *(currentStyle->animations()) == *(targetStyle->animations())) { 198 if (currentStyle && currentStyle->hasAnimations() && targetStyle.hasAnimatio ns() && *(currentStyle->animations()) == *(targetStyle.animations())) {
199 // The current and target animations are the same so we just need to tos s any 199 // The current and target animations are the same so we just need to tos s any
200 // animation which is finished (postActive). 200 // animation which is finished (postActive).
201 for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) { 201 for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) {
202 if (it->value->postActive()) 202 if (it->value->postActive())
203 it->value->setIndex(-1); 203 it->value->setIndex(-1);
204 } 204 }
205 } else { 205 } else {
206 // Mark all existing animations as no longer active. 206 // Mark all existing animations as no longer active.
207 for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it) 207 for (AnimationNameMap::const_iterator it = m_keyframeAnimations.begin(); it != kfend; ++it)
208 it->value->setIndex(-1); 208 it->value->setIndex(-1);
209 209
210 // Toss the animation order map. 210 // Toss the animation order map.
211 m_keyframeAnimationOrderList.clear(); 211 m_keyframeAnimationOrderList.clear();
212 212
213 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none", AtomicString::Con structFromLiteral)); 213 DEFINE_STATIC_LOCAL(const AtomicString, none, ("none", AtomicString::Con structFromLiteral));
214 214
215 // Now mark any still active animations as active and add any new animat ions. 215 // Now mark any still active animations as active and add any new animat ions.
216 if (targetStyle->animations()) { 216 if (targetStyle.animations()) {
217 int numAnims = targetStyle->animations()->size(); 217 int numAnims = targetStyle.animations()->size();
218 for (int i = 0; i < numAnims; ++i) { 218 for (int i = 0; i < numAnims; ++i) {
219 const CSSAnimationData* anim = targetStyle->animations()->animat ion(i); 219 const CSSAnimationData* anim = targetStyle.animations()->animati on(i);
220 if (!anim->isValidAnimation()) 220 if (!anim->isValidAnimation())
221 continue; 221 continue;
222 222
223 // See if there is a current animation for this name. 223 // See if there is a current animation for this name.
224 AtomicString name(anim->name()); 224 AtomicString name(anim->name());
225 RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.ge t(name); 225 RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.ge t(name);
226 if (keyframeAnim) { 226 if (keyframeAnim) {
227 // If this animation is postActive, skip it so it gets remov ed at the end of this function. 227 // If this animation is postActive, skip it so it gets remov ed at the end of this function.
228 if (keyframeAnim->postActive()) 228 if (keyframeAnim->postActive())
229 continue; 229 continue;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 Vector<AtomicString> newOrderList; 269 Vector<AtomicString> newOrderList;
270 for (size_t j = 0; j < m_keyframeAnimationOrderList.size(); ++j) { 270 for (size_t j = 0; j < m_keyframeAnimationOrderList.size(); ++j) {
271 AtomicString key = m_keyframeAnimationOrderList[j]; 271 AtomicString key = m_keyframeAnimationOrderList[j];
272 if (m_keyframeAnimations.contains(key)) 272 if (m_keyframeAnimations.contains(key))
273 newOrderList.append(key); 273 newOrderList.append(key);
274 } 274 }
275 m_keyframeAnimationOrderList.swap(newOrderList); 275 m_keyframeAnimationOrderList.swap(newOrderList);
276 } 276 }
277 } 277 }
278 278
279 PassRefPtr<RenderStyle> CompositeAnimation::animate(RenderObject* renderer, Rend erStyle* currentStyle, RenderStyle* targetStyle) 279 PassRefPtr<RenderStyle> CompositeAnimation::animate(RenderObject& renderer, Rend erStyle* currentStyle, RenderStyle& targetStyle)
280 { 280 {
281 RefPtr<RenderStyle> resultStyle; 281 RefPtr<RenderStyle> resultStyle;
282 282
283 // We don't do any transitions if we don't have a currentStyle (on startup). 283 // We don't do any transitions if we don't have a currentStyle (on startup).
284 updateTransitions(renderer, currentStyle, targetStyle); 284 updateTransitions(renderer, currentStyle, targetStyle);
285 updateKeyframeAnimations(renderer, currentStyle, targetStyle); 285 updateKeyframeAnimations(renderer, currentStyle, targetStyle);
286 286
287 if (currentStyle) { 287 if (currentStyle) {
288 // Now that we have transition objects ready, let them know about the ne w goal state. We want them 288 // Now that we have transition objects ready, let them know about the ne w goal state. We want them
289 // to fill in a RenderStyle*& only if needed. 289 // to fill in a RenderStyle*& only if needed.
290 if (!m_transitions.isEmpty()) { 290 if (!m_transitions.isEmpty()) {
291 CSSPropertyTransitionsMap::const_iterator end = m_transitions.end(); 291 CSSPropertyTransitionsMap::const_iterator end = m_transitions.end();
292 for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.be gin(); it != end; ++it) { 292 for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.be gin(); it != end; ++it) {
293 if (ImplicitAnimation* anim = it->value.get()) 293 if (ImplicitAnimation* anim = it->value.get())
294 anim->animate(this, renderer, currentStyle, targetStyle, res ultStyle); 294 anim->animate(this, &renderer, currentStyle, &targetStyle, r esultStyle);
295 } 295 }
296 } 296 }
297 } 297 }
298 298
299 // Now that we have animation objects ready, let them know about the new goa l state. We want them 299 // Now that we have animation objects ready, let them know about the new goa l state. We want them
300 // to fill in a RenderStyle*& only if needed. 300 // to fill in a RenderStyle*& only if needed.
301 for (Vector<AtomicString>::const_iterator it = m_keyframeAnimationOrderList. begin(); it != m_keyframeAnimationOrderList.end(); ++it) { 301 for (Vector<AtomicString>::const_iterator it = m_keyframeAnimationOrderList. begin(); it != m_keyframeAnimationOrderList.end(); ++it) {
302 RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.get(*it); 302 RefPtr<KeyframeAnimation> keyframeAnim = m_keyframeAnimations.get(*it);
303 ASSERT(keyframeAnim); 303 ASSERT(keyframeAnim);
304 keyframeAnim->animate(this, renderer, currentStyle, targetStyle, resultS tyle); 304 keyframeAnim->animate(this, &renderer, currentStyle, &targetStyle, resul tStyle);
305 } 305 }
306 306
307 return resultStyle ? resultStyle.release() : targetStyle; 307 return resultStyle ? resultStyle.release() : PassRefPtr<RenderStyle>(targetS tyle);
308 } 308 }
309 309
310 PassRefPtr<RenderStyle> CompositeAnimation::getAnimatedStyle() const 310 PassRefPtr<RenderStyle> CompositeAnimation::getAnimatedStyle() const
311 { 311 {
312 RefPtr<RenderStyle> resultStyle; 312 RefPtr<RenderStyle> resultStyle;
313 CSSPropertyTransitionsMap::const_iterator end = m_transitions.end(); 313 CSSPropertyTransitionsMap::const_iterator end = m_transitions.end();
314 for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); i t != end; ++it) { 314 for (CSSPropertyTransitionsMap::const_iterator it = m_transitions.begin(); i t != end; ++it) {
315 if (ImplicitAnimation* implicitAnimation = it->value.get()) 315 if (ImplicitAnimation* implicitAnimation = it->value.get())
316 implicitAnimation->getAnimatedStyle(resultStyle); 316 implicitAnimation->getAnimatedStyle(resultStyle);
317 } 317 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 ImplicitAnimation* anim = it->value.get(); 503 ImplicitAnimation* anim = it->value.get();
504 if (anim->running()) 504 if (anim->running())
505 ++count; 505 ++count;
506 } 506 }
507 } 507 }
508 508
509 return count; 509 return count;
510 } 510 }
511 511
512 } // namespace WebCore 512 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/frame/animation/CompositeAnimation.h ('k') | Source/core/frame/animation/ImplicitAnimation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698