Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/gfx/animation/tween.h" | |
| 8 #include "ui/views/controls/button/custom_button.h" | |
| 9 #include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h" | |
| 10 | |
| 11 namespace views { | |
| 12 | |
| 13 namespace { | |
| 14 // How long we should wait before hiding the scrollbar. | |
|
tapted
2016/02/08 00:31:15
nit: blank line before
spqchan
2016/02/09 21:21:26
Done.
| |
| 15 const int kScrollbarHideTimeoutMs = 300; | |
| 16 | |
| 17 // How many frames per second to target. | |
| 18 const int kFadeFrameRateHz = 60; | |
| 19 | |
| 20 // How long animations should take by default. | |
| 21 const int kFadeDurationMs = 120; | |
| 22 } | |
|
tapted
2016/02/08 00:31:15
nit: } // namespace
(also, blank line before)
spqchan
2016/02/09 21:21:26
Done.
| |
| 23 | |
| 24 //////////////////////////////// | |
| 25 // NativeCocoaScrollBar | |
| 26 //////////////////////////////// | |
| 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 animation_(kFadeDurationMs, kFadeFrameRateHz, this) { | |
| 45 bridge_.reset([[ViewsScrollbarBridge alloc] initWithDelegate:this]); | |
| 46 UpdateScrollStyle(); | |
|
tapted
2016/02/08 00:31:15
So I think we can simplify things a bit and get a
spqchan
2016/02/09 21:21:26
Done.
| |
| 47 } | |
| 48 | |
| 49 NativeCocoaScrollBarViews::~NativeCocoaScrollBarViews() {} | |
| 50 | |
| 51 void NativeCocoaScrollBarViews::AnimationProgressed( | |
| 52 const gfx::Animation* animation) { | |
| 53 scroller_opacity_ = 1 - animation->GetCurrentValue(); | |
| 54 SchedulePaint(); | |
| 55 } | |
| 56 | |
| 57 void NativeCocoaScrollBarViews::OnScrollerStyleChanged() { | |
| 58 UpdateScrollStyle(); | |
| 59 } | |
| 60 | |
| 61 void NativeCocoaScrollBarViews::UpdateScrollStyle() { | |
| 62 NSScrollerStyle scroller_style = [bridge_ getPreferredScrollerStyle]; | |
| 63 if (scroller_style_ == scroller_style && init_) | |
| 64 return; | |
| 65 init_ = true; | |
| 66 scroller_style_ = scroller_style; | |
| 67 if (scroller_style_) | |
| 68 HideScrollbar(); | |
| 69 else | |
| 70 ShowScrollbar(); | |
| 71 } | |
| 72 | |
| 73 ui::NativeTheme::OverlayParams NativeCocoaScrollBarViews::GetOverlayParams() { | |
| 74 ui::NativeTheme::OverlayParams params; | |
| 75 params.is_overlay = true; | |
| 76 params.alpha = scroller_opacity_; | |
| 77 return params; | |
| 78 } | |
| 79 | |
| 80 bool NativeCocoaScrollBarViews::OnScroll(float dx, float dy) { | |
| 81 bool didScroll = BaseScrollBar::OnScroll(dx, dy); | |
| 82 | |
| 83 // If we're using the overlay style, then we should fire the timer | |
| 84 if (didScroll && scroller_style_ == NSScrollerStyleOverlay) { | |
| 85 ShowScrollbar(); | |
| 86 if (hide_scrollbar_timer_.IsRunning()) { | |
| 87 hide_scrollbar_timer_.Reset(); | |
| 88 } else { | |
| 89 hide_scrollbar_timer_.Start( | |
| 90 FROM_HERE, | |
| 91 base::TimeDelta::FromMilliseconds(kScrollbarHideTimeoutMs), | |
| 92 this, | |
| 93 &NativeCocoaScrollBarViews::HideScrollbar); | |
| 94 } | |
| 95 } | |
| 96 return didScroll; | |
| 97 } | |
| 98 | |
| 99 void NativeCocoaScrollBarViews::HideScrollbar() { | |
| 100 animation_.Start(); | |
|
tapted
2016/02/08 00:31:15
Then here, you would just call
GetLayer()->GetAni
spqchan
2016/02/09 21:21:26
Done.
| |
| 101 SchedulePaint(); | |
| 102 } | |
| 103 | |
| 104 void NativeCocoaScrollBarViews::ShowScrollbar() { | |
| 105 animation_.Stop(); | |
|
tapted
2016/02/08 00:31:15
And here,
GetLayer()->SetOpacity(1.0);
spqchan
2016/02/09 21:21:26
Done.
| |
| 106 scroller_opacity_ = 1.0; | |
| 107 SchedulePaint(); | |
| 108 } | |
| 109 | |
| 110 } // end of views namespace | |
| OLD | NEW |