Bug 1211365 - Remove NS_IMPL_STATE_UTILITIES. r=mtseng
authorTing-Yu Lin <tlin@mozilla.com>
Mon, 05 Oct 2015 16:52:29 +0800
changeset 266251 a3654a2a0d28a7061192ae448bebbe335b064fda
parent 266250 2bde155634dcdaf7f485cf69073d6b761e257894
child 266252 13045de2414d2df6323281fe752c423f78ab523f
push id29484
push userkwierso@gmail.com
push dateTue, 06 Oct 2015 18:28:09 +0000
treeherdermozilla-central@2722b65059df [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmtseng
bugs1211365
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1211365 - Remove NS_IMPL_STATE_UTILITIES. r=mtseng This macro was used to implement Name() and Singleton() for state classes. Instead of enforcing the state class to be a singleton, we can implement singleton pattern in MOZ_IMPL_STATE_CLASS_GETTER directly.
layout/base/AccessibleCaretEventHub.cpp
layout/base/AccessibleCaretEventHub.h
--- a/layout/base/AccessibleCaretEventHub.cpp
+++ b/layout/base/AccessibleCaretEventHub.cpp
@@ -35,17 +35,17 @@ NS_IMPL_ISUPPORTS(AccessibleCaretEventHu
 
 // -----------------------------------------------------------------------------
 // NoActionState
 //
 class AccessibleCaretEventHub::NoActionState
   : public AccessibleCaretEventHub::State
 {
 public:
-  NS_IMPL_STATE_UTILITIES(NoActionState)
+  virtual const char* Name() const override { return "NoActionState"; }
 
   virtual nsEventStatus OnPress(AccessibleCaretEventHub* aContext,
                                 const nsPoint& aPoint,
                                 int32_t aTouchId) override
   {
     nsEventStatus rv = nsEventStatus_eIgnore;
 
     if (NS_SUCCEEDED(aContext->mManager->PressCaret(aPoint))) {
@@ -99,17 +99,17 @@ public:
 
 // -----------------------------------------------------------------------------
 // PressCaretState: Always consume the event since we've pressed on the caret.
 //
 class AccessibleCaretEventHub::PressCaretState
   : public AccessibleCaretEventHub::State
 {
 public:
-  NS_IMPL_STATE_UTILITIES(PressCaretState)
+  virtual const char* Name() const override { return "PressCaretState"; }
 
   virtual nsEventStatus OnMove(AccessibleCaretEventHub* aContext,
                                const nsPoint& aPoint) override
   {
     if (aContext->MoveDistanceIsLarge(aPoint)) {
       if (NS_SUCCEEDED(aContext->mManager->DragCaret(aPoint))) {
         aContext->SetState(aContext->DragCaretState());
       }
@@ -136,17 +136,17 @@ public:
 
 // -----------------------------------------------------------------------------
 // DragCaretState: Always consume the event since we've pressed on the caret.
 //
 class AccessibleCaretEventHub::DragCaretState
   : public AccessibleCaretEventHub::State
 {
 public:
-  NS_IMPL_STATE_UTILITIES(DragCaretState)
+  virtual const char* Name() const override { return "DragCaretState"; }
 
   virtual nsEventStatus OnMove(AccessibleCaretEventHub* aContext,
                                const nsPoint& aPoint) override
   {
     aContext->mManager->DragCaret(aPoint);
 
     return nsEventStatus_eConsumeNoDefault;
   }
@@ -162,17 +162,17 @@ public:
 
 // -----------------------------------------------------------------------------
 // PressNoCaretState
 //
 class AccessibleCaretEventHub::PressNoCaretState
   : public AccessibleCaretEventHub::State
 {
 public:
-  NS_IMPL_STATE_UTILITIES(PressNoCaretState)
+  virtual const char* Name() const override { return "PressNoCaretState"; }
 
   virtual nsEventStatus OnMove(AccessibleCaretEventHub* aContext,
                                const nsPoint& aPoint) override
   {
     if (aContext->MoveDistanceIsLarge(aPoint)) {
       aContext->SetState(aContext->NoActionState());
     }
 
@@ -234,17 +234,17 @@ public:
 
 // -----------------------------------------------------------------------------
 // ScrollState
 //
 class AccessibleCaretEventHub::ScrollState
   : public AccessibleCaretEventHub::State
 {
 public:
-  NS_IMPL_STATE_UTILITIES(ScrollState)
+  virtual const char* Name() const override { return "ScrollState"; }
 
   virtual void OnScrollEnd(AccessibleCaretEventHub* aContext) override
   {
     aContext->SetState(aContext->PostScrollState());
   }
 
   virtual void OnBlur(AccessibleCaretEventHub* aContext,
                       bool aIsLeavingDocument) override
@@ -259,17 +259,17 @@ public:
 // -----------------------------------------------------------------------------
 // PostScrollState: In this state, we are waiting for another APZ start, press
 // event, or momentum wheel scroll.
 //
 class AccessibleCaretEventHub::PostScrollState
   : public AccessibleCaretEventHub::State
 {
 public:
-  NS_IMPL_STATE_UTILITIES(PostScrollState)
+  virtual const char* Name() const override { return "PostScrollState"; }
 
   virtual nsEventStatus OnPress(AccessibleCaretEventHub* aContext,
                                 const nsPoint& aPoint,
                                 int32_t aTouchId) override
   {
     aContext->mManager->OnScrollEnd();
     aContext->SetState(aContext->NoActionState());
 
@@ -316,17 +316,17 @@ public:
 
 // -----------------------------------------------------------------------------
 // LongTapState
 //
 class AccessibleCaretEventHub::LongTapState
   : public AccessibleCaretEventHub::State
 {
 public:
-  NS_IMPL_STATE_UTILITIES(LongTapState)
+  virtual const char* Name() const override { return "LongTapState"; }
 
   virtual nsEventStatus OnLongTap(AccessibleCaretEventHub* aContext,
                                   const nsPoint& aPoint) override
   {
     nsEventStatus rv = nsEventStatus_eIgnore;
 
     if (NS_SUCCEEDED(aContext->mManager->SelectWordOrShortcut(aPoint))) {
       rv = nsEventStatus_eConsumeNoDefault;
--- a/layout/base/AccessibleCaretEventHub.h
+++ b/layout/base/AccessibleCaretEventHub.h
@@ -89,17 +89,18 @@ protected:
 
 #define MOZ_DECL_STATE_CLASS_GETTER(aClassName)                                \
   class aClassName;                                                            \
   static State* aClassName();
 
 #define MOZ_IMPL_STATE_CLASS_GETTER(aClassName)                                \
   AccessibleCaretEventHub::State* AccessibleCaretEventHub::aClassName()        \
   {                                                                            \
-    return AccessibleCaretEventHub::aClassName::Singleton();                   \
+    static class aClassName singleton;                                         \
+    return &singleton;                                                         \
   }
 
   // Concrete state getters
   MOZ_DECL_STATE_CLASS_GETTER(NoActionState)
   MOZ_DECL_STATE_CLASS_GETTER(PressCaretState)
   MOZ_DECL_STATE_CLASS_GETTER(DragCaretState)
   MOZ_DECL_STATE_CLASS_GETTER(PressNoCaretState)
   MOZ_DECL_STATE_CLASS_GETTER(ScrollState)
@@ -164,24 +165,16 @@ protected:
 // -----------------------------------------------------------------------------
 // The base class for concrete states. A concrete state should inherit from this
 // class, and override the methods to handle the events or callbacks. A concrete
 // state is also responsible for transforming itself to the next concrete state.
 //
 class AccessibleCaretEventHub::State
 {
 public:
-#define NS_IMPL_STATE_UTILITIES(aClassName)                                    \
-  virtual const char* Name() const override { return #aClassName; }            \
-  static aClassName* Singleton()                                               \
-  {                                                                            \
-    static aClassName singleton;                                               \
-    return &singleton;                                                         \
-  }
-
   virtual const char* Name() const { return ""; }
 
   virtual nsEventStatus OnPress(AccessibleCaretEventHub* aContext,
                                 const nsPoint& aPoint, int32_t aTouchId)
   {
     return nsEventStatus_eIgnore;
   }