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

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

Issue 2314873004: Fix bug that causes spurious tab switches. (Closed)
Patch Set: Created 4 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 | « no previous file | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 5 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/sdk_forward_declarations.h" 9 #include "base/mac/sdk_forward_declarations.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 29 matching lines...) Expand all
40 const NSTimeInterval kHoverHoldDuration = 0.02; 40 const NSTimeInterval kHoverHoldDuration = 0.02;
41 const NSTimeInterval kHoverHideDuration = 0.4; 41 const NSTimeInterval kHoverHideDuration = 0.4;
42 const NSTimeInterval kAlertShowDuration = 0.4; 42 const NSTimeInterval kAlertShowDuration = 0.4;
43 const NSTimeInterval kAlertHoldDuration = 0.4; 43 const NSTimeInterval kAlertHoldDuration = 0.4;
44 const NSTimeInterval kAlertHideDuration = 0.4; 44 const NSTimeInterval kAlertHideDuration = 0.4;
45 45
46 // The default time interval in seconds between glow updates (when 46 // The default time interval in seconds between glow updates (when
47 // increasing/decreasing). 47 // increasing/decreasing).
48 const NSTimeInterval kGlowUpdateInterval = 0.025; 48 const NSTimeInterval kGlowUpdateInterval = 0.025;
49 49
50 // This is used to judge whether the mouse has moved during rapid closure; if it
51 // has moved less than the threshold, we want to close the tab.
52 const CGFloat kRapidCloseDist = 2.5;
53
54 // This class contains the logic for drawing Material Design tab images. The 50 // This class contains the logic for drawing Material Design tab images. The
55 // |setTabEdgeStrokeColor| method is overridden by |TabHeavyImageMaker| to draw 51 // |setTabEdgeStrokeColor| method is overridden by |TabHeavyImageMaker| to draw
56 // high-contrast tabs. 52 // high-contrast tabs.
57 @interface TabImageMaker : NSObject 53 @interface TabImageMaker : NSObject
58 + (void)drawTabLeftMaskImage; 54 + (void)drawTabLeftMaskImage;
59 + (void)drawTabRightMaskImage; 55 + (void)drawTabRightMaskImage;
60 + (void)drawTabLeftEdgeImage; 56 + (void)drawTabLeftEdgeImage;
61 + (void)drawTabMiddleEdgeImage; 57 + (void)drawTabMiddleEdgeImage;
62 + (void)drawTabRightEdgeImage; 58 + (void)drawTabRightEdgeImage;
63 + (void)setTabEdgeStrokeColor; 59 + (void)setTabEdgeStrokeColor;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 333
338 // Try to initiate a drag. This will spin a custom event loop and may 334 // Try to initiate a drag. This will spin a custom event loop and may
339 // dispatch other mouse events. 335 // dispatch other mouse events.
340 [controller_ maybeStartDrag:theEvent forTab:controller]; 336 [controller_ maybeStartDrag:theEvent forTab:controller];
341 337
342 // The custom loop has ended, so clear the point. 338 // The custom loop has ended, so clear the point.
343 mouseDownPoint_ = NSZeroPoint; 339 mouseDownPoint_ = NSZeroPoint;
344 } 340 }
345 341
346 - (void)mouseUp:(NSEvent*)theEvent { 342 - (void)mouseUp:(NSEvent*)theEvent {
347 // Check for rapid tab closure. 343 // This method intentionally forwards to the super implementation without
348 if ([theEvent type] == NSLeftMouseUp) { 344 // doing anything. mouseDown: triggers a nested run loop that swallows the
349 NSPoint upLocation = [theEvent locationInWindow]; 345 // mouseUp: event, so we never expect a meaningful mouseUp: on a TabView.
350 CGFloat dx = upLocation.x - mouseDownPoint_.x; 346 // There's a bug in AppKit that triggers mouseUp: callbacks on inappropriate
351 CGFloat dy = upLocation.y - mouseDownPoint_.y; 347 // views, so it's doubly important that this method doesn't do anything.
352 348 // https://crbug.com/511095.
353 // During rapid tab closure (mashing tab close buttons), we may get hit 349 [super mouseUp:theEvent];
Robert Sesek 2016/09/08 15:15:12 Why is this no longer necesary?
erikchen 2016/09/08 17:09:46 Whoops, still needed.
354 // with a mouse down. As long as the mouse up is over the close button,
355 // and the mouse hasn't moved too much, we close the tab.
356 if (![closeButton_ isHidden] &&
357 (dx*dx + dy*dy) <= kRapidCloseDist*kRapidCloseDist &&
358 [controller_ inRapidClosureMode]) {
359 NSPoint hitLocation =
360 [[self superview] convertPoint:[theEvent locationInWindow]
361 fromView:nil];
362 if ([self hitTest:hitLocation] == closeButton_) {
363 [controller_ closeTab:self];
364 return;
365 }
366 }
367 }
368
369 // Fire the action to select the tab.
370 [controller_ selectTab:self];
Robert Sesek 2016/09/08 15:15:12 This is no longer necessary because the super trig
erikchen 2016/09/08 17:09:46 The nested run loop in -[TabStripDragController ma
371
372 // Messaging the drag controller with |-endDrag:| would seem like the right
373 // thing to do here. But, when a tab has been detached, the controller's
374 // target is nil until the drag is finalized. Since |-mouseUp:| gets called
375 // via the manual event loop inside -[TabStripDragController
376 // maybeStartDrag:forTab:], the drag controller can end the dragging session
377 // itself directly after calling this.
378 } 350 }
379 351
380 - (void)otherMouseUp:(NSEvent*)theEvent { 352 - (void)otherMouseUp:(NSEvent*)theEvent {
381 if ([self isClosing]) 353 if ([self isClosing])
382 return; 354 return;
383 355
384 // Support middle-click-to-close. 356 // Support middle-click-to-close.
385 if ([theEvent buttonNumber] == 2) { 357 if ([theEvent buttonNumber] == 2) {
386 // |-hitTest:| takes a location in the superview's coordinates. 358 // |-hitTest:| takes a location in the superview's coordinates.
387 NSPoint upLocation = 359 NSPoint upLocation =
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1003
1032 // For "Increase Contrast" mode, use flat black instead of semitransparent black 1004 // For "Increase Contrast" mode, use flat black instead of semitransparent black
1033 // for the tab edge stroke. 1005 // for the tab edge stroke.
1034 + (void)setTabEdgeStrokeColor { 1006 + (void)setTabEdgeStrokeColor {
1035 static NSColor* heavyStrokeColor = 1007 static NSColor* heavyStrokeColor =
1036 [skia::SkColorToSRGBNSColor(SK_ColorBLACK) retain]; 1008 [skia::SkColorToSRGBNSColor(SK_ColorBLACK) retain];
1037 [heavyStrokeColor set]; 1009 [heavyStrokeColor set];
1038 } 1010 }
1039 1011
1040 @end 1012 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698