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

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

Issue 345903005: calc expressions should support time, angle and frequency values. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
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:
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 25 matching lines...) Expand all
275 private: 287 private:
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[CalcAngle][CalcAngle] = {
alancutter (OOO until 2018) 2014/07/02 05:56:10 It's probably better to use CalcPercentLength + 1
286 // CalcNumber CalcLength CalcPercent CalcPercentNumber CalcPercentLength 298 // CalcNumber CalcLength CalcPercent CalcPercentNumber CalcPercentLength
287 /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther }, 299 /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther },
288 /* CalcLength */ { CalcOther, CalcLength, CalcPercentLengt h, CalcOther, CalcPercentLength }, 300 /* CalcLength */ { CalcOther, CalcLength, CalcPercentLengt h, CalcOther, CalcPercentLength },
289 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent, CalcPercentNumber, CalcPercentLength }, 301 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent, CalcPercentNumber, CalcPercentLength },
290 /* CalcPercentNumber */ { CalcPercentNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther }, 302 /* CalcPercentNumber */ { CalcPercentNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther },
291 /* CalcPercentLength */ { CalcOther, CalcPercentLength, CalcPercentLengt h, CalcOther, CalcPercentLength }, 303 /* CalcPercentLength */ { CalcOther, CalcPercentLength, CalcPercentLengt h, CalcOther, CalcPercentLength },
292 }; 304 };
293 305
294 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op) 306 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op)
295 { 307 {
296 CalculationCategory leftCategory = leftSide.category(); 308 CalculationCategory leftCategory = leftSide.category();
297 CalculationCategory rightCategory = rightSide.category(); 309 CalculationCategory rightCategory = rightSide.category();
298 310
299 if (leftCategory == CalcOther || rightCategory == CalcOther) 311 if (leftCategory == CalcOther || rightCategory == CalcOther)
300 return CalcOther; 312 return CalcOther;
301 313
302 switch (op) { 314 switch (op) {
303 case CalcAdd: 315 case CalcAdd:
304 case CalcSubtract: 316 case CalcSubtract:
305 return addSubtractResult[leftCategory][rightCategory]; 317 if (leftCategory < CalcAngle || rightCategory < CalcAngle)
alancutter (OOO until 2018) 2014/07/02 05:56:10 <= CalcPercentLength
318 return addSubtractResult[leftCategory][rightCategory];
319 if (leftCategory == rightCategory)
320 return leftCategory;
321 return CalcOther;
306 case CalcMultiply: 322 case CalcMultiply:
307 if (leftCategory != CalcNumber && rightCategory != CalcNumber) 323 if (leftCategory != CalcNumber && rightCategory != CalcNumber)
308 return CalcOther; 324 return CalcOther;
309 return leftCategory == CalcNumber ? rightCategory : leftCategory; 325 return leftCategory == CalcNumber ? rightCategory : leftCategory;
310 case CalcDivide: 326 case CalcDivide:
311 if (rightCategory != CalcNumber || rightSide.isZero()) 327 if (rightCategory != CalcNumber || rightSide.isZero())
312 return CalcOther; 328 return CalcOther;
313 return leftCategory; 329 return leftCategory;
314 } 330 }
315 331
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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);
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698