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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 144 |
145 int indexOffset = 0; | 145 int indexOffset = 0; |
146 | 146 |
147 // The first and the last color stops cannot be color hints. | 147 // The first and the last color stops cannot be color hints. |
148 for (size_t i = 1; i < cssGradientStops.size() - 1; ++i) { | 148 for (size_t i = 1; i < cssGradientStops.size() - 1; ++i) { |
149 if (!cssGradientStops[i].isHint()) | 149 if (!cssGradientStops[i].isHint()) |
150 continue; | 150 continue; |
151 | 151 |
152 // The current index of the stops vector. | 152 // The current index of the stops vector. |
153 size_t x = i + indexOffset; | 153 size_t x = i + indexOffset; |
154 ASSERT(x >= 1); | 154 DCHECK(x >= |
155 1); ////DCHECK_GE giving error for const unsigned int and const int | |
Srirama
2017/03/16 14:22:23
remove this comment and add review comment.
| |
155 | 156 |
156 // offsetLeft offset offsetRight | 157 // offsetLeft offset offsetRight |
157 // |-------------------|---------------------------------| | 158 // |-------------------|---------------------------------| |
158 // leftDist rightDist | 159 // leftDist rightDist |
159 | 160 |
160 float offsetLeft = stops[x - 1].offset; | 161 float offsetLeft = stops[x - 1].offset; |
161 float offsetRight = stops[x + 1].offset; | 162 float offsetRight = stops[x + 1].offset; |
162 float offset = stops[x].offset; | 163 float offset = stops[x].offset; |
163 float leftDist = offset - offsetLeft; | 164 float leftDist = offset - offsetLeft; |
164 float rightDist = offsetRight - offset; | 165 float rightDist = offsetRight - offset; |
165 float totalDist = offsetRight - offsetLeft; | 166 float totalDist = offsetRight - offsetLeft; |
166 | 167 |
167 Color leftColor = stops[x - 1].color; | 168 Color leftColor = stops[x - 1].color; |
168 Color rightColor = stops[x + 1].color; | 169 Color rightColor = stops[x + 1].color; |
169 | 170 |
170 ASSERT(offsetLeft <= offset && offset <= offsetRight); | 171 DCHECK_LE(offsetLeft, offset); |
172 DCHECK_LE(offset, offsetRight); | |
171 | 173 |
172 if (WebCoreFloatNearlyEqual(leftDist, rightDist)) { | 174 if (WebCoreFloatNearlyEqual(leftDist, rightDist)) { |
173 stops.remove(x); | 175 stops.remove(x); |
174 --indexOffset; | 176 --indexOffset; |
175 continue; | 177 continue; |
176 } | 178 } |
177 | 179 |
178 if (WebCoreFloatNearlyEqual(leftDist, .0f)) { | 180 if (WebCoreFloatNearlyEqual(leftDist, .0f)) { |
179 stops[x].color = rightColor; | 181 stops[x].color = rightColor; |
180 continue; | 182 continue; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 } | 220 } |
219 | 221 |
220 static Color resolveStopColor(const CSSValue& stopColor, | 222 static Color resolveStopColor(const CSSValue& stopColor, |
221 const LayoutObject& object) { | 223 const LayoutObject& object) { |
222 return object.document().textLinkColors().colorFromCSSValue( | 224 return object.document().textLinkColors().colorFromCSSValue( |
223 stopColor, object.resolveColor(CSSPropertyColor)); | 225 stopColor, object.resolveColor(CSSPropertyColor)); |
224 } | 226 } |
225 | 227 |
226 void CSSGradientValue::addDeprecatedStops(Gradient* gradient, | 228 void CSSGradientValue::addDeprecatedStops(Gradient* gradient, |
227 const LayoutObject& object) { | 229 const LayoutObject& object) { |
228 ASSERT(m_gradientType == CSSDeprecatedLinearGradient || | 230 DCHECK(m_gradientType == CSSDeprecatedLinearGradient || |
229 m_gradientType == CSSDeprecatedRadialGradient); | 231 m_gradientType == CSSDeprecatedRadialGradient); |
230 | 232 |
231 if (!m_stopsSorted) { | 233 if (!m_stopsSorted) { |
232 if (m_stops.size()) | 234 if (m_stops.size()) |
233 std::stable_sort(m_stops.begin(), m_stops.end(), compareStops); | 235 std::stable_sort(m_stops.begin(), m_stops.end(), compareStops); |
234 m_stopsSorted = true; | 236 m_stopsSorted = true; |
235 } | 237 } |
236 | 238 |
237 for (const auto& stop : m_stops) { | 239 for (const auto& stop : m_stops) { |
238 float offset; | 240 float offset; |
(...skipping 21 matching lines...) Expand all Loading... | |
260 if (stops.front().offset < 0 || stops.back().offset > 1) | 262 if (stops.front().offset < 0 || stops.back().offset > 1) |
261 return true; | 263 return true; |
262 | 264 |
263 return false; | 265 return false; |
264 } | 266 } |
265 | 267 |
266 // Redistribute the stops such that they fully cover [0 , 1] and add them to the | 268 // Redistribute the stops such that they fully cover [0 , 1] and add them to the |
267 // gradient. | 269 // gradient. |
268 static bool normalizeAndAddStops(const Vector<GradientStop>& stops, | 270 static bool normalizeAndAddStops(const Vector<GradientStop>& stops, |
269 Gradient* gradient) { | 271 Gradient* gradient) { |
270 ASSERT(stops.size() > 1); | 272 DCHECK(stops.size() > |
273 1); ////DCHECK_GT giving error for const unsigned int and const int | |
Srirama
2017/03/16 14:22:24
ditto
| |
271 | 274 |
272 const float firstOffset = stops.front().offset; | 275 const float firstOffset = stops.front().offset; |
273 const float lastOffset = stops.back().offset; | 276 const float lastOffset = stops.back().offset; |
274 const float span = lastOffset - firstOffset; | 277 const float span = lastOffset - firstOffset; |
275 | 278 |
276 if (fabs(span) < std::numeric_limits<float>::epsilon()) { | 279 if (fabs(span) < std::numeric_limits<float>::epsilon()) { |
277 // All stops are coincident -> use a single clamped offset value. | 280 // All stops are coincident -> use a single clamped offset value. |
278 const float clampedOffset = std::min(std::max(firstOffset, 0.f), 1.f); | 281 const float clampedOffset = std::min(std::max(firstOffset, 0.f), 1.f); |
279 | 282 |
280 // For repeating gradients, a coincident stop set defines a solid-color | 283 // For repeating gradients, a coincident stop set defines a solid-color |
281 // image with the color of the last color-stop in the rule. | 284 // image with the color of the last color-stop in the rule. |
282 // For non-repeating gradients, both the first color and the last color can | 285 // For non-repeating gradients, both the first color and the last color can |
283 // be significant (padding on both sides of the offset). | 286 // be significant (padding on both sides of the offset). |
284 if (gradient->spreadMethod() != SpreadMethodRepeat) | 287 if (gradient->spreadMethod() != SpreadMethodRepeat) |
285 gradient->addColorStop(clampedOffset, stops.front().color); | 288 gradient->addColorStop(clampedOffset, stops.front().color); |
286 gradient->addColorStop(clampedOffset, stops.back().color); | 289 gradient->addColorStop(clampedOffset, stops.back().color); |
287 | 290 |
288 return false; | 291 return false; |
289 } | 292 } |
290 | 293 |
291 ASSERT(span > 0); | 294 DCHECK_GT(span, 0); |
292 | 295 |
293 for (size_t i = 0; i < stops.size(); ++i) { | 296 for (size_t i = 0; i < stops.size(); ++i) { |
294 const float normalizedOffset = (stops[i].offset - firstOffset) / span; | 297 const float normalizedOffset = (stops[i].offset - firstOffset) / span; |
295 | 298 |
296 // stop offsets should be monotonically increasing in [0 , 1] | 299 // stop offsets should be monotonically increasing in [0 , 1] |
297 ASSERT(normalizedOffset >= 0 && normalizedOffset <= 1); | 300 DCHECK_GE(normalizedOffset, 0); |
298 ASSERT(i == 0 || | 301 DCHECK_LE(normalizedOffset, 1); |
302 DCHECK(i == 0 || | |
299 normalizedOffset >= (stops[i - 1].offset - firstOffset) / span); | 303 normalizedOffset >= (stops[i - 1].offset - firstOffset) / span); |
300 | 304 |
301 gradient->addColorStop(normalizedOffset, stops[i].color); | 305 gradient->addColorStop(normalizedOffset, stops[i].color); |
302 } | 306 } |
303 | 307 |
304 return true; | 308 return true; |
305 } | 309 } |
306 | 310 |
307 // Collapse all negative-offset stops to 0 and compute an interpolated color | 311 // Collapse all negative-offset stops to 0 and compute an interpolated color |
308 // value for that point. | 312 // value for that point. |
309 static void clampNegativeOffsets(Vector<GradientStop>& stops) { | 313 static void clampNegativeOffsets(Vector<GradientStop>& stops) { |
310 float lastNegativeOffset = 0; | 314 float lastNegativeOffset = 0; |
311 | 315 |
312 for (size_t i = 0; i < stops.size(); ++i) { | 316 for (size_t i = 0; i < stops.size(); ++i) { |
313 const float currentOffset = stops[i].offset; | 317 const float currentOffset = stops[i].offset; |
314 if (currentOffset >= 0) { | 318 if (currentOffset >= 0) { |
315 if (i > 0) { | 319 if (i > 0) { |
316 // We found the negative -> positive offset transition: compute an | 320 // We found the negative -> positive offset transition: compute an |
317 // interpolated color value for 0 and use it with the last clamped stop. | 321 // interpolated color value for 0 and use it with the last clamped stop. |
318 ASSERT(lastNegativeOffset < 0); | 322 DCHECK_LT(lastNegativeOffset, 0); |
319 float lerpRatio = | 323 float lerpRatio = |
320 -lastNegativeOffset / (currentOffset - lastNegativeOffset); | 324 -lastNegativeOffset / (currentOffset - lastNegativeOffset); |
321 stops[i - 1].color = | 325 stops[i - 1].color = |
322 blend(stops[i - 1].color, stops[i].color, lerpRatio); | 326 blend(stops[i - 1].color, stops[i].color, lerpRatio); |
323 } | 327 } |
324 | 328 |
325 break; | 329 break; |
326 } | 330 } |
327 | 331 |
328 // Clamp all negative stops to 0. | 332 // Clamp all negative stops to 0. |
329 stops[i].offset = 0; | 333 stops[i].offset = 0; |
330 lastNegativeOffset = currentOffset; | 334 lastNegativeOffset = currentOffset; |
331 } | 335 } |
332 } | 336 } |
333 | 337 |
334 // Update the linear gradient points to align with the given offset range. | 338 // Update the linear gradient points to align with the given offset range. |
335 static void adjustGradientPointsForOffsetRange(Gradient* gradient, | 339 static void adjustGradientPointsForOffsetRange(Gradient* gradient, |
336 float firstOffset, | 340 float firstOffset, |
337 float lastOffset) { | 341 float lastOffset) { |
338 ASSERT(!gradient->isRadial()); | 342 DCHECK(!gradient->isRadial()); |
339 ASSERT(firstOffset <= lastOffset); | 343 DCHECK(firstOffset <= lastOffset); |
340 | 344 |
341 const FloatPoint p0 = gradient->p0(); | 345 const FloatPoint p0 = gradient->p0(); |
342 const FloatPoint p1 = gradient->p1(); | 346 const FloatPoint p1 = gradient->p1(); |
343 const FloatSize d(p1 - p0); | 347 const FloatSize d(p1 - p0); |
344 | 348 |
345 // Linear offsets are relative to the [p0 , p1] segment. | 349 // Linear offsets are relative to the [p0 , p1] segment. |
346 gradient->setP0(p0 + d * firstOffset); | 350 gradient->setP0(p0 + d * firstOffset); |
347 gradient->setP1(p0 + d * lastOffset); | 351 gradient->setP1(p0 + d * lastOffset); |
348 } | 352 } |
349 | 353 |
350 // Update the radial gradient radii to align with the given offset range. | 354 // Update the radial gradient radii to align with the given offset range. |
351 static void adjustGradientRadiiForOffsetRange(Gradient* gradient, | 355 static void adjustGradientRadiiForOffsetRange(Gradient* gradient, |
352 float firstOffset, | 356 float firstOffset, |
353 float lastOffset) { | 357 float lastOffset) { |
354 ASSERT(gradient->isRadial()); | 358 DCHECK(gradient->isRadial()); |
355 ASSERT(firstOffset <= lastOffset); | 359 DCHECK_LE(firstOffset, lastOffset); |
356 | 360 |
357 // Radial offsets are relative to the [0 , endRadius] segment. | 361 // Radial offsets are relative to the [0 , endRadius] segment. |
358 float adjustedR0 = gradient->endRadius() * firstOffset; | 362 float adjustedR0 = gradient->endRadius() * firstOffset; |
359 float adjustedR1 = gradient->endRadius() * lastOffset; | 363 float adjustedR1 = gradient->endRadius() * lastOffset; |
360 ASSERT(adjustedR0 <= adjustedR1); | 364 DCHECK_LE(adjustedR0, adjustedR1); |
361 | 365 |
362 // Unlike linear gradients (where we can adjust the points arbitrarily), | 366 // Unlike linear gradients (where we can adjust the points arbitrarily), |
363 // we cannot let our radii turn negative here. | 367 // we cannot let our radii turn negative here. |
364 if (adjustedR0 < 0) { | 368 if (adjustedR0 < 0) { |
365 // For the non-repeat case, this can never happen: clampNegativeOffsets() | 369 // For the non-repeat case, this can never happen: clampNegativeOffsets() |
366 // ensures we don't have to deal with negative offsets at this point. | 370 // ensures we don't have to deal with negative offsets at this point. |
367 ASSERT(gradient->spreadMethod() == SpreadMethodRepeat); | 371 DCHECK_EQ(gradient->spreadMethod(), SpreadMethodRepeat); |
368 | 372 |
369 // When in repeat mode, we deal with it by repositioning both radii in the | 373 // When in repeat mode, we deal with it by repositioning both radii in the |
370 // positive domain - shifting them by a multiple of the radius span (which | 374 // positive domain - shifting them by a multiple of the radius span (which |
371 // is the period of our repeating gradient -> hence no visible side | 375 // is the period of our repeating gradient -> hence no visible side |
372 // effects). | 376 // effects). |
373 const float radiusSpan = adjustedR1 - adjustedR0; | 377 const float radiusSpan = adjustedR1 - adjustedR0; |
374 const float shiftToPositive = radiusSpan * ceilf(-adjustedR0 / radiusSpan); | 378 const float shiftToPositive = radiusSpan * ceilf(-adjustedR0 / radiusSpan); |
375 adjustedR0 += shiftToPositive; | 379 adjustedR0 += shiftToPositive; |
376 adjustedR1 += shiftToPositive; | 380 adjustedR1 += shiftToPositive; |
377 } | 381 } |
378 ASSERT(adjustedR0 >= 0); | 382 DCHECK_GE(adjustedR0, 0); |
379 ASSERT(adjustedR1 >= adjustedR0); | 383 DCHECK_GE(adjustedR1, adjustedR0); |
380 | 384 |
381 gradient->setStartRadius(adjustedR0); | 385 gradient->setStartRadius(adjustedR0); |
382 gradient->setEndRadius(adjustedR1); | 386 gradient->setEndRadius(adjustedR1); |
383 } | 387 } |
384 | 388 |
385 void CSSGradientValue::addStops(Gradient* gradient, | 389 void CSSGradientValue::addStops(Gradient* gradient, |
386 const CSSToLengthConversionData& conversionData, | 390 const CSSToLengthConversionData& conversionData, |
387 const LayoutObject& object) { | 391 const LayoutObject& object) { |
388 if (m_gradientType == CSSDeprecatedLinearGradient || | 392 if (m_gradientType == CSSDeprecatedLinearGradient || |
389 m_gradientType == CSSDeprecatedRadialGradient) { | 393 m_gradientType == CSSDeprecatedRadialGradient) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 stop.m_position->isCalculatedPercentageWithLength()) { | 425 stop.m_position->isCalculatedPercentageWithLength()) { |
422 float length; | 426 float length; |
423 if (stop.m_position->isLength()) | 427 if (stop.m_position->isLength()) |
424 length = stop.m_position->computeLength<float>(conversionData); | 428 length = stop.m_position->computeLength<float>(conversionData); |
425 else | 429 else |
426 length = stop.m_position->cssCalcValue() | 430 length = stop.m_position->cssCalcValue() |
427 ->toCalcValue(conversionData) | 431 ->toCalcValue(conversionData) |
428 ->evaluate(gradientLength); | 432 ->evaluate(gradientLength); |
429 stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0; | 433 stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0; |
430 } else { | 434 } else { |
431 ASSERT_NOT_REACHED(); | 435 NOTREACHED(); |
432 stops[i].offset = 0; | 436 stops[i].offset = 0; |
433 } | 437 } |
434 stops[i].specified = true; | 438 stops[i].specified = true; |
435 } else { | 439 } else { |
436 // If the first color-stop does not have a position, its position defaults | 440 // If the first color-stop does not have a position, its position defaults |
437 // to 0%. If the last color-stop does not have a position, its position | 441 // to 0%. If the last color-stop does not have a position, its position |
438 // defaults to 100%. | 442 // defaults to 100%. |
439 if (!i) { | 443 if (!i) { |
440 stops[i].offset = 0; | 444 stops[i].offset = 0; |
441 stops[i].specified = true; | 445 stops[i].specified = true; |
(...skipping 12 matching lines...) Expand all Loading... | |
454 --prevSpecifiedIndex) { | 458 --prevSpecifiedIndex) { |
455 if (stops[prevSpecifiedIndex].specified) | 459 if (stops[prevSpecifiedIndex].specified) |
456 break; | 460 break; |
457 } | 461 } |
458 | 462 |
459 if (stops[i].offset < stops[prevSpecifiedIndex].offset) | 463 if (stops[i].offset < stops[prevSpecifiedIndex].offset) |
460 stops[i].offset = stops[prevSpecifiedIndex].offset; | 464 stops[i].offset = stops[prevSpecifiedIndex].offset; |
461 } | 465 } |
462 } | 466 } |
463 | 467 |
464 ASSERT(stops.front().specified && stops.back().specified); | 468 DCHECK(stops.front().specified); |
469 DCHECK(stops.back().specified); | |
465 | 470 |
466 // If any color-stop still does not have a position, then, for each run of | 471 // If any color-stop still does not have a position, then, for each run of |
467 // adjacent color-stops without positions, set their positions so that they | 472 // adjacent color-stops without positions, set their positions so that they |
468 // are evenly spaced between the preceding and following color-stops with | 473 // are evenly spaced between the preceding and following color-stops with |
469 // positions. | 474 // positions. |
470 if (numStops > 2) { | 475 if (numStops > 2) { |
471 size_t unspecifiedRunStart = 0; | 476 size_t unspecifiedRunStart = 0; |
472 bool inUnspecifiedRun = false; | 477 bool inUnspecifiedRun = false; |
473 | 478 |
474 for (size_t i = 0; i < numStops; ++i) { | 479 for (size_t i = 0; i < numStops; ++i) { |
(...skipping 12 matching lines...) Expand all Loading... | |
487 for (size_t j = unspecifiedRunStart; j < unspecifiedRunEnd; ++j) | 492 for (size_t j = unspecifiedRunStart; j < unspecifiedRunEnd; ++j) |
488 stops[j].offset = | 493 stops[j].offset = |
489 lastSpecifiedOffset + (j - unspecifiedRunStart + 1) * delta; | 494 lastSpecifiedOffset + (j - unspecifiedRunStart + 1) * delta; |
490 } | 495 } |
491 | 496 |
492 inUnspecifiedRun = false; | 497 inUnspecifiedRun = false; |
493 } | 498 } |
494 } | 499 } |
495 } | 500 } |
496 | 501 |
497 ASSERT(stops.size() == m_stops.size()); | 502 DCHECK_EQ(stops.size(), m_stops.size()); |
498 if (hasHints) { | 503 if (hasHints) { |
499 replaceColorHintsWithColorStops(stops, m_stops); | 504 replaceColorHintsWithColorStops(stops, m_stops); |
500 } | 505 } |
501 | 506 |
502 // At this point we have a fully resolved set of stops. Time to perform | 507 // At this point we have a fully resolved set of stops. Time to perform |
503 // adjustments for repeat gradients and degenerate values if needed. | 508 // adjustments for repeat gradients and degenerate values if needed. |
504 if (requiresStopsNormalization(stops, gradient)) { | 509 if (requiresStopsNormalization(stops, gradient)) { |
505 // Negative offsets are only an issue for non-repeating radial gradients: | 510 // Negative offsets are only an issue for non-repeating radial gradients: |
506 // linear gradient points can be repositioned arbitrarily, and for repeating | 511 // linear gradient points can be repositioned arbitrarily, and for repeating |
507 // radial gradients we shift the radii into equivalent positive values. | 512 // radial gradients we shift the radii into equivalent positive values. |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
809 // moved origin and the fact that we're in drawing space (+y = down). | 814 // moved origin and the fact that we're in drawing space (+y = down). |
810 secondPoint.set(halfWidth + endX, halfHeight - endY); | 815 secondPoint.set(halfWidth + endX, halfHeight - endY); |
811 // Reflect around the center for the start point. | 816 // Reflect around the center for the start point. |
812 firstPoint.set(halfWidth - endX, halfHeight + endY); | 817 firstPoint.set(halfWidth - endX, halfHeight + endY); |
813 } | 818 } |
814 | 819 |
815 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient( | 820 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient( |
816 const CSSToLengthConversionData& conversionData, | 821 const CSSToLengthConversionData& conversionData, |
817 const IntSize& size, | 822 const IntSize& size, |
818 const LayoutObject& object) { | 823 const LayoutObject& object) { |
819 ASSERT(!size.isEmpty()); | 824 DCHECK(!size.isEmpty()); |
820 | 825 |
821 FloatPoint firstPoint; | 826 FloatPoint firstPoint; |
822 FloatPoint secondPoint; | 827 FloatPoint secondPoint; |
823 if (m_angle) { | 828 if (m_angle) { |
824 float angle = m_angle->computeDegrees(); | 829 float angle = m_angle->computeDegrees(); |
825 endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType); | 830 endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType); |
826 } else { | 831 } else { |
827 switch (m_gradientType) { | 832 switch (m_gradientType) { |
828 case CSSDeprecatedLinearGradient: | 833 case CSSDeprecatedLinearGradient: |
829 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), | 834 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), | 872 secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), |
868 conversionData, size); | 873 conversionData, size); |
869 if (m_firstX) | 874 if (m_firstX) |
870 firstPoint.setX(size.width() - secondPoint.x()); | 875 firstPoint.setX(size.width() - secondPoint.x()); |
871 if (m_firstY) | 876 if (m_firstY) |
872 firstPoint.setY(size.height() - secondPoint.y()); | 877 firstPoint.setY(size.height() - secondPoint.y()); |
873 } else | 878 } else |
874 secondPoint.setY(size.height()); | 879 secondPoint.setY(size.height()); |
875 break; | 880 break; |
876 default: | 881 default: |
877 ASSERT_NOT_REACHED(); | 882 NOTREACHED(); |
878 } | 883 } |
879 } | 884 } |
880 | 885 |
881 RefPtr<Gradient> gradient = Gradient::create(firstPoint, secondPoint); | 886 RefPtr<Gradient> gradient = Gradient::create(firstPoint, secondPoint); |
882 | 887 |
883 gradient->setSpreadMethod(m_repeating ? SpreadMethodRepeat : SpreadMethodPad); | 888 gradient->setSpreadMethod(m_repeating ? SpreadMethodRepeat : SpreadMethodPad); |
884 gradient->setDrawsInPMColorSpace(true); | 889 gradient->setDrawsInPMColorSpace(true); |
885 | 890 |
886 // Now add the stops. | 891 // Now add the stops. |
887 addStops(gradient.get(), conversionData, object); | 892 addStops(gradient.get(), conversionData, object); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1111 float dy1 = clampTo<float>(fabs(point.y())); | 1116 float dy1 = clampTo<float>(fabs(point.y())); |
1112 float dx2 = clampTo<float>(fabs(point.x() - size.width())); | 1117 float dx2 = clampTo<float>(fabs(point.x() - size.width())); |
1113 float dy2 = clampTo<float>(fabs(point.y() - size.height())); | 1118 float dy2 = clampTo<float>(fabs(point.y() - size.height())); |
1114 | 1119 |
1115 float dx = compare(dx1, dx2) ? dx1 : dx2; | 1120 float dx = compare(dx1, dx2) ? dx1 : dx2; |
1116 float dy = compare(dy1, dy2) ? dy1 : dy2; | 1121 float dy = compare(dy1, dy2) ? dy1 : dy2; |
1117 | 1122 |
1118 if (shape == CircleEndShape) | 1123 if (shape == CircleEndShape) |
1119 return compare(dx, dy) ? FloatSize(dx, dx) : FloatSize(dy, dy); | 1124 return compare(dx, dy) ? FloatSize(dx, dx) : FloatSize(dy, dy); |
1120 | 1125 |
1121 ASSERT(shape == EllipseEndShape); | 1126 DCHECK_EQ(shape, EllipseEndShape); |
1122 return FloatSize(dx, dy); | 1127 return FloatSize(dx, dy); |
1123 } | 1128 } |
1124 | 1129 |
1125 // Compute the radius of an ellipse with center at 0,0 which passes through p, | 1130 // Compute the radius of an ellipse with center at 0,0 which passes through p, |
1126 // and has width/height given by aspectRatio. | 1131 // and has width/height given by aspectRatio. |
1127 inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio) { | 1132 inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio) { |
1128 // If the aspectRatio is 0 or infinite, the ellipse is completely flat. | 1133 // If the aspectRatio is 0 or infinite, the ellipse is completely flat. |
1129 // TODO(sashab): Implement Degenerate Radial Gradients, see crbug.com/635727. | 1134 // TODO(sashab): Implement Degenerate Radial Gradients, see crbug.com/635727. |
1130 if (aspectRatio == 0 || std::isinf(aspectRatio)) | 1135 if (aspectRatio == 0 || std::isinf(aspectRatio)) |
1131 return FloatSize(0, 0); | 1136 return FloatSize(0, 0); |
(...skipping 21 matching lines...) Expand all Loading... | |
1153 float newDistance = (point - corners[i]).diagonalLength(); | 1158 float newDistance = (point - corners[i]).diagonalLength(); |
1154 if (compare(newDistance, distance)) { | 1159 if (compare(newDistance, distance)) { |
1155 cornerIndex = i; | 1160 cornerIndex = i; |
1156 distance = newDistance; | 1161 distance = newDistance; |
1157 } | 1162 } |
1158 } | 1163 } |
1159 | 1164 |
1160 if (shape == CircleEndShape) | 1165 if (shape == CircleEndShape) |
1161 return FloatSize(distance, distance); | 1166 return FloatSize(distance, distance); |
1162 | 1167 |
1163 ASSERT(shape == EllipseEndShape); | 1168 DCHECK_EQ(shape, EllipseEndShape); |
1164 // If the end shape is an ellipse, the gradient-shape has the same ratio of | 1169 // If the end shape is an ellipse, the gradient-shape has the same ratio of |
1165 // width to height that it would if closest-side or farthest-side were | 1170 // width to height that it would if closest-side or farthest-side were |
1166 // specified, as appropriate. | 1171 // specified, as appropriate. |
1167 const FloatSize sideRadius = | 1172 const FloatSize sideRadius = |
1168 radiusToSide(point, size, EllipseEndShape, compare); | 1173 radiusToSide(point, size, EllipseEndShape, compare); |
1169 | 1174 |
1170 return ellipseRadius(FloatPoint(corners[cornerIndex] - point), | 1175 return ellipseRadius(FloatPoint(corners[cornerIndex] - point), |
1171 sideRadius.aspectRatio()); | 1176 sideRadius.aspectRatio()); |
1172 } | 1177 } |
1173 | 1178 |
1174 } // anonymous namespace | 1179 } // anonymous namespace |
1175 | 1180 |
1176 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient( | 1181 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient( |
1177 const CSSToLengthConversionData& conversionData, | 1182 const CSSToLengthConversionData& conversionData, |
1178 const IntSize& size, | 1183 const IntSize& size, |
1179 const LayoutObject& object) { | 1184 const LayoutObject& object) { |
1180 ASSERT(!size.isEmpty()); | 1185 DCHECK(!size.isEmpty()); |
1181 | 1186 |
1182 FloatPoint firstPoint = | 1187 FloatPoint firstPoint = |
1183 computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); | 1188 computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); |
1184 if (!m_firstX) | 1189 if (!m_firstX) |
1185 firstPoint.setX(size.width() / 2); | 1190 firstPoint.setX(size.width() / 2); |
1186 if (!m_firstY) | 1191 if (!m_firstY) |
1187 firstPoint.setY(size.height() / 2); | 1192 firstPoint.setY(size.height() / 2); |
1188 | 1193 |
1189 FloatPoint secondPoint = | 1194 FloatPoint secondPoint = |
1190 computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size); | 1195 computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 visitor->trace(m_firstRadius); | 1319 visitor->trace(m_firstRadius); |
1315 visitor->trace(m_secondRadius); | 1320 visitor->trace(m_secondRadius); |
1316 visitor->trace(m_shape); | 1321 visitor->trace(m_shape); |
1317 visitor->trace(m_sizingBehavior); | 1322 visitor->trace(m_sizingBehavior); |
1318 visitor->trace(m_endHorizontalSize); | 1323 visitor->trace(m_endHorizontalSize); |
1319 visitor->trace(m_endVerticalSize); | 1324 visitor->trace(m_endVerticalSize); |
1320 CSSGradientValue::traceAfterDispatch(visitor); | 1325 CSSGradientValue::traceAfterDispatch(visitor); |
1321 } | 1326 } |
1322 | 1327 |
1323 } // namespace blink | 1328 } // namespace blink |
OLD | NEW |