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

Unified Diff: Source/core/wawwa/RemotePlayerProxy.cpp

Issue 491053004: Expose Web Animations API to Web Workers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Exposing the Web Animations API to Web Workers Created 6 years, 4 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: Source/core/wawwa/RemotePlayerProxy.cpp
diff --git a/Source/core/wawwa/RemotePlayerProxy.cpp b/Source/core/wawwa/RemotePlayerProxy.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bb1a61800641d3cd0b10314690c7e0d21f4333f8
--- /dev/null
+++ b/Source/core/wawwa/RemotePlayerProxy.cpp
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2014 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES{
+
+ } LOSS OF USE,
+ * DATA, OR PROFITS{
+
+ } OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "core/wawwa/RemotePlayerProxy.h"
+
+#include "core/animation/AnimationTimeline.h"
+#include "core/page/Page.h"
+#include "core/wawwa/ProxyMap.cpp"
+
+namespace blink {
+
+RemotePlayerProxy::RemotePlayerProxy(String id, Vector<ProxyKeyframe> keyframes, Timing timingInputDictionary, ExceptionState& es, PassRefPtr<Worker> worker)
+ : m_worker(worker)
+ , m_target(toDocument(m_worker->executionContext())->documentElement()->querySelector(*(new AtomicString(id)), es))
+{
+ m_elemID = id;
+ m_player = 0;
+ for (size_t i = 0; i < keyframes.size(); i++) {
+ m_keyframes.append(keyframes[i]);
+ }
+ m_timingInputDictionary = timingInputDictionary;
+ animated = false;
+ reported = false;
+}
+
+void RemotePlayerProxy::execute(ACTIONS val, ExceptionState& es)
+{
+ StyleSheetContents* styleSheetContents = m_target->document().elementSheet().contents();
+ StringKeyframeVector keyframes;
+ for (size_t i = 0; i < m_keyframes.size(); ++i) {
+ RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create();
+
+ if (m_keyframes[i].offset != 2) {
+ keyframe->setOffset(m_keyframes[i].offset);
+ }
+ if (m_keyframes[i].composite == "add")
+ keyframe->setComposite(AnimationEffect::CompositeAdd);
+ if (m_keyframes[i].easing.length() > 0) {
+ RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::parseAnimationTimingFunctionValue(m_keyframes[i].easing);
+ keyframe->setEasing(CSSToStyleMap::mapAnimationTimingFunction(timingFunctionValue.get(), true));
+ }
+
+ for (size_t j = 0; j < m_keyframes[i].pairs.size(); ++j) {
+ keyframe->setPropertyValue(camelCaseCSSPropertyNameToID(m_keyframes[i].pairs[j].property), m_keyframes[i].pairs[j].value, styleSheetContents);
+ }
+ keyframes.append(keyframe);
+ }
+ RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKeyframeEffectModel::create(keyframes);
+ if (!keyframeEffectModel->isReplaceOnly()) {
+ es.throwDOMException(NotSupportedError, "Partial keyframes are not supported.");
+ return;
+ }
+ keyframeEffectModel->forceConversionsToAnimatableValues(m_target.get());
+ switch (val) {
+ case blink::Animate:
+ if (!m_player) {
+ Document* doc = toDocument(m_worker->executionContext());
+ Animation* node = Animation::create(m_target.get(), keyframeEffectModel, m_timingInputDictionary).get();
+ m_player = doc->timeline().play(node);
+ animated = true;
+ return;
+ }
+ m_player->play();
+ case blink::Pause:
+ m_player->pause();
+ return;
+ case blink::Reverse:
+ m_player->reverse();
+ return;
+ case blink::Finish:
+ m_player->finish(es);
+ return;
+ case blink::Cancel:
+ m_player->cancel();
+ return;
+ case blink::Play:
+ m_player->play();
+ return;
+ }
+}
+
+void RemotePlayerProxy::reportTime()
+{
+ if (!isnan(m_player->startTime())) {
+ Document* doc = toDocument(m_worker->executionContext());
+ WorkerMessagingProxy* mp = static_cast<WorkerMessagingProxy*>(m_worker->m_contextProxy);
+ WorkerGlobalScope* hold = mp->extractWorkerGlobalScope();
+ if (hold) {
+ mp->postTaskToLoader(createCrossThreadTask(&ProxyMap::reportTime, AllowCrossThreadAccess(doc->page()->m_ProxyMap.get()), m_elemID, m_player->startTime()));
+ }
+ reported = true;
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698