2015-05-03 22:32:37 +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: */
|
2014-08-30 10:11:57 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2014-09-25 18:11:43 +04:00
|
|
|
#ifndef mozilla_dom_AnimationUtils_h
|
|
|
|
#define mozilla_dom_AnimationUtils_h
|
|
|
|
|
2014-08-30 10:11:57 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2016-12-07 12:47:23 +03:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-08-30 10:11:57 +04:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2017-08-17 17:37:29 +03:00
|
|
|
#include "nsRFPService.h"
|
2015-12-04 02:32:53 +03:00
|
|
|
#include "nsStringFwd.h"
|
|
|
|
|
|
|
|
class nsIContent;
|
2017-02-09 05:28:47 +03:00
|
|
|
class nsIFrame;
|
2016-03-11 11:20:17 +03:00
|
|
|
struct JSContext;
|
2014-08-30 10:11:57 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2019-03-29 18:11:04 +03:00
|
|
|
enum class PseudoStyleType : uint8_t;
|
2016-01-27 04:08:00 +03:00
|
|
|
class ComputedTimingFunction;
|
2017-02-09 05:28:47 +03:00
|
|
|
class EffectSet;
|
2016-01-27 04:08:00 +03:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
namespace dom {
|
|
|
|
class Document;
|
|
|
|
}
|
|
|
|
|
2014-08-30 10:11:57 +04:00
|
|
|
class AnimationUtils {
|
|
|
|
public:
|
2019-01-02 16:05:23 +03:00
|
|
|
typedef dom::Document Document;
|
|
|
|
|
2015-12-04 02:32:53 +03:00
|
|
|
static dom::Nullable<double> TimeDurationToDouble(
|
2016-03-11 11:15:23 +03:00
|
|
|
const dom::Nullable<TimeDuration>& aTime) {
|
2015-12-04 02:32:53 +03:00
|
|
|
dom::Nullable<double> result;
|
2014-08-30 10:11:57 +04:00
|
|
|
|
|
|
|
if (!aTime.IsNull()) {
|
2018-03-06 00:58:46 +03:00
|
|
|
// 0 is an inappropriate mixin for this this area; however CSS Animations
|
|
|
|
// needs to have it's Time Reduction Logic refactored, so it's currently
|
|
|
|
// only clamping for RFP mode. RFP mode gives a much lower time precision,
|
|
|
|
// so we accept the security leak here for now
|
|
|
|
result.SetValue(nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
aTime.Value().ToMilliseconds(), 0, TimerPrecisionType::RFPOnly));
|
2014-08-30 10:11:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2015-02-09 13:25:51 +03:00
|
|
|
|
2015-12-04 02:32:53 +03:00
|
|
|
static dom::Nullable<TimeDuration> DoubleToTimeDuration(
|
2016-03-11 11:15:23 +03:00
|
|
|
const dom::Nullable<double>& aTime) {
|
2015-12-04 02:32:53 +03:00
|
|
|
dom::Nullable<TimeDuration> result;
|
2015-02-09 13:25:51 +03:00
|
|
|
|
|
|
|
if (!aTime.IsNull()) {
|
|
|
|
result.SetValue(TimeDuration::FromMilliseconds(aTime.Value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2015-12-04 02:32:53 +03:00
|
|
|
|
|
|
|
static void LogAsyncAnimationFailure(nsCString& aMessage,
|
|
|
|
const nsIContent* aContent = nullptr);
|
2016-01-27 04:08:00 +03:00
|
|
|
|
2016-03-11 11:20:17 +03:00
|
|
|
/**
|
|
|
|
* Get the document from the JS context to use when parsing CSS properties.
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static Document* GetCurrentRealmDocument(JSContext* aCx);
|
2016-05-24 06:57:43 +03:00
|
|
|
|
Bug 1414674 - Do not enter the compartment of the target window when calling KeyframeEffect and KeyframeEffectReadOnly constructor via Xray. r=bz,birtles
KeyframeEffect and KeyframeEffectReadOnly constructors can run in the caller
compartment, which is okay because the current compartment is used in the
following places and all of them are safe:
1. GlobalObject::CallerType(), that is ultimately passed to
nsDocument::IsWebAnimationsEnabled in KeyframeEffectParamsFromUnion,
to decide whether to copy mIterationComposite/mComposite to
KeyframeEffectParams.
GlobalObject::CallerType() can now be different than the target window's one,
if the caller has the system principal and the target is web content, and
in that case nsDocument::IsWebAnimationsEnabled there always returns true
while Web Animations can be disabled on web content.
honoring the mIterationComposite/mComposite properties is OK, since it just
changes the animation behavior, and this is disabled by default until
remaining spec issues are resolved.
2. GlobalObject::Context(), that is ultimately passed to
KeyframeUtils::GetKeyframesFromObject and used while extracting information
from passed-in keyframe object, with iterable/iterator protocols.
Performing that operation in the caller side is okay, since the same thing
can be done on caller, and the operation doesn't perform any GCThing
allocation on the target window global.
2018-02-17 11:21:13 +03:00
|
|
|
/**
|
|
|
|
* Get the document from the global object, or nullptr if the document has
|
|
|
|
* no window, to use when constructing DOM object without entering the
|
|
|
|
* target window's compartment (see KeyframeEffect constructor).
|
|
|
|
*/
|
2019-01-02 16:05:23 +03:00
|
|
|
static Document* GetDocumentFromGlobal(JSObject* aGlobalObject);
|
Bug 1414674 - Do not enter the compartment of the target window when calling KeyframeEffect and KeyframeEffectReadOnly constructor via Xray. r=bz,birtles
KeyframeEffect and KeyframeEffectReadOnly constructors can run in the caller
compartment, which is okay because the current compartment is used in the
following places and all of them are safe:
1. GlobalObject::CallerType(), that is ultimately passed to
nsDocument::IsWebAnimationsEnabled in KeyframeEffectParamsFromUnion,
to decide whether to copy mIterationComposite/mComposite to
KeyframeEffectParams.
GlobalObject::CallerType() can now be different than the target window's one,
if the caller has the system principal and the target is web content, and
in that case nsDocument::IsWebAnimationsEnabled there always returns true
while Web Animations can be disabled on web content.
honoring the mIterationComposite/mComposite properties is OK, since it just
changes the animation behavior, and this is disabled by default until
remaining spec issues are resolved.
2. GlobalObject::Context(), that is ultimately passed to
KeyframeUtils::GetKeyframesFromObject and used while extracting information
from passed-in keyframe object, with iterable/iterator protocols.
Performing that operation in the caller side is okay, since the same thing
can be done on caller, and the operation doesn't perform any GCThing
allocation on the target window global.
2018-02-17 11:21:13 +03:00
|
|
|
|
2016-05-24 06:57:43 +03:00
|
|
|
/**
|
|
|
|
* Checks if offscreen animation throttling is enabled.
|
|
|
|
*/
|
|
|
|
static bool IsOffscreenThrottlingEnabled();
|
2016-08-10 12:58:49 +03:00
|
|
|
|
2017-02-09 05:28:47 +03:00
|
|
|
/**
|
2019-03-18 07:12:10 +03:00
|
|
|
* Returns true if the given frame has an animated scale.
|
2017-02-09 05:28:47 +03:00
|
|
|
*/
|
2019-03-18 07:12:10 +03:00
|
|
|
static bool FrameHasAnimatedScale(const nsIFrame* aFrame);
|
2019-03-18 07:09:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given (pseudo-)element has any transitions that are
|
|
|
|
* current (playing or waiting to play) or in effect (e.g. filling forwards).
|
|
|
|
*/
|
|
|
|
static bool HasCurrentTransitions(const dom::Element* aElement,
|
|
|
|
PseudoStyleType aPseudoType);
|
2014-08-30 10:11:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2014-09-25 18:11:43 +04:00
|
|
|
|
|
|
|
#endif
|