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

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, 5 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
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 #if YYDEBUG > 0 94 #if YYDEBUG > 0
95 extern int cssyydebug; 95 extern int cssyydebug;
96 #endif 96 #endif
97 97
98 extern int cssyyparse(WebCore::CSSParser*); 98 extern int cssyyparse(WebCore::CSSParser*);
99 99
100 using namespace std; 100 using namespace std;
101 using namespace WTF; 101 using namespace WTF;
102 102
103 namespace {
104
105 PassOwnPtr<Vector<float> > createKeyframeKeyList(WebCore::CSSParserValueList* ke ys)
apavlov 2013/07/15 11:54:37 Looks like this should actually belong to StyleKey
Steve Block 2013/08/14 00:44:05 Done
106 {
107 OwnPtr<Vector<float> > keyVector = adoptPtr(new Vector<float>(keys->size())) ;
108 for (unsigned i = 0; i < keys->size(); ++i) {
109 ASSERT(keys->valueAt(i)->unit == WebCore::CSSPrimitiveValue::CSS_NUMBER) ;
110 float key = static_cast<float>(keys->valueAt(i)->fValue);
111 if (key < 0 || key > 100) {
112 // As per http://www.w3.org/TR/css3-animations/#keyframes,
113 // "If a keyframe selector specifies negative percentage values
114 // or values higher than 100%, then the keyframe will be ignored."
115 keyVector->clear();
116 break;
117 }
118 keyVector->at(i) = key;
119 }
120 return keyVector.release();
121 }
122
123 } // namespace
124
103 namespace WebCore { 125 namespace WebCore {
104 126
105 static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX; 127 static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
106 static const double MAX_SCALE = 1000000; 128 static const double MAX_SCALE = 1000000;
107 129
108 template <unsigned N> 130 template <unsigned N>
109 static bool equal(const CSSParserString& a, const char (&b)[N]) 131 static bool equal(const CSSParserString& a, const char (&b)[N])
110 { 132 {
111 unsigned length = N - 1; // Ignore the trailing null character 133 unsigned length = N - 1; // Ignore the trailing null character
112 if (a.length() != length) 134 if (a.length() != length)
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 407 }
386 408
387 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet , const String& string) 409 PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet , const String& string)
388 { 410 {
389 setStyleSheet(sheet); 411 setStyleSheet(sheet);
390 setupParser("@-internal-keyframe-rule ", string, ""); 412 setupParser("@-internal-keyframe-rule ", string, "");
391 cssyyparse(this); 413 cssyyparse(this);
392 return m_keyframe.release(); 414 return m_keyframe.release();
393 } 415 }
394 416
417 PassOwnPtr<Vector<float> > CSSParser::parseKeyframeKeyList(const String& string)
418 {
419 setupParser("@-internal-keyframe-key-list ", string, "");
420 cssyyparse(this);
421 ASSERT(m_valueList);
422 return createKeyframeKeyList(m_valueList.get());
423 }
424
395 bool CSSParser::parseSupportsCondition(const String& string) 425 bool CSSParser::parseSupportsCondition(const String& string)
396 { 426 {
397 m_supportsCondition = false; 427 m_supportsCondition = false;
398 setupParser("@-internal-supports-condition ", string, ""); 428 setupParser("@-internal-supports-condition ", string, "");
399 cssyyparse(this); 429 cssyyparse(this);
400 return m_supportsCondition; 430 return m_supportsCondition;
401 } 431 }
402 432
403 static inline bool isColorPropertyID(CSSPropertyID propertyId) 433 static inline bool isColorPropertyID(CSSPropertyID propertyId)
404 { 434 {
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
1337 1367
1338 PassRefPtr<MediaQuerySet> CSSParser::parseMediaQueryList(const String& string) 1368 PassRefPtr<MediaQuerySet> CSSParser::parseMediaQueryList(const String& string)
1339 { 1369 {
1340 ASSERT(!m_mediaList); 1370 ASSERT(!m_mediaList);
1341 1371
1342 // can't use { because tokenizer state switches from mediaquery to initial s tate when it sees { token. 1372 // can't use { because tokenizer state switches from mediaquery to initial s tate when it sees { token.
1343 // instead insert one " " (which is caught by maybe_space in CSSGrammar.y) 1373 // instead insert one " " (which is caught by maybe_space in CSSGrammar.y)
1344 setupParser("@-internal-medialist ", string, ""); 1374 setupParser("@-internal-medialist ", string, "");
1345 cssyyparse(this); 1375 cssyyparse(this);
1346 1376
1347 ASSERT(m_mediaList.get()); 1377 ASSERT(m_mediaList);
1348 return m_mediaList.release(); 1378 return m_mediaList.release();
1349 } 1379 }
1350 1380
1351 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) 1381 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)
1352 { 1382 {
1353 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found. 1383 // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
1354 for (int i = input.size() - 1; i >= 0; --i) { 1384 for (int i = input.size() - 1; i >= 0; --i) {
1355 const CSSProperty& property = input[i]; 1385 const CSSProperty& property = input[i];
1356 if (property.isImportant() != important) 1386 if (property.isImportant() != important)
1357 continue; 1387 continue;
(...skipping 8820 matching lines...) Expand 10 before | Expand all | Expand 10 after
10178 m_parsingMode = MediaQueryMode; 10208 m_parsingMode = MediaQueryMode;
10179 m_token = INTERNAL_MEDIALIST_SYM; 10209 m_token = INTERNAL_MEDIALIST_SYM;
10180 } 10210 }
10181 return; 10211 return;
10182 10212
10183 case 24: 10213 case 24:
10184 if (!hasEscape && isEqualToCSSIdentifier(name + 2, "internal-keyfram e-rule")) 10214 if (!hasEscape && isEqualToCSSIdentifier(name + 2, "internal-keyfram e-rule"))
10185 m_token = INTERNAL_KEYFRAME_RULE_SYM; 10215 m_token = INTERNAL_KEYFRAME_RULE_SYM;
10186 return; 10216 return;
10187 10217
10218 case 28:
10219 if (isEqualToCSSIdentifier(name + 2, "internal-keyframe-key-list"))
10220 m_token = INTERNAL_KEYFRAME_KEY_LIST_SYM;
10221 return;
10222
10188 case 29: 10223 case 29:
10189 if (isEqualToCSSIdentifier(name + 2, "internal-supports-condition")) { 10224 if (isEqualToCSSIdentifier(name + 2, "internal-supports-condition")) {
10190 m_parsingMode = SupportsMode; 10225 m_parsingMode = SupportsMode;
10191 m_token = INTERNAL_SUPPORTS_CONDITION_SYM; 10226 m_token = INTERNAL_SUPPORTS_CONDITION_SYM;
10192 } 10227 }
10193 return; 10228 return;
10194 } 10229 }
10195 } 10230 }
10196 } 10231 }
10197 10232
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
11269 if (property.id() == CSSPropertyFontVariant && property.value()->isValue List()) { 11304 if (property.id() == CSSPropertyFontVariant && property.value()->isValue List()) {
11270 m_parsedProperties.remove(i); 11305 m_parsedProperties.remove(i);
11271 continue; 11306 continue;
11272 } 11307 }
11273 ++i; 11308 ++i;
11274 } 11309 }
11275 } 11310 }
11276 11311
11277 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys) 11312 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys)
11278 { 11313 {
11279 // Create a key string from the passed keys 11314 OwnPtr<Vector<float> > keyVector = createKeyframeKeyList(keys);
11280 StringBuilder keyString; 11315 if (keyVector->isEmpty())
11281 for (unsigned i = 0; i < keys->size(); ++i) { 11316 return 0;
11282 ASSERT(keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER);
11283 float key = static_cast<float>(keys->valueAt(i)->fValue);
11284 if (key < 0 || key > 100) {
11285 // As per http://www.w3.org/TR/css3-animations/#keyframes,
11286 // "If a keyframe selector specifies negative percentage values
11287 // or values higher than 100%, then the keyframe will be ignored."
11288 clearProperties();
11289 return 0;
11290 }
11291 if (i != 0)
11292 keyString.append(',');
11293 keyString.append(String::number(key));
11294 keyString.append('%');
11295 }
11296 11317
11297 RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create(); 11318 RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create();
11298 keyframe->setKeyText(keyString.toString()); 11319 keyframe->setKeys(keyVector.release());
11299 keyframe->setProperties(createStylePropertySet()); 11320 keyframe->setProperties(createStylePropertySet());
11300 11321
11301 clearProperties(); 11322 clearProperties();
11302 11323
11303 StyleKeyframe* keyframePtr = keyframe.get(); 11324 StyleKeyframe* keyframePtr = keyframe.get();
11304 m_parsedKeyframes.append(keyframe.release()); 11325 m_parsedKeyframes.append(keyframe.release());
11305 return keyframePtr; 11326 return keyframePtr;
11306 } 11327 }
11307 11328
11308 void CSSParser::invalidBlockHit() 11329 void CSSParser::invalidBlockHit()
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
11721 { 11742 {
11722 // The tokenizer checks for the construct of an+b. 11743 // The tokenizer checks for the construct of an+b.
11723 // However, since the {ident} rule precedes the {nth} rule, some of those 11744 // However, since the {ident} rule precedes the {nth} rule, some of those
11724 // tokens are identified as string literal. Furthermore we need to accept 11745 // tokens are identified as string literal. Furthermore we need to accept
11725 // "odd" and "even" which does not match to an+b. 11746 // "odd" and "even" which does not match to an+b.
11726 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11747 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11727 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11748 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11728 } 11749 }
11729 11750
11730 } 11751 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698