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 #import "chrome/browser/cocoa/hover_close_button.h" | 5 #import "chrome/browser/cocoa/hover_close_button.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/nsimage_cache_mac.h" | 8 #include "base/nsimage_cache_mac.h" |
| 9 #import "chrome/browser/cocoa/tab_controller.h" |
9 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 const NSString* kNormalImageString = @"close_bar.pdf"; | 14 const NSString* kNormalImageString = @"close_bar.pdf"; |
14 const NSString* kHoverImageString = @"close_bar_h.pdf"; | 15 const NSString* kHoverImageString = @"close_bar_h.pdf"; |
15 const NSString* kPressedImageString = @"close_bar_p.pdf"; | 16 const NSString* kPressedImageString = @"close_bar_p.pdf"; |
16 | 17 |
17 } | 18 } |
18 | 19 |
(...skipping 30 matching lines...) Expand all Loading... |
49 | 50 |
50 - (void)mouseEntered:(NSEvent*)theEvent { | 51 - (void)mouseEntered:(NSEvent*)theEvent { |
51 [self setImage:nsimage_cache::ImageNamed(kHoverImageString)]; | 52 [self setImage:nsimage_cache::ImageNamed(kHoverImageString)]; |
52 } | 53 } |
53 | 54 |
54 - (void)mouseExited:(NSEvent*)theEvent { | 55 - (void)mouseExited:(NSEvent*)theEvent { |
55 [self setImage:nsimage_cache::ImageNamed(kNormalImageString)]; | 56 [self setImage:nsimage_cache::ImageNamed(kNormalImageString)]; |
56 } | 57 } |
57 | 58 |
58 - (void)mouseDown:(NSEvent*)theEvent { | 59 - (void)mouseDown:(NSEvent*)theEvent { |
| 60 // controller_ is only set for close buttons in the tab strip. |
| 61 if (controller_ && ![controller_ closeButtonActive]) { |
| 62 [[controller_ view] mouseDown:theEvent]; |
| 63 return; |
| 64 } |
| 65 |
59 // The hover button needs to hold onto itself here for a bit. Otherwise, | 66 // The hover button needs to hold onto itself here for a bit. Otherwise, |
60 // it can be freed while |super mouseDown:| is in it's loop, and the | 67 // it can be freed while |super mouseDown:| is in it's loop, and the |
61 // |checkImageState| call will crash. | 68 // |checkImageState| call will crash. |
62 // http://crbug.com/28220 | 69 // http://crbug.com/28220 |
63 scoped_nsobject<HoverCloseButton> myself([self retain]); | 70 scoped_nsobject<HoverCloseButton> myself([self retain]); |
64 | 71 |
65 [super mouseDown:theEvent]; | 72 [super mouseDown:theEvent]; |
66 // We need to check the image state after the mouseDown event loop finishes. | 73 // We need to check the image state after the mouseDown event loop finishes. |
67 // It's possible that we won't get a mouseExited event if the button was | 74 // It's possible that we won't get a mouseExited event if the button was |
68 // moved under the mouse during tab resize, instead of the mouse moving over | 75 // moved under the mouse during tab resize, instead of the mouse moving over |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 kHoverImageString : kNormalImageString; | 116 kHoverImageString : kNormalImageString; |
110 NSImage* newImage = nsimage_cache::ImageNamed(name); | 117 NSImage* newImage = nsimage_cache::ImageNamed(name); |
111 NSImage* buttonImage = [self image]; | 118 NSImage* buttonImage = [self image]; |
112 if (![buttonImage isEqual:newImage]) { | 119 if (![buttonImage isEqual:newImage]) { |
113 [self setImage:newImage]; | 120 [self setImage:newImage]; |
114 } | 121 } |
115 } | 122 } |
116 } | 123 } |
117 | 124 |
118 @end | 125 @end |
OLD | NEW |