Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: sky/shell/ios/sky_surface.mm

Issue 1183833004: iOS: Wire up all gesture types in input_event.mojom (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Avoid locations in the window coordinate space Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/shell/ios/sky_surface.mm
diff --git a/sky/shell/ios/sky_surface.mm b/sky/shell/ios/sky_surface.mm
index c04a30351cbf8ee51725aa99d30d639c208980a8..d676ebdae7f8384661b66213dac71c8a73cacacc 100644
--- a/sky/shell/ios/sky_surface.mm
+++ b/sky/shell/ios/sky_surface.mm
@@ -35,6 +35,28 @@ static inline sky::EventType EventTypeFromUITouchPhase(UITouchPhase phase) {
return sky::EVENT_TYPE_UNKNOWN;
}
+static inline int64 InputEventTimestampFromNSTimeInterval(
+ NSTimeInterval interval) {
+ return base::TimeDelta::FromSecondsD(interval).InMilliseconds();
+}
+
+static sky::InputEventPtr BasicInputEventFromRecognizer(
+ sky::EventType type,
+ UIGestureRecognizer* recognizer) {
+ auto input = sky::InputEvent::New();
+ input->type = type;
+ input->time_stamp = InputEventTimestampFromNSTimeInterval(
+ CACurrentMediaTime());
+
+ input->gesture_data = sky::GestureData::New();
+
+ CGPoint windowCoordinates = [recognizer locationInView:recognizer.view];
+ const CGFloat scale = [UIScreen mainScreen].scale;
+ input->gesture_data->x = windowCoordinates.x * scale;
+ input->gesture_data->y = windowCoordinates.y * scale;
+ return input.Pass();
+}
+
@implementation SkySurface {
BOOL _platformViewInitialized;
@@ -44,8 +66,10 @@ static inline sky::EventType EventTypeFromUITouchPhase(UITouchPhase phase) {
-(instancetype) initWithShellView:(sky::shell::ShellView *) shellView {
self = [super init];
- if (self)
+ if (self) {
_shell_view.reset(shellView);
+ [self installGestureRecognizers];
+ }
return self;
}
@@ -123,9 +147,7 @@ static inline sky::EventType EventTypeFromUITouchPhase(UITouchPhase phase) {
for (UITouch* touch in touches) {
auto input = sky::InputEvent::New();
input->type = eventType;
-
- auto timedelta = base::TimeDelta::FromSecondsD(touch.timestamp);
- input->time_stamp = timedelta.InMilliseconds();
+ input->time_stamp = InputEventTimestampFromNSTimeInterval(touch.timestamp);
input->pointer_data = sky::PointerData::New();
input->pointer_data->kind = sky::POINTER_KIND_TOUCH;
@@ -155,6 +177,111 @@ static inline sky::EventType EventTypeFromUITouchPhase(UITouchPhase phase) {
[self dispatchTouches:touches phase:UITouchPhaseCancelled];
}
+#pragma mark - Gesture Recognizers
+
+-(void) installGestureRecognizers {
+ // For:
+ // GESTURE_FLING_CANCEL
+ // GESTURE_FLING_START
+ UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]
+ initWithTarget:self action:@selector(onFling:)];
+ [self addGestureRecognizer: swipe];
+ [swipe release];
+
+ // For:
+ // GESTURE_LONG_PRESS
+ // GESTURE_SHOW_PRESS
+ UILongPressGestureRecognizer *longPress =
+ [[UILongPressGestureRecognizer alloc]
+ initWithTarget:self action:@selector(onLongPress:)];
+ [self addGestureRecognizer: longPress];
+ [longPress release];
+
+ // For:
+ // GESTURE_SCROLL_BEGIN
+ // GESTURE_SCROLL_END
+ // GESTURE_SCROLL_UPDATE
+ UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]
+ initWithTarget:self action:@selector(onScroll:)];
+ [self addGestureRecognizer: pan];
+ [pan release];
+
+ // For:
+ // GESTURE_TAP
+ // GESTURE_TAP_DOWN
+ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
+ initWithTarget:self action:@selector(onTap:)];
+ [self addGestureRecognizer: tap];
+ [tap release];
+}
+
+-(void) onFling:(UISwipeGestureRecognizer *) recognizer {
+ // Swipes are discrete gestures already. So there is no equivalent to a cancel
+ if (recognizer.state != UIGestureRecognizerStateEnded) {
+ return;
+ }
+
+ auto input = BasicInputEventFromRecognizer(
+ sky::EVENT_TYPE_GESTURE_FLING_START, recognizer);
+ _viewport_observer->OnInputEvent(input.Pass());
+}
+
+-(void) onLongPress:(UILongPressGestureRecognizer *) recognizer {
+ if (recognizer.state != UIGestureRecognizerStateEnded) {
+ return;
+ }
+
+ auto input = BasicInputEventFromRecognizer(sky::EVENT_TYPE_GESTURE_LONG_PRESS,
+ recognizer);
+ _viewport_observer->OnInputEvent(input.Pass());
+}
+
+-(void) onScroll:(UIPanGestureRecognizer *) recognizer {
+ sky::EventType type = sky::EVENT_TYPE_UNKNOWN;
+ switch (recognizer.state) {
+ case UIGestureRecognizerStateBegan:
+ type = sky::EVENT_TYPE_GESTURE_SCROLL_BEGIN;
+ break;
+ case UIGestureRecognizerStateChanged:
+ type = sky::EVENT_TYPE_GESTURE_SCROLL_UPDATE;
+ break;
+ case UIGestureRecognizerStateEnded:
+ case UIGestureRecognizerStateCancelled:
+ case UIGestureRecognizerStateFailed:
+ type = sky::EVENT_TYPE_GESTURE_SCROLL_END;
+ break;
+ default:
+ break;
+ }
+
+ if (type == sky::EVENT_TYPE_UNKNOWN) {
+ return;
+ }
+
+ auto input = BasicInputEventFromRecognizer(type, recognizer);
+ auto scale = [UIScreen mainScreen].scale;
+ auto translation = [recognizer translationInView: self];
+ auto velocity = [recognizer velocityInView: self];
+
+ input->gesture_data->dx = translation.x * scale;
+ input->gesture_data->dy = translation.y * scale;
+ input->gesture_data->velocityX = velocity.x * scale;
+ input->gesture_data->velocityY = velocity.y * scale;
+
+ _viewport_observer->OnInputEvent(input.Pass());
+}
+
+-(void) onTap:(UITapGestureRecognizer *) recognizer {
+
+ if (recognizer.state != UIGestureRecognizerStateEnded) {
+ return;
+ }
+
+ auto input = BasicInputEventFromRecognizer(sky::EVENT_TYPE_GESTURE_TAP,
+ recognizer);
+ _viewport_observer->OnInputEvent(input.Pass());
+}
+
#pragma mark - Misc.
+ (Class)layerClass {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698