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 {
26 TransformFrameInactive
,
27 TransformIsBlockedByImportantRules
,
33 explicit AnimationPerformanceWarning(Type aType
) : mType(aType
) {
34 MOZ_ASSERT(mType
!= Type::None
);
37 AnimationPerformanceWarning(Type aType
,
38 std::initializer_list
<int32_t> aParams
)
40 MOZ_ASSERT(mType
!= Type::None
);
41 // FIXME: Once std::initializer_list::size() become a constexpr function,
42 // we should use static_assert here.
43 MOZ_ASSERT(aParams
.size() <= kMaxParamsForLocalization
,
44 "The length of parameters should be less than "
45 "kMaxParamsForLocalization");
46 mParams
.emplace(aParams
);
49 // Maximum number of parameters passed to
50 // nsContentUtils::FormatLocalizedString to localize warning messages.
52 // NOTE: This constexpr can't be forward declared, so if you want to use
53 // this variable, please include this header file directly.
54 // This value is the same as the limit of nsStringBundle::FormatString.
55 // See the implementation of nsStringBundle::FormatString.
56 static constexpr uint8_t kMaxParamsForLocalization
= 10;
58 // Indicates why this property could not be animated on the compositor.
61 // Optional parameters that may be used for localization.
62 Maybe
<CopyableTArray
<int32_t>> mParams
;
64 bool ToLocalizedString(nsAString
& aLocalizedString
) const;
66 nsresult
ToLocalizedStringWithIntParams(const char* aKey
,
67 nsAString
& aLocalizedString
) const;
69 bool operator==(const AnimationPerformanceWarning
& aOther
) const {
70 return mType
== aOther
.mType
&& mParams
== aOther
.mParams
;
72 bool operator!=(const AnimationPerformanceWarning
& aOther
) const {
73 return !(*this == aOther
);
77 } // namespace mozilla
79 #endif // mozilla_dom_AnimationPerformanceWarning_h