/* * Copyright (C) 2011 Andreas Kling (kling@webkit.org) * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include "config.h" #include "CSSValue.h" #include "CSSAspectRatioValue.h" #include "CSSBorderImageSliceValue.h" #include "CSSCalcValue.h" #include "CSSCanvasValue.h" #include "CSSContentDistributionValue.h" #include "CSSCrossfadeValue.h" #include "CSSCursorImageValue.h" #include "CSSCustomPropertyValue.h" #include "CSSFilterImageValue.h" #include "CSSFontFaceSrcValue.h" #include "CSSFontFeatureValue.h" #include "CSSFontStyleRangeValue.h" #include "CSSFontStyleValue.h" #include "CSSFontValue.h" #include "CSSFontVariationValue.h" #include "CSSFunctionValue.h" #include "CSSGradientValue.h" #include "CSSImageSetValue.h" #include "CSSImageValue.h" #include "CSSInheritedValue.h" #include "CSSInitialValue.h" #include "CSSLineBoxContainValue.h" #include "CSSNamedImageValue.h" #include "CSSPaintImageValue.h" #include "CSSPendingSubstitutionValue.h" #include "CSSPrimitiveValue.h" #include "CSSProperty.h" #include "CSSReflectValue.h" #include "CSSShadowValue.h" #include "CSSTimingFunctionValue.h" #include "CSSUnicodeRangeValue.h" #include "CSSUnsetValue.h" #include "CSSValueList.h" #include "CSSValuePair.h" #include "CSSVariableReferenceValue.h" #include "CSSGridAutoRepeatValue.h" #include "CSSGridIntegerRepeatValue.h" #include "CSSGridLineNamesValue.h" #include "CSSGridTemplateAreasValue.h" #include "DeprecatedCSSOMPrimitiveValue.h" #include "DeprecatedCSSOMValueList.h" namespace WebCore { struct SameSizeAsCSSValue { uint32_t refCount; uint32_t bitfields; }; COMPILE_ASSERT(sizeof(CSSValue) == sizeof(SameSizeAsCSSValue), CSS_value_should_stay_small); bool CSSValue::isImplicitInitialValue() const { return m_classType == InitialClass && downcast(*this).isImplicit(); } DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(CSSValue); CSSValue::Type CSSValue::cssValueType() const { if (isInheritedValue()) return CSS_INHERIT; if (isPrimitiveValue()) return CSS_PRIMITIVE_VALUE; if (isValueList()) return CSS_VALUE_LIST; if (isInitialValue()) return CSS_INITIAL; if (isUnsetValue()) return CSS_UNSET; if (isRevertValue()) return CSS_REVERT; return CSS_CUSTOM; } bool CSSValue::traverseSubresources(const WTF::Function& handler) const { if (is(*this)) return downcast(*this).traverseSubresources(handler); if (is(*this)) return downcast(*this).traverseSubresources(handler); if (is(*this)) return downcast(*this).traverseSubresources(handler); if (is(*this)) return downcast(*this).traverseSubresources(handler); if (is(*this)) return downcast(*this).traverseSubresources(handler); if (is(*this)) return downcast(*this).traverseSubresources(handler); return false; } void CSSValue::collectDirectComputationalDependencies(HashSet& values) const { if (is(*this)) downcast(*this).collectDirectComputationalDependencies(values); } void CSSValue::collectDirectRootComputationalDependencies(HashSet& values) const { if (is(*this)) downcast(*this).collectDirectRootComputationalDependencies(values); } template inline static bool compareCSSValues(const CSSValue& first, const CSSValue& second) { return static_cast(first).equals(static_cast(second)); } bool CSSValue::equals(const CSSValue& other) const { if (m_classType == other.m_classType) { switch (m_classType) { case AspectRatioClass: return compareCSSValues(*this, other); case BorderImageSliceClass: return compareCSSValues(*this, other); case CanvasClass: return compareCSSValues(*this, other); case NamedImageClass: return compareCSSValues(*this, other); case CursorImageClass: return compareCSSValues(*this, other); case FilterImageClass: return compareCSSValues(*this, other); #if ENABLE(CSS_PAINTING_API) case PaintImageClass: return compareCSSValues(*this, other); #endif case FontClass: return compareCSSValues(*this, other); case FontFaceSrcClass: return compareCSSValues(*this, other); case FontFeatureClass: return compareCSSValues(*this, other); case FontVariationClass: return compareCSSValues(*this, other); case FunctionClass: return compareCSSValues(*this, other); case LinearGradientClass: return compareCSSValues(*this, other); case RadialGradientClass: return compareCSSValues(*this, other); case ConicGradientClass: return compareCSSValues(*this, other); case CrossfadeClass: return compareCSSValues(*this, other); case ImageClass: return compareCSSValues(*this, other); case InheritedClass: return compareCSSValues(*this, other); case InitialClass: return compareCSSValues(*this, other); case UnsetClass: return compareCSSValues(*this, other); case RevertClass: return compareCSSValues(*this, other); case GridAutoRepeatClass: return compareCSSValues(*this, other); case GridIntegerRepeatClass: return compareCSSValues(*this, other); case GridLineNamesClass: return compareCSSValues(*this, other); case GridTemplateAreasClass: return compareCSSValues(*this, other); case PrimitiveClass: return compareCSSValues(*this, other); case ReflectClass: return compareCSSValues(*this, other); case ShadowClass: return compareCSSValues(*this, other); case CubicBezierTimingFunctionClass: return compareCSSValues(*this, other); case StepsTimingFunctionClass: return compareCSSValues(*this, other); case SpringTimingFunctionClass: return compareCSSValues(*this, other); case UnicodeRangeClass: return compareCSSValues(*this, other); case ValueListClass: return compareCSSValues(*this, other); case LineBoxContainClass: return compareCSSValues(*this, other); case CalculationClass: return compareCSSValues(*this, other); case ImageSetClass: return compareCSSValues(*this, other); case CSSContentDistributionClass: return compareCSSValues(*this, other); case CustomPropertyClass: return compareCSSValues(*this, other); case VariableReferenceClass: return compareCSSValues(*this, other); case PendingSubstitutionValueClass: return compareCSSValues(*this, other); case FontStyleClass: return compareCSSValues(*this, other); case FontStyleRangeClass: return compareCSSValues(*this, other); default: ASSERT_NOT_REACHED(); return false; } } else if (is(*this) && !is(other)) return downcast(*this).equals(other); else if (!is(*this) && is(other)) return static_cast(other).equals(*this); return false; } String CSSValue::cssText() const { switch (classType()) { case AspectRatioClass: return downcast(*this).customCSSText(); case BorderImageSliceClass: return downcast(*this).customCSSText(); case CanvasClass: return downcast(*this).customCSSText(); case NamedImageClass: return downcast(*this).customCSSText(); case CursorImageClass: return downcast(*this).customCSSText(); case FilterImageClass: return downcast(*this).customCSSText(); #if ENABLE(CSS_PAINTING_API) case PaintImageClass: return downcast(*this).customCSSText(); #endif case FontClass: return downcast(*this).customCSSText(); case FontFaceSrcClass: return downcast(*this).customCSSText(); case FontFeatureClass: return downcast(*this).customCSSText(); case FontVariationClass: return downcast(*this).customCSSText(); case FunctionClass: return downcast(*this).customCSSText(); case LinearGradientClass: return downcast(*this).customCSSText(); case RadialGradientClass: return downcast(*this).customCSSText(); case ConicGradientClass: return downcast(*this).customCSSText(); case CrossfadeClass: return downcast(*this).customCSSText(); case ImageClass: return downcast(*this).customCSSText(); case InheritedClass: return downcast(*this).customCSSText(); case InitialClass: return downcast(*this).customCSSText(); case UnsetClass: return downcast(*this).customCSSText(); case RevertClass: return downcast(*this).customCSSText(); case GridAutoRepeatClass: return downcast(*this).customCSSText(); case GridIntegerRepeatClass: return downcast(*this).customCSSText(); case GridLineNamesClass: return downcast(*this).customCSSText(); case GridTemplateAreasClass: return downcast(*this).customCSSText(); case PrimitiveClass: return downcast(*this).customCSSText(); case ReflectClass: return downcast(*this).customCSSText(); case ShadowClass: return downcast(*this).customCSSText(); case CubicBezierTimingFunctionClass: return downcast(*this).customCSSText(); case StepsTimingFunctionClass: return downcast(*this).customCSSText(); case SpringTimingFunctionClass: return downcast(*this).customCSSText(); case UnicodeRangeClass: return downcast(*this).customCSSText(); case ValueListClass: return downcast(*this).customCSSText(); case ValuePairClass: return downcast(*this).customCSSText(); case LineBoxContainClass: return downcast(*this).customCSSText(); case CalculationClass: return downcast(*this).customCSSText(); case ImageSetClass: return downcast(*this).customCSSText(); case CSSContentDistributionClass: return downcast(*this).customCSSText(); case CustomPropertyClass: return downcast(*this).customCSSText(); case VariableReferenceClass: return downcast(*this).customCSSText(); case PendingSubstitutionValueClass: return downcast(*this).customCSSText(); case FontStyleClass: return downcast(*this).customCSSText(); case FontStyleRangeClass: return downcast(*this).customCSSText(); } ASSERT_NOT_REACHED(); return String(); } ASCIILiteral CSSValue::separatorCSSText() const { switch (m_valueSeparator) { case SpaceSeparator: return " "_s; case CommaSeparator: return ", "_s; case SlashSeparator: return " / "_s; default: ASSERT_NOT_REACHED(); } return " "_s; } void CSSValue::destroy() { switch (classType()) { case AspectRatioClass: delete downcast(this); return; case BorderImageSliceClass: delete downcast(this); return; case CanvasClass: delete downcast(this); return; case NamedImageClass: delete downcast(this); return; case CursorImageClass: delete downcast(this); return; case FontClass: delete downcast(this); return; case FontFaceSrcClass: delete downcast(this); return; case FontFeatureClass: delete downcast(this); return; case FontVariationClass: delete downcast(this); return; case FunctionClass: delete downcast(this); return; case LinearGradientClass: delete downcast(this); return; case RadialGradientClass: delete downcast(this); return; case ConicGradientClass: delete downcast(this); return; case CrossfadeClass: delete downcast(this); return; case ImageClass: delete downcast(this); return; case InheritedClass: delete downcast(this); return; case InitialClass: delete downcast(this); return; case UnsetClass: delete downcast(this); return; case RevertClass: delete downcast(this); return; case GridAutoRepeatClass: delete downcast(this); return; case GridIntegerRepeatClass: delete downcast(this); return; case GridLineNamesClass: delete downcast(this); return; case GridTemplateAreasClass: delete downcast(this); return; case PrimitiveClass: delete downcast(this); return; case ReflectClass: delete downcast(this); return; case ShadowClass: delete downcast(this); return; case CubicBezierTimingFunctionClass: delete downcast(this); return; case StepsTimingFunctionClass: delete downcast(this); return; case SpringTimingFunctionClass: delete downcast(this); return; case UnicodeRangeClass: delete downcast(this); return; case ValueListClass: delete downcast(this); return; case ValuePairClass: delete downcast(this); return; case LineBoxContainClass: delete downcast(this); return; case CalculationClass: delete downcast(this); return; case ImageSetClass: delete downcast(this); return; case FilterImageClass: delete downcast(this); return; #if ENABLE(CSS_PAINTING_API) case PaintImageClass: delete downcast(this); return; #endif case CSSContentDistributionClass: delete downcast(this); return; case CustomPropertyClass: delete downcast(this); return; case VariableReferenceClass: delete downcast(this); return; case PendingSubstitutionValueClass: delete downcast(this); return; case FontStyleClass: delete downcast(this); return; case FontStyleRangeClass: delete downcast(this); return; } ASSERT_NOT_REACHED(); } Ref CSSValue::createDeprecatedCSSOMWrapper(CSSStyleDeclaration& styleDeclaration) const { if (isImageValue()) return downcast(this)->createDeprecatedCSSOMWrapper(styleDeclaration); if (isPrimitiveValue()) return DeprecatedCSSOMPrimitiveValue::create(downcast(*this), styleDeclaration); if (isValueList()) return DeprecatedCSSOMValueList::create(downcast(*this), styleDeclaration); return DeprecatedCSSOMComplexValue::create(*this, styleDeclaration); } bool CSSValue::treatAsInheritedValue(CSSPropertyID propertyID) const { return classType() == InheritedClass || (classType() == UnsetClass && CSSProperty::isInheritedProperty(propertyID)); } bool CSSValue::treatAsInitialValue(CSSPropertyID propertyID) const { return classType() == InitialClass || (classType() == UnsetClass && !CSSProperty::isInheritedProperty(propertyID)); } }