Ignore:
Timestamp:
Jun 12, 2012, 8:31:39 PM (13 years ago)
Author:
[email protected]
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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.