| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/css/CSSGradientValue.h" | 27 #include "core/css/CSSGradientValue.h" |
| 28 | 28 |
| 29 #include "core/CSSValueKeywords.h" | 29 #include "core/CSSValueKeywords.h" |
| 30 #include "core/css/CSSCalculationValue.h" | 30 #include "core/css/CSSCalculationValue.h" |
| 31 #include "core/css/CSSToLengthConversionData.h" | 31 #include "core/css/CSSToLengthConversionData.h" |
| 32 #include "core/css/Pair.h" |
| 32 #include "core/dom/NodeRenderStyle.h" | 33 #include "core/dom/NodeRenderStyle.h" |
| 33 #include "core/dom/TextLinkColors.h" | 34 #include "core/dom/TextLinkColors.h" |
| 34 #include "core/rendering/RenderObject.h" | 35 #include "core/rendering/RenderObject.h" |
| 35 #include "platform/geometry/IntSize.h" | 36 #include "platform/geometry/IntSize.h" |
| 36 #include "platform/graphics/Gradient.h" | 37 #include "platform/graphics/Gradient.h" |
| 37 #include "platform/graphics/GradientGeneratedImage.h" | 38 #include "platform/graphics/GradientGeneratedImage.h" |
| 38 #include "platform/graphics/Image.h" | 39 #include "platform/graphics/Image.h" |
| 39 #include "wtf/text/StringBuilder.h" | 40 #include "wtf/text/StringBuilder.h" |
| 40 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
| 41 | 42 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 gradient->setEndRadius(gradient->endRadius() * scale); | 383 gradient->setEndRadius(gradient->endRadius() * scale); |
| 383 } | 384 } |
| 384 } | 385 } |
| 385 | 386 |
| 386 for (unsigned i = 0; i < numStops; i++) | 387 for (unsigned i = 0; i < numStops; i++) |
| 387 gradient->addColorStop(stops[i].offset, stops[i].color); | 388 gradient->addColorStop(stops[i].offset, stops[i].color); |
| 388 } | 389 } |
| 389 | 390 |
| 390 static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConver
sionData& conversionData, const IntSize& size, bool isHorizontal) | 391 static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConver
sionData& conversionData, const IntSize& size, bool isHorizontal) |
| 391 { | 392 { |
| 393 int origin = 0; |
| 394 int sign = 1; |
| 395 int edgeDistance = isHorizontal ? size.width() : size.height(); |
| 396 |
| 397 // In this case the center of the gradient is given relative to an edge in t
he form of: |
| 398 // [ top | bottom | right | left ] [ <percentage> | <length> ]. |
| 399 if (Pair* pair = value->getPairValue()) { |
| 400 CSSValueID originID = pair->first()->getValueID(); |
| 401 value = pair->second(); |
| 402 |
| 403 if (originID == CSSValueRight || originID == CSSValueBottom) { |
| 404 // For right/bottom, the offset is relative to the far edge. |
| 405 origin = edgeDistance; |
| 406 sign = -1; |
| 407 } |
| 408 } |
| 409 |
| 392 if (value->isNumber()) | 410 if (value->isNumber()) |
| 393 return value->getFloatValue() * conversionData.zoom(); | 411 return origin + sign * value->getFloatValue() * conversionData.zoom(); |
| 394 | 412 |
| 395 int edgeDistance = isHorizontal ? size.width() : size.height(); | |
| 396 if (value->isPercentage()) | 413 if (value->isPercentage()) |
| 397 return value->getFloatValue() / 100.f * edgeDistance; | 414 return origin + sign * value->getFloatValue() / 100.f * edgeDistance; |
| 398 | 415 |
| 399 if (value->isCalculatedPercentageWithLength()) | 416 if (value->isCalculatedPercentageWithLength()) |
| 400 return value->cssCalcValue()->toCalcValue(conversionData)->evaluate(edge
Distance); | 417 return origin + sign * value->cssCalcValue()->toCalcValue(conversionData
)->evaluate(edgeDistance); |
| 401 | 418 |
| 402 switch (value->getValueID()) { | 419 switch (value->getValueID()) { |
| 403 case CSSValueTop: | 420 case CSSValueTop: |
| 404 ASSERT(!isHorizontal); | 421 ASSERT(!isHorizontal); |
| 405 return 0; | 422 return 0; |
| 406 case CSSValueLeft: | 423 case CSSValueLeft: |
| 407 ASSERT(isHorizontal); | 424 ASSERT(isHorizontal); |
| 408 return 0; | 425 return 0; |
| 409 case CSSValueBottom: | 426 case CSSValueBottom: |
| 410 ASSERT(!isHorizontal); | 427 ASSERT(!isHorizontal); |
| 411 return size.height(); | 428 return size.height(); |
| 412 case CSSValueRight: | 429 case CSSValueRight: |
| 413 ASSERT(isHorizontal); | 430 ASSERT(isHorizontal); |
| 414 return size.width(); | 431 return size.width(); |
| 415 default: | 432 default: |
| 416 break; | 433 break; |
| 417 } | 434 } |
| 418 | 435 |
| 419 return value->computeLength<float>(conversionData); | 436 return origin + sign * value->computeLength<float>(conversionData); |
| 420 } | 437 } |
| 421 | 438 |
| 422 FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSP
rimitiveValue* vertical, const CSSToLengthConversionData& conversionData, const
IntSize& size) | 439 FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSP
rimitiveValue* vertical, const CSSToLengthConversionData& conversionData, const
IntSize& size) |
| 423 { | 440 { |
| 424 FloatPoint result; | 441 FloatPoint result; |
| 425 | 442 |
| 426 if (horizontal) | 443 if (horizontal) |
| 427 result.setX(positionFromValue(horizontal, conversionData, size, true)); | 444 result.setX(positionFromValue(horizontal, conversionData, size, true)); |
| 428 | 445 |
| 429 if (vertical) | 446 if (vertical) |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 visitor->trace(m_firstRadius); | 1198 visitor->trace(m_firstRadius); |
| 1182 visitor->trace(m_secondRadius); | 1199 visitor->trace(m_secondRadius); |
| 1183 visitor->trace(m_shape); | 1200 visitor->trace(m_shape); |
| 1184 visitor->trace(m_sizingBehavior); | 1201 visitor->trace(m_sizingBehavior); |
| 1185 visitor->trace(m_endHorizontalSize); | 1202 visitor->trace(m_endHorizontalSize); |
| 1186 visitor->trace(m_endVerticalSize); | 1203 visitor->trace(m_endVerticalSize); |
| 1187 CSSGradientValue::traceAfterDispatch(visitor); | 1204 CSSGradientValue::traceAfterDispatch(visitor); |
| 1188 } | 1205 } |
| 1189 | 1206 |
| 1190 } // namespace WebCore | 1207 } // namespace WebCore |
| OLD | NEW |