Show
Ignore:
Timestamp:
08/06/08 13:29:36 (5 months ago)
Author:
mbensi
Message:

merge with webkit revision 35588

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/WebCore/css/CSSParser.cpp

    r424 r431  
    6666#include "Rect.h" 
    6767#include "ShadowValue.h" 
     68#include "WebKitCSSKeyframeRule.h" 
     69#include "WebKitCSSKeyframesRule.h" 
    6870#include "WebKitCSSTransformValue.h" 
    6971#include <kjs/dtoa.h> 
     
    230232    cssyyparse(this); 
    231233    return m_rule.release(); 
     234} 
     235 
     236PassRefPtr<CSSRule> CSSParser::parseKeyframeRule(CSSStyleSheet *sheet, const String &string) 
     237{ 
     238    m_styleSheet = sheet; 
     239    setupParser("@-webkit-keyframe-rule{ ", string, "} "); 
     240    cssyyparse(this); 
     241    return m_keyframe.release(); 
    232242} 
    233243 
     
    12951305        return false; 
    12961306    } 
     1307    case CSSPropertyWebkitAnimationDelay: 
     1308    case CSSPropertyWebkitAnimationDirection: 
     1309    case CSSPropertyWebkitAnimationDuration: 
     1310    case CSSPropertyWebkitAnimationName: 
     1311    case CSSPropertyWebkitAnimationPlayState: 
     1312    case CSSPropertyWebkitAnimationIterationCount: 
     1313    case CSSPropertyWebkitAnimationTimingFunction: 
     1314    case CSSPropertyWebkitTransitionDelay: 
    12971315    case CSSPropertyWebkitTransitionDuration: 
    1298     case CSSPropertyWebkitTransitionRepeatCount: 
    12991316    case CSSPropertyWebkitTransitionTimingFunction: 
    13001317    case CSSPropertyWebkitTransitionProperty: { 
    13011318        RefPtr<CSSValue> val; 
    1302         if (parseTransitionProperty(propId, val)) { 
     1319        if (parseAnimationProperty(propId, val)) { 
    13031320            addProperty(propId, val.release(), important); 
    13041321            return true; 
     
    15541571        return parseShorthand(propId, properties, 2, important); 
    15551572    } 
     1573    case CSSPropertyWebkitAnimation: 
     1574        return parseAnimationShorthand(important); 
    15561575    case CSSPropertyWebkitTransition: 
    15571576        return parseTransitionShorthand(important); 
     
    16911710} 
    16921711 
    1693 void CSSParser::addTransitionValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval) 
     1712void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval) 
    16941713{ 
    16951714    if (lval) { 
     
    17081727} 
    17091728 
    1710 bool CSSParser::parseTransitionShorthand(bool important) 
    1711 
    1712     const int properties[] = { CSSPropertyWebkitTransitionProperty, CSSPropertyWebkitTransitionDuration,  
    1713                                CSSPropertyWebkitTransitionTimingFunction, CSSPropertyWebkitTransitionRepeatCount }; 
     1729bool CSSParser::parseAnimationShorthand(bool important) 
     1730
     1731    const int properties[] = {  CSSPropertyWebkitAnimationName, 
     1732                                CSSPropertyWebkitAnimationDuration, 
     1733                                CSSPropertyWebkitAnimationTimingFunction, 
     1734                                CSSPropertyWebkitAnimationDelay, 
     1735                                CSSPropertyWebkitAnimationIterationCount, 
     1736                                CSSPropertyWebkitAnimationDirection }; 
    17141737    const int numProperties = sizeof(properties) / sizeof(properties[0]); 
    17151738     
    1716     ShorthandScope scope(this, CSSPropertyWebkitTransition); 
     1739    ShorthandScope scope(this, CSSPropertyWebkitAnimation); 
    17171740 
    17181741    bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary 
     
    17271750            for (i = 0; i < numProperties; ++i) { 
    17281751                if (!parsedProperty[i]) 
    1729                     addTransitionValue(values[i], CSSInitialValue::createImplicit()); 
     1752                    addAnimationValue(values[i], CSSInitialValue::createImplicit()); 
    17301753                parsedProperty[i] = false; 
    17311754            } 
     
    17381761            if (!parsedProperty[i]) { 
    17391762                RefPtr<CSSValue> val; 
    1740                 if (parseTransitionProperty(properties[i], val)) { 
     1763                if (parseAnimationProperty(properties[i], val)) { 
    17411764                    parsedProperty[i] = found = true; 
    1742                     addTransitionValue(values[i], val.release()); 
     1765                    addAnimationValue(values[i], val.release()); 
    17431766                } 
    17441767            } 
     
    17541777    for (i = 0; i < numProperties; ++i) { 
    17551778        if (!parsedProperty[i]) 
    1756             addTransitionValue(values[i], CSSInitialValue::createImplicit()); 
     1779            addAnimationValue(values[i], CSSInitialValue::createImplicit()); 
     1780    } 
     1781     
     1782    // Now add all of the properties we found. 
     1783    for (i = 0; i < numProperties; i++) 
     1784        addProperty(properties[i], values[i].release(), important); 
     1785     
     1786    return true; 
     1787
     1788 
     1789bool CSSParser::parseTransitionShorthand(bool important) 
     1790
     1791    const int properties[] = { CSSPropertyWebkitTransitionProperty, 
     1792                               CSSPropertyWebkitTransitionDuration, 
     1793                               CSSPropertyWebkitTransitionTimingFunction }; 
     1794    const int numProperties = sizeof(properties) / sizeof(properties[0]); 
     1795     
     1796    ShorthandScope scope(this, CSSPropertyWebkitTransition); 
     1797 
     1798    bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary 
     1799    RefPtr<CSSValue> values[numProperties]; 
     1800     
     1801    int i; 
     1802    while (m_valueList->current()) { 
     1803        CSSParserValue* val = m_valueList->current(); 
     1804        if (val->unit == CSSParserValue::Operator && val->iValue == ',') { 
     1805            // We hit the end.  Fill in all remaining values with the initial value. 
     1806            m_valueList->next(); 
     1807            for (i = 0; i < numProperties; ++i) { 
     1808                if (!parsedProperty[i]) 
     1809                    addAnimationValue(values[i], CSSInitialValue::createImplicit()); 
     1810                parsedProperty[i] = false; 
     1811            } 
     1812            if (!m_valueList->current()) 
     1813                break; 
     1814        } 
     1815         
     1816        bool found = false; 
     1817        for (i = 0; !found && i < numProperties; ++i) { 
     1818            if (!parsedProperty[i]) { 
     1819                RefPtr<CSSValue> val; 
     1820                if (parseAnimationProperty(properties[i], val)) { 
     1821                    parsedProperty[i] = found = true; 
     1822                    addAnimationValue(values[i], val.release()); 
     1823                } 
     1824            } 
     1825        } 
     1826 
     1827        // if we didn't find at least one match, this is an 
     1828        // invalid shorthand and we have to ignore it 
     1829        if (!found) 
     1830            return false; 
     1831    } 
     1832     
     1833    // Fill in any remaining properties with the initial value. 
     1834    for (i = 0; i < numProperties; ++i) { 
     1835        if (!parsedProperty[i]) 
     1836            addAnimationValue(values[i], CSSInitialValue::createImplicit()); 
    17571837    } 
    17581838     
     
    22072287} 
    22082288 
    2209 PassRefPtr<CSSValue> CSSParser::parseTransitionDuration() 
     2289PassRefPtr<CSSValue> CSSParser::parseAnimationDelay() 
    22102290{ 
    22112291    CSSParserValue* value = m_valueList->current(); 
     2292    if (value->id == CSSValueNow) 
     2293        return CSSPrimitiveValue::createIdentifier(value->id); 
    22122294    if (validUnit(value, FTime, m_strict)) 
    22132295        return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); 
     
    22152297} 
    22162298 
    2217 PassRefPtr<CSSValue> CSSParser::parseTransitionRepeatCount() 
     2299PassRefPtr<CSSValue> CSSParser::parseAnimationDirection() 
     2300
     2301    CSSParserValue* value = m_valueList->current(); 
     2302    if (value->id == CSSValueNormal || value->id == CSSValueAlternate) 
     2303        return CSSPrimitiveValue::createIdentifier(value->id); 
     2304    return 0; 
     2305
     2306 
     2307PassRefPtr<CSSValue> CSSParser::parseAnimationDuration() 
     2308
     2309    CSSParserValue* value = m_valueList->current(); 
     2310    if (validUnit(value, FTime|FNonNeg, m_strict)) 
     2311        return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); 
     2312    return 0; 
     2313
     2314 
     2315PassRefPtr<CSSValue> CSSParser::parseAnimationIterationCount() 
    22182316{ 
    22192317    CSSParserValue* value = m_valueList->current(); 
     
    22222320    if (validUnit(value, FInteger|FNonNeg, m_strict)) 
    22232321        return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); 
     2322    return 0; 
     2323} 
     2324 
     2325PassRefPtr<CSSValue> CSSParser::parseAnimationName() 
     2326{ 
     2327    CSSParserValue* value = m_valueList->current(); 
     2328    if (value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT) { 
     2329        if (value->id == CSSValueNone || (value->unit == CSSPrimitiveValue::CSS_STRING && equalIgnoringCase(value->string, "none"))) { 
     2330            return CSSPrimitiveValue::createIdentifier(CSSValueNone); 
     2331        } else { 
     2332            return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_STRING); 
     2333        } 
     2334    } 
     2335    return 0; 
     2336} 
     2337 
     2338PassRefPtr<CSSValue> CSSParser::parseAnimationPlayState() 
     2339{ 
     2340    CSSParserValue* value = m_valueList->current(); 
     2341    if (value->id == CSSValueRunning || value->id == CSSValuePaused) 
     2342        return CSSPrimitiveValue::createIdentifier(value->id); 
     2343    return 0; 
     2344} 
     2345 
     2346PassRefPtr<CSSValue> CSSParser::parseAnimationProperty() 
     2347{ 
     2348    CSSParserValue* value = m_valueList->current(); 
     2349    if (value->unit != CSSPrimitiveValue::CSS_IDENT) 
     2350        return 0; 
     2351    int result = cssPropertyID(value->string); 
     2352    if (result) 
     2353        return CSSPrimitiveValue::createIdentifier(result); 
     2354    if (equalIgnoringCase(value->string, "all")) 
     2355        return CSSPrimitiveValue::createIdentifier(cAnimateAll); // FIXME: Why not use CSSValueAll instead? 
     2356    if (equalIgnoringCase(value->string, "none")) 
     2357        return CSSPrimitiveValue::createIdentifier(cAnimateNone); // FIXME: Why not use CSSValueNone instead? 
    22242358    return 0; 
    22252359} 
     
    22432377} 
    22442378 
    2245 PassRefPtr<CSSValue> CSSParser::parseTransitionTimingFunction() 
     2379PassRefPtr<CSSValue> CSSParser::parseAnimationTimingFunction() 
    22462380{ 
    22472381    CSSParserValue* value = m_valueList->current(); 
     
    22732407} 
    22742408 
    2275 PassRefPtr<CSSValue> CSSParser::parseTransitionProperty() 
    2276 
    2277     CSSParserValue* value = m_valueList->current(); 
    2278     if (value->unit != CSSPrimitiveValue::CSS_IDENT) 
    2279         return 0; 
    2280     int result = cssPropertyID(value->string); 
    2281     if (result) 
    2282         return CSSPrimitiveValue::createIdentifier(result); 
    2283     if (equalIgnoringCase(value->string, "all")) 
    2284         return CSSPrimitiveValue::createIdentifier(cAnimateAll); // FIXME: Why not use CSSValueAll instead? 
    2285     if (equalIgnoringCase(value->string, "none")) 
    2286         return CSSPrimitiveValue::createIdentifier(cAnimateNone); // FIXME: Why not use CSSValueNone instead? 
    2287     return 0; 
    2288 
    2289  
    2290 bool CSSParser::parseTransitionProperty(int propId, RefPtr<CSSValue>& result) 
     2409bool CSSParser::parseAnimationProperty(int propId, RefPtr<CSSValue>& result) 
    22912410{ 
    22922411    RefPtr<CSSValueList> values; 
     
    23072426        else { 
    23082427            switch (propId) { 
    2309                 case CSSPropertyWebkitTransitionDuration: 
    2310                     currValue = parseTransitionDuration(); 
     2428                case CSSPropertyWebkitAnimationDelay: 
     2429                case CSSPropertyWebkitTransitionDelay: 
     2430                    currValue = parseAnimationDelay(); 
    23112431                    if (currValue) 
    23122432                        m_valueList->next(); 
    23132433                    break; 
    2314                 case CSSPropertyWebkitTransitionRepeatCount
    2315                     currValue = parseTransitionRepeatCount(); 
     2434                case CSSPropertyWebkitAnimationDirection
     2435                    currValue = parseAnimationDirection(); 
    23162436                    if (currValue) 
    23172437                        m_valueList->next(); 
    23182438                    break; 
    2319                 case CSSPropertyWebkitTransitionTimingFunction: 
    2320                     currValue = parseTransitionTimingFunction(); 
     2439                case CSSPropertyWebkitAnimationDuration: 
     2440                case CSSPropertyWebkitTransitionDuration: 
     2441                    currValue = parseAnimationDuration(); 
     2442                    if (currValue) 
     2443                        m_valueList->next(); 
     2444                    break; 
     2445                case CSSPropertyWebkitAnimationIterationCount: 
     2446                    currValue = parseAnimationIterationCount(); 
     2447                    if (currValue) 
     2448                        m_valueList->next(); 
     2449                    break; 
     2450                case CSSPropertyWebkitAnimationName: 
     2451                    currValue = parseAnimationName(); 
     2452                    if (currValue) 
     2453                        m_valueList->next(); 
     2454                    break; 
     2455                case CSSPropertyWebkitAnimationPlayState: 
     2456                    currValue = parseAnimationPlayState(); 
    23212457                    if (currValue) 
    23222458                        m_valueList->next(); 
    23232459                    break; 
    23242460                case CSSPropertyWebkitTransitionProperty: 
    2325                     currValue = parseTransitionProperty(); 
     2461                    currValue = parseAnimationProperty(); 
     2462                    if (currValue) 
     2463                        m_valueList->next(); 
     2464                    break; 
     2465                case CSSPropertyWebkitAnimationTimingFunction: 
     2466                case CSSPropertyWebkitTransitionTimingFunction: 
     2467                    currValue = parseAnimationTimingFunction(); 
    23262468                    if (currValue) 
    23272469                        m_valueList->next(); 
     
    23612503    return false; 
    23622504} 
     2505 
     2506 
    23632507 
    23642508#if ENABLE(DASHBOARD_SUPPORT) 
     
    39084052    // The transform is a list of functional primitives that specify transform operations. 
    39094053    // We collect a list of WebKitCSSTransformValues, where each value specifies a single operation. 
    3910     RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 
     4054    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 
    39114055    for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) { 
    39124056        if (value->unit != CSSParserValue::Function || !value->function) 
     
    40424186    case CHARSET_SYM: 
    40434187    case NAMESPACE_SYM: 
     4188    case WEBKIT_KEYFRAMES_SYM: 
    40444189 
    40454190    case IMPORTANT_SYM: 
     
    43834528} 
    43844529 
     4530WebKitCSSKeyframesRule* CSSParser::createKeyframesRule() 
     4531{ 
     4532    RefPtr<WebKitCSSKeyframesRule> rule = WebKitCSSKeyframesRule::create(m_styleSheet); 
     4533    WebKitCSSKeyframesRule* rulePtr = rule.get(); 
     4534    m_parsedStyleObjects.append(rule.release()); 
     4535    return rulePtr; 
     4536} 
     4537 
    43854538CSSRule* CSSParser::createStyleRule(CSSSelector* selector) 
    43864539{ 
     
    45304683 
    45314684    m_numParsedProperties -= deletedProperties; 
     4685} 
     4686 
     4687WebKitCSSKeyframeRule* CSSParser::createKeyframeRule(float key) 
     4688{ 
     4689    RefPtr<WebKitCSSKeyframeRule> keyframe = WebKitCSSKeyframeRule::create(m_styleSheet); 
     4690 
     4691    keyframe->setKey(key); 
     4692    keyframe->setDeclaration(CSSMutableStyleDeclaration::create(0, m_parsedProperties, m_numParsedProperties)); 
     4693    clearProperties(); 
     4694 
     4695    WebKitCSSKeyframeRule* keyframePtr = keyframe.get(); 
     4696    m_parsedStyleObjects.append(keyframe.release()); 
     4697    return keyframePtr; 
    45324698} 
    45334699