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/. */
7 #ifndef mozilla_dom_AnimationPerformanceWarning_h
8 #define mozilla_dom_AnimationPerformanceWarning_h
10 #include <initializer_list>
12 #include "mozilla/Maybe.h"
13 #include "nsStringFwd.h"
18 // Represents the reason why we can't run the CSS property on the compositor.
19 struct AnimationPerformanceWarning
{
20 enum class Type
: uint8_t {
24 TransformBackfaceVisibilityHidden
,
26 TransformWithGeometricProperties
,
27 TransformWithSyncGeometricAnimations
,
28 TransformFrameInactive
,
29 TransformIsBlockedByImportantRules
,
35 explicit AnimationPerformanceWarning(Type aType
) : mType(aType
) {
36 MOZ_ASSERT(mType
!= Type::None
);
39 AnimationPerformanceWarning(Type aType
,
40 std::initializer_list
<int32_t> aParams
)
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
);
51 // Maximum number of parameters passed to
52 // nsContentUtils::FormatLocalizedString to localize warning messages.
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;
60 // Indicates why this property could not be animated on the compositor.
63 // Optional parameters that may be used for localization.
64 Maybe
<CopyableTArray
<int32_t>> mParams
;
66 bool ToLocalizedString(nsAString
& aLocalizedString
) const;
68 nsresult
ToLocalizedStringWithIntParams(const char* aKey
,
69 nsAString
& aLocalizedString
) const;
71 bool operator==(const AnimationPerformanceWarning
& aOther
) const {
72 return mType
== aOther
.mType
&& mParams
== aOther
.mParams
;
74 bool operator!=(const AnimationPerformanceWarning
& aOther
) const {
75 return !(*this == aOther
);
79 } // namespace mozilla
81 #endif // mozilla_dom_AnimationPerformanceWarning_h