Chromium Code Reviews| 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 NSRect destinationRect = NSMakeRect( | |
| 90 0, 0, NSWidth([self bounds]), NSHeight([self bounds])); | |
|
sail
2013/01/10 17:57:19
All our code already assumes that [self bounds] ha
Nico
2013/01/10 23:26:51
Done, thanks.
| |
| 91 if ([hoverImage hitTestRect:pointRect | |
| 92 withImageDestinationRect:destinationRect | |
| 93 context:nil | |
| 94 hints:nil | |
| 95 flipped:YES]) | |
| 96 return [super hitTest:point]; | |
| 97 return nil; | |
| 98 } | |
| 99 | |
| 82 - (void)drawRect:(NSRect)dirtyRect { | 100 - (void)drawRect:(NSRect)dirtyRect { |
| 83 NSImage* image = [self imageForHoverState:[self hoverState]]; | 101 NSImage* image = [self imageForHoverState:[self hoverState]]; |
| 84 | 102 |
| 85 // Close boxes align left horizontally, and align center vertically. | 103 // Close boxes align left horizontally, and align center vertically. |
| 86 // http:crbug.com/14739 requires this. | 104 // http:crbug.com/14739 requires this. |
| 87 NSRect imageRect = NSZeroRect; | 105 NSRect imageRect = NSZeroRect; |
| 88 imageRect.size = [image size]; | 106 imageRect.size = [image size]; |
| 89 | 107 |
| 90 NSRect destRect = [self bounds]; | 108 NSRect destRect = [self bounds]; |
| 91 destRect.origin.y = floor((NSHeight(destRect) / 2) | 109 destRect.origin.y = floor((NSHeight(destRect) / 2) |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 break; | 247 break; |
| 230 case kHoverStateMouseDown: | 248 case kHoverStateMouseDown: |
| 231 imageID = IDR_WEB_UI_CLOSE_PRESSED; | 249 imageID = IDR_WEB_UI_CLOSE_PRESSED; |
| 232 break; | 250 break; |
| 233 } | 251 } |
| 234 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 252 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 235 return bundle.GetNativeImageNamed(imageID).ToNSImage(); | 253 return bundle.GetNativeImageNamed(imageID).ToNSImage(); |
| 236 } | 254 } |
| 237 | 255 |
| 238 @end | 256 @end |
| OLD | NEW |