2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CSSCalculationValue_h
32 #define CSSCalculationValue_h
34 #include "CSSParserValues.h"
36 #include "CalculationValue.h"
37 #include <wtf/PassOwnPtr.h>
38 #include <wtf/RefCounted.h>
39 #include <wtf/RefPtr.h>
43 class CSSParserValueList;
46 class CalculationValue;
47 class CalcExpressionNode;
49 enum CalculationCategory {
58 class CSSCalcExpressionNode : public RefCounted<CSSCalcExpressionNode> {
61 virtual ~CSSCalcExpressionNode() = 0;
62 virtual bool isZero() const = 0;
63 virtual PassOwnPtr<CalcExpressionNode> toCalcValue(RenderStyle*, RenderStyle* rootStyle, double zoom = 1.0) const = 0;
64 virtual double doubleValue() const = 0;
65 virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0;
66 virtual String customCssText() const = 0;
68 CalculationCategory category() const { return m_category; }
69 bool isInteger() const { return m_isInteger; }
72 CSSCalcExpressionNode(CalculationCategory category, bool isInteger)
73 : m_category(category)
74 , m_isInteger(isInteger)
78 CalculationCategory m_category;
82 class CSSCalcValue : public CSSValue {
84 static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*, CalculationPermittedValueRange);
85 static PassRefPtr<CSSCalcValue> create(CalculationValue*);
87 PassRefPtr<CalculationValue> toCalcValue(RenderStyle* style, RenderStyle* rootStyle, double zoom = 1.0) const
89 return CalculationValue::create(m_expression->toCalcValue(style, rootStyle, zoom), m_nonNegative ? CalculationRangeNonNegative : CalculationRangeAll);
91 CalculationCategory category() const { return m_expression->category(); }
92 bool isInt() const { return m_expression->isInteger(); }
93 double doubleValue() const;
94 bool isNegative() const { return m_expression->doubleValue() < 0; }
95 double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const;
97 String customCssText() const;
100 CSSCalcValue(PassRefPtr<CSSCalcExpressionNode> expression, CalculationPermittedValueRange range)
101 : CSSValue(CalculationClass)
102 , m_expression(expression)
103 , m_nonNegative(range == CalculationRangeNonNegative)
107 double clampToPermittedRange(double) const;
109 const RefPtr<CSSCalcExpressionNode> m_expression;
110 const bool m_nonNegative;
113 } // namespace WebCore
115 #endif // CSSCalculationValue_h