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

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

Issue 2097383002: Added support of calc() for SVGLength (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 case CSSPrimitiveValue::UnitType::DotsPerPixel: 116 case CSSPrimitiveValue::UnitType::DotsPerPixel:
117 case CSSPrimitiveValue::UnitType::DotsPerInch: 117 case CSSPrimitiveValue::UnitType::DotsPerInch:
118 case CSSPrimitiveValue::UnitType::DotsPerCentimeter: 118 case CSSPrimitiveValue::UnitType::DotsPerCentimeter:
119 case CSSPrimitiveValue::UnitType::Fraction: 119 case CSSPrimitiveValue::UnitType::Fraction:
120 case CSSPrimitiveValue::UnitType::Integer: 120 case CSSPrimitiveValue::UnitType::Integer:
121 return true; 121 return true;
122 case CSSPrimitiveValue::UnitType::Unknown: 122 case CSSPrimitiveValue::UnitType::Unknown:
123 case CSSPrimitiveValue::UnitType::Calc: 123 case CSSPrimitiveValue::UnitType::Calc:
124 case CSSPrimitiveValue::UnitType::CalcPercentageWithNumber: 124 case CSSPrimitiveValue::UnitType::CalcPercentageWithNumber:
125 case CSSPrimitiveValue::UnitType::CalcPercentageWithLength: 125 case CSSPrimitiveValue::UnitType::CalcPercentageWithLength:
126 case CSSPrimitiveValue::UnitType::CalcLengthWithNumber:
127 case CSSPrimitiveValue::UnitType::CalcPercentageWithLengthAndNumber:
126 case CSSPrimitiveValue::UnitType::ValueID: 128 case CSSPrimitiveValue::UnitType::ValueID:
127 case CSSPrimitiveValue::UnitType::QuirkyEms: 129 case CSSPrimitiveValue::UnitType::QuirkyEms:
128 return false; 130 return false;
129 }; 131 };
130 ASSERT_NOT_REACHED(); 132 ASSERT_NOT_REACHED();
131 return false; 133 return false;
132 } 134 }
133 135
134 static String buildCSSText(const String& expression) 136 static String buildCSSText(const String& expression)
135 { 137 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 void accumulatePixelsAndPercent(const CSSToLengthConversionData& conversionD ata, PixelsAndPercent& value, float multiplier) const override 199 void accumulatePixelsAndPercent(const CSSToLengthConversionData& conversionD ata, PixelsAndPercent& value, float multiplier) const override
198 { 200 {
199 switch (m_category) { 201 switch (m_category) {
200 case CalcLength: 202 case CalcLength:
201 value.pixels += m_value->computeLength<float>(conversionData) * mult iplier; 203 value.pixels += m_value->computeLength<float>(conversionData) * mult iplier;
202 break; 204 break;
203 case CalcPercent: 205 case CalcPercent:
204 ASSERT(m_value->isPercentage()); 206 ASSERT(m_value->isPercentage());
205 value.percent += m_value->getDoubleValue() * multiplier; 207 value.percent += m_value->getDoubleValue() * multiplier;
206 break; 208 break;
209 case CalcNumber:
210 // TODO(alancutter): Stop treating numbers like pixels unconditional ly in calcs to be able to accomodate border-image-width
211 // https://drafts.csswg.org/css-backgrounds-3/#the-border-image-widt h
212 value.pixels += m_value->getDoubleValue() * conversionData.zoom() * multiplier;
213 break;
207 default: 214 default:
208 ASSERT_NOT_REACHED(); 215 ASSERT_NOT_REACHED();
209 } 216 }
210 } 217 }
211 218
212 double doubleValue() const override 219 double doubleValue() const override
213 { 220 {
214 if (hasDoubleValue(typeWithCalcResolved())) 221 if (hasDoubleValue(typeWithCalcResolved()))
215 return m_value->getDoubleValue(); 222 return m_value->getDoubleValue();
216 ASSERT_NOT_REACHED(); 223 ASSERT_NOT_REACHED();
217 return 0; 224 return 0;
218 } 225 }
219 226
220 double computeLengthPx(const CSSToLengthConversionData& conversionData) cons t override 227 double computeLengthPx(const CSSToLengthConversionData& conversionData) cons t override
221 { 228 {
222 switch (m_category) { 229 switch (m_category) {
223 case CalcLength: 230 case CalcLength:
224 return m_value->computeLength<double>(conversionData); 231 return m_value->computeLength<double>(conversionData);
225 case CalcNumber: 232 case CalcNumber:
226 case CalcPercent: 233 case CalcPercent:
227 return m_value->getDoubleValue(); 234 return m_value->getDoubleValue();
228 case CalcAngle: 235 case CalcAngle:
229 case CalcFrequency: 236 case CalcFrequency:
230 case CalcPercentLength: 237 case CalcPercentLength:
231 case CalcPercentNumber: 238 case CalcPercentNumber:
232 case CalcTime: 239 case CalcTime:
240 case CalcLengthNumber:
241 case CalcPercentLengthNumber:
233 case CalcOther: 242 case CalcOther:
234 ASSERT_NOT_REACHED(); 243 ASSERT_NOT_REACHED();
235 break; 244 break;
236 } 245 }
237 ASSERT_NOT_REACHED(); 246 ASSERT_NOT_REACHED();
238 return 0; 247 return 0;
239 } 248 }
240 249
241 void accumulateLengthArray(CSSLengthArray& lengthArray, double multiplier) c onst override 250 void accumulateLengthArray(CSSLengthArray& lengthArray, double multiplier) c onst override
242 { 251 {
(...skipping 26 matching lines...) Expand all
269 CSSCalcPrimitiveValue(CSSPrimitiveValue* value, bool isInteger) 278 CSSCalcPrimitiveValue(CSSPrimitiveValue* value, bool isInteger)
270 : CSSCalcExpressionNode(unitCategory(value->typeWithCalcResolved()), isI nteger) 279 : CSSCalcExpressionNode(unitCategory(value->typeWithCalcResolved()), isI nteger)
271 , m_value(value) 280 , m_value(value)
272 { 281 {
273 } 282 }
274 283
275 Member<CSSPrimitiveValue> m_value; 284 Member<CSSPrimitiveValue> m_value;
276 }; 285 };
277 286
278 static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = { 287 static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = {
279 // CalcNumber CalcLength CalcPercent CalcPercentNumber CalcPercentLength CalcAngle CalcTime CalcFrequency 288 // CalcNumber CalcLength CalcPercent CalcPercentNumber CalcPercentLength Cal cAngle CalcTime CalcFrequency CalcLengthNumber CalcPercentLengthNumb er
280 /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, 289 /* CalcNumber */ { CalcNumber, CalcLengthNumber, CalcPercentNumber, CalcPercentNumber, CalcOther, Cal cOther, CalcOther, CalcOther, CalcLengthNumber, CalcPercentLengthNumb er },
281 /* CalcLength */ { CalcOther, CalcLength, CalcPercentLengt h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, 290 /* CalcLength */ { CalcLengthNumber, CalcLength, CalcPercentLength, CalcOther, CalcPercentLength, Cal cOther, CalcOther, CalcOther, CalcLengthNumber, CalcPercentLengthNumb er },
282 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent, CalcPercentNumber, CalcPercentLength, CalcOther, CalcOther, CalcOther }, 291 /* CalcPercent */ { CalcPercentNumber, CalcPercentLength, CalcPercent, CalcPercentNumber, CalcPercentLength, Cal cOther, CalcOther, CalcOther, CalcPercentLengthNumber, CalcPercentLengthNumb er },
283 /* CalcPercentNumber */ { CalcPercentNumber, CalcOther, CalcPercentNumbe r, CalcPercentNumber, CalcOther, CalcOther, CalcOther, CalcOther }, 292 /* CalcPercentNumber */ { CalcPercentNumber, CalcPercentLengthNumber , CalcPercentNumber, CalcPercentNumber, CalcPercentLengthNumber, Cal cOther, CalcOther, CalcOther, CalcOther, CalcPercentLengthNumb er },
284 /* CalcPercentLength */ { CalcOther, CalcPercentLength, CalcPercentLengt h, CalcOther, CalcPercentLength, CalcOther, CalcOther, CalcOther }, 293 /* CalcPercentLength */ { CalcPercentLengthNumber, CalcPercentLength, CalcPercentLength, CalcPercentLengthNumber, CalcPercentLength, Cal cOther, CalcOther, CalcOther, CalcOther, CalcPercentLengthNumb er },
285 /* CalcAngle */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcAngle, CalcOther, CalcOther }, 294 /* CalcAngle */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, Cal cAngle, CalcOther, CalcOther, CalcOther, CalcOther },
286 /* CalcTime */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcTime, CalcOther }, 295 /* CalcTime */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, Cal cOther, CalcTime, CalcOther, CalcOther, CalcOther },
287 /* CalcFrequency */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, CalcFrequency } 296 /* CalcFrequency */ { CalcOther, CalcOther, CalcOther, CalcOther, CalcOther, Cal cOther, CalcOther, CalcFrequency, CalcOther, CalcOther },
297 /* CalcLengthNumber */ { CalcLengthNumber, CalcLengthNumber, CalcPercentLengthNumber, CalcPercentLengthNumber, CalcPercentLengthNumber, Cal cOther, CalcOther, CalcOther, CalcLengthNumber, CalcPercentLengthNumb er },
298 /* CalcPercentLengthNumber */ { CalcPercentLengthNumber, CalcPercentLengthNumber , CalcPercentLengthNumber, CalcPercentLengthNumber, CalcPercentLengthNumber, Cal cOther, CalcOther, CalcOther, CalcPercentLengthNumber, CalcPercentLengthNumb er }
288 }; 299 };
289 300
290 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op) 301 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi de, const CSSCalcExpressionNode& rightSide, CalcOperator op)
291 { 302 {
292 CalculationCategory leftCategory = leftSide.category(); 303 CalculationCategory leftCategory = leftSide.category();
293 CalculationCategory rightCategory = rightSide.category(); 304 CalculationCategory rightCategory = rightSide.category();
294 305
295 if (leftCategory == CalcOther || rightCategory == CalcOther) 306 if (leftCategory == CalcOther || rightCategory == CalcOther)
296 return CalcOther; 307 return CalcOther;
297 308
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 return CSSPrimitiveValue::UnitType::Unknown; 522 return CSSPrimitiveValue::UnitType::Unknown;
512 } 523 }
513 case CalcAngle: 524 case CalcAngle:
514 return CSSPrimitiveValue::UnitType::Degrees; 525 return CSSPrimitiveValue::UnitType::Degrees;
515 case CalcTime: 526 case CalcTime:
516 return CSSPrimitiveValue::UnitType::Milliseconds; 527 return CSSPrimitiveValue::UnitType::Milliseconds;
517 case CalcFrequency: 528 case CalcFrequency:
518 return CSSPrimitiveValue::UnitType::Hertz; 529 return CSSPrimitiveValue::UnitType::Hertz;
519 case CalcPercentLength: 530 case CalcPercentLength:
520 case CalcPercentNumber: 531 case CalcPercentNumber:
532 case CalcLengthNumber:
533 case CalcPercentLengthNumber:
521 case CalcOther: 534 case CalcOther:
522 return CSSPrimitiveValue::UnitType::Unknown; 535 return CSSPrimitiveValue::UnitType::Unknown;
523 } 536 }
524 ASSERT_NOT_REACHED(); 537 ASSERT_NOT_REACHED();
525 return CSSPrimitiveValue::UnitType::Unknown; 538 return CSSPrimitiveValue::UnitType::Unknown;
526 } 539 }
527 540
528 DEFINE_INLINE_VIRTUAL_TRACE() 541 DEFINE_INLINE_VIRTUAL_TRACE()
529 { 542 {
530 visitor->trace(m_leftSide); 543 visitor->trace(m_leftSide);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 746
734 return expression ? new CSSCalcValue(expression, range) : nullptr; 747 return expression ? new CSSCalcValue(expression, range) : nullptr;
735 } 748 }
736 749
737 CSSCalcValue* CSSCalcValue::create(CSSCalcExpressionNode* expression, ValueRange range) 750 CSSCalcValue* CSSCalcValue::create(CSSCalcExpressionNode* expression, ValueRange range)
738 { 751 {
739 return new CSSCalcValue(expression, range); 752 return new CSSCalcValue(expression, range);
740 } 753 }
741 754
742 } // namespace blink 755 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSCalculationValue.h ('k') | third_party/WebKit/Source/core/css/CSSPrimitiveValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698