OLD | NEW |
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 #include "ui/views/controls/scrollbar/base_scroll_bar.h" | 5 #include "ui/views/controls/scrollbar/base_scroll_bar.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 return true; | 165 return true; |
166 } | 166 } |
167 return false; | 167 return false; |
168 } | 168 } |
169 | 169 |
170 bool BaseScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) { | 170 bool BaseScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) { |
171 ScrollByContentsOffset(event.offset()); | 171 ScrollByContentsOffset(event.offset()); |
172 return true; | 172 return true; |
173 } | 173 } |
174 | 174 |
175 ui::EventResult BaseScrollBar::OnGestureEvent(ui::GestureEvent* event) { | 175 void BaseScrollBar::OnGestureEvent(ui::GestureEvent* event) { |
176 // If a fling is in progress, then stop the fling for any incoming gesture | 176 // If a fling is in progress, then stop the fling for any incoming gesture |
177 // event (except for the GESTURE_END event that is generated at the end of the | 177 // event (except for the GESTURE_END event that is generated at the end of the |
178 // fling). | 178 // fling). |
179 if (scroll_animator_.get() && scroll_animator_->is_scrolling() && | 179 if (scroll_animator_.get() && scroll_animator_->is_scrolling() && |
180 (event->type() != ui::ET_GESTURE_END || | 180 (event->type() != ui::ET_GESTURE_END || |
181 event->details().touch_points() > 1)) { | 181 event->details().touch_points() > 1)) { |
182 scroll_animator_->Stop(); | 182 scroll_animator_->Stop(); |
183 } | 183 } |
184 | 184 |
185 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 185 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
186 ProcessPressEvent(*event); | 186 ProcessPressEvent(*event); |
187 return ui::ER_CONSUMED; | 187 event->SetHandled(); |
| 188 return; |
188 } | 189 } |
189 | 190 |
190 if (event->type() == ui::ET_GESTURE_LONG_PRESS) { | 191 if (event->type() == ui::ET_GESTURE_LONG_PRESS) { |
191 // For a long-press, the repeater started in tap-down should continue. So | 192 // For a long-press, the repeater started in tap-down should continue. So |
192 // return early. | 193 // return early. |
193 return ui::ER_UNHANDLED; | 194 return; |
194 } | 195 } |
195 | 196 |
196 ResetState(); | 197 ResetState(); |
197 | 198 |
198 if (event->type() == ui::ET_GESTURE_TAP) { | 199 if (event->type() == ui::ET_GESTURE_TAP) { |
199 // TAP_DOWN would have already scrolled some amount. So scrolling again on | 200 // TAP_DOWN would have already scrolled some amount. So scrolling again on |
200 // TAP is not necessary. | 201 // TAP is not necessary. |
201 return ui::ER_CONSUMED; | 202 event->SetHandled(); |
| 203 return; |
202 } | 204 } |
203 | 205 |
204 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || | 206 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || |
205 event->type() == ui::ET_GESTURE_SCROLL_END) | 207 event->type() == ui::ET_GESTURE_SCROLL_END) { |
206 return ui::ER_CONSUMED; | 208 event->SetHandled(); |
| 209 return; |
| 210 } |
207 | 211 |
208 if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { | 212 if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
209 ScrollByContentsOffset(IsHorizontal() ? event->details().scroll_x() : | 213 ScrollByContentsOffset(IsHorizontal() ? event->details().scroll_x() : |
210 event->details().scroll_y()); | 214 event->details().scroll_y()); |
211 return ui::ER_CONSUMED; | 215 event->SetHandled(); |
| 216 return; |
212 } | 217 } |
213 | 218 |
214 if (event->type() == ui::ET_SCROLL_FLING_START) { | 219 if (event->type() == ui::ET_SCROLL_FLING_START) { |
215 if (!scroll_animator_.get()) | 220 if (!scroll_animator_.get()) |
216 scroll_animator_.reset(new ScrollAnimator(this)); | 221 scroll_animator_.reset(new ScrollAnimator(this)); |
217 scroll_animator_->Start( | 222 scroll_animator_->Start( |
218 IsHorizontal() ? event->details().velocity_x() : 0.f, | 223 IsHorizontal() ? event->details().velocity_x() : 0.f, |
219 IsHorizontal() ? 0.f : event->details().velocity_y()); | 224 IsHorizontal() ? 0.f : event->details().velocity_y()); |
220 return ui::ER_CONSUMED; | 225 event->SetHandled(); |
221 } | 226 } |
222 | |
223 return ui::ER_UNHANDLED; | |
224 } | 227 } |
225 | 228 |
226 /////////////////////////////////////////////////////////////////////////////// | 229 /////////////////////////////////////////////////////////////////////////////// |
227 // BaseScrollBar, ScrollDelegate implementation: | 230 // BaseScrollBar, ScrollDelegate implementation: |
228 | 231 |
229 void BaseScrollBar::OnScroll(float dx, float dy) { | 232 void BaseScrollBar::OnScroll(float dx, float dy) { |
230 if (IsHorizontal()) | 233 if (IsHorizontal()) |
231 ScrollByContentsOffset(dx); | 234 ScrollByContentsOffset(dx); |
232 else | 235 else |
233 ScrollByContentsOffset(dy); | 236 ScrollByContentsOffset(dy); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 thumb_position = thumb_position - (thumb_->GetSize() / 2); | 455 thumb_position = thumb_position - (thumb_->GetSize() / 2); |
453 return (thumb_position * contents_size_) / GetTrackSize(); | 456 return (thumb_position * contents_size_) / GetTrackSize(); |
454 } | 457 } |
455 | 458 |
456 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { | 459 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { |
457 thumb_track_state_ = state; | 460 thumb_track_state_ = state; |
458 SchedulePaint(); | 461 SchedulePaint(); |
459 } | 462 } |
460 | 463 |
461 } // namespace views | 464 } // namespace views |
OLD | NEW |