Bug 1290023 - Allow enum class values to be passed to other nsCSSProps methods and stored in nsCSSValue/StyleAnimationValue. r?xidorn
MozReview-Commit-ID: 62usVamI3GA
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -3568,17 +3568,17 @@ StyleClipBasicShapeToCSSArray(const nsSt
functionArray->Item(functionArray->Count() - 1).
SetArrayValue(radiusArray, eCSSUnit_Array);
break;
}
default:
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;
}
bool
StyleAnimationValue::ExtractComputedValue(nsCSSProperty aProperty,
nsStyleContext* aStyleContext,
StyleAnimationValue& aComputedValue)
@@ -3959,17 +3959,17 @@ StyleAnimationValue::ExtractComputedValu
new mozilla::css::URLValue(clipPath.GetURL(),
uriAsStringBuffer,
doc->GetDocumentURI(),
doc->NodePrincipal());
auto result = MakeUnique<nsCSSValue>();
result->SetURLValue(url);
aComputedValue.SetAndAdoptCSSValueValue(result.release(), eUnit_URL);
} else if (type == NS_STYLE_CLIP_PATH_BOX) {
- aComputedValue.SetIntValue(uint8_t(clipPath.GetSizingBox()),
+ aComputedValue.SetIntValue(clipPath.GetSizingBox(),
eUnit_Enumerated);
} else if (type == NS_STYLE_CLIP_PATH_SHAPE) {
RefPtr<nsCSSValue::Array> result = nsCSSValue::Array::Create(2);
if (!StyleClipBasicShapeToCSSArray(clipPath, result)) {
return false;
}
aComputedValue.SetCSSValueArrayValue(result, eUnit_Shape);
--- a/layout/style/StyleAnimationValue.h
+++ b/layout/style/StyleAnimationValue.h
@@ -425,16 +425,24 @@ public:
StyleAnimationValue(nscolor aColor, ColorConstructorType);
~StyleAnimationValue() { FreeValue(); }
void SetNormalValue();
void SetAutoValue();
void SetNoneValue();
void SetIntValue(int32_t aInt, Unit aUnit);
+ template<typename T,
+ typename = typename std::enable_if<std::is_enum<T>::value>::type>
+ void SetIntValue(T aInt, Unit aUnit)
+ {
+ static_assert(mozilla::IsEnumFittingWithin<T, int32_t>::value,
+ "aValue must be an enum that fits within mValue.mInt");
+ SetIntValue(static_cast<int32_t>(aInt), aUnit);
+ }
void SetCoordValue(nscoord aCoord);
void SetPercentValue(float aPercent);
void SetFloatValue(float aFloat);
void SetColorValue(nscolor aColor);
void SetCurrentColorValue();
void SetUnparsedStringValue(const nsString& aString);
void SetCSSValueArrayValue(nsCSSValue::Array* aValue, Unit aUnit);
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -444,21 +444,39 @@ public:
const KTableEntry aTable[]);
// Find |aKeyword| in |aTable|, if found set |aValue| to its corresponding value.
// If not found, return false and do not set |aValue|.
static bool FindKeyword(nsCSSKeyword aKeyword, const KTableEntry aTable[],
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<typename T,
+ typename = typename std::enable_if<std::is_enum<T>::value>::type>
+ static nsCSSKeyword ValueToKeywordEnum(T aValue,
+ const KTableEntry aTable[])
+ {
+ static_assert(mozilla::IsEnumFittingWithin<T, int16_t>::value,
+ "aValue must be an enum that fits within KTableEntry::mValue");
+ return ValueToKeywordEnum(static_cast<int16_t>(aValue), aTable);
+ }
// Ditto but as a string, return "" when not found.
static const nsAFlatCString& ValueToKeyword(int32_t aValue,
const KTableEntry aTable[]);
+ template<typename T,
+ typename = typename std::enable_if<std::is_enum<T>::value>::type>
+ static const nsAFlatCString& ValueToKeyword(T aValue,
+ const KTableEntry aTable[])
+ {
+ static_assert(mozilla::IsEnumFittingWithin<T, int16_t>::value,
+ "aValue must be an enum that fits within KTableEntry::mValue");
+ return ValueToKeyword(static_cast<int16_t>(aValue), aTable);
+ }
static const nsStyleStructID kSIDTable[eCSSProperty_COUNT_no_shorthands];
static const KTableEntry* const kKeywordTableTable[eCSSProperty_COUNT_no_shorthands];
static const nsStyleAnimType kAnimTypeTable[eCSSProperty_COUNT_no_shorthands];
static const ptrdiff_t
kStyleStructOffsetTable[eCSSProperty_COUNT_no_shorthands];
private:
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -3,26 +3,29 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* representation of simple property values within CSS declarations */
#ifndef nsCSSValue_h___
#define nsCSSValue_h___
+#include <type_traits>
+
#include "mozilla/Attributes.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/SheetType.h"
#include "mozilla/UniquePtr.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
#include "nsCOMPtr.h"
#include "nsCSSKeywords.h"
#include "nsCSSProperty.h"
+#include "nsCSSProps.h"
#include "nsColor.h"
#include "nsCoord.h"
#include "nsProxyRelease.h"
#include "nsRefPtrHashtable.h"
#include "nsString.h"
#include "nsStringBuffer.h"
#include "nsTArray.h"
#include "nsStyleConsts.h"
@@ -718,16 +721,24 @@ public:
if (mUnit != eCSSUnit_Null)
DoReset();
}
private:
void DoReset();
public:
void SetIntValue(int32_t aValue, nsCSSUnit aUnit);
+ template<typename T,
+ typename = typename std::enable_if<std::is_enum<T>::value>::type>
+ void SetIntValue(T aValue, nsCSSUnit aUnit)
+ {
+ static_assert(mozilla::IsEnumFittingWithin<T, int32_t>::value,
+ "aValue must be an enum that fits within mValue.mInt");
+ SetIntValue(static_cast<int32_t>(aValue), aUnit);
+ }
void SetPercentValue(float aValue);
void SetFloatValue(float aValue, nsCSSUnit aUnit);
void SetStringValue(const nsString& aValue, nsCSSUnit aUnit);
void SetColorValue(nscolor aValue);
void SetIntegerColorValue(nscolor aValue, nsCSSUnit aUnit);
void SetFloatColorValue(float aComponent1,
float aComponent2,
float aComponent3,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -4150,17 +4150,17 @@ nsComputedDOMStyle::DoGetBoxPack()
return val.forget();
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBoxSizing()
{
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
val->SetIdent(
- nsCSSProps::ValueToKeywordEnum(uint8_t(StylePosition()->mBoxSizing),
+ nsCSSProps::ValueToKeywordEnum(StylePosition()->mBoxSizing,
nsCSSProps::kBoxSizingKTable));
return val.forget();
}
/* Border image properties */
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBorderImageSource()
@@ -5985,17 +5985,17 @@ nsComputedDOMStyle::CreatePrimitiveValue
}
if (aSizingBox == StyleClipShapeSizing::NoBox) {
return valueList.forget();
}
nsAutoString boxString;
AppendASCIItoUTF16(
- nsCSSProps::ValueToKeyword(uint8_t(aSizingBox),
+ nsCSSProps::ValueToKeyword(aSizingBox,
nsCSSProps::kClipShapeSizingKTable),
boxString);
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
val->SetString(boxString);
valueList->AppendCSSValue(val.forget());
return valueList.forget();
}