Ignore:
Timestamp:
Oct 28, 2016, 12:40:44 PM (9 years ago)
Author:
[email protected]
Message:

[CSS Parser] Clean up gradient parsing
https://bugs.webkit.org/show_bug.cgi?id=164139

Reviewed by Dean Jackson.

  • css/CSSGradientValue.cpp:

(WebCore::positionFromValue):
(WebCore::CSSGradientValue::computeEndPoint):

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::consumeDeprecatedGradient):
(WebCore::CSSPropertyParserHelpers::consumeGradientColorStops):
(WebCore::CSSPropertyParserHelpers::consumeDeprecatedRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeRadialGradient):
(WebCore::CSSPropertyParserHelpers::consumeLinearGradient):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r207396 r208062  
    3636#include "Image.h"
    3737#include "NodeRenderStyle.h"
     38#include "Pair.h"
    3839#include "RenderElement.h"
    3940#include "RenderView.h"
     
    495496}
    496497
    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 
     498static float positionFromValue(const CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal)
     499{
     500    int origin = 0;
     501    int sign = 1;
    502502    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()) {
    512529    case CSSValueTop:
    513530        ASSERT(!isHorizontal);
     
    522539        ASSERT(isHorizontal);
    523540        return size.width();
     541    case CSSValueCenter:
     542        return origin + sign * .5f * edgeDistance;
    524543    default:
    525544        break;
    526545    }
    527546
    528     return value.computeLength<float>(conversionData);
     547    return origin + sign * value->computeLength<float>(conversionData);
    529548}
    530549
     
    534553
    535554    if (horizontal)
    536         result.setX(positionFromValue(*horizontal, conversionData, size, true));
     555        result.setX(positionFromValue(horizontal, conversionData, size, true));
    537556
    538557    if (vertical)
    539         result.setY(positionFromValue(*vertical, conversionData, size, false));
     558        result.setY(positionFromValue(vertical, conversionData, size, false));
    540559
    541560    return result;
Note: See TracChangeset for help on using the changeset viewer.