Make sure the cursor doesn't drift away when dragging window.
This commit is contained in:
parent
b7c2295a1c
commit
b9d994dca2
2 changed files with 11 additions and 10 deletions
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -435,17 +435,18 @@ bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
|||
}
|
||||
|
||||
void NativeWindowMac::HandleMouseEvent(NSEvent* event) {
|
||||
if ([event type] == NSLeftMouseDown) {
|
||||
last_mouse_location_ =
|
||||
[window() convertBaseToScreen:[event locationInWindow]];
|
||||
} else if ([event type] == NSLeftMouseDragged) {
|
||||
NSPoint current_mouse_location =
|
||||
[window() convertBaseToScreen:[event locationInWindow]];
|
||||
|
||||
if ([event type] == NSLeftMouseDown) {
|
||||
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)];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue