Home | History | Annotate | Download | only in css
      1 /*
      2  * Copyright (C) 2013 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 #include "core/animation/css/CSSAnimatableValueFactory.h"
     33 
     34 #include "CSSValueKeywords.h"
     35 #include "core/animation/AnimatableNumber.h"
     36 #include "core/animation/AnimatableUnknown.h"
     37 #include "core/platform/Length.h"
     38 #include "core/rendering/style/RenderStyle.h"
     39 
     40 
     41 namespace WebCore {
     42 
     43 // FIXME: Handle remaining animatable properties (pulled from CSSPropertyAnimation):
     44 // CSSPropertyBackgroundColor
     45 // CSSPropertyBackgroundImage
     46 // CSSPropertyBackgroundPositionX
     47 // CSSPropertyBackgroundPositionY
     48 // CSSPropertyBackgroundSize
     49 // CSSPropertyBaselineShift
     50 // CSSPropertyBorderBottomColor
     51 // CSSPropertyBorderBottomLeftRadius
     52 // CSSPropertyBorderBottomRightRadius
     53 // CSSPropertyBorderBottomWidth
     54 // CSSPropertyBorderImageOutset
     55 // CSSPropertyBorderImageSlice
     56 // CSSPropertyBorderImageSource
     57 // CSSPropertyBorderImageWidth
     58 // CSSPropertyBorderLeftColor
     59 // CSSPropertyBorderLeftWidth
     60 // CSSPropertyBorderRightColor
     61 // CSSPropertyBorderRightWidth
     62 // CSSPropertyBorderTopColor
     63 // CSSPropertyBorderTopLeftRadius
     64 // CSSPropertyBorderTopRightRadius
     65 // CSSPropertyBorderTopWidth
     66 // CSSPropertyBoxShadow
     67 // CSSPropertyClip
     68 // CSSPropertyColor
     69 // CSSPropertyFill
     70 // CSSPropertyFillOpacity
     71 // CSSPropertyFloodColor
     72 // CSSPropertyFloodOpacity
     73 // CSSPropertyFontSize
     74 // CSSPropertyKerning
     75 // CSSPropertyLetterSpacing
     76 // CSSPropertyLightingColor
     77 // CSSPropertyLineHeight
     78 // CSSPropertyListStyleImage
     79 // CSSPropertyOpacity
     80 // CSSPropertyOrphans
     81 // CSSPropertyOutlineColor
     82 // CSSPropertyOutlineOffset
     83 // CSSPropertyOutlineWidth
     84 // CSSPropertyStopColor
     85 // CSSPropertyStopOpacity
     86 // CSSPropertyStroke
     87 // CSSPropertyStrokeDashoffset
     88 // CSSPropertyStrokeMiterlimit
     89 // CSSPropertyStrokeOpacity
     90 // CSSPropertyStrokeWidth
     91 // CSSPropertyTextIndent
     92 // CSSPropertyTextShadow
     93 // CSSPropertyVisibility
     94 // CSSPropertyWebkitBackgroundSize
     95 // CSSPropertyWebkitBorderHorizontalSpacing
     96 // CSSPropertyWebkitBorderVerticalSpacing
     97 // CSSPropertyWebkitBoxShadow
     98 // CSSPropertyWebkitClipPath
     99 // CSSPropertyWebkitColumnCount
    100 // CSSPropertyWebkitColumnGap
    101 // CSSPropertyWebkitColumnRuleColor
    102 // CSSPropertyWebkitColumnRuleWidth
    103 // CSSPropertyWebkitColumnWidth
    104 // CSSPropertyWebkitFilter
    105 // CSSPropertyWebkitMaskBoxImage
    106 // CSSPropertyWebkitMaskBoxImageSource
    107 // CSSPropertyWebkitMaskImage
    108 // CSSPropertyWebkitMaskPositionX
    109 // CSSPropertyWebkitMaskPositionY
    110 // CSSPropertyWebkitMaskSize
    111 // CSSPropertyWebkitPerspective
    112 // CSSPropertyWebkitShapeInside
    113 // CSSPropertyWebkitTextFillColor
    114 // CSSPropertyWebkitTextStrokeColor
    115 // CSSPropertyWebkitTransform
    116 // CSSPropertyWebkitTransformOriginZ
    117 // CSSPropertyWidows
    118 // CSSPropertyWordSpacing
    119 // CSSPropertyZIndex
    120 // CSSPropertyZoom
    121 
    122 static PassRefPtr<AnimatableValue> createFromLength(const Length& length, const RenderStyle* style)
    123 {
    124     switch (length.type()) {
    125     case Relative:
    126         return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeNumber);
    127     case Fixed:
    128         return AnimatableNumber::create(adjustFloatForAbsoluteZoom(length.value(), style), AnimatableNumber::UnitTypeLength);
    129     case Percent:
    130         return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypePercentage);
    131     case ViewportPercentageWidth:
    132         return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportWidth);
    133     case ViewportPercentageHeight:
    134         return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportHeight);
    135     case ViewportPercentageMin:
    136         return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportMin);
    137     case ViewportPercentageMax:
    138         return AnimatableNumber::create(length.value(), AnimatableNumber::UnitTypeViewportMax);
    139     case Calculated:
    140         // FIXME: Convert platform calcs to CSS calcs.
    141         ASSERT_WITH_MESSAGE(false, "Web Animations not yet implemented: Convert platform CalculationValue to AnimatableValue");
    142         return 0;
    143     case Auto:
    144     case Intrinsic:
    145     case MinIntrinsic:
    146     case MinContent:
    147     case MaxContent:
    148     case FillAvailable:
    149     case FitContent:
    150         return AnimatableUnknown::create(CSSPrimitiveValue::create(length));
    151     case Undefined:
    152         return AnimatableUnknown::create(CSSPrimitiveValue::create(CSSValueNone));
    153     case ExtendToZoom: // Does not apply to elements.
    154         ASSERT_NOT_REACHED();
    155         return 0;
    156     }
    157     ASSERT_NOT_REACHED();
    158     return 0;
    159 }
    160 
    161 inline static PassRefPtr<AnimatableValue> createFromDouble(double value)
    162 {
    163     return AnimatableNumber::create(value, AnimatableNumber::UnitTypeNumber);
    164 }
    165 
    166 // FIXME: Generate this function.
    167 PassRefPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPropertyID property, const RenderStyle* style)
    168 {
    169     switch (property) {
    170     case CSSPropertyBottom:
    171         return createFromLength(style->bottom(), style);
    172     case CSSPropertyHeight:
    173         return createFromLength(style->height(), style);
    174     case CSSPropertyLeft:
    175         return createFromLength(style->left(), style);
    176     case CSSPropertyMarginBottom:
    177         return createFromLength(style->marginBottom(), style);
    178     case CSSPropertyMarginLeft:
    179         return createFromLength(style->marginLeft(), style);
    180     case CSSPropertyMarginRight:
    181         return createFromLength(style->marginRight(), style);
    182     case CSSPropertyMarginTop:
    183         return createFromLength(style->marginTop(), style);
    184     case CSSPropertyMaxHeight:
    185         return createFromLength(style->maxHeight(), style);
    186     case CSSPropertyMaxWidth:
    187         return createFromLength(style->maxWidth(), style);
    188     case CSSPropertyMinHeight:
    189         return createFromLength(style->minHeight(), style);
    190     case CSSPropertyMinWidth:
    191         return createFromLength(style->minWidth(), style);
    192     case CSSPropertyOpacity:
    193         return createFromDouble(style->opacity());
    194     case CSSPropertyPaddingBottom:
    195         return createFromLength(style->paddingBottom(), style);
    196     case CSSPropertyPaddingLeft:
    197         return createFromLength(style->paddingLeft(), style);
    198     case CSSPropertyPaddingRight:
    199         return createFromLength(style->paddingRight(), style);
    200     case CSSPropertyPaddingTop:
    201         return createFromLength(style->paddingTop(), style);
    202     case CSSPropertyRight:
    203         return createFromLength(style->right(), style);
    204     case CSSPropertyTop:
    205         return createFromLength(style->top(), style);
    206     case CSSPropertyWebkitPerspectiveOriginX:
    207         return createFromLength(style->perspectiveOriginX(), style);
    208     case CSSPropertyWebkitPerspectiveOriginY:
    209         return createFromLength(style->perspectiveOriginY(), style);
    210     case CSSPropertyWebkitTransformOriginX:
    211         return createFromLength(style->transformOriginX(), style);
    212     case CSSPropertyWebkitTransformOriginY:
    213         return createFromLength(style->transformOriginY(), style);
    214     case CSSPropertyWidth:
    215         return createFromLength(style->width(), style);
    216     default:
    217         RELEASE_ASSERT_WITH_MESSAGE(false, "Web Animations not yet implemented: Create AnimatableValue from render style");
    218         return 0;
    219     }
    220 }
    221 
    222 } // namespace WebCore
    223