Bug 1404243 Part 1 - Move StyleShapeSource's large methods to nsStyleStruct.cpp.
MozReview-Commit-ID: 5X5LGCSzSwX
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1034,16 +1034,98 @@ StyleBasicShape::GetShapeTypeName() cons
case StyleBasicShapeType::Inset:
return eCSSKeyword_inset;
}
NS_NOTREACHED("unexpected type");
return eCSSKeyword_UNKNOWN;
}
// --------------------
+// StyleShapeSource
+
+StyleShapeSource::StyleShapeSource(const StyleShapeSource& aSource)
+ : StyleShapeSource()
+{
+ if (aSource.mType == StyleShapeSourceType::URL) {
+ SetURL(aSource.mURL);
+ } else if (aSource.mType == StyleShapeSourceType::Shape) {
+ SetBasicShape(aSource.mBasicShape, aSource.mReferenceBox);
+ } else if (aSource.mType == StyleShapeSourceType::Box) {
+ SetReferenceBox(aSource.mReferenceBox);
+ }
+}
+
+StyleShapeSource&
+StyleShapeSource::operator=(const StyleShapeSource& aOther)
+{
+ if (this == &aOther) {
+ return *this;
+ }
+
+ if (aOther.mType == StyleShapeSourceType::URL) {
+ SetURL(aOther.mURL);
+ } else if (aOther.mType == StyleShapeSourceType::Shape) {
+ SetBasicShape(aOther.mBasicShape, aOther.mReferenceBox);
+ } else if (aOther.mType == StyleShapeSourceType::Box) {
+ SetReferenceBox(aOther.mReferenceBox);
+ } else {
+ ReleaseRef();
+ mReferenceBox = StyleGeometryBox::NoBox;
+ mType = StyleShapeSourceType::None;
+ }
+ return *this;
+}
+
+bool
+StyleShapeSource::SetURL(css::URLValue* aValue)
+{
+ MOZ_ASSERT(aValue);
+ ReleaseRef();
+ mURL = aValue;
+ mURL->AddRef();
+ mType = StyleShapeSourceType::URL;
+ return true;
+}
+
+void
+StyleShapeSource::SetBasicShape(StyleBasicShape* aBasicShape,
+ StyleGeometryBox aReferenceBox)
+{
+ NS_ASSERTION(aBasicShape, "expected pointer");
+ ReleaseRef();
+ mBasicShape = aBasicShape;
+ mBasicShape->AddRef();
+ mReferenceBox = aReferenceBox;
+ mType = StyleShapeSourceType::Shape;
+}
+
+void
+StyleShapeSource::SetReferenceBox(StyleGeometryBox aReferenceBox)
+{
+ ReleaseRef();
+ mReferenceBox = aReferenceBox;
+ mType = StyleShapeSourceType::Box;
+}
+
+void
+StyleShapeSource::ReleaseRef()
+{
+ if (mType == StyleShapeSourceType::Shape) {
+ NS_ASSERTION(mBasicShape, "expected pointer");
+ mBasicShape->Release();
+ } else if (mType == StyleShapeSourceType::URL) {
+ NS_ASSERTION(mURL, "expected pointer");
+ mURL->Release();
+ }
+ // Both mBasicShape and mURL are pointers in a union. Nulling one of them
+ // nulls both of them.
+ mURL = nullptr;
+}
+
+// --------------------
// nsStyleFilter
//
nsStyleFilter::nsStyleFilter()
: mType(NS_STYLE_FILTER_NONE)
, mDropShadow(nullptr)
{
MOZ_COUNT_CTOR(nsStyleFilter);
}
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -2440,52 +2440,24 @@ private:
};
struct StyleShapeSource
{
StyleShapeSource()
: mURL(nullptr)
{}
- StyleShapeSource(const StyleShapeSource& aSource)
- : StyleShapeSource()
- {
- if (aSource.mType == StyleShapeSourceType::URL) {
- SetURL(aSource.mURL);
- } else if (aSource.mType == StyleShapeSourceType::Shape) {
- SetBasicShape(aSource.mBasicShape, aSource.mReferenceBox);
- } else if (aSource.mType == StyleShapeSourceType::Box) {
- SetReferenceBox(aSource.mReferenceBox);
- }
- }
+ StyleShapeSource(const StyleShapeSource& aSource);
~StyleShapeSource()
{
ReleaseRef();
}
- StyleShapeSource& operator=(const StyleShapeSource& aOther)
- {
- if (this == &aOther) {
- return *this;
- }
-
- if (aOther.mType == StyleShapeSourceType::URL) {
- SetURL(aOther.mURL);
- } else if (aOther.mType == StyleShapeSourceType::Shape) {
- SetBasicShape(aOther.mBasicShape, aOther.mReferenceBox);
- } else if (aOther.mType == StyleShapeSourceType::Box) {
- SetReferenceBox(aOther.mReferenceBox);
- } else {
- ReleaseRef();
- mReferenceBox = StyleGeometryBox::NoBox;
- mType = StyleShapeSourceType::None;
- }
- return *this;
- }
+ StyleShapeSource& operator=(const StyleShapeSource& aOther);
bool operator==(const StyleShapeSource& aOther) const
{
return EqualsInternal<true>(aOther);
}
bool DefinitelyEquals(const StyleShapeSource& aOther) const
{
@@ -2523,72 +2495,39 @@ struct StyleShapeSource
}
css::URLValue* GetURL() const
{
MOZ_ASSERT(mType == StyleShapeSourceType::URL, "Wrong shape source type!");
return mURL;
}
- bool SetURL(css::URLValue* aValue)
- {
- MOZ_ASSERT(aValue);
- ReleaseRef();
- mURL = aValue;
- mURL->AddRef();
- mType = StyleShapeSourceType::URL;
- return true;
- }
+ bool SetURL(css::URLValue* aValue);
StyleBasicShape* GetBasicShape() const
{
MOZ_ASSERT(mType == StyleShapeSourceType::Shape, "Wrong shape source type!");
return mBasicShape;
}
void SetBasicShape(StyleBasicShape* aBasicShape,
- StyleGeometryBox aReferenceBox)
- {
- NS_ASSERTION(aBasicShape, "expected pointer");
- ReleaseRef();
- mBasicShape = aBasicShape;
- mBasicShape->AddRef();
- mReferenceBox = aReferenceBox;
- mType = StyleShapeSourceType::Shape;
- }
+ StyleGeometryBox aReferenceBox);
StyleGeometryBox GetReferenceBox() const
{
MOZ_ASSERT(mType == StyleShapeSourceType::Box ||
mType == StyleShapeSourceType::Shape,
"Wrong shape source type!");
return mReferenceBox;
}
- void SetReferenceBox(StyleGeometryBox aReferenceBox)
- {
- ReleaseRef();
- mReferenceBox = aReferenceBox;
- mType = StyleShapeSourceType::Box;
- }
+ void SetReferenceBox(StyleGeometryBox aReferenceBox);
private:
- void ReleaseRef()
- {
- if (mType == StyleShapeSourceType::Shape) {
- NS_ASSERTION(mBasicShape, "expected pointer");
- mBasicShape->Release();
- } else if (mType == StyleShapeSourceType::URL) {
- NS_ASSERTION(mURL, "expected pointer");
- mURL->Release();
- }
- // Both mBasicShape and mURL are pointers in a union. Nulling one of them
- // nulls both of them.
- mURL = nullptr;
- }
+ void ReleaseRef();
void* operator new(size_t) = delete;
union {
StyleBasicShape* mBasicShape;
css::URLValue* mURL;
};
StyleShapeSourceType mType = StyleShapeSourceType::None;