File: cocoa_scroll_bar.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (137 lines) | stat: -rw-r--r-- 4,607 bytes parent folder | download | duplicates (9)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2016 The Chromium Authors
// 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/timer/timer.h"
#import "components/remote_cocoa/app_shim/views_scrollbar_bridge.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/views/controls/scrollbar/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 ScrollBar,
                                    public ViewsScrollbarBridgeDelegate,
                                    public ui::ImplicitAnimationObserver,
                                    public gfx::AnimationDelegate {
  METADATA_HEADER(CocoaScrollBar, ScrollBar)

 public:
  explicit CocoaScrollBar(ScrollBar::Orientation orientation);

  CocoaScrollBar(const CocoaScrollBar&) = delete;
  CocoaScrollBar& operator=(const CocoaScrollBar&) = delete;

  ~CocoaScrollBar() override;

  // ScrollBar:
  void Update(int viewport_size,
              int content_size,
              int contents_scroll_offset) override;
  void ObserveScrollEvent(const ui::ScrollEvent& event) override;

  // ViewsScrollbarBridgeDelegate:
  void OnScrollerStyleChanged() override;

  // View:
  bool GetCanProcessEventsWithinSubtree() const override;
  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 the thickness of the scrollbar.
  int ScrollbarThickness() const;

  // Returns true if the opacity is 0.0.
  bool IsScrollbarFullyHidden() const;

  // Get the parameters for painting.
  ui::NativeTheme::ExtraParams GetPainterParams() const;

 protected:
  // ScrollBar:
  gfx::Rect GetTrackBounds() const override;

  // ScrollBar:
  int GetThickness() const override;
  bool OverlapsContent() const override;

  // View:
  void Layout(PassKey) override;
  gfx::Size CalculatePreferredSize(
      const SizeBounds& available_size) const override;
  void OnPaint(gfx::Canvas* canvas) override;

 private:
  friend class ScrollBar;  // For ScrollBar::GetHideTimerForTesting().

  // 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();

  // 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::RetainingOneShotTimer 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_;

  // The scroll offset from the last adjustment to the scrollbar.
  int last_contents_scroll_offset_ = 0;

  // True when the scrollbar is expanded.
  bool is_expanded_ = false;

  // 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_ = false;

  // The bridge for NSScroller.
  ViewsScrollbarBridge* __strong bridge_;
};

}  // namespace views

#endif  // UI_VIEWS_CONTROLS_SCROLLBAR_COCOA_SCROLL_BAR_H_