Changeset 169258 in webkit for trunk/Source/WebCore/css/CSSGradientValue.cpp
- Timestamp:
- May 23, 2014, 9:13:03 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSGradientValue.cpp
r169248 r169258 61 61 62 62 if (isLinearGradientValue()) 63 gradient = toCSSLinearGradientValue(this)->createGradient( renderer, size);63 gradient = toCSSLinearGradientValue(this)->createGradient(*renderer, size); 64 64 else 65 gradient = toCSSRadialGradientValue(this)->createGradient( renderer, size);65 gradient = toCSSRadialGradientValue(this)->createGradient(*renderer, size); 66 66 67 67 RefPtr<GradientImage> newImage = GradientImage::create(gradient, size); … … 130 130 } 131 131 132 void CSSGradientValue::addStops(Gradient * gradient, RenderView*renderView, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)132 void CSSGradientValue::addStops(Gradient& gradient, RenderView& renderView, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat) 133 133 { 134 134 if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) { … … 144 144 offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_NUMBER); 145 145 146 gradient ->addColorStop(offset, stop.m_resolvedColor);146 gradient.addColorStop(offset, stop.m_resolvedColor); 147 147 } 148 148 149 149 // The back end already sorted the stops. 150 gradient ->setStopsSorted(true);150 gradient.setStopsSorted(true); 151 151 return; 152 152 } … … 159 159 bool computedGradientLength = false; 160 160 161 FloatPoint gradientStart = gradient ->p0();161 FloatPoint gradientStart = gradient.p0(); 162 162 FloatPoint gradientEnd; 163 163 if (isLinearGradientValue()) 164 gradientEnd = gradient ->p1();164 gradientEnd = gradient.p1(); 165 165 else if (isRadialGradientValue()) 166 gradientEnd = gradientStart + FloatSize(gradient ->endRadius(), 0);166 gradientEnd = gradientStart + FloatSize(gradient.endRadius(), 0); 167 167 168 168 for (size_t i = 0; i < numStops; ++i) { … … 184 184 length = positionValue.computeLength<float>(conversionData); 185 185 else if (positionValue.isViewportPercentageLength()) 186 length = valueForLength(positionValue.viewportPercentageLength(), 0, renderView);186 length = valueForLength(positionValue.viewportPercentageLength(), 0, &renderView); 187 187 else { 188 188 Ref<CalculationValue> calculationValue { positionValue.cssCalcValue()->createCalculationValue(conversionData) }; … … 336 336 stops[i].offset = (stops[i].offset - firstOffset) / scale; 337 337 338 FloatPoint p0 = gradient ->p0();339 FloatPoint p1 = gradient ->p1();340 gradient ->setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y())));341 gradient ->setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y())));338 FloatPoint p0 = gradient.p0(); 339 FloatPoint p1 = gradient.p1(); 340 gradient.setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y()))); 341 gradient.setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y()))); 342 342 } else { 343 343 // There's a single position that is outside the scale, clamp the positions to 1. … … 384 384 stops[i].offset /= scale; 385 385 386 gradient ->setStartRadius(gradient->startRadius() * scale);387 gradient ->setEndRadius(gradient->endRadius() * scale);386 gradient.setStartRadius(gradient.startRadius() * scale); 387 gradient.setEndRadius(gradient.endRadius() * scale); 388 388 } 389 389 } 390 390 391 391 for (unsigned i = 0; i < numStops; i++) 392 gradient ->addColorStop(stops[i].offset, stops[i].color);393 394 gradient ->setStopsSorted(true);395 } 396 397 static float positionFromValue(CSSPrimitiveValue *value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal)398 { 399 if (value ->isNumber())400 return value ->getFloatValue() * conversionData.zoom();392 gradient.addColorStop(stops[i].offset, stops[i].color); 393 394 gradient.setStopsSorted(true); 395 } 396 397 static float positionFromValue(CSSPrimitiveValue& value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal) 398 { 399 if (value.isNumber()) 400 return value.getFloatValue() * conversionData.zoom(); 401 401 402 402 int edgeDistance = isHorizontal ? size.width() : size.height(); 403 if (value ->isPercentage())404 return value ->getFloatValue() / 100.f * edgeDistance;405 406 if (value ->isCalculatedPercentageWithLength()) {407 Ref<CalculationValue> calculationValue { value ->cssCalcValue()->createCalculationValue(conversionData) };403 if (value.isPercentage()) 404 return value.getFloatValue() / 100.f * edgeDistance; 405 406 if (value.isCalculatedPercentageWithLength()) { 407 Ref<CalculationValue> calculationValue { value.cssCalcValue()->createCalculationValue(conversionData) }; 408 408 return calculationValue->evaluate(edgeDistance); 409 409 } 410 410 411 switch (value ->getValueID()) {411 switch (value.getValueID()) { 412 412 case CSSValueTop: 413 413 ASSERT(!isHorizontal); … … 426 426 } 427 427 428 return value ->computeLength<float>(conversionData);428 return value.computeLength<float>(conversionData); 429 429 } 430 430 … … 434 434 435 435 if (horizontal) 436 result.setX(positionFromValue( horizontal, conversionData, size, true));436 result.setX(positionFromValue(*horizontal, conversionData, size, true)); 437 437 438 438 if (vertical) 439 result.setY(positionFromValue( vertical, conversionData, size, false));439 result.setY(positionFromValue(*vertical, conversionData, size, false)); 440 440 441 441 return result; … … 644 644 } 645 645 646 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderElement *renderer, const FloatSize& size)646 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderElement& renderer, const FloatSize& size) 647 647 { 648 648 ASSERT(!size.isEmpty()); 649 649 650 CSSToLengthConversionData conversionData(&renderer ->style(), renderer->document().documentElement()->renderStyle());650 CSSToLengthConversionData conversionData(&renderer.style(), renderer.document().documentElement()->renderStyle()); 651 651 652 652 FloatPoint firstPoint; … … 705 705 706 706 // Now add the stops. 707 addStops( gradient.get(), &renderer->view(), conversionData, 1);707 addStops(*gradient, renderer.view(), conversionData, 1); 708 708 709 709 return gradient.release(); … … 892 892 } 893 893 894 float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue *radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight)894 float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue& radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight) 895 895 { 896 896 float result = 0; 897 if (radius ->isNumber()) // Can the radius be a percentage?898 result = radius ->getFloatValue() * conversionData.zoom();899 else if (widthOrHeight && radius ->isPercentage())900 result = *widthOrHeight * radius ->getFloatValue() / 100;897 if (radius.isNumber()) // Can the radius be a percentage? 898 result = radius.getFloatValue() * conversionData.zoom(); 899 else if (widthOrHeight && radius.isPercentage()) 900 result = *widthOrHeight * radius.getFloatValue() / 100; 901 901 else 902 result = radius ->computeLength<float>(conversionData);902 result = radius.computeLength<float>(conversionData); 903 903 904 904 return result; … … 982 982 983 983 // FIXME: share code with the linear version 984 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(RenderElement *renderer, const FloatSize& size)984 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(RenderElement& renderer, const FloatSize& size) 985 985 { 986 986 ASSERT(!size.isEmpty()); 987 987 988 CSSToLengthConversionData conversionData(&renderer ->style(), renderer->document().documentElement()->renderStyle());988 CSSToLengthConversionData conversionData(&renderer.style(), renderer.document().documentElement()->renderStyle()); 989 989 990 990 FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); … … 1002 1002 float firstRadius = 0; 1003 1003 if (m_firstRadius) 1004 firstRadius = resolveRadius( m_firstRadius.get(), conversionData);1004 firstRadius = resolveRadius(*m_firstRadius, conversionData); 1005 1005 1006 1006 float secondRadius = 0; 1007 1007 float aspectRatio = 1; // width / height. 1008 1008 if (m_secondRadius) 1009 secondRadius = resolveRadius( m_secondRadius.get(), conversionData);1009 secondRadius = resolveRadius(*m_secondRadius, conversionData); 1010 1010 else if (m_endHorizontalSize) { 1011 1011 float width = size.width(); 1012 1012 float height = size.height(); 1013 secondRadius = resolveRadius( m_endHorizontalSize.get(), conversionData, &width);1013 secondRadius = resolveRadius(*m_endHorizontalSize, conversionData, &width); 1014 1014 if (m_endVerticalSize) 1015 aspectRatio = secondRadius / resolveRadius( m_endVerticalSize.get(), conversionData, &height);1015 aspectRatio = secondRadius / resolveRadius(*m_endVerticalSize, conversionData, &height); 1016 1016 else 1017 1017 aspectRatio = 1; … … 1119 1119 1120 1120 // Now add the stops. 1121 addStops( gradient.get(), &renderer->view(), conversionData, maxExtent);1121 addStops(*gradient, renderer.view(), conversionData, maxExtent); 1122 1122 1123 1123 return gradient.release();
Note:
See TracChangeset
for help on using the changeset viewer.