Bug 1290023 - Allow enum class values to be passed to other nsCSSProps methods and stored in nsCSSValue/StyleAnimationValue. r=xidorn

MozReview-Commit-ID: 62usVamI3GA
This commit is contained in:
Cameron McCormack 2016-07-29 16:18:48 +08:00
Родитель 77dc3c4848
Коммит 9f39a5920a
5 изменённых файлов: 42 добавлений и 5 удалений

Просмотреть файл

@ -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<nsCSSValue::Array> result = nsCSSValue::Array::Create(2);

Просмотреть файл

@ -430,6 +430,14 @@ public:
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);

Просмотреть файл

@ -449,11 +449,29 @@ public:
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];

Просмотреть файл

@ -8,6 +8,8 @@
#ifndef nsCSSValue_h___
#define nsCSSValue_h___
#include <type_traits>
#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 @@ private:
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);

Просмотреть файл

@ -4175,7 +4175,7 @@ nsComputedDOMStyle::DoGetBoxSizing()
{
RefPtr<nsROCSSPrimitiveValue> 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<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;