Bug 1230034 part 2 - Constify aFrame parameters of frame property functions. r=dbaron
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 28 Jan 2016 14:23:59 +1100
changeset 326648 c6abdd91acbc65e9f0a818e1dec59c48a46d02f9
parent 326647 94d4c49590a052241f51572203504b0d5f8f4494
child 326649 6af8cff960690de19591697de8f2578963908bc0
push id10162
push useratolfsen@mozilla.com
push dateThu, 28 Jan 2016 10:52:36 +0000
reviewersdbaron
bugs1230034
milestone47.0a1
Bug 1230034 part 2 - Constify aFrame parameters of frame property functions. r=dbaron
layout/base/FrameLayerBuilder.cpp
layout/base/FrameLayerBuilder.h
layout/base/FramePropertyTable.cpp
layout/base/FramePropertyTable.h
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -229,17 +229,17 @@ FrameLayerBuilder::DisplayItemData::Begi
   }
 
   for (uint32_t i = 0; i < copy.Length(); i++) {
     RemoveFrame(copy[i]);
     mFrameListChanges.AppendElement(copy[i]);
   }
 }
 
-static nsIFrame* sDestroyedFrame = nullptr;
+static const nsIFrame* sDestroyedFrame = nullptr;
 FrameLayerBuilder::DisplayItemData::~DisplayItemData()
 {
   MOZ_COUNT_DTOR(FrameLayerBuilder::DisplayItemData);
   MOZ_RELEASE_ASSERT(mLayer);
   for (uint32_t i = 0; i < mFrameList.Length(); i++) {
     nsIFrame* frame = mFrameList[i];
     if (frame == sDestroyedFrame) {
       continue;
@@ -1704,17 +1704,17 @@ GetTranslationForPaintedLayer(PaintedLay
  * the DisplayItemData destructor. If the inner layer manager had any
  * items with the same frame, then we attempt to retrieve properties
  * from the deleted frame.
  *
  * Cache the destroyed frame pointer here so we can avoid crashing in this case.
  */
 
 /* static */ void
-FrameLayerBuilder::RemoveFrameFromLayerManager(nsIFrame* aFrame,
+FrameLayerBuilder::RemoveFrameFromLayerManager(const nsIFrame* aFrame,
                                                void* aPropertyValue)
 {
   MOZ_RELEASE_ASSERT(!sDestroyedFrame);
   sDestroyedFrame = aFrame;
   nsTArray<DisplayItemData*> *array =
     reinterpret_cast<nsTArray<DisplayItemData*>*>(aPropertyValue);
 
   // Hold a reference to all the items so that they don't get
--- a/layout/base/FrameLayerBuilder.h
+++ b/layout/base/FrameLayerBuilder.h
@@ -509,17 +509,17 @@ public:
     bool            mUsed;
     bool            mIsInvalid;
   };
 
 protected:
 
   friend class LayerManagerData;
 
-  static void RemoveFrameFromLayerManager(nsIFrame* aFrame, void* aPropertyValue);
+  static void RemoveFrameFromLayerManager(const nsIFrame* aFrame, void* aPropertyValue);
 
   /**
    * Given a frame and a display item key that uniquely identifies a
    * display item for the frame, find the layer that was last used to
    * render that display item. Returns null if there is no such layer.
    * This could be a dedicated layer for the display item, or a PaintedLayer
    * that renders many display items.
    */
--- a/layout/base/FramePropertyTable.cpp
+++ b/layout/base/FramePropertyTable.cpp
@@ -5,17 +5,18 @@
 
 #include "FramePropertyTable.h"
 
 #include "mozilla/MemoryReporting.h"
 
 namespace mozilla {
 
 void
-FramePropertyTable::Set(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
+FramePropertyTable::Set(const nsIFrame* aFrame,
+                        const FramePropertyDescriptor* aProperty,
                         void* aValue)
 {
   NS_ASSERTION(aFrame, "Null frame?");
   NS_ASSERTION(aProperty, "Null property?");
 
   if (mLastFrame != aFrame || !mLastEntry) {
     mLastFrame = aFrame;
     mLastEntry = mEntries.PutEntry(aFrame);
@@ -66,17 +67,17 @@ FramePropertyTable::Get(const nsIFrame* 
   NS_ASSERTION(aFrame, "Null frame?");
   NS_ASSERTION(aProperty, "Null property?");
 
   if (aFoundResult) {
     *aFoundResult = false;
   }
 
   if (mLastFrame != aFrame) {
-    mLastFrame = const_cast<nsIFrame*>(aFrame);
+    mLastFrame = aFrame;
     mLastEntry = mEntries.GetEntry(mLastFrame);
   }
   Entry* entry = mLastEntry;
   if (!entry)
     return nullptr;
 
   if (entry->mProp.mProperty == aProperty) {
     if (aFoundResult) {
@@ -98,17 +99,18 @@ FramePropertyTable::Get(const nsIFrame* 
   if (aFoundResult) {
     *aFoundResult = true;
   }
 
   return array->ElementAt(index).mValue;
 }
 
 void*
-FramePropertyTable::Remove(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
+FramePropertyTable::Remove(const nsIFrame* aFrame,
+                           const FramePropertyDescriptor* aProperty,
                            bool* aFoundResult)
 {
   NS_ASSERTION(aFrame, "Null frame?");
   NS_ASSERTION(aProperty, "Null property?");
 
   if (aFoundResult) {
     *aFoundResult = false;
   }
@@ -159,17 +161,18 @@ FramePropertyTable::Remove(nsIFrame* aFr
     array->~nsTArray<PropertyValue>();
     entry->mProp = pv;
   }
   
   return result;
 }
 
 void
-FramePropertyTable::Delete(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty)
+FramePropertyTable::Delete(const nsIFrame* aFrame,
+                           const FramePropertyDescriptor* aProperty)
 {
   NS_ASSERTION(aFrame, "Null frame?");
   NS_ASSERTION(aProperty, "Null property?");
 
   bool found;
   void* v = Remove(aFrame, aProperty, &found);
   if (found) {
     PropertyValue pv(aProperty, v);
@@ -188,17 +191,17 @@ FramePropertyTable::DeleteAllForEntry(En
   nsTArray<PropertyValue>* array = aEntry->mProp.ToArray();
   for (uint32_t i = 0; i < array->Length(); ++i) {
     array->ElementAt(i).DestroyValueFor(aEntry->GetKey());
   }
   array->~nsTArray<PropertyValue>();
 }
 
 void
-FramePropertyTable::DeleteAllFor(nsIFrame* aFrame)
+FramePropertyTable::DeleteAllFor(const nsIFrame* aFrame)
 {
   NS_ASSERTION(aFrame, "Null frame?");
 
   Entry* entry = mEntries.GetEntry(aFrame);
   if (!entry)
     return;
 
   if (mLastFrame == aFrame) {
--- a/layout/base/FramePropertyTable.h
+++ b/layout/base/FramePropertyTable.h
@@ -13,17 +13,17 @@
 
 class nsIFrame;
 
 namespace mozilla {
 
 struct FramePropertyDescriptor;
 
 typedef void (*FramePropertyDestructor)(void* aPropertyValue);
-typedef void (*FramePropertyDestructorWithFrame)(nsIFrame* aFrame,
+typedef void (*FramePropertyDestructorWithFrame)(const nsIFrame* aFrame,
                                                  void* aPropertyValue);
 
 /**
  * A pointer to a FramePropertyDescriptor serves as a unique property ID.
  * The FramePropertyDescriptor stores metadata about the property.
  * Currently the only metadata is a destructor function. The destructor
  * function is called on property values when they are overwritten or
  * deleted.
@@ -74,17 +74,17 @@ public:
   }
 
   /**
    * Set a property value on a frame. This requires one hashtable
    * lookup (using the frame as the key) and a linear search through
    * the properties of that frame. Any existing value for the property
    * is destroyed.
    */
-  void Set(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
+  void Set(const nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
            void* aValue);
   /**
    * Get a property value for a frame. This requires one hashtable
    * lookup (using the frame as the key) and a linear search through
    * the properties of that frame. If the frame has no such property,
    * returns null.
    * @param aFoundResult if non-null, receives a value 'true' iff
    * the frame has a value for the property. This lets callers
@@ -99,30 +99,30 @@ public:
    * the properties of that frame. The old property value is returned
    * (and not destroyed). If the frame has no such property,
    * returns null.
    * @param aFoundResult if non-null, receives a value 'true' iff
    * the frame had a value for the property. This lets callers
    * disambiguate a null result, which can mean 'no such property' or
    * 'property value is null'.
    */
-  void* Remove(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
+  void* Remove(const nsIFrame* aFrame, const FramePropertyDescriptor* aProperty,
                bool* aFoundResult = nullptr);
   /**
    * Remove and destroy a property value for a frame. This requires one
    * hashtable lookup (using the frame as the key) and a linear search
    * through the properties of that frame. If the frame has no such
    * property, nothing happens.
    */
-  void Delete(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty);
+  void Delete(const nsIFrame* aFrame, const FramePropertyDescriptor* aProperty);
   /**
    * Remove and destroy all property values for a frame. This requires one
    * hashtable lookup (using the frame as the key).
    */
-  void DeleteAllFor(nsIFrame* aFrame);
+  void DeleteAllFor(const nsIFrame* aFrame);
   /**
    * Remove and destroy all property values for all frames.
    */
   void DeleteAll();
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 protected:
@@ -137,17 +137,17 @@ protected:
 
     bool IsArray() { return !mProperty && mValue; }
     nsTArray<PropertyValue>* ToArray()
     {
       NS_ASSERTION(IsArray(), "Must be array");
       return reinterpret_cast<nsTArray<PropertyValue>*>(&mValue);
     }
 
-    void DestroyValueFor(nsIFrame* aFrame) {
+    void DestroyValueFor(const nsIFrame* aFrame) {
       if (mProperty->mDestructor) {
         mProperty->mDestructor(mValue);
       } else if (mProperty->mDestructorWithFrame) {
         mProperty->mDestructorWithFrame(aFrame, mValue);
       }
     }
 
     size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
@@ -184,46 +184,44 @@ protected:
       return a.mProperty == b;
     }
   };
 
   /**
    * Our hashtable entry. The key is an nsIFrame*, the value is a
    * PropertyValue representing one or more property/value pairs.
    */
-  class Entry : public nsPtrHashKey<nsIFrame>
+  class Entry : public nsPtrHashKey<const nsIFrame>
   {
   public:
-    explicit Entry(KeyTypePointer aKey) : nsPtrHashKey<nsIFrame>(aKey) {}
+    explicit Entry(KeyTypePointer aKey) : nsPtrHashKey<const nsIFrame>(aKey) {}
     Entry(const Entry &toCopy) :
-      nsPtrHashKey<nsIFrame>(toCopy), mProp(toCopy.mProp) {}
+      nsPtrHashKey<const nsIFrame>(toCopy), mProp(toCopy.mProp) {}
 
     size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
       return mProp.SizeOfExcludingThis(aMallocSizeOf);
     }
 
     PropertyValue mProp;
   };
 
   static void DeleteAllForEntry(Entry* aEntry);
 
   nsTHashtable<Entry> mEntries;
-  nsIFrame* mLastFrame;
+  const nsIFrame* mLastFrame;
   Entry* mLastEntry;
 };
 
 /**
  * This class encapsulates the properties of a frame.
  */
 class FrameProperties {
 public:
-  FrameProperties(FramePropertyTable* aTable, nsIFrame* aFrame)
+  FrameProperties(FramePropertyTable* aTable, const nsIFrame* aFrame)
     : mTable(aTable), mFrame(aFrame) {}
-  FrameProperties(FramePropertyTable* aTable, const nsIFrame* aFrame)
-    : mTable(aTable), mFrame(const_cast<nsIFrame*>(aFrame)) {}
 
   void Set(const FramePropertyDescriptor* aProperty, void* aValue) const
   {
     mTable->Set(mFrame, aProperty, aValue);
   }
   void* Get(const FramePropertyDescriptor* aProperty,
             bool* aFoundResult = nullptr) const
   {
@@ -236,14 +234,14 @@ public:
   }
   void Delete(const FramePropertyDescriptor* aProperty)
   {
     mTable->Delete(mFrame, aProperty);
   }
 
 private:
   FramePropertyTable* mTable;
-  nsIFrame* mFrame;
+  const nsIFrame* mFrame;
 };
 
 } // namespace mozilla
 
 #endif /* FRAMEPROPERTYTABLE_H_ */