From b9d994dca280ddc231242b5d549d59ea4f310e2e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 6 Sep 2013 12:12:17 +0800 Subject: [PATCH] Make sure the cursor doesn't drift away when dragging window. --- browser/native_window_mac.h | 2 +- browser/native_window_mac.mm | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/browser/native_window_mac.h b/browser/native_window_mac.h index 6c485e7..ea359fa 100644 --- a/browser/native_window_mac.h +++ b/browser/native_window_mac.h @@ -98,7 +98,7 @@ class NativeWindowMac : public NativeWindow { // Mouse location since the last mouse event, in screen coordinates. This is // used in custom drag to compute the window movement. - NSPoint last_mouse_location_; + NSPoint last_mouse_offset_; DISALLOW_COPY_AND_ASSIGN(NativeWindowMac); }; diff --git a/browser/native_window_mac.mm b/browser/native_window_mac.mm index e293074..d6858a1 100644 --- a/browser/native_window_mac.mm +++ b/browser/native_window_mac.mm @@ -435,17 +435,18 @@ bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const { } void NativeWindowMac::HandleMouseEvent(NSEvent* event) { + NSPoint current_mouse_location = + [window() convertBaseToScreen:[event locationInWindow]]; + if ([event type] == NSLeftMouseDown) { - last_mouse_location_ = - [window() convertBaseToScreen:[event locationInWindow]]; - } else if ([event type] == NSLeftMouseDragged) { - NSPoint current_mouse_location = - [window() convertBaseToScreen:[event locationInWindow]]; NSPoint frame_origin = [window() frame].origin; - frame_origin.x += current_mouse_location.x - last_mouse_location_.x; - frame_origin.y += current_mouse_location.y - last_mouse_location_.y; - [window() setFrameOrigin:frame_origin]; - last_mouse_location_ = current_mouse_location; + last_mouse_offset_ = NSMakePoint( + frame_origin.x - current_mouse_location.x, + frame_origin.y - current_mouse_location.y); + } else if ([event type] == NSLeftMouseDragged) { + [window() setFrameOrigin:NSMakePoint( + current_mouse_location.x + last_mouse_offset_.x, + current_mouse_location.y + last_mouse_offset_.y)]; } } -- 2.7.4