1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
|
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "AnimationController.h"
#include "CSSPropertyNames.h"
#include "Document.h"
#include "FloatConversion.h"
#include "Frame.h"
#include "RenderObject.h"
#include "RenderStyle.h"
#include "SystemTime.h"
#include "Timer.h"
#include "UnitBezier.h"
namespace WebCore {
static const double cAnimationTimerDelay = 0.025;
// The epsilon value we pass to UnitBezier::solve given that the animation is going to run over |dur| seconds. The longer the
// animation, the more precision we need in the timing function result to avoid ugly discontinuities.
static inline double solveEpsilon(double duration) { return 1. / (200. * duration); }
static inline double solveCubicBezierFunction(double p1x, double p1y, double p2x, double p2y, double t, double duration)
{
// Convert from input time to parametric value in curve, then from
// that to output time.
UnitBezier bezier(p1x, p1y, p2x, p2y);
return bezier.solve(t, solveEpsilon(duration));
}
class CompositeImplicitAnimation;
class ImplicitAnimation : public Noncopyable {
public:
ImplicitAnimation(const Transition*);
~ImplicitAnimation();
void animate(CompositeImplicitAnimation*, RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle, RenderStyle*& animatedStyle);
void reset(RenderObject*, RenderStyle* from, RenderStyle* to);
double progress() const;
int property() const { return m_property; }
bool finished() const { return m_finished; }
void setFinished(bool f) { m_finished = f; }
bool stale() const { return m_stale; }
void setStale() { m_stale = true; }
private:
// The two styles that we are blending.
RenderStyle* m_fromStyle;
RenderStyle* m_toStyle;
int m_property;
TimingFunction m_function;
double m_duration;
int m_repeatCount;
int m_iteration;
bool m_finished;
double m_startTime;
bool m_paused;
double m_pauseTime;
bool m_stale;
};
class CompositeImplicitAnimation : public Noncopyable {
public:
~CompositeImplicitAnimation() { deleteAllValues(m_animations); }
RenderStyle* animate(RenderObject*, RenderStyle* currentStyle, RenderStyle* targetStyle);
bool animating() const;
void reset(RenderObject*);
private:
HashMap<int, ImplicitAnimation*> m_animations;
};
ImplicitAnimation::ImplicitAnimation(const Transition* transition)
: m_fromStyle(0)
, m_toStyle(0)
, m_property(transition->property())
, m_function(transition->timingFunction())
, m_duration(transition->duration() / 1000.0)
, m_repeatCount(transition->repeatCount())
, m_iteration(0)
, m_finished(false)
, m_startTime(currentTime())
, m_paused(false)
, m_pauseTime(m_startTime)
, m_stale(false)
{
}
ImplicitAnimation::~ImplicitAnimation()
{
ASSERT(!m_fromStyle && !m_toStyle);
}
void ImplicitAnimation::reset(RenderObject* renderer, RenderStyle* from, RenderStyle* to)
{
setFinished(false);
if (m_fromStyle)
m_fromStyle->deref(renderer->renderArena());
if (m_toStyle)
m_toStyle->deref(renderer->renderArena());
m_fromStyle = from;
if (m_fromStyle)
m_fromStyle->ref();
m_toStyle = to;
if (m_toStyle)
m_toStyle->ref();
if (from || to)
m_startTime = currentTime();
// If we are stale, attempt to update to a new transition using the new |from| style. If we are able to find a new transition,
// then we will unmark ourselves for death.
if (stale() && from && to) {
for (const Transition* transition = from->transitions(); transition; transition = transition->next()) {
if (m_property != transition->property())
continue;
int duration = transition->duration();
int repeatCount = transition->repeatCount();
if (duration && repeatCount) {
m_duration = duration / 1000.0;
m_repeatCount = repeatCount;
m_stale = false;
break;
}
}
}
// If we did not find a new transition, then mark ourselves as being finished so that we can be removed.
if (stale())
setFinished(true);
}
double ImplicitAnimation::progress() const
{
double elapsedTime = currentTime() - m_startTime;
if (m_finished || !m_duration || elapsedTime >= m_duration)
return 1.0;
if (m_function.type() == LinearTimingFunction)
return elapsedTime / m_duration;
// Cubic bezier.
return solveCubicBezierFunction(m_function.x1(), m_function.y1(),
m_function.x2(), m_function.y2(),
elapsedTime / m_duration, m_duration);
}
static inline int blendFunc(int from, int to, double progress)
{
return int(from + (to - from) * progress);
}
static inline double blendFunc(double from, double to, double progress)
{
return from + (to - from) * progress;
}
static inline float blendFunc(float from, float to, double progress)
{
return narrowPrecisionToFloat(from + (to - from) * progress);
}
static inline Color blendFunc(const Color& from, const Color& to, double progress)
{
return Color(blendFunc(from.red(), to.red(), progress),
blendFunc(from.green(), to.green(), progress),
blendFunc(from.blue(), to.blue(), progress),
blendFunc(from.alpha(), to.alpha(), progress));
}
static inline Length blendFunc(const Length& from, const Length& to, double progress)
{
return to.blend(from, progress);
}
static inline IntSize blendFunc(const IntSize& from, const IntSize& to, double progress)
{
return IntSize(blendFunc(from.width(), to.width(), progress),
blendFunc(from.height(), to.height(), progress));
}
static inline ShadowData* blendFunc(const ShadowData* from, const ShadowData* to, double progress)
{
ASSERT(from && to);
return new ShadowData(blendFunc(from->x, to->x, progress), blendFunc(from->y, to->y, progress), blendFunc(from->blur, to->blur, progress), blendFunc(from->color, to->color, progress));
}
static inline TransformOperations blendFunc(const TransformOperations& from, const TransformOperations& to, double progress)
{
// Blend any operations whose types actually match up. Otherwise don't bother.
unsigned fromSize = from.size();
unsigned toSize = to.size();
unsigned size = max(fromSize, toSize);
TransformOperations result;
for (unsigned i = 0; i < size; i++) {
TransformOperation* fromOp = i < fromSize ? from[i].get() : 0;
TransformOperation* toOp = i < toSize ? to[i].get() : 0;
TransformOperation* blendedOp = toOp ? toOp->blend(fromOp, progress) : fromOp->blend(0, progress, true);
result.append(blendedOp);
}
return result;
}
static inline EVisibility blendFunc(EVisibility from, EVisibility to, double progress)
{
// Any non-zero result means we consider the object to be visible. Only at 0 do we consider the object to be
// invisible. The invisible value we use (HIDDEN vs. COLLAPSE) depends on the specified from/to values.
double fromVal = from == VISIBLE ? 1. : 0.;
double toVal = to == VISIBLE ? 1. : 0.;
if (fromVal == toVal)
return to;
double result = blendFunc(fromVal, toVal, progress);
return result > 0. ? VISIBLE : (to != VISIBLE ? to : from);
}
#define BLEND(prop, getter, setter) \
if (m_property == prop && m_toStyle->getter() != targetStyle->getter()) {\
reset(renderer, currentStyle, targetStyle); \
if (stale()) \
return; \
} \
if (m_property == cAnimateAll || m_property == prop) { \
if (m_fromStyle->getter() != m_toStyle->getter()) {\
setFinished(false); \
if (!animatedStyle) \
animatedStyle = new (renderer->renderArena()) RenderStyle(*targetStyle); \
animatedStyle->setter(blendFunc(m_fromStyle->getter(), m_toStyle->getter(), progress()));\
if (m_property == prop) \
return; \
}\
}\
#define BLEND_MAYBE_INVALID_COLOR(prop, getter, setter) \
if (m_property == prop && m_toStyle->getter() != targetStyle->getter()) { \
reset(renderer, currentStyle, targetStyle); \
if (stale()) \
return; \
} \
if (m_property == cAnimateAll || m_property == prop) { \
Color fromColor = m_fromStyle->getter(); \
Color toColor = m_toStyle->getter(); \
if (fromColor.isValid() || toColor.isValid()) { \
if (!fromColor.isValid()) \
fromColor = m_fromStyle->color(); \
if (!toColor.isValid()) \
toColor = m_toStyle->color(); \
if (fromColor != toColor) {\
setFinished(false); \
if (!animatedStyle) \
animatedStyle = new (renderer->renderArena()) RenderStyle(*targetStyle); \
animatedStyle->setter(blendFunc(fromColor, toColor, progress()));\
if (m_property == prop) \
return; \
}\
}\
}\
#define BLEND_SHADOW(prop, getter, setter) \
if (m_property == prop && (!m_toStyle->getter() || !targetStyle->getter() || *m_toStyle->getter() != *targetStyle->getter())) { \
reset(renderer, currentStyle, targetStyle); \
if (stale()) \
return; \
} \
if (m_property == cAnimateAll || m_property == prop) { \
if (m_fromStyle->getter() && m_toStyle->getter() && *m_fromStyle->getter() != *m_toStyle->getter()) {\
setFinished(false); \
if (!animatedStyle) \
animatedStyle = new (renderer->renderArena()) RenderStyle(*targetStyle); \
animatedStyle->setter(blendFunc(m_fromStyle->getter(), m_toStyle->getter(), progress()));\
if (m_property == prop) \
return; \
}\
}
void ImplicitAnimation::animate(CompositeImplicitAnimation* animation, RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle, RenderStyle*& animatedStyle)
{
// FIXME: If we have no transition-property, then the only way to tell if our goal state changed is to check
// every single animatable property. For now we'll just diff the styles to ask that question,
// but we should really exclude non-animatable properties.
if (!m_toStyle || (m_property == cAnimateAll && targetStyle->diff(m_toStyle))) {
reset(renderer, currentStyle, targetStyle);
if (stale())
return;
}
// FIXME: Blow up shorthands so that they can be honored.
setFinished(true);
BLEND(CSSPropertyLeft, left, setLeft);
BLEND(CSSPropertyRight, right, setRight);
BLEND(CSSPropertyTop, top, setTop);
BLEND(CSSPropertyBottom, bottom, setBottom);
BLEND(CSSPropertyWidth, width, setWidth);
BLEND(CSSPropertyHeight, height, setHeight);
BLEND(CSSPropertyBorderLeftWidth, borderLeftWidth, setBorderLeftWidth);
BLEND(CSSPropertyBorderRightWidth, borderRightWidth, setBorderRightWidth);
BLEND(CSSPropertyBorderTopWidth, borderTopWidth, setBorderTopWidth);
BLEND(CSSPropertyBorderBottomWidth, borderBottomWidth, setBorderBottomWidth);
BLEND(CSSPropertyMarginLeft, marginLeft, setMarginLeft);
BLEND(CSSPropertyMarginRight, marginRight, setMarginRight);
BLEND(CSSPropertyMarginTop, marginTop, setMarginTop);
BLEND(CSSPropertyMarginBottom, marginBottom, setMarginBottom);
BLEND(CSSPropertyPaddingLeft, paddingLeft, setPaddingLeft);
BLEND(CSSPropertyPaddingRight, paddingRight, setPaddingRight);
BLEND(CSSPropertyPaddingTop, paddingTop, setPaddingTop);
BLEND(CSSPropertyPaddingBottom, paddingBottom, setPaddingBottom);
BLEND(CSSPropertyOpacity, opacity, setOpacity);
BLEND(CSSPropertyColor, color, setColor);
BLEND(CSSPropertyBackgroundColor, backgroundColor, setBackgroundColor);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyWebkitColumnRuleColor, columnRuleColor, setColumnRuleColor);
BLEND(CSSPropertyWebkitColumnRuleWidth, columnRuleWidth, setColumnRuleWidth);
BLEND(CSSPropertyWebkitColumnGap, columnGap, setColumnGap);
BLEND(CSSPropertyWebkitColumnCount, columnCount, setColumnCount);
BLEND(CSSPropertyWebkitColumnWidth, columnWidth, setColumnWidth);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyWebkitTextStrokeColor, textStrokeColor, setTextStrokeColor);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyWebkitTextFillColor, textFillColor, setTextFillColor);
BLEND(CSSPropertyWebkitBorderHorizontalSpacing, horizontalBorderSpacing, setHorizontalBorderSpacing);
BLEND(CSSPropertyWebkitBorderVerticalSpacing, verticalBorderSpacing, setVerticalBorderSpacing);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyBorderLeftColor, borderLeftColor, setBorderLeftColor);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyBorderRightColor, borderRightColor, setBorderRightColor);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyBorderTopColor, borderTopColor, setBorderTopColor);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyBorderBottomColor, borderBottomColor, setBorderBottomColor);
BLEND(CSSPropertyZIndex, zIndex, setZIndex);
BLEND(CSSPropertyLineHeight, lineHeight, setLineHeight);
BLEND_MAYBE_INVALID_COLOR(CSSPropertyOutlineColor, outlineColor, setOutlineColor);
BLEND(CSSPropertyOutlineOffset, outlineOffset, setOutlineOffset);
BLEND(CSSPropertyOutlineWidth, outlineWidth, setOutlineWidth);
BLEND(CSSPropertyLetterSpacing, letterSpacing, setLetterSpacing);
BLEND(CSSPropertyWordSpacing, wordSpacing, setWordSpacing);
BLEND_SHADOW(CSSPropertyWebkitBoxShadow, boxShadow, setBoxShadow);
BLEND_SHADOW(CSSPropertyTextShadow, textShadow, setTextShadow);
BLEND(CSSPropertyWebkitTransform, transform, setTransform);
BLEND(CSSPropertyWebkitTransformOriginX, transformOriginX, setTransformOriginX);
BLEND(CSSPropertyWebkitTransformOriginY, transformOriginY, setTransformOriginY);
BLEND(CSSPropertyWebkitBorderTopLeftRadius, borderTopLeftRadius, setBorderTopLeftRadius);
BLEND(CSSPropertyWebkitBorderTopRightRadius, borderTopRightRadius, setBorderTopRightRadius);
BLEND(CSSPropertyWebkitBorderBottomLeftRadius, borderBottomLeftRadius, setBorderBottomLeftRadius);
BLEND(CSSPropertyWebkitBorderBottomRightRadius, borderBottomRightRadius, setBorderBottomRightRadius);
BLEND(CSSPropertyVisibility, visibility, setVisibility);
BLEND(CSSPropertyZoom, zoom, setZoom);
}
RenderStyle* CompositeImplicitAnimation::animate(RenderObject* renderer, RenderStyle* currentStyle, RenderStyle* targetStyle)
{
const Transition* currentTransitions = currentStyle->transitions();
const Transition* targetTransitions = targetStyle->transitions();
bool transitionsChanged = currentTransitions != targetTransitions && !(currentTransitions && targetTransitions && *currentTransitions == *targetTransitions);
if (m_animations.isEmpty()) {
// For each transition, we create a new animation unless one exists already (later occurrences of duplicate
// triggers in the layer list get ignored).
for (const Transition* transition = currentTransitions; transition; transition = transition->next()) {
int property = transition->property();
int duration = transition->duration();
int repeatCount = transition->repeatCount();
if (property && duration && repeatCount && !m_animations.contains(property)) {
ImplicitAnimation* animation = new ImplicitAnimation(transition);
m_animations.set(property, animation);
}
}
}
// Now that we have animation objects ready, let them know about the new goal state. We want them
// to fill in a RenderStyle*& only if needed.
RenderStyle* result = 0;
HashMap<int, ImplicitAnimation*>::iterator end = m_animations.end();
Vector<int> obsoleteTransitions;
// Look at the "all" animation first.
ImplicitAnimation* allAnimation = m_animations.get(cAnimateAll);
if (allAnimation) {
allAnimation->animate(this, renderer, currentStyle, targetStyle, result);
if (transitionsChanged)
// Mark the "all" animation as stale if the set of transitions changed. Stale animations continue
// to blend on a timer, and then remove themselves when finished.
allAnimation->setStale();
// If the animation is done and we are marked as stale, then we can be removed after the
// iteration of the hashmap is finished.
if (allAnimation->finished() && allAnimation->stale())
obsoleteTransitions.append(cAnimateAll);
}
// Now look at the specialized animations.
for (HashMap<int, ImplicitAnimation*>::iterator it = m_animations.begin(); it != end; ++it) {
// Skip over the "all" animation, since we animated it already.
if (it->second->property() == cAnimateAll)
continue;
it->second->animate(this, renderer, currentStyle, targetStyle, result);
if (transitionsChanged)
// Mark any running animations as stale if the set of transitions changed. Stale animations continue
// to blend on a timer, and then remove themselves when finished.
it->second->setStale();
// If the animation is done and we are marked as stale, then we can be removed after the
// iteration of the hashmap is finished.
if (it->second->finished() && it->second->stale())
obsoleteTransitions.append(it->second->property());
}
// Now cull out any stale animations that are finished.
for (unsigned i = 0; i < obsoleteTransitions.size(); ++i) {
ImplicitAnimation* animation = m_animations.take(obsoleteTransitions[i]);
animation->reset(renderer, 0, 0);
delete animation;
}
if (transitionsChanged) {
// If our transitions changed we need to add new animations for any transitions that
// don't exist yet. If a new transition conflicts with a currently running stale transition, then we will not add it.
// The stale transition is responsible for updating itself to the new transition if it ever gets reset or finishes.
for (const Transition* transition = targetTransitions; transition; transition = transition->next()) {
int property = transition->property();
int duration = transition->duration();
int repeatCount = transition->repeatCount();
if (property && duration && repeatCount && !m_animations.contains(property)) {
ImplicitAnimation* animation = new ImplicitAnimation(transition);
m_animations.set(property, animation);
}
}
}
if (result)
return result;
return targetStyle;
}
bool CompositeImplicitAnimation::animating() const
{
HashMap<int, ImplicitAnimation*>::const_iterator end = m_animations.end();
for (HashMap<int, ImplicitAnimation*>::const_iterator it = m_animations.begin(); it != end; ++it)
if (!it->second->finished())
return true;
return false;
}
void CompositeImplicitAnimation::reset(RenderObject* renderer)
{
HashMap<int, ImplicitAnimation*>::const_iterator end = m_animations.end();
for (HashMap<int, ImplicitAnimation*>::const_iterator it = m_animations.begin(); it != end; ++it)
it->second->reset(renderer, 0, 0);
}
class AnimationControllerPrivate {
public:
AnimationControllerPrivate(Frame*);
~AnimationControllerPrivate();
CompositeImplicitAnimation* get(RenderObject*);
bool clear(RenderObject*);
void timerFired(Timer<AnimationControllerPrivate>*);
void updateTimer();
bool hasImplicitAnimations() const { return !m_animations.isEmpty(); }
private:
HashMap<RenderObject*, CompositeImplicitAnimation*> m_animations;
Timer<AnimationControllerPrivate> m_timer;
Frame* m_frame;
};
AnimationControllerPrivate::AnimationControllerPrivate(Frame* frame)
: m_timer(this, &AnimationControllerPrivate::timerFired)
, m_frame(frame)
{
}
AnimationControllerPrivate::~AnimationControllerPrivate()
{
deleteAllValues(m_animations);
}
CompositeImplicitAnimation* AnimationControllerPrivate::get(RenderObject* renderer)
{
CompositeImplicitAnimation* animation = m_animations.get(renderer);
if (!animation && renderer->style()->transitions()) {
animation = new CompositeImplicitAnimation();
m_animations.set(renderer, animation);
}
return animation;
}
bool AnimationControllerPrivate::clear(RenderObject* renderer)
{
CompositeImplicitAnimation* animation = m_animations.take(renderer);
if (!animation)
return false;
animation->reset(renderer);
delete animation;
return true;
}
void AnimationControllerPrivate::updateTimer()
{
bool animating = false;
HashMap<RenderObject*, CompositeImplicitAnimation*>::iterator end = m_animations.end();
for (HashMap<RenderObject*, CompositeImplicitAnimation*>::iterator it = m_animations.begin(); it != end; ++it) {
if (it->second->animating()) {
animating = true;
break;
}
}
if (animating) {
if (!m_timer.isActive())
m_timer.startRepeating(cAnimationTimerDelay);
} else if (m_timer.isActive())
m_timer.stop();
}
void AnimationControllerPrivate::timerFired(Timer<AnimationControllerPrivate>* timer)
{
// When the timer fires, all we do is call setChanged on all DOM nodes with running animations and then do an immediate
// updateRendering. It will then call back to us with new information.
bool animating = false;
HashMap<RenderObject*, CompositeImplicitAnimation*>::iterator end = m_animations.end();
for (HashMap<RenderObject*, CompositeImplicitAnimation*>::iterator it = m_animations.begin(); it != end; ++it) {
if (it->second->animating()) {
animating = true;
it->first->element()->setChanged();
}
}
m_frame->document()->updateRendering();
updateTimer();
}
AnimationController::AnimationController(Frame* frame)
:m_data(new AnimationControllerPrivate(frame))
{
}
AnimationController::~AnimationController()
{
delete m_data;
}
void AnimationController::cancelImplicitAnimations(RenderObject* renderer)
{
if (!m_data->hasImplicitAnimations())
return;
if (m_data->clear(renderer))
renderer->element()->setChanged();
}
RenderStyle* AnimationController::updateImplicitAnimations(RenderObject* renderer, RenderStyle* newStyle)
{
// Fetch our current set of implicit animations from a hashtable. We then compare them
// against the animations in the style and make sure we're in sync. If destination values
// have changed, we reset the animation. We then do a blend to get new values and we return
// a new style.
ASSERT(renderer->element()); // FIXME: We do not animate generated content yet.
CompositeImplicitAnimation* animation = m_data->get(renderer);
if (!animation)
return newStyle;
RenderStyle* result = animation->animate(renderer, renderer->style(), newStyle);
m_data->updateTimer();
return result;
}
void AnimationController::suspendAnimations()
{
// FIXME: Walk the whole hashtable and call pause on each animation.
// Kill our timer.
}
void AnimationController::resumeAnimations()
{
// FIXME: Walk the whole hashtable and call resume on each animation.
// Start our timer.
}
}
|