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

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

Issue 8574068: Mac Panels interaction with Dock modifications. (step 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo Created 9 years, 1 month 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 293855b8e9a0a4e18c0fdb9c4576e88e892cc20b..add4c4ce42360bd6c4659bcc04a0911802545f09 100644
--- a/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm
@@ -24,6 +24,11 @@ const int kRoundedCornerSize = 3;
const int kButtonPadding = 8;
const int kIconAndTextPadding = 5;
+// Square of a distance that user needs to move the mouse in order to start the
+// drag. Threshold is needed to differentiate drags from attempts to click the
+// titlebar with a twitch of the mouse pointer.
+const int kDragThreasholdSquared = 9;
jennb 2011/11/17 23:45:40 typo: Threshold What's the logic behind using the
Dmitry Titov 2011/11/18 00:15:11 I'm computing a distance and don't want to do sqrt
+
// Used to implement TestingAPI
static NSEvent* MakeMouseEvent(NSEventType type,
NSPoint point,
@@ -317,6 +322,7 @@ static NSEvent* MakeMouseEvent(NSEventType type,
- (void)mouseDown:(NSEvent*)event {
dragState_ = PANEL_DRAG_CAN_START;
+ dragStartLocation_ = [event locationInWindow];
}
- (void)mouseUp:(NSEvent*)event {
@@ -326,6 +332,12 @@ static NSEvent* MakeMouseEvent(NSEventType type,
[controller_ onTitlebarMouseClicked];
}
+- (BOOL)overDragThreshold:(NSPoint)mouseLocation {
jennb 2011/11/17 23:45:40 exceedsDragThreshold? I'm not sure what overDragTh
Dmitry Titov 2011/11/18 00:15:11 Done.
+ float deltaX = dragStartLocation_.x - mouseLocation.x;
+ float deltaY = dragStartLocation_.y - mouseLocation.y;
+ return deltaX*deltaX + deltaY*deltaY > kDragThreasholdSquared;
jennb 2011/11/17 23:45:40 Please use parens rather than dropping the spacing
Dmitry Titov 2011/11/18 00:15:11 Done.
+}
+
- (void)mouseDragged:(NSEvent*)event {
// In addition to events needed to control the drag operation, fetch the right
// mouse click events and key down events and ignore them, to prevent their
@@ -345,8 +357,12 @@ static NSEvent* MakeMouseEvent(NSEventType type,
switch ([event type]) {
case NSLeftMouseDragged:
- if (dragState_ == PANEL_DRAG_CAN_START)
- [self startDrag];
+ if (dragState_ == PANEL_DRAG_CAN_START) {
+ if ([self overDragThreshold:[event locationInWindow]])
jennb 2011/11/17 23:45:40 nit: How about reversing this conditional to make
Dmitry Titov 2011/11/18 00:15:11 Done.
+ [self startDrag];
+ else
+ return; // Don't start real drag yet.
+ }
[self dragWithDeltaX:[event deltaX]];
break;
@@ -358,6 +374,10 @@ static NSEvent* MakeMouseEvent(NSEventType type,
break;
case NSLeftMouseUp:
+ if (dragState_ == PANEL_DRAG_CAN_START) { // Drag didn't really start.
+ [self mouseUp:event];
+ return;
jennb 2011/11/17 23:45:40 nit: I want to drop this return and add else claus
Dmitry Titov 2011/11/18 00:15:11 Done.
+ }
[self endDrag:NO];
keepGoing = NO;
break;

Powered by Google App Engine
This is Rietveld 408576698