Bug 1288383 - Replace NS_STYLE_CLIP_PATH_* with an enum class; r=heycam
MozReview-Commit-ID: H6nwOybonF3
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -3944,42 +3944,42 @@ StyleAnimationValue::ExtractComputedValu
break;
}
#endif
case eCSSProperty_clip_path: {
const nsStyleSVGReset* svgReset =
static_cast<const nsStyleSVGReset*>(styleStruct);
const nsStyleClipPath& clipPath = svgReset->mClipPath;
- const int32_t type = clipPath.GetType();
-
- if (type == NS_STYLE_CLIP_PATH_URL) {
+ const StyleClipPathType type = clipPath.GetType();
+
+ if (type == StyleClipPathType::URL) {
nsIDocument* doc = aStyleContext->PresContext()->Document();
RefPtr<nsStringBuffer> uriAsStringBuffer =
GetURIAsUtf16StringBuffer(clipPath.GetURL());
RefPtr<mozilla::css::URLValue> url =
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) {
+ } else if (type == StyleClipPathType::Box) {
aComputedValue.SetIntValue(uint8_t(clipPath.GetSizingBox()),
eUnit_Enumerated);
- } else if (type == NS_STYLE_CLIP_PATH_SHAPE) {
+ } else if (type == StyleClipPathType::Shape) {
RefPtr<nsCSSValue::Array> result = nsCSSValue::Array::Create(2);
if (!StyleClipBasicShapeToCSSArray(clipPath, result)) {
return false;
}
aComputedValue.SetCSSValueArrayValue(result, eUnit_Shape);
} else {
- MOZ_ASSERT(type == NS_STYLE_CLIP_PATH_NONE, "unknown type");
+ MOZ_ASSERT(type == StyleClipPathType::None_, "unknown type");
aComputedValue.SetNoneValue();
}
break;
}
case eCSSProperty_filter: {
const nsStyleEffects* effects =
static_cast<const nsStyleEffects*>(styleStruct);
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -5971,17 +5971,17 @@ nsComputedDOMStyle::CreatePrimitiveValue
RefPtr<nsROCSSPrimitiveValue> functionValue = new nsROCSSPrimitiveValue;
functionValue->SetString(shapeFunctionString);
return functionValue.forget();
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::CreatePrimitiveValueForClipPath(
const nsStyleBasicShape* aStyleBasicShape,
- mozilla::StyleClipShapeSizing aSizingBox)
+ StyleClipShapeSizing aSizingBox)
{
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
if (aStyleBasicShape) {
valueList->AppendCSSValue(
CreatePrimitiveValueForBasicShape(aStyleBasicShape));
}
if (aSizingBox == StyleClipShapeSizing::NoBox) {
@@ -6000,28 +6000,28 @@ nsComputedDOMStyle::CreatePrimitiveValue
return valueList.forget();
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetClipPath()
{
const nsStyleSVGReset* svg = StyleSVGReset();
switch (svg->mClipPath.GetType()) {
- case NS_STYLE_CLIP_PATH_SHAPE:
+ case StyleClipPathType::Shape:
return CreatePrimitiveValueForClipPath(svg->mClipPath.GetBasicShape(),
svg->mClipPath.GetSizingBox());
- case NS_STYLE_CLIP_PATH_BOX:
+ case StyleClipPathType::Box:
return CreatePrimitiveValueForClipPath(nullptr,
svg->mClipPath.GetSizingBox());
- case NS_STYLE_CLIP_PATH_URL: {
+ case StyleClipPathType::URL: {
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
val->SetURI(svg->mClipPath.GetURL());
return val.forget();
}
- case NS_STYLE_CLIP_PATH_NONE: {
+ case StyleClipPathType::None_: {
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
val->SetIdent(eCSSKeyword_none);
return val.forget();
}
default:
NS_NOTREACHED("unexpected type");
}
return nullptr;
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -55,16 +55,25 @@ static inline css::Side operator++(css::
((((side_) + !!(second_))*2 + ((side_) + !(parallel_))%2) % 8)
// box-sizing
enum class StyleBoxSizing : uint8_t {
Content,
Border
};
+// clip-path type
+// X11 has a #define for None causing conflicts, so we use None_ here
+enum class StyleClipPathType : uint8_t {
+ None_,
+ URL,
+ Shape,
+ Box,
+};
+
// clip-path sizing
enum class StyleClipShapeSizing : uint8_t {
NoBox,
Content,
Padding,
Border,
Margin,
Fill,
@@ -558,22 +567,16 @@ enum class FillMode : uint32_t;
// See nsStyleDisplay
#define NS_STYLE_FLOAT_NONE 0
#define NS_STYLE_FLOAT_LEFT 1
#define NS_STYLE_FLOAT_RIGHT 2
#define NS_STYLE_FLOAT_INLINE_START 3
#define NS_STYLE_FLOAT_INLINE_END 4
-// See nsStyleClipPath
-#define NS_STYLE_CLIP_PATH_NONE 0
-#define NS_STYLE_CLIP_PATH_URL 1
-#define NS_STYLE_CLIP_PATH_SHAPE 2
-#define NS_STYLE_CLIP_PATH_BOX 3
-
// See nsStyleFilter
#define NS_STYLE_FILTER_NONE 0
#define NS_STYLE_FILTER_URL 1
#define NS_STYLE_FILTER_BLUR 2
#define NS_STYLE_FILTER_BRIGHTNESS 3
#define NS_STYLE_FILTER_CONTRAST 4
#define NS_STYLE_FILTER_GRAYSCALE 5
#define NS_STYLE_FILTER_INVERT 6
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1000,124 +1000,124 @@ nsStyleBasicShape::GetShapeTypeName() co
NS_NOTREACHED("unexpected type");
return eCSSKeyword_UNKNOWN;
}
// --------------------
// nsStyleClipPath
//
nsStyleClipPath::nsStyleClipPath()
- : mType(NS_STYLE_CLIP_PATH_NONE)
- , mURL(nullptr)
- , mSizingBox(mozilla::StyleClipShapeSizing::NoBox)
+ : mURL(nullptr)
+ , mType(StyleClipPathType::None_)
+ , mSizingBox(StyleClipShapeSizing::NoBox)
{
}
nsStyleClipPath::nsStyleClipPath(const nsStyleClipPath& aSource)
- : mType(NS_STYLE_CLIP_PATH_NONE)
- , mURL(nullptr)
- , mSizingBox(mozilla::StyleClipShapeSizing::NoBox)
+ : mURL(nullptr)
+ , mType(StyleClipPathType::None_)
+ , mSizingBox(StyleClipShapeSizing::NoBox)
{
- if (aSource.mType == NS_STYLE_CLIP_PATH_URL) {
+ if (aSource.mType == StyleClipPathType::URL) {
SetURL(aSource.mURL);
- } else if (aSource.mType == NS_STYLE_CLIP_PATH_SHAPE) {
+ } else if (aSource.mType == StyleClipPathType::Shape) {
SetBasicShape(aSource.mBasicShape, aSource.mSizingBox);
- } else if (aSource.mType == NS_STYLE_CLIP_PATH_BOX) {
+ } else if (aSource.mType == StyleClipPathType::Box) {
SetSizingBox(aSource.mSizingBox);
}
}
nsStyleClipPath::~nsStyleClipPath()
{
ReleaseRef();
}
nsStyleClipPath&
nsStyleClipPath::operator=(const nsStyleClipPath& aOther)
{
if (this == &aOther) {
return *this;
}
- if (aOther.mType == NS_STYLE_CLIP_PATH_URL) {
+ if (aOther.mType == StyleClipPathType::URL) {
SetURL(aOther.mURL);
- } else if (aOther.mType == NS_STYLE_CLIP_PATH_SHAPE) {
+ } else if (aOther.mType == StyleClipPathType::Shape) {
SetBasicShape(aOther.mBasicShape, aOther.mSizingBox);
- } else if (aOther.mType == NS_STYLE_CLIP_PATH_BOX) {
+ } else if (aOther.mType == StyleClipPathType::Box) {
SetSizingBox(aOther.mSizingBox);
} else {
ReleaseRef();
- mSizingBox = mozilla::StyleClipShapeSizing::NoBox;
- mType = NS_STYLE_CLIP_PATH_NONE;
+ mSizingBox = StyleClipShapeSizing::NoBox;
+ mType = StyleClipPathType::None_;
}
return *this;
}
bool
nsStyleClipPath::operator==(const nsStyleClipPath& aOther) const
{
if (mType != aOther.mType) {
return false;
}
- if (mType == NS_STYLE_CLIP_PATH_URL) {
+ if (mType == StyleClipPathType::URL) {
return EqualURIs(mURL, aOther.mURL);
- } else if (mType == NS_STYLE_CLIP_PATH_SHAPE) {
+ } else if (mType == StyleClipPathType::Shape) {
return *mBasicShape == *aOther.mBasicShape &&
mSizingBox == aOther.mSizingBox;
- } else if (mType == NS_STYLE_CLIP_PATH_BOX) {
+ } else if (mType == StyleClipPathType::Box) {
return mSizingBox == aOther.mSizingBox;
}
return true;
}
void
nsStyleClipPath::ReleaseRef()
{
- if (mType == NS_STYLE_CLIP_PATH_SHAPE) {
+ if (mType == StyleClipPathType::Shape) {
NS_ASSERTION(mBasicShape, "expected pointer");
mBasicShape->Release();
- } else if (mType == NS_STYLE_CLIP_PATH_URL) {
+ } else if (mType == StyleClipPathType::URL) {
NS_ASSERTION(mURL, "expected pointer");
mURL->Release();
}
// mBasicShap, mURL, etc. are all pointers in a union of pointers. Nulling
// one of them nulls all of them:
mURL = nullptr;
}
void
nsStyleClipPath::SetURL(nsIURI* aURL)
{
NS_ASSERTION(aURL, "expected pointer");
ReleaseRef();
mURL = aURL;
mURL->AddRef();
- mType = NS_STYLE_CLIP_PATH_URL;
+ mType = StyleClipPathType::URL;
}
void
nsStyleClipPath::SetBasicShape(nsStyleBasicShape* aBasicShape,
- mozilla::StyleClipShapeSizing aSizingBox)
+ StyleClipShapeSizing aSizingBox)
{
NS_ASSERTION(aBasicShape, "expected pointer");
ReleaseRef();
mBasicShape = aBasicShape;
mBasicShape->AddRef();
mSizingBox = aSizingBox;
- mType = NS_STYLE_CLIP_PATH_SHAPE;
+ mType = StyleClipPathType::Shape;
}
void
-nsStyleClipPath::SetSizingBox(mozilla::StyleClipShapeSizing aSizingBox)
+nsStyleClipPath::SetSizingBox(StyleClipShapeSizing aSizingBox)
{
ReleaseRef();
mSizingBox = aSizingBox;
- mType = NS_STYLE_CLIP_PATH_BOX;
+ mType = StyleClipPathType::Box;
}
// --------------------
// nsStyleFilter
//
nsStyleFilter::nsStyleFilter()
: mType(NS_STYLE_FILTER_NONE)
, mDropShadow(nullptr)
@@ -2816,87 +2816,87 @@ nsTimingFunction::AssignFromKeyword(int3
MOZ_ASSERT(0 <= aTimingFunctionType && aTimingFunctionType < 5,
"keyword out of range");
mFunc.mX1 = timingFunctionValues[aTimingFunctionType][0];
mFunc.mY1 = timingFunctionValues[aTimingFunctionType][1];
mFunc.mX2 = timingFunctionValues[aTimingFunctionType][2];
mFunc.mY2 = timingFunctionValues[aTimingFunctionType][3];
}
-mozilla::StyleTransition::StyleTransition(const StyleTransition& aCopy)
+StyleTransition::StyleTransition(const StyleTransition& aCopy)
: mTimingFunction(aCopy.mTimingFunction)
, mDuration(aCopy.mDuration)
, mDelay(aCopy.mDelay)
, mProperty(aCopy.mProperty)
, mUnknownProperty(aCopy.mUnknownProperty)
{
}
void
-mozilla::StyleTransition::SetInitialValues()
+StyleTransition::SetInitialValues()
{
mTimingFunction = nsTimingFunction(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE);
mDuration = 0.0;
mDelay = 0.0;
mProperty = eCSSPropertyExtra_all_properties;
}
void
-mozilla::StyleTransition::SetUnknownProperty(nsCSSProperty aProperty,
+StyleTransition::SetUnknownProperty(nsCSSProperty aProperty,
const nsAString& aPropertyString)
{
MOZ_ASSERT(nsCSSProps::LookupProperty(aPropertyString,
CSSEnabledState::eForAllContent) ==
aProperty,
"property and property string should match");
MOZ_ASSERT(aProperty == eCSSProperty_UNKNOWN ||
aProperty == eCSSPropertyExtra_variable,
"should be either unknown or custom property");
mProperty = aProperty;
mUnknownProperty = NS_Atomize(aPropertyString);
}
bool
-mozilla::StyleTransition::operator==(const mozilla::StyleTransition& aOther) const
+StyleTransition::operator==(const mozilla::StyleTransition& aOther) const
{
return mTimingFunction == aOther.mTimingFunction &&
mDuration == aOther.mDuration &&
mDelay == aOther.mDelay &&
mProperty == aOther.mProperty &&
(mProperty != eCSSProperty_UNKNOWN ||
mUnknownProperty == aOther.mUnknownProperty);
}
-mozilla::StyleAnimation::StyleAnimation(const mozilla::StyleAnimation& aCopy)
+StyleAnimation::StyleAnimation(const mozilla::StyleAnimation& aCopy)
: mTimingFunction(aCopy.mTimingFunction)
, mDuration(aCopy.mDuration)
, mDelay(aCopy.mDelay)
, mName(aCopy.mName)
, mDirection(aCopy.mDirection)
, mFillMode(aCopy.mFillMode)
, mPlayState(aCopy.mPlayState)
, mIterationCount(aCopy.mIterationCount)
{
}
void
-mozilla::StyleAnimation::SetInitialValues()
+StyleAnimation::SetInitialValues()
{
mTimingFunction = nsTimingFunction(NS_STYLE_TRANSITION_TIMING_FUNCTION_EASE);
mDuration = 0.0;
mDelay = 0.0;
mName = EmptyString();
mDirection = dom::PlaybackDirection::Normal;
mFillMode = dom::FillMode::None;
mPlayState = NS_STYLE_ANIMATION_PLAY_STATE_RUNNING;
mIterationCount = 1.0f;
}
bool
-mozilla::StyleAnimation::operator==(const mozilla::StyleAnimation& aOther) const
+StyleAnimation::operator==(const mozilla::StyleAnimation& aOther) const
{
return mTimingFunction == aOther.mTimingFunction &&
mDuration == aOther.mDuration &&
mDelay == aOther.mDelay &&
mName == aOther.mName &&
mDirection == aOther.mDirection &&
mFillMode == aOther.mFillMode &&
mPlayState == aOther.mPlayState &&
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3501,47 +3501,47 @@ struct nsStyleClipPath
nsStyleClipPath& operator=(const nsStyleClipPath& aOther);
bool operator==(const nsStyleClipPath& aOther) const;
bool operator!=(const nsStyleClipPath& aOther) const {
return !(*this == aOther);
}
- int32_t GetType() const {
+ mozilla::StyleClipPathType GetType() const {
return mType;
}
nsIURI* GetURL() const {
- NS_ASSERTION(mType == NS_STYLE_CLIP_PATH_URL, "wrong clip-path type");
+ NS_ASSERTION(mType == mozilla::StyleClipPathType::URL, "wrong clip-path type");
return mURL;
}
void SetURL(nsIURI* aURL);
nsStyleBasicShape* GetBasicShape() const {
- NS_ASSERTION(mType == NS_STYLE_CLIP_PATH_SHAPE, "wrong clip-path type");
+ NS_ASSERTION(mType == mozilla::StyleClipPathType::Shape, "wrong clip-path type");
return mBasicShape;
}
void SetBasicShape(nsStyleBasicShape* mBasicShape,
mozilla::StyleClipShapeSizing aSizingBox =
mozilla::StyleClipShapeSizing::NoBox);
mozilla::StyleClipShapeSizing GetSizingBox() const { return mSizingBox; }
void SetSizingBox(mozilla::StyleClipShapeSizing aSizingBox);
private:
void ReleaseRef();
void* operator new(size_t) = delete;
- int32_t mType; // see NS_STYLE_CLIP_PATH_* constants in nsStyleConsts.h
union {
nsStyleBasicShape* mBasicShape;
nsIURI* mURL;
};
+ mozilla::StyleClipPathType mType;
mozilla::StyleClipShapeSizing mSizingBox;
};
struct nsStyleFilter
{
nsStyleFilter();
nsStyleFilter(const nsStyleFilter& aSource);
~nsStyleFilter();
@@ -3620,17 +3620,17 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
// CalcDifference never returns the reflow hints that are sometimes
// handled for descendants as hints not handled for descendants.
return nsChangeHint_NeedReflow |
nsChangeHint_ReflowChangesSizeOrPosition |
nsChangeHint_ClearAncestorIntrinsics;
}
bool HasClipPath() const {
- return mClipPath.GetType() != NS_STYLE_CLIP_PATH_NONE;
+ return mClipPath.GetType() != mozilla::StyleClipPathType::None_;
}
bool HasNonScalingStroke() const {
return mVectorEffect == NS_STYLE_VECTOR_EFFECT_NON_SCALING_STROKE;
}
nsStyleImageLayers mMask;
nsStyleClipPath mClipPath; // [reset]
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -18,42 +18,42 @@
using namespace mozilla;
using namespace mozilla::gfx;
/* static*/ void
nsCSSClipPathInstance::ApplyBasicShapeClip(gfxContext& aContext,
nsIFrame* aFrame)
{
auto& clipPathStyle = aFrame->StyleSVGReset()->mClipPath;
- int32_t type = clipPathStyle.GetType();
- MOZ_ASSERT(type != NS_STYLE_CLIP_PATH_NONE, "unexpected none value");
+ StyleClipPathType type = clipPathStyle.GetType();
+ MOZ_ASSERT(type != StyleClipPathType::None_, "unexpected none value");
// In the future nsCSSClipPathInstance may handle <clipPath> references as
// well. For the time being return early.
- if (type == NS_STYLE_CLIP_PATH_URL) {
+ if (type == StyleClipPathType::URL) {
return;
}
nsCSSClipPathInstance instance(aFrame, clipPathStyle);
aContext.NewPath();
RefPtr<Path> path = instance.CreateClipPath(aContext.GetDrawTarget());
aContext.SetPath(path);
aContext.Clip();
}
/* static*/ bool
nsCSSClipPathInstance::HitTestBasicShapeClip(nsIFrame* aFrame,
const gfxPoint& aPoint)
{
auto& clipPathStyle = aFrame->StyleSVGReset()->mClipPath;
- int32_t type = clipPathStyle.GetType();
- MOZ_ASSERT(type != NS_STYLE_CLIP_PATH_NONE, "unexpected none value");
+ StyleClipPathType type = clipPathStyle.GetType();
+ MOZ_ASSERT(type != StyleClipPathType::None_, "unexpected none value");
// In the future nsCSSClipPathInstance may handle <clipPath> references as
// well. For the time being return early.
- if (type == NS_STYLE_CLIP_PATH_URL) {
+ if (type == StyleClipPathType::URL) {
return false;
}
nsCSSClipPathInstance instance(aFrame, clipPathStyle);
RefPtr<DrawTarget> drawTarget =
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
RefPtr<Path> path = instance.CreateClipPath(drawTarget);
@@ -76,17 +76,17 @@ nsCSSClipPathInstance::CreateClipPath(Dr
break;
case StyleClipShapeSizing::Margin:
r = mTargetFrame->GetMarginRectRelativeToSelf();
break;
default: // Use the border box
r = mTargetFrame->GetRectRelativeToSelf();
}
- if (mClipPathStyle.GetType() != NS_STYLE_CLIP_PATH_SHAPE) {
+ if (mClipPathStyle.GetType() != StyleClipPathType::Shape) {
// TODO Clip to border-radius/reference box if no shape
// was specified.
RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
return builder->Finish();
}
nscoord appUnitsPerDevPixel =
mTargetFrame->PresContext()->AppUnitsPerDevPixel();
--- a/layout/svg/nsSVGEffects.cpp
+++ b/layout/svg/nsSVGEffects.cpp
@@ -566,17 +566,17 @@ nsSVGEffects::GetEffectProperties(nsIFra
{
NS_ASSERTION(!aFrame->GetPrevContinuation(), "aFrame should be first continuation");
EffectProperties result;
const nsStyleSVGReset *style = aFrame->StyleSVGReset();
result.mFilter = GetOrCreateFilterProperty(aFrame);
- if (style->mClipPath.GetType() == NS_STYLE_CLIP_PATH_URL) {
+ if (style->mClipPath.GetType() == StyleClipPathType::URL) {
result.mClipPath =
GetPaintingProperty(style->mClipPath.GetURL(), aFrame, ClipPathProperty());
} else {
result.mClipPath = nullptr;
}
MOZ_ASSERT(style->mMask.mImageCount > 0);
result.mMask = style->mMask.HasLayerWithImage()