Bug 1448763 part 3 - Remove nsCSSValueTokenStream. r?emilio draft
authorXidorn Quan <me@upsuper.org>
Thu, 05 Apr 2018 13:44:28 +1000
changeset 777684 485f40d2e8245ddafcececc08f0fc1a6eed0de79
parent 777683 f36ec0a41b2c67834f87292eea0b9a05022c10c8
child 777685 3828ab2228036b67dee6460f2d897afd2f188451
push id105263
push userxquan@mozilla.com
push dateThu, 05 Apr 2018 05:22:06 +0000
reviewersemilio
bugs1448763
milestone61.0a1
Bug 1448763 part 3 - Remove nsCSSValueTokenStream. r?emilio MozReview-Commit-ID: 79CPOfWbo7t
layout/style/ServoBindings.toml
layout/style/nsCSSValue.cpp
layout/style/nsCSSValue.h
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -287,17 +287,16 @@ whitelist-types = [
     "nsCSSValueFloatColor",
     "nsCSSValueGradient",
     "nsCSSValueGradientStop",
     "nsCSSValueList",
     "nsCSSValueList_heap",
     "nsCSSValuePair_heap",
     "nsCSSValuePairList",
     "nsCSSValuePairList_heap",
-    "nsCSSValueTokenStream",
     "nsCSSValueTriplet_heap",
     "nsCursorImage",
     "nsFont",
     "nsAtom",
     "nsDynamicAtom",
     "nsMainThreadPtrHandle",
     "nsMainThreadPtrHolder",
     "nsMargin",
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -112,23 +112,16 @@ nsCSSValue::nsCSSValue(mozilla::css::Ima
 
 nsCSSValue::nsCSSValue(nsCSSValueGradient* aValue)
   : mUnit(eCSSUnit_Gradient)
 {
   mValue.mGradient = aValue;
   mValue.mGradient->AddRef();
 }
 
-nsCSSValue::nsCSSValue(nsCSSValueTokenStream* aValue)
-  : mUnit(eCSSUnit_TokenStream)
-{
-  mValue.mTokenStream = aValue;
-  mValue.mTokenStream->AddRef();
-}
-
 nsCSSValue::nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue)
   : mUnit(eCSSUnit_GridTemplateAreas)
 {
   mValue.mGridTemplateAreas = aValue;
   mValue.mGridTemplateAreas->AddRef();
 }
 
 nsCSSValue::nsCSSValue(SharedFontList* aValue)
@@ -177,20 +170,16 @@ nsCSSValue::nsCSSValue(const nsCSSValue&
   else if (eCSSUnit_Image == mUnit) {
     mValue.mImage = aCopy.mValue.mImage;
     mValue.mImage->AddRef();
   }
   else if (eCSSUnit_Gradient == mUnit) {
     mValue.mGradient = aCopy.mValue.mGradient;
     mValue.mGradient->AddRef();
   }
-  else if (eCSSUnit_TokenStream == mUnit) {
-    mValue.mTokenStream = aCopy.mValue.mTokenStream;
-    mValue.mTokenStream->AddRef();
-  }
   else if (eCSSUnit_Pair == mUnit) {
     mValue.mPair = aCopy.mValue.mPair;
     mValue.mPair->AddRef();
   }
   else if (eCSSUnit_Triplet == mUnit) {
     mValue.mTriplet = aCopy.mValue.mTriplet;
     mValue.mTriplet->AddRef();
   }
@@ -290,19 +279,16 @@ bool nsCSSValue::operator==(const nsCSSV
       return mValue.mURL->Equals(*aOther.mValue.mURL);
     }
     else if (eCSSUnit_Image == mUnit) {
       return mValue.mImage->Equals(*aOther.mValue.mImage);
     }
     else if (eCSSUnit_Gradient == mUnit) {
       return *mValue.mGradient == *aOther.mValue.mGradient;
     }
-    else if (eCSSUnit_TokenStream == mUnit) {
-      return *mValue.mTokenStream == *aOther.mValue.mTokenStream;
-    }
     else if (eCSSUnit_Pair == mUnit) {
       return *mValue.mPair == *aOther.mValue.mPair;
     }
     else if (eCSSUnit_Triplet == mUnit) {
       return *mValue.mTriplet == *aOther.mValue.mTriplet;
     }
     else if (eCSSUnit_Rect == mUnit) {
       return *mValue.mRect == *aOther.mValue.mRect;
@@ -427,18 +413,16 @@ void nsCSSValue::DoReset()
   } else if (UnitHasArrayValue()) {
     DO_RELEASE(mArray);
   } else if (eCSSUnit_URL == mUnit) {
     DO_RELEASE(mURL);
   } else if (eCSSUnit_Image == mUnit) {
     DO_RELEASE(mImage);
   } else if (eCSSUnit_Gradient == mUnit) {
     DO_RELEASE(mGradient);
-  } else if (eCSSUnit_TokenStream == mUnit) {
-    DO_RELEASE(mTokenStream);
   } else if (eCSSUnit_Pair == mUnit) {
     DO_RELEASE(mPair);
   } else if (eCSSUnit_Triplet == mUnit) {
     DO_RELEASE(mTriplet);
   } else if (eCSSUnit_Rect == mUnit) {
     DO_RELEASE(mRect);
   } else if (eCSSUnit_List == mUnit) {
     DO_RELEASE(mList);
@@ -588,24 +572,16 @@ void nsCSSValue::SetImageValue(mozilla::
 void nsCSSValue::SetGradientValue(nsCSSValueGradient* aValue)
 {
   Reset();
   mUnit = eCSSUnit_Gradient;
   mValue.mGradient = aValue;
   mValue.mGradient->AddRef();
 }
 
-void nsCSSValue::SetTokenStreamValue(nsCSSValueTokenStream* aValue)
-{
-  Reset();
-  mUnit = eCSSUnit_TokenStream;
-  mValue.mTokenStream = aValue;
-  mValue.mTokenStream->AddRef();
-}
-
 void nsCSSValue::SetGridTemplateAreas(mozilla::css::GridTemplateAreasValue* aValue)
 {
   Reset();
   mUnit = eCSSUnit_GridTemplateAreas;
   mValue.mGridTemplateAreas = aValue;
   mValue.mGridTemplateAreas->AddRef();
 }
 
@@ -1077,21 +1053,16 @@ nsCSSValue::SizeOfExcludingThis(mozilla:
       n += mValue.mImage->SizeOfIncludingThis(aMallocSizeOf);
       break;
 
     // Gradient
     case eCSSUnit_Gradient:
       n += mValue.mGradient->SizeOfIncludingThis(aMallocSizeOf);
       break;
 
-    // TokenStream
-    case eCSSUnit_TokenStream:
-      n += mValue.mTokenStream->SizeOfIncludingThis(aMallocSizeOf);
-      break;
-
     // Pair
     case eCSSUnit_Pair:
       n += mValue.mPair->SizeOfIncludingThis(aMallocSizeOf);
       break;
 
     // Triplet
     case eCSSUnit_Triplet:
       n += mValue.mTriplet->SizeOfIncludingThis(aMallocSizeOf);
@@ -2004,39 +1975,16 @@ nsCSSValueGradient::SizeOfIncludingThis(
     n += mStops.ShallowSizeOfExcludingThis(aMallocSizeOf);
     for (uint32_t i = 0; i < mStops.Length(); i++) {
       n += mStops[i].SizeOfExcludingThis(aMallocSizeOf);
     }
   }
   return n;
 }
 
-// --- nsCSSValueTokenStream ------------
-
-nsCSSValueTokenStream::nsCSSValueTokenStream()
-  : mPropertyID(eCSSProperty_UNKNOWN)
-  , mShorthandPropertyID(eCSSProperty_UNKNOWN)
-  , mLevel(SheetType::Count)
-{}
-
-nsCSSValueTokenStream::~nsCSSValueTokenStream()
-{}
-
-size_t
-nsCSSValueTokenStream::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
-{
-  // Only measure it if it's unshared, to avoid double-counting.
-  size_t n = 0;
-  if (mRefCnt <= 1) {
-    n += aMallocSizeOf(this);
-    n += mTokenStream.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
-  }
-  return n;
-}
-
 // --- nsCSSValueFloatColor -------------
 
 bool
 nsCSSValueFloatColor::operator==(nsCSSValueFloatColor& aOther) const
 {
   return mComponent1 == aOther.mComponent1 &&
          mComponent2 == aOther.mComponent2 &&
          mComponent3 == aOther.mComponent3 &&
--- a/layout/style/nsCSSValue.h
+++ b/layout/style/nsCSSValue.h
@@ -496,17 +496,16 @@ enum nsCSSUnit {
   eCSSUnit_Calc_Minus   = 32,     // (nsCSSValue::Array*) - within calc
   eCSSUnit_Calc_Times_L = 33,     // (nsCSSValue::Array*) num * val within calc
   eCSSUnit_Calc_Times_R = 34,     // (nsCSSValue::Array*) val * num within calc
   eCSSUnit_Calc_Divided = 35,     // (nsCSSValue::Array*) / within calc
 
   eCSSUnit_URL          = 40,     // (nsCSSValue::URL*) value
   eCSSUnit_Image        = 41,     // (nsCSSValue::Image*) value
   eCSSUnit_Gradient     = 42,     // (nsCSSValueGradient*) value
-  eCSSUnit_TokenStream  = 43,     // (nsCSSValueTokenStream*) value
   eCSSUnit_GridTemplateAreas   = 44,   // (GridTemplateAreasValue*)
                                        // for grid-template-areas
 
   eCSSUnit_Pair         = 50,     // (nsCSSValuePair*) pair of values
   eCSSUnit_Triplet      = 51,     // (nsCSSValueTriplet*) triplet of values
   eCSSUnit_Rect         = 52,     // (nsCSSRect*) rectangle (four values)
   eCSSUnit_List         = 53,     // (nsCSSValueList*) list of values
   eCSSUnit_ListDep      = 54,     // (nsCSSValueList*) same as List
@@ -585,17 +584,16 @@ enum nsCSSUnit {
 
   // Flexible fraction (CSS Grid)
   eCSSUnit_FlexFraction = 4000     // (float) Fraction of free space
 };
 
 struct nsCSSValueGradient;
 struct nsCSSValuePair;
 struct nsCSSValuePair_heap;
-struct nsCSSValueTokenStream;
 struct nsCSSRect;
 struct nsCSSRect_heap;
 struct nsCSSValueList;
 struct nsCSSValueList_heap;
 struct nsCSSValueSharedList;
 struct nsCSSValuePairList;
 struct nsCSSValuePairList_heap;
 struct nsCSSValueTriplet;
@@ -620,17 +618,16 @@ public:
 
   nsCSSValue(int32_t aValue, nsCSSUnit aUnit);
   nsCSSValue(float aValue, nsCSSUnit aUnit);
   nsCSSValue(const nsString& aValue, nsCSSUnit aUnit);
   nsCSSValue(Array* aArray, nsCSSUnit aUnit);
   explicit nsCSSValue(mozilla::css::URLValue* aValue);
   explicit nsCSSValue(mozilla::css::ImageValue* aValue);
   explicit nsCSSValue(nsCSSValueGradient* aValue);
-  explicit nsCSSValue(nsCSSValueTokenStream* aValue);
   explicit nsCSSValue(mozilla::css::GridTemplateAreasValue* aValue);
   explicit nsCSSValue(mozilla::SharedFontList* aValue);
   nsCSSValue(const nsCSSValue& aCopy);
   nsCSSValue(nsCSSValue&& aOther)
     : mUnit(aOther.mUnit)
     , mValue(aOther.mValue)
   {
     aOther.mUnit = eCSSUnit_Null;
@@ -809,22 +806,16 @@ public:
   }
 
   nsCSSValueGradient* GetGradientValue() const
   {
     MOZ_ASSERT(mUnit == eCSSUnit_Gradient, "not a gradient value");
     return mValue.mGradient;
   }
 
-  nsCSSValueTokenStream* GetTokenStreamValue() const
-  {
-    MOZ_ASSERT(mUnit == eCSSUnit_TokenStream, "not a token stream value");
-    return mValue.mTokenStream;
-  }
-
   nsCSSValueSharedList* GetSharedListValue() const
   {
     MOZ_ASSERT(mUnit == eCSSUnit_SharedList, "not a shared list value");
     return mValue.mSharedList;
   }
 
   mozilla::NotNull<mozilla::SharedFontList*> GetFontFamilyListValue() const
   {
@@ -937,17 +928,16 @@ public:
                           float aAlpha, nsCSSUnit aUnit);
   void SetRGBAColorValue(const mozilla::css::RGBAColorData& aValue);
   void SetComplexColorValue(
     already_AddRefed<mozilla::css::ComplexColorValue> aValue);
   void SetArrayValue(nsCSSValue::Array* aArray, nsCSSUnit aUnit);
   void SetURLValue(mozilla::css::URLValue* aURI);
   void SetImageValue(mozilla::css::ImageValue* aImage);
   void SetGradientValue(nsCSSValueGradient* aGradient);
-  void SetTokenStreamValue(nsCSSValueTokenStream* aTokenStream);
   void SetGridTemplateAreas(mozilla::css::GridTemplateAreasValue* aValue);
   void SetFontFamilyListValue(already_AddRefed<mozilla::SharedFontList> aFontListValue);
   void SetPairValue(const nsCSSValuePair* aPair);
   void SetPairValue(const nsCSSValue& xValue, const nsCSSValue& yValue);
   void SetSharedListValue(nsCSSValueSharedList* aList);
   void SetDependentListValue(nsCSSValueList* aList);
   void SetDependentPairListValue(nsCSSValuePairList* aList);
   void SetTripletValue(const nsCSSValueTriplet* aTriplet);
@@ -1014,17 +1004,16 @@ protected:
     nsStringBuffer* MOZ_OWNING_REF mString;
     nscolor    mColor;
     nsAtom* MOZ_OWNING_REF mAtom;
     Array* MOZ_OWNING_REF mArray;
     mozilla::css::URLValue* MOZ_OWNING_REF mURL;
     mozilla::css::ImageValue* MOZ_OWNING_REF mImage;
     mozilla::css::GridTemplateAreasValue* MOZ_OWNING_REF mGridTemplateAreas;
     nsCSSValueGradient* MOZ_OWNING_REF mGradient;
-    nsCSSValueTokenStream* MOZ_OWNING_REF mTokenStream;
     nsCSSValuePair_heap* MOZ_OWNING_REF mPair;
     nsCSSRect_heap* MOZ_OWNING_REF mRect;
     nsCSSValueTriplet_heap* MOZ_OWNING_REF mTriplet;
     nsCSSValueList_heap* MOZ_OWNING_REF mList;
     nsCSSValueList* mListDependent;
     nsCSSValueSharedList* MOZ_OWNING_REF mSharedList;
     nsCSSValuePairList_heap* MOZ_OWNING_REF mPairList;
     nsCSSValuePairList* mPairListDependent;
@@ -1708,104 +1697,16 @@ private:
   ~nsCSSValueGradient()
   {
   }
 
   nsCSSValueGradient(const nsCSSValueGradient& aOther) = delete;
   nsCSSValueGradient& operator=(const nsCSSValueGradient& aOther) = delete;
 };
 
-// A string value used primarily to represent variable references.
-//
-// Animation code, specifically the KeyframeUtils class, also uses this
-// type as a container for various string values including:
-//
-// * Shorthand property values
-// * Shorthand sentinel values used for testing failure conditions
-// * Invalid longhand property values
-//
-// For the most part, the above values are not passed to functions that
-// manipulate nsCSSValue objects in a generic fashion. Instead KeyframeUtils
-// extracts the string from the nsCSSValueTokenStream and passes that around
-// instead. The single exception is nsCSSValue::AppendToString which we use
-// to serialize the string contained in the nsCSSValueTokenStream by ensuring
-// the mShorthandPropertyID is set to eCSSProperty_UNKNOWN.
-struct nsCSSValueTokenStream final {
-  nsCSSValueTokenStream();
-
-private:
-  // Private destructor, to discourage deletion outside of Release():
-  ~nsCSSValueTokenStream();
-
-public:
-  bool operator==(const nsCSSValueTokenStream& aOther) const
-  {
-    // This is not safe to call OMT, due to the URI/Principal Equals calls.
-    MOZ_ASSERT(NS_IsMainThread());
-
-    bool eq;
-    return mPropertyID == aOther.mPropertyID &&
-           mShorthandPropertyID == aOther.mShorthandPropertyID &&
-           mTokenStream.Equals(aOther.mTokenStream) &&
-           mLevel == aOther.mLevel &&
-           (mBaseURI == aOther.mBaseURI ||
-            (mBaseURI && aOther.mBaseURI &&
-             NS_SUCCEEDED(mBaseURI->Equals(aOther.mBaseURI, &eq)) &&
-             eq)) &&
-           (mSheetURI == aOther.mSheetURI ||
-            (mSheetURI && aOther.mSheetURI &&
-             NS_SUCCEEDED(mSheetURI->Equals(aOther.mSheetURI, &eq)) &&
-             eq)) &&
-           (mSheetPrincipal == aOther.mSheetPrincipal ||
-            (mSheetPrincipal && aOther.mSheetPrincipal &&
-             NS_SUCCEEDED(mSheetPrincipal->Equals(aOther.mSheetPrincipal,
-                                                  &eq)) &&
-             eq));
-  }
-
-  bool operator!=(const nsCSSValueTokenStream& aOther) const
-  {
-    return !(*this == aOther);
-  }
-
-  NS_INLINE_DECL_REFCOUNTING(nsCSSValueTokenStream)
-
-  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
-
-  // The property that has mTokenStream as its unparsed specified value.
-  // When a variable reference is used in a shorthand property, a
-  // TokenStream value is stored as the specified value for each of its
-  // component longhand properties.
-  nsCSSPropertyID mPropertyID;
-
-  // The shorthand property that had a value with a variable reference,
-  // which caused the longhand property identified by mPropertyID to have
-  // a TokenStream value.
-  nsCSSPropertyID mShorthandPropertyID;
-
-  // The unparsed CSS corresponding to the specified value of the property.
-  // When the value of a shorthand property has a variable reference, the
-  // same mTokenStream value is used on each of the nsCSSValueTokenStream
-  // objects that will be set by parsing the shorthand.
-  nsString mTokenStream;
-
-  nsCOMPtr<nsIURI> mBaseURI;
-  nsCOMPtr<nsIURI> mSheetURI;
-  nsCOMPtr<nsIPrincipal> mSheetPrincipal;
-  // XXX Should store sheet here (see Bug 952338)
-  // mozilla::CSSStyleSheet* mSheet;
-  uint32_t mLineNumber;
-  uint32_t mLineOffset;
-  mozilla::SheetType mLevel;
-
-private:
-  nsCSSValueTokenStream(const nsCSSValueTokenStream& aOther) = delete;
-  nsCSSValueTokenStream& operator=(const nsCSSValueTokenStream& aOther) = delete;
-};
-
 class nsCSSValueFloatColor final {
 public:
   nsCSSValueFloatColor(float aComponent1, float aComponent2, float aComponent3,
                        float aAlpha)
     : mComponent1(aComponent1)
     , mComponent2(aComponent2)
     , mComponent3(aComponent3)
     , mAlpha(aAlpha)