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

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

Issue 16183002: Unprefix CSS Variables (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased and updated prefix test 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSPrimitiveValue.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 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after
3042 m_implicitShorthand = false; 3042 m_implicitShorthand = false;
3043 return true; 3043 return true;
3044 } 3044 }
3045 3045
3046 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr <CSSParserValueList> value, bool important) 3046 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr <CSSParserValueList> value, bool important)
3047 { 3047 {
3048 // When CSSGrammar.y encounters an invalid declaration it passes null for th e CSSParserValueList, just bail. 3048 // When CSSGrammar.y encounters an invalid declaration it passes null for th e CSSParserValueList, just bail.
3049 if (!value) 3049 if (!value)
3050 return; 3050 return;
3051 3051
3052 static const unsigned prefixLength = sizeof("-webkit-var-") - 1; 3052 static const unsigned prefixLength = sizeof("var-") - 1;
3053 3053
3054 ASSERT(name.length() > prefixLength); 3054 ASSERT(name.length() > prefixLength);
3055 AtomicString variableName = name.atomicSubstring(prefixLength, name.length() - prefixLength); 3055 AtomicString variableName = name.atomicSubstring(prefixLength, name.length() - prefixLength);
3056 3056
3057 StringBuilder builder; 3057 StringBuilder builder;
3058 for (unsigned i = 0, size = value->size(); i < size; i++) { 3058 for (unsigned i = 0, size = value->size(); i < size; i++) {
3059 if (i) 3059 if (i)
3060 builder.append(' '); 3060 builder.append(' ');
3061 RefPtr<CSSValue> cssValue = value->valueAt(i)->createCSSValue(); 3061 RefPtr<CSSValue> cssValue = value->valueAt(i)->createCSSValue();
3062 if (!cssValue) 3062 if (!cssValue)
(...skipping 6801 matching lines...) Expand 10 before | Expand all | Expand 10 after
9864 return true; 9864 return true;
9865 } 9865 }
9866 if (isASCIIAlphaCaselessEqual(name[0], 'u') && isASCIIAlphaCaselessEqual (name[1], 'r') && isASCIIAlphaCaselessEqual(name[2], 'l')) { 9866 if (isASCIIAlphaCaselessEqual(name[0], 'u') && isASCIIAlphaCaselessEqual (name[1], 'r') && isASCIIAlphaCaselessEqual(name[2], 'l')) {
9867 m_token = URI; 9867 m_token = URI;
9868 return true; 9868 return true;
9869 } 9869 }
9870 if (isASCIIAlphaCaselessEqual(name[0], 'c') && isASCIIAlphaCaselessEqual (name[1], 'u') && isASCIIAlphaCaselessEqual(name[2], 'e')) { 9870 if (isASCIIAlphaCaselessEqual(name[0], 'c') && isASCIIAlphaCaselessEqual (name[1], 'u') && isASCIIAlphaCaselessEqual(name[2], 'e')) {
9871 m_token = CUEFUNCTION; 9871 m_token = CUEFUNCTION;
9872 return true; 9872 return true;
9873 } 9873 }
9874 if (RuntimeEnabledFeatures::cssVariablesEnabled() && isASCIIAlphaCaseles sEqual(name[0], 'v') && isASCIIAlphaCaselessEqual(name[1], 'a') && isASCIIAlphaC aselessEqual(name[2], 'r')) {
9875 m_token = VARFUNCTION;
9876 return true;
9877 }
9874 return false; 9878 return false;
9875 9879
9876 case 4: 9880 case 4:
9877 if (isEqualToCSSIdentifier(name, "calc")) { 9881 if (isEqualToCSSIdentifier(name, "calc")) {
9878 m_token = CALCFUNCTION; 9882 m_token = CALCFUNCTION;
9879 return true; 9883 return true;
9880 } 9884 }
9881 return false; 9885 return false;
9882 9886
9883 case 9: 9887 case 9:
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
10060 { 10064 {
10061 CharacterType* name = tokenStart<CharacterType>(); 10065 CharacterType* name = tokenStart<CharacterType>();
10062 10066
10063 if (length == 11) { 10067 if (length == 11) {
10064 if (isASCIIAlphaCaselessEqual(name[10], 'y') && isEqualToCSSIdentifier(n ame + 1, "webkit-an")) 10068 if (isASCIIAlphaCaselessEqual(name[10], 'y') && isEqualToCSSIdentifier(n ame + 1, "webkit-an"))
10065 m_token = ANYFUNCTION; 10069 m_token = ANYFUNCTION;
10066 else if (isASCIIAlphaCaselessEqual(name[10], 'n') && isEqualToCSSIdentif ier(name + 1, "webkit-mi")) 10070 else if (isASCIIAlphaCaselessEqual(name[10], 'n') && isEqualToCSSIdentif ier(name + 1, "webkit-mi"))
10067 m_token = MINFUNCTION; 10071 m_token = MINFUNCTION;
10068 else if (isASCIIAlphaCaselessEqual(name[10], 'x') && isEqualToCSSIdentif ier(name + 1, "webkit-ma")) 10072 else if (isASCIIAlphaCaselessEqual(name[10], 'x') && isEqualToCSSIdentif ier(name + 1, "webkit-ma"))
10069 m_token = MAXFUNCTION; 10073 m_token = MAXFUNCTION;
10070 else if (RuntimeEnabledFeatures::cssVariablesEnabled() && isASCIIAlphaCa selessEqual(name[10], 'r') && isEqualToCSSIdentifier(name + 1, "webkit-va"))
10071 m_token = VARFUNCTION;
10072 } else if (length == 12 && isEqualToCSSIdentifier(name + 1, "webkit-calc")) 10074 } else if (length == 12 && isEqualToCSSIdentifier(name + 1, "webkit-calc"))
10073 m_token = CALCFUNCTION; 10075 m_token = CALCFUNCTION;
10074 else if (length == 19 && isEqualToCSSIdentifier(name + 1, "webkit-distribute d")) 10076 else if (length == 19 && isEqualToCSSIdentifier(name + 1, "webkit-distribute d"))
10075 m_token = DISTRIBUTEDFUNCTION; 10077 m_token = DISTRIBUTEDFUNCTION;
10076 } 10078 }
10077 10079
10078 template <typename CharacterType> 10080 template <typename CharacterType>
10079 inline void CSSParser::detectAtToken(int length, bool hasEscape) 10081 inline void CSSParser::detectAtToken(int length, bool hasEscape)
10080 { 10082 {
10081 CharacterType* name = tokenStart<CharacterType>(); 10083 CharacterType* name = tokenStart<CharacterType>();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
10307 m_token = SUPPORTS_OR; 10309 m_token = SUPPORTS_OR;
10308 } else if (length == 3) { 10310 } else if (length == 3) {
10309 if (isASCIIAlphaCaselessEqual(name[0], 'a') && isASCIIAlphaCaselessEqual (name[1], 'n') && isASCIIAlphaCaselessEqual(name[2], 'd')) 10311 if (isASCIIAlphaCaselessEqual(name[0], 'a') && isASCIIAlphaCaselessEqual (name[1], 'n') && isASCIIAlphaCaselessEqual(name[2], 'd'))
10310 m_token = SUPPORTS_AND; 10312 m_token = SUPPORTS_AND;
10311 else if (isASCIIAlphaCaselessEqual(name[0], 'n') && isASCIIAlphaCaseless Equal(name[1], 'o') && isASCIIAlphaCaselessEqual(name[2], 't')) 10313 else if (isASCIIAlphaCaselessEqual(name[0], 'n') && isASCIIAlphaCaseless Equal(name[1], 'o') && isASCIIAlphaCaselessEqual(name[2], 't'))
10312 m_token = SUPPORTS_NOT; 10314 m_token = SUPPORTS_NOT;
10313 } 10315 }
10314 } 10316 }
10315 10317
10316 template <typename CharacterType> 10318 template <typename CharacterType>
10317 inline bool CSSParser::detectCSSVariablesToken(int length) 10319 inline void CSSParser::detectCSSVariableDefinitionToken(int length)
10318 { 10320 {
10319 ASSERT(tokenStart<CharacterType>()[0] == '-'); 10321 static const unsigned prefixLength = sizeof("var-") - 1;
10320 if (length < sizeof("-webkit-var-*") - 1) 10322 if (length <= prefixLength)
10321 return false; 10323 return;
10322 CharacterType* name = tokenStart<CharacterType>(); 10324 CharacterType* name = tokenStart<CharacterType>();
10323 return name[11] == '-' && isIdentifierStartAfterDash(name + 12) && isEqualTo CSSCaseSensitiveIdentifier(name + 1, "webkit-var"); 10325 COMPILE_ASSERT(prefixLength > 0, CSS_variable_prefix_must_be_nonempty);
10326 if (name[prefixLength - 1] == '-' && isIdentifierStartAfterDash(name + prefi xLength) && isEqualToCSSCaseSensitiveIdentifier(name, "var"))
10327 m_token = VAR_DEFINITION;
10324 } 10328 }
10325 10329
10326
10327 template <typename SrcCharacterType> 10330 template <typename SrcCharacterType>
10328 int CSSParser::realLex(void* yylvalWithoutType) 10331 int CSSParser::realLex(void* yylvalWithoutType)
10329 { 10332 {
10330 YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType); 10333 YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType);
10331 // Write pointer for the next character. 10334 // Write pointer for the next character.
10332 SrcCharacterType* result; 10335 SrcCharacterType* result;
10333 CSSParserString resultString; 10336 CSSParserString resultString;
10334 bool hasEscape; 10337 bool hasEscape;
10335 10338
10336 // The input buffer is terminated by a \0 character, so 10339 // The input buffer is terminated by a \0 character, so
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
10405 currentCharacter<SrcCharacterType>() = tokenStart<SrcCharact erType>() + 1; 10408 currentCharacter<SrcCharacterType>() = tokenStart<SrcCharact erType>() + 1;
10406 if (parseNthChildExtra<SrcCharacterType>()) { 10409 if (parseNthChildExtra<SrcCharacterType>()) {
10407 m_token = NTH; 10410 m_token = NTH;
10408 yylval->string.setLength(currentCharacter<SrcCharacterTy pe>() - tokenStart<SrcCharacterType>()); 10411 yylval->string.setLength(currentCharacter<SrcCharacterTy pe>() - tokenStart<SrcCharacterType>());
10409 } else { 10412 } else {
10410 // Revert the change to currentCharacter if unsuccessful . 10413 // Revert the change to currentCharacter if unsuccessful .
10411 currentCharacter<SrcCharacterType>() = nextCharacter; 10414 currentCharacter<SrcCharacterType>() = nextCharacter;
10412 } 10415 }
10413 } 10416 }
10414 } 10417 }
10418 } else if (UNLIKELY(RuntimeEnabledFeatures::cssVariablesEnabled())) {
10419 detectCSSVariableDefinitionToken<SrcCharacterType>(result - tokenSta rt<SrcCharacterType>());
10415 } 10420 }
10416 break; 10421 break;
10417 10422
10418 case CharacterDot: 10423 case CharacterDot:
10419 if (!isASCIIDigit(currentCharacter<SrcCharacterType>()[0])) 10424 if (!isASCIIDigit(currentCharacter<SrcCharacterType>()[0]))
10420 break; 10425 break;
10421 // Fall through to CharacterNumber. 10426 // Fall through to CharacterNumber.
10422 10427
10423 case CharacterNumber: { 10428 case CharacterNumber: {
10424 bool dotSeen = (m_token == '.'); 10429 bool dotSeen = (m_token == '.');
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
10491 m_token = dotSeen ? FLOATTOKEN : INTEGER; 10496 m_token = dotSeen ? FLOATTOKEN : INTEGER;
10492 break; 10497 break;
10493 } 10498 }
10494 10499
10495 case CharacterDash: 10500 case CharacterDash:
10496 if (isIdentifierStartAfterDash(currentCharacter<SrcCharacterType>())) { 10501 if (isIdentifierStartAfterDash(currentCharacter<SrcCharacterType>())) {
10497 --currentCharacter<SrcCharacterType>(); 10502 --currentCharacter<SrcCharacterType>();
10498 parseIdentifier(result, resultString, hasEscape); 10503 parseIdentifier(result, resultString, hasEscape);
10499 m_token = IDENT; 10504 m_token = IDENT;
10500 10505
10501 if (RuntimeEnabledFeatures::cssVariablesEnabled() && detectCSSVariab lesToken<SrcCharacterType>(result - tokenStart<SrcCharacterType>())) 10506 if (*currentCharacter<SrcCharacterType>() == '(') {
10502 m_token = VAR_DEFINITION;
10503 else if (*currentCharacter<SrcCharacterType>() == '(') {
10504 m_token = FUNCTION; 10507 m_token = FUNCTION;
10505 if (!hasEscape) 10508 if (!hasEscape)
10506 detectDashToken<SrcCharacterType>(result - tokenStart<SrcCha racterType>()); 10509 detectDashToken<SrcCharacterType>(result - tokenStart<SrcCha racterType>());
10507 ++currentCharacter<SrcCharacterType>(); 10510 ++currentCharacter<SrcCharacterType>();
10508 ++result; 10511 ++result;
10509 } else if (UNLIKELY(m_parsingMode == NthChildMode) && !hasEscape && isASCIIAlphaCaselessEqual(tokenStart<SrcCharacterType>()[1], 'n')) { 10512 } else if (UNLIKELY(m_parsingMode == NthChildMode) && !hasEscape && isASCIIAlphaCaselessEqual(tokenStart<SrcCharacterType>()[1], 'n')) {
10510 if (result - tokenStart<SrcCharacterType>() == 2) { 10513 if (result - tokenStart<SrcCharacterType>() == 2) {
10511 // String "-n" is IDENT but "-n+1" is NTH. 10514 // String "-n" is IDENT but "-n+1" is NTH.
10512 if (parseNthChildExtra<SrcCharacterType>()) { 10515 if (parseNthChildExtra<SrcCharacterType>()) {
10513 m_token = NTH; 10516 m_token = NTH;
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
11803 { 11806 {
11804 // The tokenizer checks for the construct of an+b. 11807 // The tokenizer checks for the construct of an+b.
11805 // 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
11806 // tokens are identified as string literal. Furthermore we need to accept 11809 // tokens are identified as string literal. Furthermore we need to accept
11807 // "odd" and "even" which does not match to an+b. 11810 // "odd" and "even" which does not match to an+b.
11808 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") 11811 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
11809 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); 11812 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
11810 } 11813 }
11811 11814
11812 } 11815 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698