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

Side by Side Diff: Source/core/wawwa/ProxyPlayer.cpp

Issue 491053004: Expose Web Animations API to Web Workers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
(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{
25
26 } LOSS OF USE,
27 * DATA, OR PROFITS{
28
29 } OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include "config.h"
36 #include "core/wawwa/ProxyPlayer.h"
37
38 #include "core/animation/AnimationTimeline.h"
39 #include "core/page/Page.h"
40 #include "core/wawwa/ListOfElements.cpp"
41
42 namespace blink {
43
44 ProxyPlayer::ProxyPlayer(String id, Vector<ProxyKeyframe> keyframes, Timing timi ngInputDictionary, ExceptionState& es, PassRefPtr<Worker> worker)
45 : m_worker(worker)
46 , m_target(toDocument(m_worker->executionContext())->documentElement()->quer ySelector(*(new AtomicString(id)), es))
47 {
48 m_elemID = id;
49 m_player = 0;
50 for (size_t i = 0; i < keyframes.size(); i++) {
51 m_keyframes.append(keyframes[i]);
52 }
53 m_timingInputDictionary = timingInputDictionary;
54 animated = false;
55 reported = false;
56 }
57
58 void ProxyPlayer::execute(String val, ExceptionState& es)
59 {
60 StyleSheetContents* styleSheetContents = m_target->document().elementSheet() .contents();
61 StringKeyframeVector keyframes;
62 for (size_t i = 0; i < m_keyframes.size(); ++i) {
63 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create();
64
65 if (m_keyframes[i].offset != 2) {
66 keyframe->setOffset(m_keyframes[i].offset);
67 }
68 if (m_keyframes[i].composite == "add")
69 keyframe->setComposite(AnimationEffect::CompositeAdd);
70 if (m_keyframes[i].easing.length() > 0) {
71 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(m_keyframes[i].easing);
72 keyframe->setEasing(CSSToStyleMap::mapAnimationTimingFunction(timing FunctionValue.get(), true));
73 }
74
75 for (size_t j = 0; j < m_keyframes[i].pairs.size(); ++j) {
76 keyframe->setPropertyValue(camelCaseCSSPropertyNameToID(m_keyframes[ i].pairs[j].property), m_keyframes[i].pairs[j].value, styleSheetContents);
77 }
78 keyframes.append(keyframe);
79 }
80 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes);
81 if (!keyframeEffectModel->isReplaceOnly()) {
82 es.throwDOMException(NotSupportedError, "Partial keyframes are not suppo rted.");
83 return;
84 }
85 keyframeEffectModel->forceConversionsToAnimatableValues(m_target.get());
86 if (val == "animate_element") {
87 if (!m_player) {
88 Document* doc = toDocument(m_worker->executionContext());
89 m_player = doc->timeline().play(Animation::create(m_target.get(), ke yframeEffectModel, m_timingInputDictionary).get());
90 animated = true;
91 } else {
92 m_player->play();
93 }
94 } else if (val == "pause_element") {
95 m_player->pause();
96 } else if (val == "reverse_element") {
97 m_player->reverse();
98 } else if (val == "finish_element") {
99 m_player->finish(es);
100 } else if (val == "cancel_element") {
101 m_player->cancel();
102 } else if (val == "play_element") {
103 m_player->play();
104 }
shans 2014/08/25 11:53:59 with an enum, you'll be able to use a switch state
105 }
106
107 void ProxyPlayer::reportTime()
108 {
109 if (!isnan(m_player->startTime())) {
110 Document* doc = toDocument(m_worker->executionContext());
111 WorkerMessagingProxy* mp = static_cast<WorkerMessagingProxy*>(m_worker-> m_contextProxy);
112 WorkerGlobalScope* hold = mp->passObject();
113 if (hold) {
114 mp->postTaskToLoader(createCrossThreadTask(&ListOfElements::reportTi me, AllowCrossThreadAccess(doc->page()->m_listOfElements.get()), m_elemID, m_pla yer->startTime()));
115 }
116 reported = true;
117 }
118 }
119
120 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698