Ignore:
Timestamp:
Apr 29, 2014, 9:36:43 AM (11 years ago)
Author:
Bem Jones-Bey
Message:

Wrap CSS length conversion arguments in an object
https://bugs.webkit.org/show_bug.cgi?id=131552

Reviewed by Andreas Kling.

This patch introduces a class CSSToLengthConversionData to wrap the
data required to convert CSS lengths to Lengths. This simplifies the
plumbing that goes on whenever we need to resolve CSS lengths and
makes it easier to update the arguments needed for resolving these (in
particular adding a RenderView for resolving viewport units at style
recalc time; removing the computingFontSize bool also appears
possible).

Note that the zoom argument, which was previously a float in some
places and a double in others is now a float.

This is a port of a Blink patch by [email protected].

No new tests, no behavior change.

  • CMakeLists.txt:
  • WebCore.vcxproj/WebCore.vcxproj:
  • WebCore.xcodeproj/project.pbxproj:
  • css/BasicShapeFunctions.cpp:

(WebCore::convertToLength):
(WebCore::convertToLengthSize):
(WebCore::convertToCenterCoordinate):
(WebCore::cssValueToBasicShapeRadius):
(WebCore::basicShapeForValue):

  • css/BasicShapeFunctions.h:
  • css/CSSCalculationValue.cpp:

(WebCore::CSSCalcValue::computeLengthPx):
(WebCore::determineCategory):

  • css/CSSCalculationValue.h:

(WebCore::CSSCalcValue::createCalculationValue):

  • css/CSSGradientValue.cpp:

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

  • css/CSSGradientValue.h:
  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::computeLength):
(WebCore::CSSPrimitiveValue::computeLengthDouble):

  • css/CSSPrimitiveValue.h:
  • css/CSSPrimitiveValueMappings.h:

(WebCore::CSSPrimitiveValue::convertToLength):

  • css/CSSToLengthConversionData.cpp: Added.

(WebCore::CSSToLengthConversionData::zoom):

  • css/CSSToLengthConversionData.h: Added.

(WebCore::CSSToLengthConversionData::CSSToLengthConversionData):
(WebCore::CSSToLengthConversionData::style):
(WebCore::CSSToLengthConversionData::rootStyle):
(WebCore::CSSToLengthConversionData::computingFontSize):
(WebCore::CSSToLengthConversionData::copyWithAdjustedZoom):

  • css/CSSToStyleMap.cpp:

(WebCore::CSSToStyleMap::CSSToStyleMap):
(WebCore::CSSToStyleMap::mapFillSize):
(WebCore::CSSToStyleMap::mapFillXPosition):
(WebCore::CSSToStyleMap::mapFillYPosition):
(WebCore::CSSToStyleMap::mapNinePieceImageQuad):

  • css/CSSToStyleMap.h:

(WebCore::CSSToStyleMap::CSSToStyleMap): Deleted.

  • css/DeprecatedStyleBuilder.cpp:

(WebCore::ApplyPropertyAuto::applyValue):
(WebCore::ApplyPropertyClip::convertToLength):
(WebCore::ApplyPropertyLength::applyValue):
(WebCore::ApplyPropertyBorderRadius::applyValue):
(WebCore::ApplyPropertyComputeLength::applyValue):
(WebCore::ApplyPropertyFontSize::applyValue):
(WebCore::csstoLengthConversionDataWithTextZoomFactor):
(WebCore::ApplyPropertyMarqueeIncrement::applyValue):
(WebCore::ApplyPropertyLineHeight::applyValue):
(WebCore::ApplyPropertyLineHeightForIOSTextAutosizing::applyValue):
(WebCore::ApplyPropertyWordSpacing::applyValue):
(WebCore::ApplyPropertyPageSize::mmLength):
(WebCore::ApplyPropertyPageSize::inchLength):
(WebCore::ApplyPropertyPageSize::applyValue):
(WebCore::ApplyPropertyVerticalAlign::applyValue):
(WebCore::ApplyPropertyClipPath::applyValue):
(WebCore::ApplyPropertyShape::applyValue):
(WebCore::ApplyPropertyTextIndent::applyValue):

  • css/MediaQueryEvaluator.cpp:

(WebCore::colorMediaFeatureEval):
(WebCore::color_indexMediaFeatureEval):
(WebCore::monochromeMediaFeatureEval):
(WebCore::orientationMediaFeatureEval):
(WebCore::aspect_ratioMediaFeatureEval):
(WebCore::device_aspect_ratioMediaFeatureEval):
(WebCore::device_pixel_ratioMediaFeatureEval):
(WebCore::resolutionMediaFeatureEval):
(WebCore::gridMediaFeatureEval):
(WebCore::computeLength):
(WebCore::device_heightMediaFeatureEval):
(WebCore::device_widthMediaFeatureEval):
(WebCore::heightMediaFeatureEval):
(WebCore::widthMediaFeatureEval):
(WebCore::min_colorMediaFeatureEval):
(WebCore::max_colorMediaFeatureEval):
(WebCore::min_color_indexMediaFeatureEval):
(WebCore::max_color_indexMediaFeatureEval):
(WebCore::min_monochromeMediaFeatureEval):
(WebCore::max_monochromeMediaFeatureEval):
(WebCore::min_aspect_ratioMediaFeatureEval):
(WebCore::max_aspect_ratioMediaFeatureEval):
(WebCore::min_device_aspect_ratioMediaFeatureEval):
(WebCore::max_device_aspect_ratioMediaFeatureEval):
(WebCore::min_device_pixel_ratioMediaFeatureEval):
(WebCore::max_device_pixel_ratioMediaFeatureEval):
(WebCore::min_heightMediaFeatureEval):
(WebCore::max_heightMediaFeatureEval):
(WebCore::min_widthMediaFeatureEval):
(WebCore::max_widthMediaFeatureEval):
(WebCore::min_device_heightMediaFeatureEval):
(WebCore::max_device_heightMediaFeatureEval):
(WebCore::min_device_widthMediaFeatureEval):
(WebCore::max_device_widthMediaFeatureEval):
(WebCore::min_resolutionMediaFeatureEval):
(WebCore::max_resolutionMediaFeatureEval):
(WebCore::animationMediaFeatureEval):
(WebCore::transitionMediaFeatureEval):
(WebCore::transform_2dMediaFeatureEval):
(WebCore::transform_3dMediaFeatureEval):
(WebCore::view_modeMediaFeatureEval):
(WebCore::video_playable_inlineMediaFeatureEval):
(WebCore::hoverMediaFeatureEval):
(WebCore::pointerMediaFeatureEval):
(WebCore::MediaQueryEvaluator::eval):

  • css/SVGCSSStyleSelector.cpp:

(WebCore::StyleResolver::applySVGProperty):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::State::clear):
(WebCore::StyleResolver::State::initForStyleResolve):
(WebCore::StyleResolver::convertToIntLength):
(WebCore::StyleResolver::convertToFloatLength):
(WebCore::createGridTrackBreadth):
(WebCore::StyleResolver::applyProperty):
(WebCore::StyleResolver::createFilterOperations):

  • css/StyleResolver.h:

(WebCore::StyleResolver::State::setStyle):
(WebCore::StyleResolver::State::cssToLengthConversionData):

  • css/TransformFunctions.cpp:

(WebCore::convertToFloatLength):
(WebCore::transformsForValue):

  • css/TransformFunctions.h:
  • css/WebKitCSSMatrix.cpp:

(WebCore::WebKitCSSMatrix::setMatrixValue):

  • rendering/RenderThemeIOS.mm:

(WebCore::applyCommonButtonPaddingToStyle):
(WebCore::RenderThemeIOS::adjustButtonStyle):

File:
1 edited

Legend:

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

    r166860 r167937  
    2828
    2929#include "CSSCalculationValue.h"
     30#include "CSSToLengthConversionData.h"
    3031#include "CSSValueKeywords.h"
    3132#include "FloatSize.h"
     
    129130}
    130131
    131 void CSSGradientValue::addStops(Gradient* gradient, RenderElement* renderer, const RenderStyle& rootStyle, float maxLengthForRepeat)
    132 {
    133     RenderStyle& style = renderer->style();
    134 
     132void CSSGradientValue::addStops(Gradient* gradient, const CSSToLengthConversionData& conversionData, float maxLengthForRepeat)
     133{
    135134    if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) {
    136135        sortStopsIfNeeded();
     
    182181                float length;
    183182                if (stop.m_position->isLength())
    184                     length = stop.m_position->computeLength<float>(&style, &rootStyle, style.effectiveZoom());
     183                    length = stop.m_position->computeLength<float>(conversionData);
    185184                else {
    186                     Ref<CalculationValue> calculationValue { stop.m_position->cssCalcValue()->createCalculationValue(&style, &rootStyle, style.effectiveZoom()) };
     185                    Ref<CalculationValue> calculationValue { stop.m_position->cssCalcValue()->createCalculationValue(conversionData) };
    187186                    length = calculationValue->evaluate(gradientLength);
    188187                }
     
    393392}
    394393
    395 static float positionFromValue(CSSPrimitiveValue* value, const RenderStyle& style, const RenderStyle& rootStyle, const FloatSize& size, bool isHorizontal)
    396 {
    397     float zoomFactor = style.effectiveZoom();
    398 
     394static float positionFromValue(CSSPrimitiveValue* value, const CSSToLengthConversionData& conversionData, const FloatSize& size, bool isHorizontal)
     395{
    399396    if (value->isNumber())
    400         return value->getFloatValue() * zoomFactor;
     397        return value->getFloatValue() * conversionData.zoom();
    401398
    402399    int edgeDistance = isHorizontal ? size.width() : size.height();
     
    405402
    406403    if (value->isCalculatedPercentageWithLength()) {
    407         Ref<CalculationValue> calculationValue { value->cssCalcValue()->createCalculationValue(&style, &rootStyle, style.effectiveZoom()) };
     404        Ref<CalculationValue> calculationValue { value->cssCalcValue()->createCalculationValue(conversionData) };
    408405        return calculationValue->evaluate(edgeDistance);
    409406    }
     
    426423    }
    427424
    428     return value->computeLength<float>(&style, &rootStyle, zoomFactor);
    429 }
    430 
    431 FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSPrimitiveValue* vertical, const RenderStyle& style, const RenderStyle& rootStyle, const FloatSize& size)
     425    return value->computeLength<float>(conversionData);
     426}
     427
     428FloatPoint CSSGradientValue::computeEndPoint(CSSPrimitiveValue* horizontal, CSSPrimitiveValue* vertical, const CSSToLengthConversionData& conversionData, const FloatSize& size)
    432429{
    433430    FloatPoint result;
    434431
    435432    if (horizontal)
    436         result.setX(positionFromValue(horizontal, style, rootStyle, size, true));
     433        result.setX(positionFromValue(horizontal, conversionData, size, true));
    437434
    438435    if (vertical)
    439         result.setY(positionFromValue(vertical, style, rootStyle, size, false));
     436        result.setY(positionFromValue(vertical, conversionData, size, false));
    440437
    441438    return result;
     
    648645    ASSERT(!size.isEmpty());
    649646
    650     RenderStyle& rootStyle = *renderer->document().documentElement()->renderStyle();
     647    CSSToLengthConversionData conversionData(&renderer->style(), renderer->document().documentElement()->renderStyle());
    651648
    652649    FloatPoint firstPoint;
     
    658655        switch (m_gradientType) {
    659656        case CSSDeprecatedLinearGradient:
    660             firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);
     657            firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
    661658            if (m_secondX || m_secondY)
    662                 secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), renderer->style(), rootStyle, size);
     659                secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size);
    663660            else {
    664661                if (m_firstX)
     
    669666            break;
    670667        case CSSPrefixedLinearGradient:
    671             firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);
     668            firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
    672669            if (m_firstX)
    673670                secondPoint.setX(size.width() - firstPoint.x());
     
    688685                endPointsFromAngle(angle, size, firstPoint, secondPoint, m_gradientType);
    689686            } else if (m_firstX || m_firstY) {
    690                 secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);
     687                secondPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
    691688                if (m_firstX)
    692689                    firstPoint.setX(size.width() - secondPoint.x());
     
    705702
    706703    // Now add the stops.
    707     addStops(gradient.get(), renderer, rootStyle, 1);
     704    addStops(gradient.get(), conversionData, 1);
    708705
    709706    return gradient.release();
     
    892889}
    893890
    894 float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, const RenderStyle& style, const RenderStyle& rootStyle, float* widthOrHeight)
    895 {
    896     float zoomFactor = style.effectiveZoom();
    897 
     891float CSSRadialGradientValue::resolveRadius(CSSPrimitiveValue* radius, const CSSToLengthConversionData& conversionData, float* widthOrHeight)
     892{
    898893    float result = 0;
    899894    if (radius->isNumber()) // Can the radius be a percentage?
    900         result = radius->getFloatValue() * zoomFactor;
     895        result = radius->getFloatValue() * conversionData.zoom();
    901896    else if (widthOrHeight && radius->isPercentage())
    902897        result = *widthOrHeight * radius->getFloatValue() / 100;
    903898    else
    904         result = radius->computeLength<float>(&style, &rootStyle, zoomFactor);
     899        result = radius->computeLength<float>(conversionData);
    905900
    906901    return result;
     
    988983    ASSERT(!size.isEmpty());
    989984
    990     RenderStyle& rootStyle = *renderer->document().documentElement()->renderStyle();
    991 
    992     FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), renderer->style(), rootStyle, size);
     985    CSSToLengthConversionData conversionData(&renderer->style(), renderer->document().documentElement()->renderStyle());
     986
     987    FloatPoint firstPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size);
    993988    if (!m_firstX)
    994989        firstPoint.setX(size.width() / 2);
     
    996991        firstPoint.setY(size.height() / 2);
    997992
    998     FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), renderer->style(), rootStyle, size);
     993    FloatPoint secondPoint = computeEndPoint(m_secondX.get(), m_secondY.get(), conversionData, size);
    999994    if (!m_secondX)
    1000995        secondPoint.setX(size.width() / 2);
     
    1004999    float firstRadius = 0;
    10051000    if (m_firstRadius)
    1006         firstRadius = resolveRadius(m_firstRadius.get(), renderer->style(), rootStyle);
     1001        firstRadius = resolveRadius(m_firstRadius.get(), conversionData);
    10071002
    10081003    float secondRadius = 0;
    10091004    float aspectRatio = 1; // width / height.
    10101005    if (m_secondRadius)
    1011         secondRadius = resolveRadius(m_secondRadius.get(), renderer->style(), rootStyle);
     1006        secondRadius = resolveRadius(m_secondRadius.get(), conversionData);
    10121007    else if (m_endHorizontalSize) {
    10131008        float width = size.width();
    10141009        float height = size.height();
    1015         secondRadius = resolveRadius(m_endHorizontalSize.get(), renderer->style(), rootStyle, &width);
     1010        secondRadius = resolveRadius(m_endHorizontalSize.get(), conversionData, &width);
    10161011        if (m_endVerticalSize)
    1017             aspectRatio = secondRadius / resolveRadius(m_endVerticalSize.get(), renderer->style(), rootStyle, &height);
     1012            aspectRatio = secondRadius / resolveRadius(m_endVerticalSize.get(), conversionData, &height);
    10181013        else
    10191014            aspectRatio = 1;
     
    11211116
    11221117    // Now add the stops.
    1123     addStops(gradient.get(), renderer, rootStyle, maxExtent);
     1118    addStops(gradient.get(), conversionData, maxExtent);
    11241119
    11251120    return gradient.release();
Note: See TracChangeset for help on using the changeset viewer.