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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 { | 180 { |
181 return clampToPermittedRange(m_expression->computeLengthPx(conversionData)); | 181 return clampToPermittedRange(m_expression->computeLengthPx(conversionData)); |
182 } | 182 } |
183 | 183 |
184 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CSSCalcExpressionNode) | 184 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CSSCalcExpressionNode) |
185 | 185 |
186 class CSSCalcPrimitiveValue final : public CSSCalcExpressionNode { | 186 class CSSCalcPrimitiveValue final : public CSSCalcExpressionNode { |
187 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(CSSCalcPrimitiveValue); | 187 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(CSSCalcPrimitiveValue); |
188 public: | 188 public: |
189 | 189 |
190 static PassRefPtrWillBeRawPtr<CSSCalcPrimitiveValue> create(PassRefPtrWillBe
RawPtr<CSSPrimitiveValue> value, bool isInteger) | 190 static PassRefPtrWillBeRawPtr<CSSCalcPrimitiveValue> create(CSSPrimitiveValu
e value, bool isInteger) |
191 { | 191 { |
192 return adoptRefWillBeNoop(new CSSCalcPrimitiveValue(value, isInteger)); | 192 return adoptRefWillBeNoop(new CSSCalcPrimitiveValue(value, isInteger)); |
193 } | 193 } |
194 | 194 |
195 static PassRefPtrWillBeRawPtr<CSSCalcPrimitiveValue> create(double value, CS
SPrimitiveValue::UnitType type, bool isInteger) | 195 static PassRefPtrWillBeRawPtr<CSSCalcPrimitiveValue> create(double value, CS
SPrimitiveValue::UnitType type, bool isInteger) |
196 { | 196 { |
197 if (std::isnan(value) || std::isinf(value)) | 197 if (std::isnan(value) || std::isinf(value)) |
198 return nullptr; | 198 return nullptr; |
199 return adoptRefWillBeNoop(new CSSCalcPrimitiveValue(CSSPrimitiveValue::c
reate(value, type).get(), isInteger)); | 199 return adoptRefWillBeNoop(new CSSCalcPrimitiveValue(CSSPrimitiveValue::c
reate(value, type), isInteger)); |
200 } | 200 } |
201 | 201 |
202 virtual bool isZero() const override | 202 virtual bool isZero() const override |
203 { | 203 { |
204 return !m_value->getDoubleValue(); | 204 return !toCSSPrimitiveValue(m_value).getDoubleValue(); |
205 } | 205 } |
206 | 206 |
207 virtual String customCSSText() const override | 207 virtual String customCSSText() const override |
208 { | 208 { |
209 return m_value->cssText(); | 209 return m_value.cssText(); |
210 } | 210 } |
211 | 211 |
212 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData& con
versionData, PixelsAndPercent& value, float multiplier) const override | 212 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData& con
versionData, PixelsAndPercent& value, float multiplier) const override |
213 { | 213 { |
214 switch (m_category) { | 214 switch (m_category) { |
215 case CalcLength: | 215 case CalcLength: |
216 value.pixels += m_value->computeLength<float>(conversionData) * mult
iplier; | 216 value.pixels += toCSSPrimitiveValue(m_value).computeLength<float>(co
nversionData) * multiplier; |
217 break; | 217 break; |
218 case CalcPercent: | 218 case CalcPercent: |
219 ASSERT(m_value->isPercentage()); | 219 ASSERT(toCSSPrimitiveValue(m_value).isPercentage()); |
220 value.percent += m_value->getDoubleValue() * multiplier; | 220 value.percent += toCSSPrimitiveValue(m_value).getDoubleValue() * mul
tiplier; |
221 break; | 221 break; |
222 default: | 222 default: |
223 ASSERT_NOT_REACHED(); | 223 ASSERT_NOT_REACHED(); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 virtual double doubleValue() const override | 227 virtual double doubleValue() const override |
228 { | 228 { |
229 if (hasDoubleValue(primitiveType())) | 229 if (hasDoubleValue(primitiveType())) |
230 return m_value->getDoubleValue(); | 230 return toCSSPrimitiveValue(m_value).getDoubleValue(); |
231 ASSERT_NOT_REACHED(); | 231 ASSERT_NOT_REACHED(); |
232 return 0; | 232 return 0; |
233 } | 233 } |
234 | 234 |
235 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa
ta) const override | 235 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa
ta) const override |
236 { | 236 { |
237 switch (m_category) { | 237 switch (m_category) { |
238 case CalcLength: | 238 case CalcLength: |
239 return m_value->computeLength<double>(conversionData); | 239 return toCSSPrimitiveValue(m_value).computeLength<double>(conversion
Data); |
240 case CalcNumber: | 240 case CalcNumber: |
241 case CalcPercent: | 241 case CalcPercent: |
242 return m_value->getDoubleValue(); | 242 return toCSSPrimitiveValue(m_value).getDoubleValue(); |
243 case CalcAngle: | 243 case CalcAngle: |
244 case CalcFrequency: | 244 case CalcFrequency: |
245 case CalcPercentLength: | 245 case CalcPercentLength: |
246 case CalcPercentNumber: | 246 case CalcPercentNumber: |
247 case CalcTime: | 247 case CalcTime: |
248 case CalcOther: | 248 case CalcOther: |
249 ASSERT_NOT_REACHED(); | 249 ASSERT_NOT_REACHED(); |
250 break; | 250 break; |
251 } | 251 } |
252 ASSERT_NOT_REACHED(); | 252 ASSERT_NOT_REACHED(); |
253 return 0; | 253 return 0; |
254 } | 254 } |
255 | 255 |
256 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTyp
eArray& lengthTypeArray, double multiplier) const override | 256 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTyp
eArray& lengthTypeArray, double multiplier) const override |
257 { | 257 { |
258 ASSERT(category() != CalcNumber); | 258 ASSERT(category() != CalcNumber); |
259 m_value->accumulateLengthArray(lengthArray, lengthTypeArray, multiplier)
; | 259 toCSSPrimitiveValue(m_value).accumulateLengthArray(lengthArray, lengthTy
peArray, multiplier); |
260 } | 260 } |
261 | 261 |
262 virtual bool equals(const CSSCalcExpressionNode& other) const override | 262 virtual bool equals(const CSSCalcExpressionNode& other) const override |
263 { | 263 { |
264 if (type() != other.type()) | 264 if (type() != other.type()) |
265 return false; | 265 return false; |
266 | 266 |
267 return compareCSSValuePtr(m_value, static_cast<const CSSCalcPrimitiveVal
ue&>(other).m_value); | 267 return m_value.equals(static_cast<const CSSCalcPrimitiveValue&>(other).m
_value); |
268 } | 268 } |
269 | 269 |
270 virtual Type type() const override { return CssCalcPrimitiveValue; } | 270 virtual Type type() const override { return CssCalcPrimitiveValue; } |
271 virtual CSSPrimitiveValue::UnitType primitiveType() const override | 271 virtual CSSPrimitiveValue::UnitType primitiveType() const override |
272 { | 272 { |
273 return m_value->primitiveType(); | 273 return toCSSPrimitiveValue(m_value).primitiveType(); |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 DEFINE_INLINE_VIRTUAL_TRACE() | 277 DEFINE_INLINE_VIRTUAL_TRACE() |
278 { | 278 { |
279 visitor->trace(m_value); | 279 visitor->trace(m_value); |
280 CSSCalcExpressionNode::trace(visitor); | 280 CSSCalcExpressionNode::trace(visitor); |
281 } | 281 } |
282 | 282 |
283 private: | 283 private: |
284 CSSCalcPrimitiveValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value, bool
isInteger) | 284 CSSCalcPrimitiveValue(CSSPrimitiveValue value, bool isInteger) |
285 : CSSCalcExpressionNode(unitCategory(value->primitiveType()), isInteger) | 285 : CSSCalcExpressionNode(unitCategory(value.primitiveType()), isInteger) |
286 , m_value(value) | 286 , m_value(value) |
287 { | 287 { |
288 } | 288 } |
289 | 289 |
290 RefPtrWillBeMember<CSSPrimitiveValue> m_value; | 290 CSSValue m_value; |
291 }; | 291 }; |
292 | 292 |
293 static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = { | 293 static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = { |
294 // CalcNumber CalcLength CalcPercent
CalcPercentNumber CalcPercentLength CalcAngle CalcTime CalcFrequency | 294 // CalcNumber CalcLength CalcPercent
CalcPercentNumber CalcPercentLength CalcAngle CalcTime CalcFrequency |
295 /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumbe
r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, | 295 /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumbe
r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, |
296 /* CalcLength */ { CalcOther, CalcLength, CalcPercentLengt
h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, | 296 /* CalcLength */ { CalcOther, CalcLength, CalcPercentLengt
h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, |
297 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent,
CalcPercentNumber, CalcPercentLength, CalcOther, CalcOther, CalcOther }, | 297 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent,
CalcPercentNumber, CalcPercentLength, CalcOther, CalcOther, CalcOther }, |
298 /* CalcPercentNumber */ { CalcPercentNumber, CalcOther, CalcPercentNumbe
r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, | 298 /* CalcPercentNumber */ { CalcPercentNumber, CalcOther, CalcPercentNumbe
r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, |
299 /* CalcPercentLength */ { CalcOther, CalcPercentLength, CalcPercentLengt
h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, | 299 /* CalcPercentLength */ { CalcOther, CalcPercentLength, CalcPercentLengt
h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, |
300 /* CalcAngle */ { CalcOther, CalcOther, CalcOther,
CalcOther, CalcOther, CalcAngle, CalcOther, CalcOther }, | 300 /* CalcAngle */ { CalcOther, CalcOther, CalcOther,
CalcOther, CalcOther, CalcAngle, CalcOther, CalcOther }, |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 ASSERT_WITH_SECURITY_IMPLICATION(*index <= tokens->size()); | 723 ASSERT_WITH_SECURITY_IMPLICATION(*index <= tokens->size()); |
724 return true; | 724 return true; |
725 } | 725 } |
726 | 726 |
727 bool parseValueExpression(CSSParserValueList* tokens, int depth, unsigned* i
ndex, Value* result) | 727 bool parseValueExpression(CSSParserValueList* tokens, int depth, unsigned* i
ndex, Value* result) |
728 { | 728 { |
729 return parseAdditiveValueExpression(tokens, depth, index, result); | 729 return parseAdditiveValueExpression(tokens, depth, index, result); |
730 } | 730 } |
731 }; | 731 }; |
732 | 732 |
733 PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> CSSCalcValue::createExpressionNode
(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value, bool isInteger) | 733 PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> CSSCalcValue::createExpressionNode
(CSSPrimitiveValue value, bool isInteger) |
734 { | 734 { |
735 return CSSCalcPrimitiveValue::create(value, isInteger); | 735 return CSSCalcPrimitiveValue::create(value, isInteger); |
736 } | 736 } |
737 | 737 |
738 PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> CSSCalcValue::createExpressionNode
(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> leftSide, PassRefPtrWillBeRawPtr<
CSSCalcExpressionNode> rightSide, CalcOperator op) | 738 PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> CSSCalcValue::createExpressionNode
(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> leftSide, PassRefPtrWillBeRawPtr<
CSSCalcExpressionNode> rightSide, CalcOperator op) |
739 { | 739 { |
740 return CSSCalcBinaryOperation::create(leftSide, rightSide, op); | 740 return CSSCalcBinaryOperation::create(leftSide, rightSide, op); |
741 } | 741 } |
742 | 742 |
743 PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> CSSCalcValue::createExpressionNode
(double pixels, double percent) | 743 PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> CSSCalcValue::createExpressionNode
(double pixels, double percent) |
(...skipping 17 matching lines...) Expand all Loading... |
761 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); | 761 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); |
762 } | 762 } |
763 | 763 |
764 DEFINE_TRACE_AFTER_DISPATCH(CSSCalcValue) | 764 DEFINE_TRACE_AFTER_DISPATCH(CSSCalcValue) |
765 { | 765 { |
766 visitor->trace(m_expression); | 766 visitor->trace(m_expression); |
767 CSSValueObject::traceAfterDispatch(visitor); | 767 CSSValueObject::traceAfterDispatch(visitor); |
768 } | 768 } |
769 | 769 |
770 } // namespace blink | 770 } // namespace blink |
OLD | NEW |