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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return clampToPermittedRange(m_expression->doubleValue()); | 176 return clampToPermittedRange(m_expression->doubleValue()); |
177 } | 177 } |
178 | 178 |
179 double CSSCalcValue::computeLengthPx(const CSSToLengthConversionData& conversion
Data) const | 179 double CSSCalcValue::computeLengthPx(const CSSToLengthConversionData& conversion
Data) const |
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; | 187 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
188 public: | 188 public: |
189 | 189 |
190 static PassRefPtrWillBeRawPtr<CSSCalcPrimitiveValue> create(PassRefPtrWillBe
RawPtr<CSSPrimitiveValue> value, bool isInteger) | 190 static PassRefPtrWillBeRawPtr<CSSCalcPrimitiveValue> create(PassRefPtrWillBe
RawPtr<CSSPrimitiveValue> 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).get(), 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 !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 += m_value->computeLength<float>(conversionData) * mult
iplier; |
217 break; | 217 break; |
218 case CalcPercent: | 218 case CalcPercent: |
219 ASSERT(m_value->isPercentage()); | 219 ASSERT(m_value->isPercentage()); |
220 value.percent += m_value->getDoubleValue() * multiplier; | 220 value.percent += m_value->getDoubleValue() * multiplier; |
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 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 m_value->computeLength<double>(conversionData); |
240 case CalcNumber: | 240 case CalcNumber: |
241 case CalcPercent: | 241 case CalcPercent: |
242 return m_value->getDoubleValue(); | 242 return 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, double multi
plier) const | 256 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, double multi
plier) const |
257 { | 257 { |
258 ASSERT(category() != CalcNumber); | 258 ASSERT(category() != CalcNumber); |
259 m_value->accumulateLengthArray(lengthArray, multiplier); | 259 m_value->accumulateLengthArray(lengthArray, 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 compareCSSValuePtr(m_value, static_cast<const CSSCalcPrimitiveVal
ue&>(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 m_value->primitiveType(); |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 virtual void trace(Visitor* visitor) | 277 virtual void trace(Visitor* visitor) |
278 { | 278 { |
279 visitor->trace(m_value); | 279 visitor->trace(m_value); |
280 CSSCalcExpressionNode::trace(visitor); | 280 CSSCalcExpressionNode::trace(visitor); |
281 } | 281 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 329 } |
330 | 330 |
331 static bool isIntegerResult(const CSSCalcExpressionNode* leftSide, const CSSCalc
ExpressionNode* rightSide, CalcOperator op) | 331 static bool isIntegerResult(const CSSCalcExpressionNode* leftSide, const CSSCalc
ExpressionNode* rightSide, CalcOperator op) |
332 { | 332 { |
333 // Not testing for actual integer values. | 333 // Not testing for actual integer values. |
334 // Performs W3C spec's type checking for calc integers. | 334 // Performs W3C spec's type checking for calc integers. |
335 // http://www.w3.org/TR/css3-values/#calc-type-checking | 335 // http://www.w3.org/TR/css3-values/#calc-type-checking |
336 return op != CalcDivide && leftSide->isInteger() && rightSide->isInteger(); | 336 return op != CalcDivide && leftSide->isInteger() && rightSide->isInteger(); |
337 } | 337 } |
338 | 338 |
339 class CSSCalcBinaryOperation FINAL : public CSSCalcExpressionNode { | 339 class CSSCalcBinaryOperation final : public CSSCalcExpressionNode { |
340 public: | 340 public: |
341 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> create(PassRefPtrWillBe
RawPtr<CSSCalcExpressionNode> leftSide, PassRefPtrWillBeRawPtr<CSSCalcExpression
Node> rightSide, CalcOperator op) | 341 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> create(PassRefPtrWillBe
RawPtr<CSSCalcExpressionNode> leftSide, PassRefPtrWillBeRawPtr<CSSCalcExpression
Node> rightSide, CalcOperator op) |
342 { | 342 { |
343 ASSERT(leftSide->category() != CalcOther && rightSide->category() != Cal
cOther); | 343 ASSERT(leftSide->category() != CalcOther && rightSide->category() != Cal
cOther); |
344 | 344 |
345 CalculationCategory newCategory = determineCategory(*leftSide, *rightSid
e, op); | 345 CalculationCategory newCategory = determineCategory(*leftSide, *rightSid
e, op); |
346 if (newCategory == CalcOther) | 346 if (newCategory == CalcOther) |
347 return nullptr; | 347 return nullptr; |
348 | 348 |
349 return adoptRefWillBeNoop(new CSSCalcBinaryOperation(leftSide, rightSide
, op, newCategory)); | 349 return adoptRefWillBeNoop(new CSSCalcBinaryOperation(leftSide, rightSide
, op, newCategory)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 return nullptr; | 398 return nullptr; |
399 | 399 |
400 CSSPrimitiveValue::UnitType otherType = otherSide->primitiveType(); | 400 CSSPrimitiveValue::UnitType otherType = otherSide->primitiveType(); |
401 if (hasDoubleValue(otherType)) | 401 if (hasDoubleValue(otherType)) |
402 return CSSCalcPrimitiveValue::create(evaluateOperator(otherSide-
>doubleValue(), number, op), otherType, isInteger); | 402 return CSSCalcPrimitiveValue::create(evaluateOperator(otherSide-
>doubleValue(), number, op), otherType, isInteger); |
403 } | 403 } |
404 | 404 |
405 return create(leftSide, rightSide, op); | 405 return create(leftSide, rightSide, op); |
406 } | 406 } |
407 | 407 |
408 virtual bool isZero() const OVERRIDE | 408 virtual bool isZero() const override |
409 { | 409 { |
410 return !doubleValue(); | 410 return !doubleValue(); |
411 } | 411 } |
412 | 412 |
413 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData& con
versionData, PixelsAndPercent& value, float multiplier) const OVERRIDE | 413 virtual void accumulatePixelsAndPercent(const CSSToLengthConversionData& con
versionData, PixelsAndPercent& value, float multiplier) const override |
414 { | 414 { |
415 switch (m_operator) { | 415 switch (m_operator) { |
416 case CalcAdd: | 416 case CalcAdd: |
417 m_leftSide->accumulatePixelsAndPercent(conversionData, value, multip
lier); | 417 m_leftSide->accumulatePixelsAndPercent(conversionData, value, multip
lier); |
418 m_rightSide->accumulatePixelsAndPercent(conversionData, value, multi
plier); | 418 m_rightSide->accumulatePixelsAndPercent(conversionData, value, multi
plier); |
419 break; | 419 break; |
420 case CalcSubtract: | 420 case CalcSubtract: |
421 m_leftSide->accumulatePixelsAndPercent(conversionData, value, multip
lier); | 421 m_leftSide->accumulatePixelsAndPercent(conversionData, value, multip
lier); |
422 m_rightSide->accumulatePixelsAndPercent(conversionData, value, -mult
iplier); | 422 m_rightSide->accumulatePixelsAndPercent(conversionData, value, -mult
iplier); |
423 break; | 423 break; |
424 case CalcMultiply: | 424 case CalcMultiply: |
425 ASSERT((m_leftSide->category() == CalcNumber) != (m_rightSide->categ
ory() == CalcNumber)); | 425 ASSERT((m_leftSide->category() == CalcNumber) != (m_rightSide->categ
ory() == CalcNumber)); |
426 if (m_leftSide->category() == CalcNumber) | 426 if (m_leftSide->category() == CalcNumber) |
427 m_rightSide->accumulatePixelsAndPercent(conversionData, value, m
ultiplier * m_leftSide->doubleValue()); | 427 m_rightSide->accumulatePixelsAndPercent(conversionData, value, m
ultiplier * m_leftSide->doubleValue()); |
428 else | 428 else |
429 m_leftSide->accumulatePixelsAndPercent(conversionData, value, mu
ltiplier * m_rightSide->doubleValue()); | 429 m_leftSide->accumulatePixelsAndPercent(conversionData, value, mu
ltiplier * m_rightSide->doubleValue()); |
430 break; | 430 break; |
431 case CalcDivide: | 431 case CalcDivide: |
432 ASSERT(m_rightSide->category() == CalcNumber); | 432 ASSERT(m_rightSide->category() == CalcNumber); |
433 m_leftSide->accumulatePixelsAndPercent(conversionData, value, multip
lier / m_rightSide->doubleValue()); | 433 m_leftSide->accumulatePixelsAndPercent(conversionData, value, multip
lier / m_rightSide->doubleValue()); |
434 break; | 434 break; |
435 default: | 435 default: |
436 ASSERT_NOT_REACHED(); | 436 ASSERT_NOT_REACHED(); |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 virtual double doubleValue() const OVERRIDE | 440 virtual double doubleValue() const override |
441 { | 441 { |
442 return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue()); | 442 return evaluate(m_leftSide->doubleValue(), m_rightSide->doubleValue()); |
443 } | 443 } |
444 | 444 |
445 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa
ta) const OVERRIDE | 445 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa
ta) const override |
446 { | 446 { |
447 const double leftValue = m_leftSide->computeLengthPx(conversionData); | 447 const double leftValue = m_leftSide->computeLengthPx(conversionData); |
448 const double rightValue = m_rightSide->computeLengthPx(conversionData); | 448 const double rightValue = m_rightSide->computeLengthPx(conversionData); |
449 return evaluate(leftValue, rightValue); | 449 return evaluate(leftValue, rightValue); |
450 } | 450 } |
451 | 451 |
452 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, double multi
plier) const | 452 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, double multi
plier) const |
453 { | 453 { |
454 switch (m_operator) { | 454 switch (m_operator) { |
455 case CalcAdd: | 455 case CalcAdd: |
(...skipping 27 matching lines...) Expand all Loading... |
483 result.append(leftExpression); | 483 result.append(leftExpression); |
484 result.append(' '); | 484 result.append(' '); |
485 result.append(static_cast<char>(op)); | 485 result.append(static_cast<char>(op)); |
486 result.append(' '); | 486 result.append(' '); |
487 result.append(rightExpression); | 487 result.append(rightExpression); |
488 result.append(')'); | 488 result.append(')'); |
489 | 489 |
490 return result.toString(); | 490 return result.toString(); |
491 } | 491 } |
492 | 492 |
493 virtual String customCSSText() const OVERRIDE | 493 virtual String customCSSText() const override |
494 { | 494 { |
495 return buildCSSText(m_leftSide->customCSSText(), m_rightSide->customCSST
ext(), m_operator); | 495 return buildCSSText(m_leftSide->customCSSText(), m_rightSide->customCSST
ext(), m_operator); |
496 } | 496 } |
497 | 497 |
498 virtual bool equals(const CSSCalcExpressionNode& exp) const OVERRIDE | 498 virtual bool equals(const CSSCalcExpressionNode& exp) const override |
499 { | 499 { |
500 if (type() != exp.type()) | 500 if (type() != exp.type()) |
501 return false; | 501 return false; |
502 | 502 |
503 const CSSCalcBinaryOperation& other = static_cast<const CSSCalcBinaryOpe
ration&>(exp); | 503 const CSSCalcBinaryOperation& other = static_cast<const CSSCalcBinaryOpe
ration&>(exp); |
504 return compareCSSValuePtr(m_leftSide, other.m_leftSide) | 504 return compareCSSValuePtr(m_leftSide, other.m_leftSide) |
505 && compareCSSValuePtr(m_rightSide, other.m_rightSide) | 505 && compareCSSValuePtr(m_rightSide, other.m_rightSide) |
506 && m_operator == other.m_operator; | 506 && m_operator == other.m_operator; |
507 } | 507 } |
508 | 508 |
509 virtual Type type() const OVERRIDE { return CssCalcBinaryOperation; } | 509 virtual Type type() const override { return CssCalcBinaryOperation; } |
510 | 510 |
511 virtual CSSPrimitiveValue::UnitType primitiveType() const OVERRIDE | 511 virtual CSSPrimitiveValue::UnitType primitiveType() const override |
512 { | 512 { |
513 switch (m_category) { | 513 switch (m_category) { |
514 case CalcNumber: | 514 case CalcNumber: |
515 ASSERT(m_leftSide->category() == CalcNumber && m_rightSide->category
() == CalcNumber); | 515 ASSERT(m_leftSide->category() == CalcNumber && m_rightSide->category
() == CalcNumber); |
516 return CSSPrimitiveValue::CSS_NUMBER; | 516 return CSSPrimitiveValue::CSS_NUMBER; |
517 case CalcLength: | 517 case CalcLength: |
518 case CalcPercent: { | 518 case CalcPercent: { |
519 if (m_leftSide->category() == CalcNumber) | 519 if (m_leftSide->category() == CalcNumber) |
520 return m_rightSide->primitiveType(); | 520 return m_rightSide->primitiveType(); |
521 if (m_rightSide->category() == CalcNumber) | 521 if (m_rightSide->category() == CalcNumber) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); | 761 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); |
762 } | 762 } |
763 | 763 |
764 void CSSCalcValue::traceAfterDispatch(Visitor* visitor) | 764 void CSSCalcValue::traceAfterDispatch(Visitor* visitor) |
765 { | 765 { |
766 visitor->trace(m_expression); | 766 visitor->trace(m_expression); |
767 CSSValue::traceAfterDispatch(visitor); | 767 CSSValue::traceAfterDispatch(visitor); |
768 } | 768 } |
769 | 769 |
770 } // namespace blink | 770 } // namespace blink |
OLD | NEW |