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 = (NSHeight(destRect) / 2) - (NSHeight(imageRect) / 2); | |
Nico
2011/08/08 18:23:06
Do you want to clamp this to integer coordinates?
| |
145 destRect.size = imageRect.size; | |
146 | |
141 switch(self.hoverState) { | 147 switch(self.hoverState) { |
142 case kHoverStateMouseOver: | 148 case kHoverStateMouseOver: |
143 [gHoverMouseOverImage drawInRect:imageRect | 149 [gHoverMouseOverImage drawInRect:destRect |
144 fromRect:imageRect | 150 fromRect:imageRect |
145 operation:NSCompositeSourceOver | 151 operation:NSCompositeSourceOver |
146 fraction:1.0]; | 152 fraction:1.0]; |
147 break; | 153 break; |
148 | 154 |
149 case kHoverStateMouseDown: | 155 case kHoverStateMouseDown: |
150 [gHoverMouseDownImage drawInRect:imageRect | 156 [gHoverMouseDownImage drawInRect:destRect |
151 fromRect:imageRect | 157 fromRect:imageRect |
152 operation:NSCompositeSourceOver | 158 operation:NSCompositeSourceOver |
153 fraction:1.0]; | 159 fraction:1.0]; |
154 break; | 160 break; |
155 | 161 |
156 default: | 162 default: |
157 case kHoverStateNone: { | 163 case kHoverStateNone: { |
158 CGFloat value = 1.0; | 164 CGFloat value = 1.0; |
159 if (fadeOutAnimation_) { | 165 if (fadeOutAnimation_) { |
160 value = [fadeOutAnimation_ currentValue]; | 166 value = [fadeOutAnimation_ currentValue]; |
161 NSImage* previousImage = nil; | 167 NSImage* previousImage = nil; |
162 if (previousState_ == kHoverStateMouseOver) { | 168 if (previousState_ == kHoverStateMouseOver) { |
163 previousImage = gHoverMouseOverImage; | 169 previousImage = gHoverMouseOverImage; |
164 } else { | 170 } else { |
165 previousImage = gHoverMouseDownImage; | 171 previousImage = gHoverMouseDownImage; |
166 } | 172 } |
167 [previousImage drawInRect:imageRect | 173 [previousImage drawInRect:destRect |
168 fromRect:imageRect | 174 fromRect:imageRect |
169 operation:NSCompositeSourceOver | 175 operation:NSCompositeSourceOver |
170 fraction:1.0 - value]; | 176 fraction:1.0 - value]; |
171 } | 177 } |
172 [gHoverNoneImage drawInRect:imageRect | 178 [gHoverNoneImage drawInRect:destRect |
173 fromRect:imageRect | 179 fromRect:imageRect |
174 operation:NSCompositeSourceOver | 180 operation:NSCompositeSourceOver |
175 fraction:value]; | 181 fraction:value]; |
176 break; | 182 break; |
177 } | 183 } |
178 } | 184 } |
179 } | 185 } |
180 | 186 |
181 - (void)setFadeOutValue:(CGFloat)value { | 187 - (void)setFadeOutValue:(CGFloat)value { |
182 [self setNeedsDisplay]; | 188 [self setNeedsDisplay]; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.15 alpha:alpha]]; | 271 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.15 alpha:alpha]]; |
266 [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; | 272 [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; |
267 [shadow setShadowBlurRadius:2.5]; | 273 [shadow setShadowBlurRadius:2.5]; |
268 [xPath fillWithInnerShadow:shadow]; | 274 [xPath fillWithInnerShadow:shadow]; |
269 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; | 275 NSImage* image = [[[NSImage alloc] initWithSize:bounds.size] autorelease]; |
270 [image addRepresentation:imageRep]; | 276 [image addRepresentation:imageRep]; |
271 return image; | 277 return image; |
272 } | 278 } |
273 | 279 |
274 @end | 280 @end |
OLD | NEW |