Bug 1404243 Part 1 - Move StyleShapeSource's large methods to nsStyleStruct.cpp. draft
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 27 Sep 2017 11:32:38 +0800
changeset 673199 9f49ba69e091c97ce64502032fd7c3960c22df9e
parent 673198 287fa4a212a6fe6eadefd4d0794852a1ebaefa44
child 673200 ef39ecaf85dbc849f8c338b335f3cd43b2e842e2
push id82495
push userbmo:tlin@mozilla.com
push dateMon, 02 Oct 2017 03:57:39 +0000
bugs1404243
milestone58.0a1
Bug 1404243 Part 1 - Move StyleShapeSource's large methods to nsStyleStruct.cpp. MozReview-Commit-ID: 5X5LGCSzSwX
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- 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;