Bug 1260651 part.38 Rename nsRangeStore to mozilla::RangeItem because the instances called 'item' in many places r?mccr8 draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 24 Jun 2016 14:44:14 +0900
changeset 385728 07c8b508d4cc23b12a622abc655343e899d634d7
parent 385727 bbe360841a0e74fdbb7c1b0e99271e1a1361f6b4
child 385729 a4082c294175bcdbbfdb63317fbcce684f833910
push id22582
push usermasayuki@d-toybox.com
push dateSat, 09 Jul 2016 03:13:39 +0000
reviewersmccr8
bugs1260651
milestone50.0a1
Bug 1260651 part.38 Rename nsRangeStore to mozilla::RangeItem because the instances called 'item' in many places r?mccr8 MozReview-Commit-ID: BUU44fpTNyW
editor/libeditor/DeleteNodeTransaction.cpp
editor/libeditor/SelectionState.cpp
editor/libeditor/SelectionState.h
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/DeleteNodeTransaction.cpp
+++ b/editor/libeditor/DeleteNodeTransaction.cpp
@@ -60,17 +60,17 @@ DeleteNodeTransaction::DoTransaction()
     return NS_OK;
   }
 
   // remember which child mNode was (by remembering which child was next);
   // mRefNode can be null
   mRefNode = mNode->GetNextSibling();
 
   // give range updater a chance.  SelAdjDeleteNode() needs to be called
-  // *before* we do the action, unlike some of the other nsRangeStore update
+  // *before* we do the action, unlike some of the other RangeItem update
   // methods.
   if (mRangeUpdater) {
     mRangeUpdater->SelAdjDeleteNode(mNode->AsDOMNode());
   }
 
   ErrorResult error;
   mParent->RemoveChild(*mNode, error);
   return error.StealNSResult();
--- a/editor/libeditor/SelectionState.cpp
+++ b/editor/libeditor/SelectionState.cpp
@@ -45,17 +45,17 @@ SelectionState::SaveSelection(Selection*
   MOZ_ASSERT(aSel);
   int32_t arrayCount = mArray.Length();
   int32_t rangeCount = aSel->RangeCount();
 
   // if we need more items in the array, new them
   if (arrayCount < rangeCount) {
     for (int32_t i = arrayCount; i < rangeCount; i++) {
       mArray.AppendElement();
-      mArray[i] = new nsRangeStore();
+      mArray[i] = new RangeItem();
     }
   } else if (arrayCount > rangeCount) {
     // else if we have too many, delete them
     for (int32_t i = arrayCount - 1; i >= rangeCount; i--) {
       mArray.RemoveElementAt(i);
     }
   }
 
@@ -149,29 +149,29 @@ using namespace mozilla::dom;
 nsRangeUpdater::nsRangeUpdater() : mArray(), mLock(false) {}
 
 nsRangeUpdater::~nsRangeUpdater()
 {
   // nothing to do, we don't own the items in our array.
 }
 
 void
-nsRangeUpdater::RegisterRangeItem(nsRangeStore *aRangeItem)
+nsRangeUpdater::RegisterRangeItem(RangeItem* aRangeItem)
 {
   if (!aRangeItem) return;
   if (mArray.Contains(aRangeItem))
   {
     NS_ERROR("tried to register an already registered range");
     return;  // don't register it again.  It would get doubly adjusted.
   }
   mArray.AppendElement(aRangeItem);
 }
 
 void
-nsRangeUpdater::DropRangeItem(nsRangeStore *aRangeItem)
+nsRangeUpdater::DropRangeItem(RangeItem* aRangeItem)
 {
   if (!aRangeItem) return;
   mArray.RemoveElement(aRangeItem);
 }
 
 nsresult
 nsRangeUpdater::RegisterSelectionState(SelectionState& aSelState)
 {
@@ -211,17 +211,17 @@ nsRangeUpdater::SelAdjCreateNode(nsINode
   }
   NS_ENSURE_TRUE(aParent, NS_ERROR_NULL_POINTER);
   uint32_t count = mArray.Length();
   if (!count) {
     return NS_OK;
   }
 
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == aParent && item->startOffset > aPosition) {
       item->startOffset++;
     }
     if (item->endNode == aParent && item->endOffset > aPosition) {
       item->endOffset++;
     }
@@ -261,17 +261,17 @@ nsRangeUpdater::SelAdjDeleteNode(nsINode
     return;
   }
 
   nsCOMPtr<nsINode> parent = aNode->GetParentNode();
   int32_t offset = parent ? parent->IndexOf(aNode) : -1;
 
   // check for range endpoints that are after aNode and in the same parent
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     MOZ_ASSERT(item);
 
     if (item->startNode == parent && item->startOffset > offset) {
       item->startOffset--;
     }
     if (item->endNode == parent && item->endOffset > offset) {
       item->endOffset--;
     }
@@ -331,17 +331,17 @@ nsRangeUpdater::SelAdjSplitNode(nsIConte
   int32_t offset = parent ? parent->IndexOf(&aOldRightNode) : -1;
 
   // first part is same as inserting aNewLeftnode
   nsresult result = SelAdjInsertNode(parent, offset - 1);
   NS_ENSURE_SUCCESS(result, result);
 
   // next step is to check for range enpoints inside aOldRightNode
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == &aOldRightNode) {
       if (item->startOffset > aOffset) {
         item->startOffset -= aOffset;
       } else {
         item->startNode = aNewLeftNode;
       }
@@ -369,17 +369,17 @@ nsRangeUpdater::SelAdjJoinNodes(nsINode&
     return NS_OK;
   }
   uint32_t count = mArray.Length();
   if (!count) {
     return NS_OK;
   }
 
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == &aParent) {
       // adjust start point in aParent
       if (item->startOffset > aOffset) {
         item->startOffset--;
       } else if (item->startOffset == aOffset) {
         // join keeps right hand node
@@ -427,17 +427,17 @@ nsRangeUpdater::SelAdjInsertText(Text& a
 
   uint32_t count = mArray.Length();
   if (!count) {
     return;
   }
 
   uint32_t len = aString.Length();
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     MOZ_ASSERT(item);
 
     if (item->startNode == &aTextNode && item->startOffset > aOffset) {
       item->startOffset += len;
     }
     if (item->endNode == &aTextNode && item->endOffset > aOffset) {
       item->endOffset += len;
     }
@@ -456,17 +456,17 @@ nsRangeUpdater::SelAdjDeleteText(nsICont
 
   uint32_t count = mArray.Length();
   if (!count) {
     return NS_OK;
   }
   NS_ENSURE_TRUE(aTextNode, NS_ERROR_NULL_POINTER);
 
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == aTextNode && item->startOffset > aOffset) {
       item->startOffset -= aLength;
       if (item->startOffset < 0) {
         item->startOffset = 0;
       }
     }
@@ -506,17 +506,17 @@ nsRangeUpdater::DidReplaceContainer(Elem
 
   NS_ENSURE_TRUE(aOriginalNode && aNewNode, NS_ERROR_NULL_POINTER);
   uint32_t count = mArray.Length();
   if (!count) {
     return NS_OK;
   }
 
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == aOriginalNode) {
       item->startNode = aNewNode;
     }
     if (item->endNode == aOriginalNode) {
       item->endNode = aNewNode;
     }
@@ -543,17 +543,17 @@ nsRangeUpdater::DidRemoveContainer(nsINo
 
   NS_ENSURE_TRUE(aNode && aParent, NS_ERROR_NULL_POINTER);
   uint32_t count = mArray.Length();
   if (!count) {
     return NS_OK;
   }
 
   for (uint32_t i = 0; i < count; i++) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     NS_ENSURE_TRUE(item, NS_ERROR_NULL_POINTER);
 
     if (item->startNode == aNode) {
       item->startNode = aParent;
       item->startOffset += aOffset;
     } else if (item->startNode == aParent && item->startOffset > aOffset) {
       item->startOffset += (int32_t)aNodeOrigLen - 1;
     }
@@ -608,17 +608,17 @@ nsRangeUpdater::DidMoveNode(nsINode* aOl
                             nsINode* aNewParent, int32_t aNewOffset)
 {
   MOZ_ASSERT(aOldParent);
   MOZ_ASSERT(aNewParent);
   NS_ENSURE_TRUE_VOID(mLock);
   mLock = false;
 
   for (uint32_t i = 0, count = mArray.Length(); i < count; ++i) {
-    nsRangeStore* item = mArray[i];
+    RangeItem* item = mArray[i];
     NS_ENSURE_TRUE_VOID(item);
 
     // like a delete in aOldParent
     if (item->startNode == aOldParent && item->startOffset > aOldOffset) {
       item->startOffset--;
     }
     if (item->endNode == aOldParent && item->endOffset > aOldOffset) {
       item->endOffset--;
@@ -629,43 +629,48 @@ nsRangeUpdater::DidMoveNode(nsINode* aOl
       item->startOffset++;
     }
     if (item->endNode == aNewParent && item->endOffset > aNewOffset) {
       item->endOffset++;
     }
   }
 }
 
-
+namespace mozilla {
 
-/***************************************************************************
- * helper class for SelectionState.  nsRangeStore stores range endpoints.
- */
+/******************************************************************************
+ * mozilla::RangeItem
+ *
+ * Helper struct for SelectionState.  This stores range endpoints.
+ ******************************************************************************/
 
-nsRangeStore::nsRangeStore()
-{
-}
-nsRangeStore::~nsRangeStore()
+RangeItem::RangeItem()
 {
 }
 
-NS_IMPL_CYCLE_COLLECTION(nsRangeStore, startNode, endNode)
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsRangeStore, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsRangeStore, Release)
+RangeItem::~RangeItem()
+{
+}
+
+NS_IMPL_CYCLE_COLLECTION(RangeItem, startNode, endNode)
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(RangeItem, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(RangeItem, Release)
 
 void
-nsRangeStore::StoreRange(nsRange* aRange)
+RangeItem::StoreRange(nsRange* aRange)
 {
   MOZ_ASSERT(aRange);
   startNode = aRange->GetStartParent();
   startOffset = aRange->StartOffset();
   endNode = aRange->GetEndParent();
   endOffset = aRange->EndOffset();
 }
 
 already_AddRefed<nsRange>
-nsRangeStore::GetRange()
+RangeItem::GetRange()
 {
   RefPtr<nsRange> range = new nsRange(startNode);
   nsresult res = range->Set(startNode, startOffset, endNode, endOffset);
   NS_ENSURE_SUCCESS(res, nullptr);
   return range.forget();
 }
+
+} // namespace mozilla
--- a/editor/libeditor/SelectionState.h
+++ b/editor/libeditor/SelectionState.h
@@ -16,62 +16,63 @@ class nsCycleCollectionTraversalCallback
 class nsIDOMCharacterData;
 class nsRange;
 class nsRangeUpdater;
 namespace mozilla {
 namespace dom {
 class Selection;
 class Text;
 } // namespace dom
-} // namespace mozilla
 
-/***************************************************************************
- * class for recording selection info.  stores selection as collection of
- * { {startnode, startoffset} , {endnode, endoffset} } tuples.  Can't store
- * ranges since dom gravity will possibly change the ranges.
+/**
+ * A helper struct for saving/setting ranges.
  */
-
-// first a helper struct for saving/setting ranges
-struct nsRangeStore final
+struct RangeItem final
 {
-  nsRangeStore();
+  RangeItem();
 
 private:
   // Private destructor, to discourage deletion outside of Release():
-  ~nsRangeStore();
+  ~RangeItem();
 
 public:
   void StoreRange(nsRange* aRange);
   already_AddRefed<nsRange> GetRange();
 
-  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsRangeStore)
-  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsRangeStore)
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(RangeItem)
+  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(RangeItem)
 
   nsCOMPtr<nsINode> startNode;
-  int32_t           startOffset;
+  int32_t startOffset;
   nsCOMPtr<nsINode> endNode;
-  int32_t           endOffset;
+  int32_t endOffset;
 };
 
-namespace mozilla {
+/**
+ * mozilla::SelectionState
+ *
+ * Class for recording selection info.  Stores selection as collection of
+ * { {startnode, startoffset} , {endnode, endoffset} } tuples.  Can't store
+ * ranges since dom gravity will possibly change the ranges.
+ */
 
 class SelectionState final
 {
 public:
   SelectionState();
   ~SelectionState();
 
   void SaveSelection(dom::Selection *aSel);
   nsresult RestoreSelection(dom::Selection* aSel);
   bool IsCollapsed();
   bool IsEqual(SelectionState *aSelState);
   void MakeEmpty();
   bool IsEmpty();
 private:
-  nsTArray<RefPtr<nsRangeStore>> mArray;
+  nsTArray<RefPtr<RangeItem>> mArray;
 
   friend class nsRangeUpdater;
   friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
                                           SelectionState&,
                                           const char*,
                                           uint32_t);
   friend void ImplCycleCollectionUnlink(SelectionState&);
 };
@@ -95,18 +96,18 @@ ImplCycleCollectionUnlink(SelectionState
 
 class nsRangeUpdater
 {
   public:
 
     nsRangeUpdater();
     ~nsRangeUpdater();
 
-    void RegisterRangeItem(nsRangeStore *aRangeItem);
-    void DropRangeItem(nsRangeStore *aRangeItem);
+    void RegisterRangeItem(mozilla::RangeItem* aRangeItem);
+    void DropRangeItem(mozilla::RangeItem* aRangeItem);
     nsresult RegisterSelectionState(mozilla::SelectionState& aSelState);
     nsresult DropSelectionState(mozilla::SelectionState& aSelState);
 
     // editor selection gravity routines.  Note that we can't always depend on
     // DOM Range gravity to do what we want to the "real" selection.  For instance,
     // if you move a node, that corresponds to deleting it and reinserting it.
     // DOM Range gravity will promote the selection out of the node on deletion,
     // which is not what you want if you know you are reinserting it.
@@ -144,17 +145,17 @@ class nsRangeUpdater
                      nsINode* aNewParent, int32_t aNewOffset);
   private:
     friend void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback&,
                                             nsRangeUpdater&,
                                             const char*,
                                             uint32_t);
     friend void ImplCycleCollectionUnlink(nsRangeUpdater& aField);
 
-    nsTArray<RefPtr<nsRangeStore> > mArray;
+    nsTArray<RefPtr<mozilla::RangeItem>> mArray;
     bool mLock;
 };
 
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
                             nsRangeUpdater& aField,
                             const char* aName,
                             uint32_t aFlags = 0)
@@ -176,41 +177,41 @@ ImplCycleCollectionUnlink(nsRangeUpdater
 class MOZ_STACK_CLASS nsAutoTrackDOMPoint
 {
   private:
     nsRangeUpdater &mRU;
     // Allow tracking either nsIDOMNode or nsINode until nsIDOMNode is gone
     nsCOMPtr<nsINode>* mNode;
     nsCOMPtr<nsIDOMNode>* mDOMNode;
     int32_t* mOffset;
-    RefPtr<nsRangeStore> mRangeItem;
+    RefPtr<mozilla::RangeItem> mRangeItem;
   public:
     nsAutoTrackDOMPoint(nsRangeUpdater &aRangeUpdater,
                         nsCOMPtr<nsINode>* aNode, int32_t* aOffset)
       : mRU(aRangeUpdater)
       , mNode(aNode)
       , mDOMNode(nullptr)
       , mOffset(aOffset)
     {
-      mRangeItem = new nsRangeStore();
+      mRangeItem = new mozilla::RangeItem();
       mRangeItem->startNode = *mNode;
       mRangeItem->endNode = *mNode;
       mRangeItem->startOffset = *mOffset;
       mRangeItem->endOffset = *mOffset;
       mRU.RegisterRangeItem(mRangeItem);
     }
 
     nsAutoTrackDOMPoint(nsRangeUpdater &aRangeUpdater,
                         nsCOMPtr<nsIDOMNode>* aNode, int32_t* aOffset)
       : mRU(aRangeUpdater)
       , mNode(nullptr)
       , mDOMNode(aNode)
       , mOffset(aOffset)
     {
-      mRangeItem = new nsRangeStore();
+      mRangeItem = new mozilla::RangeItem();
       mRangeItem->startNode = do_QueryInterface(*mDOMNode);
       mRangeItem->endNode = do_QueryInterface(*mDOMNode);
       mRangeItem->startOffset = *mOffset;
       mRangeItem->endOffset = *mOffset;
       mRU.RegisterRangeItem(mRangeItem);
     }
 
     ~nsAutoTrackDOMPoint()
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -192,17 +192,17 @@ nsHTMLEditRules::InitFields()
   mListenerEnabled = true;
   mReturnInEmptyLIKillsList = true;
   mDidDeleteSelection = false;
   mDidRangedDelete = false;
   mRestoreContentEditableCount = false;
   mUtilRange = nullptr;
   mJoinOffset = 0;
   mNewBlock = nullptr;
-  mRangeItem = new nsRangeStore();
+  mRangeItem = new RangeItem();
   // populate mCachedStyles
   mCachedStyles[0] = StyleCache(nsGkAtoms::b, EmptyString(), EmptyString());
   mCachedStyles[1] = StyleCache(nsGkAtoms::i, EmptyString(), EmptyString());
   mCachedStyles[2] = StyleCache(nsGkAtoms::u, EmptyString(), EmptyString());
   mCachedStyles[3] = StyleCache(nsGkAtoms::font, NS_LITERAL_STRING("face"), EmptyString());
   mCachedStyles[4] = StyleCache(nsGkAtoms::font, NS_LITERAL_STRING("size"), EmptyString());
   mCachedStyles[5] = StyleCache(nsGkAtoms::font, NS_LITERAL_STRING("color"), EmptyString());
   mCachedStyles[6] = StyleCache(nsGkAtoms::tt, EmptyString(), EmptyString());
@@ -5585,22 +5585,22 @@ nsHTMLEditRules::GetNodesForOperation(ns
       }
     }
   }
 
   // Bust up any inlines that cross our range endpoints, but only if we are
   // allowed to touch content.
 
   if (aTouchContent == TouchContent::yes) {
-    nsTArray<OwningNonNull<nsRangeStore>> rangeItemArray;
+    nsTArray<OwningNonNull<RangeItem>> rangeItemArray;
     rangeItemArray.AppendElements(rangeCount);
 
     // First register ranges for special editor gravity
     for (int32_t i = 0; i < rangeCount; i++) {
-      rangeItemArray[i] = new nsRangeStore();
+      rangeItemArray[i] = new RangeItem();
       rangeItemArray[i]->StoreRange(aArrayOfRanges[0]);
       mHTMLEditor->mRangeUpdater.RegisterRangeItem(rangeItemArray[i]);
       aArrayOfRanges.RemoveElementAt(0);
     }
     // Now bust up inlines.
     for (auto& item : Reversed(rangeItemArray)) {
       res = BustUpInlinesAtRangeEndpoints(*item);
       if (NS_FAILED(res)) {
@@ -5888,17 +5888,17 @@ nsHTMLEditRules::GetParagraphFormatNodes
   return NS_OK;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////
 // BustUpInlinesAtRangeEndpoints:
 //
 nsresult
-nsHTMLEditRules::BustUpInlinesAtRangeEndpoints(nsRangeStore &item)
+nsHTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& item)
 {
   bool isCollapsed = ((item.startNode == item.endNode) && (item.startOffset == item.endOffset));
 
   nsCOMPtr<nsIContent> endInline = GetHighestInlineParent(*item.endNode);
 
   // if we have inline parents above range endpoints, split them
   if (endInline && !isCollapsed)
   {
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -267,17 +267,17 @@ protected:
   nsresult GetListActionNodes(nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
                               EntireList aEntireList,
                               TouchContent aTouchContent = TouchContent::yes);
   void GetDefinitionListItemTypes(Element* aElement, bool* aDT, bool* aDD);
   nsresult GetParagraphFormatNodes(
       nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
       TouchContent aTouchContent = TouchContent::yes);
   void LookInsideDivBQandList(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
-  nsresult BustUpInlinesAtRangeEndpoints(nsRangeStore &inRange);
+  nsresult BustUpInlinesAtRangeEndpoints(mozilla::RangeItem& inRange);
   nsresult BustUpInlinesAtBRs(nsIContent& aNode,
                               nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes);
   nsIContent* GetHighestInlineParent(nsINode& aNode);
   void MakeTransitionList(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
                           nsTArray<bool>& aTransitionArray);
   nsresult RemoveBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray);
   nsresult ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
                            nsIAtom& aBlockTag);
@@ -337,14 +337,14 @@ protected:
   bool                    mListenerEnabled;
   bool                    mReturnInEmptyLIKillsList;
   bool                    mDidDeleteSelection;
   bool                    mDidRangedDelete;
   bool                    mRestoreContentEditableCount;
   RefPtr<nsRange>       mUtilRange;
   uint32_t                mJoinOffset;  // need to remember an int across willJoin/didJoin...
   nsCOMPtr<Element>       mNewBlock;
-  RefPtr<nsRangeStore>  mRangeItem;
+  RefPtr<mozilla::RangeItem> mRangeItem;
   StyleCache              mCachedStyles[SIZE_STYLE_TABLE];
 };
 
 #endif //nsHTMLEditRules_h__