Chromium Code Reviews| Index: ui/views/controls/scrollbar/native_cocoa_scroll_bar.mm |
| diff --git a/ui/views/controls/scrollbar/native_cocoa_scroll_bar.mm b/ui/views/controls/scrollbar/native_cocoa_scroll_bar.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9a96813423a1ecc8377d34c81d7263f4c9181d42 |
| --- /dev/null |
| +++ b/ui/views/controls/scrollbar/native_cocoa_scroll_bar.mm |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/views/controls/scrollbar/native_cocoa_scroll_bar.h" |
| + |
| +#include "ui/gfx/animation/tween.h" |
| +#include "ui/views/controls/button/custom_button.h" |
| +#include "ui/views/controls/scrollbar/native_scroll_bar_wrapper.h" |
| + |
| +namespace views { |
| + |
| +namespace { |
| +// 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.
|
| +const int kScrollbarHideTimeoutMs = 300; |
| + |
| +// How many frames per second to target. |
| +const int kFadeFrameRateHz = 60; |
| + |
| +// How long animations should take by default. |
| +const int kFadeDurationMs = 120; |
| +} |
|
tapted
2016/02/08 00:31:15
nit: } // namespace
(also, blank line before)
spqchan
2016/02/09 21:21:26
Done.
|
| + |
| +//////////////////////////////// |
| +// NativeCocoaScrollBar |
| +//////////////////////////////// |
| + |
| +NativeCocoaScrollBar::NativeCocoaScrollBar(bool horizontal) |
| + : NativeScrollBar(horizontal) {} |
| + |
| +NativeCocoaScrollBar::~NativeCocoaScrollBar() {} |
| + |
| +NativeScrollBarWrapper* NativeCocoaScrollBar::CreateWrapper() { |
| + return new NativeCocoaScrollBarViews(this); |
| +} |
| + |
| +//////////////////////////////// |
| +// NativeCocoaScrollBarViews |
| +//////////////////////////////// |
| + |
| +NativeCocoaScrollBarViews::NativeCocoaScrollBarViews( |
| + NativeScrollBar* native_scroll_bar) |
| + : NativeScrollBarViews(native_scroll_bar), |
| + animation_(kFadeDurationMs, kFadeFrameRateHz, this) { |
| + bridge_.reset([[ViewsScrollbarBridge alloc] initWithDelegate:this]); |
| + 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.
|
| +} |
| + |
| +NativeCocoaScrollBarViews::~NativeCocoaScrollBarViews() {} |
| + |
| +void NativeCocoaScrollBarViews::AnimationProgressed( |
| + const gfx::Animation* animation) { |
| + scroller_opacity_ = 1 - animation->GetCurrentValue(); |
| + SchedulePaint(); |
| +} |
| + |
| +void NativeCocoaScrollBarViews::OnScrollerStyleChanged() { |
| + UpdateScrollStyle(); |
| +} |
| + |
| +void NativeCocoaScrollBarViews::UpdateScrollStyle() { |
| + NSScrollerStyle scroller_style = [bridge_ getPreferredScrollerStyle]; |
| + if (scroller_style_ == scroller_style && init_) |
| + return; |
| + init_ = true; |
| + scroller_style_ = scroller_style; |
| + if (scroller_style_) |
| + HideScrollbar(); |
| + else |
| + ShowScrollbar(); |
| +} |
| + |
| +ui::NativeTheme::OverlayParams NativeCocoaScrollBarViews::GetOverlayParams() { |
| + ui::NativeTheme::OverlayParams params; |
| + params.is_overlay = true; |
| + params.alpha = scroller_opacity_; |
| + return params; |
| +} |
| + |
| +bool NativeCocoaScrollBarViews::OnScroll(float dx, float dy) { |
| + bool didScroll = BaseScrollBar::OnScroll(dx, dy); |
| + |
| + // If we're using the overlay style, then we should fire the timer |
| + if (didScroll && scroller_style_ == NSScrollerStyleOverlay) { |
| + ShowScrollbar(); |
| + if (hide_scrollbar_timer_.IsRunning()) { |
| + hide_scrollbar_timer_.Reset(); |
| + } else { |
| + hide_scrollbar_timer_.Start( |
| + FROM_HERE, |
| + base::TimeDelta::FromMilliseconds(kScrollbarHideTimeoutMs), |
| + this, |
| + &NativeCocoaScrollBarViews::HideScrollbar); |
| + } |
| + } |
| + return didScroll; |
| +} |
| + |
| +void NativeCocoaScrollBarViews::HideScrollbar() { |
| + 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.
|
| + SchedulePaint(); |
| +} |
| + |
| +void NativeCocoaScrollBarViews::ShowScrollbar() { |
| + animation_.Stop(); |
|
tapted
2016/02/08 00:31:15
And here,
GetLayer()->SetOpacity(1.0);
spqchan
2016/02/09 21:21:26
Done.
|
| + scroller_opacity_ = 1.0; |
| + SchedulePaint(); |
| +} |
| + |
| +} // end of views namespace |