Bug 1372233 - Clean up handling of default branches in APZ switch statements. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 16 Jun 2017 15:22:12 -0400
changeset 413146 f22f7f42d2d4ecaadb447fcbd636a455c3465665
parent 413145 91dd7d607bb8cae1aae0c4922208552d99dcc222
child 413147 2573b20f6f90c721ab776b4d083b46fdc4f01c02
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1372233
milestone56.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 1372233 - Clean up handling of default branches in APZ switch statements. r=botond Wherever possible, we exhaustively list all the possibilities instead of having "default" branches. This way if new items are added to the enum they won't silently end up in the "default" branch, but the compiler can tell us that we skipped handling it. Also wherever possible, the existing NS_WARNINGs were upgrade to MOZ_ASSERTs or equivalent. MozReview-Commit-ID: IVDiI0gjFtU
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/TouchCounter.cpp
gfx/layers/apz/src/WheelScrollAnimation.cpp
gfx/layers/apz/util/APZCCallbackHelper.cpp
gfx/layers/apz/util/APZEventState.cpp
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -1198,19 +1198,20 @@ ConvertToTouchBehavior(HitTestResult res
     case HitLayerTouchActionPanX:
       return AllowedTouchBehavior::HORIZONTAL_PAN;
     case HitLayerTouchActionPanY:
       return AllowedTouchBehavior::VERTICAL_PAN;
     case HitLayerTouchActionPanXY:
       return AllowedTouchBehavior::HORIZONTAL_PAN
            | AllowedTouchBehavior::VERTICAL_PAN;
     case HitDispatchToContentRegion:
-    default:
       return AllowedTouchBehavior::UNKNOWN;
   }
+  MOZ_ASSERT_UNREACHABLE("Invalid value");
+  return AllowedTouchBehavior::UNKNOWN;
 }
 
 already_AddRefed<AsyncPanZoomController>
 APZCTreeManager::GetTouchInputBlockAPZC(const MultiTouchInput& aEvent,
                                         nsTArray<TouchBehaviorFlags>* aOutTouchBehaviors,
                                         HitTestResult* aOutHitResult)
 {
   RefPtr<AsyncPanZoomController> apzc;
--- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
+++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
@@ -126,17 +126,19 @@ AndroidDynamicToolbarAnimator::ReceiveIn
   switch (multiTouch.mType) {
   case MultiTouchInput::MULTITOUCH_START:
     mControllerTouchCount = multiTouch.mTouches.Length();
     break;
   case MultiTouchInput::MULTITOUCH_END:
   case MultiTouchInput::MULTITOUCH_CANCEL:
     mControllerTouchCount -= multiTouch.mTouches.Length();
     break;
-  default:
+  case MultiTouchInput::MULTITOUCH_SENTINEL:
+    MOZ_FALLTHROUGH_ASSERT("Invalid value");
+  case MultiTouchInput::MULTITOUCH_MOVE:
     break;
   }
 
   if (mControllerTouchCount > 1) {
     mControllerResetOnNextMove = true;
   }
 
   ScreenIntCoord currentTouch = 0;
@@ -196,17 +198,18 @@ AndroidDynamicToolbarAnimator::ReceiveIn
   }
   case MultiTouchInput::MULTITOUCH_END:
   case MultiTouchInput::MULTITOUCH_CANCEL:
     // last finger was lifted
     if (mControllerTouchCount == 0) {
       HandleTouchEnd(currentToolbarState, currentTouch);
     }
     break;
-  default:
+  case MultiTouchInput::MULTITOUCH_SENTINEL:
+    MOZ_ASSERT_UNREACHABLE("Invalid value");
     break;
   }
 
   TranslateTouchEvent(multiTouch);
 
   return status;
 }
 
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -942,17 +942,17 @@ nsEventStatus AsyncPanZoomController::Ha
       }
     }
 
     switch (multiTouchInput.mType) {
       case MultiTouchInput::MULTITOUCH_START: rv = OnTouchStart(multiTouchInput); break;
       case MultiTouchInput::MULTITOUCH_MOVE: rv = OnTouchMove(multiTouchInput); break;
       case MultiTouchInput::MULTITOUCH_END: rv = OnTouchEnd(multiTouchInput); break;
       case MultiTouchInput::MULTITOUCH_CANCEL: rv = OnTouchCancel(multiTouchInput); break;
-      default: NS_WARNING("Unhandled multitouch"); break;
+      case MultiTouchInput::MULTITOUCH_SENTINEL: MOZ_ASSERT_UNREACHABLE("Invalid value"); break;
     }
     break;
   }
   case PANGESTURE_INPUT: {
     PanGestureInput panGestureInput = aEvent.AsPanGestureInput();
     if (!panGestureInput.TransformToLocal(aTransformToApzc)) {
       return rv;
     }
@@ -961,28 +961,25 @@ nsEventStatus AsyncPanZoomController::Ha
       case PanGestureInput::PANGESTURE_MAYSTART: rv = OnPanMayBegin(panGestureInput); break;
       case PanGestureInput::PANGESTURE_CANCELLED: rv = OnPanCancelled(panGestureInput); break;
       case PanGestureInput::PANGESTURE_START: rv = OnPanBegin(panGestureInput); break;
       case PanGestureInput::PANGESTURE_PAN: rv = OnPan(panGestureInput, true); break;
       case PanGestureInput::PANGESTURE_END: rv = OnPanEnd(panGestureInput); break;
       case PanGestureInput::PANGESTURE_MOMENTUMSTART: rv = OnPanMomentumStart(panGestureInput); break;
       case PanGestureInput::PANGESTURE_MOMENTUMPAN: rv = OnPan(panGestureInput, false); break;
       case PanGestureInput::PANGESTURE_MOMENTUMEND: rv = OnPanMomentumEnd(panGestureInput); break;
-      default: NS_WARNING("Unhandled pan gesture"); break;
+      case PanGestureInput::PANGESTURE_SENTINEL: MOZ_ASSERT_UNREACHABLE("Invalid value"); break;
     }
     break;
   }
   case MOUSE_INPUT: {
     MouseInput mouseInput = aEvent.AsMouseInput();
     if (!mouseInput.TransformToLocal(aTransformToApzc)) {
       return rv;
     }
-
-    // TODO Need to implement blocks to properly handle this.
-    //rv = HandleDragEvent(mouseInput, dragMetrics);
     break;
   }
   case SCROLLWHEEL_INPUT: {
     ScrollWheelInput scrollInput = aEvent.AsScrollWheelInput();
     if (!scrollInput.TransformToLocal(aTransformToApzc)) {
       return rv;
     }
 
@@ -1002,17 +999,20 @@ nsEventStatus AsyncPanZoomController::Ha
     TapGestureInput tapInput = aEvent.AsTapGestureInput();
     if (!tapInput.TransformToLocal(aTransformToApzc)) {
       return rv;
     }
 
     rv = HandleGestureEvent(tapInput);
     break;
   }
-  default: NS_WARNING("Unhandled input event type"); break;
+  case SENTINEL_INPUT: {
+    MOZ_ASSERT_UNREACHABLE("Invalid value");
+    break;
+  }
   }
 
   return rv;
 }
 
 nsEventStatus AsyncPanZoomController::HandleGestureEvent(const InputData& aEvent)
 {
   APZThreadUtils::AssertOnControllerThread();
@@ -1021,35 +1021,35 @@ nsEventStatus AsyncPanZoomController::Ha
 
   switch (aEvent.mInputType) {
   case PINCHGESTURE_INPUT: {
     const PinchGestureInput& pinchGestureInput = aEvent.AsPinchGestureInput();
     switch (pinchGestureInput.mType) {
       case PinchGestureInput::PINCHGESTURE_START: rv = OnScaleBegin(pinchGestureInput); break;
       case PinchGestureInput::PINCHGESTURE_SCALE: rv = OnScale(pinchGestureInput); break;
       case PinchGestureInput::PINCHGESTURE_END: rv = OnScaleEnd(pinchGestureInput); break;
-      default: NS_WARNING("Unhandled pinch gesture"); break;
+      case PinchGestureInput::PINCHGESTURE_SENTINEL: MOZ_ASSERT_UNREACHABLE("Invalid value"); break;
     }
     break;
   }
   case TAPGESTURE_INPUT: {
     const TapGestureInput& tapGestureInput = aEvent.AsTapGestureInput();
     switch (tapGestureInput.mType) {
       case TapGestureInput::TAPGESTURE_LONG: rv = OnLongPress(tapGestureInput); break;
       case TapGestureInput::TAPGESTURE_LONG_UP: rv = OnLongPressUp(tapGestureInput); break;
       case TapGestureInput::TAPGESTURE_UP: rv = OnSingleTapUp(tapGestureInput); break;
       case TapGestureInput::TAPGESTURE_CONFIRMED: rv = OnSingleTapConfirmed(tapGestureInput); break;
       case TapGestureInput::TAPGESTURE_DOUBLE: rv = OnDoubleTap(tapGestureInput); break;
       case TapGestureInput::TAPGESTURE_SECOND: rv = OnSecondTap(tapGestureInput); break;
       case TapGestureInput::TAPGESTURE_CANCEL: rv = OnCancelTap(tapGestureInput); break;
-      default: NS_WARNING("Unhandled tap gesture"); break;
+      case TapGestureInput::TAPGESTURE_SENTINEL: MOZ_ASSERT_UNREACHABLE("Invalid value"); break;
     }
     break;
   }
-  default: NS_WARNING("Unhandled input event"); break;
+  default: MOZ_ASSERT_UNREACHABLE("Unhandled input event"); break;
   }
 
   return rv;
 }
 
 void AsyncPanZoomController::HandleTouchVelocity(uint32_t aTimesampMs, float aSpeedY)
 {
   mY.HandleTouchVelocity(aTimesampMs, aSpeedY);
@@ -1084,19 +1084,16 @@ nsEventStatus AsyncPanZoomController::On
     }
     case TOUCHING:
     case PANNING:
     case PANNING_LOCKED_X:
     case PANNING_LOCKED_Y:
     case PINCHING:
       NS_WARNING("Received impossible touch in OnTouchStart");
       break;
-    default:
-      NS_WARNING("Unhandled case in OnTouchStart");
-      break;
   }
 
   return nsEventStatus_eConsumeNoDefault;
 }
 
 nsEventStatus AsyncPanZoomController::OnTouchMove(const MultiTouchInput& aEvent) {
   APZC_LOG("%p got a touch-move in state %d\n", this, mState);
   switch (mState) {
@@ -1595,18 +1592,20 @@ AsyncPanZoomController::GetScrollWheelDe
       delta.x = aEvent.mDeltaX * pageScrollSize.width;
       delta.y = aEvent.mDeltaY * pageScrollSize.height;
       break;
     }
     case ScrollWheelInput::SCROLLDELTA_PIXEL: {
       delta = ToParentLayerCoordinates(ScreenPoint(aEvent.mDeltaX, aEvent.mDeltaY), aEvent.mOrigin);
       break;
     }
-    default:
-      MOZ_ASSERT_UNREACHABLE("unexpected scroll delta type");
+    case ScrollWheelInput::SCROLLDELTA_SENTINEL: {
+      MOZ_ASSERT_UNREACHABLE("Invalid value");
+      break;
+    }
   }
 
   // Apply user-set multipliers.
   delta.x *= aEvent.mUserDeltaMultiplierX;
   delta.y *= aEvent.mUserDeltaMultiplierY;
 
   // For the conditions under which we allow system scroll overrides, see
   // EventStateManager::DeltaAccumulator::ComputeScrollAmountForDefaultAction
@@ -1686,18 +1685,23 @@ AsyncPanZoomController::CanScrollWithWhe
 
 bool
 AsyncPanZoomController::CanScroll(ScrollDirection aDirection) const
 {
   ReentrantMonitorAutoEnter lock(mMonitor);
   switch (aDirection) {
   case ScrollDirection::HORIZONTAL: return mX.CanScroll();
   case ScrollDirection::VERTICAL:   return mY.CanScroll();
-  default:                MOZ_ASSERT(false); return false;
+
+  case ScrollDirection::NONE:
+  case ScrollDirection::SENTINEL:
+    MOZ_ASSERT_UNREACHABLE("Invalid value");
+    break;
   }
+  return false;
 }
 
 bool
 AsyncPanZoomController::AllowScrollHandoffInCurrentBlock() const
 {
   bool result = mInputQueue->AllowScrollHandoff();
   if (!gfxPrefs::APZAllowImmediateHandoff()) {
     if (InputBlockState* currentBlock = GetCurrentInputBlock()) {
@@ -1727,20 +1731,21 @@ ScrollInputMethodForWheelDeltaType(Scrol
       return ScrollInputMethod::ApzWheelLine;
     }
     case ScrollWheelInput::SCROLLDELTA_PAGE: {
       return ScrollInputMethod::ApzWheelPage;
     }
     case ScrollWheelInput::SCROLLDELTA_PIXEL: {
       return ScrollInputMethod::ApzWheelPixel;
     }
-    default:
-      MOZ_ASSERT_UNREACHABLE("unexpected scroll delta type");
-      return ScrollInputMethod::ApzWheelLine;
+    case ScrollWheelInput::SCROLLDELTA_SENTINEL:
+      break;
   }
+  MOZ_ASSERT_UNREACHABLE("Invalid value");
+  return ScrollInputMethod::ApzWheelLine;
 }
 
 nsEventStatus AsyncPanZoomController::OnScrollWheel(const ScrollWheelInput& aEvent)
 {
   ParentLayerPoint delta = GetScrollWheelDelta(aEvent);
   APZC_LOG("%p got a scroll-wheel with delta %s\n", this, Stringify(delta).c_str());
 
   if ((delta.x || delta.y) && !CanScrollWithWheel(delta)) {
--- a/gfx/layers/apz/src/TouchCounter.cpp
+++ b/gfx/layers/apz/src/TouchCounter.cpp
@@ -30,17 +30,20 @@ TouchCounter::Update(const MultiTouchInp
       } else {
         NS_WARNING("Got an unexpected touchend/touchcancel");
         mActiveTouchCount = 0;
       }
       break;
     case MultiTouchInput::MULTITOUCH_CANCEL:
       mActiveTouchCount = 0;
       break;
-    default:
+    case MultiTouchInput::MULTITOUCH_MOVE:
+      break;
+    case MultiTouchInput::MULTITOUCH_SENTINEL:
+      MOZ_ASSERT_UNREACHABLE("Invalid input");
       break;
   }
 }
 
 uint32_t
 TouchCounter::GetActiveTouchCount() const
 {
   return mActiveTouchCount;
--- a/gfx/layers/apz/src/WheelScrollAnimation.cpp
+++ b/gfx/layers/apz/src/WheelScrollAnimation.cpp
@@ -96,18 +96,19 @@ WheelScrollAnimation::InitPreferences(Ti
   case ScrollWheelInput::SCROLLDELTA_PAGE:
     mOriginMaxMS = clamped(gfxPrefs::PageSmoothScrollMaxDurationMs(), 0, 10000);
     mOriginMinMS = clamped(gfxPrefs::PageSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
     break;
   case ScrollWheelInput::SCROLLDELTA_PIXEL:
     mOriginMaxMS = clamped(gfxPrefs::PixelSmoothScrollMaxDurationMs(), 0, 10000);
     mOriginMinMS = clamped(gfxPrefs::PixelSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
     break;
+  case ScrollWheelInput::SCROLLDELTA_SENTINEL:
+    MOZ_FALLTHROUGH_ASSERT("Invalid value");
   case ScrollWheelInput::SCROLLDELTA_LINE:
-  default:
     mOriginMaxMS = clamped(gfxPrefs::WheelSmoothScrollMaxDurationMs(), 0, 10000);
     mOriginMinMS = clamped(gfxPrefs::WheelSmoothScrollMinDurationMs(), 0, mOriginMaxMS);
     break;
   }
 
   // The pref is 100-based int percentage, while mIntervalRatio is 1-based ratio
   mIntervalRatio = ((double)gfxPrefs::SmoothScrollDurationToIntervalRatio()) / 100.0;
   mIntervalRatio = std::max(1.0, mIntervalRatio);
--- a/gfx/layers/apz/util/APZCCallbackHelper.cpp
+++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp
@@ -971,18 +971,17 @@ APZCCallbackHelper::NotifyPinchGesture(P
       break;
     case PinchGestureInput::PINCHGESTURE_SCALE:
       msg = eMagnifyGestureUpdate;
       break;
     case PinchGestureInput::PINCHGESTURE_END:
       msg = eMagnifyGesture;
       break;
     case PinchGestureInput::PINCHGESTURE_SENTINEL:
-    default:
-      MOZ_ASSERT_UNREACHABLE("Invalid gesture type");
+      MOZ_ASSERT_UNREACHABLE("Invalid value");
       return;
   }
 
   WidgetSimpleGestureEvent event(true, msg, aWidget);
   event.mDelta = aSpanChange;
   event.mModifiers = aModifiers;
   DispatchWidgetEvent(event);
 }
--- a/gfx/layers/apz/util/APZEventState.cpp
+++ b/gfx/layers/apz/util/APZEventState.cpp
@@ -376,17 +376,18 @@ APZEventState::ProcessTouchEvent(const W
     if (mPendingTouchPreventedResponse) {
       MOZ_ASSERT(aGuid == mPendingTouchPreventedGuid);
     }
     sentContentResponse = SendPendingTouchPreventedResponse(isTouchPrevented);
     break;
   }
 
   default:
-    NS_WARNING("Unknown touch event type");
+    MOZ_ASSERT_UNREACHABLE("Unknown touch event type");
+    break;
   }
 
   if (sentContentResponse &&
         aApzResponse == nsEventStatus_eConsumeDoDefault &&
         gfxPrefs::PointerEventsEnabled()) {
     WidgetTouchEvent cancelEvent(aEvent);
     cancelEvent.mMessage = eTouchPointerCancel;
     cancelEvent.mFlags.mCancelable = false; // mMessage != eTouchCancel;