| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 newStops[y].color = blend(leftColor, rightColor, weighting); | 185 newStops[y].color = blend(leftColor, rightColor, weighting); |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Replace the color hint with the new color stops. | 188 // Replace the color hint with the new color stops. |
| 189 stops.remove(x); | 189 stops.remove(x); |
| 190 stops.insert(x, newStops, 9); | 190 stops.insert(x, newStops, 9); |
| 191 indexOffset += 8; | 191 indexOffset += 8; |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 static Color resolveStopColor(CSSPrimitiveValue stopColor, const LayoutObject& o
bject) | 195 static Color resolveStopColor(const CSSPrimitiveValue& stopColor, const LayoutOb
ject& object) |
| 196 { | 196 { |
| 197 return object.document().textLinkColors().colorFromPrimitiveValue(stopColor,
object.resolveColor(CSSPropertyColor)); | 197 return object.document().textLinkColors().colorFromPrimitiveValue(stopColor,
object.resolveColor(CSSPropertyColor)); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void CSSGradientValue::addDeprecatedStops(Gradient* gradient, const LayoutObject
& object) | 200 void CSSGradientValue::addDeprecatedStops(Gradient* gradient, const LayoutObject
& object) |
| 201 { | 201 { |
| 202 ASSERT(m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CS
SDeprecatedRadialGradient); | 202 ASSERT(m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CS
SDeprecatedRadialGradient); |
| 203 | 203 |
| 204 if (!m_stopsSorted) { | 204 if (!m_stopsSorted) { |
| 205 if (m_stops.size()) | 205 if (m_stops.size()) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 372 |
| 373 for (size_t i = 0; i < numStops; ++i) { | 373 for (size_t i = 0; i < numStops; ++i) { |
| 374 const CSSGradientColorStop& stop = m_stops[i]; | 374 const CSSGradientColorStop& stop = m_stops[i]; |
| 375 | 375 |
| 376 if (stop.isHint()) | 376 if (stop.isHint()) |
| 377 hasHints = true; | 377 hasHints = true; |
| 378 else | 378 else |
| 379 stops[i].color = resolveStopColor(toCSSPrimitiveValue(*stop.m_color)
, object); | 379 stops[i].color = resolveStopColor(toCSSPrimitiveValue(*stop.m_color)
, object); |
| 380 | 380 |
| 381 if (stop.m_position) { | 381 if (stop.m_position) { |
| 382 CSSPrimitiveValue stopPosition = toCSSPrimitiveValue(*stop.m_positio
n); | 382 const CSSPrimitiveValue& stopPosition = toCSSPrimitiveValue(*stop.m_
position); |
| 383 if (stopPosition.isPercentage()) { | 383 if (stopPosition.isPercentage()) { |
| 384 stops[i].offset = toCSSPrimitiveValue(*stop.m_position).getFloat
Value() / 100; | 384 stops[i].offset = toCSSPrimitiveValue(*stop.m_position).getFloat
Value() / 100; |
| 385 } else if (stopPosition.isLength() || stopPosition.isCalculatedPerce
ntageWithLength()) { | 385 } else if (stopPosition.isLength() || stopPosition.isCalculatedPerce
ntageWithLength()) { |
| 386 float length; | 386 float length; |
| 387 if (stopPosition.isLength()) | 387 if (stopPosition.isLength()) |
| 388 length = stopPosition.computeLength<float>(conversionData); | 388 length = stopPosition.computeLength<float>(conversionData); |
| 389 else | 389 else |
| 390 length = stopPosition.cssCalcValue()->toCalcValue(conversion
Data)->evaluate(gradientLength); | 390 length = stopPosition.cssCalcValue()->toCalcValue(conversion
Data)->evaluate(gradientLength); |
| 391 stops[i].offset = (gradientLength > 0) ? length / gradientLength
: 0; | 391 stops[i].offset = (gradientLength > 0) ? length / gradientLength
: 0; |
| 392 } else { | 392 } else { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 } else { | 474 } else { |
| 475 // Normalization failed because the stop set is coincident. | 475 // Normalization failed because the stop set is coincident. |
| 476 } | 476 } |
| 477 } else { | 477 } else { |
| 478 // No normalization required, just add the current stops. | 478 // No normalization required, just add the current stops. |
| 479 for (const auto& stop : stops) | 479 for (const auto& stop : stops) |
| 480 gradient->addColorStop(stop.offset, stop.color); | 480 gradient->addColorStop(stop.offset, stop.color); |
| 481 } | 481 } |
| 482 } | 482 } |
| 483 | 483 |
| 484 static float positionFromValue(CSSPrimitiveValue value, const CSSToLengthConvers
ionData& conversionData, const IntSize& size, bool isHorizontal) | 484 static float positionFromValue(const CSSPrimitiveValue& value, const CSSToLength
ConversionData& conversionData, const IntSize& size, bool isHorizontal) |
| 485 { | 485 { |
| 486 int origin = 0; | 486 int origin = 0; |
| 487 int sign = 1; | 487 int sign = 1; |
| 488 int edgeDistance = isHorizontal ? size.width() : size.height(); | 488 int edgeDistance = isHorizontal ? size.width() : size.height(); |
| 489 | 489 |
| 490 // In this case the center of the gradient is given relative to an edge in t
he form of: | 490 // In this case the center of the gradient is given relative to an edge in t
he form of: |
| 491 // [ top | bottom | right | left ] [ <percentage> | <length> ]. | 491 // [ top | bottom | right | left ] [ <percentage> | <length> ]. |
| 492 if (Pair* pair = value.getPairValue()) { | 492 CSSPrimitiveValue valueToUse = value; |
| 493 CSSValueID originID = toCSSPrimitiveValue(*pair->first()).getValueID(); | 493 if (Pair* pair = valueToUse.getPairValue()) { |
| 494 value = toCSSPrimitiveValue(*pair->second()); | 494 CSSValueID originID = pair->first().getValueID(); |
| 495 valueToUse = pair->second(); |
| 495 | 496 |
| 496 if (originID == CSSValueRight || originID == CSSValueBottom) { | 497 if (originID == CSSValueRight || originID == CSSValueBottom) { |
| 497 // For right/bottom, the offset is relative to the far edge. | 498 // For right/bottom, the offset is relative to the far edge. |
| 498 origin = edgeDistance; | 499 origin = edgeDistance; |
| 499 sign = -1; | 500 sign = -1; |
| 500 } | 501 } |
| 501 } | 502 } |
| 502 | 503 |
| 503 if (value.isNumber()) | 504 if (valueToUse.isNumber()) |
| 504 return origin + sign * value.getFloatValue() * conversionData.zoom(); | 505 return origin + sign * valueToUse.getFloatValue() * conversionData.zoom(
); |
| 505 | 506 |
| 506 if (value.isPercentage()) | 507 if (valueToUse.isPercentage()) |
| 507 return origin + sign * value.getFloatValue() / 100.f * edgeDistance; | 508 return origin + sign * valueToUse.getFloatValue() / 100.f * edgeDistance
; |
| 508 | 509 |
| 509 if (value.isCalculatedPercentageWithLength()) | 510 if (valueToUse.isCalculatedPercentageWithLength()) |
| 510 return origin + sign * value.cssCalcValue()->toCalcValue(conversionData)
->evaluate(edgeDistance); | 511 return origin + sign * valueToUse.cssCalcValue()->toCalcValue(conversion
Data)->evaluate(edgeDistance); |
| 511 | 512 |
| 512 switch (value.getValueID()) { | 513 switch (valueToUse.getValueID()) { |
| 513 case CSSValueTop: | 514 case CSSValueTop: |
| 514 ASSERT(!isHorizontal); | 515 ASSERT(!isHorizontal); |
| 515 return 0; | 516 return 0; |
| 516 case CSSValueLeft: | 517 case CSSValueLeft: |
| 517 ASSERT(isHorizontal); | 518 ASSERT(isHorizontal); |
| 518 return 0; | 519 return 0; |
| 519 case CSSValueBottom: | 520 case CSSValueBottom: |
| 520 ASSERT(!isHorizontal); | 521 ASSERT(!isHorizontal); |
| 521 return size.height(); | 522 return size.height(); |
| 522 case CSSValueRight: | 523 case CSSValueRight: |
| 523 ASSERT(isHorizontal); | 524 ASSERT(isHorizontal); |
| 524 return size.width(); | 525 return size.width(); |
| 525 default: | 526 default: |
| 526 break; | 527 break; |
| 527 } | 528 } |
| 528 | 529 |
| 529 return origin + sign * value.computeLength<float>(conversionData); | 530 return origin + sign * valueToUse.computeLength<float>(conversionData); |
| 530 } | 531 } |
| 531 | 532 |
| 532 FloatPoint CSSGradientValue::computeEndPoint(NullableCSSValue horizontal, Nullab
leCSSValue vertical, const CSSToLengthConversionData& conversionData, const IntS
ize& size) | 533 FloatPoint CSSGradientValue::computeEndPoint(NullableCSSValue horizontal, Nullab
leCSSValue vertical, const CSSToLengthConversionData& conversionData, const IntS
ize& size) |
| 533 { | 534 { |
| 534 FloatPoint result; | 535 FloatPoint result; |
| 535 | 536 |
| 536 if (horizontal) | 537 if (horizontal) |
| 537 result.setX(positionFromValue(toCSSPrimitiveValue(*horizontal), conversi
onData, size, true)); | 538 result.setX(positionFromValue(toCSSPrimitiveValue(*horizontal), conversi
onData, size, true)); |
| 538 | 539 |
| 539 if (vertical) | 540 if (vertical) |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 if (stop.m_position) | 993 if (stop.m_position) |
| 993 result.append(stop.m_position->cssText()); | 994 result.append(stop.m_position->cssText()); |
| 994 } | 995 } |
| 995 | 996 |
| 996 } | 997 } |
| 997 | 998 |
| 998 result.append(')'); | 999 result.append(')'); |
| 999 return result.toString(); | 1000 return result.toString(); |
| 1000 } | 1001 } |
| 1001 | 1002 |
| 1002 float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue radius, const CSST
oLengthConversionData& conversionData, float* widthOrHeight) | 1003 float CSSRadialGradientValue::resolveRadius(const CSSPrimitiveValue& radius, con
st CSSToLengthConversionData& conversionData, float* widthOrHeight) |
| 1003 { | 1004 { |
| 1004 float result = 0; | 1005 float result = 0; |
| 1005 if (radius.isNumber()) // Can the radius be a percentage? | 1006 if (radius.isNumber()) // Can the radius be a percentage? |
| 1006 result = radius.getFloatValue() * conversionData.zoom(); | 1007 result = radius.getFloatValue() * conversionData.zoom(); |
| 1007 else if (widthOrHeight && radius.isPercentage()) | 1008 else if (widthOrHeight && radius.isPercentage()) |
| 1008 result = *widthOrHeight * radius.getFloatValue() / 100; | 1009 result = *widthOrHeight * radius.getFloatValue() / 100; |
| 1009 else | 1010 else |
| 1010 result = radius.computeLength<float>(conversionData); | 1011 result = radius.computeLength<float>(conversionData); |
| 1011 | 1012 |
| 1012 return std::max(result, 0.0f); | 1013 return std::max(result, 0.0f); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 visitor->trace(m_firstRadius); | 1207 visitor->trace(m_firstRadius); |
| 1207 visitor->trace(m_secondRadius); | 1208 visitor->trace(m_secondRadius); |
| 1208 visitor->trace(m_shape); | 1209 visitor->trace(m_shape); |
| 1209 visitor->trace(m_sizingBehavior); | 1210 visitor->trace(m_sizingBehavior); |
| 1210 visitor->trace(m_endHorizontalSize); | 1211 visitor->trace(m_endHorizontalSize); |
| 1211 visitor->trace(m_endVerticalSize); | 1212 visitor->trace(m_endVerticalSize); |
| 1212 CSSGradientValue::traceAfterDispatch(visitor); | 1213 CSSGradientValue::traceAfterDispatch(visitor); |
| 1213 } | 1214 } |
| 1214 | 1215 |
| 1215 } // namespace blink | 1216 } // namespace blink |
| OLD | NEW |