Chromium Code Reviews| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 case CSSPrimitiveValue::CSS_IN: | 63 case CSSPrimitiveValue::CSS_IN: |
| 64 case CSSPrimitiveValue::CSS_PT: | 64 case CSSPrimitiveValue::CSS_PT: |
| 65 case CSSPrimitiveValue::CSS_PC: | 65 case CSSPrimitiveValue::CSS_PC: |
| 66 case CSSPrimitiveValue::CSS_REMS: | 66 case CSSPrimitiveValue::CSS_REMS: |
| 67 case CSSPrimitiveValue::CSS_CHS: | 67 case CSSPrimitiveValue::CSS_CHS: |
| 68 case CSSPrimitiveValue::CSS_VW: | 68 case CSSPrimitiveValue::CSS_VW: |
| 69 case CSSPrimitiveValue::CSS_VH: | 69 case CSSPrimitiveValue::CSS_VH: |
| 70 case CSSPrimitiveValue::CSS_VMIN: | 70 case CSSPrimitiveValue::CSS_VMIN: |
| 71 case CSSPrimitiveValue::CSS_VMAX: | 71 case CSSPrimitiveValue::CSS_VMAX: |
| 72 return CalcLength; | 72 return CalcLength; |
| 73 // FIXME: Support angle, time and frequency units. | 73 case CSSPrimitiveValue::CSS_DEG: |
| 74 // http://www.w3.org/TR/css3-values/#calc-notation | 74 case CSSPrimitiveValue::CSS_GRAD: |
| 75 case CSSPrimitiveValue::CSS_RAD: | |
| 76 case CSSPrimitiveValue::CSS_TURN: | |
| 77 return CalcAngle; | |
| 78 case CSSPrimitiveValue::CSS_MS: | |
| 79 case CSSPrimitiveValue::CSS_S: | |
| 80 return CalcTime; | |
| 81 case CSSPrimitiveValue::CSS_HZ: | |
| 82 case CSSPrimitiveValue::CSS_KHZ: | |
| 83 return CalcFrequency; | |
| 75 default: | 84 default: |
| 85 ASSERT_NOT_REACHED(); | |
| 76 return CalcOther; | 86 return CalcOther; |
| 77 } | 87 } |
| 78 } | 88 } |
| 79 | 89 |
| 80 static bool hasDoubleValue(CSSPrimitiveValue::UnitType type) | 90 static bool hasDoubleValue(CSSPrimitiveValue::UnitType type) |
| 81 { | 91 { |
| 82 switch (type) { | 92 switch (type) { |
| 83 case CSSPrimitiveValue::CSS_NUMBER: | 93 case CSSPrimitiveValue::CSS_NUMBER: |
| 84 case CSSPrimitiveValue::CSS_PARSER_INTEGER: | 94 case CSSPrimitiveValue::CSS_PARSER_INTEGER: |
| 85 case CSSPrimitiveValue::CSS_PERCENTAGE: | 95 case CSSPrimitiveValue::CSS_PERCENTAGE: |
| 86 case CSSPrimitiveValue::CSS_EMS: | 96 case CSSPrimitiveValue::CSS_EMS: |
| 87 case CSSPrimitiveValue::CSS_EXS: | 97 case CSSPrimitiveValue::CSS_EXS: |
| 88 case CSSPrimitiveValue::CSS_CHS: | 98 case CSSPrimitiveValue::CSS_CHS: |
| 89 case CSSPrimitiveValue::CSS_REMS: | 99 case CSSPrimitiveValue::CSS_REMS: |
| 90 case CSSPrimitiveValue::CSS_PX: | 100 case CSSPrimitiveValue::CSS_PX: |
| 91 case CSSPrimitiveValue::CSS_CM: | 101 case CSSPrimitiveValue::CSS_CM: |
| 92 case CSSPrimitiveValue::CSS_MM: | 102 case CSSPrimitiveValue::CSS_MM: |
| 93 case CSSPrimitiveValue::CSS_IN: | 103 case CSSPrimitiveValue::CSS_IN: |
| 94 case CSSPrimitiveValue::CSS_PT: | 104 case CSSPrimitiveValue::CSS_PT: |
| 95 case CSSPrimitiveValue::CSS_PC: | 105 case CSSPrimitiveValue::CSS_PC: |
| 96 case CSSPrimitiveValue::CSS_DEG: | 106 case CSSPrimitiveValue::CSS_DEG: |
| 97 case CSSPrimitiveValue::CSS_RAD: | 107 case CSSPrimitiveValue::CSS_RAD: |
| 98 case CSSPrimitiveValue::CSS_GRAD: | 108 case CSSPrimitiveValue::CSS_GRAD: |
| 109 case CSSPrimitiveValue::CSS_TURN: | |
| 99 case CSSPrimitiveValue::CSS_MS: | 110 case CSSPrimitiveValue::CSS_MS: |
| 100 case CSSPrimitiveValue::CSS_S: | 111 case CSSPrimitiveValue::CSS_S: |
| 101 case CSSPrimitiveValue::CSS_HZ: | 112 case CSSPrimitiveValue::CSS_HZ: |
| 102 case CSSPrimitiveValue::CSS_KHZ: | 113 case CSSPrimitiveValue::CSS_KHZ: |
| 103 case CSSPrimitiveValue::CSS_DIMENSION: | 114 case CSSPrimitiveValue::CSS_DIMENSION: |
| 104 case CSSPrimitiveValue::CSS_VW: | 115 case CSSPrimitiveValue::CSS_VW: |
| 105 case CSSPrimitiveValue::CSS_VH: | 116 case CSSPrimitiveValue::CSS_VH: |
| 106 case CSSPrimitiveValue::CSS_VMIN: | 117 case CSSPrimitiveValue::CSS_VMIN: |
| 107 case CSSPrimitiveValue::CSS_VMAX: | 118 case CSSPrimitiveValue::CSS_VMAX: |
| 108 case CSSPrimitiveValue::CSS_DPPX: | 119 case CSSPrimitiveValue::CSS_DPPX: |
| 109 case CSSPrimitiveValue::CSS_DPI: | 120 case CSSPrimitiveValue::CSS_DPI: |
| 110 case CSSPrimitiveValue::CSS_DPCM: | 121 case CSSPrimitiveValue::CSS_DPCM: |
| 111 case CSSPrimitiveValue::CSS_FR: | 122 case CSSPrimitiveValue::CSS_FR: |
| 112 return true; | 123 return true; |
| 113 case CSSPrimitiveValue::CSS_UNKNOWN: | 124 case CSSPrimitiveValue::CSS_UNKNOWN: |
| 114 case CSSPrimitiveValue::CSS_STRING: | 125 case CSSPrimitiveValue::CSS_STRING: |
| 115 case CSSPrimitiveValue::CSS_URI: | 126 case CSSPrimitiveValue::CSS_URI: |
| 116 case CSSPrimitiveValue::CSS_IDENT: | 127 case CSSPrimitiveValue::CSS_IDENT: |
| 117 case CSSPrimitiveValue::CSS_ATTR: | 128 case CSSPrimitiveValue::CSS_ATTR: |
| 118 case CSSPrimitiveValue::CSS_COUNTER: | 129 case CSSPrimitiveValue::CSS_COUNTER: |
| 119 case CSSPrimitiveValue::CSS_RECT: | 130 case CSSPrimitiveValue::CSS_RECT: |
| 120 case CSSPrimitiveValue::CSS_RGBCOLOR: | 131 case CSSPrimitiveValue::CSS_RGBCOLOR: |
| 121 case CSSPrimitiveValue::CSS_PAIR: | 132 case CSSPrimitiveValue::CSS_PAIR: |
| 122 case CSSPrimitiveValue::CSS_UNICODE_RANGE: | 133 case CSSPrimitiveValue::CSS_UNICODE_RANGE: |
| 123 case CSSPrimitiveValue::CSS_PARSER_OPERATOR: | 134 case CSSPrimitiveValue::CSS_PARSER_OPERATOR: |
| 124 case CSSPrimitiveValue::CSS_PARSER_HEXCOLOR: | 135 case CSSPrimitiveValue::CSS_PARSER_HEXCOLOR: |
| 125 case CSSPrimitiveValue::CSS_PARSER_IDENTIFIER: | 136 case CSSPrimitiveValue::CSS_PARSER_IDENTIFIER: |
| 126 case CSSPrimitiveValue::CSS_TURN: | |
| 127 case CSSPrimitiveValue::CSS_COUNTER_NAME: | 137 case CSSPrimitiveValue::CSS_COUNTER_NAME: |
| 128 case CSSPrimitiveValue::CSS_SHAPE: | 138 case CSSPrimitiveValue::CSS_SHAPE: |
| 129 case CSSPrimitiveValue::CSS_QUAD: | 139 case CSSPrimitiveValue::CSS_QUAD: |
| 130 case CSSPrimitiveValue::CSS_CALC: | 140 case CSSPrimitiveValue::CSS_CALC: |
| 131 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: | 141 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: |
| 132 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH: | 142 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH: |
| 133 case CSSPrimitiveValue::CSS_PROPERTY_ID: | 143 case CSSPrimitiveValue::CSS_PROPERTY_ID: |
| 134 case CSSPrimitiveValue::CSS_VALUE_ID: | 144 case CSSPrimitiveValue::CSS_VALUE_ID: |
| 135 return false; | 145 return false; |
| 136 }; | 146 }; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 return m_value->getDoubleValue(); | 235 return m_value->getDoubleValue(); |
| 226 ASSERT_NOT_REACHED(); | 236 ASSERT_NOT_REACHED(); |
| 227 return 0; | 237 return 0; |
| 228 } | 238 } |
| 229 | 239 |
| 230 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa ta) const OVERRIDE | 240 virtual double computeLengthPx(const CSSToLengthConversionData& conversionDa ta) const OVERRIDE |
| 231 { | 241 { |
| 232 switch (m_category) { | 242 switch (m_category) { |
| 233 case CalcLength: | 243 case CalcLength: |
| 234 return m_value->computeLength<double>(conversionData); | 244 return m_value->computeLength<double>(conversionData); |
| 245 case CalcNumber: | |
| 235 case CalcPercent: | 246 case CalcPercent: |
| 236 case CalcNumber: | |
| 237 return m_value->getDoubleValue(); | 247 return m_value->getDoubleValue(); |
| 248 case CalcAngle: | |
| 249 case CalcFrequency: | |
| 238 case CalcPercentLength: | 250 case CalcPercentLength: |
| 239 case CalcPercentNumber: | 251 case CalcPercentNumber: |
| 252 case CalcTime: | |
| 240 case CalcOther: | 253 case CalcOther: |
| 241 ASSERT_NOT_REACHED(); | 254 ASSERT_NOT_REACHED(); |
| 242 break; | 255 break; |
| 243 } | 256 } |
| 244 ASSERT_NOT_REACHED(); | 257 ASSERT_NOT_REACHED(); |
| 245 return 0; | 258 return 0; |
| 246 } | 259 } |
| 247 | 260 |
| 248 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, double multi plier) const | 261 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, double multi plier) const |
| 249 { | 262 { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 276 CSSCalcPrimitiveValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value, bool isInteger) | 289 CSSCalcPrimitiveValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value, bool isInteger) |
| 277 : CSSCalcExpressionNode(unitCategory(value->primitiveType()), isInteger) | 290 : CSSCalcExpressionNode(unitCategory(value->primitiveType()), isInteger) |
| 278 , m_value(value) | 291 , m_value(value) |
| 279 { | 292 { |
| 280 } | 293 } |
| 281 | 294 |
| 282 RefPtrWillBeMember<CSSPrimitiveValue> m_value; | 295 RefPtrWillBeMember<CSSPrimitiveValue> m_value; |
| 283 }; | 296 }; |
| 284 | 297 |
| 285 static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = { | 298 static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = { |
| 286 // CalcNumber CalcLength CalcPercent CalcPercentNumber CalcPercentLength | 299 // CalcNumber CalcLength CalcPercent CalcPercentNumber CalcPercentLength CalcAngle CalcTime CalcFrequency |
| 287 /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther }, | 300 /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, |
| 288 /* CalcLength */ { CalcOther, CalcLength, CalcPercentLengt h, CalcOther, CalcPercentLength }, | 301 /* CalcLength */ { CalcOther, CalcLength, CalcPercentLengt h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, |
| 289 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent, CalcPercentNumber, CalcPercentLength }, | 302 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent, CalcPercentNumber, CalcPercentLength, CalcOther, CalcOther, CalcOther }, |
| 290 /* CalcPercentNumber */ { CalcPercentNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther }, | 303 /* CalcPercentNumber */ { CalcPercentNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, |
| 291 /* CalcPercentLength */ { CalcOther, CalcPercentLength, CalcPercentLengt h, CalcOther, CalcPercentLength }, | 304 /* CalcPercentLength */ { CalcOther, CalcPercentLength, CalcPercentLengt h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, |
| 305 /* CalcAngle */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcAngle, CalcOther, CalcOther }, | |
| 306 /* CalcTime */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcTime, CalcOther }, | |
| 307 /* CalcFrequency */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcFrequency } | |
| 292 }; | 308 }; |
| 293 | 309 |
| 294 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op) | 310 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op) |
| 295 { | 311 { |
| 296 CalculationCategory leftCategory = leftSide.category(); | 312 CalculationCategory leftCategory = leftSide.category(); |
| 297 CalculationCategory rightCategory = rightSide.category(); | 313 CalculationCategory rightCategory = rightSide.category(); |
| 298 | 314 |
| 299 if (leftCategory == CalcOther || rightCategory == CalcOther) | 315 if (leftCategory == CalcOther || rightCategory == CalcOther) |
| 300 return CalcOther; | 316 return CalcOther; |
| 301 | 317 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 case CalcPercent: { | 526 case CalcPercent: { |
| 511 if (m_leftSide->category() == CalcNumber) | 527 if (m_leftSide->category() == CalcNumber) |
| 512 return m_rightSide->primitiveType(); | 528 return m_rightSide->primitiveType(); |
| 513 if (m_rightSide->category() == CalcNumber) | 529 if (m_rightSide->category() == CalcNumber) |
| 514 return m_leftSide->primitiveType(); | 530 return m_leftSide->primitiveType(); |
| 515 CSSPrimitiveValue::UnitType leftType = m_leftSide->primitiveType(); | 531 CSSPrimitiveValue::UnitType leftType = m_leftSide->primitiveType(); |
| 516 if (leftType == m_rightSide->primitiveType()) | 532 if (leftType == m_rightSide->primitiveType()) |
| 517 return leftType; | 533 return leftType; |
| 518 return CSSPrimitiveValue::CSS_UNKNOWN; | 534 return CSSPrimitiveValue::CSS_UNKNOWN; |
| 519 } | 535 } |
| 536 case CalcAngle: | |
| 537 return CSSPrimitiveValue::CSS_DEG; | |
| 538 case CalcTime: | |
| 539 return CSSPrimitiveValue::CSS_MS; | |
| 540 case CalcFrequency: | |
| 541 return CSSPrimitiveValue::CSS_HZ; | |
| 520 case CalcPercentLength: | 542 case CalcPercentLength: |
| 521 case CalcPercentNumber: | 543 case CalcPercentNumber: |
| 522 case CalcOther: | 544 case CalcOther: |
| 523 return CSSPrimitiveValue::CSS_UNKNOWN; | 545 return CSSPrimitiveValue::CSS_UNKNOWN; |
| 524 } | 546 } |
| 525 ASSERT_NOT_REACHED(); | 547 ASSERT_NOT_REACHED(); |
| 526 return CSSPrimitiveValue::CSS_UNKNOWN; | 548 return CSSPrimitiveValue::CSS_UNKNOWN; |
| 527 } | 549 } |
| 528 | 550 |
| 529 virtual void trace(Visitor* visitor) | 551 virtual void trace(Visitor* visitor) |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result) | 645 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result) |
| 624 { | 646 { |
| 625 CSSParserValue* parserValue = tokens->valueAt(*index); | 647 CSSParserValue* parserValue = tokens->valueAt(*index); |
| 626 if (parserValue->unit == CSSParserValue::Operator) | 648 if (parserValue->unit == CSSParserValue::Operator) |
| 627 return false; | 649 return false; |
| 628 | 650 |
| 629 RefPtrWillBeRawPtr<CSSValue> value = parserValue->createCSSValue(); | 651 RefPtrWillBeRawPtr<CSSValue> value = parserValue->createCSSValue(); |
| 630 if (!value || !value->isPrimitiveValue()) | 652 if (!value || !value->isPrimitiveValue()) |
| 631 return false; | 653 return false; |
| 632 | 654 |
| 633 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); | 655 result->value = CSSCalcPrimitiveValue::create(toCSSPrimitiveValue(value. get()), parserValue->isInt); |
|
alancutter (OOO until 2018)
2014/07/21 14:03:47
The unitCategory check could be turned into an ASS
reni
2014/07/25 08:44:43
Good point! calc(42fr) showed that we have to coun
| |
| 634 if (unitCategory(primitiveValue->primitiveType()) == CalcOther) | |
| 635 return false; | |
| 636 | |
| 637 result->value = CSSCalcPrimitiveValue::create(primitiveValue, parserValu e->isInt); | |
| 638 | 656 |
| 639 ++*index; | 657 ++*index; |
| 640 return true; | 658 return true; |
| 641 } | 659 } |
| 642 | 660 |
| 643 bool parseValueTerm(CSSParserValueList* tokens, int depth, unsigned* index, Value* result) | 661 bool parseValueTerm(CSSParserValueList* tokens, int depth, unsigned* index, Value* result) |
| 644 { | 662 { |
| 645 if (checkDepthAndIndex(&depth, *index, tokens) != OK) | 663 if (checkDepthAndIndex(&depth, *index, tokens) != OK) |
| 646 return false; | 664 return false; |
| 647 | 665 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); | 772 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); |
| 755 } | 773 } |
| 756 | 774 |
| 757 void CSSCalcValue::traceAfterDispatch(Visitor* visitor) | 775 void CSSCalcValue::traceAfterDispatch(Visitor* visitor) |
| 758 { | 776 { |
| 759 visitor->trace(m_expression); | 777 visitor->trace(m_expression); |
| 760 CSSValue::traceAfterDispatch(visitor); | 778 CSSValue::traceAfterDispatch(visitor); |
| 761 } | 779 } |
| 762 | 780 |
| 763 } // namespace WebCore | 781 } // namespace WebCore |
| OLD | NEW |