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

Side by Side Diff: ui/views/controls/scrollbar/native_cocoa_scroll_bar.mm

Issue 1671313002: MacViews: Overlay Scrollbars with Show/Hide Animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 2016 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/views/controls/scrollbar/native_cocoa_scroll_bar.h"
6
7 #include "ui/compositor/layer.h"
8 #include "ui/compositor/layer_animator.h"
9 #include "ui/gfx/animation/tween.h"
10 #include "ui/views/controls/button/custom_button.h"
11 #include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h"
12
13 namespace views {
14
15 namespace {
16
17 // How long we should wait before hiding the scrollbar.
18 const int kScrollbarHideTimeoutMs = 300;
19
20 // How long animations should take by default.
21 const int kFadeDurationMs = 120;
22 }
tapted 2016/02/11 08:46:18 nit: blank line before
spqchan 2016/02/13 01:39:23 Done.
23
24 ////////////////////////////////
25 // NativeCocoaScrollBar
26 ////////////////////////////////
tapted 2016/02/11 08:46:17 The convention in views seems to be more commonly
spqchan 2016/02/13 01:39:23 Done.
27
28 NativeCocoaScrollBar::NativeCocoaScrollBar(bool horizontal)
29 : NativeScrollBar(horizontal) {}
30
31 NativeCocoaScrollBar::~NativeCocoaScrollBar() {}
32
33 NativeScrollBarWrapper* NativeCocoaScrollBar::CreateWrapper() {
34 return new NativeCocoaScrollBarViews(this);
35 }
36
37 ////////////////////////////////
38 // NativeCocoaScrollBarViews
39 ////////////////////////////////
40
41 NativeCocoaScrollBarViews::NativeCocoaScrollBarViews(
42 NativeScrollBar* native_scroll_bar)
43 : NativeScrollBarViews(native_scroll_bar) {
44 bridge_.reset([[ViewsScrollbarBridge alloc] init]);
45 [bridge_ setDelegate:this];
46
47 scroller_style_ = [bridge_ getPreferredScrollerStyle];
48
49 SetPaintToLayer(true);
50 layer()->SetOpacity(scroller_style_ == NSScrollerStyleOverlay ? 0.0 : 1.0);
51 layer()->SetAnimator(new ui::LayerAnimator(
52 base::TimeDelta::FromMilliseconds(kFadeDurationMs)));
53 }
54
55 NativeCocoaScrollBarViews::~NativeCocoaScrollBarViews() {
56 [bridge_ setDelegate:nullptr];
57 }
58
59 void NativeCocoaScrollBarViews::OnScrollerStyleChanged() {
60 NSScrollerStyle scroller_style = [bridge_ getPreferredScrollerStyle];
61 if (scroller_style_ == scroller_style)
62 return;
63
64 scroller_style_ = scroller_style;
65 if (scroller_style_)
66 HideScrollbar();
67 else
68 ShowScrollbar();
69 }
70
71 bool NativeCocoaScrollBarViews::OnScroll(float dx, float dy) {
tapted 2016/02/11 08:46:17 we also need to prevent the scroller fading out wh
spqchan 2016/02/13 01:39:23 OverlayScrollBar is a bit different since it shows
72 bool didScroll = BaseScrollBar::OnScroll(dx, dy);
tapted 2016/02/11 08:46:18 didScroll -> did_scroll
spqchan 2016/02/13 01:39:23 Done.
73
74 // If we're using the overlay style, then we should fire the timer.
75 if (didScroll && scroller_style_ == NSScrollerStyleOverlay) {
76 ShowScrollbar();
77 if (hide_scrollbar_timer_.IsRunning()) {
78 hide_scrollbar_timer_.Reset();
79 } else {
80 hide_scrollbar_timer_.Start(
81 FROM_HERE, base::TimeDelta::FromMilliseconds(kScrollbarHideTimeoutMs),
82 this, &NativeCocoaScrollBarViews::HideScrollbar);
83 }
84 }
85 return didScroll;
86 }
87
88 void NativeCocoaScrollBarViews::HideScrollbar() {
89 layer()->GetAnimator()->SetOpacity(0.0);
tapted 2016/02/11 08:46:18 confusingly, I discovered that layer()->SetOpacit
spqchan 2016/02/13 01:39:23 Heads up, SetTransitionDuration was private so I h
90 }
91
92 void NativeCocoaScrollBarViews::ShowScrollbar() {
93 layer()->SetOpacity(1.0);
94 }
95
96 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698