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 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/css/CSSCalculationValue.h" | 32 #include "core/css/CSSCalculationValue.h" |
33 | 33 |
34 #include "core/css/CSSPrimitiveValueMappings.h" | 34 #include "core/css/CSSPrimitiveValueMappings.h" |
| 35 #include "core/css/parser/CSSPropertyParser.h" |
35 #include "core/css/resolver/StyleResolver.h" | 36 #include "core/css/resolver/StyleResolver.h" |
36 #include "wtf/MathExtras.h" | 37 #include "wtf/MathExtras.h" |
37 #include "wtf/OwnPtr.h" | 38 #include "wtf/OwnPtr.h" |
38 #include "wtf/text/StringBuilder.h" | 39 #include "wtf/text/StringBuilder.h" |
39 | 40 |
40 static const int maxExpressionDepth = 100; | 41 static const int maxExpressionDepth = 100; |
41 | 42 |
42 enum ParseState { | 43 enum ParseState { |
43 OK, | 44 OK, |
44 TooDeep, | 45 TooDeep, |
(...skipping 28 matching lines...) Expand all Loading... |
73 case CSSPrimitiveValue::CSS_GRAD: | 74 case CSSPrimitiveValue::CSS_GRAD: |
74 case CSSPrimitiveValue::CSS_RAD: | 75 case CSSPrimitiveValue::CSS_RAD: |
75 case CSSPrimitiveValue::CSS_TURN: | 76 case CSSPrimitiveValue::CSS_TURN: |
76 return CalcAngle; | 77 return CalcAngle; |
77 case CSSPrimitiveValue::CSS_MS: | 78 case CSSPrimitiveValue::CSS_MS: |
78 case CSSPrimitiveValue::CSS_S: | 79 case CSSPrimitiveValue::CSS_S: |
79 return CalcTime; | 80 return CalcTime; |
80 case CSSPrimitiveValue::CSS_HZ: | 81 case CSSPrimitiveValue::CSS_HZ: |
81 case CSSPrimitiveValue::CSS_KHZ: | 82 case CSSPrimitiveValue::CSS_KHZ: |
82 return CalcFrequency; | 83 return CalcFrequency; |
| 84 case CSSPrimitiveValue::CSS_VARIABLE_REFERENCE: |
| 85 return CalcVariable; |
83 default: | 86 default: |
84 return CalcOther; | 87 return CalcOther; |
85 } | 88 } |
86 } | 89 } |
87 | 90 |
88 static bool hasDoubleValue(CSSPrimitiveValue::UnitType type) | 91 static bool hasDoubleValue(CSSPrimitiveValue::UnitType type) |
89 { | 92 { |
90 switch (type) { | 93 switch (type) { |
91 case CSSPrimitiveValue::CSS_NUMBER: | 94 case CSSPrimitiveValue::CSS_NUMBER: |
92 case CSSPrimitiveValue::CSS_PERCENTAGE: | 95 case CSSPrimitiveValue::CSS_PERCENTAGE: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 case CSSPrimitiveValue::CSS_RGBCOLOR: | 131 case CSSPrimitiveValue::CSS_RGBCOLOR: |
129 case CSSPrimitiveValue::CSS_PAIR: | 132 case CSSPrimitiveValue::CSS_PAIR: |
130 case CSSPrimitiveValue::CSS_SHAPE: | 133 case CSSPrimitiveValue::CSS_SHAPE: |
131 case CSSPrimitiveValue::CSS_QUAD: | 134 case CSSPrimitiveValue::CSS_QUAD: |
132 case CSSPrimitiveValue::CSS_CALC: | 135 case CSSPrimitiveValue::CSS_CALC: |
133 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: | 136 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER: |
134 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH: | 137 case CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH: |
135 case CSSPrimitiveValue::CSS_PROPERTY_ID: | 138 case CSSPrimitiveValue::CSS_PROPERTY_ID: |
136 case CSSPrimitiveValue::CSS_VALUE_ID: | 139 case CSSPrimitiveValue::CSS_VALUE_ID: |
137 case CSSPrimitiveValue::CSS_QEM: | 140 case CSSPrimitiveValue::CSS_QEM: |
| 141 case CSSPrimitiveValue::CSS_VARIABLE_REFERENCE: |
138 return false; | 142 return false; |
139 }; | 143 }; |
140 ASSERT_NOT_REACHED(); | 144 ASSERT_NOT_REACHED(); |
141 return false; | 145 return false; |
142 } | 146 } |
143 | 147 |
144 static String buildCSSText(const String& expression) | 148 static String buildCSSText(const String& expression) |
145 { | 149 { |
146 StringBuilder result; | 150 StringBuilder result; |
147 result.appendLiteral("calc"); | 151 result.appendLiteral("calc"); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 case CalcLength: | 240 case CalcLength: |
237 return m_value->computeLength<double>(conversionData); | 241 return m_value->computeLength<double>(conversionData); |
238 case CalcNumber: | 242 case CalcNumber: |
239 case CalcPercent: | 243 case CalcPercent: |
240 return m_value->getDoubleValue(); | 244 return m_value->getDoubleValue(); |
241 case CalcAngle: | 245 case CalcAngle: |
242 case CalcFrequency: | 246 case CalcFrequency: |
243 case CalcPercentLength: | 247 case CalcPercentLength: |
244 case CalcPercentNumber: | 248 case CalcPercentNumber: |
245 case CalcTime: | 249 case CalcTime: |
| 250 case CalcVariable: |
246 case CalcOther: | 251 case CalcOther: |
247 ASSERT_NOT_REACHED(); | 252 ASSERT_NOT_REACHED(); |
248 break; | 253 break; |
249 } | 254 } |
250 ASSERT_NOT_REACHED(); | 255 ASSERT_NOT_REACHED(); |
251 return 0; | 256 return 0; |
252 } | 257 } |
253 | 258 |
254 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTyp
eArray& lengthTypeArray, double multiplier) const override | 259 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTyp
eArray& lengthTypeArray, double multiplier) const override |
255 { | 260 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 }; | 306 }; |
302 | 307 |
303 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi
de, const CSSCalcExpressionNode& rightSide, CalcOperator op) | 308 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi
de, const CSSCalcExpressionNode& rightSide, CalcOperator op) |
304 { | 309 { |
305 CalculationCategory leftCategory = leftSide.category(); | 310 CalculationCategory leftCategory = leftSide.category(); |
306 CalculationCategory rightCategory = rightSide.category(); | 311 CalculationCategory rightCategory = rightSide.category(); |
307 | 312 |
308 if (leftCategory == CalcOther || rightCategory == CalcOther) | 313 if (leftCategory == CalcOther || rightCategory == CalcOther) |
309 return CalcOther; | 314 return CalcOther; |
310 | 315 |
| 316 if (leftCategory == CalcVariable || rightCategory == CalcVariable) |
| 317 return CalcVariable; |
| 318 |
311 switch (op) { | 319 switch (op) { |
312 case CalcAdd: | 320 case CalcAdd: |
313 case CalcSubtract: | 321 case CalcSubtract: |
314 return addSubtractResult[leftCategory][rightCategory]; | 322 return addSubtractResult[leftCategory][rightCategory]; |
315 case CalcMultiply: | 323 case CalcMultiply: |
316 if (leftCategory != CalcNumber && rightCategory != CalcNumber) | 324 if (leftCategory != CalcNumber && rightCategory != CalcNumber) |
317 return CalcOther; | 325 return CalcOther; |
318 return leftCategory == CalcNumber ? rightCategory : leftCategory; | 326 return leftCategory == CalcNumber ? rightCategory : leftCategory; |
319 case CalcDivide: | 327 case CalcDivide: |
320 if (rightCategory != CalcNumber || rightSide.isZero()) | 328 if (rightCategory != CalcNumber || rightSide.isZero()) |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 if (leftType == m_rightSide->primitiveType()) | 530 if (leftType == m_rightSide->primitiveType()) |
523 return leftType; | 531 return leftType; |
524 return CSSPrimitiveValue::CSS_UNKNOWN; | 532 return CSSPrimitiveValue::CSS_UNKNOWN; |
525 } | 533 } |
526 case CalcAngle: | 534 case CalcAngle: |
527 return CSSPrimitiveValue::CSS_DEG; | 535 return CSSPrimitiveValue::CSS_DEG; |
528 case CalcTime: | 536 case CalcTime: |
529 return CSSPrimitiveValue::CSS_MS; | 537 return CSSPrimitiveValue::CSS_MS; |
530 case CalcFrequency: | 538 case CalcFrequency: |
531 return CSSPrimitiveValue::CSS_HZ; | 539 return CSSPrimitiveValue::CSS_HZ; |
| 540 case CalcVariable: |
| 541 return CSSPrimitiveValue::CSS_VARIABLE_REFERENCE; |
532 case CalcPercentLength: | 542 case CalcPercentLength: |
533 case CalcPercentNumber: | 543 case CalcPercentNumber: |
534 case CalcOther: | 544 case CalcOther: |
535 return CSSPrimitiveValue::CSS_UNKNOWN; | 545 return CSSPrimitiveValue::CSS_UNKNOWN; |
536 } | 546 } |
537 ASSERT_NOT_REACHED(); | 547 ASSERT_NOT_REACHED(); |
538 return CSSPrimitiveValue::CSS_UNKNOWN; | 548 return CSSPrimitiveValue::CSS_UNKNOWN; |
539 } | 549 } |
540 | 550 |
541 DEFINE_INLINE_VIRTUAL_TRACE() | 551 DEFINE_INLINE_VIRTUAL_TRACE() |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 CSSParserValue* value = tokens->valueAt(index); | 638 CSSParserValue* value = tokens->valueAt(index); |
629 if (value->unit != CSSParserValue::Operator) | 639 if (value->unit != CSSParserValue::Operator) |
630 return 0; | 640 return 0; |
631 | 641 |
632 return value->iValue; | 642 return value->iValue; |
633 } | 643 } |
634 | 644 |
635 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result) | 645 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result) |
636 { | 646 { |
637 CSSParserValue* parserValue = tokens->valueAt(*index); | 647 CSSParserValue* parserValue = tokens->valueAt(*index); |
638 if (parserValue->unit >= CSSParserValue::Operator) | 648 |
639 return false; | 649 if (parserValue->unit >= CSSParserValue::Operator) { |
| 650 // We still have to check for variables, which are parser values |
| 651 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSPropertyPa
rser::isVariableReference(parserValue)) |
| 652 return false; |
| 653 |
| 654 result->value = CSSCalcPrimitiveValue::create( |
| 655 CSSPrimitiveValue::create(parserValue->function->args->valueAt(0
)->string, CSSPrimitiveValue::CSS_VARIABLE_REFERENCE), parserValue->isInt); |
| 656 ++*index; |
| 657 |
| 658 return true; |
| 659 } |
640 | 660 |
641 CSSPrimitiveValue::UnitType type = static_cast<CSSPrimitiveValue::UnitTy
pe>(parserValue->unit); | 661 CSSPrimitiveValue::UnitType type = static_cast<CSSPrimitiveValue::UnitTy
pe>(parserValue->unit); |
| 662 |
642 if (unitCategory(type) == CalcOther) | 663 if (unitCategory(type) == CalcOther) |
643 return false; | 664 return false; |
644 | 665 |
645 result->value = CSSCalcPrimitiveValue::create( | 666 result->value = CSSCalcPrimitiveValue::create( |
646 CSSPrimitiveValue::create(parserValue->fValue, type), parserValue->i
sInt); | 667 CSSPrimitiveValue::create(parserValue->fValue, type), parserValue->i
sInt); |
647 | 668 |
648 ++*index; | 669 ++*index; |
649 return true; | 670 return true; |
650 } | 671 } |
651 | 672 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); | 780 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); |
760 } | 781 } |
761 | 782 |
762 DEFINE_TRACE_AFTER_DISPATCH(CSSCalcValue) | 783 DEFINE_TRACE_AFTER_DISPATCH(CSSCalcValue) |
763 { | 784 { |
764 visitor->trace(m_expression); | 785 visitor->trace(m_expression); |
765 CSSValue::traceAfterDispatch(visitor); | 786 CSSValue::traceAfterDispatch(visitor); |
766 } | 787 } |
767 | 788 |
768 } // namespace blink | 789 } // namespace blink |
OLD | NEW |