Changeset 88553 in webkit


Ignore:
Timestamp:
Jun 10, 2011 11:17:21 AM (13 years ago)
Author:
macpherson@chromium.org
Message:

2011-06-10 Luke Macpherson <macpherson@chromium.org>

Reviewed by Eric Seidel.

Clean up CSSPrimitiveValue::computeLength*
https://bugs.webkit.org/show_bug.cgi?id=61612

No new tests as no functionality changed.

  • css/CSSGradientValue.cpp: Use new computeLength functions.
  • css/CSSPrimitiveValue.cpp: (WebCore::CSSPrimitiveValue::computeLengthIntForLength): Reduce to a single function using default parameter values. (WebCore::CSSPrimitiveValue::computeLength): Redefine existing functions with separate names as a single function using templated function specialization.
  • css/CSSPrimitiveValue.h: Prototypes for computeLengthIntForLength and computeLength.
  • css/CSSStyleApplyProperty.cpp: Use new computeLength functions.
  • css/CSSStyleSelector.cpp: Use new computeLength functions.
  • css/MediaQueryEvaluator.cpp: Use new computeLength functions.
  • css/SVGCSSStyleSelector.cpp: Use new computeLength functions.
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r88552 r88553  
     12011-06-10  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Clean up CSSPrimitiveValue::computeLength*
     6        https://bugs.webkit.org/show_bug.cgi?id=61612
     7
     8        No new tests as no functionality changed.
     9
     10        * css/CSSGradientValue.cpp:
     11        Use new computeLength functions.
     12        * css/CSSPrimitiveValue.cpp:
     13        (WebCore::CSSPrimitiveValue::computeLengthIntForLength):
     14        Reduce to a single function using default parameter values.
     15        (WebCore::CSSPrimitiveValue::computeLength):
     16        Redefine existing functions with separate names as a single function using templated function specialization.
     17        * css/CSSPrimitiveValue.h:
     18        Prototypes for computeLengthIntForLength and computeLength.
     19        * css/CSSStyleApplyProperty.cpp:
     20        Use new computeLength functions.
     21        * css/CSSStyleSelector.cpp:
     22        Use new computeLength functions.
     23        * css/MediaQueryEvaluator.cpp:
     24        Use new computeLength functions.
     25        * css/SVGCSSStyleSelector.cpp:
     26        Use new computeLength functions.
     27
    1282011-06-10  Simon Fraser  <simon.fraser@apple.com>
    229
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r87389 r88553  
    160160                stops[i].offset = stop.m_position->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) / 100;
    161161            else if (CSSPrimitiveValue::isUnitTypeLength(type)) {
    162                 float length = stop.m_position->computeLengthFloat(style, rootStyle, style->effectiveZoom());
     162                float length = stop.m_position->computeLength<float>(style, rootStyle, style->effectiveZoom());
    163163                if (!computedGradientLength) {
    164164                    FloatSize gradientSize(gradientStart - gradientEnd);
     
    392392
    393393    default:
    394         return value->computeLengthFloat(style, rootStyle, zoomFactor);
     394        return value->computeLength<float>(style, rootStyle, zoomFactor);
    395395    }
    396396}
     
    645645        result = *widthOrHeight * radius->getFloatValue() / 100;
    646646    else
    647         result = radius->computeLengthFloat(style, rootStyle, zoomFactor);
     647        result = radius->computeLength<float>(style, rootStyle, zoomFactor);
    648648 
    649649    return result;
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r80463 r88553  
    250250}
    251251
    252 int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle)
    253 {
    254     return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle));
    255 }
    256 
    257 int CSSPrimitiveValue::computeLengthInt(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
    258 {
    259     return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier));
     252template<> int CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
     253{
     254    return roundForImpreciseConversion<int, INT_MAX, INT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
    260255}
    261256
    262257// Lengths expect an int that is only 28-bits, so we have to check for a
    263258// different overflow.
    264 int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle)
    265 {
    266     return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle));
    267 }
    268 
    269 int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
    270 {
    271     return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle, multiplier));
    272 }
    273 
    274 short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle)
    275 {
    276     return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle));
    277 }
    278 
    279 short CSSPrimitiveValue::computeLengthShort(RenderStyle* style, RenderStyle* rootStyle, double multiplier)
    280 {
    281     return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier));
    282 }
    283 
    284 float CSSPrimitiveValue::computeLengthFloat(RenderStyle* style, RenderStyle* rootStyle, bool computingFontSize)
    285 {
    286     return static_cast<float>(computeLengthDouble(style, rootStyle, 1.0, computingFontSize));
    287 }
    288 
    289 float CSSPrimitiveValue::computeLengthFloat(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
     259int CSSPrimitiveValue::computeLengthIntForLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
     260{
     261    return roundForImpreciseConversion<int, intMaxForLength, intMinForLength>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
     262}
     263
     264template<> Length CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
     265{
     266    return Length(computeLengthIntForLength(style, rootStyle, multiplier, computingFontSize), Fixed);
     267}
     268
     269template<> short CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
     270{
     271    return roundForImpreciseConversion<short, SHRT_MAX, SHRT_MIN>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
     272}
     273
     274template<> float CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
    290275{
    291276    return static_cast<float>(computeLengthDouble(style, rootStyle, multiplier, computingFontSize));
     277}
     278
     279template<> double CSSPrimitiveValue::computeLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
     280{
     281    return computeLengthDouble(style, rootStyle, multiplier, computingFontSize);
    292282}
    293283
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r87771 r88553  
    137137     * and some tool to calibrate.
    138138     */
    139     int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle);
    140     int computeLengthInt(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
    141     int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle);
    142     int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
    143     short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle);
    144     short computeLengthShort(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier);
    145     float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, bool computingFontSize = false);
    146     float computeLengthFloat(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize = false);
    147     double computeLengthDouble(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
     139    template<typename T> T computeLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
     140    int computeLengthIntForLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
    148141
    149142    // use with care!!!
     
    221214    void init(PassRefPtr<DashboardRegion>); // FIXME: Dashboard region should not be a primitive value.
    222215    bool getDoubleValueInternal(UnitTypes targetUnitType, double* result) const;
     216
     217    double computeLengthDouble(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier, bool computingFontSize);
    223218
    224219    virtual bool isPrimitiveValue() const { return true; }
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r88525 r88553  
    372372            break;
    373373        case CSSValueInvalid:
    374             width = primitiveValue->computeLengthShort(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
     374            width = primitiveValue->computeLength<short>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
    375375            // CSS2 box model does not allow negative lengths for borders.
    376376            if (width < 0)
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r88526 r88553  
    33453345        } else if (CSSPrimitiveValue::isUnitTypeLength(type)) {
    33463346            if (toFloat)
    3347                 l = Length(primitiveValue->computeLengthDouble(style, rootStyle, multiplier), Fixed);
     3347                l = Length(primitiveValue->computeLength<double>(style, rootStyle, multiplier), Fixed);
    33483348            else
    33493349                l = Length(primitiveValue->computeLengthIntForLength(style, rootStyle, multiplier), Fixed);
     
    37413741        if (!primitiveValue)
    37423742            return;
    3743         short spacing = primitiveValue->computeLengthShort(style(), m_rootElementStyle, zoomFactor);
     3743        short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor);
    37443744        m_style->setHorizontalBorderSpacing(spacing);
    37453745        return;
     
    37493749        if (!primitiveValue)
    37503750            return;
    3751         short spacing = primitiveValue->computeLengthShort(style(), m_rootElementStyle, zoomFactor);
     3751        short spacing = primitiveValue->computeLength<short>(style(), m_rootElementStyle, zoomFactor);
    37523752        m_style->setVerticalBorderSpacing(spacing);
    37533753        return;
     
    38183818            if (!primitiveValue)
    38193819                return;
    3820             width = primitiveValue->computeLengthInt(style(), m_rootElementStyle, useSVGZoomRules(m_element) ? 1.0f : zoomFactor);
     3820            width = primitiveValue->computeLength<int>(style(), m_rootElementStyle, useSVGZoomRules(m_element) ? 1.0f : zoomFactor);
    38213821        }
    38223822        switch (id) {
     
    39433943                                               type != CSSPrimitiveValue::CSS_REMS));
    39443944            if (CSSPrimitiveValue::isUnitTypeLength(type))
    3945                 size = primitiveValue->computeLengthFloat(m_parentStyle, m_rootElementStyle, true);
     3945                size = primitiveValue->computeLength<float>(m_parentStyle, m_rootElementStyle, 1.0, true);
    39463946            else if (type == CSSPrimitiveValue::CSS_PERCENTAGE)
    39473947                size = (primitiveValue->getFloatValue() * oldSize) / 100.0f;
     
    45634563            radiusWidth = Length(pair->first()->getDoubleValue(), Percent);
    45644564        else
    4565             radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLengthInt(style(), m_rootElementStyle, zoomFactor))), Fixed);
     4565            radiusWidth = Length(max(intMinForLength, min(intMaxForLength, pair->first()->computeLength<int>(style(), m_rootElementStyle, zoomFactor))), Fixed);
    45664566        if (pair->second()->primitiveType() == CSSPrimitiveValue::CSS_PERCENTAGE)
    45674567            radiusHeight = Length(pair->second()->getDoubleValue(), Percent);
    45684568        else
    4569             radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLengthInt(style(), m_rootElementStyle, zoomFactor))), Fixed);
     4569            radiusHeight = Length(max(intMinForLength, min(intMaxForLength, pair->second()->computeLength<int>(style(), m_rootElementStyle, zoomFactor))), Fixed);
    45704570        int width = radiusWidth.value();
    45714571        int height = radiusHeight.value();
     
    46004600    case CSSPropertyOutlineOffset:
    46014601        HANDLE_INHERIT_AND_INITIAL(outlineOffset, OutlineOffset)
    4602         m_style->setOutlineOffset(primitiveValue->computeLengthInt(style(), m_rootElementStyle, zoomFactor));
     4602        m_style->setOutlineOffset(primitiveValue->computeLength<int>(style(), m_rootElementStyle, zoomFactor));
    46034603        return;
    46044604    case CSSPropertyImageRendering:
     
    46284628                continue;
    46294629            ShadowValue* item = static_cast<ShadowValue*>(list->itemWithoutBoundsCheck(i));
    4630             int x = item->x->computeLengthInt(style(), m_rootElementStyle, zoomFactor);
    4631             int y = item->y->computeLengthInt(style(), m_rootElementStyle, zoomFactor);
    4632             int blur = item->blur ? item->blur->computeLengthInt(style(), m_rootElementStyle, zoomFactor) : 0;
    4633             int spread = item->spread ? item->spread->computeLengthInt(style(), m_rootElementStyle, zoomFactor) : 0;
     4630            int x = item->x->computeLength<int>(style(), m_rootElementStyle, zoomFactor);
     4631            int y = item->y->computeLength<int>(style(), m_rootElementStyle, zoomFactor);
     4632            int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle, zoomFactor) : 0;
     4633            int spread = item->spread ? item->spread->computeLength<int>(style(), m_rootElementStyle, zoomFactor) : 0;
    46344634            ShadowStyle shadowStyle = item->style && item->style->getIdent() == CSSValueInset ? Inset : Normal;
    46354635            Color color;
     
    47614761            return;
    47624762        }
    4763         m_style->setColumnGap(primitiveValue->computeLengthFloat(style(), m_rootElementStyle, zoomFactor));
     4763        m_style->setColumnGap(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor));
    47644764        return;
    47654765    }
     
    47804780            return;
    47814781        }
    4782         m_style->setColumnWidth(primitiveValue->computeLengthFloat(style(), m_rootElementStyle, zoomFactor));
     4782        m_style->setColumnWidth(primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor));
    47834783        return;
    47844784    }
     
    50575057                else if (primitiveValue->getIdent() == CSSValueThick)
    50585058                    result *= 5;
    5059                 width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLengthFloat(style(), m_rootElementStyle, zoomFactor);
     5059                width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLength<float>(style(), m_rootElementStyle, zoomFactor);
    50605060                break;
    50615061            }
    50625062            default:
    5063                 width = primitiveValue->computeLengthFloat(style(), m_rootElementStyle, zoomFactor);
     5063                width = primitiveValue->computeLength<float>(style(), m_rootElementStyle, zoomFactor);
    50645064                break;
    50655065        }
     
    51105110        else if (type == CSSPrimitiveValue::CSS_NUMBER) {
    51115111            // For backward compatibility, treat valueless numbers as px.
    5112             perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLengthFloat(style(), m_rootElementStyle, zoomFactor);
     5112            perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLength<float>(style(), m_rootElementStyle, zoomFactor);
    51135113        } else
    51145114            return;
  • trunk/Source/WebCore/css/MediaQueryEvaluator.cpp

    r72954 r88553  
    312312        FloatRect sg = screenRect(frame->page()->mainFrame()->view());
    313313        RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
    314         return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
     314        return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.height()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
    315315    }
    316316    // ({,min-,max-}device-height)
     
    324324        FloatRect sg = screenRect(frame->page()->mainFrame()->view());
    325325        RenderStyle* rootStyle = frame->document()->documentElement()->renderStyle();
    326         return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
     326        return value->isPrimitiveValue() && compareValue(static_cast<int>(sg.width()), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
    327327    }
    328328    // ({,min-,max-}device-width)
     
    337337
    338338    if (value)
    339         return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
     339        return value->isPrimitiveValue() && compareValue(view->layoutHeight(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
    340340
    341341    return view->layoutHeight() != 0;
     
    348348
    349349    if (value)
    350         return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLengthInt(style, rootStyle), op);
     350        return value->isPrimitiveValue() && compareValue(view->layoutWidth(), static_cast<CSSPrimitiveValue*>(value)->computeLength<int>(style, rootStyle), op);
    351351
    352352    return view->layoutWidth() != 0;
  • trunk/Source/WebCore/css/SVGCSSStyleSelector.cpp

    r88266 r88553  
    573573                return;
    574574            ShadowValue* item = static_cast<ShadowValue*>(firstValue);
    575             int x = item->x->computeLengthInt(style(), m_rootElementStyle);
    576             int y = item->y->computeLengthInt(style(), m_rootElementStyle);
    577             int blur = item->blur ? item->blur->computeLengthInt(style(), m_rootElementStyle) : 0;
     575            int x = item->x->computeLength<int>(style(), m_rootElementStyle);
     576            int y = item->y->computeLength<int>(style(), m_rootElementStyle);
     577            int blur = item->blur ? item->blur->computeLength<int>(style(), m_rootElementStyle) : 0;
    578578            Color color;
    579579            if (item->color)
Note: See TracChangeset for help on using the changeset viewer.