Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_nsobject.h" | 8 #import "base/scoped_nsobject.h" |
| 9 #import "chrome/browser/themes/browser_theme_provider.h" | 9 #import "chrome/browser/themes/browser_theme_provider.h" |
| 10 #import "chrome/browser/ui/cocoa/image_utils.h" | 10 #import "chrome/browser/ui/cocoa/image_utils.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // outer path also gives the area in which to clip. Any of the |return...| | 21 // outer path also gives the area in which to clip. Any of the |return...| |
| 22 // arguments may be NULL (in which case the given parameter won't be returned). | 22 // arguments may be NULL (in which case the given parameter won't be returned). |
| 23 // If |returnInnerPath| or |returnOuterPath|, |*returnInnerPath| or | 23 // If |returnInnerPath| or |returnOuterPath|, |*returnInnerPath| or |
| 24 // |*returnOuterPath| should be nil, respectively. | 24 // |*returnOuterPath| should be nil, respectively. |
| 25 - (void)getDrawParamsForFrame:(NSRect)cellFrame | 25 - (void)getDrawParamsForFrame:(NSRect)cellFrame |
| 26 inView:(NSView*)controlView | 26 inView:(NSView*)controlView |
| 27 innerFrame:(NSRect*)returnInnerFrame | 27 innerFrame:(NSRect*)returnInnerFrame |
| 28 innerPath:(NSBezierPath**)returnInnerPath | 28 innerPath:(NSBezierPath**)returnInnerPath |
| 29 clipPath:(NSBezierPath**)returnClipPath; | 29 clipPath:(NSBezierPath**)returnClipPath; |
| 30 | 30 |
| 31 - (void)updateTrackingAreas; | |
| 31 | 32 |
| 32 @end | 33 @end |
| 33 | 34 |
| 34 | 35 |
| 35 static const NSTimeInterval kAnimationShowDuration = 0.2; | 36 static const NSTimeInterval kAnimationShowDuration = 0.2; |
| 36 | 37 |
| 37 // Note: due to a bug (?), drawWithFrame:inView: does not call | 38 // Note: due to a bug (?), drawWithFrame:inView: does not call |
| 38 // drawBorderAndFillForTheme::::: unless the mouse is inside. The net | 39 // drawBorderAndFillForTheme::::: unless the mouse is inside. The net |
| 39 // effect is that our "fade out" when the mouse leaves becaumes | 40 // effect is that our "fade out" when the mouse leaves becaumes |
| 40 // instantaneous. When I "fixed" it things looked horrible; the | 41 // instantaneous. When I "fixed" it things looked horrible; the |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 } | 314 } |
| 314 | 315 |
| 315 // Since we have our own drawWithFrame:, we need to also have our own | 316 // Since we have our own drawWithFrame:, we need to also have our own |
| 316 // logic for determining when the mouse is inside for honoring this | 317 // logic for determining when the mouse is inside for honoring this |
| 317 // request. | 318 // request. |
| 318 - (void)setShowsBorderOnlyWhileMouseInside:(BOOL)showOnly { | 319 - (void)setShowsBorderOnlyWhileMouseInside:(BOOL)showOnly { |
| 319 [super setShowsBorderOnlyWhileMouseInside:showOnly]; | 320 [super setShowsBorderOnlyWhileMouseInside:showOnly]; |
| 320 if (showOnly) { | 321 if (showOnly) { |
| 321 if (trackingArea_.get()) { | 322 if (trackingArea_.get()) { |
| 322 [self setShowsBorderOnlyWhileMouseInside:NO]; | 323 [self setShowsBorderOnlyWhileMouseInside:NO]; |
| 323 [[self controlView] removeTrackingArea:trackingArea_]; | |
| 324 } | 324 } |
| 325 trackingArea_.reset([[NSTrackingArea alloc] | 325 [self updateTrackingAreas]; |
| 326 initWithRect:[[self controlView] | |
| 327 bounds] | |
| 328 options:(NSTrackingMouseEnteredAndExited | | |
| 329 NSTrackingActiveInActiveApp) | |
| 330 owner:self | |
| 331 userInfo:nil]); | |
| 332 [[self controlView] addTrackingArea:trackingArea_]; | |
| 333 } else { | 326 } else { |
| 334 if (trackingArea_) { | 327 if (trackingArea_) { |
| 335 [[self controlView] removeTrackingArea:trackingArea_]; | 328 [[self controlView] removeTrackingArea:trackingArea_]; |
| 336 trackingArea_.reset(nil); | 329 trackingArea_.reset(nil); |
| 337 isMouseInside_ = NO; | 330 if (isMouseInside_) { |
| 331 isMouseInside_ = NO; | |
| 332 [[self controlView] setNeedsDisplay:YES]; | |
| 333 } | |
| 338 } | 334 } |
| 339 } | 335 } |
| 340 } | 336 } |
| 341 | 337 |
| 342 // TODO(viettrungluu): clean up/reorganize. | 338 // TODO(viettrungluu): clean up/reorganize. |
| 343 - (void)drawBorderAndFillForTheme:(ThemeProvider*)themeProvider | 339 - (void)drawBorderAndFillForTheme:(ThemeProvider*)themeProvider |
| 344 controlView:(NSView*)controlView | 340 controlView:(NSView*)controlView |
| 345 innerPath:(NSBezierPath*)innerPath | 341 innerPath:(NSBezierPath*)innerPath |
| 346 showClickedGradient:(BOOL)showClickedGradient | 342 showClickedGradient:(BOOL)showClickedGradient |
| 347 showHighlightGradient:(BOOL)showHighlightGradient | 343 showHighlightGradient:(BOOL)showHighlightGradient |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 inView:(NSView*)controlView { | 705 inView:(NSView*)controlView { |
| 710 NSBezierPath* boundingPath = nil; | 706 NSBezierPath* boundingPath = nil; |
| 711 [self getDrawParamsForFrame:cellFrame | 707 [self getDrawParamsForFrame:cellFrame |
| 712 inView:controlView | 708 inView:controlView |
| 713 innerFrame:NULL | 709 innerFrame:NULL |
| 714 innerPath:NULL | 710 innerPath:NULL |
| 715 clipPath:&boundingPath]; | 711 clipPath:&boundingPath]; |
| 716 return boundingPath; | 712 return boundingPath; |
| 717 } | 713 } |
| 718 | 714 |
| 715 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView | |
| 716 { | |
|
mrossetti
2010/12/10 18:12:49
Move brace up to end of previous line.
Leib
2010/12/13 17:32:00
Done.
| |
| 717 [super resetCursorRect:cellFrame inView:controlView]; | |
| 718 if (trackingArea_) { | |
|
mrossetti
2010/12/10 18:12:49
Note that braces are optional for single-line if b
Leib
2010/12/13 17:32:00
Done.
| |
| 719 [self updateTrackingAreas]; | |
| 720 } | |
| 721 } | |
| 722 | |
| 723 - (void)updateTrackingAreas | |
| 724 { | |
|
mrossetti
2010/12/10 18:12:49
Brace up to previous line.
Leib
2010/12/13 17:32:00
Done.
| |
| 725 BOOL mouseInView = NO; | |
| 726 NSView *controlView = [self controlView]; | |
|
mrossetti
2010/12/10 18:12:49
Asterisks precede the space in Chromium.
Leib
2010/12/13 17:32:00
Done.
| |
| 727 NSWindow *window = [controlView window]; | |
|
mrossetti
2010/12/10 18:12:49
Move asterisk to before the space.
Leib
2010/12/13 17:32:00
Done.
| |
| 728 NSRect bounds = [controlView bounds]; | |
| 729 if (window) { | |
| 730 NSPoint mousePoint = [window mouseLocationOutsideOfEventStream]; | |
| 731 mousePoint = [controlView convertPointFromBase:mousePoint]; | |
| 732 mouseInView = [controlView mouse:mousePoint inRect:bounds]; | |
| 733 } | |
| 734 | |
| 735 if (trackingArea_.get()) { | |
| 736 [controlView removeTrackingArea:trackingArea_]; | |
| 737 } | |
| 738 | |
| 739 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | | |
| 740 NSTrackingActiveInActiveApp; | |
| 741 if (mouseInView) { | |
| 742 options |= NSTrackingAssumeInside; | |
| 743 } | |
| 744 | |
| 745 trackingArea_.reset([[NSTrackingArea alloc] | |
| 746 initWithRect:bounds | |
| 747 options:options | |
| 748 owner:self | |
| 749 userInfo:nil]); | |
| 750 if (isMouseInside_ != mouseInView) { | |
| 751 isMouseInside_ = mouseInView; | |
| 752 [controlView setNeedsDisplay:YES]; | |
| 753 } | |
| 754 } | |
| 755 | |
| 719 @end | 756 @end |
| OLD | NEW |