| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if (result) | 64 if (result) |
| 65 return result; | 65 return result; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // We need to create an image. | 68 // We need to create an image. |
| 69 RefPtr<Gradient> gradient; | 69 RefPtr<Gradient> gradient; |
| 70 | 70 |
| 71 RenderStyle* rootStyle = renderer->document().documentElement()->renderStyle
(); | 71 RenderStyle* rootStyle = renderer->document().documentElement()->renderStyle
(); |
| 72 CSSToLengthConversionData conversionData(renderer->style(), rootStyle, rende
rer->view(), renderer->style()->effectiveZoom()); | 72 CSSToLengthConversionData conversionData(renderer->style(), rootStyle, rende
rer->view(), renderer->style()->effectiveZoom()); |
| 73 if (isLinearGradientValue()) | 73 if (isLinearGradientValue()) |
| 74 gradient = toCSSLinearGradientValue(this)->createGradient(conversionData
, size); | 74 gradient = toCSSLinearGradientValue(this)->createGradient(conversionData
, size, *renderer); |
| 75 else | 75 else |
| 76 gradient = toCSSRadialGradientValue(this)->createGradient(conversionData
, size); | 76 gradient = toCSSRadialGradientValue(this)->createGradient(conversionData
, size, *renderer); |
| 77 | 77 |
| 78 RefPtr<Image> newImage = GradientGeneratedImage::create(gradient, size); | 78 RefPtr<Image> newImage = GradientGeneratedImage::create(gradient, size); |
| 79 if (cacheable) | 79 if (cacheable) |
| 80 putImage(size, newImage); | 80 putImage(size, newImage); |
| 81 | 81 |
| 82 return newImage.release(); | 82 return newImage.release(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Should only ever be called for deprecated gradients. | 85 // Should only ever be called for deprecated gradients. |
| 86 static inline bool compareStops(const CSSGradientColorStop& a, const CSSGradient
ColorStop& b) | 86 static inline bool compareStops(const CSSGradientColorStop& a, const CSSGradient
ColorStop& b) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 newStops[y].color = blend(leftColor, rightColor, weighting); | 226 newStops[y].color = blend(leftColor, rightColor, weighting); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Replace the color hint with the new color stops. | 229 // Replace the color hint with the new color stops. |
| 230 stops.remove(x); | 230 stops.remove(x); |
| 231 stops.insert(x, newStops, 9); | 231 stops.insert(x, newStops, 9); |
| 232 indexOffset += 8; | 232 indexOffset += 8; |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionD
ata& conversionData, float maxLengthForRepeat) | 236 void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionD
ata& conversionData, float maxLengthForRepeat, const RenderObject& object) |
| 237 { | 237 { |
| 238 if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDe
precatedRadialGradient) { | 238 if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDe
precatedRadialGradient) { |
| 239 sortStopsIfNeeded(); | 239 sortStopsIfNeeded(); |
| 240 | 240 |
| 241 for (unsigned i = 0; i < m_stops.size(); i++) { | 241 for (unsigned i = 0; i < m_stops.size(); i++) { |
| 242 const CSSGradientColorStop& stop = m_stops[i]; | 242 const CSSGradientColorStop& stop = m_stops[i]; |
| 243 | 243 |
| 244 float offset; | 244 float offset; |
| 245 if (stop.m_position->isPercentage()) | 245 if (stop.m_position->isPercentage()) |
| 246 offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_P
ERCENTAGE) / 100; | 246 offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_P
ERCENTAGE) / 100; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 268 gradientEnd = gradient->p1(); | 268 gradientEnd = gradient->p1(); |
| 269 else if (isRadialGradientValue()) | 269 else if (isRadialGradientValue()) |
| 270 gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0); | 270 gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0); |
| 271 | 271 |
| 272 for (size_t i = 0; i < numStops; ++i) { | 272 for (size_t i = 0; i < numStops; ++i) { |
| 273 const CSSGradientColorStop& stop = m_stops[i]; | 273 const CSSGradientColorStop& stop = m_stops[i]; |
| 274 | 274 |
| 275 if (stop.isHint()) | 275 if (stop.isHint()) |
| 276 hasHints = true; | 276 hasHints = true; |
| 277 else | 277 else |
| 278 stops[i].color = stop.m_resolvedColor; | 278 stops[i].color = object.document().textLinkColors().colorFromPrimiti
veValue(stop.m_color.get(), object.style()->visitedDependentColor(CSSPropertyCol
or)); |
| 279 | 279 |
| 280 if (stop.m_position) { | 280 if (stop.m_position) { |
| 281 if (stop.m_position->isPercentage()) | 281 if (stop.m_position->isPercentage()) |
| 282 stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveVal
ue::CSS_PERCENTAGE) / 100; | 282 stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveVal
ue::CSS_PERCENTAGE) / 100; |
| 283 else if (stop.m_position->isLength() || stop.m_position->isCalculate
dPercentageWithLength()) { | 283 else if (stop.m_position->isLength() || stop.m_position->isCalculate
dPercentageWithLength()) { |
| 284 if (!computedGradientLength) { | 284 if (!computedGradientLength) { |
| 285 FloatSize gradientSize(gradientStart - gradientEnd); | 285 FloatSize gradientSize(gradientStart - gradientEnd); |
| 286 gradientLength = gradientSize.diagonalLength(); | 286 gradientLength = gradientSize.diagonalLength(); |
| 287 } | 287 } |
| 288 float length; | 288 float length; |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 float endX = c / (slope - perpendicularSlope); | 760 float endX = c / (slope - perpendicularSlope); |
| 761 float endY = perpendicularSlope * endX + c; | 761 float endY = perpendicularSlope * endX + c; |
| 762 | 762 |
| 763 // We computed the end point, so set the second point, | 763 // We computed the end point, so set the second point, |
| 764 // taking into account the moved origin and the fact that we're in drawing s
pace (+y = down). | 764 // taking into account the moved origin and the fact that we're in drawing s
pace (+y = down). |
| 765 secondPoint.set(halfWidth + endX, halfHeight - endY); | 765 secondPoint.set(halfWidth + endX, halfHeight - endY); |
| 766 // Reflect around the center for the start point. | 766 // Reflect around the center for the start point. |
| 767 firstPoint.set(halfWidth - endX, halfHeight + endY); | 767 firstPoint.set(halfWidth - endX, halfHeight + endY); |
| 768 } | 768 } |
| 769 | 769 |
| 770 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(const CSSToLengthCon
versionData& conversionData, const IntSize& size) | 770 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(const CSSToLengthCon
versionData& conversionData, const IntSize& size, const RenderObject& object) |
| 771 { | 771 { |
| 772 ASSERT(!size.isEmpty()); | 772 ASSERT(!size.isEmpty()); |
| 773 | 773 |
| 774 FloatPoint firstPoint; | 774 FloatPoint firstPoint; |
| 775 FloatPoint secondPoint; | 775 FloatPoint secondPoint; |
| 776 if (m_angle) { | 776 if (m_angle) { |
| 777 float angle = m_angle->getFloatValue(CSSPrimitiveValue::CSS_DEG); | 777 float angle = m_angle->getFloatValue(CSSPrimitiveValue::CSS_DEG); |
| 778 endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType)
; | 778 endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType)
; |
| 779 } else { | 779 } else { |
| 780 switch (m_gradientType) { | 780 switch (m_gradientType) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 ASSERT_NOT_REACHED(); | 821 ASSERT_NOT_REACHED(); |
| 822 } | 822 } |
| 823 | 823 |
| 824 } | 824 } |
| 825 | 825 |
| 826 RefPtr<Gradient> gradient = Gradient::create(firstPoint, secondPoint); | 826 RefPtr<Gradient> gradient = Gradient::create(firstPoint, secondPoint); |
| 827 | 827 |
| 828 gradient->setDrawsInPMColorSpace(true); | 828 gradient->setDrawsInPMColorSpace(true); |
| 829 | 829 |
| 830 // Now add the stops. | 830 // Now add the stops. |
| 831 addStops(gradient.get(), conversionData, 1); | 831 addStops(gradient.get(), conversionData, 1, object); |
| 832 | 832 |
| 833 return gradient.release(); | 833 return gradient.release(); |
| 834 } | 834 } |
| 835 | 835 |
| 836 bool CSSLinearGradientValue::equals(const CSSLinearGradientValue& other) const | 836 bool CSSLinearGradientValue::equals(const CSSLinearGradientValue& other) const |
| 837 { | 837 { |
| 838 if (m_gradientType == CSSDeprecatedLinearGradient) | 838 if (m_gradientType == CSSDeprecatedLinearGradient) |
| 839 return other.m_gradientType == m_gradientType | 839 return other.m_gradientType == m_gradientType |
| 840 && compareCSSValuePtr(m_firstX, other.m_firstX) | 840 && compareCSSValuePtr(m_firstX, other.m_firstX) |
| 841 && compareCSSValuePtr(m_firstY, other.m_firstY) | 841 && compareCSSValuePtr(m_firstY, other.m_firstY) |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 // width/height given by aspectRatio. | 1105 // width/height given by aspectRatio. |
| 1106 static inline float horizontalEllipseRadius(const FloatSize& p, float aspectRati
o) | 1106 static inline float horizontalEllipseRadius(const FloatSize& p, float aspectRati
o) |
| 1107 { | 1107 { |
| 1108 // x^2/a^2 + y^2/b^2 = 1 | 1108 // x^2/a^2 + y^2/b^2 = 1 |
| 1109 // a/b = aspectRatio, b = a/aspectRatio | 1109 // a/b = aspectRatio, b = a/aspectRatio |
| 1110 // a = sqrt(x^2 + y^2/(1/r^2)) | 1110 // a = sqrt(x^2 + y^2/(1/r^2)) |
| 1111 return sqrtf(p.width() * p.width() + (p.height() * p.height()) / (1 / (aspec
tRatio * aspectRatio))); | 1111 return sqrtf(p.width() * p.width() + (p.height() * p.height()) / (1 / (aspec
tRatio * aspectRatio))); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 // FIXME: share code with the linear version | 1114 // FIXME: share code with the linear version |
| 1115 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(const CSSToLengthCon
versionData& conversionData, const IntSize& size) | 1115 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(const CSSToLengthCon
versionData& conversionData, const IntSize& size, const RenderObject& object) |
| 1116 { | 1116 { |
| 1117 ASSERT(!size.isEmpty()); | 1117 ASSERT(!size.isEmpty()); |
| 1118 | 1118 |
| 1119 FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conv
ersionData, size); | 1119 FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conv
ersionData, size); |
| 1120 if (!m_firstX) | 1120 if (!m_firstX) |
| 1121 firstPoint.setX(size.width() / 2); | 1121 firstPoint.setX(size.width() / 2); |
| 1122 if (!m_firstY) | 1122 if (!m_firstY) |
| 1123 firstPoint.setY(size.height() / 2); | 1123 firstPoint.setY(size.height() / 2); |
| 1124 | 1124 |
| 1125 FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), c
onversionData, size); | 1125 FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), c
onversionData, size); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 gradient->setDrawsInPMColorSpace(true); | 1242 gradient->setDrawsInPMColorSpace(true); |
| 1243 | 1243 |
| 1244 // addStops() only uses maxExtent for repeating gradients. | 1244 // addStops() only uses maxExtent for repeating gradients. |
| 1245 float maxExtent = 0; | 1245 float maxExtent = 0; |
| 1246 if (m_repeating) { | 1246 if (m_repeating) { |
| 1247 FloatPoint corner; | 1247 FloatPoint corner; |
| 1248 maxExtent = distanceToFarthestCorner(secondPoint, size, corner); | 1248 maxExtent = distanceToFarthestCorner(secondPoint, size, corner); |
| 1249 } | 1249 } |
| 1250 | 1250 |
| 1251 // Now add the stops. | 1251 // Now add the stops. |
| 1252 addStops(gradient.get(), conversionData, maxExtent); | 1252 addStops(gradient.get(), conversionData, maxExtent, object); |
| 1253 | 1253 |
| 1254 return gradient.release(); | 1254 return gradient.release(); |
| 1255 } | 1255 } |
| 1256 | 1256 |
| 1257 bool CSSRadialGradientValue::equals(const CSSRadialGradientValue& other) const | 1257 bool CSSRadialGradientValue::equals(const CSSRadialGradientValue& other) const |
| 1258 { | 1258 { |
| 1259 if (m_gradientType == CSSDeprecatedRadialGradient) | 1259 if (m_gradientType == CSSDeprecatedRadialGradient) |
| 1260 return other.m_gradientType == m_gradientType | 1260 return other.m_gradientType == m_gradientType |
| 1261 && compareCSSValuePtr(m_firstX, other.m_firstX) | 1261 && compareCSSValuePtr(m_firstX, other.m_firstX) |
| 1262 && compareCSSValuePtr(m_firstY, other.m_firstY) | 1262 && compareCSSValuePtr(m_firstY, other.m_firstY) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 visitor->trace(m_firstRadius); | 1305 visitor->trace(m_firstRadius); |
| 1306 visitor->trace(m_secondRadius); | 1306 visitor->trace(m_secondRadius); |
| 1307 visitor->trace(m_shape); | 1307 visitor->trace(m_shape); |
| 1308 visitor->trace(m_sizingBehavior); | 1308 visitor->trace(m_sizingBehavior); |
| 1309 visitor->trace(m_endHorizontalSize); | 1309 visitor->trace(m_endHorizontalSize); |
| 1310 visitor->trace(m_endVerticalSize); | 1310 visitor->trace(m_endVerticalSize); |
| 1311 CSSGradientValue::traceAfterDispatch(visitor); | 1311 CSSGradientValue::traceAfterDispatch(visitor); |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 } // namespace blink | 1314 } // namespace blink |
| OLD | NEW |