2015-12-03 23:32:53 +00: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 "AnimationUtils.h"
|
|
|
|
|
|
|
|
#include "nsDebug.h"
|
2017-10-02 22:05:19 +00:00
|
|
|
#include "nsAtom.h"
|
2015-12-03 23:32:53 +00:00
|
|
|
#include "nsIContent.h"
|
2016-03-11 08:20:17 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
2015-12-03 23:32:53 +00:00
|
|
|
#include "nsString.h"
|
2016-03-11 08:21:03 +00:00
|
|
|
#include "xpcpublic.h" // For xpc::NativeGlobal
|
2017-02-09 02:28:47 +00:00
|
|
|
#include "mozilla/EffectSet.h"
|
|
|
|
#include "mozilla/dom/KeyframeEffectReadOnly.h"
|
2016-05-24 03:57:43 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2015-12-03 23:32:53 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
AnimationUtils::LogAsyncAnimationFailure(nsCString& aMessage,
|
|
|
|
const nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent) {
|
|
|
|
aMessage.AppendLiteral(" [");
|
|
|
|
aMessage.Append(nsAtomCString(aContent->NodeInfo()->NameAtom()));
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* id = aContent->GetID();
|
2015-12-03 23:32:53 +00:00
|
|
|
if (id) {
|
|
|
|
aMessage.AppendLiteral(" with id '");
|
|
|
|
aMessage.Append(nsAtomCString(aContent->GetID()));
|
|
|
|
aMessage.Append('\'');
|
|
|
|
}
|
|
|
|
aMessage.Append(']');
|
|
|
|
}
|
|
|
|
aMessage.Append('\n');
|
|
|
|
printf_stderr("%s", aMessage.get());
|
|
|
|
}
|
|
|
|
|
2016-03-11 08:20:17 +00:00
|
|
|
/* static */ nsIDocument*
|
|
|
|
AnimationUtils::GetCurrentRealmDocument(JSContext* aCx)
|
|
|
|
{
|
|
|
|
nsGlobalWindow* win = xpc::CurrentWindowOrNull(aCx);
|
|
|
|
if (!win) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return win->GetDoc();
|
|
|
|
}
|
|
|
|
|
2016-05-24 03:57:43 +00:00
|
|
|
/* static */ bool
|
|
|
|
AnimationUtils::IsOffscreenThrottlingEnabled()
|
|
|
|
{
|
|
|
|
static bool sOffscreenThrottlingEnabled;
|
|
|
|
static bool sPrefCached = false;
|
|
|
|
|
|
|
|
if (!sPrefCached) {
|
|
|
|
sPrefCached = true;
|
|
|
|
Preferences::AddBoolVarCache(&sOffscreenThrottlingEnabled,
|
|
|
|
"dom.animations.offscreen-throttling");
|
|
|
|
}
|
|
|
|
|
|
|
|
return sOffscreenThrottlingEnabled;
|
|
|
|
}
|
|
|
|
|
2016-08-10 09:58:49 +00:00
|
|
|
/* static */ bool
|
2016-12-03 23:07:40 +00:00
|
|
|
AnimationUtils::IsCoreAPIEnabled()
|
2016-08-10 09:58:49 +00:00
|
|
|
{
|
|
|
|
static bool sCoreAPIEnabled;
|
|
|
|
static bool sPrefCached = false;
|
|
|
|
|
|
|
|
if (!sPrefCached) {
|
|
|
|
sPrefCached = true;
|
|
|
|
Preferences::AddBoolVarCache(&sCoreAPIEnabled,
|
|
|
|
"dom.animations-api.core.enabled");
|
|
|
|
}
|
|
|
|
|
2016-12-03 23:07:40 +00:00
|
|
|
return sCoreAPIEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
2016-12-07 09:47:23 +00:00
|
|
|
AnimationUtils::IsCoreAPIEnabledForCaller(dom::CallerType aCallerType)
|
2016-12-03 23:07:40 +00:00
|
|
|
{
|
2016-12-07 09:47:23 +00:00
|
|
|
return IsCoreAPIEnabled() || aCallerType == dom::CallerType::System;
|
2016-08-10 09:58:49 +00:00
|
|
|
}
|
|
|
|
|
2017-02-09 02:28:47 +00:00
|
|
|
/* static */ bool
|
|
|
|
AnimationUtils::EffectSetContainsAnimatedScale(EffectSet& aEffects,
|
|
|
|
const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
for (const dom::KeyframeEffectReadOnly* effect : aEffects) {
|
|
|
|
if (effect->ContainsAnimatedScale(aFrame)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-03 23:32:53 +00:00
|
|
|
} // namespace mozilla
|