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

Unified 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 side-by-side diff with in-line comments
Download patch
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..bd1657476c8b7e2b6af889634981371bca565475
--- /dev/null
+++ b/ui/views/controls/scrollbar/native_cocoa_scroll_bar.mm
@@ -0,0 +1,96 @@
+// 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;
+}
tapted 2016/02/11 08:46:18 nit: blank line before
spqchan 2016/02/13 01:39:23 Done.
+
+////////////////////////////////
+// NativeCocoaScrollBar
+////////////////////////////////
tapted 2016/02/11 08:46:17 The convention in views seems to be more commonly
spqchan 2016/02/13 01:39:23 Done.
+
+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() {
+ [bridge_ setDelegate:nullptr];
+}
+
+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) {
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
+ bool didScroll = BaseScrollBar::OnScroll(dx, dy);
tapted 2016/02/11 08:46:18 didScroll -> did_scroll
spqchan 2016/02/13 01:39:23 Done.
+
+ // 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);
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
+}
+
+void NativeCocoaScrollBarViews::ShowScrollbar() {
+ layer()->SetOpacity(1.0);
+}
+
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698