Ignore:
Timestamp:
Mar 7, 2012, 10:48:35 PM (13 years ago)
Author:
[email protected]
Message:

CSS3 calc: mixed absolute/percentages work for width, height, margin and padding
https://bugs.webkit.org/show_bug.cgi?id=79621

Reviewed by Andreas Kling.

Source/WebCore:

ApplyPropertyLength in CSSStyleApplyPropery now handles mixed absolute/percentage
length expressions. All property handlers using this template now work with
mixed expressions.

This patch adds a new expression evaluator in CalculationValue.cpp. This is because
Length.[cpp|h] (in platform) cannot refer to CSSCalculationValue.[cpp|h] (in css)
due to layering restrictions.

Lengths can be copied, and so the expressions are stored in a hashmap, and only their
ids are copied along with Length. The expressions are RefCounted, and will get
cleaned up when the last referring Length is destructed.

  • WebCore.exp.in:
  • css/CSSCalculationValue.cpp:

(WebCore::CSSCalcPrimitiveValue::toCalcValue):
(CSSCalcPrimitiveValue):
(WebCore::CSSCalcBinaryOperation::toCalcValue):
(CSSCalcBinaryOperation):

  • css/CSSCalculationValue.h:

(WebCore):
(CSSCalcExpressionNode):
(CSSCalcValue):
(WebCore::CSSCalcValue::toCalcValue):

  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::CSSPrimitiveValue):

  • css/CSSStyleApplyProperty.cpp:

(WebCore::ApplyPropertyLength::applyValue):

  • css/CSSStyleSelector.cpp:

(WebCore::CSSStyleSelector::collectMatchingRulesForList):

  • css/CSSStyleSelector.h:

(CSSStyleSelector):

  • platform/CalculationValue.cpp:

(WebCore::CalcExpressionBinaryOperation::evaluate):
(WebCore):
(WebCore::CalculationValue::create):
(WebCore::CalculationValue::evaluate):

  • platform/CalculationValue.h:

(CalcExpressionNode):
(WebCore::CalcExpressionNode::~CalcExpressionNode):
(WebCore):
(CalculationValue):
(WebCore::CalculationValue::CalculationValue):
(CalcExpressionNumber):
(WebCore::CalcExpressionNumber::CalcExpressionNumber):
(WebCore::CalcExpressionNumber::evaluate):
(CalcExpressionLength):
(WebCore::CalcExpressionLength::CalcExpressionLength):
(WebCore::CalcExpressionLength::evaluate):
(CalcExpressionBinaryOperation):
(WebCore::CalcExpressionBinaryOperation::CalcExpressionBinaryOperation):

  • platform/Length.cpp:

(WebCore):
(WebCore::Length::~Length):
(CalculationValueHandleMap):
(WebCore::CalculationValueHandleMap::CalculationValueHandleMap):
(WebCore::CalculationValueHandleMap::insert):
(WebCore::CalculationValueHandleMap::remove):
(WebCore::CalculationValueHandleMap::get):
(WebCore::calcHandles):
(WebCore::Length::Length):
(WebCore::Length::calculationValue):
(WebCore::Length::calculatedValue):
(WebCore::Length::calculatedMinValue):
(WebCore::Length::calculatedFloatValue):
(WebCore::Length::incrementCalculatedRef):
(WebCore::Length::decrementCalculatedRef):
(WebCore::Length::nonNanCalculatedValue):

  • platform/Length.h:

(Length):
(WebCore::Length::Length):
(WebCore::Length::operator=):
(WebCore::Length::operator*=):
(WebCore::Length::value):
(WebCore::Length::setValue):
(WebCore::Length::calcValue):
(WebCore::Length::calcMinValue):
(WebCore::Length::calcFloatValue):
(WebCore::Length::isZero):
(WebCore::Length::isPositive):
(WebCore::Length::isNegative):
(WebCore::Length::isPercent):
(WebCore::Length::isSpecified):
(WebCore::Length::isCalculated):
(WebCore::Length::initFromLength):
(WebCore::Length::calculationHandle):

LayoutTests:

  • css3/calc/margin-expected.txt:
  • css3/calc/padding-expected.txt:
  • css3/calc/simple-calcs-expected.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSCalculationValue.h

    r110129 r110148  
    4444class CSSValueList;
    4545class RenderStyle;
    46 class CalcValue;
     46class CalculationValue;
    4747class CalcExpressionNode;
    4848
     
    5959public:
    6060   
    61     virtual ~CSSCalcExpressionNode() = 0; 
     61    virtual ~CSSCalcExpressionNode() = 0;
    6262    virtual bool isZero() const = 0;
     63    virtual PassOwnPtr<CalcExpressionNode> toCalcValue(RenderStyle*, RenderStyle* rootStyle, double zoom = 1.0) const = 0;   
    6364    virtual double doubleValue() const = 0;
    6465    virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0;
     
    8182public:
    8283    static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*, CalculationPermittedValueRange);
     84    static PassRefPtr<CSSCalcValue> create(CalculationValue*);
    8385
     86    PassRefPtr<CalculationValue> toCalcValue(RenderStyle* style, RenderStyle* rootStyle, double zoom = 1.0) const
     87    {
     88        return CalculationValue::create(m_expression->toCalcValue(style, rootStyle, zoom), m_nonNegative ? CalculationRangeNonNegative : CalculationRangeAll);
     89    }
    8490    CalculationCategory category() const { return m_expression->category(); }
    8591    bool isInt() const { return m_expression->isInteger(); }   
Note: See TracChangeset for help on using the changeset viewer.