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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 TooDeep, | 44 TooDeep, |
45 NoMoreTokens | 45 NoMoreTokens |
46 }; | 46 }; |
47 | 47 |
48 namespace blink { | 48 namespace blink { |
49 | 49 |
50 static CalculationCategory unitCategory(CSSPrimitiveValue::UnitType type) | 50 static CalculationCategory unitCategory(CSSPrimitiveValue::UnitType type) |
51 { | 51 { |
52 switch (type) { | 52 switch (type) { |
53 case CSSPrimitiveValue::CSS_NUMBER: | 53 case CSSPrimitiveValue::CSS_NUMBER: |
54 case CSSPrimitiveValue::CSS_PARSER_INTEGER: | |
55 return CalcNumber; | 54 return CalcNumber; |
56 case CSSPrimitiveValue::CSS_PERCENTAGE: | 55 case CSSPrimitiveValue::CSS_PERCENTAGE: |
57 return CalcPercent; | 56 return CalcPercent; |
58 case CSSPrimitiveValue::CSS_EMS: | 57 case CSSPrimitiveValue::CSS_EMS: |
59 case CSSPrimitiveValue::CSS_EXS: | 58 case CSSPrimitiveValue::CSS_EXS: |
60 case CSSPrimitiveValue::CSS_PX: | 59 case CSSPrimitiveValue::CSS_PX: |
61 case CSSPrimitiveValue::CSS_CM: | 60 case CSSPrimitiveValue::CSS_CM: |
62 case CSSPrimitiveValue::CSS_MM: | 61 case CSSPrimitiveValue::CSS_MM: |
63 case CSSPrimitiveValue::CSS_IN: | 62 case CSSPrimitiveValue::CSS_IN: |
64 case CSSPrimitiveValue::CSS_PT: | 63 case CSSPrimitiveValue::CSS_PT: |
(...skipping 18 matching lines...) Expand all Loading... |
83 return CalcFrequency; | 82 return CalcFrequency; |
84 default: | 83 default: |
85 return CalcOther; | 84 return CalcOther; |
86 } | 85 } |
87 } | 86 } |
88 | 87 |
89 static bool hasDoubleValue(CSSPrimitiveValue::UnitType type) | 88 static bool hasDoubleValue(CSSPrimitiveValue::UnitType type) |
90 { | 89 { |
91 switch (type) { | 90 switch (type) { |
92 case CSSPrimitiveValue::CSS_NUMBER: | 91 case CSSPrimitiveValue::CSS_NUMBER: |
93 case CSSPrimitiveValue::CSS_PARSER_INTEGER: | |
94 case CSSPrimitiveValue::CSS_PERCENTAGE: | 92 case CSSPrimitiveValue::CSS_PERCENTAGE: |
95 case CSSPrimitiveValue::CSS_EMS: | 93 case CSSPrimitiveValue::CSS_EMS: |
96 case CSSPrimitiveValue::CSS_EXS: | 94 case CSSPrimitiveValue::CSS_EXS: |
97 case CSSPrimitiveValue::CSS_CHS: | 95 case CSSPrimitiveValue::CSS_CHS: |
98 case CSSPrimitiveValue::CSS_REMS: | 96 case CSSPrimitiveValue::CSS_REMS: |
99 case CSSPrimitiveValue::CSS_PX: | 97 case CSSPrimitiveValue::CSS_PX: |
100 case CSSPrimitiveValue::CSS_CM: | 98 case CSSPrimitiveValue::CSS_CM: |
101 case CSSPrimitiveValue::CSS_MM: | 99 case CSSPrimitiveValue::CSS_MM: |
102 case CSSPrimitiveValue::CSS_IN: | 100 case CSSPrimitiveValue::CSS_IN: |
103 case CSSPrimitiveValue::CSS_PT: | 101 case CSSPrimitiveValue::CSS_PT: |
(...skipping 19 matching lines...) Expand all Loading... |
123 case CSSPrimitiveValue::CSS_UNKNOWN: | 121 case CSSPrimitiveValue::CSS_UNKNOWN: |
124 case CSSPrimitiveValue::CSS_STRING: | 122 case CSSPrimitiveValue::CSS_STRING: |
125 case CSSPrimitiveValue::CSS_URI: | 123 case CSSPrimitiveValue::CSS_URI: |
126 case CSSPrimitiveValue::CSS_IDENT: | 124 case CSSPrimitiveValue::CSS_IDENT: |
127 case CSSPrimitiveValue::CSS_ATTR: | 125 case CSSPrimitiveValue::CSS_ATTR: |
128 case CSSPrimitiveValue::CSS_COUNTER: | 126 case CSSPrimitiveValue::CSS_COUNTER: |
129 case CSSPrimitiveValue::CSS_RECT: | 127 case CSSPrimitiveValue::CSS_RECT: |
130 case CSSPrimitiveValue::CSS_RGBCOLOR: | 128 case CSSPrimitiveValue::CSS_RGBCOLOR: |
131 case CSSPrimitiveValue::CSS_PAIR: | 129 case CSSPrimitiveValue::CSS_PAIR: |
132 case CSSPrimitiveValue::CSS_UNICODE_RANGE: | 130 case CSSPrimitiveValue::CSS_UNICODE_RANGE: |
133 case CSSPrimitiveValue::CSS_PARSER_OPERATOR: | |
134 case CSSPrimitiveValue::CSS_PARSER_HEXCOLOR: | 131 case CSSPrimitiveValue::CSS_PARSER_HEXCOLOR: |
135 case CSSPrimitiveValue::CSS_PARSER_IDENTIFIER: | |
136 case CSSPrimitiveValue::CSS_COUNTER_NAME: | 132 case CSSPrimitiveValue::CSS_COUNTER_NAME: |
137 case CSSPrimitiveValue::CSS_SHAPE: | 133 case CSSPrimitiveValue::CSS_SHAPE: |
138 case CSSPrimitiveValue::CSS_QUAD: | 134 case CSSPrimitiveValue::CSS_QUAD: |
139 case CSSPrimitiveValue::CSS_CALC: | 135 case CSSPrimitiveValue::CSS_CALC: |
140 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: | 136 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: |
141 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH: | 137 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH: |
142 case CSSPrimitiveValue::CSS_PROPERTY_ID: | 138 case CSSPrimitiveValue::CSS_PROPERTY_ID: |
143 case CSSPrimitiveValue::CSS_VALUE_ID: | 139 case CSSPrimitiveValue::CSS_VALUE_ID: |
144 return false; | 140 return false; |
145 }; | 141 }; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createSimplified(PassRe
fPtrWillBeRawPtr<CSSCalcExpressionNode> leftSide, PassRefPtrWillBeRawPtr<CSSCalc
ExpressionNode> rightSide, CalcOperator op) | 352 static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> createSimplified(PassRe
fPtrWillBeRawPtr<CSSCalcExpressionNode> leftSide, PassRefPtrWillBeRawPtr<CSSCalc
ExpressionNode> rightSide, CalcOperator op) |
357 { | 353 { |
358 CalculationCategory leftCategory = leftSide->category(); | 354 CalculationCategory leftCategory = leftSide->category(); |
359 CalculationCategory rightCategory = rightSide->category(); | 355 CalculationCategory rightCategory = rightSide->category(); |
360 ASSERT(leftCategory != CalcOther && rightCategory != CalcOther); | 356 ASSERT(leftCategory != CalcOther && rightCategory != CalcOther); |
361 | 357 |
362 bool isInteger = isIntegerResult(leftSide.get(), rightSide.get(), op); | 358 bool isInteger = isIntegerResult(leftSide.get(), rightSide.get(), op); |
363 | 359 |
364 // Simplify numbers. | 360 // Simplify numbers. |
365 if (leftCategory == CalcNumber && rightCategory == CalcNumber) { | 361 if (leftCategory == CalcNumber && rightCategory == CalcNumber) { |
366 CSSPrimitiveValue::UnitType evaluationType = isInteger ? CSSPrimitiv
eValue::CSS_PARSER_INTEGER : CSSPrimitiveValue::CSS_NUMBER; | 362 return CSSCalcPrimitiveValue::create(evaluateOperator(leftSide->doub
leValue(), rightSide->doubleValue(), op), CSSPrimitiveValue::CSS_NUMBER, isInteg
er); |
367 return CSSCalcPrimitiveValue::create(evaluateOperator(leftSide->doub
leValue(), rightSide->doubleValue(), op), evaluationType, isInteger); | |
368 } | 363 } |
369 | 364 |
370 // Simplify addition and subtraction between same types. | 365 // Simplify addition and subtraction between same types. |
371 if (op == CalcAdd || op == CalcSubtract) { | 366 if (op == CalcAdd || op == CalcSubtract) { |
372 if (leftCategory == rightSide->category()) { | 367 if (leftCategory == rightSide->category()) { |
373 CSSPrimitiveValue::UnitType leftType = leftSide->primitiveType()
; | 368 CSSPrimitiveValue::UnitType leftType = leftSide->primitiveType()
; |
374 if (hasDoubleValue(leftType)) { | 369 if (hasDoubleValue(leftType)) { |
375 CSSPrimitiveValue::UnitType rightType = rightSide->primitive
Type(); | 370 CSSPrimitiveValue::UnitType rightType = rightSide->primitive
Type(); |
376 if (leftType == rightType) | 371 if (leftType == rightType) |
377 return CSSCalcPrimitiveValue::create(evaluateOperator(le
ftSide->doubleValue(), rightSide->doubleValue(), op), leftType, isInteger); | 372 return CSSCalcPrimitiveValue::create(evaluateOperator(le
ftSide->doubleValue(), rightSide->doubleValue(), op), leftType, isInteger); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 && m_operator == other.m_operator; | 506 && m_operator == other.m_operator; |
512 } | 507 } |
513 | 508 |
514 virtual Type type() const OVERRIDE { return CssCalcBinaryOperation; } | 509 virtual Type type() const OVERRIDE { return CssCalcBinaryOperation; } |
515 | 510 |
516 virtual CSSPrimitiveValue::UnitType primitiveType() const OVERRIDE | 511 virtual CSSPrimitiveValue::UnitType primitiveType() const OVERRIDE |
517 { | 512 { |
518 switch (m_category) { | 513 switch (m_category) { |
519 case CalcNumber: | 514 case CalcNumber: |
520 ASSERT(m_leftSide->category() == CalcNumber && m_rightSide->category
() == CalcNumber); | 515 ASSERT(m_leftSide->category() == CalcNumber && m_rightSide->category
() == CalcNumber); |
521 if (m_isInteger) | |
522 return CSSPrimitiveValue::CSS_PARSER_INTEGER; | |
523 return CSSPrimitiveValue::CSS_NUMBER; | 516 return CSSPrimitiveValue::CSS_NUMBER; |
524 case CalcLength: | 517 case CalcLength: |
525 case CalcPercent: { | 518 case CalcPercent: { |
526 if (m_leftSide->category() == CalcNumber) | 519 if (m_leftSide->category() == CalcNumber) |
527 return m_rightSide->primitiveType(); | 520 return m_rightSide->primitiveType(); |
528 if (m_rightSide->category() == CalcNumber) | 521 if (m_rightSide->category() == CalcNumber) |
529 return m_leftSide->primitiveType(); | 522 return m_leftSide->primitiveType(); |
530 CSSPrimitiveValue::UnitType leftType = m_leftSide->primitiveType(); | 523 CSSPrimitiveValue::UnitType leftType = m_leftSide->primitiveType(); |
531 if (leftType == m_rightSide->primitiveType()) | 524 if (leftType == m_rightSide->primitiveType()) |
532 return leftType; | 525 return leftType; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result) | 637 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result) |
645 { | 638 { |
646 CSSParserValue* parserValue = tokens->valueAt(*index); | 639 CSSParserValue* parserValue = tokens->valueAt(*index); |
647 if (parserValue->unit >= CSSParserValue::Operator) | 640 if (parserValue->unit >= CSSParserValue::Operator) |
648 return false; | 641 return false; |
649 | 642 |
650 CSSPrimitiveValue::UnitType type = static_cast<CSSPrimitiveValue::UnitTy
pe>(parserValue->unit); | 643 CSSPrimitiveValue::UnitType type = static_cast<CSSPrimitiveValue::UnitTy
pe>(parserValue->unit); |
651 if (unitCategory(type) == CalcOther) | 644 if (unitCategory(type) == CalcOther) |
652 return false; | 645 return false; |
653 | 646 |
654 if (type == CSSPrimitiveValue::CSS_NUMBER && parserValue->isInt) | |
655 type = CSSPrimitiveValue::CSS_PARSER_INTEGER; | |
656 | |
657 result->value = CSSCalcPrimitiveValue::create( | 647 result->value = CSSCalcPrimitiveValue::create( |
658 CSSPrimitiveValue::create(parserValue->fValue, type), parserValue->i
sInt); | 648 CSSPrimitiveValue::create(parserValue->fValue, type), parserValue->i
sInt); |
659 | 649 |
660 ++*index; | 650 ++*index; |
661 return true; | 651 return true; |
662 } | 652 } |
663 | 653 |
664 bool parseValueTerm(CSSParserValueList* tokens, int depth, unsigned* index,
Value* result) | 654 bool parseValueTerm(CSSParserValueList* tokens, int depth, unsigned* index,
Value* result) |
665 { | 655 { |
666 if (checkDepthAndIndex(&depth, *index, tokens) != OK) | 656 if (checkDepthAndIndex(&depth, *index, tokens) != OK) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); | 765 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); |
776 } | 766 } |
777 | 767 |
778 void CSSCalcValue::traceAfterDispatch(Visitor* visitor) | 768 void CSSCalcValue::traceAfterDispatch(Visitor* visitor) |
779 { | 769 { |
780 visitor->trace(m_expression); | 770 visitor->trace(m_expression); |
781 CSSValue::traceAfterDispatch(visitor); | 771 CSSValue::traceAfterDispatch(visitor); |
782 } | 772 } |
783 | 773 |
784 } // namespace blink | 774 } // namespace blink |
OLD | NEW |