blob: 2cca52a6e380aa0400baf2b0c70ec5152762b9eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// 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.
#ifndef UI_VIEWS_CONTROLS_SCROLLBAR_COCOA_SCROLL_BAR_H_
#define UI_VIEWS_CONTROLS_SCROLLBAR_COCOA_SCROLL_BAR_H_
#include "base/macros.h"
#import "base/mac/scoped_nsobject.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/animation/slide_animation.h"
#import "ui/views/cocoa/views_scrollbar_bridge.h"
#include "ui/views/controls/scrollbar/base_scroll_bar.h"
#include "ui/views/views_export.h"
namespace views {
class CocoaScrollBarThumb;
// The transparent scrollbar for Mac which overlays its contents.
class VIEWS_EXPORT CocoaScrollBar : public BaseScrollBar,
public ViewsScrollbarBridgeDelegate,
public ui::ImplicitAnimationObserver,
public gfx::AnimationDelegate {
public:
explicit CocoaScrollBar(bool horizontal);
~CocoaScrollBar() override;
// BaseScrollBar:
void ScrollToPosition(int position) override;
// ViewsScrollbarBridgeDelegate:
void OnScrollerStyleChanged() override;
// View:
bool OnMousePressed(const ui::MouseEvent& event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override;
// ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override;
// gfx::AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationEnded(const gfx::Animation* animation) override;
// Returns the scroller style.
NSScrollerStyle GetScrollerStyle() const { return scroller_style_; }
// Returns true if the opacity is 0.0.
bool IsScrollbarFullyHidden() const;
protected:
// BaseScrollBar:
gfx::Rect GetTrackBounds() const override;
// ScrollBar:
int GetLayoutSize() const override;
int GetContentOverlapSize() const override;
// View:
void Layout() override;
gfx::Size GetPreferredSize() const override;
void OnPaint(gfx::Canvas* canvas) override;
private:
// Methods to change the visibility of the scrollbar.
void ShowScrollbar();
void HideScrollbar();
// Returns true if the scrollbar is in a hover or pressed state.
bool IsHoverOrPressedState() const;
// Updates the thickness of the scrollbar according to the current state of
// the expand animation.
void UpdateScrollbarThickness();
// Resets the scrolltrack and the thickness if the scrollbar is not hidden
// and is not in a hover/pressed state.
void ResetOverlayScrollbar();
// Returns the thickness of the scrollbar.
int ScrollbarThickness() const;
// Sets the scrolltrack's visibility and then repaints it.
void SetScrolltrackVisible(bool visible);
// Converts GetThumb() into a CocoaScrollBarThumb object and returns it.
CocoaScrollBarThumb* GetCocoaScrollBarThumb() const;
// Scroller style the scrollbar is using.
NSScrollerStyle scroller_style_;
// Timer that will start the scrollbar's hiding animation when it reaches 0.
base::Timer hide_scrollbar_timer_;
// Slide animation that animates the thickness of an overlay scrollbar.
// The animation expands the scrollbar as the showing animation and shrinks
// the scrollbar as the hiding animation.
gfx::SlideAnimation thickness_animation_;
// True when the scrollbar is expanded.
bool is_expanded_;
// True when the scrolltrack should be drawn.
bool has_scrolltrack_;
// True when the scrollbar has started dragging since it was last shown.
// This is set to false when we begin to hide the scrollbar.
bool did_start_dragging_;
// The bridge for NSScroller.
base::scoped_nsobject<ViewsScrollbarBridge> bridge_;
DISALLOW_COPY_AND_ASSIGN(CocoaScrollBar);
};
} // namespace views
#endif // UI_VIEWS_CONTROLS_SCROLLBAR_COCOA_SCROLL_BAR_H_
|