Changeset 37077 in webkit


Ignore:
Timestamp:
Sep 29, 2008 2:31:26 PM (16 years ago)
Author:
Simon Fraser
Message:

2008-09-29 Chris Marrin <cmarrin@apple.com>

Reviewed by Dave Hyatt

Fixed https://bugs.webkit.org/show_bug.cgi?id=20995
Rewrite keyframe resolution to be like styleForElement()

Test: animations/lineheight-animation.html

  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::addKeyframeStyle): (WebCore::CSSStyleSelector::~CSSStyleSelector): (WebCore::CSSStyleSelector::keyframeStylesForAnimation): (WebCore::CSSRuleSet::addRulesFromSheet): (WebCore::CSSStyleSelector::mapAnimationName):
  • css/CSSStyleSelector.h:
  • page/animation/CompositeAnimation.cpp: (WebCore::CompositeAnimation::updateKeyframeAnimations):
  • page/animation/KeyframeAnimation.cpp: (WebCore::KeyframeAnimation::KeyframeAnimation): (WebCore::KeyframeAnimation::animate): (WebCore::KeyframeAnimation::hasAnimationForProperty): (WebCore::KeyframeAnimation::sendAnimationEvent): (WebCore::KeyframeAnimation::overrideAnimations): (WebCore::KeyframeAnimation::resumeOverriddenAnimations): (WebCore::KeyframeAnimation::affectsProperty): (WebCore::KeyframeAnimation::validateTransformFunctionList):
  • page/animation/KeyframeAnimation.h:
  • rendering/style/Animation.cpp: (WebCore::Animation::animationsMatch):
  • rendering/style/Animation.h:
  • rendering/style/KeyframeList.cpp: (WebCore::KeyframeList::~KeyframeList): (WebCore::KeyframeList::clear): (WebCore::KeyframeList::insert):
  • rendering/style/KeyframeList.h: (WebCore::KeyframeValue::KeyframeValue): (WebCore::KeyframeList::KeyframeList): (WebCore::KeyframeList::operator!=): (WebCore::KeyframeList::animationName): (WebCore::KeyframeList::addProperty): (WebCore::KeyframeList::containsProperty): (WebCore::KeyframeList::beginProperties): (WebCore::KeyframeList::endProperties): (WebCore::KeyframeList::isEmpty): (WebCore::KeyframeList::size): (WebCore::KeyframeList::beginKeyframes): (WebCore::KeyframeList::endKeyframes):
  • rendering/style/RenderStyle.h:
  • rendering/style/StyleRareNonInheritedData.cpp:
  • rendering/style/StyleRareNonInheritedData.h:
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r37076 r37077  
     12008-09-29  Chris Marrin  <cmarrin@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        * animations/lineheight-animation-expected.txt: Added.
     6        * animations/lineheight-animation.html: Added.
     7
    182008-09-29  Chris Marrin  <cmarrin@apple.com>
    29
  • trunk/WebCore/ChangeLog

    r37076 r37077  
     12008-09-29  Chris Marrin  <cmarrin@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        Fixed https://bugs.webkit.org/show_bug.cgi?id=20995
     6        Rewrite keyframe resolution to be like styleForElement()
     7       
     8        Test: animations/lineheight-animation.html
     9
     10        * css/CSSStyleSelector.cpp:
     11        (WebCore::CSSStyleSelector::addKeyframeStyle):
     12        (WebCore::CSSStyleSelector::~CSSStyleSelector):
     13        (WebCore::CSSStyleSelector::keyframeStylesForAnimation):
     14        (WebCore::CSSRuleSet::addRulesFromSheet):
     15        (WebCore::CSSStyleSelector::mapAnimationName):
     16        * css/CSSStyleSelector.h:
     17        * page/animation/CompositeAnimation.cpp:
     18        (WebCore::CompositeAnimation::updateKeyframeAnimations):
     19        * page/animation/KeyframeAnimation.cpp:
     20        (WebCore::KeyframeAnimation::KeyframeAnimation):
     21        (WebCore::KeyframeAnimation::animate):
     22        (WebCore::KeyframeAnimation::hasAnimationForProperty):
     23        (WebCore::KeyframeAnimation::sendAnimationEvent):
     24        (WebCore::KeyframeAnimation::overrideAnimations):
     25        (WebCore::KeyframeAnimation::resumeOverriddenAnimations):
     26        (WebCore::KeyframeAnimation::affectsProperty):
     27        (WebCore::KeyframeAnimation::validateTransformFunctionList):
     28        * page/animation/KeyframeAnimation.h:
     29        * rendering/style/Animation.cpp:
     30        (WebCore::Animation::animationsMatch):
     31        * rendering/style/Animation.h:
     32        * rendering/style/KeyframeList.cpp:
     33        (WebCore::KeyframeList::~KeyframeList):
     34        (WebCore::KeyframeList::clear):
     35        (WebCore::KeyframeList::insert):
     36        * rendering/style/KeyframeList.h:
     37        (WebCore::KeyframeValue::KeyframeValue):
     38        (WebCore::KeyframeList::KeyframeList):
     39        (WebCore::KeyframeList::operator!=):
     40        (WebCore::KeyframeList::animationName):
     41        (WebCore::KeyframeList::addProperty):
     42        (WebCore::KeyframeList::containsProperty):
     43        (WebCore::KeyframeList::beginProperties):
     44        (WebCore::KeyframeList::endProperties):
     45        (WebCore::KeyframeList::isEmpty):
     46        (WebCore::KeyframeList::size):
     47        (WebCore::KeyframeList::beginKeyframes):
     48        (WebCore::KeyframeList::endKeyframes):
     49        * rendering/style/RenderStyle.h:
     50        * rendering/style/StyleRareNonInheritedData.cpp:
     51        * rendering/style/StyleRareNonInheritedData.h:
     52
    1532008-09-29  Chris Marrin  <cmarrin@apple.com>
    254
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r36918 r37077  
    445445
    446446// This is a simplified style setting function for keyframe styles
    447 void CSSStyleSelector::addKeyframeStyle(Document* doc, const WebKitCSSKeyframesRule* rule)
    448 {
    449     // Create the keyframe list
     447void CSSStyleSelector::addKeyframeStyle(PassRefPtr<WebKitCSSKeyframesRule> rule)
     448{
    450449    AtomicString s(rule->name());
    451     RefPtr<KeyframeList> list;
    452     if (m_keyframeRuleMap.contains(s.impl()))
    453         list = m_keyframeRuleMap.get(s.impl()).get();
    454     else {
    455         list = KeyframeList::create(s);
    456         m_keyframeRuleMap.add(s.impl(), list);
    457     }
    458     list->clear();
    459 
    460     // Add all the keyframes
    461     for (unsigned i = 0; i < rule->length(); ++i) {
    462         const WebKitCSSKeyframeRule* kf = rule->item(i);
    463         m_style = new (doc->renderArena()) RenderStyle();
    464         m_style->ref();
    465         CSSMutableStyleDeclaration* decl = kf->style();
    466         DeprecatedValueListConstIterator<CSSProperty> end;
    467 
    468         // Record all the properties in this keyframe
    469         for (DeprecatedValueListConstIterator<CSSProperty> it = decl->valuesIterator(); it != end; ++it) {
    470             const CSSProperty& current = *it;
    471             applyProperty(current.id(), current.value());
    472             list->addProperty(current.id());
    473         }
    474 
    475         // Add this keyframe to all the indicated key times
    476         Vector<float> keys;
    477         kf->getKeys(keys);
    478 
    479         for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
    480             float key = keys[keyIndex];
    481             list->insert(key, *m_style);
    482         }
    483 
    484         m_style->deref(doc->renderArena());
    485         m_style = 0;
    486     }
    487 
    488     // Make sure there is a 0% and a 100% keyframe
    489     float first = list->beginKeyframes()->key;
    490     float last = (list->endKeyframes()-1)->key;
    491     if (first != 0 || last != 1) {
    492         list->clear();
    493         return;
    494     }
     450    m_keyframesRuleMap.add(s.impl(), rule);
    495451}
    496452
     
    512468    delete m_userStyle;
    513469    deleteAllValues(m_viewportDependentMediaQueryResults);
    514     m_keyframeRuleMap.clear();
     470    m_keyframesRuleMap.clear();
    515471}
    516472
     
    12211177    // Now return the style.
    12221178    return m_style;
     1179}
     1180
     1181void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle* elementStyle, KeyframeList& list)
     1182{
     1183    list.clear();
     1184   
     1185    // Get the keyframesRule for this name
     1186    if (!e || list.animationName().isEmpty())
     1187        return;
     1188           
     1189    if (!m_keyframesRuleMap.contains(list.animationName().impl()))
     1190        return;
     1191       
     1192    const WebKitCSSKeyframesRule* rule = m_keyframesRuleMap.find(list.animationName().impl()).get()->second.get();
     1193   
     1194    // Construct and populate the style for each keyframe
     1195    for (unsigned i = 0; i < rule->length(); ++i) {
     1196        // Apply the declaration to the style. This is a simplified version of the logic in styleForElement
     1197        initElementAndPseudoState(e);
     1198        initForStyleResolve(e);
     1199       
     1200        const WebKitCSSKeyframeRule* kf = rule->item(i);
     1201        addMatchedDeclaration(kf->style());
     1202
     1203        // Create the style
     1204        m_style = new (e->document()->renderArena()) RenderStyle(*elementStyle);
     1205        m_style->ref();
     1206       
     1207        m_lineHeightValue = 0;
     1208       
     1209        // We don't need to bother with !important. Since there is only ever one
     1210        // decl, there's nothing to override. So just add the first properties.
     1211        applyDeclarations(true, false, 0, m_matchedDecls.size() - 1);
     1212       
     1213        // If our font got dirtied, go ahead and update it now.
     1214        if (m_fontDirty)
     1215            updateFont();
     1216
     1217        // Line-height is set when we are sure we decided on the font-size
     1218        if (m_lineHeightValue)
     1219            applyProperty(CSSPropertyLineHeight, m_lineHeightValue);
     1220       
     1221        // Now do rest of the properties.
     1222        applyDeclarations(false, false, 0, m_matchedDecls.size() - 1);
     1223       
     1224        // If our font got dirtied by one of the non-essential font props,
     1225        // go ahead and update it a second time.
     1226        if (m_fontDirty)
     1227            updateFont();
     1228
     1229        // Add all the animating properties to the list
     1230        DeprecatedValueListConstIterator<CSSProperty> end;
     1231        for (DeprecatedValueListConstIterator<CSSProperty> it = kf->style()->valuesIterator(); it != end; ++it)
     1232            list.addProperty((*it).id());
     1233       
     1234        // Add this keyframe style to all the indicated key times
     1235        Vector<float> keys;
     1236        kf->getKeys(keys);
     1237        for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
     1238            float key = keys[keyIndex];
     1239            list.insert(key, m_style);
     1240        }
     1241        m_style->deref(e->document()->renderArena());
     1242        m_style = 0;
     1243    }
     1244   
     1245    // Make sure there is a 0% and a 100% keyframe
     1246    float first = list.beginKeyframes()->key;
     1247    float last = (list.endKeyframes()-1)->key;
     1248    if (first != 0 || last != 1)
     1249        list.clear();
    12231250}
    12241251
     
    24162443                    } else if (childItem->isKeyframesRule() && styleSelector) {
    24172444                        // Add this keyframe rule to our set.
    2418                         const WebKitCSSKeyframesRule* keyframesRule = static_cast<WebKitCSSKeyframesRule*>(childItem);
    2419                         styleSelector->addKeyframeStyle(sheet->doc(), keyframesRule);
     2445                        styleSelector->addKeyframeStyle(static_cast<WebKitCSSKeyframesRule*>(childItem));
    24202446                    }
    24212447                }   // for rules
     
    24302456            if (!variables->media() || medium.eval(variables->media(), styleSelector))
    24312457                styleSelector->addVariables(variables);
    2432         } else if (item->isKeyframesRule()) {
    2433             WebKitCSSKeyframesRule* r = static_cast<WebKitCSSKeyframesRule*>(item);
    2434             styleSelector->addKeyframeStyle(sheet->doc(), r);
    2435         }
     2458        } else if (item->isKeyframesRule())
     2459            styleSelector->addKeyframeStyle(static_cast<WebKitCSSKeyframesRule*>(item));
    24362460    }
    24372461}
     
    51125136    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    51135137   
    5114     if (primitiveValue->getIdent() == CSSValueNone) {
     5138    if (primitiveValue->getIdent() == CSSValueNone)
    51155139        layer->setIsNoneAnimation(true);
    5116     } else {
     5140    else
    51175141        layer->setName(primitiveValue->getStringValue());
    5118    
    5119         // resolve to the keyframes
    5120         RefPtr<KeyframeList> keyframe = findKeyframeRule(primitiveValue->getStringValue());
    5121         layer->setAnimationKeyframe(keyframe);
    5122     }
    51235142}
    51245143
  • trunk/WebCore/css/CSSStyleSelector.h

    r36619 r37077  
    8585        void initForStyleResolve(Element*, RenderStyle* parentStyle = 0, RenderStyle::PseudoId = RenderStyle::NOPSEUDO);
    8686        RenderStyle* styleForElement(Element*, RenderStyle* parentStyle = 0, bool allowSharing = true, bool resolveForRootDefault = false);
     87        void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList& list);
    8788
    8889        RenderStyle* pseudoStyleForElement(RenderStyle::PseudoId, Element*, RenderStyle* parentStyle = 0);
     
    140141        void resolveVariablesForDeclaration(CSSMutableStyleDeclaration* decl, CSSMutableStyleDeclaration* newDecl, HashSet<String>& usedBlockVariables);
    141142
    142         KeyframeList* findKeyframeRule(const String& name) const
    143         {
    144             if (name.isEmpty())
    145                 return 0;
    146            
    147             AtomicString s(name);
    148             if (!m_keyframeRuleMap.contains(s.impl()))
    149                 return 0;
    150             return m_keyframeRuleMap.find(s.impl()).get()->second.get();
    151         }
    152 
    153         void addKeyframeStyle(Document* doc, const WebKitCSSKeyframesRule* rule);
     143        void addKeyframeStyle(PassRefPtr<WebKitCSSKeyframesRule> rule);
    154144
    155145        static bool createTransformOperations(CSSValue* inValue, RenderStyle* inStyle, TransformOperations& outOperations);
     
    183173        Color m_backgroundColor;
    184174
    185         typedef HashMap<AtomicStringImpl*, RefPtr<KeyframeList> > KeyframeRuleMap;
    186         KeyframeRuleMap m_keyframeRuleMap;
     175        typedef HashMap<AtomicStringImpl*, RefPtr<WebKitCSSKeyframesRule> > KeyframesRuleMap;
     176        KeyframesRuleMap m_keyframesRuleMap;
    187177
    188178    public:
  • trunk/WebCore/page/animation/CompositeAnimation.cpp

    r37076 r37077  
    3434#include "ImplicitAnimation.h"
    3535#include "KeyframeAnimation.h"
    36 #include "KeyframeList.h"
    3736#include "RenderObject.h"
    3837#include "RenderStyle.h"
     
    155154                keyframeAnim->setAnimation(anim);
    156155                keyframeAnim->setIndex(i);
    157             } else if ((anim->duration() || anim->delay()) && anim->iterationCount()
    158                         && anim->keyframeList() && !anim->keyframeList()->isEmpty()) {
     156            } else if ((anim->duration() || anim->delay()) && anim->iterationCount()) {
    159157                keyframeAnim = new KeyframeAnimation(const_cast<Animation*>(anim), renderer, i, this, currentStyle ? currentStyle : targetStyle);
    160158                m_keyframeAnimations.set(keyframeAnim->name().impl(), keyframeAnim);
  • trunk/WebCore/page/animation/KeyframeAnimation.cpp

    r37074 r37077  
    3131
    3232#include "CSSPropertyNames.h"
     33#include "CSSStyleSelector.h"
    3334#include "CompositeAnimation.h"
    3435#include "EventNames.h"
     
    3738
    3839namespace WebCore {
     40
     41KeyframeAnimation::KeyframeAnimation(const Animation* animation, RenderObject* renderer, int index, CompositeAnimation* compAnim, const RenderStyle* unanimatedStyle)
     42    : AnimationBase(animation, renderer, compAnim)
     43    , m_keyframes(renderer, animation->name())
     44    , m_index(index)
     45    , m_unanimatedStyle(0)
     46{
     47    // Set the transform animation list
     48    validateTransformFunctionList();
     49   
     50    if (unanimatedStyle) {
     51        const_cast<RenderStyle*>(unanimatedStyle)->ref();
     52        m_unanimatedStyle = unanimatedStyle;
     53    }
     54   
     55    // Get the keyframe RenderStyles
     56    if (m_object && m_object->element() && m_object->element()->isElementNode())
     57        m_object->document()->styleSelector()->keyframeStylesForAnimation(static_cast<Element*>(m_object->element()), unanimatedStyle, m_keyframes);
     58}
    3959
    4060KeyframeAnimation::~KeyframeAnimation()
     
    84104    double scale = 1;
    85105    double offset = 0;
    86     if (m_keyframes.get()) {
    87         Vector<KeyframeValue>::const_iterator end = m_keyframes->endKeyframes();
    88         for (Vector<KeyframeValue>::const_iterator it = m_keyframes->beginKeyframes(); it != end; ++it) {
    89             if (t < it->key) {
    90                 // The first key should always be 0, so we should never succeed on the first key
    91                 if (!fromStyle)
    92                     break;
    93                 scale = 1.0 / (it->key - offset);
    94                 toStyle = const_cast<RenderStyle*>(&(it->style));
     106    Vector<KeyframeValue>::const_iterator endKeyframes = m_keyframes.endKeyframes();
     107    for (Vector<KeyframeValue>::const_iterator it = m_keyframes.beginKeyframes(); it != endKeyframes; ++it) {
     108        if (t < it->key) {
     109            // The first key should always be 0, so we should never succeed on the first key
     110            if (!fromStyle)
    95111                break;
    96             }
    97 
    98             offset = it->key;
    99             fromStyle = const_cast<RenderStyle*>(&(it->style));
    100         }
     112            scale = 1.0 / (it->key - offset);
     113            toStyle = it->style;
     114            break;
     115        }
     116
     117        offset = it->key;
     118        fromStyle = it->style;
    101119    }
    102120
     
    118136    double prog = progress(scale, offset, timingFunction);
    119137
    120     HashSet<int>::const_iterator end = m_keyframes->endProperties();
    121     for (HashSet<int>::const_iterator it = m_keyframes->beginProperties(); it != end; ++it) {
     138    HashSet<int>::const_iterator endProperties = m_keyframes.endProperties();
     139    for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != endProperties; ++it) {
    122140        if (blendProperties(this, *it, animatedStyle, fromStyle, toStyle, prog))
    123141            setAnimating();
     
    127145bool KeyframeAnimation::hasAnimationForProperty(int property) const
    128146{
    129     HashSet<int>::const_iterator end = m_keyframes->endProperties();
    130     for (HashSet<int>::const_iterator it = m_keyframes->beginProperties(); it != end; ++it) {
     147    HashSet<int>::const_iterator end = m_keyframes.endProperties();
     148    for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != end; ++it) {
    131149        if (*it == property)
    132150            return true;
     
    181199        if (Element* element = elementForEventDispatch()) {
    182200            m_waitingForEndEvent = true;
    183             m_animationEventDispatcher.startTimer(element, m_name, -1, true, eventType, elapsedTime);
     201            m_animationEventDispatcher.startTimer(element, m_keyframes.animationName(), -1, true, eventType, elapsedTime);
    184202            return true; // Did dispatch an event
    185203        }
     
    192210{
    193211    // This will override implicit animations that match the properties in the keyframe animation
    194     HashSet<int>::const_iterator end = m_keyframes->endProperties();
    195     for (HashSet<int>::const_iterator it = m_keyframes->beginProperties(); it != end; ++it)
     212    HashSet<int>::const_iterator end = m_keyframes.endProperties();
     213    for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != end; ++it)
    196214        compositeAnimation()->overrideImplicitAnimations(*it);
    197215}
     
    200218{
    201219    // This will resume overridden implicit animations
    202     HashSet<int>::const_iterator end = m_keyframes->endProperties();
    203     for (HashSet<int>::const_iterator it = m_keyframes->beginProperties(); it != end; ++it)
     220    HashSet<int>::const_iterator end = m_keyframes.endProperties();
     221    for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != end; ++it)
    204222        compositeAnimation()->resumeOverriddenImplicitAnimations(*it);
    205223}
     
    207225bool KeyframeAnimation::affectsProperty(int property) const
    208226{
    209     HashSet<int>::const_iterator end = m_keyframes->endProperties();
    210     for (HashSet<int>::const_iterator it = m_keyframes->beginProperties(); it != end; ++it) {
     227    HashSet<int>::const_iterator end = m_keyframes.endProperties();
     228    for (HashSet<int>::const_iterator it = m_keyframes.beginProperties(); it != end; ++it) {
    211229        if (*it == property)
    212230            return true;
     
    219237    m_transformFunctionListValid = false;
    220238   
    221     if (!m_keyframes.get() || m_keyframes->size() < 2 || !m_keyframes->containsProperty(CSSPropertyWebkitTransform))
    222         return;
    223 
    224     Vector<KeyframeValue>::const_iterator end = m_keyframes->endKeyframes();
     239    if (m_keyframes.size() < 2 || !m_keyframes.containsProperty(CSSPropertyWebkitTransform))
     240        return;
     241
     242    Vector<KeyframeValue>::const_iterator end = m_keyframes.endKeyframes();
    225243
    226244    // Empty transforms match anything, so find the first non-empty entry as the reference
     
    228246    Vector<KeyframeValue>::const_iterator firstIt = end;
    229247   
    230     for (Vector<KeyframeValue>::const_iterator it = m_keyframes->beginKeyframes(); it != end; ++it, ++firstIndex) {
    231         if (it->style.transform().operations().size() > 0) {
     248    for (Vector<KeyframeValue>::const_iterator it = m_keyframes.beginKeyframes(); it != end; ++it, ++firstIndex) {
     249        if (it->style->transform().operations().size() > 0) {
    232250            firstIt = it;
    233251            break;
     
    238256        return;
    239257       
    240     const TransformOperations* firstVal = &firstIt->style.transform();
     258    const TransformOperations* firstVal = &firstIt->style->transform();
    241259   
    242260    // See if the keyframes are valid
    243261    for (Vector<KeyframeValue>::const_iterator it = firstIt+1; it != end; ++it) {
    244         const TransformOperations* val = &it->style.transform();
     262        const TransformOperations* val = &it->style->transform();
    245263       
    246264        // A null transform matches anything
  • trunk/WebCore/page/animation/KeyframeAnimation.h

    r36687 r37077  
    4141class KeyframeAnimation : public AnimationBase {
    4242public:
    43     KeyframeAnimation(const Animation* animation, RenderObject* renderer, int index, CompositeAnimation* compAnim, const RenderStyle* unanimatedStyle)
    44         : AnimationBase(animation, renderer, compAnim)
    45         , m_keyframes(animation->keyframeList())
    46         , m_name(animation->name())
    47         , m_index(index)
    48         , m_unanimatedStyle(0)
    49     {
    50         // Set the transform animation list
    51         validateTransformFunctionList();
    52        
    53         if (unanimatedStyle) {
    54             const_cast<RenderStyle*>(unanimatedStyle)->ref();
    55             m_unanimatedStyle = unanimatedStyle;
    56         }
    57     }
    58 
     43    KeyframeAnimation(const Animation* animation, RenderObject* renderer, int index, CompositeAnimation* compAnim, const RenderStyle* unanimatedStyle);
    5944    virtual ~KeyframeAnimation();
    6045
    6146    virtual void animate(CompositeAnimation*, RenderObject*, const RenderStyle* currentStyle, const RenderStyle* targetStyle, RenderStyle*& animatedStyle);
    6247
    63     void setName(const String& s) { m_name = s; }
    64     const AtomicString& name() const { return m_name; }
     48    const AtomicString& name() const { return m_keyframes.animationName(); }
    6549    int index() const { return m_index; }
    6650    void setIndex(int i) { m_index = i; }
     
    9074private:
    9175    // The keyframes that we are blending.
    92     RefPtr<KeyframeList> m_keyframes;
    93     AtomicString m_name;
     76    KeyframeList m_keyframes;
     77
    9478    // The order in which this animation appears in the animation-name style.
    9579    int m_index;
  • trunk/WebCore/rendering/style/Animation.cpp

    r36619 r37077  
    2323#include "Animation.h"
    2424
    25 #include "KeyframeList.h"
    2625#include "RenderStyle.h"
    2726
     
    124123        return false;
    125124
    126     if (matchPlayStates && (m_playState != o->m_playState || m_playStateSet != o->m_playStateSet))
    127         return false;
    128 
    129     // now check keyframes
    130     if ((m_keyframeList.get() && !o->m_keyframeList.get()) || (!m_keyframeList.get() && o->m_keyframeList.get()))
    131         return false;
    132     if (!(m_keyframeList.get()))
    133         return true;
    134     return *m_keyframeList == *o->m_keyframeList;
    135 }
    136 
    137 const RefPtr<KeyframeList>& Animation::keyframeList() const
    138 {
    139     return m_keyframeList;
    140 }
    141 
    142 void Animation::setAnimationKeyframe(const RefPtr<KeyframeList> keyframeList)
    143 {
    144     m_keyframeList = keyframeList;
     125    return !matchPlayStates || (m_playState == o->m_playState && m_playStateSet == o->m_playStateSet);
    145126}
    146127
  • trunk/WebCore/rendering/style/Animation.h

    r36619 r37077  
    3232
    3333namespace WebCore {
    34 
    35 class KeyframeList;
    3634
    3735class Animation : public RefCounted<Animation> {
     
    8583    const TimingFunction& timingFunction() const { return m_timingFunction; }
    8684
    87     const RefPtr<KeyframeList>& keyframeList() const;
    88 
    8985    void setDelay(double c) { m_delay = c; m_delaySet = true; }
    9086    void setDirection(bool d) { m_direction = d; m_directionSet = true; }
     
    9793
    9894    void setIsNoneAnimation(bool n) { m_isNone = n; }
    99 
    100     void setAnimationKeyframe(const RefPtr<KeyframeList> keyframe);
    10195
    10296    Animation& operator=(const Animation& o);
     
    121115    TimingFunction m_timingFunction;
    122116
    123     RefPtr<KeyframeList> m_keyframeList;
    124 
    125117    unsigned m_playState     : 2;
    126118
  • trunk/WebCore/rendering/style/KeyframeList.cpp

    r36619 r37077  
    2222#include "config.h"
    2323#include "KeyframeList.h"
     24#include "RenderObject.h"
    2425
    2526namespace WebCore {
     27
     28KeyframeList::~KeyframeList()
     29{
     30    clear();
     31}
     32
     33void KeyframeList::clear()
     34{
     35    for (Vector<KeyframeValue>::const_iterator it = m_keyframes.begin(); it != m_keyframes.end(); ++it)
     36        if (it->style)
     37            it->style->deref(m_renderer->renderArena());
     38
     39    m_keyframes.clear();
     40    m_properties.clear();
     41}
    2642
    2743bool KeyframeList::operator==(const KeyframeList& o) const
     
    4460}
    4561
    46 void KeyframeList::insert(float inKey, const RenderStyle& inStyle)
     62void KeyframeList::insert(float key, RenderStyle* style)
    4763{
    48     if (inKey < 0 || inKey > 1)
     64    if (key < 0 || key > 1)
    4965        return;
    5066
     67    int index = -1;
     68   
    5169    for (size_t i = 0; i < m_keyframes.size(); ++i) {
    52         if (m_keyframes[i].key == inKey) {
    53             m_keyframes[i].style = inStyle;
    54             return;
     70        if (m_keyframes[i].key == key) {
     71            index = (int) i;
     72            break;
    5573        }
    56         if (m_keyframes[i].key > inKey) {
     74        if (m_keyframes[i].key > key) {
    5775            // insert before
    5876            m_keyframes.insert(i, KeyframeValue());
    59             m_keyframes[i].key = inKey;
    60             m_keyframes[i].style = inStyle;
    61             return;
     77            index = (int) i;
     78            break;
    6279        }
    6380    }
    64 
    65     // append
    66     m_keyframes.append(KeyframeValue());
    67     m_keyframes[m_keyframes.size()-1].key = inKey;
    68     m_keyframes[m_keyframes.size()-1].style = inStyle;
     81   
     82    if (index < 0) {
     83        // append
     84        index = (int) m_keyframes.size();
     85        m_keyframes.append(KeyframeValue());
     86    }
     87   
     88    if (style)
     89        style->ref();
     90    if (m_keyframes[index].style)
     91        m_keyframes[index].style->deref(m_renderer->renderArena());
     92    m_keyframes[index].key = key;
     93    m_keyframes[index].style = style;
    6994}
    7095
  • trunk/WebCore/rendering/style/KeyframeList.h

    r36619 r37077  
    2727
    2828#include "AtomicString.h"
    29 #include "RenderStyle.h"
    3029#include <wtf/Vector.h>
    3130#include <wtf/HashSet.h>
    32 #include <wtf/PassRefPtr.h>
    33 #include <wtf/RefCounted.h>
    3431
    3532namespace WebCore {
     33
     34class RenderObject;
     35class RenderStyle;
    3636
    3737class KeyframeValue {
     
    3939    KeyframeValue()
    4040        : key(-1)
     41        , style(0)
    4142    {
    4243    }
    4344
    4445    float key;
    45     RenderStyle style;
     46    RenderStyle* style;
    4647};
    4748
    48 class KeyframeList : public RefCounted<KeyframeList> {
     49class KeyframeList {
    4950public:
    50     static PassRefPtr<KeyframeList> create(const AtomicString& animationName) { return adoptRef(new KeyframeList(animationName)); }
    51 
     51    KeyframeList(RenderObject* renderer, const AtomicString& animationName)
     52        : m_animationName(animationName)
     53        , m_renderer(renderer)
     54    {
     55        insert(0, 0);
     56        insert(1, 0);
     57    }
     58    ~KeyframeList();
     59       
    5260    bool operator==(const KeyframeList& o) const;
    5361    bool operator!=(const KeyframeList& o) const { return !(*this == o); }
     
    5563    const AtomicString& animationName() const { return m_animationName; }
    5664   
    57     void insert(float inKey, const RenderStyle& inStyle);
     65    void insert(float key, RenderStyle* style);
    5866   
    5967    void addProperty(int prop) { m_properties.add(prop); }
    6068    bool containsProperty(int prop) const { return m_properties.contains(prop); }
    61     HashSet<int>::const_iterator beginProperties() { return m_properties.begin(); }
    62     HashSet<int>::const_iterator endProperties() { return m_properties.end(); }
     69    HashSet<int>::const_iterator beginProperties() const { return m_properties.begin(); }
     70    HashSet<int>::const_iterator endProperties() const { return m_properties.end(); }
    6371   
    64     void clear() { m_keyframes.clear(); m_properties.clear(); }
     72    void clear();
    6573    bool isEmpty() const { return m_keyframes.isEmpty(); }
    6674    size_t size() const { return m_keyframes.size(); }
     
    6977
    7078private:
    71     KeyframeList(const AtomicString& animationName)
    72         : m_animationName(animationName)
    73     {
    74         insert(0, RenderStyle());
    75         insert(1, RenderStyle());
    76     }
    77        
    7879    AtomicString m_animationName;
    7980    Vector<KeyframeValue> m_keyframes;
    8081    HashSet<int> m_properties;       // the properties being animated
     82    RenderObject* m_renderer;
    8183};
    8284
  • trunk/WebCore/rendering/style/RenderStyle.h

    r36635 r37077  
    946946    void adjustAnimations();
    947947    void adjustTransitions();
    948     void updateKeyframes(const CSSStyleSelector* styleSelector) { if (rareNonInheritedData.get()) rareNonInheritedData.access()->updateKeyframes(styleSelector); }
    949948
    950949    void setLineClamp(int c) { SET_VAR(rareNonInheritedData, lineClamp, c); }
  • trunk/WebCore/rendering/style/StyleRareNonInheritedData.cpp

    r36634 r37077  
    2424
    2525#include "CSSStyleSelector.h"
    26 #include "KeyframeList.h"
    2726#include "RenderStyle.h"
    2827
     
    148147}
    149148
    150 void StyleRareNonInheritedData::updateKeyframes(const CSSStyleSelector* styleSelector)
    151 {
    152     if (m_animations) {
    153         for (size_t i = 0; i < m_animations->size(); ++i) {
    154             if (m_animations->animation(i)->isValidAnimation()) {
    155                 RefPtr<KeyframeList> keyframe = styleSelector->findKeyframeRule(m_animations->animation(i)->name());
    156                 m_animations->animation(i)->setAnimationKeyframe(keyframe);
    157             }
    158         }
    159     }
    160 }
    161 
    162149bool StyleRareNonInheritedData::animationDataEquivalent(const StyleRareNonInheritedData& o) const
    163150{
  • trunk/WebCore/rendering/style/StyleRareNonInheritedData.h

    r36623 r37077  
    7575    bool animationDataEquivalent(const StyleRareNonInheritedData&) const;
    7676    bool transitionDataEquivalent(const StyleRareNonInheritedData&) const;
    77     void updateKeyframes(const CSSStyleSelector* styleSelector);
    7877
    7978    int lineClamp; // An Apple extension.
Note: See TracChangeset for help on using the changeset viewer.