Ignore:
Timestamp:
Sep 22, 2013, 6:20:19 PM (12 years ago)
Author:
[email protected]
Message:

Introduce CSS_VALUE_TYPE_CASTS macro in order to cast CSSValue type
https://bugs.webkit.org/show_bug.cgi?id=121462

Reviewed by Andreas Kling.

As r155429 introduced ELEMENT_TYPE_CASTS, CSS_VALUE_TYPE_CASTS can be used
by css value type casting as well. This type cast macros will help to detect
bad-cast bugs as well as improve a code readibility.

This patch adds the following methods,

  • CSSFooValue* toCSSFooValue(CSSValue*)
  • const CSSFooValue* toCSSFooValue(const CSSValue*)

To be consistent with other is*Value() naming style, isCSSLineBoxContainValue() and isCalculationValue()
are changed with isLineBoxContainValue() and isCalcValue().

FontValue, FontFeatureValue, ShadowValue have a manual type case function because of different
class naming style. So, toFontValue(), toFontFeatureValue() and toShadowValue() are added manually.

This patch removes unnecessary local variables.

No new tests, no behavior change.

  • css/CSSAspectRatioValue.h:
  • css/CSSBorderImageSliceValue.h:
  • css/CSSCalculationValue.cpp:

(WebCore::CSSCalcExpressionNodeParser::parseValue):

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

(WebCore::subimageKnownToBeOpaque):

  • css/CSSCrossfadeValue.h:
  • css/CSSCursorImageValue.cpp:

(WebCore::CSSCursorImageValue::~CSSCursorImageValue):
(WebCore::CSSCursorImageValue::updateIfSVGCursorIsUsed):
(WebCore::CSSCursorImageValue::cachedImage):
(WebCore::CSSCursorImageValue::cachedOrPendingImage):
(WebCore::CSSCursorImageValue::isSVGCursor):

  • css/CSSCursorImageValue.h:
  • css/CSSFilterImageValue.h:
  • css/CSSFontSelector.cpp:

(WebCore::CSSFontSelector::addFontFaceRule):

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

(WebCore::CSSImageGeneratorValue::image):
(WebCore::CSSImageGeneratorValue::fixedSize):
(WebCore::CSSImageGeneratorValue::loadSubimages):
(WebCore::CSSImageGeneratorValue::subimageIsPending):
(WebCore::CSSImageGeneratorValue::cachedImageForCSSValue):

  • css/CSSImageGeneratorValue.h:
  • css/CSSImageSetValue.cpp:

(WebCore::CSSImageSetValue::fillImageSet):

  • css/CSSImageSetValue.h:
  • css/CSSImageValue.h:
  • css/CSSInheritedValue.h:
  • css/CSSInitialValue.h:
  • css/CSSLineBoxContainValue.h:
  • css/CSSParser.cpp:

(WebCore::CSSParser::parseColor):
(WebCore::CSSParser::addProperty):
(WebCore::CSSParser::parse3ValuesFillPosition):
(WebCore::CSSParser::parseFillPosition):
(WebCore::CSSParser::parseFillRepeat):
(WebCore::CSSParser::parseDeprecatedRadialGradient):
(WebCore::CSSParser::parseRadialGradient):

  • css/CSSPrimitiveValue.h:
  • css/CSSReflectValue.h:
  • css/CSSToStyleMap.cpp:

(WebCore::CSSToStyleMap::mapFillAttachment):
(WebCore::CSSToStyleMap::mapFillClip):
(WebCore::CSSToStyleMap::mapFillComposite):
(WebCore::CSSToStyleMap::mapFillBlendMode):
(WebCore::CSSToStyleMap::mapFillOrigin):
(WebCore::CSSToStyleMap::mapFillRepeatX):
(WebCore::CSSToStyleMap::mapFillRepeatY):
(WebCore::CSSToStyleMap::mapFillSize):
(WebCore::CSSToStyleMap::mapFillXPosition):
(WebCore::CSSToStyleMap::mapFillYPosition):
(WebCore::CSSToStyleMap::mapFillMaskSourceType):
(WebCore::CSSToStyleMap::mapAnimationDelay):
(WebCore::CSSToStyleMap::mapAnimationDirection):
(WebCore::CSSToStyleMap::mapAnimationDuration):
(WebCore::CSSToStyleMap::mapAnimationFillMode):
(WebCore::CSSToStyleMap::mapAnimationIterationCount):
(WebCore::CSSToStyleMap::mapAnimationName):
(WebCore::CSSToStyleMap::mapAnimationPlayState):
(WebCore::CSSToStyleMap::mapAnimationProperty):
(WebCore::CSSToStyleMap::mapAnimationTimingFunction):
(WebCore::CSSToStyleMap::mapNinePieceImageSlice):
(WebCore::CSSToStyleMap::mapNinePieceImageQuad):
(WebCore::CSSToStyleMap::mapNinePieceImageRepeat):

  • css/CSSValue.cpp:

(WebCore::CSSValue::destroy):

  • css/CSSValue.h:

(WebCore::CSSValue::isLineBoxContainValue):
(WebCore::CSSValue::isCalcValue):

  • css/CSSValueList.h:
  • css/CSSVariableValue.h:
  • css/DeprecatedStyleBuilder.cpp:

(WebCore::ApplyPropertyDefault::applyValue):
(WebCore::ApplyPropertyNumber::applyValue):
(WebCore::ApplyPropertyAuto::applyValue):
(WebCore::ApplyPropertyClip::applyValue):
(WebCore::ApplyPropertyColor::applyValue):
(WebCore::ApplyPropertyLength::applyValue):
(WebCore::ApplyPropertyString::applyValue):
(WebCore::ApplyPropertyBorderRadius::applyValue):
(WebCore::ApplyPropertyComputeLength::applyValue):
(WebCore::ApplyPropertyFont::applyValue):
(WebCore::ApplyPropertyFontFamily::applyValue):
(WebCore::ApplyPropertyFontSize::applyValue):
(WebCore::ApplyPropertyFontWeight::applyValue):
(WebCore::ApplyPropertyFontVariantLigatures::applyValue):
(WebCore::ApplyPropertyCounter::applyValue):
(WebCore::ApplyPropertyCursor::applyValue):
(WebCore::ApplyPropertyTextAlign::applyValue):
(WebCore::ApplyPropertyTextDecoration::applyValue):
(WebCore::ApplyPropertyMarqueeIncrement::applyValue):
(WebCore::ApplyPropertyMarqueeRepetition::applyValue):
(WebCore::ApplyPropertyMarqueeSpeed::applyValue):
(WebCore::ApplyPropertyTextUnderlinePosition::applyValue):
(WebCore::ApplyPropertyLineHeight::applyValue):
(WebCore::ApplyPropertyLineHeightForIOSTextAutosizing::applyValue):
(WebCore::ApplyPropertyPageSize::applyValue):
(WebCore::ApplyPropertyTextEmphasisStyle::applyValue):
(WebCore::ApplyPropertyResize::applyValue):
(WebCore::ApplyPropertyVerticalAlign::applyValue):
(WebCore::ApplyPropertyAspectRatio::applyValue):
(WebCore::ApplyPropertyZoom::applyValue):
(WebCore::ApplyPropertyDisplay::applyValue):
(WebCore::ApplyPropertyClipPath::applyValue):
(WebCore::ApplyPropertyShape::applyValue):
(WebCore::ApplyPropertyImageResolution::applyValue):
(WebCore::ApplyPropertyTextIndent::applyValue):

  • css/FontFeatureValue.h:

(WebCore::toFontFeatureValue):

  • css/FontValue.h:

(WebCore::toFontValue):

  • css/MediaList.cpp:

(WebCore::reportMediaQueryWarningIfNeeded):

  • css/MediaQueryEvaluator.cpp:

(WebCore::compareAspectRatioValue):
(WebCore::numberValue):
(WebCore::orientationMediaFeatureEval):
(WebCore::evalResolution):
(WebCore::device_pixel_ratioMediaFeatureEval):
(WebCore::resolutionMediaFeatureEval):
(WebCore::computeLength):
(WebCore::view_modeMediaFeatureEval):
(WebCore::pointerMediaFeatureEval):

  • css/SVGCSSStyleSelector.cpp:

(WebCore::StyleResolver::applySVGProperty):

  • css/ShadowValue.h:

(WebCore::toShadowValue):

  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::getLayeredShorthandValue):

  • css/StyleResolver.cpp:

(WebCore::createGridTrackSize):
(WebCore::createGridTrackList):
(WebCore::createGridPosition):
(WebCore::hasVariableReference):
(WebCore::StyleResolver::applyProperty):
(WebCore::StyleResolver::styleImage):
(WebCore::StyleResolver::generatedOrPendingFromValue):
(WebCore::StyleResolver::styleShader):
(WebCore::StyleResolver::parseCustomFilterArrayParameter):
(WebCore::StyleResolver::parseCustomFilterColorParameter):
(WebCore::StyleResolver::parseCustomFilterNumberParameter):
(WebCore::StyleResolver::parseCustomFilterParameter):
(WebCore::StyleResolver::parseCustomFilterParameterList):
(WebCore::StyleResolver::createCustomFilterOperationWithInlineSyntax):
(WebCore::StyleResolver::createFilterOperations):

  • css/TransformFunctions.cpp:

(WebCore::transformsForValue):

  • css/ViewportStyleResolver.cpp:

(WebCore::ViewportStyleResolver::getViewportArgumentValue):

  • css/WebKitCSSMatrix.cpp:

(WebCore::WebKitCSSMatrix::setMatrixValue):

  • css/WebKitCSSShaderValue.h:

(WebCore::toWebKitCSSShaderValue):

  • editing/ApplyStyleCommand.cpp:

(WebCore::ApplyStyleCommand::computedFontSize):

  • editing/EditingStyle.cpp:

(WebCore::identifierForStyleProperty):
(WebCore::HTMLElementEquivalent::valueIsPresentInStyle):
(WebCore::cssValueToRGBA):
(WebCore::EditingStyle::extractFontSizeDelta):
(WebCore::EditingStyle::textDirection):
(WebCore::EditingStyle::prepareToApplyAt):
(WebCore::EditingStyle::mergeStyleFromRulesForSerialization):
(WebCore::EditingStyle::legacyFontSize):
(WebCore::EditingStyle::textDirectionForSelection):
(WebCore::StyleChange::extractTextStyles):
(WebCore::fontWeightIsBold):
(WebCore::isTransparentColorValue):

  • editing/markup.cpp:

(WebCore::propertyMissingOrEqualToNone):

  • page/PageSerializer.cpp:

(WebCore::PageSerializer::retrieveResourcesForProperties):

  • rendering/style/StylePendingImage.h:

(WebCore::StylePendingImage::data):
(WebCore::StylePendingImage::cssImageValue):
(WebCore::StylePendingImage::cssImageGeneratorValue):
(WebCore::StylePendingImage::cssCursorImageValue):
(WebCore::StylePendingImage::cssImageSetValue):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r155496 r156253  
    145145    if (!value || !value->isPrimitiveValue())
    146146        return 0;
    147     return static_cast<CSSPrimitiveValue*>(value.get())->getValueID();
     147    return toCSSPrimitiveValue(value.get())->getValueID();
    148148}
    149149
     
    202202{
    203203    RefPtr<CSSValue> value = style->getPropertyCSSValue(m_propertyID);
    204     return matches(element) && value && value->isPrimitiveValue() && static_cast<CSSPrimitiveValue*>(value.get())->getValueID() == m_primitiveValue->getValueID();
     204    return matches(element) && value && value->isPrimitiveValue() && toCSSPrimitiveValue(value.get())->getValueID() == m_primitiveValue->getValueID();
    205205}
    206206
     
    379379        return Color::transparent;
    380380   
    381     CSSPrimitiveValue* primitiveColor = static_cast<CSSPrimitiveValue*>(colorValue);
     381    CSSPrimitiveValue* primitiveColor = toCSSPrimitiveValue(colorValue);
    382382    if (primitiveColor->isRGBColor())
    383383        return primitiveColor->getRGBA32Value();
     
    499499        return;
    500500
    501     CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value.get());
     501    CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get());
    502502
    503503    // Only PX handled now. If we handle more types in the future, perhaps
     
    524524        return false;
    525525
    526     CSSValueID unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getValueID();
     526    CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi.get())->getValueID();
    527527    if (unicodeBidiValue == CSSValueEmbed) {
    528528        RefPtr<CSSValue> direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
     
    530530            return false;
    531531
    532         writingDirection = static_cast<CSSPrimitiveValue*>(direction.get())->getValueID() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
     532        writingDirection = toCSSPrimitiveValue(direction.get())->getValueID() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
    533533
    534534        return true;
     
    950950
    951951    if (unicodeBidi && unicodeBidi->isPrimitiveValue()) {
    952         m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSValueID>(static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getValueID()));
     952        m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSValueID>(toCSSPrimitiveValue(unicodeBidi.get())->getValueID()));
    953953        if (direction && direction->isPrimitiveValue())
    954             m_mutableStyle->setProperty(CSSPropertyDirection, static_cast<CSSValueID>(static_cast<CSSPrimitiveValue*>(direction.get())->getValueID()));
     954            m_mutableStyle->setProperty(CSSPropertyDirection, static_cast<CSSValueID>(toCSSPrimitiveValue(direction.get())->getValueID()));
    955955    }
    956956}
     
    11501150            if (!value->isPrimitiveValue())
    11511151                continue;
    1152             if (static_cast<CSSPrimitiveValue*>(value)->isPercentage()) {
     1152            if (toCSSPrimitiveValue(value)->isPercentage()) {
    11531153                if (RefPtr<CSSValue> computedPropertyValue = computedStyle.propertyValue(property.id()))
    11541154                    fromComputedStyle->addParsedProperty(CSSProperty(property.id(), computedPropertyValue.release()));
     
    12231223    if (!cssValue || !cssValue->isPrimitiveValue())
    12241224        return 0;
    1225     return legacyFontSizeFromCSSValue(document, static_cast<CSSPrimitiveValue*>(cssValue.get()),
     1225    return legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(cssValue.get()),
    12261226        m_shouldUseFixedDefaultFontSize, AlwaysUseLegacyFontSize);
    12271227}
     
    12871287                continue;
    12881288
    1289             CSSValueID unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getValueID();
     1289            CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi.get())->getValueID();
    12901290            if (unicodeBidiValue == CSSValueEmbed || unicodeBidiValue == CSSValueBidiOverride)
    12911291                return NaturalWritingDirection;
     
    13161316            continue;
    13171317
    1318         CSSValueID unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getValueID();
     1318        CSSValueID unicodeBidiValue = toCSSPrimitiveValue(unicodeBidi.get())->getValueID();
    13191319        if (unicodeBidiValue == CSSValueNormal)
    13201320            continue;
     
    13281328            continue;
    13291329
    1330         CSSValueID directionValue = static_cast<CSSPrimitiveValue*>(direction.get())->getValueID();
     1330        CSSValueID directionValue = toCSSPrimitiveValue(direction.get())->getValueID();
    13311331        if (directionValue != CSSValueLtr && directionValue != CSSValueRtl)
    13321332            continue;
     
    14681468        if (!fontSize->isPrimitiveValue())
    14691469            style->removeProperty(CSSPropertyFontSize); // Can't make sense of the number. Put no font size.
    1470         else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, static_cast<CSSPrimitiveValue*>(fontSize.get()),
     1470        else if (int legacyFontSize = legacyFontSizeFromCSSValue(document, toCSSPrimitiveValue(fontSize.get()),
    14711471                shouldUseFixedFontDefaultSize, UseLegacyFontSizeOnlyIfPixelValuesMatch)) {
    14721472            m_applyFontSize = String::number(legacyFontSize);
     
    15001500    // Because b tag can only bold text, there are only two states in plain html: bold and not bold.
    15011501    // Collapse all other values to either one of these two states for editing purposes.
    1502     switch (static_cast<CSSPrimitiveValue*>(fontWeight)->getValueID()) {
     1502    switch (toCSSPrimitiveValue(fontWeight)->getValueID()) {
    15031503        case CSSValue100:
    15041504        case CSSValue200:
     
    15941594    if (!cssValue->isPrimitiveValue())
    15951595        return false;
    1596     CSSPrimitiveValue* value = static_cast<CSSPrimitiveValue*>(cssValue);   
     1596    CSSPrimitiveValue* value = toCSSPrimitiveValue(cssValue);   
    15971597    if (value->isRGBColor())
    15981598        return !alphaChannel(value->getRGBA32Value());   
Note: See TracChangeset for help on using the changeset viewer.