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

Side by Side Diff: chrome/browser/cocoa/tab_view.mm

Issue 174461: (Mac) Make mashing the close tab button work. (Closed)
Patch Set: Rebased to ToT. Created 11 years, 3 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/cocoa/tab_strip_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/cocoa/tab_view.h"
6
5 #include "chrome/browser/cocoa/nsimage_cache.h" 7 #include "chrome/browser/cocoa/nsimage_cache.h"
6 #include "chrome/browser/cocoa/tab_controller.h" 8 #include "chrome/browser/cocoa/tab_controller.h"
7 #include "chrome/browser/cocoa/tab_view.h"
8 #include "chrome/browser/cocoa/tab_window_controller.h" 9 #include "chrome/browser/cocoa/tab_window_controller.h"
9 10
10
11 // Constants for inset and control points for tab shape. 11 // Constants for inset and control points for tab shape.
12 static const CGFloat kInsetMultiplier = 2.0/3.0; 12 static const CGFloat kInsetMultiplier = 2.0/3.0;
13 static const CGFloat kControlPoint1Multiplier = 1.0/3.0; 13 static const CGFloat kControlPoint1Multiplier = 1.0/3.0;
14 static const CGFloat kControlPoint2Multiplier = 3.0/8.0; 14 static const CGFloat kControlPoint2Multiplier = 3.0/8.0;
15 15
16 static const NSTimeInterval kAnimationShowDuration = 0.2; 16 static const NSTimeInterval kAnimationShowDuration = 0.2;
17 static const NSTimeInterval kAnimationHideDuration = 0.4; 17 static const NSTimeInterval kAnimationHideDuration = 0.4;
18 18
19 @implementation TabView 19 @implementation TabView
20 20
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 143 }
144 144
145 // Handle clicks and drags in this button. We get here because we have 145 // Handle clicks and drags in this button. We get here because we have
146 // overridden acceptsFirstMouse: and the click is within our bounds. 146 // overridden acceptsFirstMouse: and the click is within our bounds.
147 // TODO(pinkerton/alcor): This routine needs *a lot* of work to marry Cole's 147 // TODO(pinkerton/alcor): This routine needs *a lot* of work to marry Cole's
148 // ideas of dragging cocoa views between windows and how the Browser and 148 // ideas of dragging cocoa views between windows and how the Browser and
149 // TabStrip models want to manage tabs. 149 // TabStrip models want to manage tabs.
150 150
151 static const CGFloat kTearDistance = 36.0; 151 static const CGFloat kTearDistance = 36.0;
152 static const NSTimeInterval kTearDuration = 0.333; 152 static const NSTimeInterval kTearDuration = 0.333;
153 static const double kDragStartDistance = 3.0; 153
154 // This is used to judge whether the mouse has moved during rapid closure; if it
155 // has moved less than the threshold, we want to close the tab.
156 static const CGFloat kRapidCloseDist = 2.5;
154 157
155 - (void)mouseDown:(NSEvent *)theEvent { 158 - (void)mouseDown:(NSEvent *)theEvent {
159 NSPoint downLocation = [theEvent locationInWindow];
160
161 // During the tab closure animation (in particular, during rapid tab closure),
162 // we may get incorrectly hit with a mouse down. If it should have gone to the
163 // close button, we send it there -- it should then track the mouse, so we
164 // don't have to worry about mouse ups.
165 if ([controller_ inRapidClosureMode]) {
166 NSPoint hitLocation = [[self superview] convertPoint:downLocation
167 fromView:nil];
168 if ([self hitTest:hitLocation] == closeButton_) {
169 [closeButton_ mouseDown:theEvent];
170 return;
171 }
172 }
173
156 // Fire the action to select the tab. 174 // Fire the action to select the tab.
157 if ([[controller_ target] respondsToSelector:[controller_ action]]) 175 if ([[controller_ target] respondsToSelector:[controller_ action]])
158 [[controller_ target] performSelector:[controller_ action] 176 [[controller_ target] performSelector:[controller_ action]
159 withObject:self]; 177 withObject:self];
160 178
161 // Resolve overlay back to original window. 179 // Resolve overlay back to original window.
162 sourceWindow_ = [self window]; 180 sourceWindow_ = [self window];
163 if ([sourceWindow_ isKindOfClass:[NSPanel class]]) { 181 if ([sourceWindow_ isKindOfClass:[NSPanel class]]) {
164 sourceWindow_ = [sourceWindow_ parentWindow]; 182 sourceWindow_ = [sourceWindow_ parentWindow];
165 } 183 }
(...skipping 25 matching lines...) Expand all
191 theEvent = 209 theEvent =
192 [NSApp nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask 210 [NSApp nextEventMatchingMask:NSLeftMouseUpMask | NSLeftMouseDraggedMask
193 untilDate:[NSDate distantFuture] 211 untilDate:[NSDate distantFuture]
194 inMode:NSDefaultRunLoopMode dequeue:YES]; 212 inMode:NSDefaultRunLoopMode dequeue:YES];
195 NSPoint thisPoint = [NSEvent mouseLocation]; 213 NSPoint thisPoint = [NSEvent mouseLocation];
196 214
197 NSEventType type = [theEvent type]; 215 NSEventType type = [theEvent type];
198 if (type == NSLeftMouseDragged) { 216 if (type == NSLeftMouseDragged) {
199 [self mouseDragged:theEvent]; 217 [self mouseDragged:theEvent];
200 } else { // Mouse Up 218 } else { // Mouse Up
219 NSPoint upLocation = [theEvent locationInWindow];
220 CGFloat dx = upLocation.x - downLocation.x;
221 CGFloat dy = upLocation.y - downLocation.y;
222
223 // During rapid tab closure (mashing tab close buttons), we may get hit
224 // with a mouse down. As long as the mouse up is over the close button,
225 // and the mouse hasn't moved too much, we close the tab.
226 if ((dx*dx + dy*dy) <= kRapidCloseDist*kRapidCloseDist &&
227 [controller_ inRapidClosureMode]) {
228 NSPoint hitLocation =
229 [[self superview] convertPoint:[theEvent locationInWindow]
230 fromView:nil];
231 if ([self hitTest:hitLocation] == closeButton_) {
232 [controller_ closeTab:self];
233 break;
234 }
235 }
236
201 [self mouseUp:theEvent]; 237 [self mouseUp:theEvent];
202 break; 238 break;
203 } 239 }
204 } 240 }
205 } 241 }
206 242
207 - (void)mouseDragged:(NSEvent *)theEvent { 243 - (void)mouseDragged:(NSEvent *)theEvent {
208 // Special-case this to keep the logic below simpler. 244 // Special-case this to keep the logic below simpler.
209 if (moveWindowOnDrag_) { 245 if (moveWindowOnDrag_) {
210 NSPoint thisPoint = [NSEvent mouseLocation]; 246 NSPoint thisPoint = [NSEvent mouseLocation];
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 [[NSGraphicsContext currentContext] restoreGraphicsState]; 649 [[NSGraphicsContext currentContext] restoreGraphicsState];
614 } 650 }
615 651
616 // Called when the user hits the right mouse button (or control-clicks) to 652 // Called when the user hits the right mouse button (or control-clicks) to
617 // show a context menu. 653 // show a context menu.
618 - (void)rightMouseDown:(NSEvent*)theEvent { 654 - (void)rightMouseDown:(NSEvent*)theEvent {
619 [NSMenu popUpContextMenu:[self menu] withEvent:theEvent forView:self]; 655 [NSMenu popUpContextMenu:[self menu] withEvent:theEvent forView:self];
620 } 656 }
621 657
622 @end 658 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/tab_strip_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698