2016-03-07 08:11:11 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/TimingParams.h"
|
|
|
|
|
2016-03-22 10:20:31 +03:00
|
|
|
#include "mozilla/AnimationUtils.h"
|
|
|
|
#include "mozilla/dom/AnimatableBinding.h"
|
2019-01-08 09:45:18 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-09-08 23:38:53 +03:00
|
|
|
#include "mozilla/dom/KeyframeAnimationOptionsBinding.h"
|
2016-03-22 10:20:31 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffectBinding.h"
|
2017-12-01 12:35:47 +03:00
|
|
|
#include "mozilla/ServoCSSParser.h"
|
2016-03-11 11:27:34 +03:00
|
|
|
|
2016-03-07 08:11:11 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
template <class OptionsType>
|
2018-05-07 06:09:54 +03:00
|
|
|
static const dom::EffectTiming& GetTimingProperties(
|
2016-03-07 08:11:11 +03:00
|
|
|
const OptionsType& aOptions);
|
|
|
|
|
|
|
|
template <>
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
const dom::EffectTiming& GetTimingProperties(
|
2016-03-07 08:11:11 +03:00
|
|
|
const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions) {
|
|
|
|
MOZ_ASSERT(aOptions.IsKeyframeEffectOptions());
|
|
|
|
return aOptions.GetAsKeyframeEffectOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
const dom::EffectTiming& GetTimingProperties(
|
2016-03-07 08:11:11 +03:00
|
|
|
const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions) {
|
|
|
|
MOZ_ASSERT(aOptions.IsKeyframeAnimationOptions());
|
|
|
|
return aOptions.GetAsKeyframeAnimationOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class OptionsType>
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
TimingParams TimingParams::FromOptionsType(const OptionsType& aOptions,
|
|
|
|
dom::Document* aDocument,
|
|
|
|
ErrorResult& aRv) {
|
2016-03-09 08:01:45 +03:00
|
|
|
TimingParams result;
|
2018-05-07 06:34:47 +03:00
|
|
|
|
2016-03-07 08:11:11 +03:00
|
|
|
if (aOptions.IsUnrestrictedDouble()) {
|
2016-03-09 08:01:45 +03:00
|
|
|
double durationInMs = aOptions.GetAsUnrestrictedDouble();
|
|
|
|
if (durationInMs >= 0) {
|
|
|
|
result.mDuration.emplace(
|
|
|
|
StickyTimeDuration::FromMilliseconds(durationInMs));
|
|
|
|
} else {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_TYPE_ERR);
|
2017-06-22 06:12:42 +03:00
|
|
|
return result;
|
2016-03-09 08:01:45 +03:00
|
|
|
}
|
2018-05-07 06:34:47 +03:00
|
|
|
result.Update();
|
2016-03-07 08:11:11 +03:00
|
|
|
} else {
|
2018-05-07 06:09:54 +03:00
|
|
|
const dom::EffectTiming& timing = GetTimingProperties(aOptions);
|
2018-05-07 06:34:47 +03:00
|
|
|
result = FromEffectTiming(timing, aDocument, aRv);
|
2016-03-07 08:11:11 +03:00
|
|
|
}
|
2017-06-22 06:12:43 +03:00
|
|
|
|
2016-03-09 08:01:45 +03:00
|
|
|
return result;
|
2016-03-07 08:11:11 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
TimingParams TimingParams::FromOptionsUnion(
|
2016-03-07 08:11:11 +03:00
|
|
|
const dom::UnrestrictedDoubleOrKeyframeEffectOptions& aOptions,
|
2019-01-08 09:45:18 +03:00
|
|
|
dom::Document* aDocument, ErrorResult& aRv) {
|
2017-06-22 06:12:42 +03:00
|
|
|
return FromOptionsType(aOptions, aDocument, aRv);
|
2016-03-07 08:11:11 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
TimingParams TimingParams::FromOptionsUnion(
|
2016-03-07 08:11:11 +03:00
|
|
|
const dom::UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
|
2019-01-08 09:45:18 +03:00
|
|
|
dom::Document* aDocument, ErrorResult& aRv) {
|
2017-06-22 06:12:42 +03:00
|
|
|
return FromOptionsType(aOptions, aDocument, aRv);
|
2016-03-07 08:11:11 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
TimingParams TimingParams::FromEffectTiming(
|
2019-01-08 09:45:18 +03:00
|
|
|
const dom::EffectTiming& aEffectTiming, dom::Document* aDocument,
|
2018-05-07 06:34:47 +03:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
TimingParams result;
|
|
|
|
|
|
|
|
Maybe<StickyTimeDuration> duration =
|
|
|
|
TimingParams::ParseDuration(aEffectTiming.mDuration, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
TimingParams::ValidateIterationStart(aEffectTiming.mIterationStart, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
TimingParams::ValidateIterations(aEffectTiming.mIterations, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
Maybe<ComputedTimingFunction> easing =
|
|
|
|
TimingParams::ParseEasing(aEffectTiming.mEasing, aDocument, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.mDuration = duration;
|
|
|
|
result.mDelay = TimeDuration::FromMilliseconds(aEffectTiming.mDelay);
|
|
|
|
result.mEndDelay = TimeDuration::FromMilliseconds(aEffectTiming.mEndDelay);
|
|
|
|
result.mIterations = aEffectTiming.mIterations;
|
|
|
|
result.mIterationStart = aEffectTiming.mIterationStart;
|
|
|
|
result.mDirection = aEffectTiming.mDirection;
|
|
|
|
result.mFill = aEffectTiming.mFill;
|
|
|
|
result.mFunction = easing;
|
|
|
|
|
|
|
|
result.Update();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
TimingParams TimingParams::MergeOptionalEffectTiming(
|
2018-05-07 06:37:11 +03:00
|
|
|
const TimingParams& aSource, const dom::OptionalEffectTiming& aEffectTiming,
|
2019-01-08 09:45:18 +03:00
|
|
|
dom::Document* aDocument, ErrorResult& aRv) {
|
2018-05-07 06:37:11 +03:00
|
|
|
MOZ_ASSERT(!aRv.Failed(), "Initially return value should be ok");
|
|
|
|
|
|
|
|
TimingParams result = aSource;
|
|
|
|
|
|
|
|
// Check for errors first
|
|
|
|
|
|
|
|
Maybe<StickyTimeDuration> duration;
|
|
|
|
if (aEffectTiming.mDuration.WasPassed()) {
|
|
|
|
duration =
|
|
|
|
TimingParams::ParseDuration(aEffectTiming.mDuration.Value(), aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEffectTiming.mIterationStart.WasPassed()) {
|
|
|
|
TimingParams::ValidateIterationStart(aEffectTiming.mIterationStart.Value(),
|
|
|
|
aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEffectTiming.mIterations.WasPassed()) {
|
|
|
|
TimingParams::ValidateIterations(aEffectTiming.mIterations.Value(), aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ComputedTimingFunction> easing;
|
|
|
|
if (aEffectTiming.mEasing.WasPassed()) {
|
|
|
|
easing = TimingParams::ParseEasing(aEffectTiming.mEasing.Value(), aDocument,
|
|
|
|
aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assign values
|
|
|
|
|
|
|
|
if (aEffectTiming.mDuration.WasPassed()) {
|
|
|
|
result.mDuration = duration;
|
|
|
|
}
|
|
|
|
if (aEffectTiming.mDelay.WasPassed()) {
|
|
|
|
result.mDelay =
|
|
|
|
TimeDuration::FromMilliseconds(aEffectTiming.mDelay.Value());
|
|
|
|
}
|
|
|
|
if (aEffectTiming.mEndDelay.WasPassed()) {
|
|
|
|
result.mEndDelay =
|
|
|
|
TimeDuration::FromMilliseconds(aEffectTiming.mEndDelay.Value());
|
|
|
|
}
|
|
|
|
if (aEffectTiming.mIterations.WasPassed()) {
|
|
|
|
result.mIterations = aEffectTiming.mIterations.Value();
|
|
|
|
}
|
|
|
|
if (aEffectTiming.mIterationStart.WasPassed()) {
|
|
|
|
result.mIterationStart = aEffectTiming.mIterationStart.Value();
|
|
|
|
}
|
|
|
|
if (aEffectTiming.mDirection.WasPassed()) {
|
|
|
|
result.mDirection = aEffectTiming.mDirection.Value();
|
|
|
|
}
|
|
|
|
if (aEffectTiming.mFill.WasPassed()) {
|
|
|
|
result.mFill = aEffectTiming.mFill.Value();
|
|
|
|
}
|
|
|
|
if (aEffectTiming.mEasing.WasPassed()) {
|
|
|
|
result.mFunction = easing;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Update();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
Maybe<ComputedTimingFunction> TimingParams::ParseEasing(
|
2019-01-08 09:45:18 +03:00
|
|
|
const nsAString& aEasing, dom::Document* aDocument, ErrorResult& aRv) {
|
2016-03-18 10:28:22 +03:00
|
|
|
MOZ_ASSERT(aDocument);
|
|
|
|
|
2018-03-25 20:42:10 +03:00
|
|
|
nsTimingFunction timingFunction;
|
|
|
|
RefPtr<URLExtraData> url = ServoCSSParser::GetURLExtraData(aDocument);
|
|
|
|
if (!ServoCSSParser::ParseEasing(aEasing, url, timingFunction)) {
|
|
|
|
aRv.ThrowTypeError<dom::MSG_INVALID_EASING_ERROR>(aEasing);
|
|
|
|
return Nothing();
|
2017-03-21 09:27:46 +03:00
|
|
|
}
|
|
|
|
|
2018-10-26 21:03:35 +03:00
|
|
|
if (timingFunction.IsLinear()) {
|
2018-03-25 20:42:10 +03:00
|
|
|
return Nothing();
|
|
|
|
}
|
2018-02-01 07:04:04 +03:00
|
|
|
|
2018-03-25 20:42:10 +03:00
|
|
|
return Some(ComputedTimingFunction(timingFunction));
|
2016-03-18 10:28:22 +03:00
|
|
|
}
|
|
|
|
|
2016-03-07 08:11:11 +03:00
|
|
|
bool TimingParams::operator==(const TimingParams& aOther) const {
|
2017-06-22 06:12:43 +03:00
|
|
|
// We don't compare mActiveDuration and mEndTime because they are calculated
|
|
|
|
// from other timing parameters.
|
2016-03-09 08:14:20 +03:00
|
|
|
return mDuration == aOther.mDuration && mDelay == aOther.mDelay &&
|
2016-03-07 08:11:11 +03:00
|
|
|
mEndDelay == aOther.mEndDelay && mIterations == aOther.mIterations &&
|
|
|
|
mIterationStart == aOther.mIterationStart &&
|
|
|
|
mDirection == aOther.mDirection && mFill == aOther.mFill &&
|
|
|
|
mFunction == aOther.mFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|