Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: Source/core/css/CSSParser-in.cpp

Issue 19037003: Re-use CSSParser logic to parse keyframe keys (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 391 }
392 392
393 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet , const String& string) 393 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet , const String& string)
394 { 394 {
395 setStyleSheet(sheet); 395 setStyleSheet(sheet);
396 setupParser("@-internal-keyframe-rule ", string, ""); 396 setupParser("@-internal-keyframe-rule ", string, "");
397 cssyyparse(this); 397 cssyyparse(this);
398 return m_keyframe.release(); 398 return m_keyframe.release();
399 } 399 }
400 400
401 PassOwnPtr<Vector<double> > CSSParser::parseKeyframeKeyList(const String& string )
402 {
403 setupParser("@-internal-keyframe-key-list ", string, "");
404 cssyyparse(this);
405 ASSERT(m_valueList);
406 return StyleKeyframe::createKeyList(m_valueList.get());
407 }
408
401 bool CSSParser::parseSupportsCondition(const String& string) 409 bool CSSParser::parseSupportsCondition(const String& string)
402 { 410 {
403 m_supportsCondition = false; 411 m_supportsCondition = false;
404 setupParser("@-internal-supports-condition ", string, ""); 412 setupParser("@-internal-supports-condition ", string, "");
405 cssyyparse(this); 413 cssyyparse(this);
406 return m_supportsCondition; 414 return m_supportsCondition;
407 } 415 }
408 416
409 static inline bool isColorPropertyID(CSSPropertyID propertyId) 417 static inline bool isColorPropertyID(CSSPropertyID propertyId)
410 { 418 {
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 1354
1347 PassRefPtr<MediaQuerySet> CSSParser::parseMediaQueryList(const String& string) 1355 PassRefPtr<MediaQuerySet> CSSParser::parseMediaQueryList(const String& string)
1348 { 1356 {
1349 ASSERT(!m_mediaList); 1357 ASSERT(!m_mediaList);
1350 1358
1351 // can't use { because tokenizer state switches from mediaquery to initial s tate when it sees { token. 1359 // can't use { because tokenizer state switches from mediaquery to initial s tate when it sees { token.
1352 // instead insert one " " (which is caught by maybe_space in CSSGrammar.y) 1360 // instead insert one " " (which is caught by maybe_space in CSSGrammar.y)
1353 setupParser("@-internal-medialist ", string, ""); 1361 setupParser("@-internal-medialist ", string, "");
1354 cssyyparse(this); 1362 cssyyparse(this);
1355 1363
1356 ASSERT(m_mediaList.get()); 1364 ASSERT(m_mediaList);
1357 return m_mediaList.release(); 1365 return m_mediaList.release();
1358 } 1366 }
1359 1367
1360 static inline void filterProperties(bool important, const CSSParser::ParsedPrope rtyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitAr ray<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenVariables) 1368 static inline void filterProperties(bool important, const CSSParser::ParsedPrope rtyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitAr ray<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenVariables)
1361 { 1369 {
1362 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found. 1370 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
1363 for (int i = input.size() - 1; i >= 0; --i) { 1371 for (int i = input.size() - 1; i >= 0; --i) {
1364 const CSSProperty& property = input[i]; 1372 const CSSProperty& property = input[i];
1365 if (property.isImportant() != important) 1373 if (property.isImportant() != important)
1366 continue; 1374 continue;
(...skipping 9019 matching lines...) Expand 10 before | Expand all | Expand 10 after
10386 m_token = INTERNAL_SELECTOR_SYM; 10394 m_token = INTERNAL_SELECTOR_SYM;
10387 } 10395 }
10388 CASE("-internal-medialist") { 10396 CASE("-internal-medialist") {
10389 m_parsingMode = MediaQueryMode; 10397 m_parsingMode = MediaQueryMode;
10390 m_token = INTERNAL_MEDIALIST_SYM; 10398 m_token = INTERNAL_MEDIALIST_SYM;
10391 } 10399 }
10392 CASE("-internal-keyframe-rule") { 10400 CASE("-internal-keyframe-rule") {
10393 if (LIKELY(!hasEscape)) 10401 if (LIKELY(!hasEscape))
10394 m_token = INTERNAL_KEYFRAME_RULE_SYM; 10402 m_token = INTERNAL_KEYFRAME_RULE_SYM;
10395 } 10403 }
10404 CASE("-internal-keyframe-key-list") {
10405 m_token = INTERNAL_KEYFRAME_KEY_LIST_SYM;
10406 }
10396 CASE("-internal-supports-condition") { 10407 CASE("-internal-supports-condition") {
10397 m_parsingMode = SupportsMode; 10408 m_parsingMode = SupportsMode;
10398 m_token = INTERNAL_SUPPORTS_CONDITION_SYM; 10409 m_token = INTERNAL_SUPPORTS_CONDITION_SYM;
10399 } 10410 }
10400 } 10411 }
10401 } 10412 }
10402 10413
10403 template <typename CharacterType> 10414 template <typename CharacterType>
10404 inline void CSSParser::detectSupportsToken(int length) 10415 inline void CSSParser::detectSupportsToken(int length)
10405 { 10416 {
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
11530 if (property.id() == CSSPropertyFontVariant && property.value()->isValue List()) { 11541 if (property.id() == CSSPropertyFontVariant && property.value()->isValue List()) {
11531 m_parsedProperties.remove(i); 11542 m_parsedProperties.remove(i);
11532 continue; 11543 continue;
11533 } 11544 }
11534 ++i; 11545 ++i;
11535 } 11546 }
11536 } 11547 }
11537 11548
11538 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys) 11549 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys)
11539 { 11550 {
11540 // Create a key string from the passed keys 11551 OwnPtr<Vector<double> > keyVector = StyleKeyframe::createKeyList(keys);
11541 StringBuilder keyString; 11552 if (keyVector->isEmpty())
11542 for (unsigned i = 0; i < keys->size(); ++i) { 11553 return 0;
11543 ASSERT(keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER);
11544 double key = keys->valueAt(i)->fValue;
11545 if (key < 0 || key > 100) {
11546 // As per http://www.w3.org/TR/css3-animations/#keyframes,
11547 // "If a keyframe selector specifies negative percentage values
11548 // or values higher than 100%, then the keyframe will be ignored."
11549 clearProperties();
11550 return 0;
11551 }
11552 if (i != 0)
11553 keyString.append(',');
11554 keyString.append(String::number(key));
11555 keyString.append('%');
11556 }
11557 11554
11558 RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create(); 11555 RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create();
11559 keyframe->setKeyText(keyString.toString()); 11556 keyframe->setKeys(keyVector.release());
11560 keyframe->setProperties(createStylePropertySet()); 11557 keyframe->setProperties(createStylePropertySet());
11561 11558
11562 clearProperties(); 11559 clearProperties();
11563 11560
11564 StyleKeyframe* keyframePtr = keyframe.get(); 11561 StyleKeyframe* keyframePtr = keyframe.get();
11565 m_parsedKeyframes.append(keyframe.release()); 11562 m_parsedKeyframes.append(keyframe.release());
11566 return keyframePtr; 11563 return keyframePtr;
11567 } 11564 }
11568 11565
11569 void CSSParser::invalidBlockHit() 11566 void CSSParser::invalidBlockHit()
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
11980 { 11977 {
11981 // The tokenizer checks for the construct of an+b. 11978 // The tokenizer checks for the construct of an+b.
11982 // However, since the {ident} rule precedes the {nth} rule, some of those 11979 // However, since the {ident} rule precedes the {nth} rule, some of those
11983 // tokens are identified as string literal. Furthermore we need to accept 11980 // tokens are identified as string literal. Furthermore we need to accept
11984 // "odd" and "even" which does not match to an+b. 11981 // "odd" and "even" which does not match to an+b.
11985 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11982 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11986 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11983 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11987 } 11984 }
11988 11985
11989 } 11986 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698