From 9f39a5920ab4ae60ee0a6007d26ab2d5e366e8a2 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Fri, 29 Jul 2016 16:18:48 +0800 Subject: [PATCH] Bug 1290023 - Allow enum class values to be passed to other nsCSSProps methods and stored in nsCSSValue/StyleAnimationValue. r=xidorn MozReview-Commit-ID: 62usVamI3GA --- layout/style/StyleAnimationValue.cpp | 4 ++-- layout/style/StyleAnimationValue.h | 8 ++++++++ layout/style/nsCSSProps.h | 20 +++++++++++++++++++- layout/style/nsCSSValue.h | 11 +++++++++++ layout/style/nsComputedDOMStyle.cpp | 4 ++-- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/layout/style/StyleAnimationValue.cpp b/layout/style/StyleAnimationValue.cpp index 65aa0eded1bab..5a3d42094a89f 100644 --- a/layout/style/StyleAnimationValue.cpp +++ b/layout/style/StyleAnimationValue.cpp @@ -3575,7 +3575,7 @@ StyleClipBasicShapeToCSSArray(const nsStyleClipPath& aClipPath, MOZ_ASSERT_UNREACHABLE("Unknown shape type"); return false; } - aResult->Item(1).SetIntValue(uint8_t(aClipPath.GetSizingBox()), + aResult->Item(1).SetIntValue(aClipPath.GetSizingBox(), eCSSUnit_Enumerated); return true; } @@ -3966,7 +3966,7 @@ StyleAnimationValue::ExtractComputedValue(nsCSSProperty aProperty, result->SetURLValue(url); aComputedValue.SetAndAdoptCSSValueValue(result.release(), eUnit_URL); } else if (type == StyleClipPathType::Box) { - aComputedValue.SetIntValue(uint8_t(clipPath.GetSizingBox()), + aComputedValue.SetIntValue(clipPath.GetSizingBox(), eUnit_Enumerated); } else if (type == StyleClipPathType::Shape) { RefPtr result = nsCSSValue::Array::Create(2); diff --git a/layout/style/StyleAnimationValue.h b/layout/style/StyleAnimationValue.h index 7e26a395b70b3..14509db454b4f 100644 --- a/layout/style/StyleAnimationValue.h +++ b/layout/style/StyleAnimationValue.h @@ -430,6 +430,14 @@ class StyleAnimationValue { void SetAutoValue(); void SetNoneValue(); void SetIntValue(int32_t aInt, Unit aUnit); + template::value>::type> + void SetIntValue(T aInt, Unit aUnit) + { + static_assert(mozilla::IsEnumFittingWithin::value, + "aValue must be an enum that fits within mValue.mInt"); + SetIntValue(static_cast(aInt), aUnit); + } void SetCoordValue(nscoord aCoord); void SetPercentValue(float aPercent); void SetFloatValue(float aFloat); diff --git a/layout/style/nsCSSProps.h b/layout/style/nsCSSProps.h index 8094843ca9557..06e3b68b44525 100644 --- a/layout/style/nsCSSProps.h +++ b/layout/style/nsCSSProps.h @@ -449,11 +449,29 @@ class nsCSSProps { int32_t& aValue); // Return the first keyword in |aTable| that has the corresponding value |aValue|. // Return |eCSSKeyword_UNKNOWN| if not found. - static nsCSSKeyword ValueToKeywordEnum(int32_t aValue, + static nsCSSKeyword ValueToKeywordEnum(int32_t aValue, const KTableEntry aTable[]); + template::value>::type> + static nsCSSKeyword ValueToKeywordEnum(T aValue, + const KTableEntry aTable[]) + { + static_assert(mozilla::IsEnumFittingWithin::value, + "aValue must be an enum that fits within KTableEntry::mValue"); + return ValueToKeywordEnum(static_cast(aValue), aTable); + } // Ditto but as a string, return "" when not found. static const nsAFlatCString& ValueToKeyword(int32_t aValue, const KTableEntry aTable[]); + template::value>::type> + static const nsAFlatCString& ValueToKeyword(T aValue, + const KTableEntry aTable[]) + { + static_assert(mozilla::IsEnumFittingWithin::value, + "aValue must be an enum that fits within KTableEntry::mValue"); + return ValueToKeyword(static_cast(aValue), aTable); + } static const nsStyleStructID kSIDTable[eCSSProperty_COUNT_no_shorthands]; static const KTableEntry* const kKeywordTableTable[eCSSProperty_COUNT_no_shorthands]; diff --git a/layout/style/nsCSSValue.h b/layout/style/nsCSSValue.h index 383582331855d..b2c1678f533b8 100644 --- a/layout/style/nsCSSValue.h +++ b/layout/style/nsCSSValue.h @@ -8,6 +8,8 @@ #ifndef nsCSSValue_h___ #define nsCSSValue_h___ +#include + #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" #include "mozilla/SheetType.h" @@ -18,6 +20,7 @@ #include "nsCOMPtr.h" #include "nsCSSKeywords.h" #include "nsCSSProperty.h" +#include "nsCSSProps.h" #include "nsColor.h" #include "nsCoord.h" #include "nsProxyRelease.h" @@ -725,6 +728,14 @@ class nsCSSValue { public: void SetIntValue(int32_t aValue, nsCSSUnit aUnit); + template::value>::type> + void SetIntValue(T aValue, nsCSSUnit aUnit) + { + static_assert(mozilla::IsEnumFittingWithin::value, + "aValue must be an enum that fits within mValue.mInt"); + SetIntValue(static_cast(aValue), aUnit); + } void SetPercentValue(float aValue); void SetFloatValue(float aValue, nsCSSUnit aUnit); void SetStringValue(const nsString& aValue, nsCSSUnit aUnit); diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 0cc01d76025e3..e7d2e195a3c8b 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -4175,7 +4175,7 @@ nsComputedDOMStyle::DoGetBoxSizing() { RefPtr val = new nsROCSSPrimitiveValue; val->SetIdent( - nsCSSProps::ValueToKeywordEnum(uint8_t(StylePosition()->mBoxSizing), + nsCSSProps::ValueToKeywordEnum(StylePosition()->mBoxSizing, nsCSSProps::kBoxSizingKTable)); return val.forget(); } @@ -6010,7 +6010,7 @@ nsComputedDOMStyle::CreatePrimitiveValueForClipPath( nsAutoString boxString; AppendASCIItoUTF16( - nsCSSProps::ValueToKeyword(uint8_t(aSizingBox), + nsCSSProps::ValueToKeyword(aSizingBox, nsCSSProps::kClipShapeSizingKTable), boxString); RefPtr val = new nsROCSSPrimitiveValue;