diff options
Diffstat (limited to 'Source/WebCore/css/CSSPrimitiveValue.h')
-rw-r--r-- | Source/WebCore/css/CSSPrimitiveValue.h | 380 |
1 files changed, 198 insertions, 182 deletions
diff --git a/Source/WebCore/css/CSSPrimitiveValue.h b/Source/WebCore/css/CSSPrimitiveValue.h index dabc6e11e..bc6f48cdd 100644 --- a/Source/WebCore/css/CSSPrimitiveValue.h +++ b/Source/WebCore/css/CSSPrimitiveValue.h @@ -19,30 +19,33 @@ * Boston, MA 02110-1301, USA. */ -#ifndef CSSPrimitiveValue_h -#define CSSPrimitiveValue_h +#pragma once #include "CSSPropertyNames.h" #include "CSSValue.h" #include "CSSValueKeywords.h" #include "Color.h" #include "LayoutUnit.h" +#include <utility> #include <wtf/Forward.h> #include <wtf/MathExtras.h> -#include <wtf/PassRefPtr.h> +#include <wtf/NeverDestroyed.h> namespace WebCore { +class CSSBasicShape; class CSSCalcValue; +class CSSToLengthConversionData; class Counter; class DashboardRegion; +class DeprecatedCSSOMPrimitiveValue; class Pair; class Quad; class RGBColor; class Rect; class RenderStyle; -class CSSBasicShape; +struct CSSFontFamily; struct Length; struct LengthSize; @@ -52,8 +55,7 @@ const int maxValueForCssLength = intMaxForLayoutUnit - 2; const int minValueForCssLength = intMinForLayoutUnit + 2; // Dimension calculations are imprecise, often resulting in values of e.g. -// 44.99998. We need to go ahead and round if we're really close to the next -// integer value. +// 44.99998. We need to round if we're really close to the next integer value. template<typename T> inline T roundForImpreciseConversion(double value) { value += (value < 0) ? -0.01 : +0.01; @@ -71,9 +73,9 @@ template<> inline float roundForImpreciseConversion(double value) return static_cast<float>(value); } -class CSSPrimitiveValue : public CSSValue { +class CSSPrimitiveValue final : public CSSValue { public: - enum UnitTypes { + enum UnitType { CSS_UNKNOWN = 0, CSS_NUMBER = 1, CSS_PERCENTAGE = 2, @@ -115,14 +117,6 @@ public: #endif CSS_UNICODE_RANGE = 102, - // These next types are just used internally to allow us to translate back and forth from CSSPrimitiveValues to CSSParserValues. - CSS_PARSER_OPERATOR = 103, - CSS_PARSER_INTEGER = 104, - CSS_PARSER_HEXCOLOR = 105, - - // This is used internally for unknown identifiers - CSS_PARSER_IDENTIFIER = 106, - // These are from CSS3 Values and Units, but that isn't a finished standard yet CSS_TURN = 107, CSS_REMS = 108, @@ -141,8 +135,16 @@ public: CSS_CALC_PERCENTAGE_WITH_NUMBER = 114, CSS_CALC_PERCENTAGE_WITH_LENGTH = 115, + CSS_FONT_FAMILY = 116, + CSS_PROPERTY_ID = 117, - CSS_VALUE_ID = 118 + CSS_VALUE_ID = 118, + + // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE. + // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em. + // When the quirky value is used, if you're in quirks mode, the margin will collapse away + // inside a table cell. This quirk is specified in the HTML spec but our impl is different. + CSS_QUIRKY_EMS = 120 }; // This enum follows the CSSParser::Units enum augmented with UNIT_FREQUENCY for frequencies. @@ -153,43 +155,37 @@ public: UAngle, UTime, UFrequency, - UViewportPercentageLength, #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY) UResolution, #endif UOther }; - static UnitCategory unitCategory(CSSPrimitiveValue::UnitTypes); - - bool isAngle() const - { - return m_primitiveUnitType == CSS_DEG - || m_primitiveUnitType == CSS_RAD - || m_primitiveUnitType == CSS_GRAD - || m_primitiveUnitType == CSS_TURN; - } + static UnitCategory unitCategory(UnitType); + + bool isAngle() const; bool isAttr() const { return m_primitiveUnitType == CSS_ATTR; } bool isCounter() const { return m_primitiveUnitType == CSS_COUNTER; } bool isFontIndependentLength() const { return m_primitiveUnitType >= CSS_PX && m_primitiveUnitType <= CSS_PC; } - bool isFontRelativeLength() const - { - return m_primitiveUnitType == CSS_EMS - || m_primitiveUnitType == CSS_EXS - || m_primitiveUnitType == CSS_REMS - || m_primitiveUnitType == CSS_CHS; - } - bool isLength() const - { - unsigned short type = primitiveType(); - return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type == CSS_CHS; - } + static bool isFontRelativeLength(UnitType); + bool isFontRelativeLength() const { return isFontRelativeLength(static_cast<UnitType>(m_primitiveUnitType)); } + + bool isQuirkyEms() const { return primitiveType() == UnitType::CSS_QUIRKY_EMS; } + + static bool isViewportPercentageLength(UnitType type) { return type >= CSS_VW && type <= CSS_VMAX; } + bool isViewportPercentageLength() const { return isViewportPercentageLength(static_cast<UnitType>(m_primitiveUnitType)); } + + static bool isLength(UnitType); + bool isLength() const { return isLength(static_cast<UnitType>(primitiveType())); } bool isNumber() const { return primitiveType() == CSS_NUMBER; } bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } bool isPx() const { return primitiveType() == CSS_PX; } bool isRect() const { return m_primitiveUnitType == CSS_RECT; } + bool isPair() const { return m_primitiveUnitType == CSS_PAIR; } + bool isPropertyID() const { return m_primitiveUnitType == CSS_PROPERTY_ID; } bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; } bool isShape() const { return m_primitiveUnitType == CSS_SHAPE; } bool isString() const { return m_primitiveUnitType == CSS_STRING; } + bool isFontFamily() const { return m_primitiveUnitType == CSS_FONT_FAMILY; } bool isTime() const { return m_primitiveUnitType == CSS_S || m_primitiveUnitType == CSS_MS; } bool isURI() const { return m_primitiveUnitType == CSS_URI; } bool isCalculated() const { return m_primitiveUnitType == CSS_CALC; } @@ -198,13 +194,9 @@ public: bool isDotsPerInch() const { return primitiveType() == CSS_DPI; } bool isDotsPerPixel() const { return primitiveType() == CSS_DPPX; } bool isDotsPerCentimeter() const { return primitiveType() == CSS_DPCM; } - bool isResolution() const - { - unsigned short type = primitiveType(); - return type >= CSS_DPPX && type <= CSS_DPCM; - } - bool isViewportPercentageLength() const { return m_primitiveUnitType >= CSS_VW && m_primitiveUnitType <= CSS_VMAX; } + static bool isResolution(UnitType); + bool isResolution() const { return isResolution(static_cast<UnitType>(primitiveType())); } bool isViewportPercentageWidth() const { return m_primitiveUnitType == CSS_VW; } bool isViewportPercentageHeight() const { return m_primitiveUnitType == CSS_VH; } bool isViewportPercentageMax() const { return m_primitiveUnitType == CSS_VMAX; } @@ -212,199 +204,223 @@ public: bool isValueID() const { return m_primitiveUnitType == CSS_VALUE_ID; } bool isFlex() const { return primitiveType() == CSS_FR; } - static PassRef<CSSPrimitiveValue> createIdentifier(CSSValueID valueID) { return adoptRef(*new CSSPrimitiveValue(valueID)); } - static PassRef<CSSPrimitiveValue> createIdentifier(CSSPropertyID propertyID) { return adoptRef(*new CSSPrimitiveValue(propertyID)); } - static PassRef<CSSPrimitiveValue> createParserOperator(int parserOperator) { return adoptRef(*new CSSPrimitiveValue(parserOperator)); } + static Ref<CSSPrimitiveValue> createIdentifier(CSSValueID valueID) { return adoptRef(*new CSSPrimitiveValue(valueID)); } + static Ref<CSSPrimitiveValue> createIdentifier(CSSPropertyID propertyID) { return adoptRef(*new CSSPrimitiveValue(propertyID)); } - static PassRef<CSSPrimitiveValue> createColor(unsigned rgbValue) { return adoptRef(*new CSSPrimitiveValue(rgbValue)); } - static PassRef<CSSPrimitiveValue> create(double value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); } - static PassRef<CSSPrimitiveValue> create(const String& value, UnitTypes type) { return adoptRef(*new CSSPrimitiveValue(value, type)); } - static PassRef<CSSPrimitiveValue> create(const Length& value, const RenderStyle* style) { return adoptRef(*new CSSPrimitiveValue(value, style)); } - static PassRef<CSSPrimitiveValue> create(const LengthSize& value) { return adoptRef(*new CSSPrimitiveValue(value)); } + static Ref<CSSPrimitiveValue> create(double value, UnitType type) { return adoptRef(*new CSSPrimitiveValue(value, type)); } + static Ref<CSSPrimitiveValue> create(const String& value, UnitType type) { return adoptRef(*new CSSPrimitiveValue(value, type)); } + static Ref<CSSPrimitiveValue> create(const Length& value, const RenderStyle& style) { return adoptRef(*new CSSPrimitiveValue(value, style)); } + static Ref<CSSPrimitiveValue> create(const LengthSize& value, const RenderStyle& style) { return adoptRef(*new CSSPrimitiveValue(value, style)); } - template<typename T> static PassRef<CSSPrimitiveValue> create(T value) - { - return adoptRef(*new CSSPrimitiveValue(value)); - } + template<typename T> static Ref<CSSPrimitiveValue> create(T&&); // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE. // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em. // When the quirky value is used, if you're in quirks mode, the margin will collapse away // inside a table cell. - static PassRef<CSSPrimitiveValue> createAllowingMarginQuirk(double value, UnitTypes type) - { - CSSPrimitiveValue* quirkValue = new CSSPrimitiveValue(value, type); - quirkValue->m_isQuirkValue = true; - return adoptRef(*quirkValue); - } + static Ref<CSSPrimitiveValue> createAllowingMarginQuirk(double value, UnitType); ~CSSPrimitiveValue(); void cleanup(); - unsigned short primitiveType() const; + WEBCORE_EXPORT unsigned short primitiveType() const; + WEBCORE_EXPORT ExceptionOr<void> setFloatValue(unsigned short unitType, double floatValue); + WEBCORE_EXPORT ExceptionOr<float> getFloatValue(unsigned short unitType) const; + WEBCORE_EXPORT ExceptionOr<void> setStringValue(unsigned short stringType, const String& stringValue); + WEBCORE_EXPORT ExceptionOr<String> getStringValue() const; + WEBCORE_EXPORT ExceptionOr<Counter&> getCounterValue() const; + WEBCORE_EXPORT ExceptionOr<Rect&> getRectValue() const; + WEBCORE_EXPORT ExceptionOr<Ref<RGBColor>> getRGBColorValue() const; + + double computeDegrees() const; + + enum TimeUnit { Seconds, Milliseconds }; + template<typename T, TimeUnit timeUnit> T computeTime() const; - double computeDegrees(); + template<typename T> T computeLength(const CSSToLengthConversionData&) const; + template<int> Length convertToLength(const CSSToLengthConversionData&) const; - enum TimeUnit { Seconds, Milliseconds }; - template <typename T, TimeUnit timeUnit> T computeTime() - { - if (timeUnit == Seconds && m_primitiveUnitType == CSS_S) - return getValue<T>(); - if (timeUnit == Seconds && m_primitiveUnitType == CSS_MS) - return getValue<T>() / 1000; - if (timeUnit == Milliseconds && m_primitiveUnitType == CSS_MS) - return getValue<T>(); - if (timeUnit == Milliseconds && m_primitiveUnitType == CSS_S) - return getValue<T>() * 1000; - ASSERT_NOT_REACHED(); - return 0; - } - - /* - * computes a length in pixels out of the given CSSValue. Need the RenderStyle to get - * the fontinfo in case val is defined in em or ex. - * - * The metrics have to be a bit different for screen and printer output. - * For screen output we assume 1 inch == 72 px, for printer we assume 300 dpi - * - * this is screen/printer dependent, so we probably need a config option for this, - * and some tool to calibrate. - */ - template<typename T> T computeLength(const RenderStyle* currStyle, const RenderStyle* rootStyle, float multiplier = 1.0f, bool computingFontSize = false) const; - - // Converts to a Length, mapping various unit types appropriately. - template<int> Length convertToLength(const RenderStyle* currStyle, const RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const; - - // use with care!!! - void setPrimitiveType(unsigned short type) { m_primitiveUnitType = type; } - - double getDoubleValue(unsigned short unitType, ExceptionCode&) const; - double getDoubleValue(unsigned short unitType) const; - double getDoubleValue() const; - - void setFloatValue(unsigned short unitType, double floatValue, ExceptionCode&); - float getFloatValue(unsigned short unitType, ExceptionCode& ec) const { return getValue<float>(unitType, ec); } - float getFloatValue(unsigned short unitType) const { return getValue<float>(unitType); } - float getFloatValue() const { return getValue<float>(); } - - int getIntValue(unsigned short unitType, ExceptionCode& ec) const { return getValue<int>(unitType, ec); } - int getIntValue(unsigned short unitType) const { return getValue<int>(unitType); } - int getIntValue() const { return getValue<int>(); } - - template<typename T> inline T getValue(unsigned short unitType, ExceptionCode& ec) const { return clampTo<T>(getDoubleValue(unitType, ec)); } - template<typename T> inline T getValue(unsigned short unitType) const { return clampTo<T>(getDoubleValue(unitType)); } - template<typename T> inline T getValue() const { return clampTo<T>(getDoubleValue()); } - - void setStringValue(unsigned short stringType, const String& stringValue, ExceptionCode&); - String getStringValue(ExceptionCode&) const; - String getStringValue() const; - - Counter* getCounterValue(ExceptionCode&) const; - Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER ? 0 : m_value.counter; } - - Rect* getRectValue(ExceptionCode&) const; - Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_value.rect; } - - Quad* getQuadValue(ExceptionCode&) const; - Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_value.quad; } - - PassRefPtr<RGBColor> getRGBColorValue(ExceptionCode&) const; - RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; } - - Pair* getPairValue(ExceptionCode&) const; - Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? 0 : m_value.pair; } + bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const; -#if ENABLE(DASHBOARD_SUPPORT) - DashboardRegion* getDashboardRegionValue() const { return m_primitiveUnitType != CSS_DASHBOARD_REGION ? 0 : m_value.region; } -#endif + double doubleValue(UnitType) const; + double doubleValue() const; - CSSBasicShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHAPE ? 0 : m_value.shape; } + template<typename T> inline T value(UnitType type) const { return clampTo<T>(doubleValue(type)); } + template<typename T> inline T value() const { return clampTo<T>(doubleValue()); } - CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC ? 0 : m_value.calc; } + float floatValue(UnitType type) const { return value<float>(type); } + float floatValue() const { return value<float>(); } - CSSPropertyID getPropertyID() const { return m_primitiveUnitType == CSS_PROPERTY_ID ? m_value.propertyID : CSSPropertyInvalid; } - CSSValueID getValueID() const { return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid; } + int intValue(UnitType type) const { return value<int>(type); } + int intValue() const { return value<int>(); } - template<typename T> inline operator T() const; // Defined in CSSPrimitiveValueMappings.h + WEBCORE_EXPORT String stringValue() const; - String customCSSText() const; + const Color& color() const { ASSERT(m_primitiveUnitType == CSS_RGBCOLOR); return *m_value.color; } + Counter* counterValue() const { return m_primitiveUnitType != CSS_COUNTER ? nullptr : m_value.counter; } + CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC ? nullptr : m_value.calc; } + const CSSFontFamily& fontFamily() const { ASSERT(m_primitiveUnitType == CSS_FONT_FAMILY); return *m_value.fontFamily; } + Pair* pairValue() const { return m_primitiveUnitType != CSS_PAIR ? nullptr : m_value.pair; } + CSSPropertyID propertyID() const { return m_primitiveUnitType == CSS_PROPERTY_ID ? m_value.propertyID : CSSPropertyInvalid; } + Quad* quadValue() const { return m_primitiveUnitType != CSS_QUAD ? nullptr : m_value.quad; } + Rect* rectValue() const { return m_primitiveUnitType != CSS_RECT ? nullptr : m_value.rect; } + CSSBasicShape* shapeValue() const { return m_primitiveUnitType != CSS_SHAPE ? nullptr : m_value.shape; } + CSSValueID valueID() const { return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid; } - bool isQuirkValue() { return m_isQuirkValue; } +#if ENABLE(DASHBOARD_SUPPORT) + DashboardRegion* dashboardRegionValue() const { return m_primitiveUnitType != CSS_DASHBOARD_REGION ? nullptr : m_value.region; } +#endif - void addSubresourceStyleURLs(ListHashSet<URL>&, const StyleSheetContents*) const; + template<typename T> inline operator T() const; // Defined in CSSPrimitiveValueMappings.h - Length viewportPercentageLength() const; + String customCSSText() const; - PassRefPtr<CSSPrimitiveValue> cloneForCSSOM() const; - void setCSSOMSafe() { m_isCSSOMSafe = true; } + // FIXME-NEWPARSER: Can ditch the boolean and just use the unit type once old parser is gone. + bool isQuirkValue() const { return m_isQuirkValue || primitiveType() == CSS_QUIRKY_EMS; } bool equals(const CSSPrimitiveValue&) const; - static UnitTypes canonicalUnitTypeForCategory(UnitCategory); - static double conversionToCanonicalUnitsScaleFactor(unsigned short unitType); + static UnitType canonicalUnitTypeForCategory(UnitCategory); + static double conversionToCanonicalUnitsScaleFactor(UnitType); + static double computeNonCalcLengthDouble(const CSSToLengthConversionData&, UnitType, double value); + + Ref<DeprecatedCSSOMPrimitiveValue> createDeprecatedCSSOMPrimitiveWrapper() const; + +#if COMPILER(MSVC) + // FIXME: This should be private, but for some reason MSVC then fails to invoke it from LazyNeverDestroyed::construct. +public: +#else private: + friend class CSSValuePool; + friend class LazyNeverDestroyed<CSSPrimitiveValue>; +#endif + CSSPrimitiveValue(CSSValueID); CSSPrimitiveValue(CSSPropertyID); - // FIXME: int vs. unsigned overloading is too subtle to distinguish the color and operator cases. - CSSPrimitiveValue(int parserOperator); - CSSPrimitiveValue(unsigned color); // RGB value + CSSPrimitiveValue(const Color&); CSSPrimitiveValue(const Length&); - CSSPrimitiveValue(const Length&, const RenderStyle*); - CSSPrimitiveValue(const LengthSize&); - CSSPrimitiveValue(const String&, UnitTypes); - CSSPrimitiveValue(double, UnitTypes); + CSSPrimitiveValue(const Length&, const RenderStyle&); + CSSPrimitiveValue(const LengthSize&, const RenderStyle&); + CSSPrimitiveValue(const String&, UnitType); + CSSPrimitiveValue(double, UnitType); template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMappings.h - template<typename T> CSSPrimitiveValue(T* val) - : CSSValue(PrimitiveClass) - { - init(PassRefPtr<T>(val)); - } - - template<typename T> CSSPrimitiveValue(PassRefPtr<T> val) - : CSSValue(PrimitiveClass) - { - init(val); - } + template<typename T> CSSPrimitiveValue(RefPtr<T>&&); + template<typename T> CSSPrimitiveValue(Ref<T>&&); static void create(int); // compile-time guard static void create(unsigned); // compile-time guard template<typename T> operator T*(); // compile-time guard void init(const Length&); - void init(const LengthSize&); - void init(PassRefPtr<Counter>); - void init(PassRefPtr<Rect>); - void init(PassRefPtr<Pair>); - void init(PassRefPtr<Quad>); - void init(PassRefPtr<DashboardRegion>); // FIXME: Dashboard region should not be a primitive value. - void init(PassRefPtr<CSSBasicShape>); - void init(PassRefPtr<CSSCalcValue>); - bool getDoubleValueInternal(UnitTypes targetUnitType, double* result) const; - - double computeLengthDouble(const RenderStyle* currentStyle, const RenderStyle* rootStyle, float multiplier, bool computingFontSize) const; + void init(const LengthSize&, const RenderStyle&); + void init(Ref<CSSBasicShape>&&); + void init(RefPtr<CSSCalcValue>&&); + void init(Ref<Counter>&&); + void init(Ref<Pair>&&); + void init(Ref<Quad>&&); + void init(Ref<Rect>&&); + +#if ENABLE(DASHBOARD_SUPPORT) + void init(RefPtr<DashboardRegion>&&); // FIXME: Dashboard region should not be a primitive value. +#endif + + std::optional<double> doubleValueInternal(UnitType targetUnitType) const; + + double computeLengthDouble(const CSSToLengthConversionData&) const; + + ALWAYS_INLINE String formatNumberForCustomCSSText() const; + template<unsigned characterCount> ALWAYS_INLINE Ref<StringImpl> formatNumberValue(const char (&characters)[characterCount]) const; + NEVER_INLINE Ref<StringImpl> formatNumberValue(const char* suffix, unsigned suffixLength) const; union { CSSPropertyID propertyID; CSSValueID valueID; - int parserOperator; double num; StringImpl* string; Counter* counter; Rect* rect; Quad* quad; - unsigned rgbcolor; + const Color* color; Pair* pair; DashboardRegion* region; CSSBasicShape* shape; CSSCalcValue* calc; + const CSSFontFamily* fontFamily; } m_value; }; -CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()) +inline bool CSSPrimitiveValue::isAngle() const +{ + return m_primitiveUnitType == CSS_DEG + || m_primitiveUnitType == CSS_RAD + || m_primitiveUnitType == CSS_GRAD + || m_primitiveUnitType == CSS_TURN; +} + +inline bool CSSPrimitiveValue::isFontRelativeLength(UnitType type) +{ + return type == CSS_EMS + || type == CSS_EXS + || type == CSS_REMS + || type == CSS_CHS + || type == CSS_QUIRKY_EMS; +} + +inline bool CSSPrimitiveValue::isLength(UnitType type) +{ + return (type >= CSS_EMS && type <= CSS_PC) + || type == CSS_REMS + || type == CSS_CHS + || isViewportPercentageLength(type) + || type == CSS_QUIRKY_EMS; +} + +inline bool CSSPrimitiveValue::isResolution(UnitType type) +{ + return type >= CSS_DPPX && type <= CSS_DPCM; +} + +template<typename T> inline Ref<CSSPrimitiveValue> CSSPrimitiveValue::create(T&& value) +{ + return adoptRef(*new CSSPrimitiveValue(std::forward<T>(value))); +} + +inline Ref<CSSPrimitiveValue> CSSPrimitiveValue::createAllowingMarginQuirk(double value, UnitType type) +{ + auto result = adoptRef(*new CSSPrimitiveValue(value, type)); + result->m_isQuirkValue = true; + return result; +} + +template<typename T, CSSPrimitiveValue::TimeUnit timeUnit> inline T CSSPrimitiveValue::computeTime() const +{ + if (timeUnit == Seconds && primitiveType() == CSS_S) + return value<T>(); + if (timeUnit == Seconds && primitiveType() == CSS_MS) + return value<T>() / 1000; + if (timeUnit == Milliseconds && primitiveType() == CSS_MS) + return value<T>(); + if (timeUnit == Milliseconds && primitiveType() == CSS_S) + return value<T>() * 1000; + ASSERT_NOT_REACHED(); + return 0; +} + +template<typename T> inline CSSPrimitiveValue::CSSPrimitiveValue(RefPtr<T>&& value) + : CSSValue(PrimitiveClass) +{ + init(WTFMove(value)); +} + +template<typename T> inline CSSPrimitiveValue::CSSPrimitiveValue(Ref<T>&& value) + : CSSValue(PrimitiveClass) +{ + init(WTFMove(value)); +} } // namespace WebCore -#endif // CSSPrimitiveValue_h +SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSPrimitiveValue, isPrimitiveValue()) |