Changeset 36347 in webkit


Ignore:
Timestamp:
Sep 11, 2008 5:36:31 PM (16 years ago)
Author:
dino@apple.com
Message:

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

Reviewed by Dave Hyatt

Need to support comma separated list of key times in keyframes selectors
https://bugs.webkit.org/show_bug.cgi?id=20680

Test: animations/keyframes-comma-separated.html

  • css/CSSGrammar.y:
  • css/CSSParser.cpp: (WebCore::CSSParser::createKeyframeRule):
  • css/CSSParser.h:
  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::addKeyframeStyle):
  • css/WebKitCSSKeyframeRule.cpp: (WebCore::WebKitCSSKeyframeRule::WebKitCSSKeyframeRule): (WebCore::WebKitCSSKeyframeRule::cssText): (WebCore::WebKitCSSKeyframeRule::parseKeyString):
  • css/WebKitCSSKeyframeRule.h: (WebCore::WebKitCSSKeyframeRule::keyText): (WebCore::WebKitCSSKeyframeRule::setKeyText): (WebCore::WebKitCSSKeyframeRule::getKeys):
  • css/WebKitCSSKeyframesRule.cpp: (WebCore::WebKitCSSKeyframesRule::append): (WebCore::WebKitCSSKeyframesRule::insertRule): (WebCore::WebKitCSSKeyframesRule::deleteRule): (WebCore::WebKitCSSKeyframesRule::findRule): (WebCore::WebKitCSSKeyframesRule::findRuleIndex):
  • css/WebKitCSSKeyframesRule.h:
  • page/animation/AnimationBase.cpp: (WebCore::AnimationBase::blendProperties):
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r36343 r36347  
     12008-09-08  Chris Marrin  <cmarrin@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        Need to support comma separated list of key times in keyframes selectors
     6        https://bugs.webkit.org/show_bug.cgi?id=20680
     7
     8        * animations/keyframes-comma-separated-expected.txt: Added.
     9        * animations/keyframes-comma-separated.html: Added.
     10
    1112008-09-11  Kevin McCullough  <kmccullough@apple.com>
    212
  • trunk/WebCore/ChangeLog

    r36343 r36347  
     12008-09-08  Chris Marrin  <cmarrin@apple.com>
     2
     3        Reviewed by Dave Hyatt
     4
     5        Need to support comma separated list of key times in keyframes selectors
     6        https://bugs.webkit.org/show_bug.cgi?id=20680
     7
     8        Test: animations/keyframes-comma-separated.html
     9
     10        * css/CSSGrammar.y:
     11        * css/CSSParser.cpp:
     12        (WebCore::CSSParser::createKeyframeRule):
     13        * css/CSSParser.h:
     14        * css/CSSStyleSelector.cpp:
     15        (WebCore::CSSStyleSelector::addKeyframeStyle):
     16        * css/WebKitCSSKeyframeRule.cpp:
     17        (WebCore::WebKitCSSKeyframeRule::WebKitCSSKeyframeRule):
     18        (WebCore::WebKitCSSKeyframeRule::cssText):
     19        (WebCore::WebKitCSSKeyframeRule::parseKeyString):
     20        * css/WebKitCSSKeyframeRule.h:
     21        (WebCore::WebKitCSSKeyframeRule::keyText):
     22        (WebCore::WebKitCSSKeyframeRule::setKeyText):
     23        (WebCore::WebKitCSSKeyframeRule::getKeys):
     24        * css/WebKitCSSKeyframesRule.cpp:
     25        (WebCore::WebKitCSSKeyframesRule::append):
     26        (WebCore::WebKitCSSKeyframesRule::insertRule):
     27        (WebCore::WebKitCSSKeyframesRule::deleteRule):
     28        (WebCore::WebKitCSSKeyframesRule::findRule):
     29        (WebCore::WebKitCSSKeyframesRule::findRuleIndex):
     30        * css/WebKitCSSKeyframesRule.h:
     31        * page/animation/AnimationBase.cpp:
     32        (WebCore::AnimationBase::blendProperties):
     33
    1342008-09-11  Kevin McCullough  <kmccullough@apple.com>
    235
  • trunk/WebCore/css/CSSGrammar.y

    r36278 r36347  
    217217%type <keyframeRule> keyframe_rule
    218218%type <keyframesRule> keyframes_rule
    219 %type <val> key
     219%type <valueList> key_list
     220%type <value> key
    220221
    221222%type <integer> property
     
    698699        $$ = $1;
    699700        if ($2)
    700             $$->insert($2);
     701            $$->append($2);
    701702    }
    702703    ;
    703704
    704705keyframe_rule:
    705     key maybe_space '{' maybe_space declaration_list '}' {
     706    key_list maybe_space '{' maybe_space declaration_list '}' {
    706707        $$ = static_cast<CSSParser*>(parser)->createKeyframeRule($1);
    707708    }
    708709    ;
    709710
     711key_list:
     712    key {
     713        CSSParser* p = static_cast<CSSParser*>(parser);
     714        $$ = p->createFloatingValueList();
     715        $$->addValue(p->sinkFloatingValue($1));
     716    }
     717    | key_list maybe_space ',' maybe_space key {
     718        CSSParser* p = static_cast<CSSParser*>(parser);
     719        $$ = $1;
     720        if ($$)
     721            $$->addValue(p->sinkFloatingValue($5));
     722    }
     723    ;
     724
    710725key:
    711     PERCENTAGE { $$ = (float) $1; }
     726    PERCENTAGE { $$.id = 0; $$.isInt = false; $$.fValue = $1; $$.unit = CSSPrimitiveValue::CSS_NUMBER; }
    712727    | IDENT {
    713         $$ = -1;
     728        $$.id = 0; $$.isInt = false; $$.unit = CSSPrimitiveValue::CSS_NUMBER;
    714729        CSSParserString& str = $1;
    715730        if (equalIgnoringCase(static_cast<const String&>(str), "from"))
    716             $$ = 0;
     731            $$.fValue = 0;
    717732        else if (equalIgnoringCase(static_cast<const String&>(str), "to"))
    718             $$ = 100;
     733            $$.fValue = 100;
    719734        else
    720735            YYERROR;
  • trunk/WebCore/css/CSSParser.cpp

    r36046 r36347  
    46864686}
    46874687
    4688 WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(float key)
    4689 {
     4688WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(CSSParserValueList* keys)
     4689{
     4690    // Create a key string from the passed keys
     4691    String keyString;
     4692    for (unsigned i = 0; i < keys->size(); ++i) {
     4693        float key = (float) keys->valueAt(i)->fValue;
     4694        if (i != 0)
     4695            keyString += ",";
     4696        keyString += String::number(key);
     4697        keyString += "%";
     4698    }
     4699   
    46904700    RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(m_styleSheet);
    4691 
    4692     keyframe->setKey(key);
     4701    keyframe->setKeyText(keyString);
    46934702    keyframe->setDeclaration(CSSMutableStyleDeclaration::create(0, m_parsedProperties, m_numParsedProperties));
     4703   
    46944704    clearProperties();
    46954705
  • trunk/WebCore/css/CSSParser.h

    r35910 r36347  
    166166        CSSRule* createCharsetRule(const CSSParserString&);
    167167        CSSRule* createImportRule(const CSSParserString&, MediaList*);
    168         WebKitCSSKeyframeRule* createKeyframeRule(float key);
     168        WebKitCSSKeyframeRule* createKeyframeRule(CSSParserValueList*);
    169169        WebKitCSSKeyframesRule* createKeyframesRule();
    170170        CSSRule* createMediaRule(MediaList*, CSSRuleList*);
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r36339 r36347  
    440440void CSSStyleSelector::addKeyframeStyle(Document* doc, const WebKitCSSKeyframesRule* rule)
    441441{
     442    // Create the keyframe list
    442443    AtomicString s(rule->name());
    443444    RefPtr<KeyframeList> list;
     
    450451    list->clear();
    451452
    452     // Make sure there is a 0% and a 100% keyframe
    453     if (rule->item(0)->key() || rule->item(rule->length() - 1)->key() != 1)
    454         return;
    455        
     453    // Add all the keyframes
    456454    for (unsigned i = 0; i < rule->length(); ++i) {
    457455        const WebKitCSSKeyframeRule* kf = rule->item(i);
     
    460458        CSSMutableStyleDeclaration* decl = kf->style();
    461459        DeprecatedValueListConstIterator<CSSProperty> end;
     460
     461        // Record all the properties in this keyframe
    462462        for (DeprecatedValueListConstIterator<CSSProperty> it = decl->valuesIterator(); it != end; ++it) {
    463463            const CSSProperty& current = *it;
     
    465465            list->addProperty(current.id());
    466466        }
    467         list->insert(kf->key(), *m_style);
     467
     468        // Add this keyframe to all the indicated key times
     469        Vector<float> keys;
     470        kf->getKeys(keys);
     471
     472        for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
     473            float key = keys[keyIndex];
     474            list->insert(key, *m_style);
     475        }
     476
    468477        m_style->deref(doc->renderArena());
    469478        m_style = 0;
     479    }
     480
     481    // Make sure there is a 0% and a 100% keyframe
     482    float first = list->beginKeyframes()->key;
     483    float last = (list->endKeyframes()-1)->key;
     484    if (first != 0 || last != 1) {
     485        list->clear();
     486        return;
    470487    }
    471488}
  • trunk/WebCore/css/WebKitCSSKeyframeRule.cpp

    r35580 r36347  
    3333WebKitCSSKeyframeRule::WebKitCSSKeyframeRule(CSSStyleSheet* parent)
    3434    : CSSRule(parent)
    35     , m_key(0)
    3635{
    3736}
     
    4342}
    4443
    45 String WebKitCSSKeyframeRule::keyText() const
    46 {
    47     return String::number(m_key) + "%";
    48 }
    49 
    50 void WebKitCSSKeyframeRule::setKeyText(const String& s)
    51 {
    52     m_key = keyStringToFloat(s);
    53 }
    54 
    5544String WebKitCSSKeyframeRule::cssText() const
    5645{
    57     String result = String::number(m_key);
     46    String result = m_key;
    5847
    59     result += "% { ";
     48    result += " { ";
    6049    result += m_style->cssText();
    6150    result += "}";
     
    7766
    7867/* static */
    79 float WebKitCSSKeyframeRule::keyStringToFloat(const String& s)
     68void WebKitCSSKeyframeRule::parseKeyString(const String& s, Vector<float>& keys)
    8069{
    81     float key = 0;
     70    keys.clear();
     71    Vector<String> strings;
     72    s.split(',', strings);
    8273   
    83     // for now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a legal floating point number
    84     if (s == "from")
    85         key = 0;
    86     else if (s == "to")
    87         key = 100;
    88     else {
    89         if (s.endsWith("%")) {
    90             float k = s.substring(0, s.length() - 1).toFloat();
     74    for (size_t i = 0; i < strings.size(); ++i) {
     75        float key = -1;
     76        String cur = strings[i].stripWhiteSpace();
     77   
     78        // For now the syntax MUST be 'xxx%' or 'from' or 'to', where xxx is a legal floating point number
     79        if (cur == "from")
     80            key = 0;
     81        else if (cur == "to")
     82            key = 1;
     83        else if (cur.endsWith("%")) {
     84            float k = cur.substring(0, cur.length() - 1).toFloat();
    9185            if (k >= 0 && k <= 100)
    92                 key = k;
     86                key = k/100;
    9387        }
     88       
     89        if (key < 0) {
     90            keys.clear();
     91            return;
     92        }
     93        else
     94            keys.append(key);
    9495    }
    95    
    96     return key;
    9796}
    9897
  • trunk/WebCore/css/WebKitCSSKeyframeRule.h

    r35580 r36347  
    5555    virtual unsigned short type() const { return WEBKIT_KEYFRAME_RULE; }
    5656
    57     String keyText() const;
    58     void setKeyText(const String& s);
     57    String keyText() const              { return m_key; }
     58    void setKeyText(const String& s)    { m_key = s; }
     59   
     60    void getKeys(Vector<float>& keys) const   { parseKeyString(m_key, keys); }
    5961
    6062    CSSMutableStyleDeclaration* style() const { return m_style.get(); }
     
    6567    virtual bool parseString(const String&, bool = false);
    6668   
    67     float key() const { return m_key/100; }
    68     float keyAsPercent() const { return m_key; }
    69 
    70     void setKey(float k) { m_key = k; }
    7169    void setDeclaration(PassRefPtr<CSSMutableStyleDeclaration>);
    7270
     
    7472    const CSSMutableStyleDeclaration*   declaration() const { return m_style.get(); }
    7573   
    76     static float keyStringToFloat(const String& s);
    77  
    7874private:
     75    static void parseKeyString(const String& s, Vector<float>& keys);
     76   
    7977    WebKitCSSKeyframeRule(CSSStyleSheet* parent);
    8078
    8179    RefPtr<CSSMutableStyleDeclaration> m_style;
    82     float m_key;        // 0 to 100
     80    String m_key;        // comma separated list of keys
    8381};
    8482
  • trunk/WebCore/css/WebKitCSSKeyframesRule.cpp

    r35580 r36347  
    8282}
    8383
    84 void WebKitCSSKeyframesRule::insert(WebKitCSSKeyframeRule* rule)
     84void WebKitCSSKeyframesRule::append(WebKitCSSKeyframeRule* rule)
    8585{
    86     float key = rule->keyAsPercent();
    87 
    88     for (unsigned i = 0; i < length(); ++i) {
    89         if (item(i)->keyAsPercent() == key) {
    90             m_lstCSSRules.get()->deleteRule(i);
    91             m_lstCSSRules.get()->insertRule(rule, i);
    92             return;
    93         }
    94         if (item(i)->keyAsPercent() > key) {
    95             // insert before
    96             m_lstCSSRules.get()->insertRule(rule, i);
    97             return;
    98         }
    99     }
    100    
    101     // append
    10286    m_lstCSSRules.get()->append(rule);
    10387    stylesheet()->styleSheetChanged();
     
    10993    RefPtr<CSSRule> newRule = p.parseKeyframeRule(parentStyleSheet(), rule);
    11094    if (newRule.get() && newRule.get()->isKeyframeRule())
    111         insert(static_cast<WebKitCSSKeyframeRule*>(newRule.get()));
     95        append(static_cast<WebKitCSSKeyframeRule*>(newRule.get()));
    11296}
    11397
    11498void WebKitCSSKeyframesRule::deleteRule(const String& s)
    11599{
    116     float key = WebKitCSSKeyframeRule::keyStringToFloat(s);
    117     int i = findRuleIndex(key);
     100    int i = findRuleIndex(s);
    118101    if (i >= 0) {
    119102        m_lstCSSRules.get()->deleteRule(i);
     
    124107WebKitCSSKeyframeRule* WebKitCSSKeyframesRule::findRule(const String& s)
    125108{
    126     float key = WebKitCSSKeyframeRule::keyStringToFloat(s);
    127     int i = findRuleIndex(key);
     109    int i = findRuleIndex(s);
    128110    return (i >= 0) ? item(i) : 0;
    129111}
    130112
    131 int WebKitCSSKeyframesRule::findRuleIndex(float key) const
     113int WebKitCSSKeyframesRule::findRuleIndex(const String& key) const
    132114{
    133115    for (unsigned i = 0; i < length(); ++i) {
    134         if (item(i)->keyAsPercent() == key)
     116        if (item(i)->keyText() == key)
    135117            return i;
    136118    }
  • trunk/WebCore/css/WebKitCSSKeyframesRule.h

    r35580 r36347  
    7373    WebKitCSSKeyframeRule*        item(unsigned index);
    7474    const WebKitCSSKeyframeRule*  item(unsigned index) const;
    75     void insert(WebKitCSSKeyframeRule* rule);
     75    void append(WebKitCSSKeyframeRule* rule);
    7676
    7777private:
    7878    WebKitCSSKeyframesRule(CSSStyleSheet* parent);
    7979
    80     int findRuleIndex(float key) const;
     80    int findRuleIndex(const String& key) const;
    8181   
    8282    RefPtr<CSSRuleList> m_lstCSSRules;
  • trunk/WebCore/page/animation/AnimationBase.cpp

    r36322 r36347  
    419419    ASSERT(prop != cAnimateAll);
    420420    // FIXME: Why can this happen?
     421   
     422    ensurePropertyMap();
    421423    if (prop == cAnimateAll) {
    422424        bool needsTimer = false;
Note: See TracChangeset for help on using the changeset viewer.