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