Skip to content

Commit

Permalink
Bug 1290023 - Allow enum class values to be passed to other nsCSSProp…
Browse files Browse the repository at this point in the history
…s methods and stored in nsCSSValue/StyleAnimationValue. r=xidorn

MozReview-Commit-ID: 62usVamI3GA
  • Loading branch information
heycam committed Jul 29, 2016
1 parent 77dc3c4 commit 9f39a59
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions layout/style/StyleAnimationValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions layout/style/StyleAnimationValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ class StyleAnimationValue {
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);
Expand Down
20 changes: 19 additions & 1 deletion layout/style/nsCSSProps.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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];
Expand Down
11 changes: 11 additions & 0 deletions layout/style/nsCSSValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -725,6 +728,14 @@ class nsCSSValue {

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);
Expand Down
4 changes: 2 additions & 2 deletions layout/style/nsComputedDOMStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9f39a59

Please sign in to comment.