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

Side by Side Diff: chrome/browser/ui/cocoa/hover_close_button.mm

Issue 2898343002: [Mac] Update tab close button when user drags outside (Closed)
Patch Set: Add retain, comment on key events. Created 3 years, 6 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 | ui/base/cocoa/hover_button.h » ('j') | 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/hover_close_button.h" 5 #import "chrome/browser/ui/cocoa/hover_close_button.h"
6 6
7 #include "base/strings/sys_string_conversions.h" 7 #include "base/strings/sys_string_conversions.h"
8 #include "chrome/app/vector_icons/vector_icons.h" 8 #include "chrome/app/vector_icons/vector_icons.h"
9 #include "chrome/grit/generated_resources.h" 9 #include "chrome/grit/generated_resources.h"
10 #include "components/strings/grit/components_strings.h" 10 #include "components/strings/grit/components_strings.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 + (void)initialize { 52 + (void)initialize {
53 // Grab some strings that are used by all close buttons. 53 // Grab some strings that are used by all close buttons.
54 if (!gBasicAccessibilityTitle) { 54 if (!gBasicAccessibilityTitle) {
55 gBasicAccessibilityTitle = [l10n_util::GetNSStringWithFixup( 55 gBasicAccessibilityTitle = [l10n_util::GetNSStringWithFixup(
56 IDS_ACCNAME_CLOSE) copy]; 56 IDS_ACCNAME_CLOSE) copy];
57 } 57 }
58 if (!gTooltip) 58 if (!gTooltip)
59 gTooltip = [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_CLOSE_TAB) copy]; 59 gTooltip = [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_CLOSE_TAB) copy];
60 } 60 }
61 61
62 - (id)initWithFrame:(NSRect)frameRect { 62 - (void)commonInit {
63 if ((self = [super initWithFrame:frameRect])) { 63 [super commonInit];
64 [self commonInit];
65 }
66 return self;
67 }
68 64
69 - (void)awakeFromNib { 65 [self setAccessibilityTitle:nil];
70 [super awakeFromNib]; 66
71 [self commonInit]; 67 // Add a tooltip. Using 'owner:self' means that
68 // -view:stringForToolTip:point:userData: will be called to provide the
69 // tooltip contents immediately before showing it.
70 [self addToolTipRect:[self bounds] owner:self userData:NULL];
71
72 previousState_ = kHoverStateNone;
73 iconColor_ = kDefaultIconColor;
72 } 74 }
73 75
74 - (void)removeFromSuperview { 76 - (void)removeFromSuperview {
75 // -stopAnimation will call the animationDidStop: delegate method 77 // -stopAnimation will call the animationDidStop: delegate method
76 // which will release our animation. 78 // which will release our animation.
77 [fadeOutAnimation_ stopAnimation]; 79 [fadeOutAnimation_ stopAnimation];
78 [super removeFromSuperview]; 80 [super removeFromSuperview];
79 } 81 }
80 82
81 - (void)animationDidStop:(NSAnimation*)animation { 83 - (void)animationDidStop:(NSAnimation*)animation {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 [fadeOutAnimation_ setDelegate:self]; 193 [fadeOutAnimation_ setDelegate:self];
192 [fadeOutAnimation_ startAnimation]; 194 [fadeOutAnimation_ startAnimation];
193 } else { 195 } else {
194 // -stopAnimation will call the animationDidStop: delegate method 196 // -stopAnimation will call the animationDidStop: delegate method
195 // which will clean up the animation. 197 // which will clean up the animation.
196 [fadeOutAnimation_ stopAnimation]; 198 [fadeOutAnimation_ stopAnimation];
197 } 199 }
198 } 200 }
199 } 201 }
200 202
201 - (void)commonInit {
202 [self setAccessibilityTitle:nil];
203
204 // Add a tooltip. Using 'owner:self' means that
205 // -view:stringForToolTip:point:userData: will be called to provide the
206 // tooltip contents immediately before showing it.
207 [self addToolTipRect:[self bounds] owner:self userData:NULL];
208
209 previousState_ = kHoverStateNone;
210 iconColor_ = kDefaultIconColor;
211 }
212
213 // Called each time a tooltip is about to be shown. 203 // Called each time a tooltip is about to be shown.
214 - (NSString*)view:(NSView*)view 204 - (NSString*)view:(NSView*)view
215 stringForToolTip:(NSToolTipTag)tag 205 stringForToolTip:(NSToolTipTag)tag
216 point:(NSPoint)point 206 point:(NSPoint)point
217 userData:(void*)userData { 207 userData:(void*)userData {
218 if (self.hoverState == kHoverStateMouseOver) { 208 if (self.hoverState == kHoverStateMouseOver) {
219 // In some cases (e.g. the download tray), the button is still in the 209 // In some cases (e.g. the download tray), the button is still in the
220 // hover state, but is outside the bounds of its parent and not visible. 210 // hover state, but is outside the bounds of its parent and not visible.
221 // Don't show the tooltip in that case. 211 // Don't show the tooltip in that case.
222 NSRect buttonRect = [self frame]; 212 NSRect buttonRect = [self frame];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 break; 252 break;
263 case kHoverStateMouseDown: 253 case kHoverStateMouseDown:
264 imageID = IDR_CLOSE_DIALOG_P; 254 imageID = IDR_CLOSE_DIALOG_P;
265 break; 255 break;
266 } 256 }
267 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 257 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
268 return bundle.GetNativeImageNamed(imageID).ToNSImage(); 258 return bundle.GetNativeImageNamed(imageID).ToNSImage();
269 } 259 }
270 260
271 @end 261 @end
OLDNEW
« no previous file with comments | « no previous file | ui/base/cocoa/hover_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698