Changeset 208062 in webkit for trunk/Source/WebCore/css/CSSGradientValue.cpp
- Timestamp:
- Oct 28, 2016, 12:40:44 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSGradientValue.cpp
r207396 r208062 36 36 #include "Image.h" 37 37 #include "NodeRenderStyle.h" 38 #include "Pair.h" 38 39 #include "RenderElement.h" 39 40 #include "RenderView.h" … … 495 496 } 496 497 497 static float positionFromValue(CSSPrimitiveValue& value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal) 498 { 499 if (value.isNumber()) 500 return value.floatValue() * conversionData.zoom(); 501 498 static float positionFromValue(const CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal) 499 { 500 int origin = 0; 501 int sign = 1; 502 502 int edgeDistance = isHorizontal ? size.width() : size.height(); 503 if (value.isPercentage()) 504 return value.floatValue() / 100.f * edgeDistance; 505 506 if (value.isCalculatedPercentageWithLength()) { 507 Ref<CalculationValue> calculationValue { value.cssCalcValue()->createCalculationValue(conversionData) }; 508 return calculationValue->evaluate(edgeDistance); 509 } 510 511 switch (value.valueID()) { 503 504 // In this case the center of the gradient is given relative to an edge in the 505 // form of: [ top | bottom | right | left ] [ <percentage> | <length> ]. 506 if (value->isPair()) { 507 CSSValueID originID = value->pairValue()->first()->valueID(); 508 value = value->pairValue()->second(); 509 510 if (originID == CSSValueRight || originID == CSSValueBottom) { 511 // For right/bottom, the offset is relative to the far edge. 512 origin = edgeDistance; 513 sign = -1; 514 } 515 } 516 517 if (value->isNumber()) 518 return origin + sign * value->floatValue() * conversionData.zoom(); 519 520 if (value->isPercentage()) 521 return origin + sign * value->floatValue() / 100.f * edgeDistance; 522 523 if (value->isCalculatedPercentageWithLength()) { 524 Ref<CalculationValue> calculationValue { value->cssCalcValue()->createCalculationValue(conversionData) }; 525 return origin + sign * calculationValue->evaluate(edgeDistance); 526 } 527 528 switch (value->valueID()) { 512 529 case CSSValueTop: 513 530 ASSERT(!isHorizontal); … … 522 539 ASSERT(isHorizontal); 523 540 return size.width(); 541 case CSSValueCenter: 542 return origin + sign * .5f * edgeDistance; 524 543 default: 525 544 break; 526 545 } 527 546 528 return value.computeLength<float>(conversionData);547 return origin + sign * value->computeLength<float>(conversionData); 529 548 } 530 549 … … 534 553 535 554 if (horizontal) 536 result.setX(positionFromValue( *horizontal, conversionData, size, true));555 result.setX(positionFromValue(horizontal, conversionData, size, true)); 537 556 538 557 if (vertical) 539 result.setY(positionFromValue( *vertical, conversionData, size, false));558 result.setY(positionFromValue(vertical, conversionData, size, false)); 540 559 541 560 return result;
Note:
See TracChangeset
for help on using the changeset viewer.