OLD | NEW |
(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/RemotePlayerProxy.h" |
| 37 |
| 38 #include "core/animation/AnimationTimeline.h" |
| 39 #include "core/page/Page.h" |
| 40 #include "core/wawwa/ProxyMap.cpp" |
| 41 |
| 42 namespace blink { |
| 43 |
| 44 RemotePlayerProxy::RemotePlayerProxy(String id, Vector<ProxyKeyframe> keyframes,
Timing timingInputDictionary, 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 RemotePlayerProxy::execute(ACTIONS 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 switch (val) { |
| 87 case blink::Animate: |
| 88 if (!m_player) { |
| 89 Document* doc = toDocument(m_worker->executionContext()); |
| 90 Animation* node = Animation::create(m_target.get(), keyframeEffectMo
del, m_timingInputDictionary).get(); |
| 91 m_player = doc->timeline().play(node); |
| 92 animated = true; |
| 93 return; |
| 94 } |
| 95 m_player->play(); |
| 96 case blink::Pause: |
| 97 m_player->pause(); |
| 98 return; |
| 99 case blink::Reverse: |
| 100 m_player->reverse(); |
| 101 return; |
| 102 case blink::Finish: |
| 103 m_player->finish(es); |
| 104 return; |
| 105 case blink::Cancel: |
| 106 m_player->cancel(); |
| 107 return; |
| 108 case blink::Play: |
| 109 m_player->play(); |
| 110 return; |
| 111 } |
| 112 } |
| 113 |
| 114 void RemotePlayerProxy::reportTime() |
| 115 { |
| 116 if (!isnan(m_player->startTime())) { |
| 117 Document* doc = toDocument(m_worker->executionContext()); |
| 118 WorkerMessagingProxy* mp = static_cast<WorkerMessagingProxy*>(m_worker->
m_contextProxy); |
| 119 WorkerGlobalScope* hold = mp->extractWorkerGlobalScope(); |
| 120 if (hold) { |
| 121 mp->postTaskToLoader(createCrossThreadTask(&ProxyMap::reportTime, Al
lowCrossThreadAccess(doc->page()->m_ProxyMap.get()), m_elemID, m_player->startTi
me())); |
| 122 } |
| 123 reported = true; |
| 124 } |
| 125 } |
| 126 |
| 127 } // namespace blink |
OLD | NEW |