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..7f136fc8777a2182d97bba680f9746fd1c953ac0 |
| --- /dev/null |
| +++ b/ui/views/controls/scrollbar/native_cocoa_scroll_bar.mm |
| @@ -0,0 +1,94 @@ |
| +// 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/compositor/layer.h" |
| +#include "ui/compositor/layer_animator.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. |
| +const int kScrollbarHideTimeoutMs = 300; |
| + |
| +// How long animations should take by default. |
| +const int kFadeDurationMs = 120; |
| +} |
| + |
| +//////////////////////////////// |
| +// 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) { |
| + bridge_.reset([[ViewsScrollbarBridge alloc] init]); |
| + [bridge_ setDelegate:this]; |
| + |
| + scroller_style_ = [bridge_ getPreferredScrollerStyle]; |
| + |
| + SetPaintToLayer(true); |
| + layer()->SetOpacity(scroller_style_ == NSScrollerStyleOverlay ? 0.0 : 1.0); |
| + layer()->SetAnimator(new ui::LayerAnimator( |
| + base::TimeDelta::FromMilliseconds(kFadeDurationMs))); |
| +} |
| + |
| +NativeCocoaScrollBarViews::~NativeCocoaScrollBarViews() {} |
|
tapted
2016/02/09 23:51:48
[bridge_ setDelegate:nullptr];
spqchan
2016/02/10 00:35:16
Done.
|
| + |
| +void NativeCocoaScrollBarViews::OnScrollerStyleChanged() { |
| + NSScrollerStyle scroller_style = [bridge_ getPreferredScrollerStyle]; |
| + if (scroller_style_ == scroller_style) |
| + return; |
| + |
| + scroller_style_ = scroller_style; |
| + if (scroller_style_) |
| + HideScrollbar(); |
| + else |
| + ShowScrollbar(); |
| +} |
| + |
| +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() { |
| + layer()->GetAnimator()->SetOpacity(0.0); |
| +} |
| + |
| +void NativeCocoaScrollBarViews::ShowScrollbar() { |
| + layer()->SetOpacity(1.0); |
| +} |
| + |
| +} // end of views namespace |
|
tapted
2016/02/09 23:51:48
-> // namespace views
spqchan
2016/02/10 00:35:16
Done.
|