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

Side by Side Diff: ui/views/controls/scrollbar/base_scroll_bar.h

Issue 2496643002: Implement Sebastien's overlay scrollbars for native UI (Views). (Closed)
Patch Set: fix test failure Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_ 5 #ifndef UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_
6 #define UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_ 6 #define UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_
7 7
8 #include "base/gtest_prod_util.h" 8 #include "base/gtest_prod_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "ui/views/animation/scroll_animator.h" 10 #include "ui/views/animation/scroll_animator.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // Scroll the contents to the appropriate position given the supplied 56 // Scroll the contents to the appropriate position given the supplied
57 // position of the thumb (thumb track coordinates). If |scroll_to_middle| is 57 // position of the thumb (thumb track coordinates). If |scroll_to_middle| is
58 // true, then the conversion assumes |thumb_position| is in the middle of the 58 // true, then the conversion assumes |thumb_position| is in the middle of the
59 // thumb rather than the top. 59 // thumb rather than the top.
60 void ScrollToThumbPosition(int thumb_position, bool scroll_to_middle); 60 void ScrollToThumbPosition(int thumb_position, bool scroll_to_middle);
61 61
62 // Scroll the contents by the specified offset (contents coordinates). 62 // Scroll the contents by the specified offset (contents coordinates).
63 bool ScrollByContentsOffset(int contents_offset); 63 bool ScrollByContentsOffset(int contents_offset);
64 64
65 // Called when the thumb state has been changed from |old_state| to
66 // |new_state|.
67 void OnThumbStateChanged(CustomButton::ButtonState old_state,
68 CustomButton::ButtonState new_state);
69
70 // View overrides: 65 // View overrides:
71 bool OnMousePressed(const ui::MouseEvent& event) override; 66 bool OnMousePressed(const ui::MouseEvent& event) override;
72 void OnMouseReleased(const ui::MouseEvent& event) override; 67 void OnMouseReleased(const ui::MouseEvent& event) override;
73 void OnMouseCaptureLost() override; 68 void OnMouseCaptureLost() override;
74 void OnMouseEntered(const ui::MouseEvent& event) override;
75 void OnMouseExited(const ui::MouseEvent& event) override;
76 bool OnKeyPressed(const ui::KeyEvent& event) override; 69 bool OnKeyPressed(const ui::KeyEvent& event) override;
77 bool OnMouseWheel(const ui::MouseWheelEvent& event) override; 70 bool OnMouseWheel(const ui::MouseWheelEvent& event) override;
78 71
79 // ui::EventHandler overrides: 72 // ui::EventHandler overrides:
80 void OnGestureEvent(ui::GestureEvent* event) override; 73 void OnGestureEvent(ui::GestureEvent* event) override;
81 74
82 // ScrollBar overrides: 75 // ScrollBar overrides:
83 void Update(int viewport_size, 76 void Update(int viewport_size,
84 int content_size, 77 int content_size,
85 int contents_scroll_offset) override; 78 int contents_scroll_offset) override;
86 int GetLayoutSize() const override = 0; 79 int GetLayoutSize() const override = 0;
87 int GetPosition() const override; 80 int GetPosition() const override;
88 81
89 // ScrollDelegate overrides: 82 // ScrollDelegate overrides:
90 bool OnScroll(float dx, float dy) override; 83 bool OnScroll(float dx, float dy) override;
91 84
92 // ContextMenuController overrides: 85 // ContextMenuController overrides:
93 void ShowContextMenuForView(View* source, 86 void ShowContextMenuForView(View* source,
94 const gfx::Point& point, 87 const gfx::Point& point,
95 ui::MenuSourceType source_type) override; 88 ui::MenuSourceType source_type) override;
96 89
97 // Menu::Delegate overrides: 90 // Menu::Delegate overrides:
98 base::string16 GetLabel(int id) const override; 91 base::string16 GetLabel(int id) const override;
99 bool IsCommandEnabled(int id) const override; 92 bool IsCommandEnabled(int id) const override;
100 void ExecuteCommand(int id) override; 93 void ExecuteCommand(int id) override;
101 94
102 protected: 95 protected:
103 BaseScrollBarThumb* GetThumb() const; 96 BaseScrollBarThumb* GetThumb() const;
104 CustomButton::ButtonState GetThumbTrackState() const;
105 97
106 // Wrapper functions that calls the controller. We need this since native 98 // Wrapper functions that calls the controller. We need this since native
107 // scrollbars wrap around a different scrollbar. When calling the controller 99 // scrollbars wrap around a different scrollbar. When calling the controller
108 // we need to pass in the appropriate scrollbar. For normal scrollbars it's 100 // we need to pass in the appropriate scrollbar. For normal scrollbars it's
109 // the |this| scrollbar, for native scrollbars it's the native scrollbar used 101 // the |this| scrollbar, for native scrollbars it's the native scrollbar used
110 // to create this. 102 // to create this.
111 virtual void ScrollToPosition(int position); 103 virtual void ScrollToPosition(int position);
112 virtual int GetScrollIncrement(bool is_page, bool is_positive); 104 virtual int GetScrollIncrement(bool is_page, bool is_positive);
113 105
114 private: 106 private:
115 friend class test::ScrollViewTestApi; 107 friend class test::ScrollViewTestApi;
116 108
117 FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ScrollBarFitsToBottom); 109 FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ScrollBarFitsToBottom);
118 FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ThumbFullLengthOfTrack); 110 FRIEND_TEST_ALL_PREFIXES(ScrollBarViewsTest, ThumbFullLengthOfTrack);
119 int GetThumbSizeForTest(); 111 int GetThumbSizeForTest();
120 112
121 // Changes to 'pushed' state and starts a timer to scroll repeatedly. 113 // Changes to 'pushed' state and starts a timer to scroll repeatedly.
122 void ProcessPressEvent(const ui::LocatedEvent& event); 114 void ProcessPressEvent(const ui::LocatedEvent& event);
123 115
124 // Sets state to |state| and stops the repeater.
125 void SetState(CustomButton::ButtonState state);
126
127 // Called when the mouse is pressed down in the track area. 116 // Called when the mouse is pressed down in the track area.
128 void TrackClicked(); 117 void TrackClicked();
129 118
130 // Responsible for scrolling the contents and also updating the UI to the 119 // Responsible for scrolling the contents and also updating the UI to the
131 // current value of the Scroll Offset. 120 // current value of the Scroll Offset.
132 void ScrollContentsToOffset(); 121 void ScrollContentsToOffset();
133 122
134 // Returns the size (width or height) of the track area of the ScrollBar. 123 // Returns the size (width or height) of the track area of the ScrollBar.
135 int GetTrackSize() const; 124 int GetTrackSize() const;
136 125
(...skipping 15 matching lines...) Expand all
152 141
153 // The size of the scrolled contents, in pixels. 142 // The size of the scrolled contents, in pixels.
154 int contents_size_; 143 int contents_size_;
155 144
156 // The current amount the contents is offset by in the viewport. 145 // The current amount the contents is offset by in the viewport.
157 int contents_scroll_offset_; 146 int contents_scroll_offset_;
158 147
159 // The current size of the view port, in pixels. 148 // The current size of the view port, in pixels.
160 int viewport_size_; 149 int viewport_size_;
161 150
162 // The state of the scrollbar track. Typically, the track will highlight when
163 // the user presses the mouse on them (during page scrolling).
164 CustomButton::ButtonState thumb_track_state_;
165
166 // The last amount of incremental scroll that this scrollbar performed. This 151 // The last amount of incremental scroll that this scrollbar performed. This
167 // is accessed by the callbacks for the auto-repeat up/down buttons to know 152 // is accessed by the callbacks for the auto-repeat up/down buttons to know
168 // what direction to repeatedly scroll in. 153 // what direction to repeatedly scroll in.
169 ScrollAmount last_scroll_amount_; 154 ScrollAmount last_scroll_amount_;
170 155
171 // An instance of a RepeatController which scrolls the scrollbar continuously 156 // An instance of a RepeatController which scrolls the scrollbar continuously
172 // as the user presses the mouse button down on the up/down buttons or the 157 // as the user presses the mouse button down on the up/down buttons or the
173 // track. 158 // track.
174 RepeatController repeater_; 159 RepeatController repeater_;
175 160
176 // The position of the mouse within the scroll bar when the context menu 161 // The position of the mouse within the scroll bar when the context menu
177 // was invoked. 162 // was invoked.
178 int context_menu_mouse_position_; 163 int context_menu_mouse_position_;
179 164
180 std::unique_ptr<MenuRunner> menu_runner_; 165 std::unique_ptr<MenuRunner> menu_runner_;
181 std::unique_ptr<ScrollAnimator> scroll_animator_; 166 std::unique_ptr<ScrollAnimator> scroll_animator_;
182 167
183 // Difference between current position and cumulative deltas obtained from 168 // Difference between current position and cumulative deltas obtained from
184 // scroll update events. 169 // scroll update events.
185 // TODO(tdresser): This should be removed when raw pixel scrolling for views 170 // TODO(tdresser): This should be removed when raw pixel scrolling for views
186 // is enabled. See crbug.com/329354. 171 // is enabled. See crbug.com/329354.
187 gfx::Vector2dF roundoff_error_; 172 gfx::Vector2dF roundoff_error_;
188 173
189 DISALLOW_COPY_AND_ASSIGN(BaseScrollBar); 174 DISALLOW_COPY_AND_ASSIGN(BaseScrollBar);
190 }; 175 };
191 176
192 } // namespace views 177 } // namespace views
193 178
194 #endif // UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_ 179 #endif // UI_VIEWS_CONTROLS_SCROLLBAR_BASE_SCROLL_BAR_H_
OLDNEW
« no previous file with comments | « ui/views/controls/scroll_view_unittest.cc ('k') | ui/views/controls/scrollbar/base_scroll_bar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698