Make sure the cursor doesn't drift away when dragging window.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 6 Sep 2013 04:12:17 +0000 (12:12 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 6 Sep 2013 04:12:17 +0000 (12:12 +0800)
browser/native_window_mac.h
browser/native_window_mac.mm

index 6c485e7..ea359fa 100644 (file)
@@ -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);
 };
index e293074..d6858a1 100644 (file)
@@ -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)];
   }
 }