diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/css/CSSCalculationValue.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/css/CSSCalculationValue.h')
-rw-r--r-- | Source/WebCore/css/CSSCalculationValue.h | 90 |
1 files changed, 42 insertions, 48 deletions
diff --git a/Source/WebCore/css/CSSCalculationValue.h b/Source/WebCore/css/CSSCalculationValue.h index e68a6e589..23f9fddba 100644 --- a/Source/WebCore/css/CSSCalculationValue.h +++ b/Source/WebCore/css/CSSCalculationValue.h @@ -28,25 +28,16 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CSSCalculationValue_h -#define CSSCalculationValue_h +#pragma once -#include "CSSParserValues.h" #include "CSSPrimitiveValue.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 CalculationValue; -class CalcExpressionNode; +class CSSParserTokenRange; +class CSSToLengthConversionData; class RenderStyle; -struct Length; enum CalculationCategory { CalcNumber = 0, @@ -54,6 +45,9 @@ enum CalculationCategory { CalcPercent, CalcPercentNumber, CalcPercentLength, + CalcAngle, + CalcTime, + CalcFrequency, CalcOther }; @@ -64,17 +58,17 @@ public: CssCalcBinaryOperation }; - virtual ~CSSCalcExpressionNode() = 0; + virtual ~CSSCalcExpressionNode() { } virtual bool isZero() const = 0; - virtual PassOwnPtr<CalcExpressionNode> toCalcValue(const RenderStyle*, const RenderStyle* rootStyle, double zoom = 1.0) const = 0; + virtual std::unique_ptr<CalcExpressionNode> createCalcExpression(const CSSToLengthConversionData&) 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 double computeLengthPx(const CSSToLengthConversionData&) const = 0; virtual String customCSSText() const = 0; virtual bool equals(const CSSCalcExpressionNode& other) const { return m_category == other.m_category && m_isInteger == other.m_isInteger; } virtual Type type() const = 0; + virtual CSSPrimitiveValue::UnitType primitiveType() const = 0; CalculationCategory category() const { return m_category; } - virtual CSSPrimitiveValue::UnitTypes primitiveType() const = 0; bool isInteger() const { return m_isInteger; } protected: @@ -84,58 +78,58 @@ protected: { } +private: CalculationCategory m_category; bool m_isInteger; }; -class CSSCalcValue : public CSSValue { +class CSSCalcValue final : public CSSValue { public: - static PassRefPtr<CSSCalcValue> create(CSSParserString name, CSSParserValueList*, CalculationPermittedValueRange); - static PassRef<CSSCalcValue> create(PassRefPtr<CSSCalcExpressionNode>, CalculationPermittedValueRange = CalculationRangeAll); - static PassRef<CSSCalcValue> create(const CalculationValue* value, const RenderStyle* style) { return adoptRef(*new CSSCalcValue(value, style)); } - - static PassRefPtr<CSSCalcExpressionNode> createExpressionNode(PassRefPtr<CSSPrimitiveValue>, bool isInteger = false); - static PassRefPtr<CSSCalcExpressionNode> createExpressionNode(PassRefPtr<CSSCalcExpressionNode>, PassRefPtr<CSSCalcExpressionNode>, CalcOperator); - static PassRefPtr<CSSCalcExpressionNode> createExpressionNode(const CalcExpressionNode*, const RenderStyle*); - static PassRefPtr<CSSCalcExpressionNode> createExpressionNode(const Length&, const RenderStyle*); + static RefPtr<CSSCalcValue> create(const CSSParserTokenRange&, ValueRange); + + static RefPtr<CSSCalcValue> create(const CalculationValue&, const RenderStyle&); - 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 isPositive() const { return m_expression->doubleValue() > 0; } bool isNegative() const { return m_expression->doubleValue() < 0; } - CalculationPermittedValueRange permittedValueRange() { return m_nonNegative ? CalculationRangeNonNegative : CalculationRangeAll; } - double computeLengthPx(const RenderStyle* currentStyle, const RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const; - CSSCalcExpressionNode* expressionNode() const { return m_expression.get(); } + double computeLengthPx(const CSSToLengthConversionData&) const; + unsigned short primitiveType() const { return m_expression->primitiveType(); } + + Ref<CalculationValue> createCalculationValue(const CSSToLengthConversionData&) const; + void setPermittedValueRange(ValueRange); String customCSSText() const; bool equals(const CSSCalcValue&) const; private: - CSSCalcValue(PassRefPtr<CSSCalcExpressionNode> expression, CalculationPermittedValueRange range) - : CSSValue(CalculationClass) - , m_expression(expression) - , m_nonNegative(range == CalculationRangeNonNegative) - { - } - CSSCalcValue(const CalculationValue* value, const RenderStyle* style) - : CSSValue(CalculationClass) - , m_expression(createExpressionNode(value->expression(), style)) - , m_nonNegative(value->isNonNegative()) - { - } + CSSCalcValue(Ref<CSSCalcExpressionNode>&&, bool shouldClampToNonNegative); double clampToPermittedRange(double) const; - const RefPtr<CSSCalcExpressionNode> m_expression; - const bool m_nonNegative; + const Ref<CSSCalcExpressionNode> m_expression; + bool m_shouldClampToNonNegative; }; -CSS_VALUE_TYPE_CASTS(CSSCalcValue, isCalcValue()) +inline CSSCalcValue::CSSCalcValue(Ref<CSSCalcExpressionNode>&& expression, bool shouldClampToNonNegative) + : CSSValue(CalculationClass) + , m_expression(WTFMove(expression)) + , m_shouldClampToNonNegative(shouldClampToNonNegative) +{ +} + +inline Ref<CalculationValue> CSSCalcValue::createCalculationValue(const CSSToLengthConversionData& conversionData) const +{ + return CalculationValue::create(m_expression->createCalcExpression(conversionData), + m_shouldClampToNonNegative ? ValueRangeNonNegative : ValueRangeAll); +} + +inline void CSSCalcValue::setPermittedValueRange(ValueRange range) +{ + m_shouldClampToNonNegative = range != ValueRangeAll; +} } // namespace WebCore -#endif // CSSCalculationValue_h +SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSCalcValue, isCalcValue()) |