OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2015 Google Inc. All rights reserved. | 3 * Copyright (C) 2015 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1026 | 1026 |
1027 enum EndShapeType { | 1027 enum EndShapeType { |
1028 CircleEndShape, | 1028 CircleEndShape, |
1029 EllipseEndShape | 1029 EllipseEndShape |
1030 }; | 1030 }; |
1031 | 1031 |
1032 // Compute the radius to the closest/farthest side (depending on the compare fun ctor). | 1032 // Compute the radius to the closest/farthest side (depending on the compare fun ctor). |
1033 FloatSize radiusToSide(const FloatPoint& point, const FloatSize& size, EndShapeT ype shape, | 1033 FloatSize radiusToSide(const FloatPoint& point, const FloatSize& size, EndShapeT ype shape, |
1034 bool (*compare)(float, float)) | 1034 bool (*compare)(float, float)) |
1035 { | 1035 { |
1036 float dx1 = fabs(point.x()); | 1036 float dx1 = clampTo<float>(fabs(point.x())); |
1037 float dy1 = fabs(point.y()); | 1037 float dy1 = clampTo<float>(fabs(point.y())); |
1038 float dx2 = fabs(point.x() - size.width()); | 1038 float dx2 = clampTo<float>(fabs(point.x() - size.width())); |
1039 float dy2 = fabs(point.y() - size.height()); | 1039 float dy2 = clampTo<float>(fabs(point.y() - size.height())); |
1040 | 1040 |
1041 float dx = compare(dx1, dx2) ? dx1 : dx2; | 1041 float dx = compare(dx1, dx2) ? dx1 : dx2; |
1042 float dy = compare(dy1, dy2) ? dy1 : dy2; | 1042 float dy = compare(dy1, dy2) ? dy1 : dy2; |
1043 | 1043 |
1044 if (shape == CircleEndShape) | 1044 if (shape == CircleEndShape) |
1045 return compare(dx, dy) ? FloatSize(dx, dx) : FloatSize(dy, dy); | 1045 return compare(dx, dy) ? FloatSize(dx, dx) : FloatSize(dy, dy); |
1046 | 1046 |
1047 ASSERT(shape == EllipseEndShape); | 1047 ASSERT(shape == EllipseEndShape); |
1048 return FloatSize(dx, dy); | 1048 return FloatSize(dx, dy); |
1049 } | 1049 } |
1050 | 1050 |
1051 // Compute the radius of an ellipse with center at 0,0 which passes through p, a nd has | 1051 // Compute the radius of an ellipse with center at 0,0 which passes through p, a nd has |
1052 // width/height given by aspectRatio. | 1052 // width/height given by aspectRatio. |
1053 inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio) | 1053 inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio) |
1054 { | 1054 { |
1055 // x^2/a^2 + y^2/b^2 = 1 | 1055 // x^2/a^2 + y^2/b^2 = 1 |
1056 // a/b = aspectRatio, b = a/aspectRatio | 1056 // a/b = aspectRatio, b = a/aspectRatio |
1057 // a = sqrt(x^2 + y^2/(1/r^2)) | 1057 // a = sqrt(x^2 + y^2/(1/r^2)) |
1058 float a = sqrtf(p.x() * p.x() + p.y() * p.y() * aspectRatio * aspectRatio); | 1058 float a = clampTo<float>(sqrtf(p.x() * p.x() + p.y() * p.y() * aspectRatio * aspectRatio)); |
fs
2016/06/05 23:34:02
Could the division on the next line potentially pu
f(malita)
2016/06/06 13:13:10
Hrmpf, you're right. Updated to clamp both values
| |
1059 return FloatSize(a, a / aspectRatio); | 1059 return FloatSize(a, a / aspectRatio); |
1060 } | 1060 } |
1061 | 1061 |
1062 // Compute the radius to the closest/farthest corner (depending on the compare f unctor). | 1062 // Compute the radius to the closest/farthest corner (depending on the compare f unctor). |
1063 FloatSize radiusToCorner(const FloatPoint& point, const FloatSize& size, EndShap eType shape, | 1063 FloatSize radiusToCorner(const FloatPoint& point, const FloatSize& size, EndShap eType shape, |
1064 bool (*compare)(float, float)) | 1064 bool (*compare)(float, float)) |
1065 { | 1065 { |
1066 const FloatRect rect(FloatPoint(), size); | 1066 const FloatRect rect(FloatPoint(), size); |
1067 const FloatPoint corners[] = { | 1067 const FloatPoint corners[] = { |
1068 rect.minXMinYCorner(), | 1068 rect.minXMinYCorner(), |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 secondRadius = radiusToCorner(secondPoint, floatSize, shape, | 1146 secondRadius = radiusToCorner(secondPoint, floatSize, shape, |
1147 [] (float a, float b) { return a < b; }); | 1147 [] (float a, float b) { return a < b; }); |
1148 break; | 1148 break; |
1149 default: | 1149 default: |
1150 secondRadius = radiusToCorner(secondPoint, floatSize, shape, | 1150 secondRadius = radiusToCorner(secondPoint, floatSize, shape, |
1151 [] (float a, float b) { return a > b; }); | 1151 [] (float a, float b) { return a > b; }); |
1152 break; | 1152 break; |
1153 } | 1153 } |
1154 } | 1154 } |
1155 | 1155 |
1156 DCHECK(std::isfinite(firstRadius)); | |
1157 DCHECK(std::isfinite(secondRadius.width())); | |
1158 DCHECK(std::isfinite(secondRadius.height())); | |
1159 | |
1156 bool isDegenerate = !secondRadius.width() || !secondRadius.height(); | 1160 bool isDegenerate = !secondRadius.width() || !secondRadius.height(); |
1157 RefPtr<Gradient> gradient = Gradient::create(firstPoint, firstRadius, second Point, | 1161 RefPtr<Gradient> gradient = Gradient::create(firstPoint, firstRadius, second Point, |
1158 isDegenerate ? 0 : secondRadius.width(), isDegenerate ? 1 : secondRadius .aspectRatio()); | 1162 isDegenerate ? 0 : secondRadius.width(), isDegenerate ? 1 : secondRadius .aspectRatio()); |
1159 | 1163 |
1160 gradient->setSpreadMethod(m_repeating ? SpreadMethodRepeat : SpreadMethodPad ); | 1164 gradient->setSpreadMethod(m_repeating ? SpreadMethodRepeat : SpreadMethodPad ); |
1161 gradient->setDrawsInPMColorSpace(true); | 1165 gradient->setDrawsInPMColorSpace(true); |
1162 | 1166 |
1163 // Now add the stops. | 1167 // Now add the stops. |
1164 addStops(gradient.get(), conversionData, object); | 1168 addStops(gradient.get(), conversionData, object); |
1165 | 1169 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1217 visitor->trace(m_firstRadius); | 1221 visitor->trace(m_firstRadius); |
1218 visitor->trace(m_secondRadius); | 1222 visitor->trace(m_secondRadius); |
1219 visitor->trace(m_shape); | 1223 visitor->trace(m_shape); |
1220 visitor->trace(m_sizingBehavior); | 1224 visitor->trace(m_sizingBehavior); |
1221 visitor->trace(m_endHorizontalSize); | 1225 visitor->trace(m_endHorizontalSize); |
1222 visitor->trace(m_endVerticalSize); | 1226 visitor->trace(m_endVerticalSize); |
1223 CSSGradientValue::traceAfterDispatch(visitor); | 1227 CSSGradientValue::traceAfterDispatch(visitor); |
1224 } | 1228 } |
1225 | 1229 |
1226 } // namespace blink | 1230 } // namespace blink |
OLD | NEW |