Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/compositorworker/WorkletAnimation.h" | |
| 6 | |
| 7 #include "core/animation/DocumentTimeline.h" | |
| 8 #include "core/animation/ScrollTimeline.h" | |
| 9 #include "platform/wtf/text/WTFString.h" | |
| 10 | |
| 11 namespace blink { | |
| 12 | |
| 13 namespace { | |
| 14 bool ValidateTimelines(HeapVector<DocumentTimelineOrScrollTimeline>& timelines, | |
| 15 String* error_string) { | |
| 16 for (const auto& timeline : timelines) { | |
| 17 if (timeline.isScrollTimeline()) { | |
| 18 DoubleOrScrollTimelineAutoKeyword time_range; | |
| 19 timeline.getAsScrollTimeline()->timeRange(time_range); | |
| 20 if (time_range.isScrollTimelineAutoKeyword()) { | |
| 21 *error_string = "ScrollTimeline timeRange must have non-auto value"; | |
|
flackr
2017/05/12 18:08:23
nit: Maybe "ScrollTimeline timeRange auto is not s
smcgruer
2017/05/18 17:58:39
Done.
| |
| 22 return false; | |
| 23 } | |
| 24 } | |
| 25 } | |
| 26 return true; | |
| 27 } | |
| 28 } // namespace | |
| 29 | |
| 30 WorkletAnimation* WorkletAnimation::Create( | |
| 31 String animator_name, | |
| 32 const HeapVector<Member<KeyframeEffectReadOnly>>& effects, | |
| 33 HeapVector<DocumentTimelineOrScrollTimeline>& timelines, | |
| 34 RefPtr<SerializedScriptValue> user_data, | |
| 35 ExceptionState& exception_state) { | |
| 36 if (effects.IsEmpty()) { | |
| 37 exception_state.ThrowDOMException(kNotSupportedError, | |
| 38 "Effects array must be non-empty"); | |
| 39 return nullptr; | |
| 40 } | |
| 41 | |
| 42 if (timelines.IsEmpty()) { | |
| 43 exception_state.ThrowDOMException(kNotSupportedError, | |
| 44 "Timelines array must be non-empty"); | |
| 45 return nullptr; | |
| 46 } | |
| 47 | |
| 48 String error_string; | |
| 49 if (!ValidateTimelines(timelines, &error_string)) { | |
| 50 exception_state.ThrowDOMException(kNotSupportedError, error_string); | |
| 51 return nullptr; | |
| 52 } | |
| 53 | |
| 54 Document& document = effects.at(0)->Target()->GetDocument(); | |
|
flackr
2017/05/12 18:08:22
effects.at(0) seems a bit arbitrary, perhaps we sh
smcgruer
2017/05/18 17:58:39
Yes, we should. Done.
| |
| 55 AnimationTimeline& main_document_timeline = document.Timeline(); | |
| 56 ExecutionContext* execution_context = document.ContextDocument(); | |
| 57 | |
| 58 return new WorkletAnimation(execution_context, main_document_timeline, | |
| 59 animator_name, effects, timelines, | |
| 60 std::move(user_data)); | |
| 61 } | |
| 62 | |
| 63 WorkletAnimation::WorkletAnimation( | |
| 64 ExecutionContext* execution_context, | |
| 65 AnimationTimeline& document_timeline, | |
| 66 String animator_name, | |
| 67 const HeapVector<Member<KeyframeEffectReadOnly>>& effects, | |
| 68 HeapVector<DocumentTimelineOrScrollTimeline>& timelines, | |
| 69 RefPtr<SerializedScriptValue> user_data) | |
| 70 : Animation(execution_context, document_timeline, nullptr), | |
| 71 animator_name_(animator_name), | |
| 72 effects_(effects), | |
| 73 timelines_(timelines), | |
| 74 user_data_(std::move(user_data)) { | |
| 75 // Shut the compiler up. | |
|
flackr
2017/05/12 18:08:22
Not very nice to the compiler, fortunately I hear
smcgruer
2017/05/18 17:58:39
Heh. Just temporary, of course.
| |
| 76 (void)(effects_); | |
| 77 (void)(timelines_); | |
| 78 (void)(user_data_); | |
| 79 } | |
| 80 | |
| 81 DEFINE_TRACE(WorkletAnimation) { | |
| 82 Animation::Trace(visitor); | |
| 83 } | |
| 84 | |
| 85 } // namespace blink | |
| OLD | NEW |