Chromium Code Reviews| Index: Source/core/wawwa/ProxyPlayer.cpp |
| diff --git a/Source/core/wawwa/ProxyPlayer.cpp b/Source/core/wawwa/ProxyPlayer.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a80b07632e3bcae80801070917a5db916261bd04 |
| --- /dev/null |
| +++ b/Source/core/wawwa/ProxyPlayer.cpp |
| @@ -0,0 +1,120 @@ |
| +/* |
| + * 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/ProxyPlayer.h" |
| + |
| +#include "core/animation/AnimationTimeline.h" |
| +#include "core/page/Page.h" |
| +#include "core/wawwa/ListOfElements.cpp" |
| + |
| +namespace blink { |
| + |
| +ProxyPlayer::ProxyPlayer(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 ProxyPlayer::execute(String 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()); |
| + if (val == "animate_element") { |
| + if (!m_player) { |
| + Document* doc = toDocument(m_worker->executionContext()); |
| + m_player = doc->timeline().play(Animation::create(m_target.get(), keyframeEffectModel, m_timingInputDictionary).get()); |
| + animated = true; |
| + } else { |
| + m_player->play(); |
| + } |
| + } else if (val == "pause_element") { |
| + m_player->pause(); |
| + } else if (val == "reverse_element") { |
| + m_player->reverse(); |
| + } else if (val == "finish_element") { |
| + m_player->finish(es); |
| + } else if (val == "cancel_element") { |
| + m_player->cancel(); |
| + } else if (val == "play_element") { |
| + m_player->play(); |
| + } |
|
shans
2014/08/25 11:53:59
with an enum, you'll be able to use a switch state
|
| +} |
| + |
| +void ProxyPlayer::reportTime() |
| +{ |
| + if (!isnan(m_player->startTime())) { |
| + Document* doc = toDocument(m_worker->executionContext()); |
| + WorkerMessagingProxy* mp = static_cast<WorkerMessagingProxy*>(m_worker->m_contextProxy); |
| + WorkerGlobalScope* hold = mp->passObject(); |
| + if (hold) { |
| + mp->postTaskToLoader(createCrossThreadTask(&ListOfElements::reportTime, AllowCrossThreadAccess(doc->page()->m_listOfElements.get()), m_elemID, m_player->startTime())); |
| + } |
| + reported = true; |
| + } |
| +} |
| + |
| +} // namespace blink |