Changeset 167937 in webkit for trunk/Source/WebCore/css/CSSGradientValue.cpp
- Timestamp:
- Apr 29, 2014, 9:36:43 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSGradientValue.cpp
r166860 r167937 28 28 29 29 #include "CSSCalculationValue.h" 30 #include "CSSToLengthConversionData.h" 30 31 #include "CSSValueKeywords.h" 31 32 #include "FloatSize.h" … … 129 130 } 130 131 131 void CSSGradientValue::addStops(Gradient* gradient, RenderElement* renderer, const RenderStyle& rootStyle, float maxLengthForRepeat) 132 { 133 RenderStyle& style = renderer->style(); 134 132 void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat) 133 { 135 134 if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) { 136 135 sortStopsIfNeeded(); … … 182 181 float length; 183 182 if (stop.m_position->isLength()) 184 length = stop.m_position->computeLength<float>( &style, &rootStyle, style.effectiveZoom());183 length = stop.m_position->computeLength<float>(conversionData); 185 184 else { 186 Ref<CalculationValue> calculationValue { stop.m_position->cssCalcValue()->createCalculationValue( &style, &rootStyle, style.effectiveZoom()) };185 Ref<CalculationValue> calculationValue { stop.m_position->cssCalcValue()->createCalculationValue(conversionData) }; 187 186 length = calculationValue->evaluate(gradientLength); 188 187 } … … 393 392 } 394 393 395 static float positionFromValue(CSSPrimitiveValue* value, const RenderStyle& style, const RenderStyle& rootStyle, const FloatSize& size, bool isHorizontal) 396 { 397 float zoomFactor = style.effectiveZoom(); 398 394 static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal) 395 { 399 396 if (value->isNumber()) 400 return value->getFloatValue() * zoomFactor;397 return value->getFloatValue() * conversionData.zoom(); 401 398 402 399 int edgeDistance = isHorizontal ? size.width() : size.height(); … … 405 402 406 403 if (value->isCalculatedPercentageWithLength()) { 407 Ref<CalculationValue> calculationValue { value->cssCalcValue()->createCalculationValue( &style, &rootStyle, style.effectiveZoom()) };404 Ref<CalculationValue> calculationValue { value->cssCalcValue()->createCalculationValue(conversionData) }; 408 405 return calculationValue->evaluate(edgeDistance); 409 406 } … … 426 423 } 427 424 428 return value->computeLength<float>( &style, &rootStyle, zoomFactor);429 } 430 431 FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSPrimitiveValue* vertical, const RenderStyle& style, const RenderStyle& rootStyle, const FloatSize& size)425 return value->computeLength<float>(conversionData); 426 } 427 428 FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSPrimitiveValue* vertical, const CSSToLengthConversionData& conversionData, const FloatSize& size) 432 429 { 433 430 FloatPoint result; 434 431 435 432 if (horizontal) 436 result.setX(positionFromValue(horizontal, style, rootStyle, size, true));433 result.setX(positionFromValue(horizontal, conversionData, size, true)); 437 434 438 435 if (vertical) 439 result.setY(positionFromValue(vertical, style, rootStyle, size, false));436 result.setY(positionFromValue(vertical, conversionData, size, false)); 440 437 441 438 return result; … … 648 645 ASSERT(!size.isEmpty()); 649 646 650 RenderStyle& rootStyle = *renderer->document().documentElement()->renderStyle();647 CSSToLengthConversionData conversionData(&renderer->style(), renderer->document().documentElement()->renderStyle()); 651 648 652 649 FloatPoint firstPoint; … … 658 655 switch (m_gradientType) { 659 656 case CSSDeprecatedLinearGradient: 660 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);657 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); 661 658 if (m_secondX || m_secondY) 662 secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), renderer->style(), rootStyle, size);659 secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size); 663 660 else { 664 661 if (m_firstX) … … 669 666 break; 670 667 case CSSPrefixedLinearGradient: 671 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);668 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); 672 669 if (m_firstX) 673 670 secondPoint.setX(size.width() - firstPoint.x()); … … 688 685 endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType); 689 686 } else if (m_firstX || m_firstY) { 690 secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);687 secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); 691 688 if (m_firstX) 692 689 firstPoint.setX(size.width() - secondPoint.x()); … … 705 702 706 703 // Now add the stops. 707 addStops(gradient.get(), renderer, rootStyle, 1);704 addStops(gradient.get(), conversionData, 1); 708 705 709 706 return gradient.release(); … … 892 889 } 893 890 894 float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, const RenderStyle& style, const RenderStyle& rootStyle, float* widthOrHeight) 895 { 896 float zoomFactor = style.effectiveZoom(); 897 891 float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight) 892 { 898 893 float result = 0; 899 894 if (radius->isNumber()) // Can the radius be a percentage? 900 result = radius->getFloatValue() * zoomFactor;895 result = radius->getFloatValue() * conversionData.zoom(); 901 896 else if (widthOrHeight && radius->isPercentage()) 902 897 result = *widthOrHeight * radius->getFloatValue() / 100; 903 898 else 904 result = radius->computeLength<float>( &style, &rootStyle, zoomFactor);899 result = radius->computeLength<float>(conversionData); 905 900 906 901 return result; … … 988 983 ASSERT(!size.isEmpty()); 989 984 990 RenderStyle& rootStyle = *renderer->document().documentElement()->renderStyle();991 992 FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);985 CSSToLengthConversionData conversionData(&renderer->style(), renderer->document().documentElement()->renderStyle()); 986 987 FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); 993 988 if (!m_firstX) 994 989 firstPoint.setX(size.width() / 2); … … 996 991 firstPoint.setY(size.height() / 2); 997 992 998 FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), renderer->style(), rootStyle, size);993 FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size); 999 994 if (!m_secondX) 1000 995 secondPoint.setX(size.width() / 2); … … 1004 999 float firstRadius = 0; 1005 1000 if (m_firstRadius) 1006 firstRadius = resolveRadius(m_firstRadius.get(), renderer->style(), rootStyle);1001 firstRadius = resolveRadius(m_firstRadius.get(), conversionData); 1007 1002 1008 1003 float secondRadius = 0; 1009 1004 float aspectRatio = 1; // width / height. 1010 1005 if (m_secondRadius) 1011 secondRadius = resolveRadius(m_secondRadius.get(), renderer->style(), rootStyle);1006 secondRadius = resolveRadius(m_secondRadius.get(), conversionData); 1012 1007 else if (m_endHorizontalSize) { 1013 1008 float width = size.width(); 1014 1009 float height = size.height(); 1015 secondRadius = resolveRadius(m_endHorizontalSize.get(), renderer->style(), rootStyle, &width);1010 secondRadius = resolveRadius(m_endHorizontalSize.get(), conversionData, &width); 1016 1011 if (m_endVerticalSize) 1017 aspectRatio = secondRadius / resolveRadius(m_endVerticalSize.get(), renderer->style(), rootStyle, &height);1012 aspectRatio = secondRadius / resolveRadius(m_endVerticalSize.get(), conversionData, &height); 1018 1013 else 1019 1014 aspectRatio = 1; … … 1121 1116 1122 1117 // Now add the stops. 1123 addStops(gradient.get(), renderer, rootStyle, maxExtent);1118 addStops(gradient.get(), conversionData, maxExtent); 1124 1119 1125 1120 return gradient.release();
Note:
See TracChangeset
for help on using the changeset viewer.