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

Side by Side Diff: Source/core/css/parser/CSSPropertyParser.cpp

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ToT-ed again... Created 5 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 16 matching lines...) Expand all
27 #include "config.h" 27 #include "config.h"
28 #include "core/css/parser/CSSPropertyParser.h" 28 #include "core/css/parser/CSSPropertyParser.h"
29 29
30 #include "core/StylePropertyShorthand.h" 30 #include "core/StylePropertyShorthand.h"
31 #include "core/css/CSSBasicShapes.h" 31 #include "core/css/CSSBasicShapes.h"
32 #include "core/css/CSSBorderImage.h" 32 #include "core/css/CSSBorderImage.h"
33 #include "core/css/CSSCanvasValue.h" 33 #include "core/css/CSSCanvasValue.h"
34 #include "core/css/CSSContentDistributionValue.h" 34 #include "core/css/CSSContentDistributionValue.h"
35 #include "core/css/CSSCrossfadeValue.h" 35 #include "core/css/CSSCrossfadeValue.h"
36 #include "core/css/CSSCursorImageValue.h" 36 #include "core/css/CSSCursorImageValue.h"
37 #include "core/css/CSSCustomVariableValue.h"
37 #include "core/css/CSSFontFaceSrcValue.h" 38 #include "core/css/CSSFontFaceSrcValue.h"
38 #include "core/css/CSSFontFeatureValue.h" 39 #include "core/css/CSSFontFeatureValue.h"
39 #include "core/css/CSSFunctionValue.h" 40 #include "core/css/CSSFunctionValue.h"
40 #include "core/css/CSSGridLineNamesValue.h" 41 #include "core/css/CSSGridLineNamesValue.h"
41 #include "core/css/CSSImageSetValue.h" 42 #include "core/css/CSSImageSetValue.h"
42 #include "core/css/CSSImageValue.h" 43 #include "core/css/CSSImageValue.h"
43 #include "core/css/CSSLineBoxContainValue.h" 44 #include "core/css/CSSLineBoxContainValue.h"
44 #include "core/css/CSSPathValue.h" 45 #include "core/css/CSSPathValue.h"
45 #include "core/css/CSSPrimitiveValueMappings.h" 46 #include "core/css/CSSPrimitiveValueMappings.h"
46 #include "core/css/CSSProperty.h" 47 #include "core/css/CSSProperty.h"
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 return false; 435 return false;
435 addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitial Value(), important); 436 addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitial Value(), important);
436 return true; 437 return true;
437 } else if (id == CSSValueUnset) { 438 } else if (id == CSSValueUnset) {
438 if (m_valueList->size() != 1) 439 if (m_valueList->size() != 1)
439 return false; 440 return false;
440 addExpandedPropertyForValue(propId, cssValuePool().createUnsetValue(), i mportant); 441 addExpandedPropertyForValue(propId, cssValuePool().createUnsetValue(), i mportant);
441 return true; 442 return true;
442 } 443 }
443 444
445
444 int num = inShorthand() ? 1 : m_valueList->size(); 446 int num = inShorthand() ? 1 : m_valueList->size();
445 447
448 if (RuntimeEnabledFeatures::cssVariablesEnabled() && value->unit == CSSParse rValue::VariableValue) {
449 // We don't expand the shorthand here because crazypants.
450 m_parsedProperties.append(CSSProperty(propId, CSSPrimitiveValue::create( value->variableData), important, false, 0, m_implicitShorthand));
451 m_valueList->next();
452 return true;
453 }
454
446 if (CSSParserFastPaths::isKeywordPropertyID(propId)) { 455 if (CSSParserFastPaths::isKeywordPropertyID(propId)) {
447 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id)) 456 if (!CSSParserFastPaths::isValidKeywordPropertyAndValue(propId, id))
448 return false; 457 return false;
449 if (m_valueList->next() && !inShorthand()) 458 if (m_valueList->next() && !inShorthand())
450 return false; 459 return false;
451 addProperty(propId, cssValuePool().createIdentifierValue(id), important) ; 460 addProperty(propId, cssValuePool().createIdentifierValue(id), important) ;
452 return true; 461 return true;
453 } 462 }
454 463
455 bool validPrimitive = false; 464 bool validPrimitive = false;
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 1534
1526 // Properties below are validated inside parseViewportProperty, because we 1535 // Properties below are validated inside parseViewportProperty, because we
1527 // check for parser state. We need to invalidate if someone adds them outsid e 1536 // check for parser state. We need to invalidate if someone adds them outsid e
1528 // a @viewport rule. 1537 // a @viewport rule.
1529 case CSSPropertyMaxZoom: 1538 case CSSPropertyMaxZoom:
1530 case CSSPropertyMinZoom: 1539 case CSSPropertyMinZoom:
1531 case CSSPropertyOrientation: 1540 case CSSPropertyOrientation:
1532 case CSSPropertyUserZoom: 1541 case CSSPropertyUserZoom:
1533 validPrimitive = false; 1542 validPrimitive = false;
1534 break; 1543 break;
1535
Timothy Loh 2015/07/23 08:11:47 change isn't relevant
1536 case CSSPropertyScrollSnapPointsX: 1544 case CSSPropertyScrollSnapPointsX:
1537 case CSSPropertyScrollSnapPointsY: 1545 case CSSPropertyScrollSnapPointsY:
1538 parsedValue = parseScrollSnapPoints(); 1546 parsedValue = parseScrollSnapPoints();
1539 break; 1547 break;
1540 case CSSPropertyScrollSnapCoordinate: 1548 case CSSPropertyScrollSnapCoordinate:
1541 parsedValue = parseScrollSnapCoordinate(); 1549 parsedValue = parseScrollSnapCoordinate();
1542 break; 1550 break;
1543 case CSSPropertyScrollSnapDestination: 1551 case CSSPropertyScrollSnapDestination:
1544 parsedValue = parsePosition(m_valueList); 1552 parsedValue = parsePosition(m_valueList);
1545 break; 1553 break;
1546
1547 default: 1554 default:
1548 return parseSVGValue(propId, important); 1555 return parseSVGValue(propId, important);
1549 } 1556 }
1550 1557
1551 if (validPrimitive) { 1558 if (validPrimitive) {
1552 parsedValue = parseValidPrimitive(id, value); 1559 parsedValue = parseValidPrimitive(id, value);
1553 m_valueList->next(); 1560 m_valueList->next();
1554 } 1561 }
1555 ASSERT(!m_parsedCalculation); 1562 ASSERT(!m_parsedCalculation);
1556 if (parsedValue) { 1563 if (parsedValue) {
(...skipping 6010 matching lines...) Expand 10 before | Expand all | Expand 10 after
7567 7574
7568 // If just one value is supplied, the second value 7575 // If just one value is supplied, the second value
7569 // is implicitly initialized with the first value. 7576 // is implicitly initialized with the first value.
7570 if (numValues == 1) 7577 if (numValues == 1)
7571 m_valueList->previous(); 7578 m_valueList->previous();
7572 7579
7573 return parseViewportProperty(second, important); 7580 return parseViewportProperty(second, important);
7574 } 7581 }
7575 7582
7576 template <typename CharacterType> 7583 template <typename CharacterType>
7584 static bool isVariableDefinition(const CharacterType* propertyName, unsigned len gth)
7585 {
7586 return (length >= 2 && propertyName[0] == '-' && propertyName[1] == '-');
7587 }
7588
7589 template <typename CharacterType>
7577 static CSSPropertyID unresolvedCSSPropertyID(const CharacterType* propertyName, unsigned length) 7590 static CSSPropertyID unresolvedCSSPropertyID(const CharacterType* propertyName, unsigned length)
7578 { 7591 {
7579 char buffer[maxCSSPropertyNameLength + 1]; // 1 for null character 7592 char buffer[maxCSSPropertyNameLength + 1]; // 1 for null character
7580 7593
7581 for (unsigned i = 0; i != length; ++i) { 7594 for (unsigned i = 0; i != length; ++i) {
7582 CharacterType c = propertyName[i]; 7595 CharacterType c = propertyName[i];
7583 if (c == 0 || c >= 0x7F) 7596 if (c == 0 || c >= 0x7F) {
7597 if (isVariableDefinition(propertyName, length))
Timothy Loh 2015/07/23 08:11:47 These don't really do what I'd expect. Any code wh
7598 return CSSPropertyVariable;
7584 return CSSPropertyInvalid; // illegal character 7599 return CSSPropertyInvalid; // illegal character
7600 }
7585 buffer[i] = toASCIILower(c); 7601 buffer[i] = toASCIILower(c);
7586 } 7602 }
7587 buffer[length] = '\0'; 7603 buffer[length] = '\0';
7588 7604
7589 const char* name = buffer; 7605 const char* name = buffer;
7590 const Property* hashTableEntry = findProperty(name, length); 7606 const Property* hashTableEntry = findProperty(name, length);
7591 if (!hashTableEntry) 7607 if (!hashTableEntry) {
7608 if (isVariableDefinition(propertyName, length))
7609 return CSSPropertyVariable;
7592 return CSSPropertyInvalid; 7610 return CSSPropertyInvalid;
7611 }
7593 CSSPropertyID property = static_cast<CSSPropertyID>(hashTableEntry->id); 7612 CSSPropertyID property = static_cast<CSSPropertyID>(hashTableEntry->id);
7594 if (!CSSPropertyMetadata::isEnabledProperty(property)) 7613 if (!CSSPropertyMetadata::isEnabledProperty(property))
7595 return CSSPropertyInvalid; 7614 return CSSPropertyInvalid;
7596 return property; 7615 return property;
7597 } 7616 }
7598 7617
7599 CSSPropertyID unresolvedCSSPropertyID(const String& string) 7618 CSSPropertyID unresolvedCSSPropertyID(const String& string)
7600 { 7619 {
7601 unsigned length = string.length(); 7620 unsigned length = string.length();
7602 7621
7603 if (!length) 7622 if (!length)
7604 return CSSPropertyInvalid; 7623 return CSSPropertyInvalid;
7605 if (length > maxCSSPropertyNameLength) 7624 if (length > maxCSSPropertyNameLength) {
7625 if (string.is8Bit() ? isVariableDefinition(string.characters8(), length) : isVariableDefinition(string.characters16(), length))
7626 return CSSPropertyVariable;
7606 return CSSPropertyInvalid; 7627 return CSSPropertyInvalid;
7628 }
7607 7629
7608 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt h) : unresolvedCSSPropertyID(string.characters16(), length); 7630 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt h) : unresolvedCSSPropertyID(string.characters16(), length);
7609 } 7631 }
7610 7632
7611 CSSPropertyID unresolvedCSSPropertyID(const CSSParserString& string) 7633 CSSPropertyID unresolvedCSSPropertyID(const CSSParserString& string)
7612 { 7634 {
7613 unsigned length = string.length(); 7635 unsigned length = string.length();
7614 7636
7615 if (!length) 7637 if (!length)
7616 return CSSPropertyInvalid; 7638 return CSSPropertyInvalid;
7617 if (length > maxCSSPropertyNameLength) 7639 if (length > maxCSSPropertyNameLength) {
7640 if (string.is8Bit() ? isVariableDefinition(string.characters8(), length) : isVariableDefinition(string.characters16(), length))
7641 return CSSPropertyVariable;
7618 return CSSPropertyInvalid; 7642 return CSSPropertyInvalid;
7643 }
7619 7644
7620 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt h) : unresolvedCSSPropertyID(string.characters16(), length); 7645 return string.is8Bit() ? unresolvedCSSPropertyID(string.characters8(), lengt h) : unresolvedCSSPropertyID(string.characters16(), length);
7621 } 7646 }
7622 7647
7623 template <typename CharacterType> 7648 template <typename CharacterType>
7624 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length) 7649 static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
7625 { 7650 {
7626 char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character 7651 char buffer[maxCSSValueKeywordLength + 1]; // 1 for null character
7627 7652
7628 for (unsigned i = 0; i != length; ++i) { 7653 for (unsigned i = 0; i != length; ++i) {
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
8152 } 8177 }
8153 } 8178 }
8154 8179
8155 if (!list->length()) 8180 if (!list->length())
8156 return nullptr; 8181 return nullptr;
8157 8182
8158 return list.release(); 8183 return list.release();
8159 } 8184 }
8160 8185
8161 } // namespace blink 8186 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698