Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/animation/AnimationUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "AnimationUtils.h"
8
9
#include "nsDebug.h"
10
#include "nsAtom.h"
11
#include "nsIContent.h"
12
#include "nsIDocument.h"
13
#include "nsGlobalWindow.h"
14
#include "nsString.h"
15
#include "xpcpublic.h" // For xpc::NativeGlobal
16
#include "mozilla/EffectSet.h"
17
#include "mozilla/dom/KeyframeEffect.h"
18
#include "mozilla/Preferences.h"
19
20
namespace mozilla {
21
22
/* static */ void
23
AnimationUtils::LogAsyncAnimationFailure(nsCString& aMessage,
24
                                         const nsIContent* aContent)
25
0
{
26
0
  if (aContent) {
27
0
    aMessage.AppendLiteral(" [");
28
0
    aMessage.Append(nsAtomCString(aContent->NodeInfo()->NameAtom()));
29
0
30
0
    nsAtom* id = aContent->GetID();
31
0
    if (id) {
32
0
      aMessage.AppendLiteral(" with id '");
33
0
      aMessage.Append(nsAtomCString(aContent->GetID()));
34
0
      aMessage.Append('\'');
35
0
    }
36
0
    aMessage.Append(']');
37
0
  }
38
0
  aMessage.Append('\n');
39
0
  printf_stderr("%s", aMessage.get());
40
0
}
41
42
/* static */ nsIDocument*
43
AnimationUtils::GetCurrentRealmDocument(JSContext* aCx)
44
0
{
45
0
  nsGlobalWindowInner* win = xpc::CurrentWindowOrNull(aCx);
46
0
  if (!win) {
47
0
    return nullptr;
48
0
  }
49
0
  return win->GetDoc();
50
0
}
51
52
/* static */ nsIDocument*
53
AnimationUtils::GetDocumentFromGlobal(JSObject* aGlobalObject)
54
0
{
55
0
  nsGlobalWindowInner* win = xpc::WindowOrNull(aGlobalObject);
56
0
  if (!win) {
57
0
    return nullptr;
58
0
  }
59
0
  return win->GetDoc();
60
0
}
61
62
/* static */ bool
63
AnimationUtils::IsOffscreenThrottlingEnabled()
64
0
{
65
0
  static bool sOffscreenThrottlingEnabled;
66
0
  static bool sPrefCached = false;
67
0
68
0
  if (!sPrefCached) {
69
0
    sPrefCached = true;
70
0
    Preferences::AddBoolVarCache(&sOffscreenThrottlingEnabled,
71
0
                                 "dom.animations.offscreen-throttling");
72
0
  }
73
0
74
0
  return sOffscreenThrottlingEnabled;
75
0
}
76
77
/* static */ bool
78
AnimationUtils::EffectSetContainsAnimatedScale(EffectSet& aEffects,
79
                                               const nsIFrame* aFrame)
80
0
{
81
0
  for (const dom::KeyframeEffect* effect : aEffects) {
82
0
    if (effect->ContainsAnimatedScale(aFrame)) {
83
0
      return true;
84
0
    }
85
0
  }
86
0
87
0
  return false;
88
0
}
89
90
} // namespace mozilla