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 #include "chrome/browser/ui/cocoa/gradient_button_cell.h" | 5 #include "chrome/browser/ui/cocoa/gradient_button_cell.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/memory/scoped_nsobject.h" | 8 #import "base/memory/scoped_nsobject.h" |
9 #import "chrome/browser/themes/theme_service.h" | 9 #import "chrome/browser/themes/theme_service.h" |
10 #import "chrome/browser/ui/cocoa/image_utils.h" | 10 #import "chrome/browser/ui/cocoa/image_utils.h" |
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 clipPath:&boundingPath]; | 716 clipPath:&boundingPath]; |
717 return boundingPath; | 717 return boundingPath; |
718 } | 718 } |
719 | 719 |
720 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView*)controlView { | 720 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView*)controlView { |
721 [super resetCursorRect:cellFrame inView:controlView]; | 721 [super resetCursorRect:cellFrame inView:controlView]; |
722 if (trackingArea_) | 722 if (trackingArea_) |
723 [self updateTrackingAreas]; | 723 [self updateTrackingAreas]; |
724 } | 724 } |
725 | 725 |
726 - (void)updateTrackingAreas { | 726 - (BOOL)isMouseReallyInside { |
727 BOOL mouseInView = NO; | 727 BOOL mouseInView = NO; |
728 NSView* controlView = [self controlView]; | 728 NSView* controlView = [self controlView]; |
729 NSWindow* window = [controlView window]; | 729 NSWindow* window = [controlView window]; |
730 NSRect bounds = [controlView bounds]; | 730 NSRect bounds = [controlView bounds]; |
731 if (window) { | 731 if (window) { |
732 NSPoint mousePoint = [window mouseLocationOutsideOfEventStream]; | 732 NSPoint mousePoint = [window mouseLocationOutsideOfEventStream]; |
733 mousePoint = [controlView convertPointFromBase:mousePoint]; | 733 mousePoint = [controlView convertPointFromBase:mousePoint]; |
734 mouseInView = [controlView mouse:mousePoint inRect:bounds]; | 734 mouseInView = [controlView mouse:mousePoint inRect:bounds]; |
735 } | 735 } |
| 736 return mouseInView; |
| 737 } |
| 738 |
| 739 - (void)updateTrackingAreas { |
| 740 NSView* controlView = [self controlView]; |
| 741 BOOL mouseInView = [self isMouseReallyInside]; |
736 | 742 |
737 if (trackingArea_.get()) | 743 if (trackingArea_.get()) |
738 [controlView removeTrackingArea:trackingArea_]; | 744 [controlView removeTrackingArea:trackingArea_]; |
739 | 745 |
740 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | | 746 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | |
741 NSTrackingActiveInActiveApp; | 747 NSTrackingActiveInActiveApp; |
742 if (mouseInView) | 748 if (mouseInView) |
743 options |= NSTrackingAssumeInside; | 749 options |= NSTrackingAssumeInside; |
744 | 750 |
745 trackingArea_.reset([[NSTrackingArea alloc] | 751 trackingArea_.reset([[NSTrackingArea alloc] |
746 initWithRect:bounds | 752 initWithRect:[controlView bounds] |
747 options:options | 753 options:options |
748 owner:self | 754 owner:self |
749 userInfo:nil]); | 755 userInfo:nil]); |
750 if (isMouseInside_ != mouseInView) { | 756 if (isMouseInside_ != mouseInView) { |
751 isMouseInside_ = mouseInView; | 757 [self setMouseInside:mouseInView animate:NO]; |
752 [controlView setNeedsDisplay:YES]; | 758 [controlView setNeedsDisplay:YES]; |
753 } | 759 } |
754 } | 760 } |
755 | 761 |
756 @end | 762 @end |
OLD | NEW |