Ignore:
Timestamp:
May 23, 2014, 9:13:03 AM (11 years ago)
Author:
Simon Fraser
Message:

Switch CSSGradientValue to use more references
https://bugs.webkit.org/show_bug.cgi?id=133206

Reviewed by Andreas Kling.

Switch from pointers to references in various places.

  • css/CSSGradientValue.cpp:

(WebCore::CSSGradientValue::image):
(WebCore::CSSGradientValue::addStops):
(WebCore::positionFromValue):
(WebCore::CSSGradientValue::computeEndPoint):
(WebCore::CSSLinearGradientValue::createGradient):
(WebCore::CSSRadialGradientValue::resolveRadius):
(WebCore::CSSRadialGradientValue::createGradient):

  • css/CSSGradientValue.h:
File:
1 edited

Legend:

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

    r169248 r169258  
    6161
    6262    if (isLinearGradientValue())
    63         gradient = toCSSLinearGradientValue(this)->createGradient(renderer, size);
     63        gradient = toCSSLinearGradientValue(this)->createGradient(*renderer, size);
    6464    else
    65         gradient = toCSSRadialGradientValue(this)->createGradient(renderer, size);
     65        gradient = toCSSRadialGradientValue(this)->createGradient(*renderer, size);
    6666
    6767    RefPtr<GradientImage> newImage = GradientImage::create(gradient, size);
     
    130130}
    131131
    132 void CSSGradientValue::addStops(Gradient* gradient, RenderView* renderView, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
     132void CSSGradientValue::addStops(Gradient& gradient, RenderView& renderView, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
    133133{
    134134    if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) {
     
    144144                offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_NUMBER);
    145145
    146             gradient->addColorStop(offset, stop.m_resolvedColor);
     146            gradient.addColorStop(offset, stop.m_resolvedColor);
    147147        }
    148148
    149149        // The back end already sorted the stops.
    150         gradient->setStopsSorted(true);
     150        gradient.setStopsSorted(true);
    151151        return;
    152152    }
     
    159159    bool computedGradientLength = false;
    160160
    161     FloatPoint gradientStart = gradient->p0();
     161    FloatPoint gradientStart = gradient.p0();
    162162    FloatPoint gradientEnd;
    163163    if (isLinearGradientValue())
    164         gradientEnd = gradient->p1();
     164        gradientEnd = gradient.p1();
    165165    else if (isRadialGradientValue())
    166         gradientEnd = gradientStart + FloatSize(gradient->endRadius(), 0);
     166        gradientEnd = gradientStart + FloatSize(gradient.endRadius(), 0);
    167167
    168168    for (size_t i = 0; i < numStops; ++i) {
     
    184184                    length = positionValue.computeLength<float>(conversionData);
    185185                else if (positionValue.isViewportPercentageLength())
    186                     length = valueForLength(positionValue.viewportPercentageLength(), 0, renderView);
     186                    length = valueForLength(positionValue.viewportPercentageLength(), 0, &renderView);
    187187                else {
    188188                    Ref<CalculationValue> calculationValue { positionValue.cssCalcValue()->createCalculationValue(conversionData) };
     
    336336                    stops[i].offset = (stops[i].offset - firstOffset) / scale;
    337337
    338                 FloatPoint p0 = gradient->p0();
    339                 FloatPoint p1 = gradient->p1();
    340                 gradient->setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y())));
    341                 gradient->setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y())));
     338                FloatPoint p0 = gradient.p0();
     339                FloatPoint p1 = gradient.p1();
     340                gradient.setP0(FloatPoint(p0.x() + firstOffset * (p1.x() - p0.x()), p0.y() + firstOffset * (p1.y() - p0.y())));
     341                gradient.setP1(FloatPoint(p1.x() + (lastOffset - 1) * (p1.x() - p0.x()), p1.y() + (lastOffset - 1) * (p1.y() - p0.y())));
    342342            } else {
    343343                // There's a single position that is outside the scale, clamp the positions to 1.
     
    384384                stops[i].offset /= scale;
    385385
    386             gradient->setStartRadius(gradient->startRadius() * scale);
    387             gradient->setEndRadius(gradient->endRadius() * scale);
     386            gradient.setStartRadius(gradient.startRadius() * scale);
     387            gradient.setEndRadius(gradient.endRadius() * scale);
    388388        }
    389389    }
    390390
    391391    for (unsigned i = 0; i < numStops; i++)
    392         gradient->addColorStop(stops[i].offset, stops[i].color);
    393 
    394     gradient->setStopsSorted(true);
    395 }
    396 
    397 static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal)
    398 {
    399     if (value->isNumber())
    400         return value->getFloatValue() * conversionData.zoom();
     392        gradient.addColorStop(stops[i].offset, stops[i].color);
     393
     394    gradient.setStopsSorted(true);
     395}
     396
     397static float positionFromValue(CSSPrimitiveValue& value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal)
     398{
     399    if (value.isNumber())
     400        return value.getFloatValue() * conversionData.zoom();
    401401
    402402    int edgeDistance = isHorizontal ? size.width() : size.height();
    403     if (value->isPercentage())
    404         return value->getFloatValue() / 100.f * edgeDistance;
    405 
    406     if (value->isCalculatedPercentageWithLength()) {
    407         Ref<CalculationValue> calculationValue { value->cssCalcValue()->createCalculationValue(conversionData) };
     403    if (value.isPercentage())
     404        return value.getFloatValue() / 100.f * edgeDistance;
     405
     406    if (value.isCalculatedPercentageWithLength()) {
     407        Ref<CalculationValue> calculationValue { value.cssCalcValue()->createCalculationValue(conversionData) };
    408408        return calculationValue->evaluate(edgeDistance);
    409409    }
    410410
    411     switch (value->getValueID()) {
     411    switch (value.getValueID()) {
    412412    case CSSValueTop:
    413413        ASSERT(!isHorizontal);
     
    426426    }
    427427
    428     return value->computeLength<float>(conversionData);
     428    return value.computeLength<float>(conversionData);
    429429}
    430430
     
    434434
    435435    if (horizontal)
    436         result.setX(positionFromValue(horizontal, conversionData, size, true));
     436        result.setX(positionFromValue(*horizontal, conversionData, size, true));
    437437
    438438    if (vertical)
    439         result.setY(positionFromValue(vertical, conversionData, size, false));
     439        result.setY(positionFromValue(*vertical, conversionData, size, false));
    440440
    441441    return result;
     
    644644}
    645645
    646 PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderElement* renderer, const FloatSize& size)
     646PassRefPtr<Gradient> CSSLinearGradientValue::createGradient(RenderElement& renderer, const FloatSize& size)
    647647{
    648648    ASSERT(!size.isEmpty());
    649649
    650     CSSToLengthConversionData conversionData(&renderer->style(), renderer->document().documentElement()->renderStyle());
     650    CSSToLengthConversionData conversionData(&renderer.style(), renderer.document().documentElement()->renderStyle());
    651651
    652652    FloatPoint firstPoint;
     
    705705
    706706    // Now add the stops.
    707     addStops(gradient.get(), &renderer->view(), conversionData, 1);
     707    addStops(*gradient, renderer.view(), conversionData, 1);
    708708
    709709    return gradient.release();
     
    892892}
    893893
    894 float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight)
     894float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue& radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight)
    895895{
    896896    float result = 0;
    897     if (radius->isNumber()) // Can the radius be a percentage?
    898         result = radius->getFloatValue() * conversionData.zoom();
    899     else if (widthOrHeight && radius->isPercentage())
    900         result = *widthOrHeight * radius->getFloatValue() / 100;
     897    if (radius.isNumber()) // Can the radius be a percentage?
     898        result = radius.getFloatValue() * conversionData.zoom();
     899    else if (widthOrHeight && radius.isPercentage())
     900        result = *widthOrHeight * radius.getFloatValue() / 100;
    901901    else
    902         result = radius->computeLength<float>(conversionData);
     902        result = radius.computeLength<float>(conversionData);
    903903
    904904    return result;
     
    982982
    983983// FIXME: share code with the linear version
    984 PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(RenderElement* renderer, const FloatSize& size)
     984PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(RenderElement& renderer, const FloatSize& size)
    985985{
    986986    ASSERT(!size.isEmpty());
    987987
    988     CSSToLengthConversionData conversionData(&renderer->style(), renderer->document().documentElement()->renderStyle());
     988    CSSToLengthConversionData conversionData(&renderer.style(), renderer.document().documentElement()->renderStyle());
    989989
    990990    FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
     
    10021002    float firstRadius = 0;
    10031003    if (m_firstRadius)
    1004         firstRadius = resolveRadius(m_firstRadius.get(), conversionData);
     1004        firstRadius = resolveRadius(*m_firstRadius, conversionData);
    10051005
    10061006    float secondRadius = 0;
    10071007    float aspectRatio = 1; // width / height.
    10081008    if (m_secondRadius)
    1009         secondRadius = resolveRadius(m_secondRadius.get(), conversionData);
     1009        secondRadius = resolveRadius(*m_secondRadius, conversionData);
    10101010    else if (m_endHorizontalSize) {
    10111011        float width = size.width();
    10121012        float height = size.height();
    1013         secondRadius = resolveRadius(m_endHorizontalSize.get(), conversionData, &width);
     1013        secondRadius = resolveRadius(*m_endHorizontalSize, conversionData, &width);
    10141014        if (m_endVerticalSize)
    1015             aspectRatio = secondRadius / resolveRadius(m_endVerticalSize.get(), conversionData, &height);
     1015            aspectRatio = secondRadius / resolveRadius(*m_endVerticalSize, conversionData, &height);
    10161016        else
    10171017            aspectRatio = 1;
     
    11191119
    11201120    // Now add the stops.
    1121     addStops(gradient.get(), &renderer->view(), conversionData, maxExtent);
     1121    addStops(*gradient, renderer.view(), conversionData, maxExtent);
    11221122
    11231123    return gradient.release();
Note: See TracChangeset for help on using the changeset viewer.