nsEventStatus GestureEventListener::HandleInputTouchMove()
{
    nsEventStatus rv = nsEventStatus_eIgnore;

    switch (mState) {
    case GESTURE_NONE:
        // Ignore this input signal as the corresponding events get handled by APZC
        break;

    case GESTURE_LONG_TOUCH_DOWN:
        if (MoveDistanceIsLarge()) {
            // So that we don't fire a long-tap-up if the user moves around after a
            // long-tap
            SetState(GESTURE_NONE);
        }
        break;

    case GESTURE_FIRST_SINGLE_TOUCH_DOWN:
    case GESTURE_FIRST_SINGLE_TOUCH_MAX_TAP_DOWN:
    case GESTURE_SECOND_SINGLE_TOUCH_DOWN: {
        // If we move too much, bail out of the tap.
        if (MoveDistanceIsLarge()) {
            CancelLongTapTimeoutTask();
            CancelMaxTapTimeoutTask();
            SetState(GESTURE_NONE);
        }
        break;
    }

    case GESTURE_MULTI_TOUCH_DOWN: {
        if (mLastTouchInput.mTouches.Length() < 2) {
            NS_WARNING("Wrong input: less than 2 moving points in GESTURE_MULTI_TOUCH_DOWN state");
            break;
        }

        float currentSpan = GetCurrentSpan(mLastTouchInput);

        mSpanChange += fabsf(currentSpan - mPreviousSpan);
        if (mSpanChange > PINCH_START_THRESHOLD) {
            SetState(GESTURE_PINCH);
            PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_START,
                                         mLastTouchInput.mTime,
                                         mLastTouchInput.mTimeStamp,
                                         GetCurrentFocus(mLastTouchInput),
                                         currentSpan,
                                         currentSpan,
                                         mLastTouchInput.modifiers);

            rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
        } else {
            // Prevent APZC::OnTouchMove from processing a move event when two
            // touches are active
            rv = nsEventStatus_eConsumeNoDefault;
        }

        mPreviousSpan = currentSpan;
        break;
    }

    case GESTURE_PINCH: {
        if (mLastTouchInput.mTouches.Length() < 2) {
            NS_WARNING("Wrong input: less than 2 moving points in GESTURE_PINCH state");
            // Prevent APZC::OnTouchMove() from handling this wrong input
            rv = nsEventStatus_eConsumeNoDefault;
            break;
        }

        float currentSpan = GetCurrentSpan(mLastTouchInput);

        PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_SCALE,
                                     mLastTouchInput.mTime,
                                     mLastTouchInput.mTimeStamp,
                                     GetCurrentFocus(mLastTouchInput),
                                     currentSpan,
                                     mPreviousSpan,
                                     mLastTouchInput.modifiers);

        rv = mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
        mPreviousSpan = currentSpan;

        break;
    }

    default:
        NS_WARNING("Unhandled state upon touch move");
        SetState(GESTURE_NONE);
        break;
    }

    return rv;
}
nsEventStatus GestureEventListener::HandleInputTouchMove()
{
  nsEventStatus rv = nsEventStatus_eIgnore;

  switch (mState) {
  case GESTURE_NONE:
  case GESTURE_LONG_TOUCH_DOWN:
    // Ignore this input signal as the corresponding events get handled by APZC
    break;

  case GESTURE_FIRST_SINGLE_TOUCH_DOWN:
  case GESTURE_FIRST_SINGLE_TOUCH_MAX_TAP_DOWN:
  case GESTURE_SECOND_SINGLE_TOUCH_DOWN: {
    // If we move too much, bail out of the tap.
    ScreenIntPoint delta = mLastTouchInput.mTouches[0].mScreenPoint - mTouchStartPosition;
    if (NS_hypot(delta.x, delta.y) > AsyncPanZoomController::GetTouchStartTolerance()) {
      CancelLongTapTimeoutTask();
      CancelMaxTapTimeoutTask();
      SetState(GESTURE_NONE);
    }
    break;
  }

  case GESTURE_MULTI_TOUCH_DOWN: {
    if (mLastTouchInput.mTouches.Length() < 2) {
      NS_WARNING("Wrong input: less than 2 moving points in GESTURE_MULTI_TOUCH_DOWN state");
      break;
    }

    float currentSpan = GetCurrentSpan(mLastTouchInput);

    mSpanChange += fabsf(currentSpan - mPreviousSpan);
    if (mSpanChange > PINCH_START_THRESHOLD) {
      SetState(GESTURE_PINCH);
      PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_START,
                                   mLastTouchInput.mTime,
                                   GetCurrentFocus(mLastTouchInput),
                                   currentSpan,
                                   currentSpan,
                                   mLastTouchInput.modifiers);

      mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
    }
    rv = nsEventStatus_eConsumeNoDefault;
    mPreviousSpan = currentSpan;
    break;
  }

  case GESTURE_PINCH: {
    if (mLastTouchInput.mTouches.Length() < 2) {
      NS_WARNING("Wrong input: less than 2 moving points in GESTURE_PINCH state");
      // Prevent APZC::OnTouchMove() from handling this wrong input
      rv = nsEventStatus_eConsumeNoDefault;
      break;
    }

    float currentSpan = GetCurrentSpan(mLastTouchInput);

    PinchGestureInput pinchEvent(PinchGestureInput::PINCHGESTURE_SCALE,
                                 mLastTouchInput.mTime,
                                 GetCurrentFocus(mLastTouchInput),
                                 currentSpan,
                                 mPreviousSpan,
                                 mLastTouchInput.modifiers);

    mAsyncPanZoomController->HandleGestureEvent(pinchEvent);
    rv = nsEventStatus_eConsumeNoDefault;
    mPreviousSpan = currentSpan;

    break;
  }

  default:
    NS_WARNING("Unhandled state upon touch move");
    SetState(GESTURE_NONE);
    break;
  }

  return rv;
}