tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AnimationPerformanceWarning.h (2738B)


      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    NonScalingStroke,
     25    TransformSVG,
     26    TransformFrameInactive,
     27    TransformIsBlockedByImportantRules,
     28    OpacityFrameInactive,
     29    HasRenderingObserver,
     30    HasCurrentColor,
     31  };
     32 
     33  explicit AnimationPerformanceWarning(Type aType) : mType(aType) {
     34    MOZ_ASSERT(mType != Type::None);
     35  }
     36 
     37  AnimationPerformanceWarning(Type aType,
     38                              std::initializer_list<int32_t> aParams)
     39      : mType(aType) {
     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);
     47  }
     48 
     49  // Maximum number of parameters passed to
     50  // nsContentUtils::FormatLocalizedString to localize warning messages.
     51  //
     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;
     57 
     58  // Indicates why this property could not be animated on the compositor.
     59  Type mType;
     60 
     61  // Optional parameters that may be used for localization.
     62  Maybe<CopyableTArray<int32_t>> mParams;
     63 
     64  bool ToLocalizedString(nsAString& aLocalizedString) const;
     65  template <uint32_t N>
     66  nsresult ToLocalizedStringWithIntParams(const char* aKey,
     67                                          nsAString& aLocalizedString) const;
     68 
     69  bool operator==(const AnimationPerformanceWarning& aOther) const {
     70    return mType == aOther.mType && mParams == aOther.mParams;
     71  }
     72  bool operator!=(const AnimationPerformanceWarning& aOther) const {
     73    return !(*this == aOther);
     74  }
     75 };
     76 
     77 }  // namespace mozilla
     78 
     79 #endif  // mozilla_dom_AnimationPerformanceWarning_h