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

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

Issue 2158723002: Make CSSValuePair store const CSSValues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_make_cssparsersinglevalue_return_const
Patch Set: Review feedback 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) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2015 Google Inc. All rights reserved. 3 * Copyright (C) 2015 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } else { 474 } else {
475 // Normalization failed because the stop set is coincident. 475 // Normalization failed because the stop set is coincident.
476 } 476 }
477 } else { 477 } else {
478 // No normalization required, just add the current stops. 478 // No normalization required, just add the current stops.
479 for (const auto& stop : stops) 479 for (const auto& stop : stops)
480 gradient->addColorStop(stop.offset, stop.color); 480 gradient->addColorStop(stop.offset, stop.color);
481 } 481 }
482 } 482 }
483 483
484 static float positionFromValue(CSSValue* value, const CSSToLengthConversionData& conversionData, const IntSize& size, bool isHorizontal) 484 static float positionFromValue(const CSSValue* value, const CSSToLengthConversio nData& conversionData, const IntSize& size, bool isHorizontal)
485 { 485 {
486 int origin = 0; 486 int origin = 0;
487 int sign = 1; 487 int sign = 1;
488 int edgeDistance = isHorizontal ? size.width() : size.height(); 488 int edgeDistance = isHorizontal ? size.width() : size.height();
489 489
490 // In this case the center of the gradient is given relative to an edge in t he form of: 490 // In this case the center of the gradient is given relative to an edge in t he form of:
491 // [ top | bottom | right | left ] [ <percentage> | <length> ]. 491 // [ top | bottom | right | left ] [ <percentage> | <length> ].
492 if (value->isValuePair()) { 492 if (value->isValuePair()) {
493 CSSValuePair& pair = toCSSValuePair(*value); 493 const CSSValuePair& pair = toCSSValuePair(*value);
494 CSSValueID originID = toCSSPrimitiveValue(pair.first()).getValueID(); 494 CSSValueID originID = toCSSPrimitiveValue(pair.first()).getValueID();
495 value = &pair.second(); 495 value = &pair.second();
496 496
497 if (originID == CSSValueRight || originID == CSSValueBottom) { 497 if (originID == CSSValueRight || originID == CSSValueBottom) {
498 // For right/bottom, the offset is relative to the far edge. 498 // For right/bottom, the offset is relative to the far edge.
499 origin = edgeDistance; 499 origin = edgeDistance;
500 sign = -1; 500 sign = -1;
501 } 501 }
502 } 502 }
503 503
504 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 504 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
505 505
506 if (primitiveValue->isNumber()) 506 if (primitiveValue->isNumber())
507 return origin + sign * primitiveValue->getFloatValue() * conversionData. zoom(); 507 return origin + sign * primitiveValue->getFloatValue() * conversionData. zoom();
508 508
509 if (primitiveValue->isPercentage()) 509 if (primitiveValue->isPercentage())
510 return origin + sign * primitiveValue->getFloatValue() / 100.f * edgeDis tance; 510 return origin + sign * primitiveValue->getFloatValue() / 100.f * edgeDis tance;
511 511
512 if (primitiveValue->isCalculatedPercentageWithLength()) 512 if (primitiveValue->isCalculatedPercentageWithLength())
513 return origin + sign * primitiveValue->cssCalcValue()->toCalcValue(conve rsionData)->evaluate(edgeDistance); 513 return origin + sign * primitiveValue->cssCalcValue()->toCalcValue(conve rsionData)->evaluate(edgeDistance);
514 514
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 visitor->trace(m_firstRadius); 1222 visitor->trace(m_firstRadius);
1223 visitor->trace(m_secondRadius); 1223 visitor->trace(m_secondRadius);
1224 visitor->trace(m_shape); 1224 visitor->trace(m_shape);
1225 visitor->trace(m_sizingBehavior); 1225 visitor->trace(m_sizingBehavior);
1226 visitor->trace(m_endHorizontalSize); 1226 visitor->trace(m_endHorizontalSize);
1227 visitor->trace(m_endVerticalSize); 1227 visitor->trace(m_endVerticalSize);
1228 CSSGradientValue::traceAfterDispatch(visitor); 1228 CSSGradientValue::traceAfterDispatch(visitor);
1229 } 1229 }
1230 1230
1231 } // namespace blink 1231 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSBasicShapeValues.cpp ('k') | third_party/WebKit/Source/core/css/CSSValuePair.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698