Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(442)

Unified Diff: third_party/WebKit/Source/modules/compositorworker/WorkletAnimation.cpp

Issue 2869183002: Initial implementation of WorkletAnimation (Closed)
Patch Set: Make WorkletAnimation subclass Animation Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/compositorworker/WorkletAnimation.cpp
diff --git a/third_party/WebKit/Source/modules/compositorworker/WorkletAnimation.cpp b/third_party/WebKit/Source/modules/compositorworker/WorkletAnimation.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..1532fb2ac348d91e735d26adde41d31d865d4106
--- /dev/null
+++ b/third_party/WebKit/Source/modules/compositorworker/WorkletAnimation.cpp
@@ -0,0 +1,85 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/compositorworker/WorkletAnimation.h"
+
+#include "core/animation/DocumentTimeline.h"
+#include "core/animation/ScrollTimeline.h"
+#include "platform/wtf/text/WTFString.h"
+
+namespace blink {
+
+namespace {
+bool ValidateTimelines(HeapVector<DocumentTimelineOrScrollTimeline>& timelines,
+ String* error_string) {
+ for (const auto& timeline : timelines) {
+ if (timeline.isScrollTimeline()) {
+ DoubleOrScrollTimelineAutoKeyword time_range;
+ timeline.getAsScrollTimeline()->timeRange(time_range);
+ if (time_range.isScrollTimelineAutoKeyword()) {
+ *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.
+ return false;
+ }
+ }
+ }
+ return true;
+}
+} // namespace
+
+WorkletAnimation* WorkletAnimation::Create(
+ String animator_name,
+ const HeapVector<Member<KeyframeEffectReadOnly>>& effects,
+ HeapVector<DocumentTimelineOrScrollTimeline>& timelines,
+ RefPtr<SerializedScriptValue> user_data,
+ ExceptionState& exception_state) {
+ if (effects.IsEmpty()) {
+ exception_state.ThrowDOMException(kNotSupportedError,
+ "Effects array must be non-empty");
+ return nullptr;
+ }
+
+ if (timelines.IsEmpty()) {
+ exception_state.ThrowDOMException(kNotSupportedError,
+ "Timelines array must be non-empty");
+ return nullptr;
+ }
+
+ String error_string;
+ if (!ValidateTimelines(timelines, &error_string)) {
+ exception_state.ThrowDOMException(kNotSupportedError, error_string);
+ return nullptr;
+ }
+
+ 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.
+ AnimationTimeline& main_document_timeline = document.Timeline();
+ ExecutionContext* execution_context = document.ContextDocument();
+
+ return new WorkletAnimation(execution_context, main_document_timeline,
+ animator_name, effects, timelines,
+ std::move(user_data));
+}
+
+WorkletAnimation::WorkletAnimation(
+ ExecutionContext* execution_context,
+ AnimationTimeline& document_timeline,
+ String animator_name,
+ const HeapVector<Member<KeyframeEffectReadOnly>>& effects,
+ HeapVector<DocumentTimelineOrScrollTimeline>& timelines,
+ RefPtr<SerializedScriptValue> user_data)
+ : Animation(execution_context, document_timeline, nullptr),
+ animator_name_(animator_name),
+ effects_(effects),
+ timelines_(timelines),
+ user_data_(std::move(user_data)) {
+ // 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.
+ (void)(effects_);
+ (void)(timelines_);
+ (void)(user_data_);
+}
+
+DEFINE_TRACE(WorkletAnimation) {
+ Animation::Trace(visitor);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698