Hook up pinch-zoom and swipe gestures.

Sets UIPinchGestureRecognizer and UISwipeGestureRecognizers and
passes the result down to the sk_app::Window. To simplify detection,
swipes take precedence over pans, and pans require a single touch.
This is less flexible for the app, but in most cases I think is
what we want.

Bug: skia:8737
Change-Id: Ib031b6ad465d3a353da29d7e0b48a666d4ff8b9a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/239776
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp
index 601856c..6349113 100644
--- a/tools/viewer/Viewer.cpp
+++ b/tools/viewer/Viewer.cpp
@@ -1444,6 +1444,11 @@
             fGesture.touchMoved(castedOwner, x, y);
             break;
         }
+        default: {
+            // kLeft and kRight are only for swipes
+            SkASSERT(false);
+            break;
+        }
     }
     fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kTouch : GestureDevice::kNone;
     fWindow->inval();
@@ -1474,6 +1479,10 @@
             fGesture.touchMoved(nullptr, x, y);
             break;
         }
+        default: {
+            SkASSERT(false); // shouldn't see kRight or kLeft here
+            break;
+        }
     }
     fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone;
 
@@ -1483,6 +1492,39 @@
     return true;
 }
 
+bool Viewer::onFling(skui::InputState state) {
+    if (skui::InputState::kRight == state) {
+        this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.count() - 1);
+        return true;
+    } else if (skui::InputState::kLeft == state) {
+        this->setCurrentSlide(fCurrentSlide < fSlides.count() - 1 ? fCurrentSlide + 1 : 0);
+        return true;
+    }
+    return false;
+}
+
+bool Viewer::onPinch(skui::InputState state, float scale, float x, float y) {
+    switch (state) {
+        case skui::InputState::kDown:
+            fGesture.startZoom();
+            return true;
+            break;
+        case skui::InputState::kMove:
+            fGesture.updateZoom(scale, x, y, x, y);
+            return true;
+            break;
+        case skui::InputState::kUp:
+            fGesture.endZoom();
+            return true;
+            break;
+        default:
+            SkASSERT(false);
+            break;
+    }
+
+    return false;
+}
+
 static void ImGui_Primaries(SkColorSpacePrimaries* primaries, SkPaint* gamutPaint) {
     // The gamut image covers a (0.8 x 0.9) shaped region
     ImGui::DragCanvas dc(primaries, { 0.0f, 0.9f }, { 0.8f, 0.0f });