| OLD | NEW |
| 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/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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 DCHECK(animation == fadeOutAnimation_); | 72 DCHECK(animation == fadeOutAnimation_); |
| 73 [fadeOutAnimation_ setDelegate:nil]; | 73 [fadeOutAnimation_ setDelegate:nil]; |
| 74 [fadeOutAnimation_ release]; | 74 [fadeOutAnimation_ release]; |
| 75 fadeOutAnimation_ = nil; | 75 fadeOutAnimation_ = nil; |
| 76 } | 76 } |
| 77 | 77 |
| 78 - (void)animationDidEnd:(NSAnimation*)animation { | 78 - (void)animationDidEnd:(NSAnimation*)animation { |
| 79 [self animationDidStop:animation]; | 79 [self animationDidStop:animation]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Override to only accept clicks within the bounds of the defined path, not |
| 83 // the entire bounding box. |aPoint| is in the superview's coordinate system. |
| 84 - (NSView*)hitTest:(NSPoint)point { |
| 85 NSPoint localPoint = [self convertPoint:point fromView:[self superview]]; |
| 86 NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1); |
| 87 |
| 88 NSImage* hoverImage = [self imageForHoverState:kHoverStateMouseOver]; |
| 89 if ([hoverImage hitTestRect:pointRect |
| 90 withImageDestinationRect:[self bounds] |
| 91 context:nil |
| 92 hints:nil |
| 93 flipped:YES]) |
| 94 return [super hitTest:point]; |
| 95 return nil; |
| 96 } |
| 97 |
| 82 - (void)drawRect:(NSRect)dirtyRect { | 98 - (void)drawRect:(NSRect)dirtyRect { |
| 83 NSImage* image = [self imageForHoverState:[self hoverState]]; | 99 NSImage* image = [self imageForHoverState:[self hoverState]]; |
| 84 | 100 |
| 85 // Close boxes align left horizontally, and align center vertically. | 101 // Close boxes align left horizontally, and align center vertically. |
| 86 // http:crbug.com/14739 requires this. | 102 // http:crbug.com/14739 requires this. |
| 87 NSRect imageRect = NSZeroRect; | 103 NSRect imageRect = NSZeroRect; |
| 88 imageRect.size = [image size]; | 104 imageRect.size = [image size]; |
| 89 | 105 |
| 90 NSRect destRect = [self bounds]; | 106 NSRect destRect = [self bounds]; |
| 91 destRect.origin.y = floor((NSHeight(destRect) / 2) | 107 destRect.origin.y = floor((NSHeight(destRect) / 2) |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 break; | 245 break; |
| 230 case kHoverStateMouseDown: | 246 case kHoverStateMouseDown: |
| 231 imageID = IDR_WEB_UI_CLOSE_PRESSED; | 247 imageID = IDR_WEB_UI_CLOSE_PRESSED; |
| 232 break; | 248 break; |
| 233 } | 249 } |
| 234 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 250 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 235 return bundle.GetNativeImageNamed(imageID).ToNSImage(); | 251 return bundle.GetNativeImageNamed(imageID).ToNSImage(); |
| 236 } | 252 } |
| 237 | 253 |
| 238 @end | 254 @end |
| OLD | NEW |