From fbbfb2a75fbd0e9f6d80e2b386e66bd06fe647d8 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Fri, 14 Jan 2011 19:03:16 +0000 Subject: Scaling mouse coordinates svn path=/trunk/netsurf/; revision=11321 --- cocoa/BrowserView.m | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'cocoa/BrowserView.m') diff --git a/cocoa/BrowserView.m b/cocoa/BrowserView.m index 118da277f..74bdf7d24 100644 --- a/cocoa/BrowserView.m +++ b/cocoa/BrowserView.m @@ -135,17 +135,26 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) return result; } +- (NSPoint) convertMousePoint: (NSEvent *)event; +{ + NSPoint location = [self convertPoint: [event locationInWindow] fromView: nil]; + if (NULL != browser) { + location.x /= browser->scale; + location.y /= browser->scale; + } + return location; +} + - (void) mouseDown: (NSEvent *)theEvent; { - NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil]; - dragStart = location; + dragStart = [self convertMousePoint: theEvent]; - browser_window_mouse_click( browser, BROWSER_MOUSE_PRESS_1 | cocoa_mouse_flags_for_event( theEvent ), location.x, location.y ); + browser_window_mouse_click( browser, BROWSER_MOUSE_PRESS_1 | cocoa_mouse_flags_for_event( theEvent ), dragStart.x, dragStart.y ); } - (void) mouseUp: (NSEvent *)theEvent; { - NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + NSPoint location = [self convertMousePoint: theEvent]; browser_mouse_state modifierFlags = cocoa_mouse_flags_for_event( theEvent ); @@ -164,7 +173,7 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) - (void) mouseDragged: (NSEvent *)theEvent; { - NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + NSPoint location = [self convertMousePoint: theEvent]; if (!isDragging) { const CGFloat distance = squared( dragStart.x - location.x ) + squared( dragStart.y - location.y ); @@ -180,7 +189,7 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) - (void) mouseMoved: (NSEvent *)theEvent; { - NSPoint location = [self convertPoint: [theEvent locationInWindow] fromView: nil]; + NSPoint location = [self convertMousePoint: theEvent]; browser_window_mouse_track( browser, cocoa_mouse_flags_for_event( theEvent ), location.x, location.y ); } -- cgit v1.2.3