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/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 } | |
| 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 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() {} | |
|
tapted
2016/02/09 23:51:48
[bridge_ setDelegate:nullptr];
spqchan
2016/02/10 00:35:16
Done.
| |
| 56 | |
| 57 void NativeCocoaScrollBarViews::OnScrollerStyleChanged() { | |
| 58 NSScrollerStyle scroller_style = [bridge_ getPreferredScrollerStyle]; | |
| 59 if (scroller_style_ == scroller_style) | |
| 60 return; | |
| 61 | |
| 62 scroller_style_ = scroller_style; | |
| 63 if (scroller_style_) | |
| 64 HideScrollbar(); | |
| 65 else | |
| 66 ShowScrollbar(); | |
| 67 } | |
| 68 | |
| 69 bool NativeCocoaScrollBarViews::OnScroll(float dx, float dy) { | |
| 70 bool didScroll = BaseScrollBar::OnScroll(dx, dy); | |
| 71 | |
| 72 // If we're using the overlay style, then we should fire the timer. | |
| 73 if (didScroll && scroller_style_ == NSScrollerStyleOverlay) { | |
| 74 ShowScrollbar(); | |
| 75 if (hide_scrollbar_timer_.IsRunning()) { | |
| 76 hide_scrollbar_timer_.Reset(); | |
| 77 } else { | |
| 78 hide_scrollbar_timer_.Start( | |
| 79 FROM_HERE, base::TimeDelta::FromMilliseconds(kScrollbarHideTimeoutMs), | |
| 80 this, &NativeCocoaScrollBarViews::HideScrollbar); | |
| 81 } | |
| 82 } | |
| 83 return didScroll; | |
| 84 } | |
| 85 | |
| 86 void NativeCocoaScrollBarViews::HideScrollbar() { | |
| 87 layer()->GetAnimator()->SetOpacity(0.0); | |
| 88 } | |
| 89 | |
| 90 void NativeCocoaScrollBarViews::ShowScrollbar() { | |
| 91 layer()->SetOpacity(1.0); | |
| 92 } | |
| 93 | |
| 94 } // end of views namespace | |
|
tapted
2016/02/09 23:51:48
-> // namespace views
spqchan
2016/02/10 00:35:16
Done.
| |
| OLD | NEW |