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

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: All windows error are Resolved now. Created 3 years, 8 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_EQ(lengthArray.values.size(),
331 static_cast<unsigned>(LengthUnitTypeCount));
331 332
332 if (type() == UnitType::Calc) { 333 if (type() == UnitType::Calc) {
333 cssCalcValue()->accumulateLengthArray(lengthArray, multiplier); 334 cssCalcValue()->accumulateLengthArray(lengthArray, multiplier);
334 return; 335 return;
335 } 336 }
336 337
337 LengthUnitType lengthType; 338 LengthUnitType lengthType;
338 bool conversionSuccess = unitTypeToLengthUnitType(type(), lengthType); 339 bool conversionSuccess = unitTypeToLengthUnitType(type(), lengthType);
339 DCHECK(conversionSuccess); 340 DCHECK(conversionSuccess);
340 lengthArray.values[lengthType] += 341 lengthArray.values[lengthType] +=
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 395
395 return factor; 396 return factor;
396 } 397 }
397 398
398 Length CSSPrimitiveValue::convertToLength( 399 Length CSSPrimitiveValue::convertToLength(
399 const CSSToLengthConversionData& conversionData) const { 400 const CSSToLengthConversionData& conversionData) const {
400 if (isLength()) 401 if (isLength())
401 return computeLength<Length>(conversionData); 402 return computeLength<Length>(conversionData);
402 if (isPercentage()) 403 if (isPercentage())
403 return Length(getDoubleValue(), Percent); 404 return Length(getDoubleValue(), Percent);
404 ASSERT(isCalculated()); 405 DCHECK(isCalculated());
405 return Length(cssCalcValue()->toCalcValue(conversionData)); 406 return Length(cssCalcValue()->toCalcValue(conversionData));
406 } 407 }
407 408
408 double CSSPrimitiveValue::getDoubleValue() const { 409 double CSSPrimitiveValue::getDoubleValue() const {
409 return type() != UnitType::Calc ? m_value.num : m_value.calc->doubleValue(); 410 return type() != UnitType::Calc ? m_value.num : m_value.calc->doubleValue();
410 } 411 }
411 412
412 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory( 413 CSSPrimitiveValue::UnitType CSSPrimitiveValue::canonicalUnitTypeForCategory(
413 UnitCategory category) { 414 UnitCategory category) {
414 // The canonical unit type is chosen according to the way 415 // 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; 499 return CSSPrimitiveValue::UnitType::ViewportWidth;
499 case UnitTypeViewportHeight: 500 case UnitTypeViewportHeight:
500 return CSSPrimitiveValue::UnitType::ViewportHeight; 501 return CSSPrimitiveValue::UnitType::ViewportHeight;
501 case UnitTypeViewportMin: 502 case UnitTypeViewportMin:
502 return CSSPrimitiveValue::UnitType::ViewportMin; 503 return CSSPrimitiveValue::UnitType::ViewportMin;
503 case UnitTypeViewportMax: 504 case UnitTypeViewportMax:
504 return CSSPrimitiveValue::UnitType::ViewportMax; 505 return CSSPrimitiveValue::UnitType::ViewportMax;
505 case LengthUnitTypeCount: 506 case LengthUnitTypeCount:
506 break; 507 break;
507 } 508 }
508 ASSERT_NOT_REACHED(); 509 NOTREACHED();
509 return CSSPrimitiveValue::UnitType::Unknown; 510 return CSSPrimitiveValue::UnitType::Unknown;
510 } 511 }
511 512
512 static String formatNumber(double number, const StringView& suffix) { 513 static String formatNumber(double number, const StringView& suffix) {
513 #if OS(WIN) && _MSC_VER < 1900 514 #if OS(WIN) && _MSC_VER < 1900
514 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT); 515 unsigned oldFormat = _set_output_format(_TWO_DIGIT_EXPONENT);
515 #endif 516 #endif
516 String result = String::format("%.6g", number); 517 String result = String::format("%.6g", number);
517 #if OS(WIN) && _MSC_VER < 1900 518 #if OS(WIN) && _MSC_VER < 1900
518 _set_output_format(oldFormat); 519 _set_output_format(oldFormat);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 case UnitType::ViewportMax: 584 case UnitType::ViewportMax:
584 return "vmax"; 585 return "vmax";
585 case UnitType::Unknown: 586 case UnitType::Unknown:
586 case UnitType::Calc: 587 case UnitType::Calc:
587 case UnitType::CalcPercentageWithNumber: 588 case UnitType::CalcPercentageWithNumber:
588 case UnitType::CalcPercentageWithLength: 589 case UnitType::CalcPercentageWithLength:
589 case UnitType::CalcLengthWithNumber: 590 case UnitType::CalcLengthWithNumber:
590 case UnitType::CalcPercentageWithLengthAndNumber: 591 case UnitType::CalcPercentageWithLengthAndNumber:
591 break; 592 break;
592 }; 593 };
593 ASSERT_NOT_REACHED(); 594 NOTREACHED();
594 return ""; 595 return "";
595 } 596 }
596 597
597 String CSSPrimitiveValue::customCSSText() const { 598 String CSSPrimitiveValue::customCSSText() const {
598 if (m_hasCachedCSSText) { 599 if (m_hasCachedCSSText) {
599 ASSERT(cssTextCache().contains(this)); 600 DCHECK(cssTextCache().contains(this));
600 return cssTextCache().at(this); 601 return cssTextCache().at(this);
601 } 602 }
602 603
603 String text; 604 String text;
604 switch (type()) { 605 switch (type()) {
605 case UnitType::Unknown: 606 case UnitType::Unknown:
606 // FIXME 607 // FIXME
607 break; 608 break;
608 case UnitType::Integer: 609 case UnitType::Integer:
609 text = String::format("%d", getIntValue()); 610 text = String::format("%d", getIntValue());
(...skipping 30 matching lines...) Expand all
640 case UnitType::ViewportMax: 641 case UnitType::ViewportMax:
641 text = formatNumber(m_value.num, unitTypeToString(type())); 642 text = formatNumber(m_value.num, unitTypeToString(type()));
642 break; 643 break;
643 case UnitType::Calc: 644 case UnitType::Calc:
644 text = m_value.calc->customCSSText(); 645 text = m_value.calc->customCSSText();
645 break; 646 break;
646 case UnitType::CalcPercentageWithNumber: 647 case UnitType::CalcPercentageWithNumber:
647 case UnitType::CalcPercentageWithLength: 648 case UnitType::CalcPercentageWithLength:
648 case UnitType::CalcLengthWithNumber: 649 case UnitType::CalcLengthWithNumber:
649 case UnitType::CalcPercentageWithLengthAndNumber: 650 case UnitType::CalcPercentageWithLengthAndNumber:
650 ASSERT_NOT_REACHED(); 651 NOTREACHED();
651 break; 652 break;
652 } 653 }
653 654
654 ASSERT(!cssTextCache().contains(this)); 655 DCHECK(!cssTextCache().contains(this));
655 cssTextCache().set(this, text); 656 cssTextCache().set(this, text);
656 m_hasCachedCSSText = true; 657 m_hasCachedCSSText = true;
657 return text; 658 return text;
658 } 659 }
659 660
660 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const { 661 bool CSSPrimitiveValue::equals(const CSSPrimitiveValue& other) const {
661 if (type() != other.type()) 662 if (type() != other.type())
662 return false; 663 return false;
663 664
664 switch (type()) { 665 switch (type()) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 case UnitType::Calc: 714 case UnitType::Calc:
714 visitor->trace(m_value.calc); 715 visitor->trace(m_value.calc);
715 break; 716 break;
716 default: 717 default:
717 break; 718 break;
718 } 719 }
719 CSSValue::traceAfterDispatch(visitor); 720 CSSValue::traceAfterDispatch(visitor);
720 } 721 }
721 722
722 } // namespace blink 723 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSPrimitiveValue.h ('k') | third_party/WebKit/Source/core/css/CSSPrimitiveValueMappings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698