Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: ui/app_list/cocoa/scroll_view_with_no_scrollbars.mm

Issue 2131463002: Purge the App Launcher code from Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Zap mac-specific icon assets Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/app_list/cocoa/scroll_view_with_no_scrollbars.h"
6
7 #include "base/mac/scoped_cftyperef.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/mac/sdk_forward_declarations.h"
10
11 @interface InvisibleScroller : NSScroller;
12 @end
13
14 @implementation InvisibleScroller
15
16 // Makes it non-interactive (and invisible) on Lion with both 10.6 and 10.7
17 // SDKs. TODO(tapted): Find a way to make it non-interactive on Snow Leopard.
18 // TODO(tapted): Find a way to make it take up no space on Lion with a 10.6 SDK.
19 - (NSRect)rectForPart:(NSScrollerPart)aPart {
20 return NSZeroRect;
21 }
22
23 @end
24
25 @implementation ScrollViewWithNoScrollbars
26
27 @synthesize delegate = delegate_;
28
29 - (id)initWithFrame:(NSRect)frame {
30 if ((self = [super initWithFrame:frame])) {
31 [self setHasHorizontalScroller:YES];
32 NSRect horizontalScrollerRect = [self bounds];
33 horizontalScrollerRect.size.height = 0;
34 base::scoped_nsobject<InvisibleScroller> horizontalScroller(
35 [[InvisibleScroller alloc] initWithFrame:horizontalScrollerRect]);
36 [self setHorizontalScroller:horizontalScroller];
37 }
38 return self;
39 }
40
41 - (void)scrollWheel:(NSEvent*)event {
42 if ([event subtype] == NSMouseEventSubtype) {
43 // Since the scroll view has no vertical scroller, regular up and down mouse
44 // wheel events would be ignored. This maps mouse wheel events to a
45 // horizontal scroll event of one line, to turn pages.
46 BOOL downOrRight;
47 if ([event deltaX] != 0)
48 downOrRight = [event deltaX] > 0;
49 else if ([event deltaY] != 0)
50 downOrRight = [event deltaY] > 0;
51 else
52 return;
53
54 base::ScopedCFTypeRef<CGEventRef> cgEvent(CGEventCreateScrollWheelEvent(
55 NULL, kCGScrollEventUnitLine, 2, 0, downOrRight ? 1 : -1));
56 [super scrollWheel:[NSEvent eventWithCGEvent:cgEvent]];
57 return;
58 }
59
60 [super scrollWheel:event];
61 if (![event respondsToSelector:@selector(momentumPhase)])
62 return;
63
64 BOOL scrollComplete = [event momentumPhase] == NSEventPhaseEnded ||
65 ([event momentumPhase] == NSEventPhaseNone &&
66 [event phase] == NSEventPhaseEnded);
67
68 [delegate_ userScrolling:!scrollComplete];
69 }
70
71 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698