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

Side by Side Diff: Source/core/wawwa/AnimatableElement.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/AnimatableElement.h"
37
38 namespace blink {
39
40 AnimatableElement::AnimatableElement(String inputID)
41 : m_id(inputID)
42 {
43 }
44
45 PassRefPtrWillBeRawPtr<AnimatableElement> AnimatableElement::create(String input ID)
46 {
47 return adoptRef(new AnimatableElement(inputID));
48 }
49
50 AnimatableElement * AnimatableElement::clone()
51 {
52 return new AnimatableElement(m_id);
53 }
54
55 PassRefPtrWillBeRawPtr<MockAnimationPlayer> AnimatableElement::animate(const Vec tor<Dictionary>& keyframeDictionaryVector, const Dictionary& timingInputDictiona ry, PassRefPtr<DedicatedWorkerGlobalScope> workerGlobalScope, ExceptionState& es )
56 {
57 String temp = m_id.isolatedCopy();
58 String action = "animate_element";
59 action = action.isolatedCopy();
60 if (!temp.isSafeToSendToAnotherThread() || !action.isSafeToSendToAnotherThre ad()) {
61 exit(42);
shans 2014/08/25 11:53:58 ASSERT(temp.isSafeToSendToAnotherThread() && actio
62 }
63 Document* doc = static_cast<Document*>(workerGlobalScope->thread()->workerOb jectProxy().context());
64 Page* page = doc->page();
65
66 Timing ti = TimingInput::convert(timingInputDictionary);
67
68 Vector<ProxyKeyframe> holdVector;
69
70 ProxyKeyframe keyframe;
71 double lastOffset = 0;
72 for (size_t i = 0; i < keyframeDictionaryVector.size(); i++) {
73 ScriptValue scriptValue;
74 bool frameHasOffset = DictionaryHelper::get(keyframeDictionaryVector[i], "offset", scriptValue) && !scriptValue.isNull();
75 if (frameHasOffset) {
76 double offset;
77 DictionaryHelper::get(keyframeDictionaryVector[i], "offset", offset) ;
78 if (std::isnan(offset)) {
79 es.throwDOMException(InvalidModificationError, "Non numeric offs et provided");
80 }
81 if (offset < 0 || offset > 1) {
82 es.throwDOMException(InvalidModificationError, "Offsets provided outside the range [0, 1]");
83 return nullptr;
84 }
85 if (offset < lastOffset) {
86 es.throwDOMException(InvalidModificationError, "Keyframes with s pecified offsets are not sorted");
87 return nullptr;
88 }
89 lastOffset = offset;
90 keyframe.offset = offset;
91 }
92 keyframe.offset = 2;
93 String compositeString;
94 DictionaryHelper::get(keyframeDictionaryVector[i], "composite", composit eString);
95 if (compositeString == "add")
96 keyframe.composite = compositeString;
97 String timingFunctionString;
98 if (DictionaryHelper::get(keyframeDictionaryVector[i], "easing", timingF unctionString)) {
99 if (RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParse r::parseAnimationTimingFunctionValue(timingFunctionString))
100 keyframe.easing = timingFunctionString;
101 }
102
103 Vector<String> holdProperties;
104 holdProperties.clear();
105 keyframe.pairs.clear();
106 keyframeDictionaryVector[i].getOwnPropertyNames(holdProperties);
107 for (size_t j = 0; j < holdProperties.size(); j++) {
108 String property = holdProperties[j];
109 String value;
110 DictionaryHelper::get(keyframeDictionaryVector[i], property, value);
111 ProxyPairs pair1 = {property, value};
112 keyframe.pairs.append(pair1);
113 }
114 holdVector.append(keyframe);
115 }
116 workerGlobalScope->thread()->workerObjectProxy().postTaskToMainExecutionCont ext(createCrossThreadTask(&ListOfElements::execute, AllowCrossThreadAccess(page- >m_listOfElements.get()), action, temp, holdVector, ti));
shans 2014/08/25 11:53:58 This could be split onto a few lines for better re
117 return adoptRef(new MockAnimationPlayer(m_id, workerGlobalScope, holdVector, ti));
118 }
119
120 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698