| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/app_list/cocoa/scroll_view_with_no_scrollbars.h" | 5 #include "ui/app_list/cocoa/scroll_view_with_no_scrollbars.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | |
| 8 #include "base/mac/scoped_cftyperef.h" | 7 #include "base/mac/scoped_cftyperef.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/mac/sdk_forward_declarations.h" | 9 #include "base/mac/sdk_forward_declarations.h" |
| 11 | 10 |
| 12 @interface InvisibleScroller : NSScroller; | 11 @interface InvisibleScroller : NSScroller; |
| 13 @end | 12 @end |
| 14 | 13 |
| 15 @implementation InvisibleScroller | 14 @implementation InvisibleScroller |
| 16 | 15 |
| 17 // Makes it non-interactive (and invisible) on Lion with both 10.6 and 10.7 | 16 // Makes it non-interactive (and invisible) on Lion with both 10.6 and 10.7 |
| 18 // SDKs. TODO(tapted): Find a way to make it non-interactive on Snow Leopard. | 17 // SDKs. TODO(tapted): Find a way to make it non-interactive on Snow Leopard. |
| 19 // TODO(tapted): Find a way to make it take up no space on Lion with a 10.6 SDK. | 18 // TODO(tapted): Find a way to make it take up no space on Lion with a 10.6 SDK. |
| 20 - (NSRect)rectForPart:(NSScrollerPart)aPart { | 19 - (NSRect)rectForPart:(NSScrollerPart)aPart { |
| 21 return NSZeroRect; | 20 return NSZeroRect; |
| 22 } | 21 } |
| 23 | 22 |
| 24 @end | 23 @end |
| 25 | 24 |
| 26 @implementation ScrollViewWithNoScrollbars | 25 @implementation ScrollViewWithNoScrollbars |
| 27 | 26 |
| 28 @synthesize delegate = delegate_; | 27 @synthesize delegate = delegate_; |
| 29 | 28 |
| 30 - (id)initWithFrame:(NSRect)frame { | 29 - (id)initWithFrame:(NSRect)frame { |
| 31 if ((self = [super initWithFrame:frame])) { | 30 if ((self = [super initWithFrame:frame])) { |
| 32 [self setHasHorizontalScroller:base::mac::IsOSLionOrLater()]; | 31 [self setHasHorizontalScroller:YES]; |
| 33 NSRect horizontalScrollerRect = [self bounds]; | 32 NSRect horizontalScrollerRect = [self bounds]; |
| 34 horizontalScrollerRect.size.height = 0; | 33 horizontalScrollerRect.size.height = 0; |
| 35 base::scoped_nsobject<InvisibleScroller> horizontalScroller( | 34 base::scoped_nsobject<InvisibleScroller> horizontalScroller( |
| 36 [[InvisibleScroller alloc] initWithFrame:horizontalScrollerRect]); | 35 [[InvisibleScroller alloc] initWithFrame:horizontalScrollerRect]); |
| 37 [self setHorizontalScroller:horizontalScroller]; | 36 [self setHorizontalScroller:horizontalScroller]; |
| 38 } | 37 } |
| 39 return self; | 38 return self; |
| 40 } | 39 } |
| 41 | 40 |
| 42 - (void)endGestureWithEvent:(NSEvent*)event { | |
| 43 [super endGestureWithEvent:event]; | |
| 44 if (!base::mac::IsOSLionOrLater()) | |
| 45 [delegate_ userScrolling:NO]; | |
| 46 } | |
| 47 | |
| 48 - (void)scrollWheel:(NSEvent*)event { | 41 - (void)scrollWheel:(NSEvent*)event { |
| 49 if ([event subtype] == NSMouseEventSubtype) { | 42 if ([event subtype] == NSMouseEventSubtype) { |
| 50 // Since the scroll view has no vertical scroller, regular up and down mouse | 43 // Since the scroll view has no vertical scroller, regular up and down mouse |
| 51 // wheel events would be ignored. This maps mouse wheel events to a | 44 // wheel events would be ignored. This maps mouse wheel events to a |
| 52 // horizontal scroll event of one line, to turn pages. | 45 // horizontal scroll event of one line, to turn pages. |
| 53 BOOL downOrRight; | 46 BOOL downOrRight; |
| 54 if ([event deltaX] != 0) | 47 if ([event deltaX] != 0) |
| 55 downOrRight = [event deltaX] > 0; | 48 downOrRight = [event deltaX] > 0; |
| 56 else if ([event deltaY] != 0) | 49 else if ([event deltaY] != 0) |
| 57 downOrRight = [event deltaY] > 0; | 50 downOrRight = [event deltaY] > 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 return; | 62 return; |
| 70 | 63 |
| 71 BOOL scrollComplete = [event momentumPhase] == NSEventPhaseEnded || | 64 BOOL scrollComplete = [event momentumPhase] == NSEventPhaseEnded || |
| 72 ([event momentumPhase] == NSEventPhaseNone && | 65 ([event momentumPhase] == NSEventPhaseNone && |
| 73 [event phase] == NSEventPhaseEnded); | 66 [event phase] == NSEventPhaseEnded); |
| 74 | 67 |
| 75 [delegate_ userScrolling:!scrollComplete]; | 68 [delegate_ userScrolling:!scrollComplete]; |
| 76 } | 69 } |
| 77 | 70 |
| 78 @end | 71 @end |
| OLD | NEW |