AnimationPerformanceWarning.cpp (2713B)
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 "AnimationPerformanceWarning.h" 8 9 #include "nsContentUtils.h" 10 11 namespace mozilla { 12 13 template <uint32_t N> 14 nsresult AnimationPerformanceWarning::ToLocalizedStringWithIntParams( 15 const char* aKey, nsAString& aLocalizedString) const { 16 AutoTArray<nsString, N> strings; 17 18 MOZ_DIAGNOSTIC_ASSERT(mParams->Length() == N); 19 for (size_t i = 0, n = mParams->Length(); i < n; i++) { 20 strings.AppendElement()->AppendInt((*mParams)[i]); 21 } 22 23 return nsContentUtils::FormatLocalizedString( 24 nsContentUtils::eLAYOUT_PROPERTIES, aKey, strings, aLocalizedString); 25 } 26 27 bool AnimationPerformanceWarning::ToLocalizedString( 28 nsAString& aLocalizedString) const { 29 const char* key = nullptr; 30 31 switch (mType) { 32 case Type::ContentTooLarge: 33 MOZ_ASSERT(mParams && mParams->Length() == 6, 34 "Parameter's length should be 6 for ContentTooLarge2"); 35 36 return NS_SUCCEEDED(ToLocalizedStringWithIntParams<6>( 37 "CompositorAnimationWarningContentTooLarge2", aLocalizedString)); 38 case Type::ContentTooLargeArea: 39 MOZ_ASSERT(mParams && mParams->Length() == 2, 40 "Parameter's length should be 2 for ContentTooLargeArea"); 41 42 return NS_SUCCEEDED(ToLocalizedStringWithIntParams<2>( 43 "CompositorAnimationWarningContentTooLargeArea", aLocalizedString)); 44 case Type::NonScalingStroke: 45 key = "CompositorAnimationWarningNonScalingStroke"; 46 break; 47 case Type::TransformSVG: 48 key = "CompositorAnimationWarningTransformSVG"; 49 break; 50 case Type::TransformFrameInactive: 51 key = "CompositorAnimationWarningTransformFrameInactive"; 52 break; 53 case Type::TransformIsBlockedByImportantRules: 54 key = "CompositorAnimationWarningTransformIsBlockedByImportantRules"; 55 break; 56 case Type::OpacityFrameInactive: 57 key = "CompositorAnimationWarningOpacityFrameInactive"; 58 break; 59 case Type::HasRenderingObserver: 60 key = "CompositorAnimationWarningHasRenderingObserver"; 61 break; 62 case Type::HasCurrentColor: 63 key = "CompositorAnimationWarningHasCurrentColor"; 64 break; 65 case Type::None: 66 MOZ_ASSERT_UNREACHABLE("Uninitialized type shouldn't be used"); 67 return false; 68 } 69 70 nsresult rv = nsContentUtils::GetLocalizedString( 71 nsContentUtils::eLAYOUT_PROPERTIES, key, aLocalizedString); 72 return NS_SUCCEEDED(rv); 73 } 74 75 } // namespace mozilla