OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 CalcLength, | 59 CalcLength, |
60 CalcPercent, | 60 CalcPercent, |
61 CalcPercentNumber, | 61 CalcPercentNumber, |
62 CalcPercentLength, | 62 CalcPercentLength, |
63 CalcAngle, | 63 CalcAngle, |
64 CalcTime, | 64 CalcTime, |
65 CalcFrequency, | 65 CalcFrequency, |
66 CalcOther | 66 CalcOther |
67 }; | 67 }; |
68 | 68 |
69 class CSSCalcExpressionNode : public RefCountedWillBeGarbageCollected<CSSCalcExp
ressionNode> { | 69 class CSSCalcExpressionNode : public RefCounted<CSSCalcExpressionNode> { |
70 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(CSSCalcExpressionNode); | |
71 public: | 70 public: |
| 71 virtual ~CSSCalcExpressionNode() |
| 72 { |
| 73 } |
| 74 |
72 enum Type { | 75 enum Type { |
73 CssCalcPrimitiveValue = 1, | 76 CssCalcPrimitiveValue = 1, |
74 CssCalcBinaryOperation | 77 CssCalcBinaryOperation |
75 }; | 78 }; |
76 | 79 |
77 virtual bool isZero() const = 0; | 80 virtual bool isZero() const = 0; |
78 virtual double doubleValue() const = 0; | 81 virtual double doubleValue() const = 0; |
79 virtual double computeLengthPx(const CSSToLengthConversionData&) const = 0; | 82 virtual double computeLengthPx(const CSSToLengthConversionData&) const = 0; |
80 virtual void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, dou
ble multiplier) const = 0; | 83 virtual void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, dou
ble multiplier) const = 0; |
81 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData&, Pi
xelsAndPercent&, float multiplier = 1) const = 0; | 84 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData&, Pi
xelsAndPercent&, float multiplier = 1) const = 0; |
82 virtual String customCSSText() const = 0; | 85 virtual String customCSSText() const = 0; |
83 virtual bool equals(const CSSCalcExpressionNode& other) const { return m_cat
egory == other.m_category && m_isInteger == other.m_isInteger; } | 86 virtual bool equals(const CSSCalcExpressionNode& other) const { return m_cat
egory == other.m_category && m_isInteger == other.m_isInteger; } |
84 virtual Type type() const = 0; | 87 virtual Type type() const = 0; |
85 | 88 |
86 CalculationCategory category() const { return m_category; } | 89 CalculationCategory category() const { return m_category; } |
87 virtual CSSPrimitiveValue::UnitType typeWithCalcResolved() const = 0; | 90 virtual CSSPrimitiveValue::UnitType typeWithCalcResolved() const = 0; |
88 bool isInteger() const { return m_isInteger; } | 91 bool isInteger() const { return m_isInteger; } |
89 | 92 |
90 DEFINE_INLINE_VIRTUAL_TRACE() { } | |
91 | |
92 protected: | 93 protected: |
93 CSSCalcExpressionNode(CalculationCategory category, bool isInteger) | 94 CSSCalcExpressionNode(CalculationCategory category, bool isInteger) |
94 : m_category(category) | 95 : m_category(category) |
95 , m_isInteger(isInteger) | 96 , m_isInteger(isInteger) |
96 { | 97 { |
97 ASSERT(category != CalcOther); | 98 ASSERT(category != CalcOther); |
98 } | 99 } |
99 | 100 |
100 CalculationCategory m_category; | 101 CalculationCategory m_category; |
101 bool m_isInteger; | 102 bool m_isInteger; |
102 }; | 103 }; |
103 | 104 |
104 class CORE_EXPORT CSSCalcValue : public RefCountedWillBeGarbageCollected<CSSCalc
Value> { | 105 class CORE_EXPORT CSSCalcValue : public RefCounted<CSSCalcValue> { |
105 public: | 106 public: |
106 static PassRefPtrWillBeRawPtr<CSSCalcValue> create(const CSSParserTokenRange
&, ValueRange); | 107 static PassRefPtr<CSSCalcValue> create(const CSSParserTokenRange&, ValueRang
e); |
107 static PassRefPtrWillBeRawPtr<CSSCalcValue> create(PassRefPtrWillBeRawPtr<CS
SCalcExpressionNode>, ValueRange = ValueRangeAll); | 108 static PassRefPtr<CSSCalcValue> create(PassRefPtr<CSSCalcExpressionNode>, Va
lueRange = ValueRangeAll); |
108 | 109 |
109 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(Pa
ssRefPtrWillBeRawPtr<CSSPrimitiveValue>, bool isInteger = false); | 110 static PassRefPtr<CSSCalcExpressionNode> createExpressionNode(PassRefPtr<CSS
PrimitiveValue>, bool isInteger = false); |
110 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(Pa
ssRefPtrWillBeRawPtr<CSSCalcExpressionNode>, PassRefPtrWillBeRawPtr<CSSCalcExpre
ssionNode>, CalcOperator); | 111 static PassRefPtr<CSSCalcExpressionNode> createExpressionNode(PassRefPtr<CSS
CalcExpressionNode>, PassRefPtr<CSSCalcExpressionNode>, CalcOperator); |
111 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createExpressionNode(do
uble pixels, double percent); | 112 static PassRefPtr<CSSCalcExpressionNode> createExpressionNode(double pixels,
double percent); |
112 | 113 |
113 PassRefPtr<CalculationValue> toCalcValue(const CSSToLengthConversionData& co
nversionData) const | 114 PassRefPtr<CalculationValue> toCalcValue(const CSSToLengthConversionData& co
nversionData) const |
114 { | 115 { |
115 PixelsAndPercent value(0, 0); | 116 PixelsAndPercent value(0, 0); |
116 m_expression->accumulatePixelsAndPercent(conversionData, value); | 117 m_expression->accumulatePixelsAndPercent(conversionData, value); |
117 return CalculationValue::create(value, m_nonNegative ? ValueRangeNonNega
tive : ValueRangeAll); | 118 return CalculationValue::create(value, m_nonNegative ? ValueRangeNonNega
tive : ValueRangeAll); |
118 } | 119 } |
119 CalculationCategory category() const { return m_expression->category(); } | 120 CalculationCategory category() const { return m_expression->category(); } |
120 bool isInt() const { return m_expression->isInteger(); } | 121 bool isInt() const { return m_expression->isInteger(); } |
121 double doubleValue() const; | 122 double doubleValue() const; |
122 bool isNegative() const { return m_expression->doubleValue() < 0; } | 123 bool isNegative() const { return m_expression->doubleValue() < 0; } |
123 ValueRange permittedValueRange() { return m_nonNegative ? ValueRangeNonNegat
ive : ValueRangeAll; } | 124 ValueRange permittedValueRange() { return m_nonNegative ? ValueRangeNonNegat
ive : ValueRangeAll; } |
124 double computeLengthPx(const CSSToLengthConversionData&) const; | 125 double computeLengthPx(const CSSToLengthConversionData&) const; |
125 void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTypeArray&
lengthTypeArray, double multiplier) const { m_expression->accumulateLengthArray(
lengthArray, lengthTypeArray, multiplier); } | 126 void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTypeArray&
lengthTypeArray, double multiplier) const { m_expression->accumulateLengthArray(
lengthArray, lengthTypeArray, multiplier); } |
126 CSSCalcExpressionNode* expressionNode() const { return m_expression.get(); } | 127 CSSCalcExpressionNode* expressionNode() const { return m_expression.get(); } |
127 | 128 |
128 String customCSSText() const; | 129 String customCSSText() const; |
129 bool equals(const CSSCalcValue&) const; | 130 bool equals(const CSSCalcValue&) const; |
130 | 131 |
131 DEFINE_INLINE_TRACE() | |
132 { | |
133 visitor->trace(m_expression); | |
134 } | |
135 | |
136 private: | 132 private: |
137 CSSCalcValue(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> expression, Value
Range range) | 133 CSSCalcValue(PassRefPtr<CSSCalcExpressionNode> expression, ValueRange range) |
138 : m_expression(expression) | 134 : m_expression(expression) |
139 , m_nonNegative(range == ValueRangeNonNegative) | 135 , m_nonNegative(range == ValueRangeNonNegative) |
140 { | 136 { |
141 } | 137 } |
142 | 138 |
143 double clampToPermittedRange(double) const; | 139 double clampToPermittedRange(double) const; |
144 | 140 |
145 const RefPtrWillBeMember<CSSCalcExpressionNode> m_expression; | 141 const RefPtr<CSSCalcExpressionNode> m_expression; |
146 const bool m_nonNegative; | 142 const bool m_nonNegative; |
147 }; | 143 }; |
148 | 144 |
149 } // namespace blink | 145 } // namespace blink |
150 | 146 |
151 #endif // CSSCalculationValue_h | 147 #endif // CSSCalculationValue_h |
OLD | NEW |