OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_nsobject.h" | 7 #include "base/memory/scoped_nsobject.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #import "chrome/browser/ui/cocoa/animation_utils.h" | 9 #import "chrome/browser/ui/cocoa/animation_utils.h" |
10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
11 #import "third_party/GTM/AppKit/GTMKeyValueAnimation.h" | 11 #import "third_party/GTM/AppKit/GTMKeyValueAnimation.h" |
12 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h" | 12 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 14 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 const CGFloat kButtonWidth = 16; | 17 const CGFloat kButtonWidth = 16; |
18 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good. | 18 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good. |
19 const CGFloat kCircleRadius = 0.415 * kButtonWidth; | 19 const CGFloat kCircleRadius = 0.415 * kButtonWidth; |
20 const CGFloat kCircleHoverWhite = 0.565; | 20 const CGFloat kCircleHoverWhite = 0.565; |
21 const CGFloat kCircleClickWhite = 0.396; | 21 const CGFloat kCircleClickWhite = 0.396; |
22 const CGFloat kXShadowAlpha = 0.75; | 22 const CGFloat kXShadowAlpha = 0.75; |
23 const CGFloat kXShadowCircleAlpha = 0.1; | 23 const CGFloat kXShadowCircleAlpha = 0.1; |
24 const CGFloat kDefaultAnimationDuration = 0.25; | 24 const CGFloat kCloseAnimationDuration = 0.1; |
25 | 25 |
26 // Images that are used for all close buttons. Set up in +initialize. | 26 // Images that are used for all close buttons. Set up in +initialize. |
27 NSImage* gHoverNoneImage = nil; | 27 NSImage* gHoverNoneImage = nil; |
28 NSImage* gHoverMouseOverImage = nil; | 28 NSImage* gHoverMouseOverImage = nil; |
29 NSImage* gHoverMouseDownImage = nil; | 29 NSImage* gHoverMouseDownImage = nil; |
30 | 30 |
31 // Strings that are used for all close buttons. Set up in +initialize. | 31 // Strings that are used for all close buttons. Set up in +initialize. |
32 NSString* gTooltip = nil; | 32 NSString* gTooltip = nil; |
33 NSString* gDescription = nil; | 33 NSString* gDescription = nil; |
34 | 34 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 - (void)setHoverState:(HoverState)state { | 185 - (void)setHoverState:(HoverState)state { |
186 if (state != self.hoverState) { | 186 if (state != self.hoverState) { |
187 previousState_ = self.hoverState; | 187 previousState_ = self.hoverState; |
188 [super setHoverState:state]; | 188 [super setHoverState:state]; |
189 // Only animate the HoverStateNone case. | 189 // Only animate the HoverStateNone case. |
190 if (state == kHoverStateNone) { | 190 if (state == kHoverStateNone) { |
191 DCHECK(fadeOutAnimation_ == nil); | 191 DCHECK(fadeOutAnimation_ == nil); |
192 fadeOutAnimation_ = | 192 fadeOutAnimation_ = |
193 [[GTMKeyValueAnimation alloc] initWithTarget:self | 193 [[GTMKeyValueAnimation alloc] initWithTarget:self |
194 keyPath:kFadeOutValueKeyPath]; | 194 keyPath:kFadeOutValueKeyPath]; |
195 [fadeOutAnimation_ setDuration:kDefaultAnimationDuration]; | 195 [fadeOutAnimation_ setDuration:kCloseAnimationDuration]; |
196 [fadeOutAnimation_ setFrameRate:kFramesPerSecond]; | 196 [fadeOutAnimation_ setFrameRate:kFramesPerSecond]; |
197 [fadeOutAnimation_ setDelegate:self]; | 197 [fadeOutAnimation_ setDelegate:self]; |
198 [fadeOutAnimation_ startAnimation]; | 198 [fadeOutAnimation_ startAnimation]; |
199 } else { | 199 } else { |
200 // -stopAnimation will call the animationDidStop: delegate method | 200 // -stopAnimation will call the animationDidStop: delegate method |
201 // which will clean up the animation. | 201 // which will clean up the animation. |
202 [fadeOutAnimation_ stopAnimation]; | 202 [fadeOutAnimation_ stopAnimation]; |
203 } | 203 } |
204 } | 204 } |
205 } | 205 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.15 alpha:alpha]]; | 265 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.15 alpha:alpha]]; |
266 [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; | 266 [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; |
267 [shadow setShadowBlurRadius:2.5]; | 267 [shadow setShadowBlurRadius:2.5]; |
268 [xPath fillWithInnerShadow:shadow]; | 268 [xPath fillWithInnerShadow:shadow]; |
269 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; | 269 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; |
270 [image addRepresentation:imageRep]; | 270 [image addRepresentation:imageRep]; |
271 return image; | 271 return image; |
272 } | 272 } |
273 | 273 |
274 @end | 274 @end |
OLD | NEW |