Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/ElementAnimation.h" | |
| 33 | |
| 34 #include "core/animation/AnimatableLength.h" | |
| 35 #include "core/animation/AnimationEffect.h" | |
| 36 #include "core/animation/DocumentTimeline.h" | |
| 37 #include "core/animation/KeyframeAnimationEffect.h" | |
| 38 #include "core/animation/css/CSSAnimatableValueFactory.h" | |
| 39 #include "core/animation/css/CSSAnimations.h" | |
| 40 #include "core/css/CSSParser.h" | |
| 41 #include "core/css/resolver/StyleBuilder.h" | |
| 42 #include "core/css/resolver/StyleResolverState.h" | |
| 43 #include "core/page/RuntimeCSSEnabled.h" | |
| 44 #include "core/rendering/style/RenderStyle.h" | |
| 45 #include "wtf/text/StringBuilder.h" | |
| 46 | |
| 47 | |
| 48 namespace WebCore { | |
| 49 | |
| 50 namespace { | |
| 51 | |
| 52 static CSSPropertyID camelCasePropertyToCSSPropertyID(String propertyName) | |
|
Steve Block
2013/12/06 03:27:27
No need for static now this is in an anonymous nam
rjwright
2013/12/07 11:09:06
Done.
| |
| 53 { | |
| 54 StringBuilder builder; | |
| 55 size_t position = 0; | |
| 56 size_t end; | |
| 57 while ((end = propertyName.find(isASCIIUpper, position)) != kNotFound) { | |
| 58 builder.append(propertyName.substring(position, end) + "-" + toASCIILowe r(propertyName[end])); | |
| 59 position = end + 1; | |
| 60 } | |
| 61 builder.append(propertyName.substring(position)); | |
| 62 return cssPropertyID(builder.toString()); | |
|
Steve Block
2013/12/06 03:27:27
We should check RuntimeCSSEnabled::isCSSPropertyEn
rjwright
2013/12/09 00:29:45
Done.
| |
| 63 } | |
| 64 | |
| 65 } // namespace | |
| 66 | |
| 67 void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDict ionaryVector) | |
| 68 { | |
| 69 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); | |
| 70 | |
| 71 KeyframeAnimationEffect::KeyframeVector keyframes; | |
| 72 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::creat e(); | |
| 73 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { | |
| 74 | |
| 75 Vector<String> keyframeProperties; | |
| 76 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); | |
|
Steve Block
2013/12/06 03:27:27
Move this down to line 91
rjwright
2013/12/07 11:09:06
Done.
| |
| 77 | |
| 78 RefPtr<Keyframe> keyframe = Keyframe::create(); | |
| 79 | |
| 80 double offset; | |
| 81 if (keyframeDictionaryVector[i].get("offset", offset)) | |
| 82 keyframe->setOffset(offset); | |
| 83 else | |
| 84 RELEASE_ASSERT_WITH_MESSAGE(false, "Web Animations not yet implement ed: Handling for keyframes without specified offset."); | |
| 85 | |
| 86 String compositeString; | |
| 87 keyframeDictionaryVector[i].get("composite", compositeString); | |
| 88 if (compositeString == String("add")) | |
| 89 keyframe->setComposite(AnimationEffect::CompositeAdd); | |
| 90 | |
| 91 for (size_t j = 0; j < keyframeProperties.size(); ++j) { | |
| 92 String property = keyframeProperties[j]; | |
| 93 String value; | |
| 94 keyframeDictionaryVector[i].get(property, value); | |
| 95 CSSPropertyID id = camelCasePropertyToCSSPropertyID(property); | |
| 96 | |
| 97 if (!id || !CSSAnimations::isAnimatableProperty(id)) | |
|
Steve Block
2013/12/06 03:27:27
(id != CSSPropertyInvalid || ...) for clarity
rjwright
2013/12/07 11:09:06
Done.
| |
| 98 continue; | |
|
Steve Block
2013/12/06 03:27:27
There should be a RELEASE_ASSERT or at least a FIX
rjwright
2013/12/07 11:09:06
Done.
| |
| 99 if (!CSSParser::parseValue(propertySet.get(), id, value, false, elem ent->document())) | |
| 100 continue; | |
|
Steve Block
2013/12/06 03:27:27
Same thing about a RELEASE_ASSERT or FIXME
| |
| 101 | |
| 102 RefPtr<RenderStyle> style = RenderStyle::clone(element->styleForRend erer().get()); | |
|
esprehn
2013/12/04 06:14:13
Calling styleForRenderer() repeatedly for each pro
rjwright
2013/12/07 11:09:06
Done.
| |
| 103 StyleResolverState state(element->document(), element); | |
|
esprehn
2013/12/04 06:14:13
Constructing states is not cheap, one per property
rjwright
2013/12/07 11:09:06
Done.
| |
| 104 state.setStyle(style); | |
| 105 StyleBuilder::applyProperty(id, state, propertySet->getPropertyCSSVa lue(id).get()); | |
| 106 keyframe->setPropertyValue(id, CSSAnimatableValueFactory::create(id, *style.get()).get()); | |
|
esprehn
2013/12/04 06:14:13
This does not look like the right way to do this.
rjwright
2013/12/07 11:09:06
Done.
| |
| 107 } | |
| 108 keyframes.append(keyframe); | |
| 109 } | |
| 110 | |
| 111 RefPtr<KeyframeAnimationEffect> effect = KeyframeAnimationEffect::create(key frames); | |
| 112 | |
| 113 // FIXME: Totally hardcoded Timing for now. Will handle timing parameters la ter. | |
| 114 Timing timing; | |
| 115 timing.hasIterationDuration = true; | |
| 116 timing.iterationDuration = 1; | |
| 117 | |
| 118 RefPtr<Animation> animation = Animation::create(element, effect, timing); | |
| 119 | |
| 120 DocumentTimeline* timeline = element->document().timeline(); | |
| 121 ASSERT(timeline); | |
| 122 | |
| 123 timeline->play(animation.get()); | |
| 124 } | |
| 125 | |
| 126 } // namespace WebCore | |
| OLD | NEW |