Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: Source/core/css/CSSCalculationValue.cpp

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 case CSSPrimitiveValue::CSS_RECT: 130 case CSSPrimitiveValue::CSS_RECT:
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:
140 case CSSPrimitiveValue::CSS_VARIABLE_REFERENCE:
137 return false; 141 return false;
138 }; 142 };
139 ASSERT_NOT_REACHED(); 143 ASSERT_NOT_REACHED();
140 return false; 144 return false;
141 } 145 }
142 146
143 static String buildCSSText(const String& expression) 147 static String buildCSSText(const String& expression)
144 { 148 {
145 StringBuilder result; 149 StringBuilder result;
146 result.appendLiteral("calc"); 150 result.appendLiteral("calc");
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 case CalcLength: 239 case CalcLength:
236 return m_value->computeLength<double>(conversionData); 240 return m_value->computeLength<double>(conversionData);
237 case CalcNumber: 241 case CalcNumber:
238 case CalcPercent: 242 case CalcPercent:
239 return m_value->getDoubleValue(); 243 return m_value->getDoubleValue();
240 case CalcAngle: 244 case CalcAngle:
241 case CalcFrequency: 245 case CalcFrequency:
242 case CalcPercentLength: 246 case CalcPercentLength:
243 case CalcPercentNumber: 247 case CalcPercentNumber:
244 case CalcTime: 248 case CalcTime:
249 case CalcVariable:
245 case CalcOther: 250 case CalcOther:
246 ASSERT_NOT_REACHED(); 251 ASSERT_NOT_REACHED();
247 break; 252 break;
248 } 253 }
249 ASSERT_NOT_REACHED(); 254 ASSERT_NOT_REACHED();
250 return 0; 255 return 0;
251 } 256 }
252 257
253 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTyp eArray& lengthTypeArray, double multiplier) const override 258 virtual void accumulateLengthArray(CSSLengthArray& lengthArray, CSSLengthTyp eArray& lengthTypeArray, double multiplier) const override
254 { 259 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 }; 305 };
301 306
302 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op) 307 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op)
303 { 308 {
304 CalculationCategory leftCategory = leftSide.category(); 309 CalculationCategory leftCategory = leftSide.category();
305 CalculationCategory rightCategory = rightSide.category(); 310 CalculationCategory rightCategory = rightSide.category();
306 311
307 if (leftCategory == CalcOther || rightCategory == CalcOther) 312 if (leftCategory == CalcOther || rightCategory == CalcOther)
308 return CalcOther; 313 return CalcOther;
309 314
315 if (leftCategory == CalcVariable || rightCategory == CalcVariable)
316 return CalcVariable;
317
310 switch (op) { 318 switch (op) {
311 case CalcAdd: 319 case CalcAdd:
312 case CalcSubtract: 320 case CalcSubtract:
313 return addSubtractResult[leftCategory][rightCategory]; 321 return addSubtractResult[leftCategory][rightCategory];
314 case CalcMultiply: 322 case CalcMultiply:
315 if (leftCategory != CalcNumber && rightCategory != CalcNumber) 323 if (leftCategory != CalcNumber && rightCategory != CalcNumber)
316 return CalcOther; 324 return CalcOther;
317 return leftCategory == CalcNumber ? rightCategory : leftCategory; 325 return leftCategory == CalcNumber ? rightCategory : leftCategory;
318 case CalcDivide: 326 case CalcDivide:
319 if (rightCategory != CalcNumber || rightSide.isZero()) 327 if (rightCategory != CalcNumber || rightSide.isZero())
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 if (leftType == m_rightSide->primitiveType()) 529 if (leftType == m_rightSide->primitiveType())
522 return leftType; 530 return leftType;
523 return CSSPrimitiveValue::CSS_UNKNOWN; 531 return CSSPrimitiveValue::CSS_UNKNOWN;
524 } 532 }
525 case CalcAngle: 533 case CalcAngle:
526 return CSSPrimitiveValue::CSS_DEG; 534 return CSSPrimitiveValue::CSS_DEG;
527 case CalcTime: 535 case CalcTime:
528 return CSSPrimitiveValue::CSS_MS; 536 return CSSPrimitiveValue::CSS_MS;
529 case CalcFrequency: 537 case CalcFrequency:
530 return CSSPrimitiveValue::CSS_HZ; 538 return CSSPrimitiveValue::CSS_HZ;
539 case CalcVariable:
540 return CSSPrimitiveValue::CSS_VARIABLE_REFERENCE;
531 case CalcPercentLength: 541 case CalcPercentLength:
532 case CalcPercentNumber: 542 case CalcPercentNumber:
533 case CalcOther: 543 case CalcOther:
534 return CSSPrimitiveValue::CSS_UNKNOWN; 544 return CSSPrimitiveValue::CSS_UNKNOWN;
535 } 545 }
536 ASSERT_NOT_REACHED(); 546 ASSERT_NOT_REACHED();
537 return CSSPrimitiveValue::CSS_UNKNOWN; 547 return CSSPrimitiveValue::CSS_UNKNOWN;
538 } 548 }
539 549
540 DEFINE_INLINE_VIRTUAL_TRACE() 550 DEFINE_INLINE_VIRTUAL_TRACE()
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 CSSParserValue* value = tokens->valueAt(index); 637 CSSParserValue* value = tokens->valueAt(index);
628 if (value->unit != CSSParserValue::Operator) 638 if (value->unit != CSSParserValue::Operator)
629 return 0; 639 return 0;
630 640
631 return value->iValue; 641 return value->iValue;
632 } 642 }
633 643
634 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result) 644 bool parseValue(CSSParserValueList* tokens, unsigned* index, Value* result)
635 { 645 {
636 CSSParserValue* parserValue = tokens->valueAt(*index); 646 CSSParserValue* parserValue = tokens->valueAt(*index);
637 if (parserValue->unit >= CSSParserValue::Operator) 647
638 return false; 648 if (parserValue->unit >= CSSParserValue::Operator) {
649 // We still have to check for variables, which are parser values
650 if (!RuntimeEnabledFeatures::cssVariablesEnabled() || !CSSPropertyPa rser::isVariableReference(parserValue))
651 return false;
652
653 result->value = CSSCalcPrimitiveValue::create(
654 CSSPrimitiveValue::create(parserValue->function->args->valueAt(0 )->string, CSSPrimitiveValue::CSS_VARIABLE_REFERENCE), parserValue->isInt);
655 ++*index;
656
657 return true;
658 }
639 659
640 CSSPrimitiveValue::UnitType type = static_cast<CSSPrimitiveValue::UnitTy pe>(parserValue->unit); 660 CSSPrimitiveValue::UnitType type = static_cast<CSSPrimitiveValue::UnitTy pe>(parserValue->unit);
661
641 if (unitCategory(type) == CalcOther) 662 if (unitCategory(type) == CalcOther)
642 return false; 663 return false;
643 664
644 result->value = CSSCalcPrimitiveValue::create( 665 result->value = CSSCalcPrimitiveValue::create(
645 CSSPrimitiveValue::create(parserValue->fValue, type), parserValue->i sInt); 666 CSSPrimitiveValue::create(parserValue->fValue, type), parserValue->i sInt);
646 667
647 ++*index; 668 ++*index;
648 return true; 669 return true;
649 } 670 }
650 671
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 return adoptRefWillBeNoop(new CSSCalcValue(expression, range)); 779 return adoptRefWillBeNoop(new CSSCalcValue(expression, range));
759 } 780 }
760 781
761 DEFINE_TRACE_AFTER_DISPATCH(CSSCalcValue) 782 DEFINE_TRACE_AFTER_DISPATCH(CSSCalcValue)
762 { 783 {
763 visitor->trace(m_expression); 784 visitor->trace(m_expression);
764 CSSValue::traceAfterDispatch(visitor); 785 CSSValue::traceAfterDispatch(visitor);
765 } 786 }
766 787
767 } // namespace blink 788 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698