summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/tab_view.mm
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 13:40:24 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-01 13:40:24 +0000
commitc8ff5088b569fa422e37d87db20b770e1e5476ef (patch)
tree780703a7a1511e6c47d404ad40f986ecb6847894 /chrome/browser/cocoa/tab_view.mm
parent27a126d6b700e05534deb0e947f25f342ff3fa42 (diff)
downloadchromium_src-c8ff5088b569fa422e37d87db20b770e1e5476ef.zip
chromium_src-c8ff5088b569fa422e37d87db20b770e1e5476ef.tar.gz
chromium_src-c8ff5088b569fa422e37d87db20b770e1e5476ef.tar.bz2
(Mac) Make mashing the close tab button work.
To do this, I had to commit several crimes against humanity. In particular, Cocoa doesn't generate the required extra hit tests during animations, so we have to. Sometimes, it gets really messed up and ends up hitting the "drag blocking view". Moreover, we have to account for the possibility of the mouse down hitting a moving tab, and going up on the close button, etc. BUG=17720 TEST=Mash the close tabs button under a wide variety of situations. \ Also make sure that the handling of the tabs (dragging, etc.) \ hasn't accidentally been messed up. Review URL: http://codereview.chromium.org/174461 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25029 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/tab_view.mm')
-rw-r--r--chrome/browser/cocoa/tab_view.mm42
1 files changed, 39 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/tab_view.mm b/chrome/browser/cocoa/tab_view.mm
index 16074e9..351882c 100644
--- a/chrome/browser/cocoa/tab_view.mm
+++ b/chrome/browser/cocoa/tab_view.mm
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/cocoa/tab_view.h"
+
#include "chrome/browser/cocoa/nsimage_cache.h"
#include "chrome/browser/cocoa/tab_controller.h"
-#include "chrome/browser/cocoa/tab_view.h"
#include "chrome/browser/cocoa/tab_window_controller.h"
-
// Constants for inset and control points for tab shape.
static const CGFloat kInsetMultiplier = 2.0/3.0;
static const CGFloat kControlPoint1Multiplier = 1.0/3.0;
@@ -150,9 +150,27 @@ static const NSTimeInterval kAnimationHideDuration = 0.4;
static const CGFloat kTearDistance = 36.0;
static const NSTimeInterval kTearDuration = 0.333;
-static const double kDragStartDistance = 3.0;
+
+// This is used to judge whether the mouse has moved during rapid closure; if it
+// has moved less than the threshold, we want to close the tab.
+static const CGFloat kRapidCloseDist = 2.5;
- (void)mouseDown:(NSEvent *)theEvent {
+ NSPoint downLocation = [theEvent locationInWindow];
+
+ // During the tab closure animation (in particular, during rapid tab closure),
+ // we may get incorrectly hit with a mouse down. If it should have gone to the
+ // close button, we send it there -- it should then track the mouse, so we
+ // don't have to worry about mouse ups.
+ if ([controller_ inRapidClosureMode]) {
+ NSPoint hitLocation = [[self superview] convertPoint:downLocation
+ fromView:nil];
+ if ([self hitTest:hitLocation] == closeButton_) {
+ [closeButton_ mouseDown:theEvent];
+ return;
+ }
+ }
+
// Fire the action to select the tab.
if ([[controller_ target] respondsToSelector:[controller_ action]])
[[controller_ target] performSelector:[controller_ action]
@@ -198,6 +216,24 @@ static const double kDragStartDistance = 3.0;
if (type == NSLeftMouseDragged) {
[self mouseDragged:theEvent];
} else { // Mouse Up
+ NSPoint upLocation = [theEvent locationInWindow];
+ CGFloat dx = upLocation.x - downLocation.x;
+ CGFloat dy = upLocation.y - downLocation.y;
+
+ // During rapid tab closure (mashing tab close buttons), we may get hit
+ // with a mouse down. As long as the mouse up is over the close button,
+ // and the mouse hasn't moved too much, we close the tab.
+ if ((dx*dx + dy*dy) <= kRapidCloseDist*kRapidCloseDist &&
+ [controller_ inRapidClosureMode]) {
+ NSPoint hitLocation =
+ [[self superview] convertPoint:[theEvent locationInWindow]
+ fromView:nil];
+ if ([self hitTest:hitLocation] == closeButton_) {
+ [controller_ closeTab:self];
+ break;
+ }
+ }
+
[self mouseUp:theEvent];
break;
}