Bug 1304302 part 5 - Make StyleSheet::As{Gecko,Servo} return pointer instead of reference. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Fri, 23 Sep 2016 17:05:29 +1000
changeset 416884 b3b854b0d20a72a95527d505386b59b7c50fe684
parent 416883 607433fe6507079d7c6add1a1a89952ea5d193c1
child 416885 d791e6a7a2f8789095ab5c7d7b432d98cb39a7cf
child 417489 51fdc11721bef68046480ac45ef2c0539e8f97af
push id30278
push userxquan@mozilla.com
push dateFri, 23 Sep 2016 07:08:40 +0000
reviewersheycam
bugs1304302
milestone51.0a1
Bug 1304302 part 5 - Make StyleSheet::As{Gecko,Servo} return pointer instead of reference. r?heycam To match the behavior of StyleSheetHandle so that we can simply replace uses of StyleSheetHandle with StyleSheet* in later patch. MozReview-Commit-ID: LfGKrUmzC4h
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
layout/style/StyleSheetInlines.h
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -53,17 +53,18 @@ bool
 StyleSheet::IsComplete() const
 {
   return SheetInfo().mComplete;
 }
 
 void
 StyleSheet::SetComplete()
 {
-  NS_ASSERTION(!IsGecko() || !AsGecko().mDirty, "Can't set a dirty sheet complete!");
+  NS_ASSERTION(!IsGecko() || !AsGecko()->mDirty,
+               "Can't set a dirty sheet complete!");
   SheetInfo().mComplete = true;
   if (mDocument && !mDisabled) {
     // Let the document know
     mDocument->BeginUpdate(UPDATE_STYLE);
     mDocument->SetStyleSheetApplicableState(AsHandle(), true);
     mDocument->EndUpdate(UPDATE_STYLE);
   }
 
@@ -74,14 +75,14 @@ StyleSheet::SetComplete()
     shadowRoot->StyleSheetChanged();
   }
 }
 
 StyleSheetInfo&
 StyleSheet::SheetInfo()
 {
   if (IsServo()) {
-    return AsServo();
+    return *AsServo();
   }
-  return *AsGecko().mInner;
+  return *AsGecko()->mInner;
 }
 
 } // namespace mozilla
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -62,21 +62,21 @@ public:
     return mType == StyleBackendType::Servo;
 #else
     return false;
 #endif
   }
 
   // Only safe to call if the caller has verified that that |this| is of the
   // correct type.
-  inline CSSStyleSheet& AsGecko();
-  inline ServoStyleSheet& AsServo();
+  inline CSSStyleSheet* AsGecko();
+  inline ServoStyleSheet* AsServo();
   inline StyleSheetHandle AsHandle();
-  inline const CSSStyleSheet& AsGecko() const;
-  inline const ServoStyleSheet& AsServo() const;
+  inline const CSSStyleSheet* AsGecko() const;
+  inline const ServoStyleSheet* AsServo() const;
 
   inline MozExternalRefCountType AddRef();
   inline MozExternalRefCountType Release();
 
   // Whether the sheet is for an inline <style> element.
   inline bool IsInline() const;
 
   inline nsIURI* GetSheetURI() const;
--- a/layout/style/StyleSheetInlines.h
+++ b/layout/style/StyleSheetInlines.h
@@ -8,64 +8,64 @@
 #define mozilla_StyleSheetInlines_h
 
 #include "mozilla/TypeTraits.h"
 #include "mozilla/ServoStyleSheet.h"
 #include "mozilla/CSSStyleSheet.h"
 
 namespace mozilla {
 
-CSSStyleSheet&
+CSSStyleSheet*
 StyleSheet::AsGecko()
 {
   MOZ_ASSERT(IsGecko());
-  return *static_cast<CSSStyleSheet*>(this);
+  return static_cast<CSSStyleSheet*>(this);
 }
 
-ServoStyleSheet&
+ServoStyleSheet*
 StyleSheet::AsServo()
 {
   MOZ_ASSERT(IsServo());
-  return *static_cast<ServoStyleSheet*>(this);
+  return static_cast<ServoStyleSheet*>(this);
 }
 
 StyleSheetHandle
 StyleSheet::AsHandle()
 {
   if (IsServo()) {
-    return &AsServo();
+    return AsServo();
   }
-  return &AsGecko();
+  return AsGecko();
 }
 
-const CSSStyleSheet&
+const CSSStyleSheet*
 StyleSheet::AsGecko() const
 {
   MOZ_ASSERT(IsGecko());
-  return *static_cast<const CSSStyleSheet*>(this);
+  return static_cast<const CSSStyleSheet*>(this);
 }
 
-const ServoStyleSheet&
+const ServoStyleSheet*
 StyleSheet::AsServo() const
 {
   MOZ_ASSERT(IsServo());
-  return *static_cast<const ServoStyleSheet*>(this);
+  return static_cast<const ServoStyleSheet*>(this);
 }
 
 #define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \
   static_assert(!IsSame<decltype(&StyleSheet::method_), \
                         decltype(&CSSStyleSheet::method_)>::value, \
                 "CSSStyleSheet should define its own " #method_); \
   static_assert(!IsSame<decltype(&StyleSheet::method_), \
                         decltype(&ServoStyleSheet::method_)>::value, \
                 "ServoStyleSheet should define its own " #method_); \
   if (IsServo()) { \
-    return AsServo().method_ servoargs_; \
+    return AsServo()->method_ servoargs_; \
   } \
-  return AsGecko().method_ geckoargs_;
+  return AsGecko()->method_ geckoargs_;
 
 #define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_)
 
 MozExternalRefCountType
 StyleSheet::AddRef()
 {
   FORWARD(AddRef, ())
 }
@@ -135,17 +135,17 @@ StyleSheet*
 StyleSheet::GetParentSheet() const
 {
   FORWARD(GetParentSheet, ())
 }
 
 void
 StyleSheet::AppendStyleSheet(StyleSheet* aSheet)
 {
-  FORWARD_CONCRETE(AppendStyleSheet, (&aSheet->AsGecko()), (&aSheet->AsServo()))
+  FORWARD_CONCRETE(AppendStyleSheet, (aSheet->AsGecko()), (aSheet->AsServo()))
 }
 
 nsIPrincipal*
 StyleSheet::Principal() const
 {
   return SheetInfo().mPrincipal;
 }