Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 3045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3056 m_implicitShorthand = false; | 3056 m_implicitShorthand = false; |
| 3057 return true; | 3057 return true; |
| 3058 } | 3058 } |
| 3059 | 3059 |
| 3060 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr <CSSParserValueList> value, bool important) | 3060 void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr <CSSParserValueList> value, bool important) |
| 3061 { | 3061 { |
| 3062 // When CSSGrammar.y encounters an invalid declaration it passes null for th e CSSParserValueList, just bail. | 3062 // When CSSGrammar.y encounters an invalid declaration it passes null for th e CSSParserValueList, just bail. |
| 3063 if (!value) | 3063 if (!value) |
| 3064 return; | 3064 return; |
| 3065 | 3065 |
| 3066 static const unsigned prefixLength = sizeof("-webkit-var-") - 1; | 3066 static const unsigned prefixLength = sizeof("var-") - 1; |
| 3067 | 3067 |
| 3068 ASSERT(name.length() > prefixLength); | 3068 ASSERT(name.length() > prefixLength); |
| 3069 AtomicString variableName = name.atomicSubstring(prefixLength, name.length() - prefixLength); | 3069 AtomicString variableName = name.atomicSubstring(prefixLength, name.length() - prefixLength); |
| 3070 | 3070 |
| 3071 StringBuilder builder; | 3071 StringBuilder builder; |
| 3072 for (unsigned i = 0, size = value->size(); i < size; i++) { | 3072 for (unsigned i = 0, size = value->size(); i < size; i++) { |
| 3073 if (i) | 3073 if (i) |
| 3074 builder.append(' '); | 3074 builder.append(' '); |
| 3075 RefPtr<CSSValue> cssValue = value->valueAt(i)->createCSSValue(); | 3075 RefPtr<CSSValue> cssValue = value->valueAt(i)->createCSSValue(); |
| 3076 if (!cssValue) | 3076 if (!cssValue) |
| (...skipping 6712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9789 return true; | 9789 return true; |
| 9790 } | 9790 } |
| 9791 if (isASCIIAlphaCaselessEqual(name[0], 'u') && isASCIIAlphaCaselessEqual (name[1], 'r') && isASCIIAlphaCaselessEqual(name[2], 'l')) { | 9791 if (isASCIIAlphaCaselessEqual(name[0], 'u') && isASCIIAlphaCaselessEqual (name[1], 'r') && isASCIIAlphaCaselessEqual(name[2], 'l')) { |
| 9792 m_token = URI; | 9792 m_token = URI; |
| 9793 return true; | 9793 return true; |
| 9794 } | 9794 } |
| 9795 if (isASCIIAlphaCaselessEqual(name[0], 'c') && isASCIIAlphaCaselessEqual (name[1], 'u') && isASCIIAlphaCaselessEqual(name[2], 'e')) { | 9795 if (isASCIIAlphaCaselessEqual(name[0], 'c') && isASCIIAlphaCaselessEqual (name[1], 'u') && isASCIIAlphaCaselessEqual(name[2], 'e')) { |
| 9796 m_token = CUEFUNCTION; | 9796 m_token = CUEFUNCTION; |
| 9797 return true; | 9797 return true; |
| 9798 } | 9798 } |
| 9799 if (RuntimeEnabledFeatures::cssVariablesEnabled() && isASCIIAlphaCaseles sEqual(name[0], 'v') && isASCIIAlphaCaselessEqual(name[1], 'a') && isASCIIAlphaC aselessEqual(name[2], 'r')) { | |
|
Mike Lawther (Google)
2013/05/29 04:54:13
This is a job for a new patch, but this looks like
alancutter (OOO until 2018)
2013/05/29 06:41:51
I was unsure whether I should tackle that in this
Mike Lawther (Google)
2013/05/29 08:23:00
I agree - post a new patch for this.
| |
| 9800 m_token = VARFUNCTION; | |
| 9801 return true; | |
| 9802 } | |
| 9799 return false; | 9803 return false; |
| 9800 | 9804 |
| 9801 case 4: | 9805 case 4: |
| 9802 if (isEqualToCSSIdentifier(name, "calc")) { | 9806 if (isEqualToCSSIdentifier(name, "calc")) { |
| 9803 m_token = CALCFUNCTION; | 9807 m_token = CALCFUNCTION; |
| 9804 return true; | 9808 return true; |
| 9805 } | 9809 } |
| 9806 return false; | 9810 return false; |
| 9807 | 9811 |
| 9808 case 9: | 9812 case 9: |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9985 { | 9989 { |
| 9986 CharacterType* name = tokenStart<CharacterType>(); | 9990 CharacterType* name = tokenStart<CharacterType>(); |
| 9987 | 9991 |
| 9988 if (length == 11) { | 9992 if (length == 11) { |
| 9989 if (isASCIIAlphaCaselessEqual(name[10], 'y') && isEqualToCSSIdentifier(n ame + 1, "webkit-an")) | 9993 if (isASCIIAlphaCaselessEqual(name[10], 'y') && isEqualToCSSIdentifier(n ame + 1, "webkit-an")) |
| 9990 m_token = ANYFUNCTION; | 9994 m_token = ANYFUNCTION; |
| 9991 else if (isASCIIAlphaCaselessEqual(name[10], 'n') && isEqualToCSSIdentif ier(name + 1, "webkit-mi")) | 9995 else if (isASCIIAlphaCaselessEqual(name[10], 'n') && isEqualToCSSIdentif ier(name + 1, "webkit-mi")) |
| 9992 m_token = MINFUNCTION; | 9996 m_token = MINFUNCTION; |
| 9993 else if (isASCIIAlphaCaselessEqual(name[10], 'x') && isEqualToCSSIdentif ier(name + 1, "webkit-ma")) | 9997 else if (isASCIIAlphaCaselessEqual(name[10], 'x') && isEqualToCSSIdentif ier(name + 1, "webkit-ma")) |
| 9994 m_token = MAXFUNCTION; | 9998 m_token = MAXFUNCTION; |
| 9995 else if (RuntimeEnabledFeatures::cssVariablesEnabled() && isASCIIAlphaCa selessEqual(name[10], 'r') && isEqualToCSSIdentifier(name + 1, "webkit-va")) | |
| 9996 m_token = VARFUNCTION; | |
| 9997 } else if (length == 12 && isEqualToCSSIdentifier(name + 1, "webkit-calc")) | 9999 } else if (length == 12 && isEqualToCSSIdentifier(name + 1, "webkit-calc")) |
| 9998 m_token = CALCFUNCTION; | 10000 m_token = CALCFUNCTION; |
| 9999 else if (length == 19 && isEqualToCSSIdentifier(name + 1, "webkit-distribute d")) | 10001 else if (length == 19 && isEqualToCSSIdentifier(name + 1, "webkit-distribute d")) |
| 10000 m_token = DISTRIBUTEDFUNCTION; | 10002 m_token = DISTRIBUTEDFUNCTION; |
| 10001 } | 10003 } |
| 10002 | 10004 |
| 10003 template <typename CharacterType> | 10005 template <typename CharacterType> |
| 10004 inline void CSSParser::detectAtToken(int length, bool hasEscape) | 10006 inline void CSSParser::detectAtToken(int length, bool hasEscape) |
| 10005 { | 10007 { |
| 10006 CharacterType* name = tokenStart<CharacterType>(); | 10008 CharacterType* name = tokenStart<CharacterType>(); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10237 m_token = SUPPORTS_OR; | 10239 m_token = SUPPORTS_OR; |
| 10238 } else if (length == 3) { | 10240 } else if (length == 3) { |
| 10239 if (isASCIIAlphaCaselessEqual(name[0], 'a') && isASCIIAlphaCaselessEqual (name[1], 'n') && isASCIIAlphaCaselessEqual(name[2], 'd')) | 10241 if (isASCIIAlphaCaselessEqual(name[0], 'a') && isASCIIAlphaCaselessEqual (name[1], 'n') && isASCIIAlphaCaselessEqual(name[2], 'd')) |
| 10240 m_token = SUPPORTS_AND; | 10242 m_token = SUPPORTS_AND; |
| 10241 else if (isASCIIAlphaCaselessEqual(name[0], 'n') && isASCIIAlphaCaseless Equal(name[1], 'o') && isASCIIAlphaCaselessEqual(name[2], 't')) | 10243 else if (isASCIIAlphaCaselessEqual(name[0], 'n') && isASCIIAlphaCaseless Equal(name[1], 'o') && isASCIIAlphaCaselessEqual(name[2], 't')) |
| 10242 m_token = SUPPORTS_NOT; | 10244 m_token = SUPPORTS_NOT; |
| 10243 } | 10245 } |
| 10244 } | 10246 } |
| 10245 | 10247 |
| 10246 template <typename CharacterType> | 10248 template <typename CharacterType> |
| 10247 inline bool CSSParser::detectCSSVariablesToken(int length) | 10249 inline void CSSParser::detectCSSVariableDeclarationToken(int length) |
| 10248 { | 10250 { |
| 10249 ASSERT(tokenStart<CharacterType>()[0] == '-'); | 10251 static const unsigned prefixLength = sizeof("var-") - 1; |
| 10250 if (length < sizeof("-webkit-var-*") - 1) | 10252 if (length <= prefixLength) |
| 10251 return false; | 10253 return; |
| 10252 CharacterType* name = tokenStart<CharacterType>(); | 10254 CharacterType* name = tokenStart<CharacterType>(); |
| 10253 return name[11] == '-' && isIdentifierStartAfterDash(name + 12) && isEqualTo CSSIdentifier(name + 1, "webkit-var"); | 10255 if (name[3] == '-' && isIdentifierStartAfterDash(name + 4) && isEqualToCSSId entifier(name, "var")) |
|
Mike Lawther (Google)
2013/05/29 04:54:13
You can get rid of these magic numbers with someth
alancutter (OOO until 2018)
2013/05/29 06:41:51
I would prefer to have the entire "var-" as a stri
Mike Lawther (Google)
2013/05/29 08:23:00
Can you make that a COMPILE_ASSERT? No need to hav
| |
| 10256 m_token = VAR_DEFINITION; | |
| 10254 } | 10257 } |
| 10255 | 10258 |
| 10256 | |
| 10257 template <typename SrcCharacterType> | 10259 template <typename SrcCharacterType> |
| 10258 int CSSParser::realLex(void* yylvalWithoutType) | 10260 int CSSParser::realLex(void* yylvalWithoutType) |
| 10259 { | 10261 { |
| 10260 YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType); | 10262 YYSTYPE* yylval = static_cast<YYSTYPE*>(yylvalWithoutType); |
| 10261 // Write pointer for the next character. | 10263 // Write pointer for the next character. |
| 10262 SrcCharacterType* result; | 10264 SrcCharacterType* result; |
| 10263 CSSParserString resultString; | 10265 CSSParserString resultString; |
| 10264 bool hasEscape; | 10266 bool hasEscape; |
| 10265 | 10267 |
| 10266 // The input buffer is terminated by a \0 character, so | 10268 // The input buffer is terminated by a \0 character, so |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10344 currentCharacter<SrcCharacterType>() = tokenStart<SrcCharact erType>() + 1; | 10346 currentCharacter<SrcCharacterType>() = tokenStart<SrcCharact erType>() + 1; |
| 10345 if (parseNthChildExtra<SrcCharacterType>()) { | 10347 if (parseNthChildExtra<SrcCharacterType>()) { |
| 10346 m_token = NTH; | 10348 m_token = NTH; |
| 10347 yylval->string.setLength(currentCharacter<SrcCharacterTy pe>() - tokenStart<SrcCharacterType>()); | 10349 yylval->string.setLength(currentCharacter<SrcCharacterTy pe>() - tokenStart<SrcCharacterType>()); |
| 10348 } else { | 10350 } else { |
| 10349 // Revert the change to currentCharacter if unsuccessful . | 10351 // Revert the change to currentCharacter if unsuccessful . |
| 10350 currentCharacter<SrcCharacterType>() = nextCharacter; | 10352 currentCharacter<SrcCharacterType>() = nextCharacter; |
| 10351 } | 10353 } |
| 10352 } | 10354 } |
| 10353 } | 10355 } |
| 10356 } else if (UNLIKELY(RuntimeEnabledFeatures::cssVariablesEnabled())) { | |
| 10357 detectCSSVariableDeclarationToken<SrcCharacterType>(result - tokenSt art<SrcCharacterType>()); | |
| 10354 } | 10358 } |
| 10355 break; | 10359 break; |
| 10356 | 10360 |
| 10357 case CharacterDot: | 10361 case CharacterDot: |
| 10358 if (!isASCIIDigit(currentCharacter<SrcCharacterType>()[0])) | 10362 if (!isASCIIDigit(currentCharacter<SrcCharacterType>()[0])) |
| 10359 break; | 10363 break; |
| 10360 // Fall through to CharacterNumber. | 10364 // Fall through to CharacterNumber. |
| 10361 | 10365 |
| 10362 case CharacterNumber: { | 10366 case CharacterNumber: { |
| 10363 bool dotSeen = (m_token == '.'); | 10367 bool dotSeen = (m_token == '.'); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10430 m_token = dotSeen ? FLOATTOKEN : INTEGER; | 10434 m_token = dotSeen ? FLOATTOKEN : INTEGER; |
| 10431 break; | 10435 break; |
| 10432 } | 10436 } |
| 10433 | 10437 |
| 10434 case CharacterDash: | 10438 case CharacterDash: |
| 10435 if (isIdentifierStartAfterDash(currentCharacter<SrcCharacterType>())) { | 10439 if (isIdentifierStartAfterDash(currentCharacter<SrcCharacterType>())) { |
| 10436 --currentCharacter<SrcCharacterType>(); | 10440 --currentCharacter<SrcCharacterType>(); |
| 10437 parseIdentifier(result, resultString, hasEscape); | 10441 parseIdentifier(result, resultString, hasEscape); |
| 10438 m_token = IDENT; | 10442 m_token = IDENT; |
| 10439 | 10443 |
| 10440 if (RuntimeEnabledFeatures::cssVariablesEnabled() && detectCSSVariab lesToken<SrcCharacterType>(result - tokenStart<SrcCharacterType>())) | 10444 if (*currentCharacter<SrcCharacterType>() == '(') { |
| 10441 m_token = VAR_DEFINITION; | |
| 10442 else if (*currentCharacter<SrcCharacterType>() == '(') { | |
| 10443 m_token = FUNCTION; | 10445 m_token = FUNCTION; |
| 10444 if (!hasEscape) | 10446 if (!hasEscape) |
| 10445 detectDashToken<SrcCharacterType>(result - tokenStart<SrcCha racterType>()); | 10447 detectDashToken<SrcCharacterType>(result - tokenStart<SrcCha racterType>()); |
| 10446 ++currentCharacter<SrcCharacterType>(); | 10448 ++currentCharacter<SrcCharacterType>(); |
| 10447 ++result; | 10449 ++result; |
| 10448 } else if (UNLIKELY(m_parsingMode == NthChildMode) && !hasEscape && isASCIIAlphaCaselessEqual(tokenStart<SrcCharacterType>()[1], 'n')) { | 10450 } else if (UNLIKELY(m_parsingMode == NthChildMode) && !hasEscape && isASCIIAlphaCaselessEqual(tokenStart<SrcCharacterType>()[1], 'n')) { |
| 10449 if (result - tokenStart<SrcCharacterType>() == 2) { | 10451 if (result - tokenStart<SrcCharacterType>() == 2) { |
| 10450 // String "-n" is IDENT but "-n+1" is NTH. | 10452 // String "-n" is IDENT but "-n+1" is NTH. |
| 10451 if (parseNthChildExtra<SrcCharacterType>()) { | 10453 if (parseNthChildExtra<SrcCharacterType>()) { |
| 10452 m_token = NTH; | 10454 m_token = NTH; |
| (...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11739 { | 11741 { |
| 11740 // The tokenizer checks for the construct of an+b. | 11742 // The tokenizer checks for the construct of an+b. |
| 11741 // However, since the {ident} rule precedes the {nth} rule, some of those | 11743 // However, since the {ident} rule precedes the {nth} rule, some of those |
| 11742 // tokens are identified as string literal. Furthermore we need to accept | 11744 // tokens are identified as string literal. Furthermore we need to accept |
| 11743 // "odd" and "even" which does not match to an+b. | 11745 // "odd" and "even" which does not match to an+b. |
| 11744 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") | 11746 return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even") |
| 11745 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); | 11747 || equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n"); |
| 11746 } | 11748 } |
| 11747 | 11749 |
| 11748 } | 11750 } |
| OLD | NEW |