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

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

Issue 13943004: Avoid reparsing keyframe selectors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased to master Created 7 years, 6 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
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 11332 matching lines...) Expand 10 before | Expand all | Expand 10 after
11343 if (property.id() == CSSPropertyFontVariant && property.value()->isValue List()) { 11343 if (property.id() == CSSPropertyFontVariant && property.value()->isValue List()) {
11344 m_parsedProperties.remove(i); 11344 m_parsedProperties.remove(i);
11345 continue; 11345 continue;
11346 } 11346 }
11347 ++i; 11347 ++i;
11348 } 11348 }
11349 } 11349 }
11350 11350
11351 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys) 11351 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys)
11352 { 11352 {
11353 // Create a key string from the passed keys 11353 Vector<float> keyframeKeys;
11354 StringBuilder keyString; 11354 unsigned keyCount = keys->size();
11355 for (unsigned i = 0; i < keys->size(); ++i) { 11355 for (unsigned i = 0; i < keyCount; ++i) {
apavlov 2013/06/18 09:59:50 IIRC, Vector::size() returns a size_t, so while we
11356 // Just as per the comment below, we ignore keyframes with
11357 // invalid key values (plain numbers or unknown identifiers)
11358 // marked as CSSPrimitiveValue::CSS_UNKNOWN during parsing.
11359 if (keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_UNKNOWN) {
11360 clearProperties();
11361 return 0;
11362 }
11363
11356 ASSERT(keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER); 11364 ASSERT(keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER);
11357 float key = static_cast<float>(keys->valueAt(i)->fValue); 11365 float key = static_cast<float>(keys->valueAt(i)->fValue);
11358 if (key < 0 || key > 100) { 11366 if (key < 0 || key > 100) {
11359 // As per http://www.w3.org/TR/css3-animations/#keyframes, 11367 // As per http://www.w3.org/TR/css3-animations/#keyframes,
11360 // "If a keyframe selector specifies negative percentage values 11368 // "If a keyframe selector specifies negative percentage values
11361 // or values higher than 100%, then the keyframe will be ignored." 11369 // or values higher than 100%, then the keyframe will be ignored."
11362 clearProperties(); 11370 clearProperties();
11363 return 0; 11371 return 0;
11364 } 11372 }
11365 if (i != 0) 11373
11366 keyString.append(','); 11374 keyframeKeys.append(key / 100);
11367 keyString.append(String::number(key));
11368 keyString.append('%');
11369 } 11375 }
11370 11376
11371 RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create(); 11377 RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create();
11372 keyframe->setKeyText(keyString.toString()); 11378 keyframe->setKeys(keyframeKeys);
11373 keyframe->setProperties(createStylePropertySet()); 11379 keyframe->setProperties(createStylePropertySet());
11374 11380
11375 clearProperties(); 11381 clearProperties();
11376 11382
11377 StyleKeyframe* keyframePtr = keyframe.get(); 11383 StyleKeyframe* keyframePtr = keyframe.get();
11378 m_parsedKeyframes.append(keyframe.release()); 11384 m_parsedKeyframes.append(keyframe.release());
11379 return keyframePtr; 11385 return keyframePtr;
11380 } 11386 }
11381 11387
11382 void CSSParser::invalidBlockHit() 11388 void CSSParser::invalidBlockHit()
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
11800 { 11806 {
11801 // The tokenizer checks for the construct of an+b. 11807 // The tokenizer checks for the construct of an+b.
11802 // However, since the {ident} rule precedes the {nth} rule, some of those 11808 // However, since the {ident} rule precedes the {nth} rule, some of those
11803 // tokens are identified as string literal. Furthermore we need to accept 11809 // tokens are identified as string literal. Furthermore we need to accept
11804 // "odd" and "even" which does not match to an+b. 11810 // "odd" and "even" which does not match to an+b.
11805 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11811 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11806 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11812 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11807 } 11813 }
11808 11814
11809 } 11815 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698