Changeset 155119 in webkit


Ignore:
Timestamp:
Sep 5, 2013 8:15:59 AM (11 years ago)
Author:
andersca@apple.com
Message:

Animations in an AnimationList are never null
https://bugs.webkit.org/show_bug.cgi?id=120720

Reviewed by Andreas Kling.

Change AnimationList::operator[] to return an Animation& and fix up related code to also take references.

  • css/CSSComputedStyleDeclaration.cpp:
  • css/DeprecatedStyleBuilder.cpp:
  • page/animation/CompositeAnimation.cpp:
  • page/animation/KeyframeAnimation.cpp:
  • platform/animation/Animation.h:
  • platform/animation/AnimationList.cpp:
  • platform/animation/AnimationList.h:
  • rendering/RenderLayerBacking.cpp:
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r155116 r155119  
     12013-09-04  Anders Carlsson  <andersca@apple.com>
     2
     3        Animations in an AnimationList are never null
     4        https://bugs.webkit.org/show_bug.cgi?id=120720
     5
     6        Reviewed by Andreas Kling.
     7
     8        Change AnimationList::operator[] to return an Animation& and fix up related code to also take references.
     9
     10        * css/CSSComputedStyleDeclaration.cpp:
     11        * css/DeprecatedStyleBuilder.cpp:
     12        * page/animation/CompositeAnimation.cpp:
     13        * page/animation/KeyframeAnimation.cpp:
     14        * platform/animation/Animation.h:
     15        * platform/animation/AnimationList.cpp:
     16        * platform/animation/AnimationList.h:
     17        * rendering/RenderLayerBacking.cpp:
     18
    1192013-09-05  Antti Koivisto  <antti@apple.com>
    220
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r154996 r155119  
    11661166}
    11671167
    1168 static PassRefPtr<CSSValue> createTransitionPropertyValue(const Animation* animation)
     1168static PassRefPtr<CSSValue> createTransitionPropertyValue(const Animation& animation)
    11691169{
    11701170    RefPtr<CSSValue> propertyValue;
    1171     if (animation->animationMode() == Animation::AnimateNone)
     1171    if (animation.animationMode() == Animation::AnimateNone)
    11721172        propertyValue = cssValuePool().createIdentifierValue(CSSValueNone);
    1173     else if (animation->animationMode() == Animation::AnimateAll)
     1173    else if (animation.animationMode() == Animation::AnimateAll)
    11741174        propertyValue = cssValuePool().createIdentifierValue(CSSValueAll);
    11751175    else
    1176         propertyValue = cssValuePool().createValue(getPropertyNameString(animation->property()), CSSPrimitiveValue::CSS_STRING);
     1176        propertyValue = cssValuePool().createValue(getPropertyNameString(animation.property()), CSSPrimitiveValue::CSS_STRING);
    11771177    return propertyValue.release();
    11781178}
     1179
    11791180static PassRefPtr<CSSValue> getTransitionPropertyValue(const AnimationList* animList)
    11801181{
     
    11931194    if (animList) {
    11941195        for (size_t i = 0; i < animList->size(); ++i)
    1195             list->append(cssValuePool().createValue(animList->animation(i)->delay(), CSSPrimitiveValue::CSS_S));
     1196            list->append(cssValuePool().createValue(animList->animation(i).delay(), CSSPrimitiveValue::CSS_S));
    11961197    } else {
    11971198        // Note that initialAnimationDelay() is used for both transitions and animations
     
    12061207    if (animList) {
    12071208        for (size_t i = 0; i < animList->size(); ++i)
    1208             list->append(cssValuePool().createValue(animList->animation(i)->duration(), CSSPrimitiveValue::CSS_S));
     1209            list->append(cssValuePool().createValue(animList->animation(i).duration(), CSSPrimitiveValue::CSS_S));
    12091210    } else {
    12101211        // Note that initialAnimationDuration() is used for both transitions and animations
     
    12551256    if (animList) {
    12561257        for (size_t i = 0; i < animList->size(); ++i)
    1257             list->append(createTimingFunctionValue(animList->animation(i)->timingFunction().get()));
     1258            list->append(createTimingFunctionValue(animList->animation(i).timingFunction().get()));
    12581259    } else
    12591260        // Note that initialAnimationTimingFunction() is used for both transitions and animations
     
    25242525            if (t) {
    25252526                for (size_t i = 0; i < t->size(); ++i) {
    2526                     if (t->animation(i)->direction())
     2527                    if (t->animation(i).direction())
    25272528                        list->append(cssValuePool().createIdentifierValue(CSSValueAlternate));
    25282529                    else
     
    25402541            if (t) {
    25412542                for (size_t i = 0; i < t->size(); ++i) {
    2542                     switch (t->animation(i)->fillMode()) {
     2543                    switch (t->animation(i).fillMode()) {
    25432544                    case AnimationFillModeNone:
    25442545                        list->append(cssValuePool().createIdentifierValue(CSSValueNone));
     
    25642565            if (t) {
    25652566                for (size_t i = 0; i < t->size(); ++i) {
    2566                     double iterationCount = t->animation(i)->iterationCount();
     2567                    double iterationCount = t->animation(i).iterationCount();
    25672568                    if (iterationCount == Animation::IterationCountInfinite)
    25682569                        list->append(cssValuePool().createIdentifierValue(CSSValueInfinite));
     
    25792580            if (t) {
    25802581                for (size_t i = 0; i < t->size(); ++i)
    2581                     list->append(cssValuePool().createValue(t->animation(i)->name(), CSSPrimitiveValue::CSS_STRING));
     2582                    list->append(cssValuePool().createValue(t->animation(i).name(), CSSPrimitiveValue::CSS_STRING));
    25822583            } else
    25832584                list->append(cssValuePool().createIdentifierValue(CSSValueNone));
     
    25892590            if (t) {
    25902591                for (size_t i = 0; i < t->size(); ++i) {
    2591                     int prop = t->animation(i)->playState();
     2592                    int prop = t->animation(i).playState();
    25922593                    if (prop == AnimPlayStatePlaying)
    25932594                        list->append(cssValuePool().createIdentifierValue(CSSValueRunning));
     
    27432744                for (size_t i = 0; i < animList->size(); ++i) {
    27442745                    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
    2745                     const Animation* animation = animList->animation(i);
     2746                    const Animation& animation = animList->animation(i);
    27462747                    list->append(createTransitionPropertyValue(animation));
    2747                     list->append(cssValuePool().createValue(animation->duration(), CSSPrimitiveValue::CSS_S));
    2748                     list->append(createTimingFunctionValue(animation->timingFunction().get()));
    2749                     list->append(cssValuePool().createValue(animation->delay(), CSSPrimitiveValue::CSS_S));
     2748                    list->append(cssValuePool().createValue(animation.duration(), CSSPrimitiveValue::CSS_S));
     2749                    list->append(createTimingFunctionValue(animation.timingFunction().get()));
     2750                    list->append(cssValuePool().createValue(animation.delay(), CSSPrimitiveValue::CSS_S));
    27502751                    transitionsList->append(list);
    27512752                }
  • trunk/Source/WebCore/css/DeprecatedStyleBuilder.cpp

    r154887 r155119  
    16361636class ApplyPropertyAnimation {
    16371637public:
    1638     static void setValue(Animation* animation, T value) { (animation->*setterFunction)(value); }
    1639     static T value(const Animation* animation) { return (animation->*getterFunction)(); }
    1640     static bool test(const Animation* animation) { return (animation->*testFunction)(); }
    1641     static void clear(Animation* animation) { (animation->*clearFunction)(); }
     1638    static void setValue(Animation& animation, T value) { (animation.*setterFunction)(value); }
     1639    static T value(const Animation& animation) { return (animation.*getterFunction)(); }
     1640    static bool test(const Animation& animation) { return (animation.*testFunction)(); }
     1641    static void clear(Animation& animation) { (animation.*clearFunction)(); }
    16421642    static T initial() { return (*initialFunction)(); }
    1643     static void map(StyleResolver* styleResolver, Animation* animation, CSSValue* value) { (styleResolver->styleMap()->*mapFunction)(animation, value); }
     1643    static void map(StyleResolver* styleResolver, Animation& animation, CSSValue* value) { (styleResolver->styleMap()->*mapFunction)(&animation, value); }
    16441644    static AnimationList* accessAnimations(RenderStyle* style) { return (style->*animationGetterFunction)(); }
    16451645    static const AnimationList* animations(RenderStyle* style) { return (style->*immutableAnimationGetterFunction)(); }
     
    16541654                list->append(Animation::create());
    16551655            setValue(list->animation(i), value(parentList->animation(i)));
    1656             list->animation(i)->setAnimationMode(parentList->animation(i)->animationMode());
     1656            list->animation(i).setAnimationMode(parentList->animation(i).animationMode());
    16571657        }
    16581658
     
    16691669        setValue(list->animation(0), initial());
    16701670        if (propertyID == CSSPropertyWebkitTransitionProperty)
    1671             list->animation(0)->setAnimationMode(Animation::AnimateAll);
     1671            list->animation(0).setAnimationMode(Animation::AnimateAll);
    16721672        for (size_t i = 1; i < list->size(); ++i)
    16731673            clear(list->animation(i));
  • trunk/Source/WebCore/page/animation/CompositeAnimation.cpp

    r153396 r155119  
    9898    if (targetStyle->transitions()) {
    9999        for (size_t i = 0; i < targetStyle->transitions()->size(); ++i) {
    100             const Animation* anim = targetStyle->transitions()->animation(i);
    101             bool isActiveTransition = !m_suspended && (anim->duration() || anim->delay() > 0);
    102 
    103             Animation::AnimationMode mode = anim->animationMode();
     100            const Animation& animation = targetStyle->transitions()->animation(i);
     101            bool isActiveTransition = !m_suspended && (animation.duration() || animation.delay() > 0);
     102
     103            Animation::AnimationMode mode = animation.animationMode();
    104104            if (mode == Animation::AnimateNone)
    105105                continue;
    106106
    107             CSSPropertyID prop = anim->property();
     107            CSSPropertyID prop = animation.property();
    108108
    109109            bool all = mode == Animation::AnimateAll;
     
    175175                if (!equal && isActiveTransition) {
    176176                    // Add the new transition
    177                     RefPtr<ImplicitAnimation> animation = ImplicitAnimation::create(const_cast<Animation*>(anim), prop, renderer, this, modifiedCurrentStyle ? modifiedCurrentStyle.get() : fromStyle);
    178                     LOG(Animations, "Created ImplicitAnimation %p for property %s duration %.2f delay %.2f", animation.get(), getPropertyName(prop), anim->duration(), anim->delay());
    179                     m_transitions.set(prop, animation.release());
     177                    RefPtr<ImplicitAnimation> implicitAnimation = ImplicitAnimation::create(const_cast<Animation*>(&animation), prop, renderer, this, modifiedCurrentStyle ? modifiedCurrentStyle.get() : fromStyle);
     178                    LOG(Animations, "Created ImplicitAnimation %p for property %s duration %.2f delay %.2f", implicitAnimation.get(), getPropertyName(prop), animation.duration(), animation.delay());
     179                    m_transitions.set(prop, implicitAnimation.release());
    180180                }
    181181               
     
    235235            int numAnims = targetStyle->animations()->size();
    236236            for (int i = 0; i < numAnims; ++i) {
    237                 const Animation* anim = targetStyle->animations()->animation(i);
    238                 AtomicString animationName(anim->name());
    239 
    240                 if (!anim->isValidAnimation())
     237                const Animation& animation = targetStyle->animations()->animation(i);
     238                AtomicString animationName(animation.name());
     239
     240                if (!animation.isValidAnimation())
    241241                    continue;
    242242               
     
    252252
    253253                    // Animations match, but play states may differ. Update if needed.
    254                     keyframeAnim->updatePlayState(anim->playState());
     254                    keyframeAnim->updatePlayState(animation.playState());
    255255                               
    256256                    // Set the saved animation to this new one, just in case the play state has changed.
    257                     keyframeAnim->setAnimation(anim);
     257                    keyframeAnim->setAnimation(&animation);
    258258                    keyframeAnim->setIndex(i);
    259                 } else if ((anim->duration() || anim->delay()) && anim->iterationCount() && animationName != none) {
    260                     keyframeAnim = KeyframeAnimation::create(const_cast<Animation*>(anim), renderer, i, this, targetStyle);
    261                     LOG(Animations, "Creating KeyframeAnimation %p with keyframes %s, duration %.2f, delay %.2f, iterations %.2f", keyframeAnim.get(), anim->name().utf8().data(), anim->duration(), anim->delay(), anim->iterationCount());
     259                } else if ((animation.duration() || animation.delay()) && animation.iterationCount() && animationName != none) {
     260                    keyframeAnim = KeyframeAnimation::create(const_cast<Animation*>(&animation), renderer, i, this, targetStyle);
     261                    LOG(Animations, "Creating KeyframeAnimation %p with keyframes %s, duration %.2f, delay %.2f, iterations %.2f", keyframeAnim.get(), animation.name().utf8().data(), animation.duration(), animation.delay(), animation.iterationCount());
    262262                    if (m_suspended) {
    263263                        keyframeAnim->updatePlayState(AnimPlayStatePaused);
  • trunk/Source/WebCore/page/animation/KeyframeAnimation.cpp

    r154877 r155119  
    7474
    7575    for (size_t i = 0; i < style->animations()->size(); i++) {
    76         if (name == style->animations()->animation(i)->name())
    77             return style->animations()->animation(i);
     76        if (name == style->animations()->animation(i).name())
     77            return &style->animations()->animation(i);
    7878    }
    7979
  • trunk/Source/WebCore/platform/animation/Animation.h

    r127757 r155119  
    4040
    4141    static PassRefPtr<Animation> create() { return adoptRef(new Animation); }
    42     static PassRefPtr<Animation> create(const Animation* o) { return adoptRef(new Animation(*o)); }
     42    static PassRefPtr<Animation> create(const Animation& other) { return adoptRef(new Animation(other)); }
    4343
    4444    bool isDelaySet() const { return m_delaySet; }
  • trunk/Source/WebCore/platform/animation/AnimationList.cpp

    r95901 r155119  
    2626
    2727#define FILL_UNSET_PROPERTY(test, propGet, propSet) \
    28 for (i = 0; i < size() && animation(i)->test(); ++i) { } \
     28for (i = 0; i < size() && animation(i).test(); ++i) { } \
    2929if (i < size() && i != 0) { \
    3030    for (size_t j = 0; i < size(); ++i, ++j) \
    31         animation(i)->propSet(animation(j)->propGet()); \
     31        animation(i).propSet(animation(j).propGet()); \
    3232}
    3333
    34 AnimationList::AnimationList(const AnimationList& o)
     34AnimationList::AnimationList(const AnimationList& other)
    3535{
    36     for (size_t i = 0; i < o.size(); ++i)
    37         m_animations.append(Animation::create(o.animation(i)));
     36    for (size_t i = 0; i < other.size(); ++i)
     37        m_animations.append(Animation::create(other.animation(i)));
    3838}
    3939
     
    5252}
    5353
    54 bool AnimationList::operator==(const AnimationList& o) const
     54bool AnimationList::operator==(const AnimationList& other) const
    5555{
    56     if (size() != o.size())
     56    if (size() != other.size())
    5757        return false;
    5858    for (size_t i = 0; i < size(); ++i)
    59         if (*animation(i) != *o.animation(i))
     59        if (animation(i) != other.animation(i))
    6060            return false;
    6161    return true;
  • trunk/Source/WebCore/platform/animation/AnimationList.h

    r95901 r155119  
    3939
    4040    void fillUnsetProperties();
    41     bool operator==(const AnimationList& o) const;
    42     bool operator!=(const AnimationList& o) const
     41    bool operator==(const AnimationList&) const;
     42    bool operator!=(const AnimationList& other) const
    4343    {
    44         return !(*this == o);
     44        return !(*this == other);
    4545    }
    4646   
     
    5050    void resize(size_t n) { m_animations.resize(n); }
    5151    void remove(size_t i) { m_animations.remove(i); }
    52     void append(PassRefPtr<Animation> anim) { m_animations.append(anim); }
     52    void append(PassRefPtr<Animation> animation)
     53    {
     54        ASSERT(animation);
     55        m_animations.append(animation);
     56    }
    5357   
    54     Animation* animation(size_t i) { return m_animations[i].get(); }
    55     const Animation* animation(size_t i) const { return m_animations[i].get(); }
     58    Animation& animation(size_t i) { return *m_animations[i]; }
     59    const Animation& animation(size_t i) const { return *m_animations[i]; }
    5660   
    5761private:
    5862    AnimationList& operator=(const AnimationList&);
    5963
    60     Vector<RefPtr<Animation> > m_animations;
     64    Vector<RefPtr<Animation>> m_animations;
    6165};   
    6266
  • trunk/Source/WebCore/platform/graphics/GraphicsLayerAnimation.cpp

    r154706 r155119  
    217217    : m_keyframes(keyframes)
    218218    , m_boxSize(boxSize)
    219     , m_animation(Animation::create(animation))
     219    , m_animation(Animation::create(*animation))
    220220    , m_name(name)
    221221    , m_listsMatch(listsMatch)
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r154937 r155119  
    21192119           
    21202120        // Get timing function.
    2121         RefPtr<TimingFunction> tf = keyframeStyle->hasAnimations() ? (*keyframeStyle->animations()).animation(0)->timingFunction() : 0;
     2121        RefPtr<TimingFunction> tf = keyframeStyle->hasAnimations() ? (*keyframeStyle->animations()).animation(0).timingFunction() : 0;
    21222122       
    21232123        bool isFirstOrLastKeyframe = key == 0 || key == 1;
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r154993 r155119  
    12591259    // Get rid of empty animations and anything beyond them
    12601260    for (size_t i = 0; i < animationList->size(); ++i) {
    1261         if (animationList->animation(i)->isEmpty()) {
     1261        if (animationList->animation(i).isEmpty()) {
    12621262            animationList->resize(i);
    12631263            break;
     
    12821282    // Get rid of empty transitions and anything beyond them
    12831283    for (size_t i = 0; i < transitionList->size(); ++i) {
    1284         if (transitionList->animation(i)->isEmpty()) {
     1284        if (transitionList->animation(i).isEmpty()) {
    12851285            transitionList->resize(i);
    12861286            break;
     
    13001300    for (size_t i = 0; i < transitionList->size(); ++i) {
    13011301        for (size_t j = i+1; j < transitionList->size(); ++j) {
    1302             if (transitionList->animation(i)->property() == transitionList->animation(j)->property()) {
     1302            if (transitionList->animation(i).property() == transitionList->animation(j).property()) {
    13031303                // toss i
    13041304                transitionList->remove(i);
     
    13271327    if (transitions()) {
    13281328        for (size_t i = 0; i < transitions()->size(); ++i) {
    1329             const Animation* p = transitions()->animation(i);
    1330             if (p->animationMode() == Animation::AnimateAll || p->property() == property) {
    1331                 return p;
     1329            const Animation& p = transitions()->animation(i);
     1330            if (p.animationMode() == Animation::AnimateAll || p.property() == property) {
     1331                return &p;
    13321332            }
    13331333        }
Note: See TracChangeset for help on using the changeset viewer.