CSS3 calc() - simple parse time evaluation

https://bugs.webkit.org/show_bug.cgi?id=77960

Source/WebCore:

Adds simple number/percent expression evaluation. rgb() and hsl() functions now
allow simple calc() expressions.

Reviewed by Ojan Vafai.

* css/CSSCalculationValue.cpp:
(WebCore):
(WebCore::CSSCalcValue::doubleValue):
(WebCore::CSSCalcPrimitiveValue::doubleValue):
(WebCore::CSSCalcBinaryOperation::doubleValue):
(CSSCalcBinaryOperation):
(WebCore::CSSCalcBinaryOperation::evaluate):
* css/CSSCalculationValue.h:
(CSSCalcExpressionNode):
(WebCore::CSSCalcValue::isInt):
(CSSCalcValue):
* css/CSSParser.cpp:
(WebCore::CSSParser::parsedDouble):

LayoutTests:

Reviewed by Ojan Vafai.

* css3/calc/color-hsl-expected.txt:
* css3/calc/color-rgb-expected.txt:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107030 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f789322e
2012-02-07 Mike Lawther <mikelawther@chromium.org>
CSS3 calc() - simple parse time evaluation
https://bugs.webkit.org/show_bug.cgi?id=77960
Reviewed by Ojan Vafai.
* css3/calc/color-hsl-expected.txt:
* css3/calc/color-rgb-expected.txt:
2012-02-07 Chris Palmer <palmer@google.com>
Resolve crash in FrameLoader::checkTimerFired.
......@@ -2,4 +2,4 @@ These two sentences should be the same color (simple)
These two sentences should be the same color (simple)
These two sentences should be the same color (alpha)
These two sentences should be the same color (alpha)
FAIL
PASS
......@@ -6,4 +6,4 @@ C. These two sentences should be the same color (alpha)
C. These two sentences should be the same color (alpha)
These two sentences should be the same color (percent alpha)
These two sentences should be the same color (percent alpha)
FAIL
PASS
2012-02-07 Mike Lawther <mikelawther@chromium.org>
CSS3 calc() - simple parse time evaluation
https://bugs.webkit.org/show_bug.cgi?id=77960
Adds simple number/percent expression evaluation. rgb() and hsl() functions now
allow simple calc() expressions.
Reviewed by Ojan Vafai.
* css/CSSCalculationValue.cpp:
(WebCore):
(WebCore::CSSCalcValue::doubleValue):
(WebCore::CSSCalcPrimitiveValue::doubleValue):
(WebCore::CSSCalcBinaryOperation::doubleValue):
(CSSCalcBinaryOperation):
(WebCore::CSSCalcBinaryOperation::evaluate):
* css/CSSCalculationValue.h:
(CSSCalcExpressionNode):
(WebCore::CSSCalcValue::isInt):
(CSSCalcValue):
* css/CSSParser.cpp:
(WebCore::CSSParser::parsedDouble):
2012-02-07 Andreas Kling <awesomekling@apple.com>
REGRESSION(r106668-r106889): Chromium page cycler tests (Intl2) performance regressions.
......@@ -76,6 +76,11 @@ String CSSCalcValue::customCssText() const
{
return "";
}
double CSSCalcValue::doubleValue() const
{
return m_expression->doubleValue();
}
CSSCalcExpressionNode::~CSSCalcExpressionNode()
{
......@@ -94,7 +99,21 @@ public:
return m_value->cssText();
}
virtual double doubleValue() const
{
switch (m_category) {
case CalcNumber:
case CalcPercent:
return m_value->getDoubleValue();
case CalcLength:
case CalcPercentLength:
case CalcPercentNumber:
case CalcOther:
ASSERT_NOT_REACHED();
break;
}
return 0;
}
private:
explicit CSSCalcPrimitiveValue(CSSPrimitiveValue* value, bool isInteger)
: CSSCalcExpressionNode(unitCategory((CSSPrimitiveValue::UnitTypes)value->primitiveType()), isInteger)
......@@ -152,6 +171,11 @@ public:
return adoptRef(new CSSCalcBinaryOperation(leftSide, rightSide, op, newCategory));
}
virtual double doubleValue() const
{
return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue());
}
private:
CSSCalcBinaryOperation(PassRefPtr<CSSCalcExpressionNode> leftSide, PassRefPtr<CSSCalcExpressionNode> rightSide, CalcOperator op, CalculationCategory category)
: CSSCalcExpressionNode(category, leftSide->isInteger() && rightSide->isInteger())
......@@ -161,6 +185,27 @@ private:
{
}
double evaluate(double leftValue, double rightValue) const
{
switch (m_operator) {
case CalcAdd:
return leftValue + rightValue;
case CalcSubtract:
return leftValue - rightValue;
case CalcMultiply:
return leftValue * rightValue;
case CalcDivide:
if (rightValue)
return leftValue / rightValue;
return std::numeric_limits<double>::quiet_NaN();
case CalcMod:
// FIXME calc() : mod has been removed from the spec, need to remove
// this enum value
return 0;
}
return 0;
}
const RefPtr<CSSCalcExpressionNode> m_leftSide;
const RefPtr<CSSCalcExpressionNode> m_rightSide;
const CalcOperator m_operator;
......
......@@ -58,7 +58,8 @@ enum CalculationCategory {
class CSSCalcExpressionNode : public RefCounted<CSSCalcExpressionNode> {
public:
virtual ~CSSCalcExpressionNode() = 0;
virtual ~CSSCalcExpressionNode() = 0;
virtual double doubleValue() const = 0;
CalculationCategory category() const { return m_category; }
bool isInteger() const { return m_isInteger; }
......@@ -80,7 +81,8 @@ public:
static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*);
CalculationCategory category() const { return m_expression->category(); }
bool isInt() const { return m_expression->isInteger(); }
bool isInt() const { return m_expression->isInteger(); }
double doubleValue() const;
String customCssText() const;
......
......@@ -4949,9 +4949,7 @@ bool CSSParser::fastParseColor(RGBA32& rgb, const String& name, bool strict)
inline double CSSParser::parsedDouble(CSSParserValue *v, ReleaseParsedCalcValueCondition releaseCalc)
{
// FIXME calc (http://webkit.org/b/16662): evaluate calc here, eg
// const double result = m_parsedCalculation ? m_parsedCalculation->doubleValue() : v->fValue;
const double result = m_parsedCalculation ? 0 : v->fValue;
const double result = m_parsedCalculation ? m_parsedCalculation->doubleValue() : v->fValue;
if (releaseCalc == ReleaseParsedCalcValue)
m_parsedCalculation.release();
return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment