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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 int indexOffset = 0; | 208 int indexOffset = 0; |
209 | 209 |
210 // The first and the last color stops cannot be color hints. | 210 // The first and the last color stops cannot be color hints. |
211 for (size_t i = 1; i < cssGradientStops.size() - 1; ++i) { | 211 for (size_t i = 1; i < cssGradientStops.size() - 1; ++i) { |
212 if (!cssGradientStops[i].isHint()) | 212 if (!cssGradientStops[i].isHint()) |
213 continue; | 213 continue; |
214 | 214 |
215 // The current index of the stops vector. | 215 // The current index of the stops vector. |
216 size_t x = i + indexOffset; | 216 size_t x = i + indexOffset; |
217 ASSERT(x >= 1); | 217 DCHECK_GE(x, 1u); |
218 | 218 |
219 // offsetLeft offset offsetRight | 219 // offsetLeft offset offsetRight |
220 // |-------------------|---------------------------------| | 220 // |-------------------|---------------------------------| |
221 // leftDist rightDist | 221 // leftDist rightDist |
222 | 222 |
223 float offsetLeft = stops[x - 1].offset; | 223 float offsetLeft = stops[x - 1].offset; |
224 float offsetRight = stops[x + 1].offset; | 224 float offsetRight = stops[x + 1].offset; |
225 float offset = stops[x].offset; | 225 float offset = stops[x].offset; |
226 float leftDist = offset - offsetLeft; | 226 float leftDist = offset - offsetLeft; |
227 float rightDist = offsetRight - offset; | 227 float rightDist = offsetRight - offset; |
228 float totalDist = offsetRight - offsetLeft; | 228 float totalDist = offsetRight - offsetLeft; |
229 | 229 |
230 Color leftColor = stops[x - 1].color; | 230 Color leftColor = stops[x - 1].color; |
231 Color rightColor = stops[x + 1].color; | 231 Color rightColor = stops[x + 1].color; |
232 | 232 |
233 ASSERT(offsetLeft <= offset && offset <= offsetRight); | 233 DCHECK_LE(offsetLeft, offset); |
| 234 DCHECK_LE(offset, offsetRight); |
234 | 235 |
235 if (WebCoreFloatNearlyEqual(leftDist, rightDist)) { | 236 if (WebCoreFloatNearlyEqual(leftDist, rightDist)) { |
236 stops.erase(x); | 237 stops.erase(x); |
237 --indexOffset; | 238 --indexOffset; |
238 continue; | 239 continue; |
239 } | 240 } |
240 | 241 |
241 if (WebCoreFloatNearlyEqual(leftDist, .0f)) { | 242 if (WebCoreFloatNearlyEqual(leftDist, .0f)) { |
242 stops[x].color = rightColor; | 243 stops[x].color = rightColor; |
243 continue; | 244 continue; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 282 } |
282 | 283 |
283 static Color resolveStopColor(const CSSValue& stopColor, | 284 static Color resolveStopColor(const CSSValue& stopColor, |
284 const LayoutObject& object) { | 285 const LayoutObject& object) { |
285 return object.document().textLinkColors().colorFromCSSValue( | 286 return object.document().textLinkColors().colorFromCSSValue( |
286 stopColor, object.resolveColor(CSSPropertyColor)); | 287 stopColor, object.resolveColor(CSSPropertyColor)); |
287 } | 288 } |
288 | 289 |
289 void CSSGradientValue::addDeprecatedStops(GradientDesc& desc, | 290 void CSSGradientValue::addDeprecatedStops(GradientDesc& desc, |
290 const LayoutObject& object) { | 291 const LayoutObject& object) { |
291 ASSERT(m_gradientType == CSSDeprecatedLinearGradient || | 292 DCHECK(m_gradientType == CSSDeprecatedLinearGradient || |
292 m_gradientType == CSSDeprecatedRadialGradient); | 293 m_gradientType == CSSDeprecatedRadialGradient); |
293 | 294 |
294 if (!m_stopsSorted) { | 295 if (!m_stopsSorted) { |
295 if (m_stops.size()) | 296 if (m_stops.size()) |
296 std::stable_sort(m_stops.begin(), m_stops.end(), compareStops); | 297 std::stable_sort(m_stops.begin(), m_stops.end(), compareStops); |
297 m_stopsSorted = true; | 298 m_stopsSorted = true; |
298 } | 299 } |
299 | 300 |
300 for (const auto& stop : m_stops) { | 301 for (const auto& stop : m_stops) { |
301 float offset; | 302 float offset; |
(...skipping 21 matching lines...) Expand all Loading... |
323 if (stops.front().offset < 0 || stops.back().offset > 1) | 324 if (stops.front().offset < 0 || stops.back().offset > 1) |
324 return true; | 325 return true; |
325 | 326 |
326 return false; | 327 return false; |
327 } | 328 } |
328 | 329 |
329 // Redistribute the stops such that they fully cover [0 , 1] and add them to the | 330 // Redistribute the stops such that they fully cover [0 , 1] and add them to the |
330 // gradient. | 331 // gradient. |
331 static bool normalizeAndAddStops(const Vector<GradientStop>& stops, | 332 static bool normalizeAndAddStops(const Vector<GradientStop>& stops, |
332 CSSGradientValue::GradientDesc& desc) { | 333 CSSGradientValue::GradientDesc& desc) { |
333 ASSERT(stops.size() > 1); | 334 DCHECK_GT(stops.size(), 1u); |
334 | 335 |
335 const float firstOffset = stops.front().offset; | 336 const float firstOffset = stops.front().offset; |
336 const float lastOffset = stops.back().offset; | 337 const float lastOffset = stops.back().offset; |
337 const float span = lastOffset - firstOffset; | 338 const float span = lastOffset - firstOffset; |
338 | 339 |
339 if (fabs(span) < std::numeric_limits<float>::epsilon()) { | 340 if (fabs(span) < std::numeric_limits<float>::epsilon()) { |
340 // All stops are coincident -> use a single clamped offset value. | 341 // All stops are coincident -> use a single clamped offset value. |
341 const float clampedOffset = std::min(std::max(firstOffset, 0.f), 1.f); | 342 const float clampedOffset = std::min(std::max(firstOffset, 0.f), 1.f); |
342 | 343 |
343 // For repeating gradients, a coincident stop set defines a solid-color | 344 // For repeating gradients, a coincident stop set defines a solid-color |
344 // image with the color of the last color-stop in the rule. | 345 // image with the color of the last color-stop in the rule. |
345 // For non-repeating gradients, both the first color and the last color can | 346 // For non-repeating gradients, both the first color and the last color can |
346 // be significant (padding on both sides of the offset). | 347 // be significant (padding on both sides of the offset). |
347 if (desc.spreadMethod != SpreadMethodRepeat) | 348 if (desc.spreadMethod != SpreadMethodRepeat) |
348 desc.stops.emplace_back(clampedOffset, stops.front().color); | 349 desc.stops.emplace_back(clampedOffset, stops.front().color); |
349 desc.stops.emplace_back(clampedOffset, stops.back().color); | 350 desc.stops.emplace_back(clampedOffset, stops.back().color); |
350 | 351 |
351 return false; | 352 return false; |
352 } | 353 } |
353 | 354 |
354 ASSERT(span > 0); | 355 DCHECK_GT(span, 0); |
355 | 356 |
356 for (size_t i = 0; i < stops.size(); ++i) { | 357 for (size_t i = 0; i < stops.size(); ++i) { |
357 const float normalizedOffset = (stops[i].offset - firstOffset) / span; | 358 const float normalizedOffset = (stops[i].offset - firstOffset) / span; |
358 | 359 |
359 // stop offsets should be monotonically increasing in [0 , 1] | 360 // stop offsets should be monotonically increasing in [0 , 1] |
360 ASSERT(normalizedOffset >= 0 && normalizedOffset <= 1); | 361 DCHECK_GE(normalizedOffset, 0); |
361 ASSERT(i == 0 || | 362 DCHECK_LE(normalizedOffset, 1); |
| 363 DCHECK(i == 0 || |
362 normalizedOffset >= (stops[i - 1].offset - firstOffset) / span); | 364 normalizedOffset >= (stops[i - 1].offset - firstOffset) / span); |
363 | 365 |
364 desc.stops.emplace_back(normalizedOffset, stops[i].color); | 366 desc.stops.emplace_back(normalizedOffset, stops[i].color); |
365 } | 367 } |
366 | 368 |
367 return true; | 369 return true; |
368 } | 370 } |
369 | 371 |
370 // Collapse all negative-offset stops to 0 and compute an interpolated color | 372 // Collapse all negative-offset stops to 0 and compute an interpolated color |
371 // value for that point. | 373 // value for that point. |
372 static void clampNegativeOffsets(Vector<GradientStop>& stops) { | 374 static void clampNegativeOffsets(Vector<GradientStop>& stops) { |
373 float lastNegativeOffset = 0; | 375 float lastNegativeOffset = 0; |
374 | 376 |
375 for (size_t i = 0; i < stops.size(); ++i) { | 377 for (size_t i = 0; i < stops.size(); ++i) { |
376 const float currentOffset = stops[i].offset; | 378 const float currentOffset = stops[i].offset; |
377 if (currentOffset >= 0) { | 379 if (currentOffset >= 0) { |
378 if (i > 0) { | 380 if (i > 0) { |
379 // We found the negative -> positive offset transition: compute an | 381 // We found the negative -> positive offset transition: compute an |
380 // interpolated color value for 0 and use it with the last clamped stop. | 382 // interpolated color value for 0 and use it with the last clamped stop. |
381 ASSERT(lastNegativeOffset < 0); | 383 DCHECK_LT(lastNegativeOffset, 0); |
382 float lerpRatio = | 384 float lerpRatio = |
383 -lastNegativeOffset / (currentOffset - lastNegativeOffset); | 385 -lastNegativeOffset / (currentOffset - lastNegativeOffset); |
384 stops[i - 1].color = | 386 stops[i - 1].color = |
385 blend(stops[i - 1].color, stops[i].color, lerpRatio); | 387 blend(stops[i - 1].color, stops[i].color, lerpRatio); |
386 } | 388 } |
387 | 389 |
388 break; | 390 break; |
389 } | 391 } |
390 | 392 |
391 // Clamp all negative stops to 0. | 393 // Clamp all negative stops to 0. |
392 stops[i].offset = 0; | 394 stops[i].offset = 0; |
393 lastNegativeOffset = currentOffset; | 395 lastNegativeOffset = currentOffset; |
394 } | 396 } |
395 } | 397 } |
396 | 398 |
397 // Update the linear gradient points to align with the given offset range. | 399 // Update the linear gradient points to align with the given offset range. |
398 static void adjustGradientPointsForOffsetRange( | 400 static void adjustGradientPointsForOffsetRange( |
399 CSSGradientValue::GradientDesc& desc, | 401 CSSGradientValue::GradientDesc& desc, |
400 float firstOffset, | 402 float firstOffset, |
401 float lastOffset) { | 403 float lastOffset) { |
402 ASSERT(firstOffset <= lastOffset); | 404 DCHECK_LE(firstOffset, lastOffset); |
403 | 405 |
404 const FloatPoint p0 = desc.p0; | 406 const FloatPoint p0 = desc.p0; |
405 const FloatPoint p1 = desc.p1; | 407 const FloatPoint p1 = desc.p1; |
406 const FloatSize d(p1 - p0); | 408 const FloatSize d(p1 - p0); |
407 | 409 |
408 // Linear offsets are relative to the [p0 , p1] segment. | 410 // Linear offsets are relative to the [p0 , p1] segment. |
409 desc.p0 = p0 + d * firstOffset; | 411 desc.p0 = p0 + d * firstOffset; |
410 desc.p1 = p0 + d * lastOffset; | 412 desc.p1 = p0 + d * lastOffset; |
411 } | 413 } |
412 | 414 |
413 // Update the radial gradient radii to align with the given offset range. | 415 // Update the radial gradient radii to align with the given offset range. |
414 static void adjustGradientRadiiForOffsetRange( | 416 static void adjustGradientRadiiForOffsetRange( |
415 CSSGradientValue::GradientDesc& desc, | 417 CSSGradientValue::GradientDesc& desc, |
416 float firstOffset, | 418 float firstOffset, |
417 float lastOffset) { | 419 float lastOffset) { |
418 ASSERT(firstOffset <= lastOffset); | 420 DCHECK_LE(firstOffset, lastOffset); |
419 | 421 |
420 // Radial offsets are relative to the [0 , endRadius] segment. | 422 // Radial offsets are relative to the [0 , endRadius] segment. |
421 float adjustedR0 = desc.r1 * firstOffset; | 423 float adjustedR0 = desc.r1 * firstOffset; |
422 float adjustedR1 = desc.r1 * lastOffset; | 424 float adjustedR1 = desc.r1 * lastOffset; |
423 ASSERT(adjustedR0 <= adjustedR1); | 425 DCHECK_LE(adjustedR0, adjustedR1); |
424 | |
425 // Unlike linear gradients (where we can adjust the points arbitrarily), | 426 // Unlike linear gradients (where we can adjust the points arbitrarily), |
426 // we cannot let our radii turn negative here. | 427 // we cannot let our radii turn negative here. |
427 if (adjustedR0 < 0) { | 428 if (adjustedR0 < 0) { |
428 // For the non-repeat case, this can never happen: clampNegativeOffsets() | 429 // For the non-repeat case, this can never happen: clampNegativeOffsets() |
429 // ensures we don't have to deal with negative offsets at this point. | 430 // ensures we don't have to deal with negative offsets at this point. |
| 431 |
430 DCHECK_EQ(desc.spreadMethod, SpreadMethodRepeat); | 432 DCHECK_EQ(desc.spreadMethod, SpreadMethodRepeat); |
431 | 433 |
432 // When in repeat mode, we deal with it by repositioning both radii in the | 434 // When in repeat mode, we deal with it by repositioning both radii in the |
433 // positive domain - shifting them by a multiple of the radius span (which | 435 // positive domain - shifting them by a multiple of the radius span (which |
434 // is the period of our repeating gradient -> hence no visible side | 436 // is the period of our repeating gradient -> hence no visible side |
435 // effects). | 437 // effects). |
436 const float radiusSpan = adjustedR1 - adjustedR0; | 438 const float radiusSpan = adjustedR1 - adjustedR0; |
437 const float shiftToPositive = radiusSpan * ceilf(-adjustedR0 / radiusSpan); | 439 const float shiftToPositive = radiusSpan * ceilf(-adjustedR0 / radiusSpan); |
438 adjustedR0 += shiftToPositive; | 440 adjustedR0 += shiftToPositive; |
439 adjustedR1 += shiftToPositive; | 441 adjustedR1 += shiftToPositive; |
440 } | 442 } |
441 ASSERT(adjustedR0 >= 0); | 443 DCHECK_GE(adjustedR0, 0); |
442 ASSERT(adjustedR1 >= adjustedR0); | 444 DCHECK_GE(adjustedR1, adjustedR0); |
443 | 445 |
444 desc.r0 = adjustedR0; | 446 desc.r0 = adjustedR0; |
445 desc.r1 = adjustedR1; | 447 desc.r1 = adjustedR1; |
446 } | 448 } |
447 | 449 |
448 void CSSGradientValue::addStops(CSSGradientValue::GradientDesc& desc, | 450 void CSSGradientValue::addStops(CSSGradientValue::GradientDesc& desc, |
449 const CSSToLengthConversionData& conversionData, | 451 const CSSToLengthConversionData& conversionData, |
450 const LayoutObject& object) { | 452 const LayoutObject& object) { |
451 if (m_gradientType == CSSDeprecatedLinearGradient || | 453 if (m_gradientType == CSSDeprecatedLinearGradient || |
452 m_gradientType == CSSDeprecatedRadialGradient) { | 454 m_gradientType == CSSDeprecatedRadialGradient) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 if (stop.m_offset->isLength()) | 488 if (stop.m_offset->isLength()) |
487 length = stop.m_offset->computeLength<float>(conversionData); | 489 length = stop.m_offset->computeLength<float>(conversionData); |
488 else | 490 else |
489 length = stop.m_offset->cssCalcValue() | 491 length = stop.m_offset->cssCalcValue() |
490 ->toCalcValue(conversionData) | 492 ->toCalcValue(conversionData) |
491 ->evaluate(gradientLength); | 493 ->evaluate(gradientLength); |
492 stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0; | 494 stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0; |
493 } else if (stop.m_offset->isAngle()) { | 495 } else if (stop.m_offset->isAngle()) { |
494 stops[i].offset = stop.m_offset->computeDegrees() / 360.0f; | 496 stops[i].offset = stop.m_offset->computeDegrees() / 360.0f; |
495 } else { | 497 } else { |
496 ASSERT_NOT_REACHED(); | 498 NOTREACHED(); |
497 stops[i].offset = 0; | 499 stops[i].offset = 0; |
498 } | 500 } |
499 stops[i].specified = true; | 501 stops[i].specified = true; |
500 } else { | 502 } else { |
501 // If the first color-stop does not have a position, its position defaults | 503 // If the first color-stop does not have a position, its position defaults |
502 // to 0%. If the last color-stop does not have a position, its position | 504 // to 0%. If the last color-stop does not have a position, its position |
503 // defaults to 100%. | 505 // defaults to 100%. |
504 if (!i) { | 506 if (!i) { |
505 stops[i].offset = 0; | 507 stops[i].offset = 0; |
506 stops[i].specified = true; | 508 stops[i].specified = true; |
(...skipping 12 matching lines...) Expand all Loading... |
519 --prevSpecifiedIndex) { | 521 --prevSpecifiedIndex) { |
520 if (stops[prevSpecifiedIndex].specified) | 522 if (stops[prevSpecifiedIndex].specified) |
521 break; | 523 break; |
522 } | 524 } |
523 | 525 |
524 if (stops[i].offset < stops[prevSpecifiedIndex].offset) | 526 if (stops[i].offset < stops[prevSpecifiedIndex].offset) |
525 stops[i].offset = stops[prevSpecifiedIndex].offset; | 527 stops[i].offset = stops[prevSpecifiedIndex].offset; |
526 } | 528 } |
527 } | 529 } |
528 | 530 |
529 ASSERT(stops.front().specified && stops.back().specified); | 531 DCHECK(stops.front().specified); |
| 532 DCHECK(stops.back().specified); |
530 | 533 |
531 // If any color-stop still does not have a position, then, for each run of | 534 // If any color-stop still does not have a position, then, for each run of |
532 // adjacent color-stops without positions, set their positions so that they | 535 // adjacent color-stops without positions, set their positions so that they |
533 // are evenly spaced between the preceding and following color-stops with | 536 // are evenly spaced between the preceding and following color-stops with |
534 // positions. | 537 // positions. |
535 if (numStops > 2) { | 538 if (numStops > 2) { |
536 size_t unspecifiedRunStart = 0; | 539 size_t unspecifiedRunStart = 0; |
537 bool inUnspecifiedRun = false; | 540 bool inUnspecifiedRun = false; |
538 | 541 |
539 for (size_t i = 0; i < numStops; ++i) { | 542 for (size_t i = 0; i < numStops; ++i) { |
(...skipping 12 matching lines...) Expand all Loading... |
552 for (size_t j = unspecifiedRunStart; j < unspecifiedRunEnd; ++j) | 555 for (size_t j = unspecifiedRunStart; j < unspecifiedRunEnd; ++j) |
553 stops[j].offset = | 556 stops[j].offset = |
554 lastSpecifiedOffset + (j - unspecifiedRunStart + 1) * delta; | 557 lastSpecifiedOffset + (j - unspecifiedRunStart + 1) * delta; |
555 } | 558 } |
556 | 559 |
557 inUnspecifiedRun = false; | 560 inUnspecifiedRun = false; |
558 } | 561 } |
559 } | 562 } |
560 } | 563 } |
561 | 564 |
562 ASSERT(stops.size() == m_stops.size()); | 565 DCHECK_EQ(stops.size(), m_stops.size()); |
563 if (hasHints) { | 566 if (hasHints) { |
564 replaceColorHintsWithColorStops(stops, m_stops); | 567 replaceColorHintsWithColorStops(stops, m_stops); |
565 } | 568 } |
566 | 569 |
567 // At this point we have a fully resolved set of stops. Time to perform | 570 // At this point we have a fully resolved set of stops. Time to perform |
568 // adjustments for repeat gradients and degenerate values if needed. | 571 // adjustments for repeat gradients and degenerate values if needed. |
569 if (requiresStopsNormalization(stops, desc)) { | 572 if (requiresStopsNormalization(stops, desc)) { |
570 // Negative offsets are only an issue for non-repeating radial gradients: | 573 // Negative offsets are only an issue for non-repeating radial gradients: |
571 // linear gradient points can be repositioned arbitrarily, and for repeating | 574 // linear gradient points can be repositioned arbitrarily, and for repeating |
572 // radial gradients we shift the radii into equivalent positive values. | 575 // radial gradients we shift the radii into equivalent positive values. |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 // moved origin and the fact that we're in drawing space (+y = down). | 839 // moved origin and the fact that we're in drawing space (+y = down). |
837 secondPoint.set(halfWidth + endX, halfHeight - endY); | 840 secondPoint.set(halfWidth + endX, halfHeight - endY); |
838 // Reflect around the center for the start point. | 841 // Reflect around the center for the start point. |
839 firstPoint.set(halfWidth - endX, halfHeight + endY); | 842 firstPoint.set(halfWidth - endX, halfHeight + endY); |
840 } | 843 } |
841 | 844 |
842 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient( | 845 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient( |
843 const CSSToLengthConversionData& conversionData, | 846 const CSSToLengthConversionData& conversionData, |
844 const IntSize& size, | 847 const IntSize& size, |
845 const LayoutObject& object) { | 848 const LayoutObject& object) { |
846 ASSERT(!size.isEmpty()); | 849 DCHECK(!size.isEmpty()); |
847 | 850 |
848 FloatPoint firstPoint; | 851 FloatPoint firstPoint; |
849 FloatPoint secondPoint; | 852 FloatPoint secondPoint; |
850 if (m_angle) { | 853 if (m_angle) { |
851 float angle = m_angle->computeDegrees(); | 854 float angle = m_angle->computeDegrees(); |
852 endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType); | 855 endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType); |
853 } else { | 856 } else { |
854 switch (m_gradientType) { | 857 switch (m_gradientType) { |
855 case CSSDeprecatedLinearGradient: | 858 case CSSDeprecatedLinearGradient: |
856 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), | 859 firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), | 897 secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), |
895 conversionData, size); | 898 conversionData, size); |
896 if (m_firstX) | 899 if (m_firstX) |
897 firstPoint.setX(size.width() - secondPoint.x()); | 900 firstPoint.setX(size.width() - secondPoint.x()); |
898 if (m_firstY) | 901 if (m_firstY) |
899 firstPoint.setY(size.height() - secondPoint.y()); | 902 firstPoint.setY(size.height() - secondPoint.y()); |
900 } else | 903 } else |
901 secondPoint.setY(size.height()); | 904 secondPoint.setY(size.height()); |
902 break; | 905 break; |
903 default: | 906 default: |
904 ASSERT_NOT_REACHED(); | 907 NOTREACHED(); |
905 } | 908 } |
906 } | 909 } |
907 | 910 |
908 GradientDesc desc(firstPoint, secondPoint, | 911 GradientDesc desc(firstPoint, secondPoint, |
909 m_repeating ? SpreadMethodRepeat : SpreadMethodPad); | 912 m_repeating ? SpreadMethodRepeat : SpreadMethodPad); |
910 addStops(desc, conversionData, object); | 913 addStops(desc, conversionData, object); |
911 | 914 |
912 RefPtr<Gradient> gradient = | 915 RefPtr<Gradient> gradient = |
913 Gradient::create(desc.p0, desc.p1, desc.spreadMethod, | 916 Gradient::create(desc.p0, desc.p1, desc.spreadMethod, |
914 Gradient::ColorInterpolation::Premultiplied); | 917 Gradient::ColorInterpolation::Premultiplied); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 float dy1 = clampTo<float>(fabs(point.y())); | 1131 float dy1 = clampTo<float>(fabs(point.y())); |
1129 float dx2 = clampTo<float>(fabs(point.x() - size.width())); | 1132 float dx2 = clampTo<float>(fabs(point.x() - size.width())); |
1130 float dy2 = clampTo<float>(fabs(point.y() - size.height())); | 1133 float dy2 = clampTo<float>(fabs(point.y() - size.height())); |
1131 | 1134 |
1132 float dx = compare(dx1, dx2) ? dx1 : dx2; | 1135 float dx = compare(dx1, dx2) ? dx1 : dx2; |
1133 float dy = compare(dy1, dy2) ? dy1 : dy2; | 1136 float dy = compare(dy1, dy2) ? dy1 : dy2; |
1134 | 1137 |
1135 if (shape == CircleEndShape) | 1138 if (shape == CircleEndShape) |
1136 return compare(dx, dy) ? FloatSize(dx, dx) : FloatSize(dy, dy); | 1139 return compare(dx, dy) ? FloatSize(dx, dx) : FloatSize(dy, dy); |
1137 | 1140 |
1138 ASSERT(shape == EllipseEndShape); | 1141 DCHECK_EQ(shape, EllipseEndShape); |
1139 return FloatSize(dx, dy); | 1142 return FloatSize(dx, dy); |
1140 } | 1143 } |
1141 | 1144 |
1142 // Compute the radius of an ellipse with center at 0,0 which passes through p, | 1145 // Compute the radius of an ellipse with center at 0,0 which passes through p, |
1143 // and has width/height given by aspectRatio. | 1146 // and has width/height given by aspectRatio. |
1144 inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio) { | 1147 inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio) { |
1145 // If the aspectRatio is 0 or infinite, the ellipse is completely flat. | 1148 // If the aspectRatio is 0 or infinite, the ellipse is completely flat. |
1146 // TODO(sashab): Implement Degenerate Radial Gradients, see crbug.com/635727. | 1149 // TODO(sashab): Implement Degenerate Radial Gradients, see crbug.com/635727. |
1147 if (aspectRatio == 0 || std::isinf(aspectRatio)) | 1150 if (aspectRatio == 0 || std::isinf(aspectRatio)) |
1148 return FloatSize(0, 0); | 1151 return FloatSize(0, 0); |
(...skipping 21 matching lines...) Expand all Loading... |
1170 float newDistance = (point - corners[i]).diagonalLength(); | 1173 float newDistance = (point - corners[i]).diagonalLength(); |
1171 if (compare(newDistance, distance)) { | 1174 if (compare(newDistance, distance)) { |
1172 cornerIndex = i; | 1175 cornerIndex = i; |
1173 distance = newDistance; | 1176 distance = newDistance; |
1174 } | 1177 } |
1175 } | 1178 } |
1176 | 1179 |
1177 if (shape == CircleEndShape) | 1180 if (shape == CircleEndShape) |
1178 return FloatSize(distance, distance); | 1181 return FloatSize(distance, distance); |
1179 | 1182 |
1180 ASSERT(shape == EllipseEndShape); | 1183 DCHECK_EQ(shape, EllipseEndShape); |
1181 // If the end shape is an ellipse, the gradient-shape has the same ratio of | 1184 // If the end shape is an ellipse, the gradient-shape has the same ratio of |
1182 // width to height that it would if closest-side or farthest-side were | 1185 // width to height that it would if closest-side or farthest-side were |
1183 // specified, as appropriate. | 1186 // specified, as appropriate. |
1184 const FloatSize sideRadius = | 1187 const FloatSize sideRadius = |
1185 radiusToSide(point, size, EllipseEndShape, compare); | 1188 radiusToSide(point, size, EllipseEndShape, compare); |
1186 | 1189 |
1187 return ellipseRadius(FloatPoint(corners[cornerIndex] - point), | 1190 return ellipseRadius(FloatPoint(corners[cornerIndex] - point), |
1188 sideRadius.aspectRatio()); | 1191 sideRadius.aspectRatio()); |
1189 } | 1192 } |
1190 | 1193 |
1191 } // anonymous namespace | 1194 } // anonymous namespace |
1192 | 1195 |
1193 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient( | 1196 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient( |
1194 const CSSToLengthConversionData& conversionData, | 1197 const CSSToLengthConversionData& conversionData, |
1195 const IntSize& size, | 1198 const IntSize& size, |
1196 const LayoutObject& object) { | 1199 const LayoutObject& object) { |
1197 ASSERT(!size.isEmpty()); | 1200 DCHECK(!size.isEmpty()); |
1198 | 1201 |
1199 FloatPoint firstPoint = | 1202 FloatPoint firstPoint = |
1200 computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); | 1203 computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); |
1201 if (!m_firstX) | 1204 if (!m_firstX) |
1202 firstPoint.setX(size.width() / 2); | 1205 firstPoint.setX(size.width() / 2); |
1203 if (!m_firstY) | 1206 if (!m_firstY) |
1204 firstPoint.setY(size.height() / 2); | 1207 firstPoint.setY(size.height() / 2); |
1205 | 1208 |
1206 FloatPoint secondPoint = | 1209 FloatPoint secondPoint = |
1207 computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size); | 1210 computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 dataEquivalent(m_fromAngle, other.m_fromAngle) && | 1382 dataEquivalent(m_fromAngle, other.m_fromAngle) && |
1380 m_stops == other.m_stops; | 1383 m_stops == other.m_stops; |
1381 } | 1384 } |
1382 | 1385 |
1383 DEFINE_TRACE_AFTER_DISPATCH(CSSConicGradientValue) { | 1386 DEFINE_TRACE_AFTER_DISPATCH(CSSConicGradientValue) { |
1384 visitor->trace(m_fromAngle); | 1387 visitor->trace(m_fromAngle); |
1385 CSSGradientValue::traceAfterDispatch(visitor); | 1388 CSSGradientValue::traceAfterDispatch(visitor); |
1386 } | 1389 } |
1387 | 1390 |
1388 } // namespace blink | 1391 } // namespace blink |
OLD | NEW |