Changeset 120154 in webkit


Ignore:
Timestamp:
Jun 12, 2012 8:31:39 PM (6 years ago)
Author:
macpherson@chromium.org
Message:

WIP: Implement CSS Variables Standard.
https://bugs.webkit.org/show_bug.cgi?id=85580

Reviewed by Ojan Vafai.

Implement CSS Variables Module Level 1. (See http://www.w3.org/TR/css-variables/)

A HashMap of properties is referenced by RenderStyle, and used to store variables as strings.
That HashMap is copy-on-write, and unless new variables are defined is simply a pointer to the
parent's definitions. At usage time the variable's value is parsed according to the CSS property
where it is used.
Variables can:

Define lists of values (ie. entire shorthand values).
Define individual values.
Refer to other variables. (Cycle detection is implemented).

Please see the supplied test cases for example usage.

Missing features:

CSS variables cannot yet be used inside some functions such as -webkit-calc.

Covered by existing test suite under fast/css/variables.

  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):

  • css/CSSGrammar.y:
  • css/CSSParser.cpp:

(WebCore):
(WebCore::filterProperties):
(WebCore::CSSParser::createStylePropertySet):
(WebCore::CSSParser::validUnit):
(WebCore::CSSParser::createPrimitiveNumericValue):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::storeVariableDeclaration):
(WebCore::CSSParser::detectDashToken):
(WebCore::CSSParser::lex):

  • css/CSSParser.h:

(CSSParser):

  • css/CSSParserValues.cpp:

(WebCore::CSSParserValue::createCSSValue):

  • css/CSSPrimitiveValue.cpp:

(WebCore::isValidCSSUnitTypeForDoubleConversion):
(WebCore::CSSPrimitiveValue::getStringValue):
(WebCore::CSSPrimitiveValue::customSerializeResolvingVariables):
(WebCore):

  • css/CSSPrimitiveValue.h:

(CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::isVariableName):

  • css/CSSProperty.cpp:

(WebCore::CSSProperty::isInheritedProperty):

  • css/CSSValue.cpp:

(WebCore::CSSValue::serializeResolvingVariables):
(WebCore):
(WebCore::CSSValue::destroy):

  • css/CSSValue.h:

(CSSValue):
(WebCore::CSSValue::isVariableValue):

  • css/CSSValueList.cpp:

(WebCore):
(WebCore::CSSValueList::customSerializeResolvingVariables):

  • css/CSSValueList.h:

(CSSValueList):

  • css/CSSVariableValue.h: Added.

(WebCore):
(CSSVariableValue):
(WebCore::CSSVariableValue::create):
(WebCore::CSSVariableValue::name):
(WebCore::CSSVariableValue::value):
(WebCore::CSSVariableValue::CSSVariableValue):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::collectMatchingRulesForList):

  • css/StyleResolver.h:
  • css/WebKitCSSTransformValue.cpp:

(WebCore):
(WebCore::WebKitCSSTransformValue::customSerializeResolvingVariables):

  • css/WebKitCSSTransformValue.h:

(WebKitCSSTransformValue):

  • css/makeprop.pl:
  • rendering/style/RenderStyle.h:
  • rendering/style/StyleVariableData.h: Added.

(WebCore):
(StyleVariableData):
(WebCore::StyleVariableData::create):
(WebCore::StyleVariableData::copy):
(WebCore::StyleVariableData::operator==):
(WebCore::StyleVariableData::operator!=):
(WebCore::StyleVariableData::setVariable):
(WebCore::StyleVariableData::StyleVariableData):

Location:
trunk/Source/WebCore
Files:
2 added
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r120147 r120154  
     12012-06-12  Luke Macpherson  <macpherson@chromium.org>
     2
     3        WIP: Implement CSS Variables Standard.
     4        https://bugs.webkit.org/show_bug.cgi?id=85580
     5
     6        Reviewed by Ojan Vafai.
     7
     8        Implement CSS Variables Module Level 1. (See http://www.w3.org/TR/css-variables/)
     9
     10        A HashMap of properties is referenced by RenderStyle, and used to store variables as strings.
     11        That HashMap is copy-on-write, and unless new variables are defined is simply a pointer to the
     12        parent's definitions. At usage time the variable's value is parsed according to the CSS property
     13        where it is used.
     14        Variables can:
     15               Define lists of values (ie. entire shorthand values).
     16               Define individual values.
     17               Refer to other variables. (Cycle detection is implemented).
     18        Please see the supplied test cases for example usage.
     19
     20        Missing features:
     21               CSS variables cannot yet be used inside some functions such as -webkit-calc.
     22
     23        Covered by existing test suite under fast/css/variables.
     24
     25        * GNUmakefile.list.am:
     26        * Target.pri:
     27        * WebCore.gypi:
     28        * WebCore.vcproj/WebCore.vcproj:
     29        * WebCore.xcodeproj/project.pbxproj:
     30        * css/CSSComputedStyleDeclaration.cpp:
     31        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
     32        * css/CSSGrammar.y:
     33        * css/CSSParser.cpp:
     34        (WebCore):
     35        (WebCore::filterProperties):
     36        (WebCore::CSSParser::createStylePropertySet):
     37        (WebCore::CSSParser::validUnit):
     38        (WebCore::CSSParser::createPrimitiveNumericValue):
     39        (WebCore::CSSParser::parseValue):
     40        (WebCore::CSSParser::storeVariableDeclaration):
     41        (WebCore::CSSParser::detectDashToken):
     42        (WebCore::CSSParser::lex):
     43        * css/CSSParser.h:
     44        (CSSParser):
     45        * css/CSSParserValues.cpp:
     46        (WebCore::CSSParserValue::createCSSValue):
     47        * css/CSSPrimitiveValue.cpp:
     48        (WebCore::isValidCSSUnitTypeForDoubleConversion):
     49        (WebCore::CSSPrimitiveValue::getStringValue):
     50        (WebCore::CSSPrimitiveValue::customSerializeResolvingVariables):
     51        (WebCore):
     52        * css/CSSPrimitiveValue.h:
     53        (CSSPrimitiveValue):
     54        (WebCore::CSSPrimitiveValue::isVariableName):
     55        * css/CSSProperty.cpp:
     56        (WebCore::CSSProperty::isInheritedProperty):
     57        * css/CSSValue.cpp:
     58        (WebCore::CSSValue::serializeResolvingVariables):
     59        (WebCore):
     60        (WebCore::CSSValue::destroy):
     61        * css/CSSValue.h:
     62        (CSSValue):
     63        (WebCore::CSSValue::isVariableValue):
     64        * css/CSSValueList.cpp:
     65        (WebCore):
     66        (WebCore::CSSValueList::customSerializeResolvingVariables):
     67        * css/CSSValueList.h:
     68        (CSSValueList):
     69        * css/CSSVariableValue.h: Added.
     70        (WebCore):
     71        (CSSVariableValue):
     72        (WebCore::CSSVariableValue::create):
     73        (WebCore::CSSVariableValue::name):
     74        (WebCore::CSSVariableValue::value):
     75        (WebCore::CSSVariableValue::CSSVariableValue):
     76        * css/StyleResolver.cpp:
     77        (WebCore::StyleResolver::collectMatchingRulesForList):
     78        * css/StyleResolver.h:
     79        * css/WebKitCSSTransformValue.cpp:
     80        (WebCore):
     81        (WebCore::WebKitCSSTransformValue::customSerializeResolvingVariables):
     82        * css/WebKitCSSTransformValue.h:
     83        (WebKitCSSTransformValue):
     84        * css/makeprop.pl:
     85        * rendering/style/RenderStyle.h:
     86        * rendering/style/StyleVariableData.h: Added.
     87        (WebCore):
     88        (StyleVariableData):
     89        (WebCore::StyleVariableData::create):
     90        (WebCore::StyleVariableData::copy):
     91        (WebCore::StyleVariableData::operator==):
     92        (WebCore::StyleVariableData::operator!=):
     93        (WebCore::StyleVariableData::setVariable):
     94        (WebCore::StyleVariableData::StyleVariableData):
     95
    1962012-06-12  MORITA Hajime  <morrita@google.com>
    297
  • trunk/Source/WebCore/GNUmakefile.list.am

    r120057 r120154  
    16871687        Source/WebCore/css/CSSValuePool.cpp \
    16881688        Source/WebCore/css/CSSValuePool.h \
     1689        Source/WebCore/css/CSSVariableValue.h \
    16891690        Source/WebCore/css/DashboardRegion.h \
    16901691        Source/WebCore/css/FontFeatureValue.cpp \
     
    40364037        Source/WebCore/rendering/style/StyleTransformData.cpp \
    40374038        Source/WebCore/rendering/style/StyleTransformData.h \
     4039        Source/WebCore/rendering/style/StyleVariableData.h \
    40384040        Source/WebCore/rendering/style/StyleVisualData.cpp \
    40394041        Source/WebCore/rendering/style/StyleVisualData.h \
  • trunk/Source/WebCore/Target.pri

    r120057 r120154  
    16531653    css/CSSValueList.h \
    16541654    css/CSSValuePool.h \
     1655    css/CSSVariableValue.h \
    16551656    css/CSSWrapShapes.h \
    16561657    css/FontFeatureValue.h \
     
    25662567    rendering/style/StyleSurroundData.h \
    25672568    rendering/style/StyleTransformData.h \
     2569    rendering/style/StyleVariableData.h \
    25682570    rendering/style/StyleVisualData.h \
    25692571    rendering/style/SVGRenderStyleDefs.h \
  • trunk/Source/WebCore/WebCore.gypi

    r120085 r120154  
    601601            'rendering/style/StyleSurroundData.h',
    602602            'rendering/style/StyleTransformData.h',
     603            'rendering/style/StyleVariableData.h',
    603604            'rendering/style/StyleVisualData.h',
    604605            'rendering/svg/SVGResourcesCache.h',
     
    25042505            'css/CSSValuePool.cpp',
    25052506            'css/CSSValuePool.h',
     2507            'css/CSSVariableValue.h',
    25062508            'css/CSSWrapShapes.cpp',
    25072509            'css/Counter.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r120085 r120154  
    3685236852                        </File>
    3685336853                        <File
     36854                                RelativePath="..\css\CSSVariableValue.h"
     36855                                >
     36856                        </File>
     36857                        <File
    3685436858                                RelativePath="..\css\CSSWrapShapes.cpp"
    3685536859                                >
     
    4584345847                                                />
    4584445848                                        </FileConfiguration>
     45849                                </File>
     45850                                <File
     45851                                        RelativePath="..\rendering\style\StyleVariableData.h"
     45852                                        >
    4584545853                                </File>
    4584645854                                <File
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r120057 r120154  
    53455345                BC5EB67D0E81D42000B25965 /* StyleBoxData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC5EB67C0E81D42000B25965 /* StyleBoxData.cpp */; };
    53465346                BC5EB67F0E81D4A700B25965 /* StyleDashboardRegion.h in Headers */ = {isa = PBXBuildFile; fileRef = BC5EB67E0E81D4A700B25965 /* StyleDashboardRegion.h */; settings = {ATTRIBUTES = (Private, ); }; };
     5347                BC5EB69A0E81DA6300B25966 /* StyleVariableData.h in Headers */ = {isa = PBXBuildFile; fileRef = BC5EB6980E81DA6300B25966 /* StyleVariableData.h */; settings = {ATTRIBUTES = (Private, ); }; };
    53475348                BC5EB6990E81DA6300B25965 /* StyleVisualData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC5EB6970E81DA6300B25965 /* StyleVisualData.cpp */; };
    53485349                BC5EB69A0E81DA6300B25965 /* StyleVisualData.h in Headers */ = {isa = PBXBuildFile; fileRef = BC5EB6980E81DA6300B25965 /* StyleVisualData.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    57625763                CAE9F90F146441F000C245B0 /* CSSAspectRatioValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CAE9F90D146441F000C245B0 /* CSSAspectRatioValue.cpp */; };
    57635764                CAE9F910146441F000C245B0 /* CSSAspectRatioValue.h in Headers */ = {isa = PBXBuildFile; fileRef = CAE9F90E146441F000C245B0 /* CSSAspectRatioValue.h */; };
     5765                CAE9F910146441F000C245B1 /* CSSVariableValue.h in Headers */ = {isa = PBXBuildFile; fileRef = CAE9F90E146441F000C245B1 /* CSSVariableValue.h */; };
    57645766                CD127DED14F3097D00E84779 /* WebCoreFullScreenWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */; };
    57655767                CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1249012492                BC5EB67C0E81D42000B25965 /* StyleBoxData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleBoxData.cpp; path = style/StyleBoxData.cpp; sourceTree = "<group>"; };
    1249112493                BC5EB67E0E81D4A700B25965 /* StyleDashboardRegion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleDashboardRegion.h; path = style/StyleDashboardRegion.h; sourceTree = "<group>"; };
     12494                BC5EB6980E81DA6300B25966 /* StyleVariableData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleVariableData.h; path = style/StyleVariableData.h; sourceTree = "<group>"; };
    1249212495                BC5EB6970E81DA6300B25965 /* StyleVisualData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleVisualData.cpp; path = style/StyleVisualData.cpp; sourceTree = "<group>"; };
    1249312496                BC5EB6980E81DA6300B25965 /* StyleVisualData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleVisualData.h; path = style/StyleVisualData.h; sourceTree = "<group>"; };
     
    1294412947                CAE9F90D146441F000C245B0 /* CSSAspectRatioValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSAspectRatioValue.cpp; sourceTree = "<group>"; };
    1294512948                CAE9F90E146441F000C245B0 /* CSSAspectRatioValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSAspectRatioValue.h; sourceTree = "<group>"; };
     12949                CAE9F90E146441F000C245B1 /* CSSVariableValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSVariableValue.h; sourceTree = "<group>"; };
    1294612950                CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreFullScreenWindow.h; sourceTree = "<group>"; };
    1294712951                CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreFullScreenWindow.mm; sourceTree = "<group>"; };
     
    2015920163                                BC5EB80D0E81F2CE00B25965 /* StyleTransformData.cpp */,
    2016020164                                BC5EB80E0E81F2CE00B25965 /* StyleTransformData.h */,
     20165                                BC5EB6980E81DA6300B25966 /* StyleVariableData.h */,
    2016120166                                BC5EB6970E81DA6300B25965 /* StyleVisualData.cpp */,
    2016220167                                BC5EB6980E81DA6300B25965 /* StyleVisualData.h */,
     
    2081820823                                E49BDA0A131FD3E5003C56F0 /* CSSValuePool.cpp */,
    2081920824                                E49BD9F9131FD2ED003C56F0 /* CSSValuePool.h */,
     20825                                CAE9F90E146441F000C245B1 /* CSSVariableValue.h */,
    2082020826                                501BAAB11395114B00F7ACEB /* CSSWrapShapes.cpp */,
    2082120827                                501BA9E11393CEA000F7ACEB /* CSSWrapShapes.h */,
     
    2213822144                                A80E6CE90A1989CA007FB8C5 /* CSSValueList.h in Headers */,
    2213922145                                E49BD9FA131FD2ED003C56F0 /* CSSValuePool.h in Headers */,
     22146                                CAE9F910146441F000C245B1 /* CSSVariableValue.h in Headers */,
    2214022147                                501BA9E21393CEA000F7ACEB /* CSSWrapShapes.h in Headers */,
    2214122148                                93F1992F08245E59001E9ABC /* Cursor.h in Headers */,
     
    2453524542                                BC5EB5E50E81BF6D00B25965 /* StyleSurroundData.h in Headers */,
    2453624543                                BC5EB8100E81F2CE00B25965 /* StyleTransformData.h in Headers */,
     24544                                BC5EB69A0E81DA6300B25966 /* StyleVariableData.h in Headers */,
    2453724545                                BC5EB69A0E81DA6300B25965 /* StyleVisualData.h in Headers */,
    2453824546                                D000ED2811C1B9CD00C47726 /* SubframeLoader.h in Headers */,
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r120029 r120154  
    13631363    switch (propertyID) {
    13641364        case CSSPropertyInvalid:
     1365#if ENABLE(CSS_VARIABLES)
     1366        case CSSPropertyVariable:
     1367#endif
    13651368            break;
    13661369
  • trunk/Source/WebCore/css/CSSGrammar.y

    r119984 r120154  
    102102%}
    103103
    104 %expect 59
     104%expect 61
    105105
    106106%nonassoc LOWEST_PREC
     
    136136%token CHARSET_SYM
    137137%token NAMESPACE_SYM
     138%token VARFUNCTION
    138139%token WEBKIT_RULE_SYM
    139140%token WEBKIT_DECLS_SYM
     
    203204%token <string> MINFUNCTION
    204205%token <string> MAXFUNCTION
     206%token <string> VAR_DEFINITION
    205207
    206208%token <string> UNICODERANGE
     
    12981300
    12991301declaration:
     1302    VAR_DEFINITION ':' maybe_space expr prio {
     1303#if ENABLE(CSS_VARIABLES)
     1304        CSSParser* p = static_cast<CSSParser*>(parser);
     1305        p->storeVariableDeclaration($1, p->sinkFloatingValueList($4), $5);
     1306        $$ = true;
     1307        p->markPropertyEnd($5, $$);
     1308#else
     1309        $$ = false;
     1310#endif
     1311    }
     1312    |
    13001313    property ':' maybe_space expr prio {
    13011314        $$ = false;
     
    14301443  | HEX maybe_space { $$.id = 0; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; }
    14311444  | '#' maybe_space { $$.id = 0; $$.string = CSSParserString(); $$.unit = CSSPrimitiveValue::CSS_PARSER_HEXCOLOR; } /* Handle error case: "color: #;" */
     1445  | VARFUNCTION maybe_space IDENT ')' maybe_space {
     1446#if ENABLE(CSS_VARIABLES)
     1447      $$.id = 0;
     1448      $$.string = $3;
     1449      $$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
     1450#endif
     1451  }
    14321452  /* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */
    14331453  | function {
  • trunk/Source/WebCore/css/CSSParser.cpp

    r120147 r120154  
    5252#include "CSSValueList.h"
    5353#include "CSSValuePool.h"
     54#if ENABLE(CSS_VARIABLES)
     55#include "CSSVariableValue.h"
     56#endif
    5457#include "CSSWrapShapes.h"
    5558#include "Counter.h"
     
    11821185}
    11831186
     1187#if ENABLE(CSS_VARIABLES)
     1188static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenVariables)
     1189#else
    11841190static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties)
     1191#endif
    11851192{
    11861193    // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
     
    11891196        if (property.isImportant() != important)
    11901197            continue;
     1198#if ENABLE(CSS_VARIABLES)
     1199        if (property.id() == CSSPropertyVariable) {
     1200            const AtomicString& name = static_cast<CSSVariableValue*>(property.value())->name();
     1201            if (seenVariables.contains(name))
     1202                continue;
     1203            seenVariables.add(name);
     1204            output[--unusedEntries] = property;
     1205            continue;
     1206        }
     1207#endif
    11911208        const unsigned propertyIDIndex = property.id() - firstCSSProperty;
    11921209        if (seenProperties.get(propertyIDIndex))
     
    12041221
    12051222    // Important properties have higher priority, so add them first. Duplicate definitions can then be ignored when found.
     1223#if ENABLE(CSS_VARIABLES)
     1224    HashSet<AtomicString> seenVariables;
     1225    filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties, seenVariables);
     1226    filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties, seenVariables);
     1227#else
    12061228    filterProperties(true, m_parsedProperties, results, unusedEntries, seenProperties);
    12071229    filterProperties(false, m_parsedProperties, results, unusedEntries, seenProperties);
    1208 
     1230#endif
    12091231    if (unusedEntries)
    12101232        results.remove(0, unusedEntries);
     
    13021324    bool b = false;
    13031325    switch (value->unit) {
     1326#if ENABLE(CSS_VARIABLES)
     1327    case CSSPrimitiveValue::CSS_VARIABLE_NAME:
     1328        // Variables are checked at the point they are dereferenced because unit type is not available here.
     1329        b = true;
     1330        break;
     1331#endif
    13041332    case CSSPrimitiveValue::CSS_NUMBER:
    13051333        b = (unitflags & FNumber);
     
    13581386inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSParserValue* value)
    13591387{
     1388#if ENABLE(CSS_VARIABLES)
     1389    if (value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME)
     1390        return CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIABLE_NAME);
     1391#endif
     1392
    13601393    if (m_parsedCalculation) {
    13611394        ASSERT(isCalculation(value));
     
    15301563        return true;
    15311564    }
     1565
     1566#if ENABLE(CSS_VARIABLES)
     1567    if (!id && value->unit == CSSPrimitiveValue::CSS_VARIABLE_NAME && num == 1) {
     1568        addProperty(propId, CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_VARIABLE_NAME), important);
     1569        m_valueList->next();
     1570        return true;
     1571    }
     1572#endif
    15321573
    15331574    if (isKeywordPropertyID(propId)) {
     
    28272868    return true;
    28282869}
     2870
     2871#if ENABLE(CSS_VARIABLES)
     2872void CSSParser::storeVariableDeclaration(const CSSParserString& name, PassOwnPtr<CSSParserValueList> value, bool important)
     2873{
     2874    StringBuilder builder;
     2875    for (unsigned i = 0, size = value->size(); i < size; i++) {
     2876        if (i)
     2877            builder.append(' ');
     2878        builder.append(value->valueAt(i)->createCSSValue()->cssText());
     2879    }
     2880    addProperty(CSSPropertyVariable, CSSVariableValue::create(name, builder.toString()), important, false);
     2881}
     2882#endif
    28292883
    28302884void CSSParser::addAnimationValue(RefPtr<CSSValue>& lval, PassRefPtr<CSSValue> rval)
     
    84288482        else if (isASCIIAlphaCaselessEqual(name[10], 'x') && isEqualToCSSIdentifier(name + 1, "webkit-ma"))
    84298483            m_token = MAXFUNCTION;
     8484#if ENABLE(CSS_VARIABLES)
     8485        else if (isASCIIAlphaCaselessEqual(name[10], 'r') && isEqualToCSSIdentifier(name + 1, "webkit-va"))
     8486            m_token = VARFUNCTION;
     8487#endif
    84308488    } else if (length == 12 && isEqualToCSSIdentifier(name + 1, "webkit-calc"))
    84318489        m_token = CALCFUNCTION;
     
    87668824
    87678825    case CharacterDash:
     8826#if ENABLE(CSS_VARIABLES)
     8827        if (m_currentCharacter[10] == '-' && isEqualToCSSIdentifier(m_currentCharacter, "webkit-var") && isIdentifierStartAfterDash(m_currentCharacter + 11)) {
     8828            // handle variable declarations
     8829            m_currentCharacter += 11;
     8830            parseIdentifier(result, hasEscape);
     8831            m_token = VAR_DEFINITION;
     8832            yylval->string.characters = m_tokenStart;
     8833            yylval->string.length = result - m_tokenStart;
     8834        } else
     8835#endif
    87688836        if (isIdentifierStartAfterDash(m_currentCharacter)) {
    87698837            --m_currentCharacter;
  • trunk/Source/WebCore/css/CSSParser.h

    r119984 r120154  
    9292    bool parseQuotes(CSSPropertyID, bool important);
    9393
     94#if ENABLE(CSS_VARIABLES)
     95    void storeVariableDeclaration(const CSSParserString&, PassOwnPtr<CSSParserValueList>, bool important);
     96#endif
     97
    9498    PassRefPtr<CSSValue> parseAttr(CSSParserValueList* args);
    9599
  • trunk/Source/WebCore/css/CSSParserValues.cpp

    r103498 r120154  
    2626#include "CSSSelector.h"
    2727#include "CSSSelectorList.h"
     28#if ENABLE(CSS_VARIABLES)
     29#include "CSSVariableValue.h"
     30#endif
    2831
    2932namespace WebCore {
     
    7679    } else if (unit == CSSParserValue::Function)
    7780        parsedValue = CSSFunctionValue::create(function);
    78     else if (unit == CSSPrimitiveValue::CSS_STRING || unit == CSSPrimitiveValue::CSS_URI || unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR)
     81    else if (unit == CSSPrimitiveValue::CSS_STRING
     82             || unit == CSSPrimitiveValue::CSS_URI
     83#if ENABLE(CSS_VARIABLES)
     84             || unit == CSSPrimitiveValue::CSS_VARIABLE_NAME
     85#endif
     86             || unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR)
    7987        parsedValue = CSSPrimitiveValue::create(string, (CSSPrimitiveValue::UnitTypes)unit);
    8088    else if (unit >= CSSPrimitiveValue::CSS_NUMBER && unit <= CSSPrimitiveValue::CSS_KHZ)
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r119984 r120154  
    106106    case CSSPrimitiveValue:: CSS_UNKNOWN:
    107107    case CSSPrimitiveValue:: CSS_URI:
     108#if ENABLE(CSS_VARIABLES)
     109    case CSSPrimitiveValue:: CSS_VARIABLE_NAME:
     110#endif
    108111        return false;
    109112    }
     
    712715        case CSS_ATTR:
    713716        case CSS_URI:
     717#if ENABLE(CSS_VARIABLES)
     718        case CSS_VARIABLE_NAME:
     719#endif
    714720            return m_value.string;
    715721        case CSS_IDENT:
     
    729735        case CSS_ATTR:
    730736        case CSS_URI:
    731              return m_value.string;
     737#if ENABLE(CSS_VARIABLES)
     738        case CSS_VARIABLE_NAME:
     739#endif
     740            return m_value.string;
    732741        case CSS_IDENT:
    733742            return valueOrPropertyName(m_value.ident);
     
    10761085            text = formatNumber(m_value.num) + "vmin";
    10771086            break;
     1087#if ENABLE(CSS_VARIABLES)
     1088        case CSS_VARIABLE_NAME:
     1089            text = "-webkit-var(";
     1090            text += m_value.string;
     1091            text += ")";
     1092            break;
     1093#endif
    10781094    }
    10791095
     
    10831099    return text;
    10841100}
     1101
     1102#if ENABLE(CSS_VARIABLES)
     1103String CSSPrimitiveValue::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
     1104{
     1105    if (m_primitiveUnitType == CSS_VARIABLE_NAME && variables.contains(m_value.string))
     1106        return variables.get(m_value.string);
     1107    return customCssText();
     1108}
     1109#endif
    10851110
    10861111void CSSPrimitiveValue::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r119984 r120154  
    124124        CSS_CALC = 112,
    125125        CSS_CALC_PERCENTAGE_WITH_NUMBER = 113,
    126         CSS_CALC_PERCENTAGE_WITH_LENGTH = 114
     126        CSS_CALC_PERCENTAGE_WITH_LENGTH = 114,
     127
     128#if ENABLE(CSS_VARIABLES)
     129        CSS_VARIABLE_NAME = 115,
     130#endif
    127131    };
    128132
     
    174178    bool isCalculatedPercentageWithNumber() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_NUMBER; }
    175179    bool isCalculatedPercentageWithLength() const { return primitiveType() == CSS_CALC_PERCENTAGE_WITH_LENGTH; }
     180#if ENABLE(CSS_VARIABLES)
     181    bool isVariableName() const { return primitiveType() == CSS_VARIABLE_NAME; }
     182#endif
    176183    bool isViewportPercentageLength() const { return m_primitiveUnitType >= CSS_VW && m_primitiveUnitType <= CSS_VMIN; }
    177184
     
    285292
    286293    String customCssText() const;
     294#if ENABLE(CSS_VARIABLES)
     295    String customSerializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     296#endif
    287297
    288298    bool isQuirkValue() { return m_isQuirkValue; }
  • trunk/Source/WebCore/css/CSSProperty.cpp

    r120029 r120154  
    290290    case CSSPropertyTextShadow:
    291291    case CSSPropertyTextTransform:
     292#if ENABLE(CSS_VARIABLES)
     293    case CSSPropertyVariable:
     294#endif
    292295    case CSSPropertyVisibility:
    293296    case CSSPropertyWebkitAspectRatio:
  • trunk/Source/WebCore/css/CSSValue.cpp

    r120044 r120154  
    4848#include "CSSUnicodeRangeValue.h"
    4949#include "CSSValueList.h"
     50#if ENABLE(CSS_VARIABLES)
     51#include "CSSVariableValue.h"
     52#endif
    5053#include "FontValue.h"
    5154#include "FontFeatureValue.h"
     
    186189#endif
    187190#endif
     191#if ENABLE(CSS_VARIABLES)
     192    case VariableClass:
     193        return static_cast<const CSSVariableValue*>(this)->value();
     194#endif
    188195#if ENABLE(SVG)
    189196    case SVGColorClass:
     
    197204}
    198205
     206#if ENABLE(CSS_VARIABLES)
     207String CSSValue::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
     208{
     209    switch (classType()) {
     210    case PrimitiveClass:
     211        return static_cast<const CSSPrimitiveValue*>(this)->customSerializeResolvingVariables(variables);
     212    case ValueListClass:
     213        return static_cast<const CSSValueList*>(this)->customSerializeResolvingVariables(variables);
     214    case WebKitCSSTransformClass:
     215        return static_cast<const WebKitCSSTransformValue*>(this)->customSerializeResolvingVariables(variables);
     216    default:
     217        return cssText();
     218    }
     219}
     220#endif
     221
    199222void CSSValue::destroy()
    200223{
     
    296319        return;
    297320#endif
     321#endif
     322#if ENABLE(CSS_VARIABLES)
     323    case VariableClass:
     324        delete static_cast<CSSVariableValue*>(this);
     325        return;
    298326#endif
    299327#if ENABLE(SVG)
  • trunk/Source/WebCore/css/CSSValue.h

    r118963 r120154  
    6060    String cssText() const;
    6161    void setCssText(const String&, ExceptionCode&) { } // FIXME: Not implemented.
     62#if ENABLE(CSS_VARIABLES)
     63    String serializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     64#endif
    6265
    6366    bool isPrimitiveValue() const { return m_classType == PrimitiveClass; }
     
    9194#endif
    9295#endif // ENABLE(CSS_FILTERS)
     96#if ENABLE(CSS_VARIABLES)
     97    bool isVariableValue() const { return m_classType == VariableClass; }
     98#endif
    9399#if ENABLE(SVG)
    94100    bool isSVGColor() const { return m_classType == SVGColorClass || m_classType == SVGPaintClass; }
     
    149155#if ENABLE(CSS_FILTERS) && ENABLE(CSS_SHADERS)
    150156        WebKitCSSShaderClass,
     157#endif
     158#if ENABLE(CSS_VARIABLES)
     159        VariableClass,
    151160#endif
    152161#if ENABLE(SVG)
  • trunk/Source/WebCore/css/CSSValueList.cpp

    r118963 r120154  
    137137}
    138138
     139#if ENABLE(CSS_VARIABLES)
     140String CSSValueList::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
     141{
     142    StringBuilder result;
     143    String separator;
     144    switch (m_valueListSeparator) {
     145    case SpaceSeparator:
     146        separator = " ";
     147        break;
     148    case CommaSeparator:
     149        separator = ", ";
     150        break;
     151    case SlashSeparator:
     152        separator = " / ";
     153        break;
     154    default:
     155        ASSERT_NOT_REACHED();
     156    }
     157
     158    unsigned size = m_values.size();
     159    for (unsigned i = 0; i < size; i++) {
     160        if (!result.isEmpty())
     161            result.append(separator);
     162        result.append(m_values[i]->serializeResolvingVariables(variables));
     163    }
     164
     165    return result.toString();
     166}
     167#endif
     168
    139169void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
    140170{
  • trunk/Source/WebCore/css/CSSValueList.h

    r118963 r120154  
    6060
    6161    String customCssText() const;
     62#if ENABLE(CSS_VARIABLES)
     63    String customSerializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     64#endif
    6265
    6366    void addSubresourceStyleURLs(ListHashSet<KURL>&, const StyleSheetContents*) const;
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r120132 r120154  
    5050#include "CSSTimingFunctionValue.h"
    5151#include "CSSValueList.h"
     52#if ENABLE(CSS_VARIABLES)
     53#include "CSSVariableValue.h"
     54#endif
    5255#include "CachedImage.h"
    5356#include "CalculationValue.h"
     
    18761879    m_lineHeightValue = 0;
    18771880    bool inheritedOnly = false;
     1881#if ENABLE(CSS_VARIABLES)
     1882    applyMatchedProperties<VariableDefinitions>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
     1883#endif
    18781884    applyMatchedProperties<HighPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
    18791885
     
    27182724            continue;
    27192725
    2720         if (pass == HighPriorityProperties) {
     2726        switch (pass) {
     2727#if ENABLE(CSS_VARIABLES)
     2728        case VariableDefinitions:
     2729            COMPILE_ASSERT(CSSPropertyVariable < firstCSSProperty, CSS_variable_is_before_first_property);
     2730            if (property == CSSPropertyVariable)
     2731                applyProperty(current.id(), current.value());
     2732            break;
     2733#endif
     2734        case HighPriorityProperties:
    27212735            COMPILE_ASSERT(firstCSSProperty == CSSPropertyColor, CSS_color_is_first_property);
    27222736            COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyColor + 18, CSS_zoom_is_end_of_first_prop_range);
    27232737            COMPILE_ASSERT(CSSPropertyLineHeight == CSSPropertyZoom + 1, CSS_line_height_is_after_zoom);
     2738#if ENABLE(CSS_VARIABLES)
     2739            if (property == CSSPropertyVariable)
     2740                continue;
     2741#endif
    27242742            // give special priority to font-xxx, color properties, etc
     2743            if (property < CSSPropertyLineHeight)
     2744                applyProperty(current.id(), current.value());
     2745            // we apply line-height later
     2746            else if (property == CSSPropertyLineHeight)
     2747                m_lineHeightValue = current.value();
     2748            break;
     2749        case LowPriorityProperties:
    27252750            if (property > CSSPropertyLineHeight)
    2726                 continue;
    2727             // we apply line-height later
    2728             if (property == CSSPropertyLineHeight) {
    2729                 m_lineHeightValue = current.value();
    2730                 continue;
    2731             }
    2732             applyProperty(current.id(), current.value());
    2733             continue;
    2734         }
    2735         if (property > CSSPropertyLineHeight)
    2736             applyProperty(current.id(), current.value());
     2751                applyProperty(current.id(), current.value());
     2752        }
    27372753    }
    27382754    InspectorInstrumentation::didProcessRule(cookie);
     
    28802896        applyInheritedOnly = true;
    28812897    }
     2898
     2899#if ENABLE(CSS_VARIABLES)
     2900    // First apply all variable definitions, as they may be used during application of later properties.
     2901    applyMatchedProperties<VariableDefinitions>(matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
     2902    applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
     2903    applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
     2904    applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
     2905#endif
     2906
    28822907    // Now we have all of the matched rules in the appropriate order. Walk the rules and apply
    28832908    // high-priority properties first, i.e., those properties that other properties depend on.
     
    31943219}
    31953220
    3196 void StyleResolver::applyProperty(CSSPropertyID id, CSSValue *value)
    3197 {
     3221#if ENABLE(CSS_VARIABLES)
     3222static bool hasVariableReference(CSSValue* value)
     3223{
     3224    if (value->isPrimitiveValue() && static_cast<CSSPrimitiveValue*>(value)->isVariableName())
     3225        return true;
     3226
     3227    for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
     3228        if (hasVariableReference(i.value()))
     3229            return true;
     3230    }
     3231
     3232    return false;
     3233}
     3234
     3235void StyleResolver::resolveVariables(CSSPropertyID id, CSSValue* value, Vector<std::pair<CSSPropertyID, String> >& knownExpressions)
     3236{
     3237    std::pair<CSSPropertyID, String> expression(id, value->serializeResolvingVariables(*style()->variables()));
     3238
     3239    if (knownExpressions.contains(expression))
     3240        return; // cycle detected.
     3241
     3242    knownExpressions.append(expression);
     3243
     3244    // FIXME: It would be faster not to re-parse from strings, but for now CSS property validation lives inside the parser so we do it there.
     3245    RefPtr<StylePropertySet> resultSet = StylePropertySet::create();
     3246    if (!CSSParser::parseValue(resultSet.get(), id, expression.second, false, CSSStrictMode, 0))
     3247        return; // expression failed to parse.
     3248
     3249    for (unsigned i = 0; i < resultSet->propertyCount(); i++) {
     3250        const CSSProperty& property = resultSet->propertyAt(i);
     3251        if (property.id() != CSSPropertyVariable && hasVariableReference(property.value()))
     3252            resolveVariables(property.id(), property.value(), knownExpressions);
     3253        else
     3254            applyProperty(property.id(), property.value());
     3255    }
     3256}
     3257#endif
     3258
     3259void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value)
     3260{
     3261#if ENABLE(CSS_VARIABLES)
     3262    if (id != CSSPropertyVariable && hasVariableReference(value)) {
     3263        Vector<std::pair<CSSPropertyID, String> > knownExpressions;
     3264        resolveVariables(id, value, knownExpressions);
     3265        return;
     3266    }
     3267#endif
     3268
    31983269    bool isInherit = m_parentNode && value->isInheritedValue();
    31993270    bool isInitial = value->isInitialValue() || (!m_parentNode && value->isInheritedValue());
     
    32093280        m_parentStyle->setHasExplicitlyInheritedProperties();
    32103281
    3211     // check lookup table for implementations and use when available
     3282#if ENABLE(CSS_VARIABLES)
     3283    if (id == CSSPropertyVariable) {
     3284        ASSERT(value->isVariableValue());
     3285        CSSVariableValue* variable = static_cast<CSSVariableValue*>(value);
     3286        ASSERT(!variable->name().isEmpty());
     3287        ASSERT(!variable->value().isEmpty());
     3288        m_style->setVariable(variable->name(), variable->value());
     3289        return;
     3290    }
     3291#endif
     3292
     3293    // Check lookup table for implementations and use when available.
    32123294    const PropertyHandler& handler = m_styleBuilder.propertyHandler(id);
    32133295    if (handler.isValid()) {
     
    52525334    for (CSSValueListIterator i = inValue; i.hasMore(); i.advance()) {
    52535335        CSSValue* currValue = i.value();
     5336
    52545337        if (!currValue->isWebKitCSSTransformValue())
    52555338            continue;
  • trunk/Source/WebCore/css/StyleResolver.h

    r119949 r120154  
    3333#include <wtf/RefPtr.h>
    3434#include <wtf/Vector.h>
     35#include <wtf/text/AtomicStringHash.h>
    3536#include <wtf/text/StringHash.h>
    3637
     
    356357    void applyMatchedProperties(const MatchResult&, const Element*);
    357358    enum StyleApplicationPass {
     359#if ENABLE(CSS_VARIABLES)
     360        VariableDefinitions,
     361#endif
    358362        HighPriorityProperties,
    359363        LowPriorityProperties
     
    363367    template <StyleApplicationPass pass>
    364368    void applyProperties(const StylePropertySet* properties, StyleRule*, bool isImportant, bool inheritedOnly, bool filterRegionProperties);
    365 
     369#if ENABLE(CSS_VARIABLES)
     370    void resolveVariables(CSSPropertyID, CSSValue*, Vector<std::pair<CSSPropertyID, String> >& knownExpressions);
     371#endif
    366372    static bool isValidRegionStyleProperty(CSSPropertyID);
    367373
  • trunk/Source/WebCore/css/WebKitCSSTransformValue.cpp

    r118885 r120154  
    7979}
    8080
     81#if ENABLE(CSS_VARIABLES)
     82String WebKitCSSTransformValue::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
     83{
     84    StringBuilder result;
     85    if (m_type != UnknownTransformOperation) {
     86        ASSERT(static_cast<size_t>(m_type) < WTF_ARRAY_LENGTH(transformName));
     87        result.append(transformName[m_type]);
     88        result.append('(');
     89        result.append(CSSValueList::customSerializeResolvingVariables(variables));
     90        result.append(')');
     91    }
     92    return result.toString();
     93}
     94#endif
     95
    8196WebKitCSSTransformValue::WebKitCSSTransformValue(const WebKitCSSTransformValue& cloneFrom)
    8297    : CSSValueList(cloneFrom)
  • trunk/Source/WebCore/css/WebKitCSSTransformValue.h

    r113588 r120154  
    6767
    6868    String customCssText() const;
     69#if ENABLE(CSS_VARIABLES)
     70    String customSerializeResolvingVariables(const HashMap<AtomicString, String>&) const;
     71#endif
    6972
    7073    TransformOperationType operationType() const { return m_type; }
  • trunk/Source/WebCore/css/makeprop.pl

    r118624 r120154  
    165165enum CSSPropertyID {
    166166    CSSPropertyInvalid = 0,
     167#if ENABLE(CSS_VARIABLES)
     168    CSSPropertyVariable = 1,
     169#endif
    167170EOF
    168171
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r119984 r120154  
    140140    rareInheritedData.init();
    141141    inherited.init();
    142 
    143142#if ENABLE(SVG)
    144143    m_svgStyle.init();
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r120100 r120154  
    407407
    408408    const PseudoStyleCache* cachedPseudoStyles() const { return m_cachedPseudoStyles.get(); }
     409
     410#if ENABLE(CSS_VARIABLES)
     411    void setVariable(const AtomicString& name, const String& value) { rareInheritedData.access()->m_variables.access()->setVariable(name, value); }
     412    const HashMap<AtomicString, String>* variables() { return &(rareInheritedData->m_variables->m_data); }
     413#endif
    409414
    410415    bool affectedByHoverRules() const { return noninherited_flags.affectedByHover(); }
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.cpp

    r119984 r120154  
    7171#endif   
    7272{
     73#if ENABLE(CSS_VARIABLES)
     74    m_variables.init();
     75#endif
    7376}
    7477
     
    125128    , tapHighlightColor(o.tapHighlightColor)
    126129#endif
     130#if ENABLE(CSS_VARIABLES)
     131    , m_variables(o.m_variables)
     132#endif
    127133{
    128134}
     
    193199#endif
    194200        && m_lineSnap == o.m_lineSnap
     201#if ENABLE(CSS_VARIABLES)
     202        && m_variables == o.m_variables
     203#endif
    195204        && m_lineAlign == o.m_lineAlign;
    196205}
  • trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h

    r119984 r120154  
    3131#include <wtf/PassRefPtr.h>
    3232#include <wtf/text/AtomicString.h>
     33
     34#if ENABLE(CSS_VARIABLES)
     35#include "DataRef.h"
     36#include "StyleVariableData.h"
     37#endif
    3338
    3439namespace WebCore {
     
    119124#endif
    120125
     126#if ENABLE(CSS_VARIABLES)
     127    DataRef<StyleVariableData> m_variables;
     128#endif
     129
    121130private:
    122131    StyleRareInheritedData();
Note: See TracChangeset for help on using the changeset viewer.