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

Unified Diff: Source/core/css/CSSGradientValue.cpp

Issue 1225553002: CSSValue Immediates: Make CSSPrimitiveValue a container (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@cssvalue_patch_1
Patch Set: Rebase Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/CSSGradientValue.h ('k') | Source/core/css/CSSMatrix.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSGradientValue.cpp
diff --git a/Source/core/css/CSSGradientValue.cpp b/Source/core/css/CSSGradientValue.cpp
index b2e665e64bf337be2fe19970c3c98328b1014f5c..0467195962303cc25e9cf1f7a4ddb6c1bf47567e 100644
--- a/Source/core/css/CSSGradientValue.cpp
+++ b/Source/core/css/CSSGradientValue.cpp
@@ -87,8 +87,8 @@ PassRefPtr<Image> CSSGradientValue::image(LayoutObject* layoutObject, const IntS
// Should only ever be called for deprecated gradients.
static inline bool compareStops(const CSSGradientColorStop& a, const CSSGradientColorStop& b)
{
- double aVal = a.m_position->getDoubleValue();
- double bVal = b.m_position->getDoubleValue();
+ double aVal = toCSSPrimitiveValue(*a.m_position).getDoubleValue();
+ double bVal = toCSSPrimitiveValue(*b.m_position).getDoubleValue();
return aVal < bVal;
}
@@ -192,7 +192,7 @@ static void replaceColorHintsWithColorStops(Vector<GradientStop>& stops, const W
}
}
-static Color resolveStopColor(CSSPrimitiveValue& stopColor, const LayoutObject& object)
+static Color resolveStopColor(CSSPrimitiveValue stopColor, const LayoutObject& object)
{
return object.document().textLinkColors().colorFromPrimitiveValue(stopColor, object.resolveColor(CSSPropertyColor));
}
@@ -209,12 +209,12 @@ void CSSGradientValue::addDeprecatedStops(Gradient* gradient, const LayoutObject
for (const auto& stop : m_stops) {
float offset;
- if (stop.m_position->isPercentage())
- offset = stop.m_position->getFloatValue() / 100;
+ if (toCSSPrimitiveValue(*stop.m_position).isPercentage())
+ offset = toCSSPrimitiveValue(*stop.m_position).getFloatValue() / 100;
else
- offset = stop.m_position->getFloatValue();
+ offset = toCSSPrimitiveValue(*stop.m_position).getFloatValue();
- gradient->addColorStop(offset, resolveStopColor(*stop.m_color.get(), object));
+ gradient->addColorStop(offset, resolveStopColor(toCSSPrimitiveValue(*stop.m_color), object));
}
}
@@ -376,17 +376,18 @@ void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionD
if (stop.isHint())
hasHints = true;
else
- stops[i].color = resolveStopColor(*stop.m_color.get(), object);
+ stops[i].color = resolveStopColor(toCSSPrimitiveValue(*stop.m_color), object);
if (stop.m_position) {
- if (stop.m_position->isPercentage())
- stops[i].offset = stop.m_position->getFloatValue() / 100;
- else if (stop.m_position->isLength() || stop.m_position->isCalculatedPercentageWithLength()) {
+ CSSPrimitiveValue stopPosition = toCSSPrimitiveValue(*stop.m_position);
+ if (stopPosition.isPercentage()) {
+ stops[i].offset = toCSSPrimitiveValue(*stop.m_position).getFloatValue() / 100;
+ } else if (stopPosition.isLength() || stopPosition.isCalculatedPercentageWithLength()) {
float length;
- if (stop.m_position->isLength())
- length = stop.m_position->computeLength<float>(conversionData);
+ if (stopPosition.isLength())
+ length = stopPosition.computeLength<float>(conversionData);
else
- length = stop.m_position->cssCalcValue()->toCalcValue(conversionData)->evaluate(gradientLength);
+ length = stopPosition.cssCalcValue()->toCalcValue(conversionData)->evaluate(gradientLength);
stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0;
} else {
ASSERT_NOT_REACHED();
@@ -480,7 +481,7 @@ void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionD
}
}
-static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const IntSize& size, bool isHorizontal)
+static float positionFromValue(CSSPrimitiveValue value, const CSSToLengthConversionData& conversionData, const IntSize& size, bool isHorizontal)
{
int origin = 0;
int sign = 1;
@@ -488,9 +489,9 @@ static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConver
// In this case the center of the gradient is given relative to an edge in the form of:
// [ top | bottom | right | left ] [ <percentage> | <length> ].
- if (Pair* pair = value->getPairValue()) {
- CSSValueID originID = pair->first()->getValueID();
- value = pair->second();
+ if (Pair* pair = value.getPairValue()) {
+ CSSValueID originID = toCSSPrimitiveValue(*pair->first()).getValueID();
+ value = toCSSPrimitiveValue(*pair->second());
if (originID == CSSValueRight || originID == CSSValueBottom) {
// For right/bottom, the offset is relative to the far edge.
@@ -499,16 +500,16 @@ static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConver
}
}
- if (value->isNumber())
- return origin + sign * value->getFloatValue() * conversionData.zoom();
+ if (value.isNumber())
+ return origin + sign * value.getFloatValue() * conversionData.zoom();
- if (value->isPercentage())
- return origin + sign * value->getFloatValue() / 100.f * edgeDistance;
+ if (value.isPercentage())
+ return origin + sign * value.getFloatValue() / 100.f * edgeDistance;
- if (value->isCalculatedPercentageWithLength())
- return origin + sign * value->cssCalcValue()->toCalcValue(conversionData)->evaluate(edgeDistance);
+ if (value.isCalculatedPercentageWithLength())
+ return origin + sign * value.cssCalcValue()->toCalcValue(conversionData)->evaluate(edgeDistance);
- switch (value->getValueID()) {
+ switch (value.getValueID()) {
case CSSValueTop:
ASSERT(!isHorizontal);
return 0;
@@ -525,18 +526,18 @@ static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConver
break;
}
- return origin + sign * value->computeLength<float>(conversionData);
+ return origin + sign * value.computeLength<float>(conversionData);
}
-FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSPrimitiveValue* vertical, const CSSToLengthConversionData& conversionData, const IntSize& size)
+FloatPoint CSSGradientValue::computeEndPoint(NullableCSSValue horizontal, NullableCSSValue vertical, const CSSToLengthConversionData& conversionData, const IntSize& size)
{
FloatPoint result;
if (horizontal)
- result.setX(positionFromValue(horizontal, conversionData, size, true));
+ result.setX(positionFromValue(toCSSPrimitiveValue(*horizontal), conversionData, size, true));
if (vertical)
- result.setY(positionFromValue(vertical, conversionData, size, false));
+ result.setY(positionFromValue(toCSSPrimitiveValue(*vertical), conversionData, size, false));
return result;
}
@@ -546,13 +547,13 @@ bool CSSGradientValue::isCacheable() const
for (size_t i = 0; i < m_stops.size(); ++i) {
const CSSGradientColorStop& stop = m_stops[i];
- if (!stop.isHint() && stop.m_color->colorIsDerivedFromElement())
+ if (!stop.isHint() && toCSSPrimitiveValue(*stop.m_color).colorIsDerivedFromElement())
return false;
if (!stop.m_position)
continue;
- if (stop.m_position->isFontRelativeLength())
+ if (toCSSPrimitiveValue(*stop.m_position).isFontRelativeLength())
return false;
}
@@ -563,7 +564,7 @@ bool CSSGradientValue::knownToBeOpaque(const LayoutObject* object) const
{
ASSERT(object);
for (auto& stop : m_stops) {
- if (!stop.isHint() && resolveStopColor(*stop.m_color.get(), *object).hasAlpha())
+ if (!stop.isHint() && resolveStopColor(toCSSPrimitiveValue(*stop.m_color), *object).hasAlpha())
return false;
}
return true;
@@ -633,10 +634,10 @@ String CSSLinearGradientValue::customCSSText() const
bool wroteSomething = false;
- if (m_angle && m_angle->computeDegrees() != 180) {
+ if (m_angle && toCSSPrimitiveValue(*m_angle).computeDegrees() != 180) {
result.append(m_angle->cssText());
wroteSomething = true;
- } else if ((m_firstX || m_firstY) && !(!m_firstX && m_firstY && m_firstY->getValueID() == CSSValueBottom)) {
+ } else if ((m_firstX || m_firstY) && !(!m_firstX && m_firstY && toCSSPrimitiveValue(*m_firstY).getValueID() == CSSValueBottom)) {
result.appendLiteral("to ");
if (m_firstX && m_firstY) {
result.append(m_firstX->cssText());
@@ -745,14 +746,14 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(const CSSToLengthCon
FloatPoint firstPoint;
FloatPoint secondPoint;
if (m_angle) {
- float angle = m_angle->computeDegrees();
+ float angle = toCSSPrimitiveValue(*m_angle).computeDegrees();
endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType);
} else {
switch (m_gradientType) {
case CSSDeprecatedLinearGradient:
- firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
+ firstPoint = computeEndPoint(m_firstX, m_firstY, conversionData, size);
if (m_secondX || m_secondY)
- secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size);
+ secondPoint = computeEndPoint(m_secondX, m_secondY, conversionData, size);
else {
if (m_firstX)
secondPoint.setX(size.width() - firstPoint.x());
@@ -761,7 +762,7 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(const CSSToLengthCon
}
break;
case CSSPrefixedLinearGradient:
- firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
+ firstPoint = computeEndPoint(m_firstX, m_firstY, conversionData, size);
if (m_firstX)
secondPoint.setX(size.width() - firstPoint.x());
if (m_firstY)
@@ -772,15 +773,15 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(const CSSToLengthCon
// "Magic" corners, so the 50% line touches two corners.
float rise = size.width();
float run = size.height();
- if (m_firstX && m_firstX->getValueID() == CSSValueLeft)
+ if (m_firstX && toCSSPrimitiveValue(*m_firstX).getValueID() == CSSValueLeft)
run *= -1;
- if (m_firstY && m_firstY->getValueID() == CSSValueBottom)
+ if (m_firstY && toCSSPrimitiveValue(*m_firstY).getValueID() == CSSValueBottom)
rise *= -1;
// Compute angle, and flip it back to "bearing angle" degrees.
float angle = 90 - rad2deg(atan2(rise, run));
endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType);
} else if (m_firstX || m_firstY) {
- secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
+ secondPoint = computeEndPoint(m_firstX, m_firstY, conversionData, size);
if (m_firstX)
firstPoint.setX(size.width() - secondPoint.x());
if (m_firstY)
@@ -809,28 +810,28 @@ bool CSSLinearGradientValue::equals(const CSSLinearGradientValue& other) const
{
if (m_gradientType == CSSDeprecatedLinearGradient)
return other.m_gradientType == m_gradientType
- && compareCSSValuePtr(m_firstX, other.m_firstX)
- && compareCSSValuePtr(m_firstY, other.m_firstY)
- && compareCSSValuePtr(m_secondX, other.m_secondX)
- && compareCSSValuePtr(m_secondY, other.m_secondY)
+ && m_firstX == other.m_firstX
+ && m_firstY == other.m_firstY
+ && m_secondX == other.m_secondX
+ && m_secondY == other.m_secondY
&& m_stops == other.m_stops;
if (m_repeating != other.m_repeating)
return false;
if (m_angle)
- return compareCSSValuePtr(m_angle, other.m_angle) && m_stops == other.m_stops;
+ return m_angle == other.m_angle && m_stops == other.m_stops;
if (other.m_angle)
return false;
bool equalXandY = false;
if (m_firstX && m_firstY)
- equalXandY = compareCSSValuePtr(m_firstX, other.m_firstX) && compareCSSValuePtr(m_firstY, other.m_firstY);
+ equalXandY = m_firstX == other.m_firstX && m_firstY == other.m_firstY;
else if (m_firstX)
- equalXandY = compareCSSValuePtr(m_firstX, other.m_firstX) && !other.m_firstY;
+ equalXandY = m_firstX == other.m_firstX && !other.m_firstY;
else if (m_firstY)
- equalXandY = compareCSSValuePtr(m_firstY, other.m_firstY) && !other.m_firstX;
+ equalXandY = m_firstY == other.m_firstY && !other.m_firstX;
else
equalXandY = !other.m_firstX && !other.m_firstY;
@@ -848,17 +849,18 @@ inline void CSSGradientValue::appendCSSTextForDeprecatedColorStops(StringBuilder
for (unsigned i = 0; i < m_stops.size(); i++) {
const CSSGradientColorStop& stop = m_stops[i];
result.appendLiteral(", ");
- if (stop.m_position->getDoubleValue() == 0) {
+ double stopValue = toCSSPrimitiveValue(*stop.m_position).getDoubleValue();
+ if (stopValue == 0) {
result.appendLiteral("from(");
result.append(stop.m_color->cssText());
result.append(')');
- } else if (stop.m_position->getDoubleValue() == 1) {
+ } else if (stopValue == 1) {
result.appendLiteral("to(");
result.append(stop.m_color->cssText());
result.append(')');
} else {
result.appendLiteral("color-stop(");
- result.appendNumber(stop.m_position->getDoubleValue());
+ result.appendNumber(stopValue);
result.appendLiteral(", ");
result.append(stop.m_color->cssText());
result.append(')');
@@ -940,12 +942,12 @@ String CSSRadialGradientValue::customCSSText() const
// The only ambiguous case that needs an explicit shape to be provided
// is when a sizing keyword is used (or all sizing is omitted).
- if (m_shape && m_shape->getValueID() != CSSValueEllipse && (m_sizingBehavior || (!m_sizingBehavior && !m_endHorizontalSize))) {
+ if (m_shape && toCSSPrimitiveValue(*m_shape).getValueID() != CSSValueEllipse && (m_sizingBehavior || (!m_sizingBehavior && !m_endHorizontalSize))) {
result.appendLiteral("circle");
wroteSomething = true;
}
- if (m_sizingBehavior && m_sizingBehavior->getValueID() != CSSValueFarthestCorner) {
+ if (m_sizingBehavior && toCSSPrimitiveValue(*m_sizingBehavior).getValueID() != CSSValueFarthestCorner) {
if (wroteSomething)
result.append(' ');
result.append(m_sizingBehavior->cssText());
@@ -997,15 +999,15 @@ String CSSRadialGradientValue::customCSSText() const
return result.toString();
}
-float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight)
+float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight)
{
float result = 0;
- if (radius->isNumber()) // Can the radius be a percentage?
- result = radius->getFloatValue() * conversionData.zoom();
- else if (widthOrHeight && radius->isPercentage())
- result = *widthOrHeight * radius->getFloatValue() / 100;
+ if (radius.isNumber()) // Can the radius be a percentage?
+ result = radius.getFloatValue() * conversionData.zoom();
+ else if (widthOrHeight && radius.isPercentage())
+ result = *widthOrHeight * radius.getFloatValue() / 100;
else
- result = radius->computeLength<float>(conversionData);
+ result = radius.computeLength<float>(conversionData);
return std::max(result, 0.0f);
}
@@ -1100,26 +1102,26 @@ PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(const CSSToLengthCon
float firstRadius = 0;
if (m_firstRadius)
- firstRadius = resolveRadius(m_firstRadius.get(), conversionData);
+ firstRadius = resolveRadius(toCSSPrimitiveValue(*m_firstRadius), conversionData);
FloatSize secondRadius(0, 0);
if (m_secondRadius) {
- secondRadius.setWidth(resolveRadius(m_secondRadius.get(), conversionData));
+ secondRadius.setWidth(resolveRadius(toCSSPrimitiveValue(*m_secondRadius), conversionData));
secondRadius.setHeight(secondRadius.width());
} else if (m_endHorizontalSize) {
float width = size.width();
float height = size.height();
- secondRadius.setWidth(resolveRadius(m_endHorizontalSize.get(), conversionData, &width));
+ secondRadius.setWidth(resolveRadius(toCSSPrimitiveValue(*m_endHorizontalSize), conversionData, &width));
secondRadius.setHeight(m_endVerticalSize
- ? resolveRadius(m_endVerticalSize.get(), conversionData, &height)
+ ? resolveRadius(toCSSPrimitiveValue(*m_endVerticalSize), conversionData, &height)
: secondRadius.width());
} else {
- EndShapeType shape = (m_shape && m_shape->getValueID() == CSSValueCircle) ||
- (!m_shape && !m_sizingBehavior && m_endHorizontalSize && !m_endVerticalSize)
+ EndShapeType shape = (m_shape && toCSSPrimitiveValue(*m_shape).getValueID() == CSSValueCircle)
+ || (!m_shape && !m_sizingBehavior && m_endHorizontalSize && !m_endVerticalSize)
? CircleEndShape
: EllipseEndShape;
- switch (m_sizingBehavior ? m_sizingBehavior->getValueID() : 0) {
+ switch (m_sizingBehavior ? toCSSPrimitiveValue(*m_sizingBehavior).getValueID() : 0) {
case CSSValueContain:
case CSSValueClosestSide:
secondRadius = radiusToSide(secondPoint, size, shape,
@@ -1157,12 +1159,12 @@ bool CSSRadialGradientValue::equals(const CSSRadialGradientValue& other) const
{
if (m_gradientType == CSSDeprecatedRadialGradient)
return other.m_gradientType == m_gradientType
- && compareCSSValuePtr(m_firstX, other.m_firstX)
- && compareCSSValuePtr(m_firstY, other.m_firstY)
- && compareCSSValuePtr(m_secondX, other.m_secondX)
- && compareCSSValuePtr(m_secondY, other.m_secondY)
- && compareCSSValuePtr(m_firstRadius, other.m_firstRadius)
- && compareCSSValuePtr(m_secondRadius, other.m_secondRadius)
+ && m_firstX == other.m_firstX
+ && m_firstY == other.m_firstY
+ && m_secondX == other.m_secondX
+ && m_secondY == other.m_secondY
+ && m_firstRadius == other.m_firstRadius
+ && m_secondRadius == other.m_secondRadius
&& m_stops == other.m_stops;
if (m_repeating != other.m_repeating)
@@ -1170,11 +1172,11 @@ bool CSSRadialGradientValue::equals(const CSSRadialGradientValue& other) const
bool equalXandY = false;
if (m_firstX && m_firstY)
- equalXandY = compareCSSValuePtr(m_firstX, other.m_firstX) && compareCSSValuePtr(m_firstY, other.m_firstY);
+ equalXandY = m_firstX == other.m_firstX && m_firstY == other.m_firstY;
else if (m_firstX)
- equalXandY = compareCSSValuePtr(m_firstX, other.m_firstX) && !other.m_firstY;
+ equalXandY = m_firstX == other.m_firstX && !other.m_firstY;
else if (m_firstY)
- equalXandY = compareCSSValuePtr(m_firstY, other.m_firstY) && !other.m_firstX;
+ equalXandY = m_firstY == other.m_firstY && !other.m_firstX;
else
equalXandY = !other.m_firstX && !other.m_firstY;
@@ -1186,11 +1188,11 @@ bool CSSRadialGradientValue::equals(const CSSRadialGradientValue& other) const
bool equalHorizontalAndVerticalSize = true;
if (m_shape)
- equalShape = compareCSSValuePtr(m_shape, other.m_shape);
+ equalShape = m_shape == other.m_shape;
else if (m_sizingBehavior)
- equalSizingBehavior = compareCSSValuePtr(m_sizingBehavior, other.m_sizingBehavior);
+ equalSizingBehavior = m_sizingBehavior == other.m_sizingBehavior;
else if (m_endHorizontalSize && m_endVerticalSize)
- equalHorizontalAndVerticalSize = compareCSSValuePtr(m_endHorizontalSize, other.m_endHorizontalSize) && compareCSSValuePtr(m_endVerticalSize, other.m_endVerticalSize);
+ equalHorizontalAndVerticalSize = m_endHorizontalSize == other.m_endHorizontalSize && m_endVerticalSize == other.m_endVerticalSize;
else {
equalShape = !other.m_shape;
equalSizingBehavior = !other.m_sizingBehavior;
« no previous file with comments | « Source/core/css/CSSGradientValue.h ('k') | Source/core/css/CSSMatrix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698