Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Unified Diff: chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm

Issue 9616037: Change panel drag related methods to use mouse location in screen coordinates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac trybot Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
diff --git a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
index f637494ac95ed9f19e0ef0f0df412e1817f0b593..7725de2530e35c184a79af87e815df1bf1de4a8e 100644
--- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
@@ -392,7 +392,8 @@ static NSEvent* MakeMouseEvent(NSEventType type,
- (void)mouseDown:(NSEvent*)event {
if ([controller_ isDraggable]) {
dragState_ = PANEL_DRAG_CAN_START;
- dragStartLocation_ = [event locationInWindow];
+ dragStartLocation_ =
+ [[self window] convertBaseToScreen:[event locationInWindow]];
}
}
@@ -406,7 +407,7 @@ static NSEvent* MakeMouseEvent(NSEventType type,
- (BOOL)exceedsDragThreshold:(NSPoint)mouseLocation {
float deltaX = dragStartLocation_.x - mouseLocation.x;
float deltaY = dragStartLocation_.y - mouseLocation.y;
- return deltaX > kDragThreshold || deltaY > kDragThreshold;
+ return fabs(deltaX) > kDragThreshold || fabs(deltaY) > kDragThreshold;
}
- (void)mouseDragged:(NSEvent*)event {
@@ -430,15 +431,19 @@ static NSEvent* MakeMouseEvent(NSEventType type,
dequeue:YES];
switch ([event type]) {
- case NSLeftMouseDragged:
+ case NSLeftMouseDragged: {
+ // Get current mouse location in screen coordinates.
+ NSPoint mouseLocation =
+ [[self window] convertBaseToScreen:[event locationInWindow]];
if (dragState_ == PANEL_DRAG_CAN_START) {
- if (![self exceedsDragThreshold:[event locationInWindow]])
+ if (![self exceedsDragThreshold:mouseLocation])
return; // Don't start real drag yet.
- [self startDrag];
+ [self startDrag:dragStartLocation_];
}
- [self dragWithDeltaX:[event deltaX]
- deltaY:[event deltaY]];
+ if (dragState_ == PANEL_DRAG_IN_PROGRESS)
+ [self drag:mouseLocation];
break;
+ }
case NSKeyUp:
if ([event keyCode] == kVK_Escape) {
@@ -468,10 +473,10 @@ static NSEvent* MakeMouseEvent(NSEventType type,
}
}
-- (void)startDrag {
+- (void)startDrag:(NSPoint)mouseLocation {
DCHECK(dragState_ == PANEL_DRAG_CAN_START);
dragState_ = PANEL_DRAG_IN_PROGRESS;
- [controller_ startDrag];
+ [controller_ startDrag:mouseLocation];
}
- (void)endDrag:(BOOL)cancelled {
@@ -480,12 +485,10 @@ static NSEvent* MakeMouseEvent(NSEventType type,
dragState_ = PANEL_DRAG_SUPPRESSED;
}
-- (void)dragWithDeltaX:(int)deltaX
- deltaY:(int)deltaY {
+- (void)drag:(NSPoint)mouseLocation {
if (dragState_ != PANEL_DRAG_IN_PROGRESS)
return;
- [controller_ dragWithDeltaX:deltaX
- deltaY:deltaY];
+ [controller_ drag:mouseLocation];
}
- (void)drawAttention {
@@ -569,8 +572,9 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[[closeButton_ cell] performClick:closeButton_];
}
-- (void)pressLeftMouseButtonTitlebar {
- NSEvent* event = MakeMouseEvent(NSLeftMouseDown, NSZeroPoint, 0);
+- (void)pressLeftMouseButtonTitlebar:(NSPoint)mouseLocation {
+ NSEvent* event = MakeMouseEvent(
+ NSLeftMouseDown, [[self window] convertScreenToBase:mouseLocation], 0);
[self mouseDown:event];
}
@@ -579,12 +583,10 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[self mouseUp:event];
}
-- (void)dragTitlebarDeltaX:(double)delta_x
- deltaY:(double)delta_y {
+- (void)dragTitlebar:(NSPoint)mouseLocation {
if (dragState_ == PANEL_DRAG_CAN_START)
- [self startDrag];
- [self dragWithDeltaX:delta_x
- deltaY:delta_y];
+ [self startDrag:dragStartLocation_];
+ [self drag:mouseLocation];
}
- (void)cancelDragTitlebar {

Powered by Google App Engine
This is Rietveld 408576698