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 #ifndef mozilla_dom_AnimationPerformanceWarning_h
8 #define mozilla_dom_AnimationPerformanceWarning_h
9 
10 #include <initializer_list>
11 
12 #include "mozilla/Maybe.h"
13 #include "nsStringFwd.h"
14 #include "nsTArray.h"
15 
16 namespace mozilla {
17 
18 // Represents the reason why we can't run the CSS property on the compositor.
19 struct AnimationPerformanceWarning {
20   enum class Type : uint8_t {
21     None,
22     ContentTooLarge,
23     ContentTooLargeArea,
24     TransformBackfaceVisibilityHidden,
25     TransformSVG,
26     TransformWithGeometricProperties,
27     TransformWithSyncGeometricAnimations,
28     TransformFrameInactive,
29     TransformIsBlockedByImportantRules,
30     OpacityFrameInactive,
31     HasRenderingObserver,
32     HasCurrentColor,
33   };
34 
AnimationPerformanceWarningAnimationPerformanceWarning35   explicit AnimationPerformanceWarning(Type aType) : mType(aType) {
36     MOZ_ASSERT(mType != Type::None);
37   }
38 
AnimationPerformanceWarningAnimationPerformanceWarning39   AnimationPerformanceWarning(Type aType,
40                               std::initializer_list<int32_t> aParams)
41       : mType(aType) {
42     MOZ_ASSERT(mType != Type::None);
43     // FIXME:  Once std::initializer_list::size() become a constexpr function,
44     // we should use static_assert here.
45     MOZ_ASSERT(aParams.size() <= kMaxParamsForLocalization,
46                "The length of parameters should be less than "
47                "kMaxParamsForLocalization");
48     mParams.emplace(aParams);
49   }
50 
51   // Maximum number of parameters passed to
52   // nsContentUtils::FormatLocalizedString to localize warning messages.
53   //
54   // NOTE: This constexpr can't be forward declared, so if you want to use
55   // this variable, please include this header file directly.
56   // This value is the same as the limit of nsStringBundle::FormatString.
57   // See the implementation of nsStringBundle::FormatString.
58   static constexpr uint8_t kMaxParamsForLocalization = 10;
59 
60   // Indicates why this property could not be animated on the compositor.
61   Type mType;
62 
63   // Optional parameters that may be used for localization.
64   Maybe<CopyableTArray<int32_t>> mParams;
65 
66   bool ToLocalizedString(nsAString& aLocalizedString) const;
67   template <uint32_t N>
68   nsresult ToLocalizedStringWithIntParams(const char* aKey,
69                                           nsAString& aLocalizedString) const;
70 
71   bool operator==(const AnimationPerformanceWarning& aOther) const {
72     return mType == aOther.mType && mParams == aOther.mParams;
73   }
74   bool operator!=(const AnimationPerformanceWarning& aOther) const {
75     return !(*this == aOther);
76   }
77 };
78 
79 }  // namespace mozilla
80 
81 #endif  // mozilla_dom_AnimationPerformanceWarning_h
82