Changeset 431 for trunk/WebCore/css/CSSParser.cpp
- Timestamp:
- 08/06/08 13:29:36 (5 months ago)
- Files:
-
- trunk/WebCore/css/CSSParser.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/WebCore/css/CSSParser.cpp
r424 r431 66 66 #include "Rect.h" 67 67 #include "ShadowValue.h" 68 #include "WebKitCSSKeyframeRule.h" 69 #include "WebKitCSSKeyframesRule.h" 68 70 #include "WebKitCSSTransformValue.h" 69 71 #include <kjs/dtoa.h> … … 230 232 cssyyparse(this); 231 233 return m_rule.release(); 234 } 235 236 PassRefPtr<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(); 232 242 } 233 243 … … 1295 1305 return false; 1296 1306 } 1307 case CSSPropertyWebkitAnimationDelay: 1308 case CSSPropertyWebkitAnimationDirection: 1309 case CSSPropertyWebkitAnimationDuration: 1310 case CSSPropertyWebkitAnimationName: 1311 case CSSPropertyWebkitAnimationPlayState: 1312 case CSSPropertyWebkitAnimationIterationCount: 1313 case CSSPropertyWebkitAnimationTimingFunction: 1314 case CSSPropertyWebkitTransitionDelay: 1297 1315 case CSSPropertyWebkitTransitionDuration: 1298 case CSSPropertyWebkitTransitionRepeatCount:1299 1316 case CSSPropertyWebkitTransitionTimingFunction: 1300 1317 case CSSPropertyWebkitTransitionProperty: { 1301 1318 RefPtr<CSSValue> val; 1302 if (parse TransitionProperty(propId, val)) {1319 if (parseAnimationProperty(propId, val)) { 1303 1320 addProperty(propId, val.release(), important); 1304 1321 return true; … … 1554 1571 return parseShorthand(propId, properties, 2, important); 1555 1572 } 1573 case CSSPropertyWebkitAnimation: 1574 return parseAnimationShorthand(important); 1556 1575 case CSSPropertyWebkitTransition: 1557 1576 return parseTransitionShorthand(important); … … 1691 1710 } 1692 1711 1693 void CSSParser::add TransitionValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)1712 void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval) 1694 1713 { 1695 1714 if (lval) { … … 1708 1727 } 1709 1728 1710 bool CSSParser::parseTransitionShorthand(bool important) 1711 { 1712 const int properties[] = { CSSPropertyWebkitTransitionProperty, CSSPropertyWebkitTransitionDuration, 1713 CSSPropertyWebkitTransitionTimingFunction, CSSPropertyWebkitTransitionRepeatCount }; 1729 bool CSSParser::parseAnimationShorthand(bool important) 1730 { 1731 const int properties[] = { CSSPropertyWebkitAnimationName, 1732 CSSPropertyWebkitAnimationDuration, 1733 CSSPropertyWebkitAnimationTimingFunction, 1734 CSSPropertyWebkitAnimationDelay, 1735 CSSPropertyWebkitAnimationIterationCount, 1736 CSSPropertyWebkitAnimationDirection }; 1714 1737 const int numProperties = sizeof(properties) / sizeof(properties[0]); 1715 1738 1716 ShorthandScope scope(this, CSSPropertyWebkit Transition);1739 ShorthandScope scope(this, CSSPropertyWebkitAnimation); 1717 1740 1718 1741 bool parsedProperty[numProperties] = { false }; // compiler will repeat false as necessary … … 1727 1750 for (i = 0; i < numProperties; ++i) { 1728 1751 if (!parsedProperty[i]) 1729 add TransitionValue(values[i], CSSInitialValue::createImplicit());1752 addAnimationValue(values[i], CSSInitialValue::createImplicit()); 1730 1753 parsedProperty[i] = false; 1731 1754 } … … 1738 1761 if (!parsedProperty[i]) { 1739 1762 RefPtr<CSSValue> val; 1740 if (parse TransitionProperty(properties[i], val)) {1763 if (parseAnimationProperty(properties[i], val)) { 1741 1764 parsedProperty[i] = found = true; 1742 add TransitionValue(values[i], val.release());1765 addAnimationValue(values[i], val.release()); 1743 1766 } 1744 1767 } … … 1754 1777 for (i = 0; i < numProperties; ++i) { 1755 1778 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 1789 bool 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()); 1757 1837 } 1758 1838 … … 2207 2287 } 2208 2288 2209 PassRefPtr<CSSValue> CSSParser::parse TransitionDuration()2289 PassRefPtr<CSSValue> CSSParser::parseAnimationDelay() 2210 2290 { 2211 2291 CSSParserValue* value = m_valueList->current(); 2292 if (value->id == CSSValueNow) 2293 return CSSPrimitiveValue::createIdentifier(value->id); 2212 2294 if (validUnit(value, FTime, m_strict)) 2213 2295 return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); … … 2215 2297 } 2216 2298 2217 PassRefPtr<CSSValue> CSSParser::parseTransitionRepeatCount() 2299 PassRefPtr<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 2307 PassRefPtr<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 2315 PassRefPtr<CSSValue> CSSParser::parseAnimationIterationCount() 2218 2316 { 2219 2317 CSSParserValue* value = m_valueList->current(); … … 2222 2320 if (validUnit(value, FInteger|FNonNeg, m_strict)) 2223 2321 return CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes)value->unit); 2322 return 0; 2323 } 2324 2325 PassRefPtr<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 2338 PassRefPtr<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 2346 PassRefPtr<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? 2224 2358 return 0; 2225 2359 } … … 2243 2377 } 2244 2378 2245 PassRefPtr<CSSValue> CSSParser::parse TransitionTimingFunction()2379 PassRefPtr<CSSValue> CSSParser::parseAnimationTimingFunction() 2246 2380 { 2247 2381 CSSParserValue* value = m_valueList->current(); … … 2273 2407 } 2274 2408 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) 2409 bool CSSParser::parseAnimationProperty(int propId, RefPtr<CSSValue>& result) 2291 2410 { 2292 2411 RefPtr<CSSValueList> values; … … 2307 2426 else { 2308 2427 switch (propId) { 2309 case CSSPropertyWebkitTransitionDuration: 2310 currValue = parseTransitionDuration(); 2428 case CSSPropertyWebkitAnimationDelay: 2429 case CSSPropertyWebkitTransitionDelay: 2430 currValue = parseAnimationDelay(); 2311 2431 if (currValue) 2312 2432 m_valueList->next(); 2313 2433 break; 2314 case CSSPropertyWebkit TransitionRepeatCount:2315 currValue = parse TransitionRepeatCount();2434 case CSSPropertyWebkitAnimationDirection: 2435 currValue = parseAnimationDirection(); 2316 2436 if (currValue) 2317 2437 m_valueList->next(); 2318 2438 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(); 2321 2457 if (currValue) 2322 2458 m_valueList->next(); 2323 2459 break; 2324 2460 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(); 2326 2468 if (currValue) 2327 2469 m_valueList->next(); … … 2361 2503 return false; 2362 2504 } 2505 2506 2363 2507 2364 2508 #if ENABLE(DASHBOARD_SUPPORT) … … 3908 4052 // The transform is a list of functional primitives that specify transform operations. 3909 4053 // We collect a list of WebKitCSSTransformValues, where each value specifies a single operation. 3910 RefPtr<CSSValueList> list = CSSValueList::create CommaSeparated();4054 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 3911 4055 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) { 3912 4056 if (value->unit != CSSParserValue::Function || !value->function) … … 4042 4186 case CHARSET_SYM: 4043 4187 case NAMESPACE_SYM: 4188 case WEBKIT_KEYFRAMES_SYM: 4044 4189 4045 4190 case IMPORTANT_SYM: … … 4383 4528 } 4384 4529 4530 WebKitCSSKeyframesRule* 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 4385 4538 CSSRule* CSSParser::createStyleRule(CSSSelector* selector) 4386 4539 { … … 4530 4683 4531 4684 m_numParsedProperties -= deletedProperties; 4685 } 4686 4687 WebKitCSSKeyframeRule* 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; 4532 4698 } 4533 4699
