提交 9b74ec02 编写于 作者: C Chinmay Garde

iOS: Wire up all gesture types in input_event.mojom

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1183833004.
上级 5faecb46
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册