| Index: Source/core/css/CSSGradientValue.cpp
|
| diff --git a/Source/core/css/CSSGradientValue.cpp b/Source/core/css/CSSGradientValue.cpp
|
| index 089190c13dd114fac59f705bed5504e1a597093c..d3002c256046bd4d55a9af7881f726e7d211e4a5 100644
|
| --- a/Source/core/css/CSSGradientValue.cpp
|
| +++ b/Source/core/css/CSSGradientValue.cpp
|
| @@ -28,6 +28,7 @@
|
|
|
| #include "CSSValueKeywords.h"
|
| #include "core/css/CSSCalculationValue.h"
|
| +#include "core/css/CSSToLengthConversionData.h"
|
| #include "core/dom/NodeRenderStyle.h"
|
| #include "core/dom/TextLinkColors.h"
|
| #include "core/platform/graphics/Gradient.h"
|
| @@ -61,10 +62,12 @@ PassRefPtr<Image> CSSGradientValue::image(RenderObject* renderer, const IntSize&
|
| // We need to create an image.
|
| RefPtr<Gradient> gradient;
|
|
|
| + RenderStyle* rootStyle = renderer->document().documentElement()->renderStyle();
|
| + CSSToLengthConversionData conversionData(renderer->style(), rootStyle);
|
| if (isLinearGradientValue())
|
| - gradient = toCSSLinearGradientValue(this)->createGradient(renderer, size);
|
| + gradient = toCSSLinearGradientValue(this)->createGradient(conversionData, size);
|
| else
|
| - gradient = toCSSRadialGradientValue(this)->createGradient(renderer, size);
|
| + gradient = toCSSRadialGradientValue(this)->createGradient(conversionData, size);
|
|
|
| RefPtr<Image> newImage = GradientGeneratedImage::create(gradient, size);
|
| if (cacheable)
|
| @@ -131,10 +134,8 @@ PassRefPtr<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(const
|
| return result.release();
|
| }
|
|
|
| -void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, RenderStyle* rootStyle, float maxLengthForRepeat)
|
| +void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
|
| {
|
| - RenderStyle* style = renderer->style();
|
| -
|
| if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) {
|
| sortStopsIfNeeded();
|
|
|
| @@ -184,9 +185,9 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend
|
| }
|
| float length;
|
| if (stop.m_position->isLength())
|
| - length = stop.m_position->computeLength<float>(style, rootStyle, style->effectiveZoom());
|
| + length = stop.m_position->computeLength<float>(conversionData);
|
| else
|
| - length = stop.m_position->cssCalcValue()->toCalcValue(style, rootStyle, style->effectiveZoom())->evaluate(gradientLength);
|
| + length = stop.m_position->cssCalcValue()->toCalcValue(conversionData)->evaluate(gradientLength);
|
| stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0;
|
| } else {
|
| ASSERT_NOT_REACHED();
|
| @@ -387,19 +388,17 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend
|
| gradient->setStopsSorted(true);
|
| }
|
|
|
| -static float positionFromValue(CSSPrimitiveValue* value, RenderStyle* style, RenderStyle* rootStyle, const IntSize& size, bool isHorizontal)
|
| +static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const IntSize& size, bool isHorizontal)
|
| {
|
| - float zoomFactor = style->effectiveZoom();
|
| -
|
| if (value->isNumber())
|
| - return value->getFloatValue() * zoomFactor;
|
| + return value->getFloatValue() * conversionData.zoom();
|
|
|
| int edgeDistance = isHorizontal ? size.width() : size.height();
|
| if (value->isPercentage())
|
| return value->getFloatValue() / 100.f * edgeDistance;
|
|
|
| if (value->isCalculatedPercentageWithLength())
|
| - return value->cssCalcValue()->toCalcValue(style, rootStyle, style->effectiveZoom())->evaluate(edgeDistance);
|
| + return value->cssCalcValue()->toCalcValue(conversionData)->evaluate(edgeDistance);
|
|
|
| switch (value->getValueID()) {
|
| case CSSValueTop:
|
| @@ -418,18 +417,18 @@ static float positionFromValue(CSSPrimitiveValue* value, RenderStyle* style, Ren
|
| break;
|
| }
|
|
|
| - return value->computeLength<float>(style, rootStyle, zoomFactor);
|
| + return value->computeLength<float>(conversionData);
|
| }
|
|
|
| -FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSPrimitiveValue* vertical, RenderStyle* style, RenderStyle* rootStyle, const IntSize& size)
|
| +FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSPrimitiveValue* vertical, const CSSToLengthConversionData& conversionData, const IntSize& size)
|
| {
|
| FloatPoint result;
|
|
|
| if (horizontal)
|
| - result.setX(positionFromValue(horizontal, style, rootStyle, size, true));
|
| + result.setX(positionFromValue(horizontal, conversionData, size, true));
|
|
|
| if (vertical)
|
| - result.setY(positionFromValue(vertical, style, rootStyle, size, false));
|
| + result.setY(positionFromValue(vertical, conversionData, size, false));
|
|
|
| return result;
|
| }
|
| @@ -636,12 +635,10 @@ static void endPointsFromAngle(float angleDeg, const IntSize& size, FloatPoint&
|
| firstPoint.set(halfWidth - endX, halfHeight + endY);
|
| }
|
|
|
| -PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderObject* renderer, const IntSize& size)
|
| +PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(const CSSToLengthConversionData& conversionData, const IntSize& size)
|
| {
|
| ASSERT(!size.isEmpty());
|
|
|
| - RenderStyle* rootStyle = renderer->document().documentElement()->renderStyle();
|
| -
|
| FloatPoint firstPoint;
|
| FloatPoint secondPoint;
|
| if (m_angle) {
|
| @@ -650,9 +647,9 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderObject* render
|
| } else {
|
| switch (m_gradientType) {
|
| case CSSDeprecatedLinearGradient:
|
| - firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);
|
| + firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
|
| if (m_secondX || m_secondY)
|
| - secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), renderer->style(), rootStyle, size);
|
| + secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size);
|
| else {
|
| if (m_firstX)
|
| secondPoint.setX(size.width() - firstPoint.x());
|
| @@ -661,7 +658,7 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderObject* render
|
| }
|
| break;
|
| case CSSPrefixedLinearGradient:
|
| - firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);
|
| + firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
|
| if (m_firstX)
|
| secondPoint.setX(size.width() - firstPoint.x());
|
| if (m_firstY)
|
| @@ -680,7 +677,7 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderObject* render
|
| 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(), renderer->style(), rootStyle, size);
|
| + secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
|
| if (m_firstX)
|
| firstPoint.setX(size.width() - secondPoint.x());
|
| if (m_firstY)
|
| @@ -699,7 +696,7 @@ PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderObject* render
|
| gradient->setDrawsInPMColorSpace(true);
|
|
|
| // Now add the stops.
|
| - addStops(gradient.get(), renderer, rootStyle, 1);
|
| + addStops(gradient.get(), conversionData, 1);
|
|
|
| return gradient.release();
|
| }
|
| @@ -886,17 +883,15 @@ String CSSRadialGradientValue::customCSSText() const
|
| return result.toString();
|
| }
|
|
|
| -float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, RenderStyle* style, RenderStyle* rootStyle, float* widthOrHeight)
|
| +float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight)
|
| {
|
| - float zoomFactor = style->effectiveZoom();
|
| -
|
| float result = 0;
|
| if (radius->isNumber()) // Can the radius be a percentage?
|
| - result = radius->getFloatValue() * zoomFactor;
|
| + result = radius->getFloatValue() * conversionData.zoom();
|
| else if (widthOrHeight && radius->isPercentage())
|
| result = *widthOrHeight * radius->getFloatValue() / 100;
|
| else
|
| - result = radius->computeLength<float>(style, rootStyle, zoomFactor);
|
| + result = radius->computeLength<float>(conversionData);
|
|
|
| return result;
|
| }
|
| @@ -978,19 +973,17 @@ static inline float horizontalEllipseRadius(const FloatSize& p, float aspectRati
|
| }
|
|
|
| // FIXME: share code with the linear version
|
| -PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(RenderObject* renderer, const IntSize& size)
|
| +PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(const CSSToLengthConversionData& conversionData, const IntSize& size)
|
| {
|
| ASSERT(!size.isEmpty());
|
|
|
| - RenderStyle* rootStyle = renderer->document().documentElement()->renderStyle();
|
| -
|
| - FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);
|
| + FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
|
| if (!m_firstX)
|
| firstPoint.setX(size.width() / 2);
|
| if (!m_firstY)
|
| firstPoint.setY(size.height() / 2);
|
|
|
| - FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), renderer->style(), rootStyle, size);
|
| + FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size);
|
| if (!m_secondX)
|
| secondPoint.setX(size.width() / 2);
|
| if (!m_secondY)
|
| @@ -998,18 +991,18 @@ PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(RenderObject* render
|
|
|
| float firstRadius = 0;
|
| if (m_firstRadius)
|
| - firstRadius = resolveRadius(m_firstRadius.get(), renderer->style(), rootStyle);
|
| + firstRadius = resolveRadius(m_firstRadius.get(), conversionData);
|
|
|
| float secondRadius = 0;
|
| float aspectRatio = 1; // width / height.
|
| if (m_secondRadius)
|
| - secondRadius = resolveRadius(m_secondRadius.get(), renderer->style(), rootStyle);
|
| + secondRadius = resolveRadius(m_secondRadius.get(), conversionData);
|
| else if (m_endHorizontalSize) {
|
| float width = size.width();
|
| float height = size.height();
|
| - secondRadius = resolveRadius(m_endHorizontalSize.get(), renderer->style(), rootStyle, &width);
|
| + secondRadius = resolveRadius(m_endHorizontalSize.get(), conversionData, &width);
|
| if (m_endVerticalSize)
|
| - aspectRatio = secondRadius / resolveRadius(m_endVerticalSize.get(), renderer->style(), rootStyle, &height);
|
| + aspectRatio = secondRadius / resolveRadius(m_endVerticalSize.get(), conversionData, &height);
|
| else
|
| aspectRatio = 1;
|
| } else {
|
| @@ -1117,7 +1110,7 @@ PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(RenderObject* render
|
| }
|
|
|
| // Now add the stops.
|
| - addStops(gradient.get(), renderer, rootStyle, maxExtent);
|
| + addStops(gradient.get(), conversionData, maxExtent);
|
|
|
| return gradient.release();
|
| }
|
|
|