diff options
Diffstat (limited to 'WebKit/chromium/src/mac/WebInputEventFactory.mm')
-rw-r--r-- | WebKit/chromium/src/mac/WebInputEventFactory.mm | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/WebKit/chromium/src/mac/WebInputEventFactory.mm b/WebKit/chromium/src/mac/WebInputEventFactory.mm index 46b0afe..55883c9 100644 --- a/WebKit/chromium/src/mac/WebInputEventFactory.mm +++ b/WebKit/chromium/src/mac/WebInputEventFactory.mm @@ -856,11 +856,36 @@ static inline int modifiersFromEvent(NSEvent* event) { modifiers |= WebInputEvent::AltKey; if ([event modifierFlags] & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey; + if ([event modifierFlags] & NSAlphaShiftKeyMask) + modifiers |= WebInputEvent::CapsLockOn; // TODO(port): Set mouse button states return modifiers; } +static inline void setWebEventLocationFromEventInView(WebMouseEvent* result, + NSEvent* event, + NSView* view) { + NSPoint windowLocal = [event locationInWindow]; + + NSPoint screenLocal = [[view window] convertBaseToScreen:windowLocal]; + result->globalX = screenLocal.x; + // Flip y. + NSScreen* primaryScreen = ([[NSScreen screens] count] > 0) ? + [[NSScreen screens] objectAtIndex:0] : nil; + if (primaryScreen) + result->globalY = [primaryScreen frame].size.height - screenLocal.y; + else + result->globalY = screenLocal.y; + + NSPoint contentLocal = [view convertPoint:windowLocal fromView:nil]; + result->x = contentLocal.x; + result->y = [view frame].size.height - contentLocal.y; // Flip y. + + result->windowX = result->x; + result->windowY = result->y; +} + WebKeyboardEvent WebInputEventFactory::keyboardEvent(NSEvent* event) { WebKeyboardEvent result; @@ -991,14 +1016,17 @@ WebMouseEvent WebInputEventFactory::mouseEvent(NSEvent* event, NSView* view) break; case NSLeftMouseUp: result.type = WebInputEvent::MouseUp; + result.clickCount = [event clickCount]; result.button = WebMouseEvent::ButtonLeft; break; case NSOtherMouseUp: result.type = WebInputEvent::MouseUp; + result.clickCount = [event clickCount]; result.button = WebMouseEvent::ButtonMiddle; break; case NSRightMouseUp: result.type = WebInputEvent::MouseUp; + result.clickCount = [event clickCount]; result.button = WebMouseEvent::ButtonRight; break; case NSMouseMoved: @@ -1021,16 +1049,7 @@ WebMouseEvent WebInputEventFactory::mouseEvent(NSEvent* event, NSView* view) ASSERT_NOT_REACHED(); } - NSPoint location = [NSEvent mouseLocation]; // global coordinates - result.globalX = location.x; - result.globalY = [[[view window] screen] frame].size.height - location.y; - - NSPoint windowLocal = [event locationInWindow]; - location = [view convertPoint:windowLocal fromView:nil]; - result.y = [view frame].size.height - location.y; // flip y - result.x = location.x; - result.windowX = result.x; - result.windowY = result.y; + setWebEventLocationFromEventInView(&result, event, view); result.modifiers = modifiersFromEvent(event); @@ -1050,16 +1069,7 @@ WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView* result.modifiers = modifiersFromEvent(event); - // Set coordinates by translating event coordinates from screen to client. - NSPoint location = [NSEvent mouseLocation]; // global coordinates - result.globalX = location.x; - result.globalY = location.y; - NSPoint windowLocal = [event locationInWindow]; - location = [view convertPoint:windowLocal fromView:nil]; - result.x = location.x; - result.y = [view frame].size.height - location.y; // flip y - result.windowX = result.x; - result.windowY = result.y; + setWebEventLocationFromEventInView(&result, event, view); // Of Mice and Men // --------------- @@ -1173,22 +1183,19 @@ WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView* // the point delta data instead, since we cannot distinguish trackpad data // from data from any other continuous device. + // Conversion between wheel delta amounts and number of pixels to scroll. + static const double scrollbarPixelsPerCocoaTick = 40.0; + if (CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventIsContinuous)) { - result.wheelTicksY = result.deltaY = - CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1); - result.wheelTicksX = result.deltaX = - CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis2); + result.deltaX = CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis2); + result.deltaY = CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1); + result.wheelTicksX = result.deltaX / scrollbarPixelsPerCocoaTick; + result.wheelTicksY = result.deltaY / scrollbarPixelsPerCocoaTick; } else { - result.wheelTicksY = - CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis1); - result.wheelTicksX = - CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis2); - - // Convert wheel delta amount to a number of pixels to scroll. - static const double scrollbarPixelsPerCocoaTick = 40.0; - result.deltaX = [event deltaX] * scrollbarPixelsPerCocoaTick; result.deltaY = [event deltaY] * scrollbarPixelsPerCocoaTick; + result.wheelTicksY = CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis1); + result.wheelTicksX = CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis2); } result.timeStampSeconds = [event timestamp]; |