OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2014 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 "bindings/core/v8/V8Element.h" | |
33 | |
34 #include "bindings/core/v8/Dictionary.h" | |
35 #include "bindings/core/v8/ExceptionState.h" | |
36 #include "bindings/core/v8/V8AnimationEffect.h" | |
37 #include "bindings/core/v8/V8AnimationPlayer.h" | |
38 #include "bindings/core/v8/V8Binding.h" | |
39 #include "bindings/core/v8/V8BindingMacros.h" | |
40 #include "core/animation/ElementAnimation.h" | |
41 #include "core/dom/Element.h" | |
42 #include "core/frame/UseCounter.h" | |
43 #include "platform/RuntimeEnabledFeatures.h" | |
44 #include "wtf/GetPtr.h" | |
45 | |
46 namespace blink { | |
47 | |
48 //////////////////////////////////////////////////////////////////////////////// | |
49 // Overload resolution for animate() | |
50 // FIXME: needs support for union types http://crbug.com/240176 | |
51 //////////////////////////////////////////////////////////////////////////////// | |
52 | |
53 // AnimationPlayer animate(AnimationEffect? effect); | |
54 void animate1Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
55 { | |
56 Element* impl = V8Element::toImpl(info.Holder()); | |
57 TONATIVE_VOID(AnimationEffect*, effect, V8AnimationEffect::toImplWithTypeChe
ck(info.GetIsolate(), info[0])); | |
58 v8SetReturnValueFast(info, WTF::getPtr(ElementAnimation::animate(*impl, effe
ct)), impl); | |
59 } | |
60 | |
61 // [RaisesException] AnimationPlayer animate(sequence<Dictionary> effect); | |
62 void animate2Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
63 { | |
64 ExceptionState exceptionState(ExceptionState::ExecutionContext, "animate", "
Element", info.Holder(), info.GetIsolate()); | |
65 Element* impl = V8Element::toImpl(info.Holder()); | |
66 TONATIVE_VOID_EXCEPTIONSTATE(Vector<Dictionary>, keyframes, toImplArray<Dict
ionary>(info[0], 1, info.GetIsolate(), exceptionState), exceptionState); | |
67 RefPtrWillBeRawPtr<AnimationPlayer> result = ElementAnimation::animate(*impl
, keyframes, exceptionState); | |
68 if (exceptionState.throwIfNeeded()) | |
69 return; | |
70 v8SetReturnValueFast(info, WTF::getPtr(result.release()), impl); | |
71 } | |
72 | |
73 // AnimationPlayer animate(AnimationEffect? effect, double timing); | |
74 void animate3Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
75 { | |
76 Element* impl = V8Element::toImpl(info.Holder()); | |
77 TONATIVE_VOID(AnimationEffect*, effect, V8AnimationEffect::toImplWithTypeChe
ck(info.GetIsolate(), info[0])); | |
78 TONATIVE_VOID(double, duration, static_cast<double>(info[1]->NumberValue()))
; | |
79 v8SetReturnValueFast(info, WTF::getPtr(ElementAnimation::animate(*impl, effe
ct, duration)), impl); | |
80 } | |
81 | |
82 // AnimationPlayer animate(AnimationEffect? effect, Dictionary timing); | |
83 void animate4Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
84 { | |
85 ExceptionState exceptionState(ExceptionState::ExecutionContext, "animate", "
Element", info.Holder(), info.GetIsolate()); | |
86 Element* impl = V8Element::toImpl(info.Holder()); | |
87 TONATIVE_VOID(AnimationEffect*, effect, V8AnimationEffect::toImplWithTypeChe
ck(info.GetIsolate(), info[0])); | |
88 TONATIVE_VOID(Dictionary, timingInput, Dictionary(info[1], info.GetIsolate()
, exceptionState)); | |
89 if (!timingInput.isUndefinedOrNull() && !timingInput.isObject()) { | |
90 V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::f
ailedToExecute("animate", "Element", "parameter 2 ('timingInput') is not an obje
ct.")); | |
91 return; | |
92 } | |
93 v8SetReturnValueFast(info, WTF::getPtr(ElementAnimation::animate(*impl, effe
ct, timingInput)), impl); | |
94 } | |
95 | |
96 // [RaisesException] AnimationPlayer animate(sequence<Dictionary> effect, double
timing); | |
97 void animate5Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
98 { | |
99 ExceptionState exceptionState(ExceptionState::ExecutionContext, "animate", "
Element", info.Holder(), info.GetIsolate()); | |
100 Element* impl = V8Element::toImpl(info.Holder()); | |
101 TONATIVE_VOID_EXCEPTIONSTATE(Vector<Dictionary>, keyframes, toImplArray<Dict
ionary>(info[0], 1, info.GetIsolate(), exceptionState), exceptionState); | |
102 TONATIVE_VOID(double, duration, static_cast<double>(info[1]->NumberValue()))
; | |
103 RefPtrWillBeRawPtr<AnimationPlayer> result = ElementAnimation::animate(*impl
, keyframes, duration, exceptionState); | |
104 if (exceptionState.throwIfNeeded()) | |
105 return; | |
106 v8SetReturnValueFast(info, WTF::getPtr(result.release()), impl); | |
107 } | |
108 | |
109 // [RaisesException] AnimationPlayer animate(sequence<Dictionary> effect, Dictio
nary timing); | |
110 void animate6Method(const v8::FunctionCallbackInfo<v8::Value>& info) | |
111 { | |
112 ExceptionState exceptionState(ExceptionState::ExecutionContext, "animate", "
Element", info.Holder(), info.GetIsolate()); | |
113 Element* impl = V8Element::toImpl(info.Holder()); | |
114 TONATIVE_VOID_EXCEPTIONSTATE(Vector<Dictionary>, keyframes, toImplArray<Dict
ionary>(info[0], 1, info.GetIsolate(), exceptionState), exceptionState); | |
115 TONATIVE_VOID(Dictionary, timingInput, Dictionary(info[1], info.GetIsolate()
, exceptionState)); | |
116 if (!timingInput.isUndefinedOrNull() && !timingInput.isObject()) { | |
117 exceptionState.throwTypeError("parameter 2 ('timingInput') is not an obj
ect."); | |
118 exceptionState.throwIfNeeded(); | |
119 return; | |
120 } | |
121 RefPtrWillBeRawPtr<AnimationPlayer> result = ElementAnimation::animate(*impl
, keyframes, timingInput, exceptionState); | |
122 if (exceptionState.throwIfNeeded()) | |
123 return; | |
124 v8SetReturnValueFast(info, WTF::getPtr(result.release()), impl); | |
125 } | |
126 | |
127 void V8Element::animateMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& i
nfo) | |
128 { | |
129 v8::Isolate* isolate = info.GetIsolate(); | |
130 ExceptionState exceptionState(ExceptionState::ExecutionContext, "animate", "
Element", info.Holder(), isolate); | |
131 // AnimationPlayer animate( | |
132 // (AnimationEffect or sequence<Dictionary>)? effect, | |
133 // optional (double or Dictionary) timing); | |
134 switch (info.Length()) { | |
135 case 1: | |
136 // null resolved as to AnimationEffect, as if the member were nullable: | |
137 // (AnimationEffect? or sequence<Dictionary>) | |
138 // instead of the *union* being nullable: | |
139 // (AnimationEffect or sequence<Dictionary>)? | |
140 // AnimationPlayer animate(AnimationEffect? effect); | |
141 if (info[0]->IsNull()) { | |
142 animate1Method(info); | |
143 return; | |
144 } | |
145 // AnimationPlayer animate(AnimationEffect effect); | |
146 if (V8AnimationEffect::hasInstance(info[0], isolate)) { | |
147 animate1Method(info); | |
148 return; | |
149 } | |
150 // [MeasureAs=ElementAnimateKeyframeListEffectNoTiming] | |
151 // AnimationPlayer animate(sequence<Dictionary> effect); | |
152 if (info[0]->IsArray()) { | |
153 UseCounter::countIfNotPrivateScript(isolate, callingExecutionContext
(isolate), UseCounter::ElementAnimateKeyframeListEffectNoTiming); | |
154 animate2Method(info); | |
155 return; | |
156 } | |
157 break; | |
158 case 2: | |
159 // As above, null resolved to AnimationEffect | |
160 // AnimationPlayer animate(AnimationEffect? effect, Dictionary timing); | |
161 if (info[0]->IsNull() && info[1]->IsObject()) { | |
162 animate4Method(info); | |
163 return; | |
164 } | |
165 // AnimationPlayer animate(AnimationEffect? effect, double timing); | |
166 if (info[0]->IsNull()) { | |
167 animate3Method(info); | |
168 return; | |
169 } | |
170 // AnimationPlayer animate(AnimationEffect effect, Dictionary timing); | |
171 if (V8AnimationEffect::hasInstance(info[0], isolate) | |
172 && info[1]->IsObject()) { | |
173 animate4Method(info); | |
174 return; | |
175 } | |
176 // AnimationPlayer animate(AnimationEffect effect, double timing); | |
177 if (V8AnimationEffect::hasInstance(info[0], isolate)) { | |
178 animate3Method(info); | |
179 return; | |
180 } | |
181 // [MeasureAs=ElementAnimateKeyframeListEffectObjectTiming] | |
182 // AnimationPlayer animate(sequence<Dictionary> effect, Dictionary timin
g); | |
183 if (info[0]->IsArray() && info[1]->IsObject()) { | |
184 UseCounter::countIfNotPrivateScript(isolate, callingExecutionContext
(isolate), UseCounter::ElementAnimateKeyframeListEffectObjectTiming); | |
185 animate6Method(info); | |
186 return; | |
187 } | |
188 // [MeasureAs=ElementAnimateKeyframeListEffectDoubleTiming] | |
189 // AnimationPlayer animate(sequence<Dictionary> effect, double timing); | |
190 if (info[0]->IsArray()) { | |
191 UseCounter::countIfNotPrivateScript(isolate, callingExecutionContext
(isolate), UseCounter::ElementAnimateKeyframeListEffectDoubleTiming); | |
192 animate5Method(info); | |
193 return; | |
194 } | |
195 break; | |
196 default: | |
197 setArityTypeError(exceptionState, "[1]", info.Length()); | |
198 exceptionState.throwIfNeeded(); | |
199 return; | |
200 break; | |
201 } | |
202 exceptionState.throwTypeError("No function was found that matched the signat
ure provided."); | |
203 exceptionState.throwIfNeeded(); | |
204 } | |
205 | |
206 } // namespace blink | |
OLD | NEW |