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

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

Issue 2755493004: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in core/css/ (Closed)
Patch Set: Worked on Review Comments done Created 3 years, 9 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return UnitType::Milliseconds; 162 return UnitType::Milliseconds;
163 case CalcOther: 163 case CalcOther:
164 return UnitType::Unknown; 164 return UnitType::Unknown;
165 } 165 }
166 return UnitType::Unknown; 166 return UnitType::Unknown;
167 } 167 }
168 168
169 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type) 169 CSSPrimitiveValue::CSSPrimitiveValue(double num, UnitType type)
170 : CSSValue(PrimitiveClass) { 170 : CSSValue(PrimitiveClass) {
171 init(type); 171 init(type);
172 ASSERT(std::isfinite(num)); 172 DCHECK(std::isfinite(num));
173 m_value.num = num; 173 m_value.num = num;
174 } 174 }
175 175
176 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom) 176 CSSPrimitiveValue::CSSPrimitiveValue(const Length& length, float zoom)
177 : CSSValue(PrimitiveClass) { 177 : CSSValue(PrimitiveClass) {
178 switch (length.type()) { 178 switch (length.type()) {
179 case Percent: 179 case Percent:
180 init(UnitType::Percentage); 180 init(UnitType::Percentage);
181 ASSERT(std::isfinite(length.percent())); 181 DCHECK(std::isfinite(length.percent()));
182 m_value.num = length.percent(); 182 m_value.num = length.percent();
183 break; 183 break;
184 case Fixed: 184 case Fixed:
185 init(UnitType::Pixels); 185 init(UnitType::Pixels);
186 m_value.num = length.value() / zoom; 186 m_value.num = length.value() / zoom;
187 break; 187 break;
188 case Calculated: { 188 case Calculated: {
189 const CalculationValue& calc = length.getCalculationValue(); 189 const CalculationValue& calc = length.getCalculationValue();
190 if (calc.pixels() && calc.percent()) { 190 if (calc.pixels() && calc.percent()) {
191 init(CSSCalcValue::create(CSSCalcValue::createExpressionNode( 191 init(CSSCalcValue::create(CSSCalcValue::createExpressionNode(
(...skipping 14 matching lines...) Expand all
206 } 206 }
207 case Auto: 207 case Auto:
208 case MinContent: 208 case MinContent:
209 case MaxContent: 209 case MaxContent:
210 case FillAvailable: 210 case FillAvailable:
211 case FitContent: 211 case FitContent:
212 case ExtendToZoom: 212 case ExtendToZoom:
213 case DeviceWidth: 213 case DeviceWidth:
214 case DeviceHeight: 214 case DeviceHeight:
215 case MaxSizeNone: 215 case MaxSizeNone:
216 ASSERT_NOT_REACHED(); 216 NOTREACHED();
217 break; 217 break;
218 } 218 }
219 } 219 }
220 220
221 void CSSPrimitiveValue::init(UnitType type) { 221 void CSSPrimitiveValue::init(UnitType type) {
222 m_primitiveUnitType = static_cast<unsigned>(type); 222 m_primitiveUnitType = static_cast<unsigned>(type);
223 } 223 }
224 224
225 void CSSPrimitiveValue::init(CSSCalcValue* c) { 225 void CSSPrimitiveValue::init(CSSCalcValue* c) {
226 init(UnitType::Calc); 226 init(UnitType::Calc);
227 m_hasCachedCSSText = false; 227 m_hasCachedCSSText = false;
228 m_value.calc = c; 228 m_value.calc = c;
229 } 229 }
230 230
231 CSSPrimitiveValue::~CSSPrimitiveValue() {} 231 CSSPrimitiveValue::~CSSPrimitiveValue() {}
232 232
233 double CSSPrimitiveValue::computeSeconds() const { 233 double CSSPrimitiveValue::computeSeconds() const {
234 ASSERT(isTime() || 234 DCHECK(isTime() ||
235 (isCalculated() && cssCalcValue()->category() == CalcTime)); 235 (isCalculated() && cssCalcValue()->category() == CalcTime));
236 UnitType currentType = 236 UnitType currentType =
237 isCalculated() ? cssCalcValue()->expressionNode()->typeWithCalcResolved() 237 isCalculated() ? cssCalcValue()->expressionNode()->typeWithCalcResolved()
238 : type(); 238 : type();
239 if (currentType == UnitType::Seconds) 239 if (currentType == UnitType::Seconds)
240 return getDoubleValue(); 240 return getDoubleValue();
241 if (currentType == UnitType::Milliseconds) 241 if (currentType == UnitType::Milliseconds)
242 return getDoubleValue() / 1000; 242 return getDoubleValue() / 1000;
243 ASSERT_NOT_REACHED(); 243 NOTREACHED();
244 return 0; 244 return 0;
245 } 245 }
246 246
247 double CSSPrimitiveValue::computeDegrees() const { 247 double CSSPrimitiveValue::computeDegrees() const {
248 ASSERT(isAngle() || 248 DCHECK(isAngle() ||
249 (isCalculated() && cssCalcValue()->category() == CalcAngle)); 249 (isCalculated() && cssCalcValue()->category() == CalcAngle));
250 UnitType currentType = 250 UnitType currentType =
251 isCalculated() ? cssCalcValue()->expressionNode()->typeWithCalcResolved() 251 isCalculated() ? cssCalcValue()->expressionNode()->typeWithCalcResolved()
252 : type(); 252 : type();
253 switch (currentType) { 253 switch (currentType) {
254 case UnitType::Degrees: 254 case UnitType::Degrees:
255 return getDoubleValue(); 255 return getDoubleValue();
256 case UnitType::Radians: 256 case UnitType::Radians:
257 return rad2deg(getDoubleValue()); 257 return rad2deg(getDoubleValue());
258 case UnitType::Gradians: 258 case UnitType::Gradians:
259 return grad2deg(getDoubleValue()); 259 return grad2deg(getDoubleValue());
260 case UnitType::Turns: 260 case UnitType::Turns:
261 return turn2deg(getDoubleValue()); 261 return turn2deg(getDoubleValue());
262 default: 262 default:
263 ASSERT_NOT_REACHED(); 263 NOTREACHED();
264 return 0; 264 return 0;
265 } 265 }
266 } 266 }
267 267
268 template <> 268 template <>
269 int CSSPrimitiveValue::computeLength( 269 int CSSPrimitiveValue::computeLength(
270 const CSSToLengthConversionData& conversionData) const { 270 const CSSToLengthConversionData& conversionData) const {
271 return roundForImpreciseConversion<int>(computeLengthDouble(conversionData)); 271 return roundForImpreciseConversion<int>(computeLengthDouble(conversionData));
272 } 272 }
273 273
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 320
321 double CSSPrimitiveValue::computeLengthDouble( 321 double CSSPrimitiveValue::computeLengthDouble(
322 const CSSToLengthConversionData& conversionData) const { 322 const CSSToLengthConversionData& conversionData) const {
323 if (type() == UnitType::Calc) 323 if (type() == UnitType::Calc)
324 return m_value.calc->computeLengthPx(conversionData); 324 return m_value.calc->computeLengthPx(conversionData);
325 return conversionData.zoomedComputedPixels(getDoubleValue(), type()); 325 return conversionData.zoomedComputedPixels(getDoubleValue(), type());
326 } 326 }
327 327
328 void CSSPrimitiveValue::accumulateLengthArray(CSSLengthArray& lengthArray, 328 void CSSPrimitiveValue::accumulateLengthArray(CSSLengthArray& lengthArray,
329 double multiplier) const { 329 double multiplier) const {
330 ASSERT(lengthArray.values.size() == LengthUnitTypeCount); 330 DCHECK(lengthArray.values.size() == LengthUnitTypeCount);
tkent 2017/03/28 14:44:55 Use DCHECK_EQ
nikhil.sahni 2017/03/30 12:17:57 Done.
331 331
332 if (type() == UnitType::Calc) { 332 if (type() == UnitType::Calc) {
333 cssCalcValue()->accumulateLengthArray(lengthArray, multiplier); 333 cssCalcValue()->accumulateLengthArray(lengthArray, multiplier);
334 return; 334 return;
335 } 335 }
336 336
337 LengthUnitType lengthType; 337 LengthUnitType lengthType;
338 bool conversionSuccess = unitTypeToLengthUnitType(type(), lengthType); 338 bool conversionSuccess = unitTypeToLengthUnitType(type(), lengthType);
339 DCHECK(conversionSuccess); 339 DCHECK(conversionSuccess);
340 lengthArray.values[lengthType] += 340 lengthArray.values[lengthType] +=
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 return factor; 395 return factor;
396 } 396 }
397 397
398 Length CSSPrimitiveValue::convertToLength( 398 Length CSSPrimitiveValue::convertToLength(
399 const CSSToLengthConversionData& conversionData) const { 399 const CSSToLengthConversionData& conversionData) const {
400 if (isLength()) 400 if (isLength())
401 return computeLength<Length>(conversionData); 401 return computeLength<Length>(conversionData);
402 if (isPercentage()) 402 if (isPercentage())
403 return Length(getDoubleValue(), Percent); 403 return Length(getDoubleValue(), Percent);
404 ASSERT(isCalculated()); 404 DCHECK(isCalculated());
405 return Length(cssCalcValue()->toCalcValue(conversionData)); 405 return Length(cssCalcValue()->toCalcValue(conversionData));
406 } 406 }
407 407
408 double CSSPrimitiveValue::getDoubleValue() const { 408 double CSSPrimitiveValue::getDoubleValue() const {
409 return type() != UnitType::Calc ? m_value.num : m_value.calc->doubleValue(); 409 return type() != UnitType::Calc ? m_value.num : m_value.calc->doubleValue();
410 } 410 }
411 411
412 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory( 412 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory(
413 UnitCategory category) { 413 UnitCategory category) {
414 // The canonical unit type is chosen according to the way 414 // The canonical unit type is chosen according to the way
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 return CSSPrimitiveValue::UnitType::ViewportWidth; 498 return CSSPrimitiveValue::UnitType::ViewportWidth;
499 case UnitTypeViewportHeight: 499 case UnitTypeViewportHeight:
500 return CSSPrimitiveValue::UnitType::ViewportHeight; 500 return CSSPrimitiveValue::UnitType::ViewportHeight;
501 case UnitTypeViewportMin: 501 case UnitTypeViewportMin:
502 return CSSPrimitiveValue::UnitType::ViewportMin; 502 return CSSPrimitiveValue::UnitType::ViewportMin;
503 case UnitTypeViewportMax: 503 case UnitTypeViewportMax:
504 return CSSPrimitiveValue::UnitType::ViewportMax; 504 return CSSPrimitiveValue::UnitType::ViewportMax;
505 case LengthUnitTypeCount: 505 case LengthUnitTypeCount:
506 break; 506 break;
507 } 507 }
508 ASSERT_NOT_REACHED(); 508 NOTREACHED();
509 return CSSPrimitiveValue::UnitType::Unknown; 509 return CSSPrimitiveValue::UnitType::Unknown;
510 } 510 }
511 511
512 static String formatNumber(double number, const StringView& suffix) { 512 static String formatNumber(double number, const StringView& suffix) {
513 #if OS(WIN) && _MSC_VER < 1900 513 #if OS(WIN) && _MSC_VER < 1900
514 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT); 514 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT);
515 #endif 515 #endif
516 String result = String::format("%.6g", number); 516 String result = String::format("%.6g", number);
517 #if OS(WIN) && _MSC_VER < 1900 517 #if OS(WIN) && _MSC_VER < 1900
518 _set_output_format(oldFormat); 518 _set_output_format(oldFormat);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 case UnitType::ViewportMax: 583 case UnitType::ViewportMax:
584 return "vmax"; 584 return "vmax";
585 case UnitType::Unknown: 585 case UnitType::Unknown:
586 case UnitType::Calc: 586 case UnitType::Calc:
587 case UnitType::CalcPercentageWithNumber: 587 case UnitType::CalcPercentageWithNumber:
588 case UnitType::CalcPercentageWithLength: 588 case UnitType::CalcPercentageWithLength:
589 case UnitType::CalcLengthWithNumber: 589 case UnitType::CalcLengthWithNumber:
590 case UnitType::CalcPercentageWithLengthAndNumber: 590 case UnitType::CalcPercentageWithLengthAndNumber:
591 break; 591 break;
592 }; 592 };
593 ASSERT_NOT_REACHED(); 593 NOTREACHED();
594 return ""; 594 return "";
595 } 595 }
596 596
597 String CSSPrimitiveValue::customCSSText() const { 597 String CSSPrimitiveValue::customCSSText() const {
598 if (m_hasCachedCSSText) { 598 if (m_hasCachedCSSText) {
599 ASSERT(cssTextCache().contains(this)); 599 DCHECK(cssTextCache().contains(this));
600 return cssTextCache().at(this); 600 return cssTextCache().at(this);
601 } 601 }
602 602
603 String text; 603 String text;
604 switch (type()) { 604 switch (type()) {
605 case UnitType::Unknown: 605 case UnitType::Unknown:
606 // FIXME 606 // FIXME
607 break; 607 break;
608 case UnitType::Integer: 608 case UnitType::Integer:
609 text = String::format("%d", getIntValue()); 609 text = String::format("%d", getIntValue());
(...skipping 30 matching lines...) Expand all
640 case UnitType::ViewportMax: 640 case UnitType::ViewportMax:
641 text = formatNumber(m_value.num, unitTypeToString(type())); 641 text = formatNumber(m_value.num, unitTypeToString(type()));
642 break; 642 break;
643 case UnitType::Calc: 643 case UnitType::Calc:
644 text = m_value.calc->customCSSText(); 644 text = m_value.calc->customCSSText();
645 break; 645 break;
646 case UnitType::CalcPercentageWithNumber: 646 case UnitType::CalcPercentageWithNumber:
647 case UnitType::CalcPercentageWithLength: 647 case UnitType::CalcPercentageWithLength:
648 case UnitType::CalcLengthWithNumber: 648 case UnitType::CalcLengthWithNumber:
649 case UnitType::CalcPercentageWithLengthAndNumber: 649 case UnitType::CalcPercentageWithLengthAndNumber:
650 ASSERT_NOT_REACHED(); 650 NOTREACHED();
651 break; 651 break;
652 } 652 }
653 653
654 ASSERT(!cssTextCache().contains(this)); 654 DCHECK(!cssTextCache().contains(this));
655 cssTextCache().set(this, text); 655 cssTextCache().set(this, text);
656 m_hasCachedCSSText = true; 656 m_hasCachedCSSText = true;
657 return text; 657 return text;
658 } 658 }
659 659
660 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const { 660 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const {
661 if (type() != other.type()) 661 if (type() != other.type())
662 return false; 662 return false;
663 663
664 switch (type()) { 664 switch (type()) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 case UnitType::Calc: 713 case UnitType::Calc:
714 visitor->trace(m_value.calc); 714 visitor->trace(m_value.calc);
715 break; 715 break;
716 default: 716 default:
717 break; 717 break;
718 } 718 }
719 CSSValue::traceAfterDispatch(visitor); 719 CSSValue::traceAfterDispatch(visitor);
720 } 720 }
721 721
722 } // namespace blink 722 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698