Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/css/resolver/AnimatedStyleBuilder.h" | 32 #include "core/css/resolver/AnimatedStyleBuilder.h" |
| 33 | 33 |
| 34 #include "core/animation/AnimatableImage.h" | |
| 35 #include "core/animation/AnimatableLengthBox.h" | |
| 34 #include "core/animation/AnimatableNumber.h" | 36 #include "core/animation/AnimatableNumber.h" |
| 35 #include "core/animation/AnimatableTransform.h" | 37 #include "core/animation/AnimatableTransform.h" |
| 36 #include "core/animation/AnimatableUnknown.h" | 38 #include "core/animation/AnimatableUnknown.h" |
| 37 #include "core/animation/AnimatableValue.h" | 39 #include "core/animation/AnimatableValue.h" |
| 40 #include "core/animation/css/CSSAnimations.h" | |
| 38 #include "core/css/resolver/StyleBuilder.h" | 41 #include "core/css/resolver/StyleBuilder.h" |
| 39 #include "core/css/resolver/StyleResolverState.h" | 42 #include "core/css/resolver/StyleResolverState.h" |
| 40 #include "core/rendering/style/RenderStyle.h" | 43 #include "core/rendering/style/RenderStyle.h" |
| 41 #include "wtf/MathExtras.h" | 44 #include "wtf/MathExtras.h" |
| 42 | 45 |
| 43 namespace WebCore { | 46 namespace WebCore { |
| 44 | 47 |
| 45 namespace { | 48 namespace { |
| 46 | 49 |
| 47 Length animatableValueToLength(const AnimatableValue* value, const StyleResolver State& state) | 50 Length animatableValueToLength(const AnimatableValue* value, const StyleResolver State& state) |
| 48 { | 51 { |
| 49 const RenderStyle* style = state.style(); | 52 const RenderStyle* style = state.style(); |
| 50 return toAnimatableNumber(value)->toLength(style, state.rootElementStyle(), style->effectiveZoom()); | 53 return toAnimatableNumber(value)->toLength(style, state.rootElementStyle(), style->effectiveZoom()); |
| 51 } | 54 } |
| 52 | 55 |
| 53 unsigned animatableValueToUnsigned(const AnimatableValue* value) | 56 unsigned animatableValueToUnsigned(const AnimatableValue* value) |
| 54 { | 57 { |
| 55 return clampTo<unsigned>(round(toAnimatableNumber(value)->toDouble())); | 58 return clampTo<unsigned>(round(toAnimatableNumber(value)->toDouble())); |
| 56 } | 59 } |
| 57 | 60 |
| 61 LengthBox animatableValueToLengthBox(const AnimatableValue* value, const StyleRe solverState& state) | |
| 62 { | |
| 63 const AnimatableLengthBox* animatableLengthBox = toAnimatableLengthBox(value ); | |
| 64 return LengthBox( | |
| 65 animatableValueToLength(animatableLengthBox->left(), state), | |
| 66 animatableValueToLength(animatableLengthBox->right(), state), | |
| 67 animatableValueToLength(animatableLengthBox->top(), state), | |
| 68 animatableValueToLength(animatableLengthBox->bottom(), state)); | |
|
alancutter (OOO until 2018)
2013/08/27 02:37:45
This will fail when any of these values are 'auto'
Timothy Loh
2013/08/27 04:26:06
I think the logic for creating a LengthBox should
dstockwell
2013/08/27 05:02:02
I've updated animatableValueToLength for now.
| |
| 69 } | |
| 70 | |
| 58 } // namespace | 71 } // namespace |
| 59 | 72 |
| 60 // FIXME: This should handle all animatable properties | |
| 61 // (see CSSAnimatableValueFactory for list of remaining) | |
| 62 | |
| 63 // FIXME: Generate this function. | 73 // FIXME: Generate this function. |
| 64 void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverSt ate& state, const AnimatableValue* value) | 74 void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverSt ate& state, const AnimatableValue* value) |
| 65 { | 75 { |
| 66 if (value->isUnknown()) { | 76 if (value->isUnknown()) { |
| 67 StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)- >toCSSValue().get()); | 77 StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)- >toCSSValue().get()); |
| 68 return; | 78 return; |
| 69 } | 79 } |
| 70 RenderStyle* style = state.style(); | 80 RenderStyle* style = state.style(); |
| 71 switch (property) { | 81 switch (property) { |
| 72 case CSSPropertyBorderBottomWidth: | 82 case CSSPropertyBorderBottomWidth: |
| 73 style->setBorderBottomWidth(animatableValueToUnsigned(value)); | 83 style->setBorderBottomWidth(animatableValueToUnsigned(value)); |
| 74 return; | 84 return; |
| 85 case CSSPropertyBorderImageOutset: | |
| 86 style->setBorderImageOutset(animatableValueToLengthBox(value, state)); | |
| 87 return; | |
| 88 case CSSPropertyBorderImageSlice: | |
| 89 style->setBorderImageSlices(animatableValueToLengthBox(value, state)); | |
| 90 return; | |
| 91 case CSSPropertyBorderImageSource: | |
| 92 style->setBorderImageSource(toAnimatableImage(value)->toStyleImage()); | |
| 93 return; | |
| 94 case CSSPropertyBorderImageWidth: | |
| 95 style->setBorderImageWidth(animatableValueToLengthBox(value, state)); | |
| 96 return; | |
| 75 case CSSPropertyBorderLeftWidth: | 97 case CSSPropertyBorderLeftWidth: |
| 76 style->setBorderLeftWidth(animatableValueToUnsigned(value)); | 98 style->setBorderLeftWidth(animatableValueToUnsigned(value)); |
| 77 return; | 99 return; |
| 78 case CSSPropertyBorderRightWidth: | 100 case CSSPropertyBorderRightWidth: |
| 79 style->setBorderRightWidth(animatableValueToUnsigned(value)); | 101 style->setBorderRightWidth(animatableValueToUnsigned(value)); |
| 80 return; | 102 return; |
| 81 case CSSPropertyBorderTopWidth: | 103 case CSSPropertyBorderTopWidth: |
| 82 style->setBorderTopWidth(animatableValueToUnsigned(value)); | 104 style->setBorderTopWidth(animatableValueToUnsigned(value)); |
| 83 return; | 105 return; |
| 84 case CSSPropertyBottom: | 106 case CSSPropertyBottom: |
| 85 style->setBottom(animatableValueToLength(value, state)); | 107 style->setBottom(animatableValueToLength(value, state)); |
| 86 return; | 108 return; |
| 109 case CSSPropertyClip: | |
| 110 style->setClip(animatableValueToLengthBox(value, state)); | |
| 111 return; | |
| 87 case CSSPropertyHeight: | 112 case CSSPropertyHeight: |
| 88 style->setHeight(animatableValueToLength(value, state)); | 113 style->setHeight(animatableValueToLength(value, state)); |
| 89 return; | 114 return; |
| 115 case CSSPropertyListStyleImage: | |
| 116 style->setListStyleImage(toAnimatableImage(value)->toStyleImage()); | |
| 117 return; | |
| 90 case CSSPropertyLeft: | 118 case CSSPropertyLeft: |
| 91 style->setLeft(animatableValueToLength(value, state)); | 119 style->setLeft(animatableValueToLength(value, state)); |
| 92 return; | 120 return; |
| 93 case CSSPropertyMarginBottom: | 121 case CSSPropertyMarginBottom: |
| 94 style->setMarginBottom(animatableValueToLength(value, state)); | 122 style->setMarginBottom(animatableValueToLength(value, state)); |
| 95 return; | 123 return; |
| 96 case CSSPropertyMarginLeft: | 124 case CSSPropertyMarginLeft: |
| 97 style->setMarginLeft(animatableValueToLength(value, state)); | 125 style->setMarginLeft(animatableValueToLength(value, state)); |
| 98 return; | 126 return; |
| 99 case CSSPropertyMarginRight: | 127 case CSSPropertyMarginRight: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 128 return; | 156 return; |
| 129 case CSSPropertyPaddingTop: | 157 case CSSPropertyPaddingTop: |
| 130 style->setPaddingTop(animatableValueToLength(value, state)); | 158 style->setPaddingTop(animatableValueToLength(value, state)); |
| 131 return; | 159 return; |
| 132 case CSSPropertyRight: | 160 case CSSPropertyRight: |
| 133 style->setRight(animatableValueToLength(value, state)); | 161 style->setRight(animatableValueToLength(value, state)); |
| 134 return; | 162 return; |
| 135 case CSSPropertyTop: | 163 case CSSPropertyTop: |
| 136 style->setTop(animatableValueToLength(value, state)); | 164 style->setTop(animatableValueToLength(value, state)); |
| 137 return; | 165 return; |
| 166 case CSSPropertyWebkitMaskBoxImageSource: | |
| 167 style->setMaskBoxImageSource(toAnimatableImage(value)->toStyleImage()); | |
| 168 return; | |
| 169 case CSSPropertyWebkitMaskImage: | |
| 170 style->setMaskImage(toAnimatableImage(value)->toStyleImage()); | |
| 171 return; | |
| 138 case CSSPropertyWebkitPerspectiveOriginX: | 172 case CSSPropertyWebkitPerspectiveOriginX: |
| 139 style->setPerspectiveOriginX(animatableValueToLength(value, state)); | 173 style->setPerspectiveOriginX(animatableValueToLength(value, state)); |
| 140 return; | 174 return; |
| 141 case CSSPropertyWebkitPerspectiveOriginY: | 175 case CSSPropertyWebkitPerspectiveOriginY: |
| 142 style->setPerspectiveOriginY(animatableValueToLength(value, state)); | 176 style->setPerspectiveOriginY(animatableValueToLength(value, state)); |
| 143 return; | 177 return; |
| 144 case CSSPropertyWebkitTransform: | 178 case CSSPropertyWebkitTransform: |
| 145 style->setTransform(toAnimatableTransform(value)->transformOperations()) ; | 179 style->setTransform(toAnimatableTransform(value)->transformOperations()) ; |
| 146 return; | 180 return; |
| 147 case CSSPropertyWebkitTransformOriginX: | 181 case CSSPropertyWebkitTransformOriginX: |
| 148 style->setTransformOriginX(animatableValueToLength(value, state)); | 182 style->setTransformOriginX(animatableValueToLength(value, state)); |
| 149 return; | 183 return; |
| 150 case CSSPropertyWebkitTransformOriginY: | 184 case CSSPropertyWebkitTransformOriginY: |
| 151 style->setTransformOriginY(animatableValueToLength(value, state)); | 185 style->setTransformOriginY(animatableValueToLength(value, state)); |
| 152 return; | 186 return; |
| 153 case CSSPropertyWidth: | 187 case CSSPropertyWidth: |
| 154 style->setWidth(animatableValueToLength(value, state)); | 188 style->setWidth(animatableValueToLength(value, state)); |
| 155 return; | 189 return; |
| 156 default: | 190 default: |
| 157 RELEASE_ASSERT_WITH_MESSAGE(false, "Unable to apply AnimatableValue to R enderStyle, not yet implemented!"); | 191 RELEASE_ASSERT_WITH_MESSAGE(!CSSAnimations::isAnimatableProperty(propert y), "Unable to apply AnimatableValue to RenderStyle, not yet implemented: %s", g etPropertyNameString(property).utf8().data()); |
| 158 return; | 192 ASSERT_NOT_REACHED(); |
| 159 } | 193 } |
| 160 } | 194 } |
| 161 | 195 |
| 162 } // namespace WebCore | 196 } // namespace WebCore |
| OLD | NEW |