| 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" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 [fadeOutAnimation_ setDelegate:nil]; | 128 [fadeOutAnimation_ setDelegate:nil]; |
| 129 [fadeOutAnimation_ release]; | 129 [fadeOutAnimation_ release]; |
| 130 fadeOutAnimation_ = nil; | 130 fadeOutAnimation_ = nil; |
| 131 } | 131 } |
| 132 | 132 |
| 133 - (void)animationDidEnd:(NSAnimation*)animation { | 133 - (void)animationDidEnd:(NSAnimation*)animation { |
| 134 [self animationDidStop:animation]; | 134 [self animationDidStop:animation]; |
| 135 } | 135 } |
| 136 | 136 |
| 137 - (void)drawRect:(NSRect)dirtyRect { | 137 - (void)drawRect:(NSRect)dirtyRect { |
| 138 // Close boxes align left horizontally, and align center vertically. |
| 139 // http:crbug.com/14739 requires this. |
| 138 NSRect imageRect = NSZeroRect; | 140 NSRect imageRect = NSZeroRect; |
| 139 imageRect.size = [gHoverMouseOverImage size]; | 141 imageRect.size = [gHoverMouseOverImage size]; |
| 140 | 142 |
| 143 NSRect destRect = [self bounds]; |
| 144 destRect.origin.y = floor((NSHeight(destRect) / 2) |
| 145 - (NSHeight(imageRect) / 2)); |
| 146 destRect.size = imageRect.size; |
| 147 |
| 141 switch(self.hoverState) { | 148 switch(self.hoverState) { |
| 142 case kHoverStateMouseOver: | 149 case kHoverStateMouseOver: |
| 143 [gHoverMouseOverImage drawInRect:imageRect | 150 [gHoverMouseOverImage drawInRect:destRect |
| 144 fromRect:imageRect | 151 fromRect:imageRect |
| 145 operation:NSCompositeSourceOver | 152 operation:NSCompositeSourceOver |
| 146 fraction:1.0]; | 153 fraction:1.0]; |
| 147 break; | 154 break; |
| 148 | 155 |
| 149 case kHoverStateMouseDown: | 156 case kHoverStateMouseDown: |
| 150 [gHoverMouseDownImage drawInRect:imageRect | 157 [gHoverMouseDownImage drawInRect:destRect |
| 151 fromRect:imageRect | 158 fromRect:imageRect |
| 152 operation:NSCompositeSourceOver | 159 operation:NSCompositeSourceOver |
| 153 fraction:1.0]; | 160 fraction:1.0]; |
| 154 break; | 161 break; |
| 155 | 162 |
| 156 default: | 163 default: |
| 157 case kHoverStateNone: { | 164 case kHoverStateNone: { |
| 158 CGFloat value = 1.0; | 165 CGFloat value = 1.0; |
| 159 if (fadeOutAnimation_) { | 166 if (fadeOutAnimation_) { |
| 160 value = [fadeOutAnimation_ currentValue]; | 167 value = [fadeOutAnimation_ currentValue]; |
| 161 NSImage* previousImage = nil; | 168 NSImage* previousImage = nil; |
| 162 if (previousState_ == kHoverStateMouseOver) { | 169 if (previousState_ == kHoverStateMouseOver) { |
| 163 previousImage = gHoverMouseOverImage; | 170 previousImage = gHoverMouseOverImage; |
| 164 } else { | 171 } else { |
| 165 previousImage = gHoverMouseDownImage; | 172 previousImage = gHoverMouseDownImage; |
| 166 } | 173 } |
| 167 [previousImage drawInRect:imageRect | 174 [previousImage drawInRect:destRect |
| 168 fromRect:imageRect | 175 fromRect:imageRect |
| 169 operation:NSCompositeSourceOver | 176 operation:NSCompositeSourceOver |
| 170 fraction:1.0 - value]; | 177 fraction:1.0 - value]; |
| 171 } | 178 } |
| 172 [gHoverNoneImage drawInRect:imageRect | 179 [gHoverNoneImage drawInRect:destRect |
| 173 fromRect:imageRect | 180 fromRect:imageRect |
| 174 operation:NSCompositeSourceOver | 181 operation:NSCompositeSourceOver |
| 175 fraction:value]; | 182 fraction:value]; |
| 176 break; | 183 break; |
| 177 } | 184 } |
| 178 } | 185 } |
| 179 } | 186 } |
| 180 | 187 |
| 181 - (void)setFadeOutValue:(CGFloat)value { | 188 - (void)setFadeOutValue:(CGFloat)value { |
| 182 [self setNeedsDisplay]; | 189 [self setNeedsDisplay]; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.15 alpha:alpha]]; | 272 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.15 alpha:alpha]]; |
| 266 [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; | 273 [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; |
| 267 [shadow setShadowBlurRadius:2.5]; | 274 [shadow setShadowBlurRadius:2.5]; |
| 268 [xPath fillWithInnerShadow:shadow]; | 275 [xPath fillWithInnerShadow:shadow]; |
| 269 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; | 276 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; |
| 270 [image addRepresentation:imageRep]; | 277 [image addRepresentation:imageRep]; |
| 271 return image; | 278 return image; |
| 272 } | 279 } |
| 273 | 280 |
| 274 @end | 281 @end |
| OLD | NEW |