CSSCalculationValue.h [plain text]
#ifndef CSSCalculationValue_h
#define CSSCalculationValue_h
#include "CSSParserValues.h"
#include "CSSValue.h"
#include "CalculationValue.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class CSSParserValueList;
class CSSValueList;
class RenderStyle;
class CalculationValue;
class CalcExpressionNode;
enum CalculationCategory {
CalcNumber = 0,
CalcLength,
CalcPercent,
CalcPercentNumber,
CalcPercentLength,
#if ENABLE(CSS_VARIABLES)
CalcVariable,
#endif
CalcOther
};
class CSSCalcExpressionNode : public RefCounted<CSSCalcExpressionNode> {
public:
enum Type {
CssCalcPrimitiveValue = 1,
CssCalcBinaryOperation
};
virtual ~CSSCalcExpressionNode() = 0;
virtual bool isZero() const = 0;
virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const RenderStyle*, const RenderStyle* rootStyle, double zoom = 1.0) const = 0;
virtual double doubleValue() const = 0;
virtual double computeLengthPx(const RenderStyle* currentStyle, const RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0;
virtual String customCssText() const = 0;
#if ENABLE(CSS_VARIABLES)
virtual String serializeResolvingVariables(const HashMap<AtomicString, String>&) const = 0;
virtual bool hasVariableReference() const = 0;
#endif
virtual bool equals(const CSSCalcExpressionNode& other) const { return m_category == other.m_category && m_isInteger == other.m_isInteger; }
virtual Type type() const = 0;
CalculationCategory category() const { return m_category; }
bool isInteger() const { return m_isInteger; }
protected:
CSSCalcExpressionNode(CalculationCategory category, bool isInteger)
: m_category(category)
, m_isInteger(isInteger)
{
}
CalculationCategory m_category;
bool m_isInteger;
};
class CSSCalcValue : public CSSValue {
public:
static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*, CalculationPermittedValueRange);
static PassRefPtr<CSSCalcValue> create(CalculationValue*);
PassRefPtr<CalculationValue> toCalcValue(const RenderStyle* style, const RenderStyle* rootStyle, double zoom = 1.0) const
{
return CalculationValue::create(m_expression->toCalcValue(style, rootStyle, zoom), m_nonNegative ? CalculationRangeNonNegative : CalculationRangeAll);
}
CalculationCategory category() const { return m_expression->category(); }
bool isInt() const { return m_expression->isInteger(); }
double doubleValue() const;
bool isNegative() const { return m_expression->doubleValue() < 0; }
double computeLengthPx(const RenderStyle* currentStyle, const RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const;
String customCssText() const;
bool equals(const CSSCalcValue&) const;
#if ENABLE(CSS_VARIABLES)
String customSerializeResolvingVariables(const HashMap<AtomicString, String>&) const;
bool hasVariableReference() const;
#endif
private:
CSSCalcValue(PassRefPtr<CSSCalcExpressionNode> expression, CalculationPermittedValueRange range)
: CSSValue(CalculationClass)
, m_expression(expression)
, m_nonNegative(range == CalculationRangeNonNegative)
{
}
double clampToPermittedRange(double) const;
const RefPtr<CSSCalcExpressionNode> m_expression;
const bool m_nonNegative;
};
}
#endif // CSSCalculationValue_h