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 | |
|
Steve Block
2013/11/29 07:31:19
NO blank line here
rjwright
2013/12/04 05:05:54
Done.
| |
| 33 #include "core/animation/AnimatedElement.h" | |
| 34 | |
| 35 #include "core/animation/AnimatableLength.h" | |
| 36 #include "core/animation/AnimationEffect.h" | |
| 37 #include "core/animation/DocumentTimeline.h" | |
| 38 #include "core/animation/KeyframeAnimationEffect.h" | |
| 39 #include "core/animation/css/CSSAnimatableValueFactory.h" | |
| 40 #include "core/animation/css/CSSAnimations.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 bool isUpper(UChar ch) { return isASCIIUpper(ch); } | |
|
Steve Block
2013/11/29 07:31:19
Why do you need this wrapper function?
rjwright
2013/12/04 05:05:54
We don't.
Done.
| |
| 53 | |
| 54 static CSSPropertyID v8PropertyToCSSPropertyID(String propertyName) | |
|
Steve Block
2013/11/29 07:31:19
I'm surprised we don't have this logic elsewhere f
apavlov
2013/11/29 09:19:02
FWIW, this logic (and a little bit more :)) is fou
rjwright
2013/12/04 05:05:54
Name change done. The logic exists elsewhere but n
rjwright
2013/12/04 05:05:54
Yes that's where I copied it from. There was no ob
| |
| 55 { | |
| 56 StringBuilder builder; | |
| 57 size_t position = 0; | |
| 58 while (true) { | |
| 59 size_t end = propertyName.find(isUpper, position); | |
| 60 if (end == kNotFound) { | |
|
Steve Block
2013/11/29 07:31:19
Is this simpler ...
size_t end;
while (end = prop
rjwright
2013/12/04 05:05:54
Done.
| |
| 61 builder.append(propertyName.substring(position)); | |
| 62 break; | |
| 63 } | |
| 64 builder.append(propertyName.substring(position, end) + "-" + toASCIILowe r(propertyName[end])); | |
| 65 position = end + 1; | |
| 66 } | |
| 67 return cssPropertyID(builder.toString()); | |
| 68 } | |
| 69 | |
| 70 } // namespace | |
| 71 | |
| 72 void AnimatedElement::animate(Element* element, Vector<Dictionary> dictionaryKey framesVector) | |
|
Steve Block
2013/11/29 07:31:19
s/dictionaryKeyframesVector/keyframeDictionaryVect
rjwright
2013/12/04 05:05:54
Done.
| |
| 73 { | |
| 74 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); | |
| 75 | |
| 76 KeyframeAnimationEffect::KeyframeVector keyframes; | |
| 77 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::creat e(); | |
| 78 for (size_t i = 0; i < dictionaryKeyframesVector.size(); ++i) { | |
| 79 | |
| 80 Vector<String> keyframeProperties; | |
| 81 dictionaryKeyframesVector[i].getOwnPropertyNames(keyframeProperties); | |
| 82 | |
| 83 if (!keyframeProperties.size()) | |
|
Steve Block
2013/11/29 07:31:19
This is incorrect. The spec requires that animatio
rjwright
2013/12/04 05:05:54
Done.
| |
| 84 continue; | |
| 85 | |
| 86 keyframes.append(Keyframe::create()); | |
|
Steve Block
2013/11/29 07:31:19
Probably best to build up the keyframe before appe
rjwright
2013/12/04 05:05:54
Done.
| |
| 87 | |
| 88 double offset; | |
| 89 if (dictionaryKeyframesVector[i].get("offset", offset)) | |
| 90 keyframes.last()->setOffset(offset); | |
| 91 else | |
| 92 keyframes.last()->setOffset(std::numeric_limits<double>::quiet_NaN() ); | |
|
Steve Block
2013/11/29 07:31:19
No need for this, it's the default offset for a ke
rjwright
2013/12/04 05:05:54
Done. nullValue()?
| |
| 93 | |
| 94 String compositeOperationString; | |
| 95 dictionaryKeyframesVector[i].get("compositeOperation", compositeOperatio nString); | |
|
Steve Block
2013/12/02 04:45:45
This should be 'composite'. 'CompositeOperation' i
rjwright
2013/12/04 05:05:54
Done.
| |
| 96 if (compositeOperationString == String("add")) | |
| 97 keyframes.last()->setComposite(AnimationEffect::CompositeAdd); | |
| 98 else | |
| 99 keyframes.last()->setComposite(AnimationEffect::CompositeReplace); | |
|
Steve Block
2013/11/29 07:31:19
Again, keyframes use replace composition by defaul
rjwright
2013/12/04 05:05:54
Done.
| |
| 100 | |
| 101 for (size_t j = 0; j < keyframeProperties.size(); ++j) { | |
| 102 String property = keyframeProperties[j]; | |
| 103 String value; | |
| 104 dictionaryKeyframesVector[i].get(property, value); | |
| 105 CSSPropertyID id = v8PropertyToCSSPropertyID(property); | |
| 106 | |
| 107 if (!id || !CSSAnimations::isAnimatableProperty(id)) | |
|
Steve Block
2013/11/29 07:31:19
Isn't there a CSSPropertyInvalid we can use here?
rjwright
2013/12/04 05:05:54
If the property from the dictionary isn't a valid
| |
| 108 continue; | |
|
Steve Block
2013/11/29 07:31:19
Again, we shouldn't be skipping invalid keyframes
Steve Block
2013/12/02 01:59:43
I guess we need to decide whether to change the AP
rjwright
2013/12/04 05:05:54
We should discuss this. There's a bunch of differe
| |
| 109 if (!CSSParser::parseValue(propertySet.get(), id, value, false, elem ent->document())) | |
| 110 continue; | |
|
Steve Block
2013/11/29 07:31:19
Same as above
rjwright
2013/12/04 05:05:54
I can't change this to anything more meaningful un
| |
| 111 | |
| 112 RefPtr<RenderStyle> style = RenderStyle::clone(element->styleForRend erer().get()); | |
| 113 StyleResolverState state(element->document(), element); | |
| 114 state.setStyle(style); | |
| 115 StyleBuilder::applyProperty(id, state, propertySet->getPropertyCSSVa lue(id).get()); | |
| 116 keyframes.last()->setPropertyValue(id, CSSAnimatableValueFactory::cr eate(id, *style.get()).get()); | |
| 117 } | |
| 118 if (!keyframes.last()->properties().size() && isnan(keyframes.last()->of fset())) | |
|
Steve Block
2013/11/29 07:31:19
Same comment about getFrames(). Also, use isEmpty(
rjwright
2013/12/04 05:05:54
Done.
| |
| 119 keyframes.removeLast(); | |
| 120 } | |
| 121 | |
| 122 RefPtr<KeyframeAnimationEffect> effect = KeyframeAnimationEffect::create(key frames); | |
| 123 | |
| 124 // FIXME: Totally hardcoded Timing for now. Will handle timing parameters la ter. | |
| 125 Timing timing; | |
| 126 timing.hasIterationDuration = true; | |
| 127 timing.iterationDuration = 1; | |
| 128 timing.iterationCount = 1; | |
|
Steve Block
2013/11/29 07:31:19
Superfluous. The default iterationCount is 1.
rjwright
2013/12/04 05:05:54
Done.
| |
| 129 | |
| 130 RefPtr<Animation> animation = Animation::create(element, effect, timing); | |
| 131 | |
| 132 DocumentTimeline* timeline = element->document().timeline(); | |
|
Steve Block
2013/11/29 07:31:19
ASSERT(timeline)
rjwright
2013/12/04 05:05:54
Done.
| |
| 133 // FIXME: If any property appears in only one keyframe (which includes the c ase where there is | |
| 134 // only one keyframe) this crashes. | |
|
Steve Block
2013/11/29 07:31:19
This shouldn't be the case. KeyframeAnimationEffec
Steve Block
2013/12/02 04:45:45
I think you're just seeing the fact that add compo
rjwright
2013/12/04 05:05:54
Yep that's it. In that case I'll just pass those c
| |
| 135 // Handling for this case not yet implemented. | |
| 136 // We can check for this here but the check will be pretty clunky. Prefer to add release-assert | |
| 137 // where implementation is missing. | |
| 138 // | |
| 139 // FIXME: If there are more than two keyframes and any of those keyframes do esn't have a specified | |
|
Steve Block
2013/11/29 07:31:19
It's not clear which of these you plan to fix befo
rjwright
2013/12/04 05:05:54
Done.
| |
| 140 // offset, this crashes. If there are exactly two keyframes then missing off sets are ok. | |
| 141 // Handling for this case not yet implemented. | |
|
Steve Block
2013/11/29 07:31:19
This will be handled by KeyframeAnimationEffect. S
rjwright
2013/12/04 05:05:54
Done.
| |
| 142 // Can restrict input to 2 keyframes, or check that either all keyframes hav e offsets | |
| 143 // or no keyframes have offsets, or add release assert where implementation is missing. | |
| 144 timeline->play(animation.get()); | |
| 145 } | |
| 146 | |
| 147 } // namespace WebCore | |
| OLD | NEW |