| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2013 Google Inc. All rights reserved. | 2  * Copyright (C) 2013 Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions are | 5  * modification, are permitted provided that the following conditions are | 
| 6  * met: | 6  * met: | 
| 7  * | 7  * | 
| 8  *     * Redistributions of source code must retain the above copyright | 8  *     * Redistributions of source code must retain the above copyright | 
| 9  * notice, this list of conditions and the following disclaimer. | 9  * notice, this list of conditions and the following disclaimer. | 
| 10  *     * Redistributions in binary form must reproduce the above | 10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 35 #include "core/css/CSSCalculationValue.h" | 35 #include "core/css/CSSCalculationValue.h" | 
| 36 #include "core/css/CSSPrimitiveValue.h" | 36 #include "core/css/CSSPrimitiveValue.h" | 
| 37 | 37 | 
| 38 namespace WebCore { | 38 namespace WebCore { | 
| 39 | 39 | 
| 40 // Handles animation of CSSPrimitiveValues that can be represented by doubles in
     cluding CSSCalcValue. | 40 // Handles animation of CSSPrimitiveValues that can be represented by doubles in
     cluding CSSCalcValue. | 
| 41 // See primitiveUnitToNumberType() for the list of supported units (with the exc
     eption of calc). | 41 // See primitiveUnitToNumberType() for the list of supported units (with the exc
     eption of calc). | 
| 42 // If created from a CSSPrimitiveValue this class will cache it to be returned i
     n toCSSValue(). | 42 // If created from a CSSPrimitiveValue this class will cache it to be returned i
     n toCSSValue(). | 
| 43 class AnimatableNumber : public AnimatableValue { | 43 class AnimatableNumber : public AnimatableValue { | 
| 44 public: | 44 public: | 
| 45     virtual ~AnimatableNumber() { } |  | 
| 46     static bool canCreateFrom(const CSSValue*); |  | 
| 47     static PassRefPtr<AnimatableNumber> create(CSSValue*); |  | 
| 48     virtual PassRefPtr<CSSValue> toCSSValue() const OVERRIDE; |  | 
| 49 |  | 
| 50 protected: |  | 
| 51     virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do
     uble fraction) const OVERRIDE; |  | 
| 52     virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV
     ERRIDE; |  | 
| 53 |  | 
| 54 private: |  | 
| 55     enum NumberUnitType { | 45     enum NumberUnitType { | 
| 56         UnitTypeNone, | 46         UnitTypeNumber, | 
| 57         UnitTypeLength, | 47         UnitTypeLength, | 
| 58         UnitTypeFontSize, | 48         UnitTypeFontSize, | 
| 59         UnitTypeFontXSize, | 49         UnitTypeFontXSize, | 
| 60         UnitTypeRootFontSize, | 50         UnitTypeRootFontSize, | 
| 61         UnitTypePercentage, | 51         UnitTypePercentage, | 
| 62         UnitTypeViewportWidth, | 52         UnitTypeViewportWidth, | 
| 63         UnitTypeViewportHeight, | 53         UnitTypeViewportHeight, | 
| 64         UnitTypeViewportMin, | 54         UnitTypeViewportMin, | 
| 65         UnitTypeViewportMax, | 55         UnitTypeViewportMax, | 
| 66         UnitTypeTime, | 56         UnitTypeTime, | 
| 67         UnitTypeAngle, | 57         UnitTypeAngle, | 
| 68         UnitTypeFrequency, | 58         UnitTypeFrequency, | 
| 69         UnitTypeResolution, | 59         UnitTypeResolution, | 
| 70         UnitTypeInvalid, | 60         UnitTypeInvalid, | 
| 71     }; | 61     }; | 
| 72 | 62 | 
|  | 63     virtual ~AnimatableNumber() { } | 
|  | 64     static bool canCreateFrom(const CSSValue*); | 
|  | 65     static PassRefPtr<AnimatableNumber> create(CSSValue*); | 
|  | 66     static PassRefPtr<AnimatableNumber> create(double number, NumberUnitType uni
     tType, CSSPrimitiveValue* cssPrimitiveValue = 0) | 
|  | 67     { | 
|  | 68         return adoptRef(new AnimatableNumber(number, unitType, cssPrimitiveValue
     )); | 
|  | 69     } | 
|  | 70     virtual PassRefPtr<CSSValue> toCSSValue() const OVERRIDE; | 
|  | 71 | 
|  | 72 protected: | 
|  | 73     virtual PassRefPtr<AnimatableValue> interpolateTo(const AnimatableValue*, do
     uble fraction) const OVERRIDE; | 
|  | 74     virtual PassRefPtr<AnimatableValue> addWith(const AnimatableValue*) const OV
     ERRIDE; | 
|  | 75 | 
|  | 76 private: | 
| 73     AnimatableNumber(double number, NumberUnitType unitType, CSSPrimitiveValue* 
     cssPrimitiveValue) | 77     AnimatableNumber(double number, NumberUnitType unitType, CSSPrimitiveValue* 
     cssPrimitiveValue) | 
| 74         : AnimatableValue(TypeNumber) | 78         : AnimatableValue(TypeNumber) | 
| 75         , m_number(number) | 79         , m_number(number) | 
| 76         , m_unitType(unitType) | 80         , m_unitType(unitType) | 
| 77         , m_isCalc(false) | 81         , m_isCalc(false) | 
| 78         , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 82         , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 
| 79     { | 83     { | 
| 80         ASSERT(m_unitType != UnitTypeInvalid); | 84         ASSERT(m_unitType != UnitTypeInvalid); | 
| 81     } | 85     } | 
| 82     AnimatableNumber(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit
     iveValue* cssPrimitiveValue) | 86     AnimatableNumber(PassRefPtr<CSSCalcExpressionNode> calcExpression, CSSPrimit
     iveValue* cssPrimitiveValue) | 
| 83         : AnimatableValue(TypeNumber) | 87         : AnimatableValue(TypeNumber) | 
| 84         , m_isCalc(true) | 88         , m_isCalc(true) | 
| 85         , m_calcExpression(calcExpression) | 89         , m_calcExpression(calcExpression) | 
| 86         , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 90         , m_cachedCSSPrimitiveValue(cssPrimitiveValue) | 
| 87     { | 91     { | 
| 88         ASSERT(m_calcExpression); | 92         ASSERT(m_calcExpression); | 
| 89     } | 93     } | 
| 90 | 94 | 
| 91     static PassRefPtr<AnimatableNumber> create(double number, NumberUnitType uni
     tType, CSSPrimitiveValue* cssPrimitiveValue = 0) |  | 
| 92     { |  | 
| 93         return adoptRef(new AnimatableNumber(number, unitType, cssPrimitiveValue
     )); |  | 
| 94     } |  | 
| 95     static PassRefPtr<AnimatableNumber> create(PassRefPtr<CSSCalcExpressionNode>
      calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0) | 95     static PassRefPtr<AnimatableNumber> create(PassRefPtr<CSSCalcExpressionNode>
      calcExpression, CSSPrimitiveValue* cssPrimitiveValue = 0) | 
| 96     { | 96     { | 
| 97         return adoptRef(new AnimatableNumber(calcExpression, cssPrimitiveValue))
     ; | 97         return adoptRef(new AnimatableNumber(calcExpression, cssPrimitiveValue))
     ; | 
| 98     } | 98     } | 
| 99     static PassRefPtr<AnimatableNumber> create(const AnimatableNumber* leftAdden
     d, const AnimatableNumber* rightAddend); | 99     static PassRefPtr<AnimatableNumber> create(const AnimatableNumber* leftAdden
     d, const AnimatableNumber* rightAddend); | 
| 100 | 100 | 
| 101     PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue() const; | 101     PassRefPtr<CSSPrimitiveValue> toCSSPrimitiveValue() const; | 
| 102     PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const; | 102     PassRefPtr<CSSCalcExpressionNode> toCSSCalcExpressionNode() const; | 
| 103 | 103 | 
| 104     PassRefPtr<AnimatableNumber> scale(double) const; | 104     PassRefPtr<AnimatableNumber> scale(double) const; | 
| 105     static NumberUnitType primitiveUnitToNumberType(unsigned short primitiveUnit
     ); | 105     static NumberUnitType primitiveUnitToNumberType(unsigned short primitiveUnit
     ); | 
| 106     static unsigned short numberTypeToPrimitiveUnit(NumberUnitType numberType); | 106     static unsigned short numberTypeToPrimitiveUnit(NumberUnitType numberType); | 
| 107 | 107 | 
| 108     double m_number; | 108     double m_number; | 
| 109     NumberUnitType m_unitType; | 109     NumberUnitType m_unitType; | 
| 110 | 110 | 
| 111     bool m_isCalc; | 111     bool m_isCalc; | 
| 112     RefPtr<CSSCalcExpressionNode> m_calcExpression; | 112     RefPtr<CSSCalcExpressionNode> m_calcExpression; | 
| 113 | 113 | 
| 114     mutable RefPtr<CSSPrimitiveValue> m_cachedCSSPrimitiveValue; | 114     mutable RefPtr<CSSPrimitiveValue> m_cachedCSSPrimitiveValue; | 
| 115 }; | 115 }; | 
| 116 | 116 | 
| 117 | 117 | 
| 118 } // namespace WebCore | 118 } // namespace WebCore | 
| 119 | 119 | 
| 120 #endif // AnimatableNumber_h | 120 #endif // AnimatableNumber_h | 
| OLD | NEW | 
|---|