OLD | NEW |
---|---|
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_controller.h" | 5 #include "chrome/browser/cocoa/tab_controller.h" |
6 #include "chrome/browser/cocoa/tab_view.h" | 6 #include "chrome/browser/cocoa/tab_view.h" |
7 #include "chrome/browser/cocoa/tab_window_controller.h" | 7 #include "chrome/browser/cocoa/tab_window_controller.h" |
8 | 8 |
9 @implementation TabView | 9 @implementation TabView |
10 | 10 |
11 - (id)initWithFrame:(NSRect)frame { | 11 - (id)initWithFrame:(NSRect)frame { |
12 self = [super initWithFrame:frame]; | 12 self = [super initWithFrame:frame]; |
13 if (self) { | 13 if (self) { |
14 // TODO(alcor): register for theming, either here or the cell | 14 // TODO(alcor): register for theming, either here or the cell |
15 // [self gtm_registerForThemeNotifications]; | 15 // [self gtm_registerForThemeNotifications]; |
16 } | 16 } |
17 return self; | 17 return self; |
18 } | 18 } |
19 | 19 |
20 - (void)awakeFromNib { | |
21 // Set up the tracking rect for the close button mouseover. Add it | |
22 // to the |closeButton_| view, but we'll handle the message ourself. | |
23 // The mouseover is always enabled, because the close button works | |
24 // regardless of key/main/active status. | |
25 trackingArea_.reset( | |
26 [[NSTrackingArea alloc] initWithRect:[closeButton_ bounds] | |
27 options:NSTrackingMouseEnteredAndExited | | |
28 NSTrackingActiveAlways | |
29 owner:self | |
pink (ping after 24hrs)
2009/05/27 13:07:59
are you sure this doesn't set up an ownership cycl
rohitrao (ping after 24h)
2009/05/27 23:58:50
I added logging in dealloc and verified that deall
| |
30 userInfo:nil]); | |
31 [closeButton_ addTrackingArea:trackingArea_.get()]; | |
32 } | |
33 | |
20 - (void)dealloc { | 34 - (void)dealloc { |
21 // [self gtm_unregisterForThemeNotifications]; | 35 // [self gtm_unregisterForThemeNotifications]; |
36 [closeButton_ removeTrackingArea:trackingArea_.get()]; | |
22 [super dealloc]; | 37 [super dealloc]; |
23 } | 38 } |
24 | 39 |
25 // Overridden so that mouse clicks come to this view (the parent of the | 40 // Overridden so that mouse clicks come to this view (the parent of the |
26 // hierarchy) first. We want to handle clicks and drags in this class and | 41 // hierarchy) first. We want to handle clicks and drags in this class and |
27 // leave the background button for display purposes only. | 42 // leave the background button for display purposes only. |
28 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { | 43 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent { |
29 return YES; | 44 return YES; |
30 } | 45 } |
31 | 46 |
47 - (void)mouseEntered:(NSEvent *)theEvent { | |
48 // We only set up one tracking area, so we know any mouseEntered: | |
49 // messages are for close button mouseovers. | |
50 [closeButton_ setImage:[NSImage imageNamed:@"close_bar_h"]]; | |
51 } | |
52 | |
53 - (void)mouseExited:(NSEvent *)theEvent { | |
54 // We only set up one tracking area, so we know any mouseExited: | |
55 // messages are for close button mouseovers. | |
56 [closeButton_ setImage:[NSImage imageNamed:@"close_bar"]]; | |
57 } | |
58 | |
32 // Determines which view a click in our frame actually hit. It's either this | 59 // Determines which view a click in our frame actually hit. It's either this |
33 // view or our child close button. | 60 // view or our child close button. |
34 - (NSView *)hitTest:(NSPoint)aPoint { | 61 - (NSView *)hitTest:(NSPoint)aPoint { |
35 NSPoint viewPoint = [self convertPoint:aPoint fromView:[self superview]]; | 62 NSPoint viewPoint = [self convertPoint:aPoint fromView:[self superview]]; |
36 NSRect frame = [self frame]; | 63 NSRect frame = [self frame]; |
37 | 64 |
38 // Reduce the width of the hit rect slightly to remove the overlap | 65 // Reduce the width of the hit rect slightly to remove the overlap |
39 // between adjacent tabs. The drawing code in TabCell has the top | 66 // between adjacent tabs. The drawing code in TabCell has the top |
40 // corners of the tab inset by height*2/3, so we inset by half of | 67 // corners of the tab inset by height*2/3, so we inset by half of |
41 // that here. This doesn't completely eliminate the overlap, but it | 68 // that here. This doesn't completely eliminate the overlap, but it |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 } | 352 } |
326 | 353 |
327 - (void)otherMouseUp:(NSEvent*) theEvent { | 354 - (void)otherMouseUp:(NSEvent*) theEvent { |
328 // Support middle-click-to-close. | 355 // Support middle-click-to-close. |
329 if ([theEvent buttonNumber] == 2) { | 356 if ([theEvent buttonNumber] == 2) { |
330 [controller_ closeTab:self]; | 357 [controller_ closeTab:self]; |
331 } | 358 } |
332 } | 359 } |
333 | 360 |
334 @end | 361 @end |
OLD | NEW |