Bug 1260651 part.35 Move PorpItem and TypeInState from global namespace to mozilla namespace r=mccr8 draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 08 Jul 2016 11:51:46 +0900
changeset 385867 c1eb348713dc2241293f86b99f97931d37faed5f
parent 385866 dba84654da6583cfefafefb140acc6f685c56754
child 385868 426242e99cc2134436e7d5f85919c0f0fda0dc9d
push id22587
push usermasayuki@d-toybox.com
push dateSat, 09 Jul 2016 06:59:31 +0000
reviewersmccr8
bugs1260651
milestone50.0a1
Bug 1260651 part.35 Move PorpItem and TypeInState from global namespace to mozilla namespace r=mccr8 Moving PropItem and TypeInState into mozilla namespace. I.e., these names are: PropItem -> mozilla::PropItem TypeInState -> mozilla::TypeInState Although, there might be better names for them. They are too general names. MozReview-Commit-ID: By9CX1KlAaU
editor/libeditor/TypeInState.cpp
editor/libeditor/TypeInState.h
editor/libeditor/nsHTMLEditRules.h
editor/libeditor/nsHTMLEditor.h
--- a/editor/libeditor/TypeInState.cpp
+++ b/editor/libeditor/TypeInState.cpp
@@ -18,40 +18,35 @@
 #include "nsISupportsBase.h"
 #include "nsISupportsImpl.h"
 #include "nsReadableUtils.h"
 #include "nsStringFwd.h"
 
 class nsIAtom;
 class nsIDOMDocument;
 
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
+
+using namespace dom;
 
 /********************************************************************
- *                     XPCOM cruft
+ * mozilla::TypeInState
  *******************************************************************/
 
 NS_IMPL_CYCLE_COLLECTION(TypeInState, mLastSelectionContainer)
 NS_IMPL_CYCLE_COLLECTING_ADDREF(TypeInState)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(TypeInState)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TypeInState)
   NS_INTERFACE_MAP_ENTRY(nsISelectionListener)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
-/********************************************************************
- *                   public methods
- *******************************************************************/
-
-TypeInState::TypeInState() :
- mSetArray()
-,mClearedArray()
-,mRelativeFontSize(0)
-,mLastSelectionOffset(0)
+TypeInState::TypeInState()
+  : mRelativeFontSize(0)
+  , mLastSelectionOffset(0)
 {
   Reset();
 }
 
 TypeInState::~TypeInState()
 {
   // Call Reset() to release any data that may be in
   // mClearedArray and mSetArray.
@@ -67,17 +62,20 @@ TypeInState::UpdateSelState(Selection* a
   if (!aSelection->Collapsed()) {
     return NS_OK;
   }
 
   return nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(mLastSelectionContainer), &mLastSelectionOffset);
 }
 
 
-NS_IMETHODIMP TypeInState::NotifySelectionChanged(nsIDOMDocument *, nsISelection *aSelection, int16_t)
+NS_IMETHODIMP
+TypeInState::NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
+                                    nsISelection* aSelection,
+                                    int16_t aReason)
 {
   // XXX: Selection currently generates bogus selection changed notifications
   // XXX: (bug 140303). It can notify us when the selection hasn't actually
   // XXX: changed, and it notifies us more than once for the same change.
   // XXX:
   // XXX: The following code attempts to work around the bogus notifications,
   // XXX: and should probably be removed once bug 140303 is fixed.
   // XXX:
@@ -114,31 +112,33 @@ NS_IMETHODIMP TypeInState::NotifySelecti
       mLastSelectionOffset = 0;
     }
   }
 
   Reset();
   return NS_OK;
 }
 
-void TypeInState::Reset()
+void
+TypeInState::Reset()
 {
   for(uint32_t i = 0, n = mClearedArray.Length(); i < n; i++) {
     delete mClearedArray[i];
   }
   mClearedArray.Clear();
   for(uint32_t i = 0, n = mSetArray.Length(); i < n; i++) {
     delete mSetArray[i];
   }
   mSetArray.Clear();
 }
 
 
 void
-TypeInState::SetProp(nsIAtom* aProp, const nsAString& aAttr,
+TypeInState::SetProp(nsIAtom* aProp,
+                     const nsAString& aAttr,
                      const nsAString& aValue)
 {
   // special case for big/small, these nest
   if (nsGkAtoms::big == aProp) {
     mRelativeFontSize++;
     return;
   }
   if (nsGkAtoms::small == aProp) {
@@ -164,17 +164,18 @@ TypeInState::SetProp(nsIAtom* aProp, con
 void
 TypeInState::ClearAllProps()
 {
   // null prop means "all" props
   ClearProp(nullptr, EmptyString());
 }
 
 void
-TypeInState::ClearProp(nsIAtom* aProp, const nsAString& aAttr)
+TypeInState::ClearProp(nsIAtom* aProp,
+                       const nsAString& aAttr)
 {
   // if it's already cleared we are done
   if (IsPropCleared(aProp, aAttr)) {
     return;
   }
 
   // make a new propitem
   PropItem* item = new PropItem(aProp, aAttr, EmptyString());
@@ -182,74 +183,77 @@ TypeInState::ClearProp(nsIAtom* aProp, c
   // remove it from the list of set properties, if we have a match
   RemovePropFromSetList(aProp, aAttr);
 
   // add it to the list of cleared properties
   mClearedArray.AppendElement(item);
 }
 
 
-/***************************************************************************
- *    TakeClearProperty: hands back next property item on the clear list.
- *                       caller assumes ownership of PropItem and must delete it.
+/**
+ * TakeClearProperty() hands back next property item on the clear list.
+ * Caller assumes ownership of PropItem and must delete it.
  */
 PropItem*
 TypeInState::TakeClearProperty()
 {
   uint32_t count = mClearedArray.Length();
   if (!count) {
     return nullptr;
   }
 
   --count; // indices are zero based
   PropItem* propItem = mClearedArray[count];
   mClearedArray.RemoveElementAt(count);
   return propItem;
 }
 
-/***************************************************************************
- *    TakeSetProperty: hands back next poroperty item on the set list.
- *                     caller assumes ownership of PropItem and must delete it.
+/**
+ * TakeSetProperty() hands back next poroperty item on the set list.
+ * Caller assumes ownership of PropItem and must delete it.
  */
 PropItem*
 TypeInState::TakeSetProperty()
 {
   uint32_t count = mSetArray.Length();
   if (!count) {
     return nullptr;
   }
   count--; // indices are zero based
   PropItem* propItem = mSetArray[count];
   mSetArray.RemoveElementAt(count);
   return propItem;
 }
 
-//**************************************************************************
-//    TakeRelativeFontSize: hands back relative font value, which is then
-//                          cleared out.
+/**
+ * TakeRelativeFontSize() hands back relative font value, which is then
+ * cleared out.
+ */
 int32_t
 TypeInState::TakeRelativeFontSize()
 {
   int32_t relSize = mRelativeFontSize;
   mRelativeFontSize = 0;
   return relSize;
 }
 
 void
-TypeInState::GetTypingState(bool &isSet, bool &theSetting, nsIAtom *aProp)
+TypeInState::GetTypingState(bool& isSet,
+                            bool& theSetting,
+                            nsIAtom* aProp)
 {
   GetTypingState(isSet, theSetting, aProp, EmptyString(), nullptr);
 }
 
 void
-TypeInState::GetTypingState(bool &isSet,
-                            bool &theSetting,
-                            nsIAtom *aProp,
-                            const nsString &aAttr,
-                            nsString *aValue)
+TypeInState::GetTypingState(bool& isSet,
+                            bool& theSetting,
+                            nsIAtom* aProp,
+                            const nsString& aAttr,
+                            nsString* aValue)
 {
   if (IsPropSet(aProp, aAttr, aValue))
   {
     isSet = true;
     theSetting = true;
   }
   else if (IsPropCleared(aProp, aAttr))
   {
@@ -257,24 +261,19 @@ TypeInState::GetTypingState(bool &isSet,
     theSetting = false;
   }
   else
   {
     isSet = false;
   }
 }
 
-
-
-/********************************************************************
- *                   protected methods
- *******************************************************************/
-
 void
-TypeInState::RemovePropFromSetList(nsIAtom* aProp, const nsAString& aAttr)
+TypeInState::RemovePropFromSetList(nsIAtom* aProp,
+                                   const nsAString& aAttr)
 {
   int32_t index;
   if (!aProp)
   {
     // clear _all_ props
     for(uint32_t i = 0, n = mSetArray.Length(); i < n; i++) {
       delete mSetArray[i];
     }
@@ -285,40 +284,43 @@ TypeInState::RemovePropFromSetList(nsIAt
   {
     delete mSetArray[index];
     mSetArray.RemoveElementAt(index);
   }
 }
 
 
 void
-TypeInState::RemovePropFromClearedList(nsIAtom* aProp, const nsAString& aAttr)
+TypeInState::RemovePropFromClearedList(nsIAtom* aProp,
+                                       const nsAString& aAttr)
 {
   int32_t index;
   if (FindPropInList(aProp, aAttr, nullptr, mClearedArray, index))
   {
     delete mClearedArray[index];
     mClearedArray.RemoveElementAt(index);
   }
 }
 
 
-bool TypeInState::IsPropSet(nsIAtom *aProp,
-                            const nsAString& aAttr,
-                            nsAString* outValue)
+bool
+TypeInState::IsPropSet(nsIAtom* aProp,
+                       const nsAString& aAttr,
+                       nsAString* outValue)
 {
   int32_t i;
   return IsPropSet(aProp, aAttr, outValue, i);
 }
 
 
-bool TypeInState::IsPropSet(nsIAtom* aProp,
-                            const nsAString& aAttr,
-                            nsAString* outValue,
-                            int32_t& outIndex)
+bool
+TypeInState::IsPropSet(nsIAtom* aProp,
+                       const nsAString& aAttr,
+                       nsAString* outValue,
+                       int32_t& outIndex)
 {
   // linear search.  list should be short.
   uint32_t i, count = mSetArray.Length();
   for (i=0; i<count; i++)
   {
     PropItem *item = mSetArray[i];
     if ( (item->tag == aProp) &&
          (item->attr == aAttr) )
@@ -327,44 +329,47 @@ bool TypeInState::IsPropSet(nsIAtom* aPr
       outIndex = i;
       return true;
     }
   }
   return false;
 }
 
 
-bool TypeInState::IsPropCleared(nsIAtom* aProp,
-                                const nsAString& aAttr)
+bool
+TypeInState::IsPropCleared(nsIAtom* aProp,
+                           const nsAString& aAttr)
 {
   int32_t i;
   return IsPropCleared(aProp, aAttr, i);
 }
 
 
-bool TypeInState::IsPropCleared(nsIAtom* aProp,
-                                const nsAString& aAttr,
-                                int32_t& outIndex)
+bool
+TypeInState::IsPropCleared(nsIAtom* aProp,
+                           const nsAString& aAttr,
+                           int32_t& outIndex)
 {
   if (FindPropInList(aProp, aAttr, nullptr, mClearedArray, outIndex))
     return true;
   if (FindPropInList(0, EmptyString(), nullptr, mClearedArray, outIndex))
   {
     // special case for all props cleared
     outIndex = -1;
     return true;
   }
   return false;
 }
 
-bool TypeInState::FindPropInList(nsIAtom *aProp,
-                                   const nsAString &aAttr,
-                                   nsAString *outValue,
-                                   nsTArray<PropItem*> &aList,
-                                   int32_t &outIndex)
+bool
+TypeInState::FindPropInList(nsIAtom* aProp,
+                            const nsAString& aAttr,
+                            nsAString* outValue,
+                            nsTArray<PropItem*>& aList,
+                            int32_t& outIndex)
 {
   // linear search.  list should be short.
   uint32_t i, count = aList.Length();
   for (i=0; i<count; i++)
   {
     PropItem *item = aList[i];
     if ( (item->tag == aProp) &&
          (item->attr == aAttr) )
@@ -372,34 +377,34 @@ bool TypeInState::FindPropInList(nsIAtom
       if (outValue) *outValue = item->value;
       outIndex = i;
       return true;
     }
   }
   return false;
 }
 
-
-
 /********************************************************************
- *    PropItem: helper struct for TypeInState
+ * mozilla::PropItem: helper struct for mozilla::TypeInState
  *******************************************************************/
 
-PropItem::PropItem() :
- tag(nullptr)
-,attr()
-,value()
+PropItem::PropItem()
+  : tag(nullptr)
 {
   MOZ_COUNT_CTOR(PropItem);
 }
 
-PropItem::PropItem(nsIAtom *aTag, const nsAString &aAttr, const nsAString &aValue) :
- tag(aTag)
-,attr(aAttr)
-,value(aValue)
+PropItem::PropItem(nsIAtom* aTag,
+                   const nsAString& aAttr,
+                   const nsAString &aValue)
+  : tag(aTag)
+  , attr(aAttr)
+  , value(aValue)
 {
   MOZ_COUNT_CTOR(PropItem);
 }
 
 PropItem::~PropItem()
 {
   MOZ_COUNT_DTOR(PropItem);
 }
+
+} // namespace mozilla
--- a/editor/libeditor/TypeInState.h
+++ b/editor/libeditor/TypeInState.h
@@ -1,104 +1,111 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#ifndef TypeInState_h__
-#define TypeInState_h__
+#ifndef TypeInState_h
+#define TypeInState_h
 
 #include "nsCOMPtr.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsISelectionListener.h"
 #include "nsISupportsImpl.h"
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nscore.h"
 
 // Workaround for windows headers
 #ifdef SetProp
 #undef SetProp
 #endif
 
+class nsHTMLEditRules;
 class nsIAtom;
 class nsIDOMNode;
+
 namespace mozilla {
+
 namespace dom {
 class Selection;
 } // namespace dom
-} // namespace mozilla
 
 struct PropItem
 {
-  nsIAtom *tag;
+  nsIAtom* tag;
   nsString attr;
   nsString value;
 
   PropItem();
-  PropItem(nsIAtom *aTag, const nsAString &aAttr, const nsAString &aValue);
+  PropItem(nsIAtom* aTag, const nsAString& aAttr, const nsAString& aValue);
   ~PropItem();
 };
 
-class TypeInState : public nsISelectionListener
+class TypeInState final : public nsISelectionListener
 {
 public:
-
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS(TypeInState)
 
   TypeInState();
   void Reset();
 
-  nsresult UpdateSelState(mozilla::dom::Selection* aSelection);
+  nsresult UpdateSelState(dom::Selection* aSelection);
 
   // nsISelectionListener
   NS_DECL_NSISELECTIONLISTENER
 
   void SetProp(nsIAtom* aProp, const nsAString& aAttr, const nsAString& aValue);
 
   void ClearAllProps();
   void ClearProp(nsIAtom* aProp, const nsAString& aAttr);
 
-  //**************************************************************************
-  //    TakeClearProperty: hands back next property item on the clear list.
-  //                       caller assumes ownership of PropItem and must delete it.
+  /**
+   * TakeClearProperty() hands back next property item on the clear list.
+   * Caller assumes ownership of PropItem and must delete it.
+   */
   PropItem* TakeClearProperty();
 
-  //**************************************************************************
-  //    TakeSetProperty: hands back next property item on the set list.
-  //                     caller assumes ownership of PropItem and must delete it.
+  /**
+   * TakeSetProperty() hands back next property item on the set list.
+   * Caller assumes ownership of PropItem and must delete it.
+   */
   PropItem* TakeSetProperty();
 
-  //**************************************************************************
-  //    TakeRelativeFontSize: hands back relative font value, which is then
-  //                          cleared out.
+  /**
+   * TakeRelativeFontSize() hands back relative font value, which is then
+   * cleared out.
+   */
   int32_t TakeRelativeFontSize();
 
-  void GetTypingState(bool &isSet, bool &theSetting, nsIAtom *aProp);
-  void GetTypingState(bool &isSet, bool &theSetting, nsIAtom *aProp,
-                      const nsString &aAttr, nsString* outValue);
+  void GetTypingState(bool& isSet, bool& theSetting, nsIAtom* aProp);
+  void GetTypingState(bool& isSet, bool& theSetting, nsIAtom* aProp,
+                      const nsString& aAttr, nsString* outValue);
 
-  static   bool FindPropInList(nsIAtom *aProp, const nsAString &aAttr, nsAString *outValue, nsTArray<PropItem*> &aList, int32_t &outIndex);
+  static bool FindPropInList(nsIAtom* aProp, const nsAString& aAttr,
+                             nsAString* outValue, nsTArray<PropItem*>& aList,
+                             int32_t& outIndex);
 
 protected:
   virtual ~TypeInState();
 
   void RemovePropFromSetList(nsIAtom* aProp, const nsAString& aAttr);
   void RemovePropFromClearedList(nsIAtom* aProp, const nsAString& aAttr);
   bool IsPropSet(nsIAtom* aProp, const nsAString& aAttr, nsAString* outValue);
-  bool IsPropSet(nsIAtom* aProp, const nsAString& aAttr, nsAString* outValue, int32_t& outIndex);
+  bool IsPropSet(nsIAtom* aProp, const nsAString& aAttr, nsAString* outValue,
+                 int32_t& outIndex);
   bool IsPropCleared(nsIAtom* aProp, const nsAString& aAttr);
   bool IsPropCleared(nsIAtom* aProp, const nsAString& aAttr, int32_t& outIndex);
 
   nsTArray<PropItem*> mSetArray;
   nsTArray<PropItem*> mClearedArray;
   int32_t mRelativeFontSize;
   nsCOMPtr<nsIDOMNode> mLastSelectionContainer;
   int32_t mLastSelectionOffset;
 
   friend class nsHTMLEditRules;
 };
 
-
+} // namespace mozilla
 
-#endif  // TypeInState_h__
+#endif  // #ifndef TypeInState_h
 
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -32,17 +32,17 @@ class nsRulesInfo;
 namespace mozilla {
 struct EditorDOMPoint;
 namespace dom {
 class Element;
 class Selection;
 } // namespace dom
 } // namespace mozilla
 
-struct StyleCache : public PropItem
+struct StyleCache : public mozilla::PropItem
 {
   bool mPresent;
 
   StyleCache() : PropItem(), mPresent(false) {
     MOZ_COUNT_CTOR(StyleCache);
   }
 
   StyleCache(nsIAtom *aTag, const nsAString &aAttr, const nsAString &aValue) :
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -41,25 +41,25 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/StyleSheetHandle.h"
 
 class nsDocumentFragment;
 class nsIDOMKeyEvent;
 class nsITransferable;
 class nsIClipboard;
-class TypeInState;
 class nsIContentFilter;
 class nsILinkHandler;
 class nsTableWrapperFrame;
 class nsIDOMRange;
 class nsRange;
-struct PropItem;
 
 namespace mozilla {
+class TypeInState;
+struct PropItem;
 template<class T> class OwningNonNull;
 namespace dom {
 class BlobImpl;
 class DocumentFragment;
 } // namespace dom
 namespace widget {
 struct IMEState;
 } // namespace widget
@@ -779,17 +779,17 @@ protected:
 
   void SetElementPosition(Element& aElement, int32_t aX, int32_t aY);
 
 // Data members
 protected:
 
   nsTArray<OwningNonNull<nsIContentFilter>> mContentFilters;
 
-  RefPtr<TypeInState>        mTypeInState;
+  RefPtr<mozilla::TypeInState> mTypeInState;
 
   bool mCRInParagraphCreatesParagraph;
 
   bool mCSSAware;
   nsAutoPtr<nsHTMLCSSUtils> mHTMLCSSUtils;
 
   // Used by GetFirstSelectedCell and GetNextSelectedCell
   int32_t  mSelectedCellIndex;
@@ -797,17 +797,17 @@ protected:
   nsString mLastStyleSheetURL;
   nsString mLastOverrideStyleSheetURL;
 
   // Maintain a list of associated style sheets and their urls.
   nsTArray<nsString> mStyleSheetURLs;
   nsTArray<mozilla::StyleSheetHandle::RefPtr> mStyleSheets;
 
   // an array for holding default style settings
-  nsTArray<PropItem*> mDefaultStyles;
+  nsTArray<mozilla::PropItem*> mDefaultStyles;
 
 protected:
 
   /* ANONYMOUS UTILS */
   void     RemoveListenerAndDeleteRef(const nsAString& aEvent,
                                       nsIDOMEventListener* aListener,
                                       bool aUseCapture,
                                       Element* aElement,