Bug 1204872 - Prettify enum class printing. r=roc
authorTing-Yu Lin <tlin@mozilla.com>
Sat, 19 Sep 2015 01:05:19 +0800
changeset 297606 51c8dca62df70a3d9de67bc4be6e3d10b2e8cc11
parent 297605 ac5e6b9eb56ac1f9f6b70a84586889f0e9854b6c
child 297607 0a3148919d902c36e92633cf3784d6aa5909335e
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1204872
milestone43.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 1204872 - Prettify enum class printing. r=roc Provide operator<< functions so that gtest can use them to print enum classes.
layout/base/AccessibleCaret.cpp
layout/base/AccessibleCaret.h
layout/base/AccessibleCaretManager.cpp
layout/base/AccessibleCaretManager.h
--- a/layout/base/AccessibleCaret.cpp
+++ b/layout/base/AccessibleCaret.cpp
@@ -27,34 +27,45 @@ using namespace dom;
 
 NS_IMPL_ISUPPORTS(AccessibleCaret::DummyTouchListener, nsIDOMEventListener)
 
 float AccessibleCaret::sWidth = 0.0f;
 float AccessibleCaret::sHeight = 0.0f;
 float AccessibleCaret::sMarginLeft = 0.0f;
 float AccessibleCaret::sBarWidth = 0.0f;
 
+#define AC_PROCESS_ENUM_TO_STREAM(e) case(e): aStream << #e; break;
 std::ostream&
 operator<<(std::ostream& aStream, const AccessibleCaret::Appearance& aAppearance)
 {
   using Appearance = AccessibleCaret::Appearance;
-
-#define AC_PROCESS_APPEARANCE_TO_STREAM(e) case(e): aStream << #e; break;
   switch (aAppearance) {
-    AC_PROCESS_APPEARANCE_TO_STREAM(Appearance::None);
-    AC_PROCESS_APPEARANCE_TO_STREAM(Appearance::Normal);
-    AC_PROCESS_APPEARANCE_TO_STREAM(Appearance::NormalNotShown);
-    AC_PROCESS_APPEARANCE_TO_STREAM(Appearance::Left);
-    AC_PROCESS_APPEARANCE_TO_STREAM(Appearance::Right);
+    AC_PROCESS_ENUM_TO_STREAM(Appearance::None);
+    AC_PROCESS_ENUM_TO_STREAM(Appearance::Normal);
+    AC_PROCESS_ENUM_TO_STREAM(Appearance::NormalNotShown);
+    AC_PROCESS_ENUM_TO_STREAM(Appearance::Left);
+    AC_PROCESS_ENUM_TO_STREAM(Appearance::Right);
   }
-#undef AC_PROCESS_APPEARANCE_TO_STREAM
-
   return aStream;
 }
 
+std::ostream&
+operator<<(std::ostream& aStream,
+           const AccessibleCaret::PositionChangedResult& aResult)
+{
+  using PositionChangedResult = AccessibleCaret::PositionChangedResult;
+  switch (aResult) {
+    AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::NotChanged);
+    AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Changed);
+    AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Invisible);
+  }
+  return aStream;
+}
+#undef AC_PROCESS_ENUM_TO_STREAM
+
 // -----------------------------------------------------------------------------
 // Implementation of AccessibleCaret methods
 
 AccessibleCaret::AccessibleCaret(nsIPresShell* aPresShell)
   : mPresShell(aPresShell)
 {
   // Check all resources required.
   if (mPresShell) {
--- a/layout/base/AccessibleCaret.h
+++ b/layout/base/AccessibleCaret.h
@@ -64,16 +64,19 @@ public:
 
     // Display the caret which is tilted to the left.
     Left,
 
     // Display the caret which is tilted to the right.
     Right
   };
 
+  friend std::ostream& operator<<(std::ostream& aStream,
+                                  const Appearance& aAppearance);
+
   Appearance GetAppearance() const
   {
     return mAppearance;
   }
 
   virtual void SetAppearance(Appearance aAppearance);
 
   // Return true if current appearance is either Normal, NormalNotShown, Left,
@@ -100,16 +103,20 @@ public:
     NotChanged,
 
     // Position is changed.
     Changed,
 
     // Position is out of scroll port.
     Invisible
   };
+
+  friend std::ostream& operator<<(std::ostream& aStream,
+                                  const PositionChangedResult& aResult);
+
   virtual PositionChangedResult SetPosition(nsIFrame* aFrame, int32_t aOffset);
 
   // Does two AccessibleCarets overlap?
   bool Intersects(const AccessibleCaret& aCaret) const;
 
   // Is the point within the caret's rect? The point should be relative to root
   // frame.
   bool Contains(const nsPoint& aPoint) const;
@@ -208,11 +215,17 @@ protected:
   // Static class variables
   static float sWidth;
   static float sHeight;
   static float sMarginLeft;
   static float sBarWidth;
 
 }; // class AccessibleCaret
 
+std::ostream& operator<<(std::ostream& aStream,
+                         const AccessibleCaret::Appearance& aAppearance);
+
+std::ostream& operator<<(std::ostream& aStream,
+                         const AccessibleCaret::PositionChangedResult& aResult);
+
 } // namespace mozilla
 
 #endif // AccessibleCaret_h__
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -29,16 +29,42 @@ namespace mozilla {
 #undef AC_LOGV
 #define AC_LOGV(message, ...)                                                  \
   AC_LOGV_BASE("AccessibleCaretManager (%p): " message, this, ##__VA_ARGS__);
 
 using namespace dom;
 using Appearance = AccessibleCaret::Appearance;
 using PositionChangedResult = AccessibleCaret::PositionChangedResult;
 
+#define AC_PROCESS_ENUM_TO_STREAM(e) case(e): aStream << #e; break;
+std::ostream&
+operator<<(std::ostream& aStream,
+           const AccessibleCaretManager::CaretMode& aCaretMode)
+{
+  using CaretMode = AccessibleCaretManager::CaretMode;
+  switch (aCaretMode) {
+    AC_PROCESS_ENUM_TO_STREAM(CaretMode::None);
+    AC_PROCESS_ENUM_TO_STREAM(CaretMode::Cursor);
+    AC_PROCESS_ENUM_TO_STREAM(CaretMode::Selection);
+  }
+  return aStream;
+}
+
+std::ostream& operator<<(std::ostream& aStream,
+                         const AccessibleCaretManager::UpdateCaretsHint& aHint)
+{
+  using UpdateCaretsHint = AccessibleCaretManager::UpdateCaretsHint;
+  switch (aHint) {
+    AC_PROCESS_ENUM_TO_STREAM(UpdateCaretsHint::Default);
+    AC_PROCESS_ENUM_TO_STREAM(UpdateCaretsHint::RespectOldAppearance);
+  }
+  return aStream;
+}
+#undef AC_PROCESS_ENUM_TO_STREAM
+
 AccessibleCaretManager::AccessibleCaretManager(nsIPresShell* aPresShell)
   : mPresShell(aPresShell)
 {
   if (mPresShell) {
     mFirstCaret = MakeUnique<AccessibleCaret>(mPresShell);
     mSecondCaret = MakeUnique<AccessibleCaret>(mPresShell);
 
     mCaretTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
--- a/layout/base/AccessibleCaretManager.h
+++ b/layout/base/AccessibleCaretManager.h
@@ -101,25 +101,32 @@ protected:
 
     // One caret, i.e. the selection is collapsed.
     Cursor,
 
     // Two carets, i.e. the selection is not collapsed.
     Selection
   };
 
+  friend std::ostream& operator<<(std::ostream& aStream,
+                                  const CaretMode& aCaretMode);
+
   enum class UpdateCaretsHint : uint8_t {
     // Update everything including appearance and position.
     Default,
 
     // Update everything while respecting the old appearance. For example, if
     // the caret in cursor mode is hidden due to timeout, do not change its
     // appearance to Normal.
     RespectOldAppearance
   };
+
+  friend std::ostream& operator<<(std::ostream& aStream,
+                                  const UpdateCaretsHint& aResult);
+
   // Update carets based on current selection status.
   void UpdateCarets(UpdateCaretsHint aHint = UpdateCaretsHint::Default);
 
   // Force hiding all carets regardless of the current selection status.
   void HideCarets();
 
   void UpdateCaretsForCursorMode(UpdateCaretsHint aHint);
   void UpdateCaretsForSelectionMode(UpdateCaretsHint aHint);
@@ -212,11 +219,17 @@ protected:
   nsCOMPtr<nsITimer> mCaretTimeoutTimer;
 
   // The caret mode since last update carets.
   CaretMode mLastUpdateCaretMode = CaretMode::None;
 
   static const int32_t kAutoScrollTimerDelay = 30;
 };
 
+std::ostream& operator<<(std::ostream& aStream,
+                         const AccessibleCaretManager::CaretMode& aCaretMode);
+
+std::ostream& operator<<(std::ostream& aStream,
+                         const AccessibleCaretManager::UpdateCaretsHint& aResult);
+
 } // namespace mozilla
 
 #endif // AccessibleCaretManager_h