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 [super resetCursorRect:cellFrame inView:controlView]; |
| 717 if (trackingArea_) |
| 718 [self updateTrackingAreas]; |
| 719 } |
| 720 |
| 721 - (void)updateTrackingAreas { |
| 722 BOOL mouseInView = NO; |
| 723 NSView* controlView = [self controlView]; |
| 724 NSWindow* window = [controlView window]; |
| 725 NSRect bounds = [controlView bounds]; |
| 726 if (window) { |
| 727 NSPoint mousePoint = [window mouseLocationOutsideOfEventStream]; |
| 728 mousePoint = [controlView convertPointFromBase:mousePoint]; |
| 729 mouseInView = [controlView mouse:mousePoint inRect:bounds]; |
| 730 } |
| 731 |
| 732 if (trackingArea_.get()) |
| 733 [controlView removeTrackingArea:trackingArea_]; |
| 734 |
| 735 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | |
| 736 NSTrackingActiveInActiveApp; |
| 737 if (mouseInView) |
| 738 options |= NSTrackingAssumeInside; |
| 739 |
| 740 trackingArea_.reset([[NSTrackingArea alloc] |
| 741 initWithRect:bounds |
| 742 options:options |
| 743 owner:self |
| 744 userInfo:nil]); |
| 745 if (isMouseInside_ != mouseInView) { |
| 746 isMouseInside_ = mouseInView; |
| 747 [controlView setNeedsDisplay:YES]; |
| 748 } |
| 749 } |
| 750 |
719 @end | 751 @end |
OLD | NEW |