Skip to content

Commit

Permalink
Bug 1304904 - Handle tabletProximity to detect stylus and support til…
Browse files Browse the repository at this point in the history
…t for OS X. r=mstange, r=smaug
  • Loading branch information
mingchou committed Jan 10, 2017
1 parent 5df2341 commit 2b44bf8
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions widget/cocoa/nsChildView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@

static uint32_t gNumberOfWidgetsNeedingEventThread = 0;

static bool sIsTabletPointerActivated = false;

@interface ChildView(Private)

// sets up our view, attaching it to its owning gecko view
Expand All @@ -162,7 +164,8 @@ - (void) convertCocoaMouseWheelEvent:(NSEvent*)aMouseEvent
toGeckoEvent:(WidgetWheelEvent*)outWheelEvent;
- (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent
toGeckoEvent:(WidgetInputEvent*)outGeckoEvent;

- (void) convertCocoaTabletPointerEvent:(NSEvent*)aMouseEvent
toGeckoEvent:(WidgetMouseEvent*)outGeckoEvent;
- (NSMenu*)contextMenu;

- (BOOL)isRectObscuredBySubview:(NSRect)inRect;
Expand Down Expand Up @@ -5183,9 +5186,10 @@ - (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent
case NSOtherMouseDown:
case NSOtherMouseUp:
case NSOtherMouseDragged:
case NSMouseMoved:
if ([aMouseEvent subtype] == NSTabletPointEventSubtype) {
mouseEvent->pressure = [aMouseEvent pressure];
MOZ_ASSERT(mouseEvent->pressure >= 0.0 && mouseEvent->pressure <= 1.0);
[self convertCocoaTabletPointerEvent:aMouseEvent
toGeckoEvent:mouseEvent->AsMouseEvent()];
}
break;

Expand All @@ -5197,6 +5201,32 @@ - (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent
NS_OBJC_END_TRY_ABORT_BLOCK;
}

- (void) convertCocoaTabletPointerEvent:(NSEvent*)aPointerEvent
toGeckoEvent:(WidgetMouseEvent*)aOutGeckoEvent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN
if (!aOutGeckoEvent || !sIsTabletPointerActivated) {
return;
}
if ([aPointerEvent type] != NSMouseMoved) {
aOutGeckoEvent->pressure = [aPointerEvent pressure];
MOZ_ASSERT(aOutGeckoEvent->pressure >= 0.0 &&
aOutGeckoEvent->pressure <= 1.0);
}
aOutGeckoEvent->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_PEN;
aOutGeckoEvent->tiltX = lround([aPointerEvent tilt].x * 90);
aOutGeckoEvent->tiltY = lround([aPointerEvent tilt].y * 90);

NS_OBJC_END_TRY_ABORT_BLOCK;
}

- (void)tabletProximity:(NSEvent *)theEvent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN
sIsTabletPointerActivated = [theEvent isEnteringProximity];
NS_OBJC_END_TRY_ABORT_BLOCK
}

- (BOOL)shouldZoomOnDoubleClick
{
if ([NSWindow respondsToSelector:@selector(_shouldZoomOnDoubleClick)]) {
Expand Down

0 comments on commit 2b44bf8

Please sign in to comment.