| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/events/gesture_detection/gesture_provider.h" | 5 #include "ui/events/gesture_detection/gesture_provider.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
| 12 #include "ui/events/gesture_detection/gesture_event_data.h" | 12 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 13 #include "ui/events/gesture_detection/gesture_listeners.h" |
| 13 #include "ui/events/gesture_detection/motion_event.h" | 14 #include "ui/events/gesture_detection/motion_event.h" |
| 15 #include "ui/events/gesture_detection/scale_gesture_listeners.h" |
| 14 #include "ui/gfx/geometry/point_f.h" | 16 #include "ui/gfx/geometry/point_f.h" |
| 15 | 17 |
| 16 namespace ui { | 18 namespace ui { |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 // Double-tap drag zoom sensitivity (speed). | 21 // Double-tap drag zoom sensitivity (speed). |
| 20 const float kDoubleTapDragZoomSpeed = 0.005f; | 22 const float kDoubleTapDragZoomSpeed = 0.005f; |
| 21 | 23 |
| 22 const char* GetMotionEventActionName(MotionEvent::Action action) { | 24 const char* GetMotionEventActionName(MotionEvent::Action action) { |
| 23 switch (action) { | 25 switch (action) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 gesture_begin_end_types_enabled(false), | 67 gesture_begin_end_types_enabled(false), |
| 66 min_gesture_bounds_length(0), | 68 min_gesture_bounds_length(0), |
| 67 max_gesture_bounds_length(0) { | 69 max_gesture_bounds_length(0) { |
| 68 } | 70 } |
| 69 | 71 |
| 70 GestureProvider::Config::~Config() { | 72 GestureProvider::Config::~Config() { |
| 71 } | 73 } |
| 72 | 74 |
| 73 // GestureProvider::GestureListener | 75 // GestureProvider::GestureListener |
| 74 | 76 |
| 75 class GestureProvider::GestureListenerImpl | 77 class GestureProvider::GestureListenerImpl : public ScaleGestureListener, |
| 76 : public ScaleGestureDetector::ScaleGestureListener, | 78 public GestureListener, |
| 77 public GestureDetector::GestureListener, | 79 public DoubleTapListener { |
| 78 public GestureDetector::DoubleTapListener { | |
| 79 public: | 80 public: |
| 80 GestureListenerImpl(const GestureProvider::Config& config, | 81 GestureListenerImpl(const GestureProvider::Config& config, |
| 81 GestureProviderClient* client) | 82 GestureProviderClient* client) |
| 82 : config_(config), | 83 : config_(config), |
| 83 client_(client), | 84 client_(client), |
| 84 gesture_detector_(config.gesture_detector_config, this, this), | 85 gesture_detector_(config.gesture_detector_config, this, this), |
| 85 scale_gesture_detector_(config.scale_gesture_detector_config, this), | 86 scale_gesture_detector_(config.scale_gesture_detector_config, this), |
| 86 snap_scroll_controller_(config.display), | 87 snap_scroll_controller_(config.display), |
| 87 ignore_multitouch_zoom_events_(false), | 88 ignore_multitouch_zoom_events_(false), |
| 88 ignore_single_tap_(false), | 89 ignore_single_tap_(false), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 if (pinch_event_sent_ || scroll_event_sent_) | 186 if (pinch_event_sent_ || scroll_event_sent_) |
| 186 return; | 187 return; |
| 187 default: | 188 default: |
| 188 break; | 189 break; |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 client_->OnGestureEvent(gesture); | 192 client_->OnGestureEvent(gesture); |
| 192 GestureTouchUMAHistogram::RecordGestureEvent(gesture); | 193 GestureTouchUMAHistogram::RecordGestureEvent(gesture); |
| 193 } | 194 } |
| 194 | 195 |
| 195 // ScaleGestureDetector::ScaleGestureListener implementation. | 196 // ScaleGestureListener implementation. |
| 196 virtual bool OnScaleBegin(const ScaleGestureDetector& detector, | 197 virtual bool OnScaleBegin(const ScaleGestureDetector& detector, |
| 197 const MotionEvent& e) OVERRIDE { | 198 const MotionEvent& e) OVERRIDE { |
| 198 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode()) | 199 if (ignore_multitouch_zoom_events_ && !detector.InDoubleTapMode()) |
| 199 return false; | 200 return false; |
| 200 return true; | 201 return true; |
| 201 } | 202 } |
| 202 | 203 |
| 203 virtual void OnScaleEnd(const ScaleGestureDetector& detector, | 204 virtual void OnScaleEnd(const ScaleGestureDetector& detector, |
| 204 const MotionEvent& e) OVERRIDE { | 205 const MotionEvent& e) OVERRIDE { |
| 205 if (!pinch_event_sent_) | 206 if (!pinch_event_sent_) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 detector.GetFocusX(), | 256 detector.GetFocusX(), |
| 256 detector.GetFocusY(), | 257 detector.GetFocusY(), |
| 257 detector.GetFocusX() + e.GetRawOffsetX(), | 258 detector.GetFocusX() + e.GetRawOffsetX(), |
| 258 detector.GetFocusY() + e.GetRawOffsetY(), | 259 detector.GetFocusY() + e.GetRawOffsetY(), |
| 259 e.GetPointerCount(), | 260 e.GetPointerCount(), |
| 260 GetBoundingBox(e, pinch_details.type()), | 261 GetBoundingBox(e, pinch_details.type()), |
| 261 e.GetFlags())); | 262 e.GetFlags())); |
| 262 return true; | 263 return true; |
| 263 } | 264 } |
| 264 | 265 |
| 265 // GestureDetector::GestureListener implementation. | 266 // GestureListener implementation. |
| 266 virtual bool OnDown(const MotionEvent& e) OVERRIDE { | 267 virtual bool OnDown(const MotionEvent& e) OVERRIDE { |
| 267 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN); | 268 GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN); |
| 268 Send(CreateGesture(tap_details, e)); | 269 Send(CreateGesture(tap_details, e)); |
| 269 | 270 |
| 270 // Return true to indicate that we want to handle touch. | 271 // Return true to indicate that we want to handle touch. |
| 271 return true; | 272 return true; |
| 272 } | 273 } |
| 273 | 274 |
| 274 virtual bool OnScroll(const MotionEvent& e1, | 275 virtual bool OnScroll(const MotionEvent& e1, |
| 275 const MotionEvent& e2, | 276 const MotionEvent& e2, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 !current_longpress_time_.is_null() && | 436 !current_longpress_time_.is_null() && |
| 436 !IsScaleGestureDetectionInProgress()) { | 437 !IsScaleGestureDetectionInProgress()) { |
| 437 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP); | 438 GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP); |
| 438 Send(CreateGesture(long_tap_details, e)); | 439 Send(CreateGesture(long_tap_details, e)); |
| 439 return true; | 440 return true; |
| 440 } | 441 } |
| 441 | 442 |
| 442 return false; | 443 return false; |
| 443 } | 444 } |
| 444 | 445 |
| 445 // GestureDetector::DoubleTapListener implementation. | 446 // DoubleTapListener implementation. |
| 446 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { | 447 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE { |
| 447 // Long taps in the edges of the screen have their events delayed by | 448 // Long taps in the edges of the screen have their events delayed by |
| 448 // ContentViewHolder for tab swipe operations. As a consequence of the delay | 449 // ContentViewHolder for tab swipe operations. As a consequence of the delay |
| 449 // this method might be called after receiving the up event. | 450 // this method might be called after receiving the up event. |
| 450 // These corner cases should be ignored. | 451 // These corner cases should be ignored. |
| 451 if (ignore_single_tap_) | 452 if (ignore_single_tap_) |
| 452 return true; | 453 return true; |
| 453 | 454 |
| 454 ignore_single_tap_ = true; | 455 ignore_single_tap_ = true; |
| 455 | 456 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 // null'ing of the listener until the sequence has ended. | 813 // null'ing of the listener until the sequence has ended. |
| 813 if (current_down_event_) | 814 if (current_down_event_) |
| 814 return; | 815 return; |
| 815 | 816 |
| 816 const bool double_tap_enabled = | 817 const bool double_tap_enabled = |
| 817 double_tap_support_for_page_ && double_tap_support_for_platform_; | 818 double_tap_support_for_page_ && double_tap_support_for_platform_; |
| 818 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 819 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 819 } | 820 } |
| 820 | 821 |
| 821 } // namespace ui | 822 } // namespace ui |
| OLD | NEW |