pass modifier keys to click events (e.g. control | shift etc.)
Review URL: https://codereview.appspot.com/7062054
git-svn-id: http://skia.googlecode.com/svn/trunk@7082 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm
index ffa9d7c..fc82ac4 100644
--- a/src/views/mac/SkNSView.mm
+++ b/src/views/mac/SkNSView.mm
@@ -192,35 +192,68 @@
// unichar c = [[event characters] characterAtIndex:0];
}
+static const struct {
+ unsigned fNSModifierMask;
+ unsigned fSkModifierMask;
+} gModifierMasks[] = {
+ { NSAlphaShiftKeyMask, kShift_SkModifierKey },
+ { NSShiftKeyMask, kShift_SkModifierKey },
+ { NSControlKeyMask, kControl_SkModifierKey },
+ { NSAlternateKeyMask, kOption_SkModifierKey },
+ { NSCommandKeyMask, kCommand_SkModifierKey },
+};
+
+static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
+ unsigned skModi = 0;
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gModifierMasks); ++i) {
+ if (nsModi & gModifierMasks[i].fNSModifierMask) {
+ skModi |= gModifierMasks[i].fSkModifierMask;
+ }
+ }
+ return skModi;
+}
+
- (void)mouseDown:(NSEvent *)event {
NSPoint p = [event locationInWindow];
+ unsigned modi = convertNSModifiersToSk([event modifierFlags]);
+
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
- fWind->handleClick((int) loc.x, (int) loc.y, SkView::Click::kDown_State, self);
+ fWind->handleClick((int) loc.x, (int) loc.y,
+ SkView::Click::kDown_State, self, modi);
}
}
- (void)mouseDragged:(NSEvent *)event {
NSPoint p = [event locationInWindow];
+ unsigned modi = convertNSModifiersToSk([event modifierFlags]);
+
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
- fWind->handleClick((int) loc.x, (int) loc.y, SkView::Click::kMoved_State, self);
+ fWind->handleClick((int) loc.x, (int) loc.y,
+ SkView::Click::kMoved_State, self, modi);
}
}
- (void)mouseMoved:(NSEvent *)event {
NSPoint p = [event locationInWindow];
+ unsigned modi = convertNSModifiersToSk([event modifierFlags]);
+
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
- fWind->handleClick((int) loc.x, (int) loc.y, SkView::Click::kMoved_State, self);
+ fWind->handleClick((int) loc.x, (int) loc.y,
+ SkView::Click::kMoved_State, self, modi);
}
}
- (void)mouseUp:(NSEvent *)event {
NSPoint p = [event locationInWindow];
+ unsigned modi = convertNSModifiersToSk([event modifierFlags]);
+
if ([self mouse:p inRect:[self bounds]] && NULL != fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
- fWind->handleClick((int) loc.x, (int) loc.y, SkView::Click::kUp_State, self);
+ fWind->handleClick((int) loc.x, (int) loc.y,
+ SkView::Click::kUp_State, self, modi);
}
}