Changeset 108750 in webkit


Ignore:
Timestamp:
Feb 24, 2012 1:33:28 AM (12 years ago)
Author:
mikelawther@chromium.org
Message:

CSS3 calc(): handle non-negative values
https://bugs.webkit.org/show_bug.cgi?id=79188

Reviewed by Daniel Bates.

Source/WebCore:

Some CSS properties (e.g. padding) are required to be non-negative. These
are now restricted to the correct range.

Tests: css3/calc/negative-padding-expected.html

css3/calc/negative-padding.html

  • css/CSSCalculationValue.cpp:

(WebCore):
(WebCore::CSSCalcValue::clampToPermittedRange): Added
(WebCore::CSSCalcValue::doubleValue):
(WebCore::CSSCalcValue::isNegative): Added
(WebCore::CSSCalcValue::computeLengthPx):
(WebCore::CSSCalcValue::create):

  • css/CSSCalculationValue.h:

(CSSCalcValue):
(WebCore::CSSCalcValue::CSSCalcValue):

  • css/CSSParser.cpp:

(WebCore::CSSParser::validCalculationUnit):
(WebCore::CSSParser::parseCalculation):

  • css/CSSParser.h:
  • platform/CalculationValue.h:

LayoutTests:

  • css3/calc/negative-padding-expected.html: Added.
  • css3/calc/negative-padding.html: Added.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r108749 r108750  
     12012-02-24  Mike Lawther  <mikelawther@chromium.org>
     2
     3        CSS3 calc(): handle non-negative values
     4        https://bugs.webkit.org/show_bug.cgi?id=79188
     5
     6        Reviewed by Daniel Bates.
     7
     8        * css3/calc/negative-padding-expected.html: Added.
     9        * css3/calc/negative-padding.html: Added.
     10
    1112012-02-22  Vsevolod Vlasov  <vsevik@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r108749 r108750  
     12012-02-24  Mike Lawther  <mikelawther@chromium.org>
     2
     3        CSS3 calc(): handle non-negative values
     4        https://bugs.webkit.org/show_bug.cgi?id=79188
     5
     6        Reviewed by Daniel Bates.
     7
     8        Some CSS properties (e.g. padding) are required to be non-negative. These
     9        are now restricted to the correct range.
     10
     11        Tests: css3/calc/negative-padding-expected.html
     12               css3/calc/negative-padding.html
     13
     14        * css/CSSCalculationValue.cpp:
     15        (WebCore):
     16        (WebCore::CSSCalcValue::clampToPermittedRange): Added
     17        (WebCore::CSSCalcValue::doubleValue):
     18        (WebCore::CSSCalcValue::isNegative): Added
     19        (WebCore::CSSCalcValue::computeLengthPx):
     20        (WebCore::CSSCalcValue::create):
     21        * css/CSSCalculationValue.h:
     22        (CSSCalcValue):
     23        (WebCore::CSSCalcValue::CSSCalcValue):
     24        * css/CSSParser.cpp:
     25        (WebCore::CSSParser::validCalculationUnit):
     26        (WebCore::CSSParser::parseCalculation):
     27        * css/CSSParser.h:
     28        * platform/CalculationValue.h:
     29
    1302012-02-22  Vsevolod Vlasov  <vsevik@chromium.org>
    231
  • trunk/Source/WebCore/css/CSSCalculationValue.cpp

    r107724 r108750  
    7777    return "";
    7878}
    79 
     79   
     80double CSSCalcValue::clampToPermittedRange(double value) const
     81{
     82    return m_nonNegative && value < 0 ? 0 : value;
     83}   
     84   
    8085double CSSCalcValue::doubleValue() const
    8186{
    82     return m_expression->doubleValue();
    83 }
    84    
     87    return clampToPermittedRange(m_expression->doubleValue());
     88}
     89
    8590double CSSCalcValue::computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize) const
    8691{
    87     return m_expression->computeLengthPx(currentStyle, rootStyle, multiplier, computingFontSize);
     92    return clampToPermittedRange(m_expression->computeLengthPx(currentStyle, rootStyle, multiplier, computingFontSize));
    8893}
    8994   
     
    382387};
    383388
    384 PassRefPtr<CSSCalcValue> CSSCalcValue::create(CSSParserString name, CSSParserValueList* parserValueList)
     389PassRefPtr<CSSCalcValue> CSSCalcValue::create(CSSParserString name, CSSParserValueList* parserValueList, CalculationPermittedValueRange range)
    385390{   
    386391    CSSCalcExpressionNodeParser parser;   
     
    391396    // FIXME calc (http://webkit.org/b/16662) Add parsing for min and max here
    392397
    393     return expression ? adoptRef(new CSSCalcValue(expression)) : 0;
     398    return expression ? adoptRef(new CSSCalcValue(expression, range)) : 0;
    394399}
    395400
  • trunk/Source/WebCore/css/CSSCalculationValue.h

    r107724 r108750  
    6161    virtual ~CSSCalcExpressionNode() = 0; 
    6262    virtual bool isZero() const = 0;
    63     virtual double doubleValue() const = 0; 
     63    virtual double doubleValue() const = 0;
    6464    virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0;
    6565   
     
    8080class CSSCalcValue : public CSSValue {
    8181public:
    82     static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*);
     82    static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*, CalculationPermittedValueRange);
    8383
    8484    CalculationCategory category() const { return m_expression->category(); }
    8585    bool isInt() const { return m_expression->isInteger(); }   
    8686    double doubleValue() const;
     87    bool isNegative() const { return m_expression->doubleValue() < 0; }
    8788    double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const;
    8889       
     
    9091   
    9192private:   
    92     CSSCalcValue(PassRefPtr<CSSCalcExpressionNode> expression)
     93    CSSCalcValue(PassRefPtr<CSSCalcExpressionNode> expression, CalculationPermittedValueRange range)
    9394        : CSSValue(CalculationClass)
    9495        , m_expression(expression)
     96        , m_nonNegative(range == CalculationRangeNonNegative)
    9597    {
    9698    }
    9799   
     100    double clampToPermittedRange(double) const;
     101
    98102    const RefPtr<CSSCalcExpressionNode> m_expression;
     103    const bool m_nonNegative;
    99104};
    100105   
  • trunk/Source/WebCore/css/CSSParser.cpp

    r108451 r108750  
    712712bool CSSParser::validCalculationUnit(CSSParserValue* value, Units unitflags)
    713713{
    714     if (!parseCalculation(value))
     714    bool mustBeNonNegative = unitflags & FNonNeg;
     715
     716    if (!parseCalculation(value, mustBeNonNegative ? CalculationRangeNonNegative : CalculationRangeAll))
    715717        return false;
    716718
     
    722724    case CalcPercent:
    723725        b = (unitflags & FPercent);
    724         // FIXME calc (http://webkit.org/b/16662): test FNonNeg here, eg
    725         // if (b && (unitflags & FNonNeg) && m_parsedCalculation->doubleValue() < 0)
    726         //    b = false;
     726        if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
     727            b = false;
    727728        break;
    728729    case CalcNumber:
     
    730731        if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
    731732            b = true;
    732         // FIXME calc (http://webkit.org/b/16662): test FNonNeg here, eg
    733         // if (b && (unitflags & FNonNeg) && m_parsedCalculation->doubleValue() < 0)
    734         //    b = false;
     733        if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
     734            b = false;
    735735        break;
    736736    case CalcPercentLength:
     
    74207420}
    74217421
    7422 bool CSSParser::parseCalculation(CSSParserValue* value)
     7422bool CSSParser::parseCalculation(CSSParserValue* value, CalculationPermittedValueRange range)
    74237423{
    74247424    ASSERT(isCalculation(value));
     
    74297429
    74307430    ASSERT(!m_parsedCalculation);
    7431     m_parsedCalculation = CSSCalcValue::create(value->function->name, args);
     7431    m_parsedCalculation = CSSCalcValue::create(value->function->name, args, range);
    74327432   
    74337433    if (!m_parsedCalculation)
  • trunk/Source/WebCore/css/CSSParser.h

    r108451 r108750  
    210210
    211211    bool parseLineBoxContain(bool important);
    212     bool parseCalculation(CSSParserValue*);
     212    bool parseCalculation(CSSParserValue*, CalculationPermittedValueRange);
    213213
    214214    bool parseFontFeatureTag(CSSValueList*);
  • trunk/Source/WebCore/platform/CalculationValue.h

    r107259 r108750  
    4444    CalcSubtract = '-',
    4545    CalcMultiply = '*',
    46     CalcDivide = '/',
     46    CalcDivide = '/'
     47};
     48
     49enum CalculationPermittedValueRange {
     50    CalculationRangeAll,
     51    CalculationRangeNonNegative
    4752};
    4853
Note: See TracChangeset for help on using the changeset viewer.