Changeset 106166 in webkit


Ignore:
Timestamp:
Jan 27, 2012 4:05:00 PM (12 years ago)
Author:
mikelawther@chromium.org
Message:

CSS calc parsing stage
https://bugs.webkit.org/show_bug.cgi?id=57082

This is the parsing stage of calc. The expressions are evaluated and
expression trees are generated. CSS values are not created yet - that
will happen in a subsequent commit.

Reviewed by David Hyatt.

No functional change - covered by existing tests in LayoutTests/css3/calc.

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSCalculationValue.cpp: Added.

(WebCore):
(WebCore::unitCategory):
(WebCore::CSSCalcValue::customCssText):
(WebCore::CSSCalcExpressionNode::~CSSCalcExpressionNode):
(CSSCalcPrimitiveValue):
(WebCore::CSSCalcPrimitiveValue::create):
(WebCore::CSSCalcPrimitiveValue::cssText):
(WebCore::CSSCalcPrimitiveValue::CSSCalcPrimitiveValue):
():
(CSSCalcBinaryOperation):
(WebCore::CSSCalcBinaryOperation::create):
(WebCore::CSSCalcBinaryOperation::CSSCalcBinaryOperation):
(WebCore::checkDepthAndIndex):
(CSSCalcExpressionNodeParser):
(WebCore::CSSCalcExpressionNodeParser::parseCalc):
(Value):
(WebCore::CSSCalcExpressionNodeParser::operatorValue):
(WebCore::CSSCalcExpressionNodeParser::parseValue):
(WebCore::CSSCalcExpressionNodeParser::parseValueTerm):
(WebCore::CSSCalcExpressionNodeParser::parseValueMultiplicativeExpression):
(WebCore::CSSCalcExpressionNodeParser::parseAdditiveValueExpression):
(WebCore::CSSCalcExpressionNodeParser::parseValueExpression):
(WebCore::CSSCalcValue::create):

  • css/CSSCalculationValue.h: Added.

(WebCore):
():
(CSSCalcExpressionNode):
(WebCore::CSSCalcExpressionNode::category):
(WebCore::CSSCalcExpressionNode::isInt):
(WebCore::CSSCalcExpressionNode::isZero):
(WebCore::CSSCalcExpressionNode::CSSCalcExpressionNode):
(CSSCalcValue):
(WebCore::CSSCalcValue::category):
(WebCore::CSSCalcValue::isInt):
(WebCore::CSSCalcValue::CSSCalcValue):

  • css/CSSParser.cpp:

(WebCore::CSSParser::validCalculationUnit):
(WebCore):
(WebCore::CSSParser::validUnit):
(WebCore::CSSParser::createPrimitiveNumericValue):
(WebCore::CSSParser::parseValidPrimitive):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseFillPositionComponent):
(WebCore::CSSParser::parsedDouble):
(WebCore::CSSParser::isCalculation):
(WebCore::CSSParser::colorIntFromValue):
(WebCore::CSSParser::parseColorParameters):
(WebCore::CSSParser::parseHSLParameters):
(WebCore::ShadowParseContext::ShadowParseContext):
(WebCore::ShadowParseContext::commitLength):
(WebCore::ShadowParseContext::commitStyle):
(ShadowParseContext):
(WebCore::CSSParser::parseShadow):
(WebCore::BorderImageSliceParseContext::BorderImageSliceParseContext):
(WebCore::BorderImageSliceParseContext::commitNumber):
(WebCore::BorderImageSliceParseContext::commitBorderImageSlice):
(BorderImageSliceParseContext):
(WebCore::CSSParser::parseBorderImageSlice):
(WebCore::BorderImageQuadParseContext::BorderImageQuadParseContext):
(WebCore::BorderImageQuadParseContext::commitNumber):
(WebCore::BorderImageQuadParseContext::commitBorderImageQuad):
(BorderImageQuadParseContext):
(WebCore::CSSParser::parseBorderImageQuad):
(WebCore::CSSParser::parseCalculation):

  • css/CSSParser.h:

():
(CSSParser):

  • css/CSSValue.cpp:

(WebCore::CSSValue::cssText):
(WebCore::CSSValue::destroy):

  • css/CSSValue.h:

(WebCore::CSSValue::isCalculationValue):
():

  • css/SVGCSSParser.cpp:

(WebCore::CSSParser::parseSVGValue):

  • platform/CalculationValue.cpp: Added.

(WebCore):

  • platform/CalculationValue.h: Added.

(WebCore):
():

Location:
trunk/Source/WebCore
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r106156 r106166  
    433433    css/CSSBorderImage.cpp
    434434    css/CSSBorderImageSliceValue.cpp
     435    css/CSSCalculationValue.cpp
    435436    css/CSSCanvasValue.cpp
    436437    css/CSSCharsetRule.cpp
     
    10461047
    10471048    platform/Arena.cpp
     1049    platform/CalculationValue.cpp
    10481050    platform/Clock.cpp
    10491051    platform/ContextMenu.cpp
  • trunk/Source/WebCore/ChangeLog

    r106163 r106166  
     12012-01-27  Mike Lawther  <mikelawther@chromium.org>
     2
     3        CSS calc parsing stage
     4        https://bugs.webkit.org/show_bug.cgi?id=57082
     5
     6        This is the parsing stage of calc. The expressions are evaluated and
     7        expression trees are generated. CSS values are not created yet - that
     8        will happen in a subsequent commit.
     9
     10        Reviewed by David Hyatt.
     11
     12        No functional change - covered by existing tests in LayoutTests/css3/calc.
     13
     14        * CMakeLists.txt:
     15        * GNUmakefile.list.am:
     16        * Target.pri:
     17        * WebCore.gypi:
     18        * WebCore.vcproj/WebCore.vcproj:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * css/CSSCalculationValue.cpp: Added.
     21        (WebCore):
     22        (WebCore::unitCategory):
     23        (WebCore::CSSCalcValue::customCssText):
     24        (WebCore::CSSCalcExpressionNode::~CSSCalcExpressionNode):
     25        (CSSCalcPrimitiveValue):
     26        (WebCore::CSSCalcPrimitiveValue::create):
     27        (WebCore::CSSCalcPrimitiveValue::cssText):
     28        (WebCore::CSSCalcPrimitiveValue::CSSCalcPrimitiveValue):
     29        ():
     30        (CSSCalcBinaryOperation):
     31        (WebCore::CSSCalcBinaryOperation::create):
     32        (WebCore::CSSCalcBinaryOperation::CSSCalcBinaryOperation):
     33        (WebCore::checkDepthAndIndex):
     34        (CSSCalcExpressionNodeParser):
     35        (WebCore::CSSCalcExpressionNodeParser::parseCalc):
     36        (Value):
     37        (WebCore::CSSCalcExpressionNodeParser::operatorValue):
     38        (WebCore::CSSCalcExpressionNodeParser::parseValue):
     39        (WebCore::CSSCalcExpressionNodeParser::parseValueTerm):
     40        (WebCore::CSSCalcExpressionNodeParser::parseValueMultiplicativeExpression):
     41        (WebCore::CSSCalcExpressionNodeParser::parseAdditiveValueExpression):
     42        (WebCore::CSSCalcExpressionNodeParser::parseValueExpression):
     43        (WebCore::CSSCalcValue::create):
     44        * css/CSSCalculationValue.h: Added.
     45        (WebCore):
     46        ():
     47        (CSSCalcExpressionNode):
     48        (WebCore::CSSCalcExpressionNode::category):
     49        (WebCore::CSSCalcExpressionNode::isInt):
     50        (WebCore::CSSCalcExpressionNode::isZero):
     51        (WebCore::CSSCalcExpressionNode::CSSCalcExpressionNode):
     52        (CSSCalcValue):
     53        (WebCore::CSSCalcValue::category):
     54        (WebCore::CSSCalcValue::isInt):
     55        (WebCore::CSSCalcValue::CSSCalcValue):
     56        * css/CSSParser.cpp:
     57        (WebCore::CSSParser::validCalculationUnit):
     58        (WebCore):
     59        (WebCore::CSSParser::validUnit):
     60        (WebCore::CSSParser::createPrimitiveNumericValue):
     61        (WebCore::CSSParser::parseValidPrimitive):
     62        (WebCore::CSSParser::parseValue):
     63        (WebCore::CSSParser::parseFillPositionComponent):
     64        (WebCore::CSSParser::parsedDouble):
     65        (WebCore::CSSParser::isCalculation):
     66        (WebCore::CSSParser::colorIntFromValue):
     67        (WebCore::CSSParser::parseColorParameters):
     68        (WebCore::CSSParser::parseHSLParameters):
     69        (WebCore::ShadowParseContext::ShadowParseContext):
     70        (WebCore::ShadowParseContext::commitLength):
     71        (WebCore::ShadowParseContext::commitStyle):
     72        (ShadowParseContext):
     73        (WebCore::CSSParser::parseShadow):
     74        (WebCore::BorderImageSliceParseContext::BorderImageSliceParseContext):
     75        (WebCore::BorderImageSliceParseContext::commitNumber):
     76        (WebCore::BorderImageSliceParseContext::commitBorderImageSlice):
     77        (BorderImageSliceParseContext):
     78        (WebCore::CSSParser::parseBorderImageSlice):
     79        (WebCore::BorderImageQuadParseContext::BorderImageQuadParseContext):
     80        (WebCore::BorderImageQuadParseContext::commitNumber):
     81        (WebCore::BorderImageQuadParseContext::commitBorderImageQuad):
     82        (BorderImageQuadParseContext):
     83        (WebCore::CSSParser::parseBorderImageQuad):
     84        (WebCore::CSSParser::parseCalculation):
     85        * css/CSSParser.h:
     86        ():
     87        (CSSParser):
     88        * css/CSSValue.cpp:
     89        (WebCore::CSSValue::cssText):
     90        (WebCore::CSSValue::destroy):
     91        * css/CSSValue.h:
     92        (WebCore::CSSValue::isCalculationValue):
     93        ():
     94        * css/SVGCSSParser.cpp:
     95        (WebCore::CSSParser::parseSVGValue):
     96        * platform/CalculationValue.cpp: Added.
     97        (WebCore):
     98        * platform/CalculationValue.h: Added.
     99        (WebCore):
     100        ():
     101
    11022012-01-27  Anders Carlsson  <andersca@apple.com>
    2103
  • trunk/Source/WebCore/GNUmakefile.list.am

    r106156 r106166  
    12921292        Source/WebCore/css/CSSCharsetRule.cpp \
    12931293        Source/WebCore/css/CSSCharsetRule.h \
     1294        Source/WebCore/css/CSSCalculationValue.cpp \
     1295        Source/WebCore/css/CSSCalculationValue.h \
    12941296        Source/WebCore/css/CSSComputedStyleDeclaration.cpp \
    12951297        Source/WebCore/css/CSSComputedStyleDeclaration.h \
     
    27972799        Source/WebCore/platform/AsyncFileSystem.h \
    27982800        Source/WebCore/platform/AutodrainedPool.h \
     2801        Source/WebCore/platform/CalculationValue.cpp \
     2802        Source/WebCore/platform/CalculationValue.h \
    27992803        Source/WebCore/platform/Clock.cpp \
    28002804        Source/WebCore/platform/Clock.h \
  • trunk/Source/WebCore/Target.pri

    r106156 r106166  
    396396    css/CSSBorderImageSliceValue.cpp \
    397397    css/CSSBorderImage.cpp \
     398    css/CSSCalculationValue.cpp \
    398399    css/CSSCanvasValue.cpp \
    399400    css/CSSCharsetRule.cpp \
     
    10281029    platform/text/LocalizedNumberNone.cpp \
    10291030    platform/text/QuotedPrintable.cpp \
     1031    platform/CalculationValue.cpp \
    10301032    platform/Clock.cpp \
    10311033    platform/ClockGeneric.cpp \
     
    15081510    css/CSSAspectRatioValue.h \
    15091511    css/CSSBorderImageSliceValue.h \
     1512    css/CSSBorderImageValue.h \
    15101513    css/CSSBorderImage.h \
     1514    css/CSSBorderImageValue.h \
     1515    css/CSSCalculationValue.h \
    15111516    css/CSSCanvasValue.h \
    15121517    css/CSSCharsetRule.h \
     
    20782083    platform/Arena.h \
    20792084    platform/AsyncFileStream.h \
     2085    platform/CalculationValue.h \
    20802086    platform/Clock.h \
    20812087    platform/ClockGeneric.h \
  • trunk/Source/WebCore/WebCore.gypi

    r106156 r106166  
    19851985            'css/CSSCanvasValue.cpp',
    19861986            'css/CSSCanvasValue.h',
     1987            'css/CSSCalculationValue.cpp',
     1988            'css/CSSCalculationValue.h',
    19871989            'css/CSSCharsetRule.cpp',
    19881990            'css/CSSCharsetRule.h',
     
    27172719            'platform/AsyncFileSystemCallbacks.h',
    27182720            'platform/AutodrainedPool.h',
     2721            'platform/CalculationValue.cpp',
     2722            'platform/CalculationValue.h',
    27192723            'platform/Clock.cpp',
    27202724            'platform/Clock.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r106156 r106166  
    2646326463                        </File>
    2646426464                        <File
     26465                                RelativePath="..\platform\CalculationValue.cpp"
     26466                                >
     26467                        </File>
     26468                        <File
     26469                                RelativePath="..\platform\CalculationValue.h"
     26470                                >
     26471                        </File>
     26472                        <File
    2646526473                                RelativePath="..\platform\Clock.cpp"
    2646626474                                >
     
    3280732815                        </File>
    3280832816                        <File
     32817                                RelativePath="..\css\CSSCalculationValue.cpp"
     32818                                >
     32819                        </File>
     32820                        <File
     32821                                RelativePath="..\css\CSSCalculationValue.h"
     32822                                >
     32823                        </File>
     32824                        <File
    3280932825                                RelativePath="..\css\CSSCanvasValue.cpp"
    3281032826                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r106156 r106166  
    12291229                499B3ED7128CD31400E726C2 /* GraphicsLayerCA.h in Headers */ = {isa = PBXBuildFile; fileRef = 499B3ED5128CD31400E726C2 /* GraphicsLayerCA.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12301230                499B3EDD128DB50200E726C2 /* PlatformCAAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 499B3EDC128DB50100E726C2 /* PlatformCAAnimation.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1231                49AE2D8E134EE50C0072920A /* CSSCalculationValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49AE2D8C134EE50C0072920A /* CSSCalculationValue.cpp */; };
     1232                49AE2D8F134EE50C0072920A /* CSSCalculationValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 49AE2D8D134EE50C0072920A /* CSSCalculationValue.h */; };
     1233                49AE2D96134EE5F90072920A /* CalculationValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49AE2D94134EE5F90072920A /* CalculationValue.cpp */; };
     1234                49AE2D97134EE5F90072920A /* CalculationValue.h in Headers */ = {isa = PBXBuildFile; fileRef = 49AE2D95134EE5F90072920A /* CalculationValue.h */; };
    12311235                49AF2D6914435D050016A784 /* DisplayRefreshMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 49AF2D6814435D050016A784 /* DisplayRefreshMonitor.h */; };
    12321236                49AF2D6C14435D210016A784 /* DisplayRefreshMonitorMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49AF2D6B14435D210016A784 /* DisplayRefreshMonitorMac.cpp */; };
     
    80358039                499B3ED5128CD31400E726C2 /* GraphicsLayerCA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GraphicsLayerCA.h; path = ca/GraphicsLayerCA.h; sourceTree = "<group>"; };
    80368040                499B3EDC128DB50100E726C2 /* PlatformCAAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformCAAnimation.h; path = ca/PlatformCAAnimation.h; sourceTree = "<group>"; };
     8041                49AE2D8C134EE50C0072920A /* CSSCalculationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSCalculationValue.cpp; sourceTree = "<group>"; };
     8042                49AE2D8D134EE50C0072920A /* CSSCalculationValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSCalculationValue.h; sourceTree = "<group>"; };
     8043                49AE2D94134EE5F90072920A /* CalculationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CalculationValue.cpp; sourceTree = "<group>"; };
     8044                49AE2D95134EE5F90072920A /* CalculationValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CalculationValue.h; sourceTree = "<group>"; };
    80378045                49AF2D6814435D050016A784 /* DisplayRefreshMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisplayRefreshMonitor.h; sourceTree = "<group>"; };
    80388046                49AF2D6B14435D210016A784 /* DisplayRefreshMonitorMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DisplayRefreshMonitorMac.cpp; sourceTree = "<group>"; };
     
    1959519603                                89D08D9E12228451001241DF /* AsyncFileSystemCallbacks.h */,
    1959619604                                51E1ECB10C91C55600DC255B /* AutodrainedPool.h */,
     19605                                49AE2D94134EE5F90072920A /* CalculationValue.cpp */,
     19606                                49AE2D95134EE5F90072920A /* CalculationValue.h */,
    1959719607                                CDEA76331460B462008B31F1 /* Clock.cpp */,
    1959819608                                CDEA762C14608224008B31F1 /* Clock.h */,
     
    1990619916                                BC274B30140EBED800EADFA6 /* CSSBorderImageSliceValue.cpp */,
    1990719917                                BC274B2E140EBEB200EADFA6 /* CSSBorderImageSliceValue.h */,
     19918                                49AE2D8C134EE50C0072920A /* CSSCalculationValue.cpp */,
     19919                                49AE2D8D134EE50C0072920A /* CSSCalculationValue.h */,
    1990819920                                BC604A420DB5634E00204739 /* CSSCanvasValue.cpp */,
    1990919921                                BC6049CB0DB560C200204739 /* CSSCanvasValue.h */,
     
    2114521157                                BCB16C280979C3BD00467741 /* CachedXSLStyleSheet.h in Headers */,
    2114621158                                93F1995008245E59001E9ABC /* CachePolicy.h in Headers */,
     21159                                49AE2D97134EE5F90072920A /* CalculationValue.h in Headers */,
    2114721160                                B1D5ECB5134B58DA0087C78F /* CallbackFunction.h in Headers */,
    2114821161                                6E4E91AD10F7FB3100A2779C /* CanvasContextAttributes.h in Headers */,
     
    2123321246                                E16A84FA14C85CCC002977DF /* CSSBorderImage.h in Headers */,
    2123421247                                BC274B2F140EBEB200EADFA6 /* CSSBorderImageSliceValue.h in Headers */,
     21248                                49AE2D8F134EE50C0072920A /* CSSCalculationValue.h in Headers */,
    2123521249                                BC6049CC0DB560C200204739 /* CSSCanvasValue.h in Headers */,
    2123621250                                A80E6CF90A1989CA007FB8C5 /* CSSCharsetRule.h in Headers */,
     
    2417024184                        isa = PBXProject;
    2417124185                        attributes = {
     24186                                BuildIndependentTargetsInParallel = YES;
    2417224187                                LastUpgradeCheck = 0440;
    2417324188                        };
     
    2456024575                                0753860214489E9800B78452 /* CachedTextTrack.cpp in Sources */,
    2456124576                                BCB16C270979C3BD00467741 /* CachedXSLStyleSheet.cpp in Sources */,
     24577                                49AE2D96134EE5F90072920A /* CalculationValue.cpp in Sources */,
    2456224578                                B1827493134CA4C100B98C2D /* CallbackFunction.cpp in Sources */,
    2456324579                                6E4E91AC10F7FB3100A2779C /* CanvasContextAttributes.cpp in Sources */,
     
    2463524651                                E16A84F914C85CCC002977DF /* CSSBorderImage.cpp in Sources */,
    2463624652                                BC274B31140EBED800EADFA6 /* CSSBorderImageSliceValue.cpp in Sources */,
     24653                                49AE2D8E134EE50C0072920A /* CSSCalculationValue.cpp in Sources */,
    2463724654                                BC604A430DB5634E00204739 /* CSSCanvasValue.cpp in Sources */,
    2463824655                                E1EBBBD40AAC9B87001FE8E2 /* CSSCharsetRule.cpp in Sources */,
  • trunk/Source/WebCore/css/CSSParser.cpp

    r105901 r106166  
    693693}
    694694
     695bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags)
     696{
     697    if (!parseCalculation(value))
     698        return false;
     699
     700    bool b = false;
     701    switch (m_parsedCalculation->category()) {
     702    case CalcLength:
     703        b = (unitflags & FLength);
     704        break;
     705    case CalcPercent:
     706        b = (unitflags & FPercent);
     707        // FIXME calc (http://webkit.org/b/16662): test FNonNeg here, eg
     708        // if (b && (unitflags & FNonNeg) && m_parsedCalculation->doubleValue() < 0)
     709        //    b = false;
     710        break;
     711    case CalcNumber:
     712        b = (unitflags & FNumber);
     713        if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
     714            b = true;
     715        // FIXME calc (http://webkit.org/b/16662): test FNonNeg here, eg
     716        // if (b && (unitflags & FNonNeg) && m_parsedCalculation->doubleValue() < 0)
     717        //    b = false;
     718        break;
     719    case CalcPercentLength:
     720        b = (unitflags & FPercent) && (unitflags & FLength);
     721        break;
     722    case CalcPercentNumber:
     723        b = (unitflags & FPercent) && (unitflags & FNumber);
     724        break;
     725    case CalcOther:
     726        break;
     727    }
     728    if (!b)
     729        m_parsedCalculation.release();
     730    return b;   
     731}
     732
    695733bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, bool strict)
    696734{
     735    if (isCalculation(value))
     736        return validCalculationUnit(value, unitflags);
     737       
    697738    bool b = false;
    698739    switch (value->unit) {
    699740    case CSSPrimitiveValue::CSS_NUMBER:
    700741        b = (unitflags & FNumber);
    701         if (!b && ((unitflags & (FLength | FAngle | FTime)) && (value->fValue == 0 || !strict))) {
     742        if (!b && ((unitflags & (FLength | FAngle | FTime)) && (!value->fValue || !strict))) {
    702743            value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX :
    703744                          ((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
     
    745786inline PassRefPtr<CSSPrimitiveValue> CSSParser::createPrimitiveNumericValue(CSSParserValue* value)
    746787{
     788    if (m_parsedCalculation) {
     789        ASSERT(isCalculation(value));
     790        // FIXME calc() http://webkit.org/b/16662: create a CSSPrimitiveValue here, ie
     791        // return CSSPrimitiveValue::create(m_parsedCalculation.release());
     792        m_parsedCalculation.release();
     793        return 0;
     794    }
     795               
    747796    ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
    748797           || (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_REMS));
     
    842891    if (value->unit >= CSSParserValue::Q_EMS)
    843892        return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
     893    if (isCalculation(value))
     894        // FIXME calc()  http://webkit.org/b/16662: create a primitive value here, ie
     895        // return CSSPrimitiveValue::create(m_parsedCalculation.release());
     896        m_parsedCalculation.release();
     897
    844898    return 0;
    845899}
     
    855909        return false;
    856910
     911    // Note: m_parsedCalculation is used to pass the calc value to validUnit and then cleared at the end of this function.
     912    // FIXME: This is to avoid having to pass parsedCalc to all validUnit callers.
     913    ASSERT(!m_parsedCalculation);
     914   
    857915    int id = value->id;
    858916
     
    22822340        m_valueList->next();
    22832341    }
     2342    ASSERT(!m_parsedCalculation);
    22842343    if (parsedValue) {
    22852344        if (!m_valueList->current() || inShorthand()) {
     
    29893048            cumulativeFlags |= YFillPosition;
    29903049            individualFlag = YFillPosition;
    2991         } else
     3050        } else {
     3051            if (m_parsedCalculation)
     3052                m_parsedCalculation.release();
    29923053            return 0;
     3054        }
    29933055        return createPrimitiveNumericValue(valueList->current());
    29943056    }
     
    48724934    return false;
    48734935}
    4874 
    4875 static inline int colorIntFromValue(CSSParserValue* v)
    4876 {
    4877     if (v->fValue <= 0.0)
     4936   
     4937inline double CSSParser::parsedDouble(CSSParserValue *v, ReleaseParsedCalcValueCondition releaseCalc)
     4938{
     4939    // FIXME calc (http://webkit.org/b/16662): evaluate calc here, eg
     4940    // const double result = m_parsedCalculation ? m_parsedCalculation->doubleValue() : v->fValue;
     4941    const double result = m_parsedCalculation ? 0 : v->fValue;
     4942    if (releaseCalc == ReleaseParsedCalcValue)
     4943        m_parsedCalculation.release();
     4944    return result;
     4945}
     4946
     4947bool CSSParser::isCalculation(CSSParserValue* value)
     4948{
     4949    return (value->unit == CSSParserValue::Function)
     4950        && (equalIgnoringCase(value->function->name, "-webkit-calc(")
     4951            || equalIgnoringCase(value->function->name, "-webkit-min(")
     4952            || equalIgnoringCase(value->function->name, "-webkit-max("));
     4953}
     4954
     4955inline int CSSParser::colorIntFromValue(CSSParserValue* v)
     4956{
     4957    bool isPercent;
     4958   
     4959    if (m_parsedCalculation)
     4960        isPercent = m_parsedCalculation->category() == CalcPercent;
     4961    else
     4962        isPercent = v->unit == CSSPrimitiveValue::CSS_PERCENTAGE;
     4963
     4964    const double value = parsedDouble(v, ReleaseParsedCalcValue);
     4965   
     4966    if (value <= 0.0)
    48784967        return 0;
    48794968
    4880     if (v->unit == CSSPrimitiveValue::CSS_PERCENTAGE) {
    4881         if (v->fValue >= 100.0)
     4969    if (isPercent) {
     4970        if (value >= 100.0)
    48824971            return 255;
    4883         return static_cast<int>(v->fValue * 256.0 / 100.0);
    4884     }
    4885 
    4886     if (v->fValue >= 255.0)
     4972        return static_cast<int>(value * 256.0 / 100.0);
     4973    }
     4974
     4975    if (value >= 255.0)
    48874976        return 255;
    48884977
    4889     return static_cast<int>(v->fValue);
     4978    return static_cast<int>(value);
    48904979}
    48914980
     
    49024991    else
    49034992        return false;
     4993   
    49044994    colorArray[0] = colorIntFromValue(v);
    49054995    for (int i = 1; i < 3; i++) {
     
    49195009        if (!validUnit(v, FNumber, true))
    49205010            return false;
     5011        const double value = parsedDouble(v, ReleaseParsedCalcValue);
    49215012        // Convert the floating pointer number of alpha to an integer in the range [0, 256),
    49225013        // with an equal distribution across all 256 values.
    4923         colorArray[3] = static_cast<int>(max(0.0, min(1.0, v->fValue)) * nextafter(256.0, 0.0));
     5014        colorArray[3] = static_cast<int>(max(0.0, min(1.0, value)) * nextafter(256.0, 0.0));
    49245015    }
    49255016    return true;
     
    49395030        return false;
    49405031    // normalize the Hue value and change it to be between 0 and 1.0
    4941     colorArray[0] = (((static_cast<int>(v->fValue) % 360) + 360) % 360) / 360.0;
     5032    colorArray[0] = (((static_cast<int>(parsedDouble(v, ReleaseParsedCalcValue)) % 360) + 360) % 360) / 360.0;
    49425033    for (int i = 1; i < 3; i++) {
    49435034        v = args->next();
     
    49475038        if (!validUnit(v, FPercent, true))
    49485039            return false;
    4949         colorArray[i] = max(0.0, min(100.0, v->fValue)) / 100.0; // needs to be value between 0 and 1.0
     5040        colorArray[i] = max(0.0, min(100.0, parsedDouble(v, ReleaseParsedCalcValue))) / 100.0; // needs to be value between 0 and 1.0
    49505041    }
    49515042    if (parseAlpha) {
     
    49565047        if (!validUnit(v, FNumber, true))
    49575048            return false;
    4958         colorArray[3] = max(0.0, min(1.0, v->fValue));
     5049        colorArray[3] = max(0.0, min(1.0, parsedDouble(v, ReleaseParsedCalcValue)));
    49595050    }
    49605051    return true;
     
    50245115// without the allowBreak bit being set, then it will clean up all of the objects and destroy them.
    50255116struct ShadowParseContext {
    5026     ShadowParseContext(CSSPropertyID prop, CSSValuePool* cssValuePool)
     5117    ShadowParseContext(CSSPropertyID prop, CSSParser* parser)
    50275118        : property(prop)
    5028         , m_cssValuePool(cssValuePool)
     5119        , m_parser(parser)
    50295120        , allowX(true)
    50305121        , allowY(false)
     
    50695160    void commitLength(CSSParserValue* v)
    50705161    {
    5071         RefPtr<CSSPrimitiveValue> val = m_cssValuePool->createValue(v->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(v->unit));
     5162        RefPtr<CSSPrimitiveValue> val = m_parser->createPrimitiveNumericValue(v);
    50725163
    50735164        if (allowX) {
     
    51115202    void commitStyle(CSSParserValue* v)
    51125203    {
    5113         style = m_cssValuePool->createIdentifierValue(v->id);
     5204        style = m_parser->cssValuePool()->createIdentifierValue(v->id);
    51145205        allowStyle = false;
    51155206        if (allowX)
     
    51235214
    51245215    CSSPropertyID property;
    5125     CSSValuePool* m_cssValuePool;
     5216    CSSParser* m_parser;
    51265217
    51275218    RefPtr<CSSValueList> values;
     
    51445235PassRefPtr<CSSValueList> CSSParser::parseShadow(CSSParserValueList* valueList, int propId)
    51455236{
    5146     ShadowParseContext context(static_cast<CSSPropertyID>(propId), cssValuePool());
     5237    ShadowParseContext context(static_cast<CSSPropertyID>(propId), this);
    51475238    CSSParserValue* val;
    51485239    while ((val = valueList->current())) {
     
    55285619class BorderImageSliceParseContext {
    55295620public:
    5530     BorderImageSliceParseContext(CSSValuePool* cssValuePool)
    5531     : m_cssValuePool(cssValuePool)
     5621    BorderImageSliceParseContext(CSSParser* parser)
     5622    : m_parser(parser)
    55325623    , m_allowNumber(true)
    55335624    , m_allowFill(false)
     
    55435634    void commitNumber(CSSParserValue* v)
    55445635    {
    5545         RefPtr<CSSPrimitiveValue> val = m_cssValuePool->createValue(v->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(v->unit));
     5636        RefPtr<CSSPrimitiveValue> val = m_parser->createPrimitiveNumericValue(v);
    55465637        if (!m_top)
    55475638            m_top = val;
     
    55895680
    55905681        // Make our new border image value now.
    5591         return CSSBorderImageSliceValue::create(m_cssValuePool->createValue(quad.release()), m_fill);
     5682        return CSSBorderImageSliceValue::create(m_parser->cssValuePool()->createValue(quad.release()), m_fill);
    55925683    }
    55935684
    55945685private:
    5595     CSSValuePool* m_cssValuePool;
     5686    CSSParser* m_parser;
    55965687
    55975688    bool m_allowNumber;
     
    56095700bool CSSParser::parseBorderImageSlice(int propId, RefPtr<CSSBorderImageSliceValue>& result)
    56105701{
    5611     BorderImageSliceParseContext context(cssValuePool());
     5702    BorderImageSliceParseContext context(this);
    56125703    CSSParserValue* val;
    56135704    while ((val = m_valueList->current())) {
    5614         if (context.allowNumber() && validUnit(val, FInteger | FNonNeg | FPercent, true)) {
     5705        // FIXME calc() http://webkit.org/b/16662 : calc is parsed but values are not created yet.
     5706        if (context.allowNumber() && !isCalculation(val) && validUnit(val, FInteger | FNonNeg | FPercent, true)) {
    56155707            context.commitNumber(val);
    56165708        } else if (context.allowFill() && val->id == CSSValueFill)
     
    56455737class BorderImageQuadParseContext {
    56465738public:
    5647     BorderImageQuadParseContext(CSSValuePool* cssValuePool)
    5648     : m_cssValuePool(cssValuePool)
     5739    BorderImageQuadParseContext(CSSParser* parser)
     5740    : m_parser(parser)
    56495741    , m_allowNumber(true)
    56505742    , m_allowFinalCommit(false)
     
    56595751        RefPtr<CSSPrimitiveValue> val;
    56605752        if (v->id == CSSValueAuto)
    5661             val = m_cssValuePool->createIdentifierValue(v->id);
     5753            val = m_parser->cssValuePool()->createIdentifierValue(v->id);
    56625754        else
    5663             val = m_cssValuePool->createValue(v->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(v->unit));
     5755            val = m_parser->createPrimitiveNumericValue(v);
    56645756
    56655757        if (!m_top)
     
    57055797
    57065798        // Make our new value now.
    5707         return m_cssValuePool->createValue(quad.release());
     5799        return m_parser->cssValuePool()->createValue(quad.release());
    57085800    }
    57095801
    57105802private:
    5711     CSSValuePool* m_cssValuePool;
     5803    CSSParser* m_parser;
    57125804
    57135805    bool m_allowNumber;
     
    57225814bool CSSParser::parseBorderImageQuad(Units validUnits, RefPtr<CSSPrimitiveValue>& result)
    57235815{
    5724     BorderImageQuadParseContext context(cssValuePool());
     5816    BorderImageQuadParseContext context(this);
    57255817    CSSParserValue* val;
    57265818    while ((val = m_valueList->current())) {
     
    73267418}
    73277419
     7420bool CSSParser::parseCalculation(CSSParserValue* value)
     7421{
     7422    ASSERT(isCalculation(value));
     7423   
     7424    CSSParserValueList* args = value->function->args.get();
     7425    if (!args || !args->size())
     7426        return false;
     7427
     7428    ASSERT(!m_parsedCalculation);
     7429    m_parsedCalculation = CSSCalcValue::create(value->function->name, args);
     7430   
     7431    if (!m_parsedCalculation)
     7432        return false;
     7433   
     7434    return true;
     7435}
     7436   
    73287437static inline int yyerror(const char*) { return 1; }
    73297438
  • trunk/Source/WebCore/css/CSSParser.h

    r105901 r106166  
    2424#define CSSParser_h
    2525
     26#include "CSSCalculationValue.h"
    2627#include "CSSGradientValue.h"
    2728#include "CSSParserValues.h"
     
    212213
    213214    bool parseLineBoxContain(bool important);
     215    bool parseCalculation(CSSParserValue*);
    214216
    215217    bool parseFontFeatureTag(CSSValueList*);
     
    323325    int lex();
    324326
     327    PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*);
     328    PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*);
     329       
    325330private:
    326331    void setStyleSheet(CSSStyleSheet*);
     
    388393    Vector<OwnPtr<CSSParserSelector> > m_reusableSelectorVector;
    389394    Vector<OwnPtr<CSSParserSelector> > m_reusableRegionSelectorVector;
     395
     396    RefPtr<CSSCalcValue> m_parsedCalculation;
    390397
    391398    // defines units allowed for a certain property, used in parseUnit
     
    408415    }
    409416
    410     static bool validUnit(CSSParserValue*, Units, bool strict);
     417    bool validCalculationUnit(CSSParserValue*, Units);
     418    bool validUnit(CSSParserValue*, Units, bool strict);
    411419
    412420    bool parseBorderImageQuad(Units, RefPtr<CSSPrimitiveValue>&);
    413 
    414     PassRefPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*);
    415     PassRefPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*);
    416 
     421    int colorIntFromValue(CSSParserValue*);
     422
     423    enum ReleaseParsedCalcValueCondition {
     424        ReleaseParsedCalcValue,
     425        DoNotReleaseParsedCalcValue
     426    };   
     427    double parsedDouble(CSSParserValue*, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
     428    bool isCalculation(CSSParserValue*);
     429   
    417430    friend class TransformOperationInfo;
    418431#if ENABLE(CSS_FILTERS)
  • trunk/Source/WebCore/css/CSSValue.cpp

    r105502 r106166  
    3030#include "CSSAspectRatioValue.h"
    3131#include "CSSBorderImageSliceValue.h"
     32#include "CSSCalculationValue.h"
    3233#include "CSSCanvasValue.h"
    3334#include "CSSCrossfadeValue.h"
     
    150151    case FlexClass:
    151152        return static_cast<const CSSFlexValue*>(this)->customCssText();
     153    case CalculationClass:
     154        return static_cast<const CSSCalcValue*>(this)->customCssText();
    152155#if ENABLE(CSS_FILTERS)
    153156    case WebKitCSSFilterClass:
     
    250253        delete static_cast<CSSFlexValue*>(this);
    251254        return;
     255    case CalculationClass:
     256        delete static_cast<CSSCalcValue*>(this);
     257        return;
    252258#if ENABLE(CSS_FILTERS)
    253259    case WebKitCSSFilterClass:
  • trunk/Source/WebCore/css/CSSValue.h

    r105502 r106166  
    7777    bool isCSSLineBoxContainValue() const { return m_classType == LineBoxContainClass; }
    7878    bool isFlexValue() const { return m_classType == FlexClass; }
     79    bool isCalculationValue() const {return m_classType == CalculationClass; }
    7980#if ENABLE(CSS_FILTERS)
    8081    bool isWebKitCSSFilterValue() const { return m_classType == WebKitCSSFilterClass; }
     
    127128        LineBoxContainClass,
    128129        FlexClass,
     130        CalculationClass,
    129131#if ENABLE(CSS_FILTERS) && ENABLE(CSS_SHADERS)
    130132        WebKitCSSShaderClass,
  • trunk/Source/WebCore/css/SVGCSSParser.cpp

    r103692 r106166  
    315315        else if (value->unit >= CSSParserValue::Q_EMS)
    316316            parsedValue = CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
     317        if (isCalculation(value)) {
     318            // FIXME calc() http://webkit.org/b/16662 : actually create a CSSPrimitiveValue here, ie
     319            // parsedValue = CSSPrimitiveValue::create(m_parsedCalculation.release());
     320            m_parsedCalculation.release();
     321            parsedValue = 0;
     322        }
    317323        m_valueList->next();
    318324    }
Note: See TracChangeset for help on using the changeset viewer.