Chromium Code Reviews| 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" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 // GestureProvider::ScaleGestureListener | 123 // GestureProvider::ScaleGestureListener |
| 124 | 124 |
| 125 class GestureProvider::ScaleGestureListenerImpl | 125 class GestureProvider::ScaleGestureListenerImpl |
| 126 : public ScaleGestureDetector::ScaleGestureListener { | 126 : public ScaleGestureDetector::ScaleGestureListener { |
| 127 public: | 127 public: |
| 128 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config, | 128 ScaleGestureListenerImpl(const ScaleGestureDetector::Config& config, |
| 129 GestureProvider* provider) | 129 GestureProvider* provider) |
| 130 : scale_gesture_detector_(config, this), | 130 : scale_gesture_detector_(config, this), |
| 131 provider_(provider), | 131 provider_(provider), |
| 132 ignore_multitouch_events_(false), | 132 ignore_multitouch_events_(false), |
| 133 pinch_event_sent_(false) {} | 133 pinch_event_sent_(false), |
| 134 min_pinch_update_span_delta_(config.min_pinch_update_span_delta), | |
| 135 prev_span_(0) {} | |
| 134 | 136 |
| 135 bool OnTouchEvent(const MotionEvent& event) { | 137 bool OnTouchEvent(const MotionEvent& event) { |
| 136 // TODO: Need to deal with multi-touch transition. | 138 // TODO: Need to deal with multi-touch transition. |
| 137 const bool in_scale_gesture = IsScaleGestureDetectionInProgress(); | 139 const bool in_scale_gesture = IsScaleGestureDetectionInProgress(); |
| 138 bool handled = scale_gesture_detector_.OnTouchEvent(event); | 140 bool handled = scale_gesture_detector_.OnTouchEvent(event); |
| 139 if (!in_scale_gesture && | 141 if (!in_scale_gesture && |
| 140 (event.GetAction() == MotionEvent::ACTION_UP || | 142 (event.GetAction() == MotionEvent::ACTION_UP || |
| 141 event.GetAction() == MotionEvent::ACTION_CANCEL)) { | 143 event.GetAction() == MotionEvent::ACTION_CANCEL)) { |
| 142 return false; | 144 return false; |
| 143 } | 145 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 164 0, | 166 0, |
| 165 e.GetPointerCount(), | 167 e.GetPointerCount(), |
| 166 GetBoundingBox(e))); | 168 GetBoundingBox(e))); |
| 167 pinch_event_sent_ = false; | 169 pinch_event_sent_ = false; |
| 168 } | 170 } |
| 169 | 171 |
| 170 virtual bool OnScale(const ScaleGestureDetector& detector, | 172 virtual bool OnScale(const ScaleGestureDetector& detector, |
| 171 const MotionEvent& e) OVERRIDE { | 173 const MotionEvent& e) OVERRIDE { |
| 172 if (ignore_multitouch_events_ && !detector.InDoubleTapMode()) | 174 if (ignore_multitouch_events_ && !detector.InDoubleTapMode()) |
| 173 return false; | 175 return false; |
| 176 | |
| 177 float span = detector.GetCurrentSpan(); | |
| 178 bool pinch_occured = | |
|
jdduke (slow)
2014/05/22 17:37:24
Hmm, why are you doing this before the if (!pinch_
tdresser
2014/05/22 17:57:22
Done.
| |
| 179 std::abs(span - prev_span_) >= min_pinch_update_span_delta_; | |
| 180 | |
| 181 if (!pinch_occured) | |
| 182 return true; | |
| 183 | |
| 184 prev_span_ = span; | |
| 185 | |
| 174 if (!pinch_event_sent_) { | 186 if (!pinch_event_sent_) { |
| 175 pinch_event_sent_ = true; | 187 pinch_event_sent_ = true; |
| 176 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, | 188 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, |
| 177 e.GetId(), | 189 e.GetId(), |
| 178 detector.GetEventTime(), | 190 detector.GetEventTime(), |
| 179 detector.GetFocusX(), | 191 detector.GetFocusX(), |
| 180 detector.GetFocusY(), | 192 detector.GetFocusY(), |
| 181 e.GetPointerCount(), | 193 e.GetPointerCount(), |
| 182 GetBoundingBox(e))); | 194 GetBoundingBox(e))); |
| 183 } | 195 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 | 252 |
| 241 GestureProvider* const provider_; | 253 GestureProvider* const provider_; |
| 242 | 254 |
| 243 // Completely silence multi-touch (pinch) scaling events. Used in WebView when | 255 // Completely silence multi-touch (pinch) scaling events. Used in WebView when |
| 244 // zoom support is turned off. | 256 // zoom support is turned off. |
| 245 bool ignore_multitouch_events_; | 257 bool ignore_multitouch_events_; |
| 246 | 258 |
| 247 // Whether any pinch zoom event has been sent to native. | 259 // Whether any pinch zoom event has been sent to native. |
| 248 bool pinch_event_sent_; | 260 bool pinch_event_sent_; |
| 249 | 261 |
| 262 // The minimum change in span required before this is considered a pinch. See | |
| 263 // crbug.com/373318. | |
| 264 float min_pinch_update_span_delta_; | |
| 265 | |
| 266 float prev_span_; | |
|
jdduke (slow)
2014/05/22 17:37:24
See comment above, we shouldn't need to cache the
tdresser
2014/05/22 17:57:22
Done.
| |
| 267 | |
| 250 DISALLOW_COPY_AND_ASSIGN(ScaleGestureListenerImpl); | 268 DISALLOW_COPY_AND_ASSIGN(ScaleGestureListenerImpl); |
| 251 }; | 269 }; |
| 252 | 270 |
| 253 // GestureProvider::GestureListener | 271 // GestureProvider::GestureListener |
| 254 | 272 |
| 255 class GestureProvider::GestureListenerImpl | 273 class GestureProvider::GestureListenerImpl |
| 256 : public GestureDetector::GestureListener, | 274 : public GestureDetector::GestureListener, |
| 257 public GestureDetector::DoubleTapListener { | 275 public GestureDetector::DoubleTapListener { |
| 258 public: | 276 public: |
| 259 GestureListenerImpl( | 277 GestureListenerImpl( |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 if (current_down_event_) | 793 if (current_down_event_) |
| 776 return; | 794 return; |
| 777 | 795 |
| 778 const bool double_tap_enabled = double_tap_support_for_page_ && | 796 const bool double_tap_enabled = double_tap_support_for_page_ && |
| 779 double_tap_support_for_platform_; | 797 double_tap_support_for_platform_; |
| 780 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 798 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 781 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 799 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 782 } | 800 } |
| 783 | 801 |
| 784 } // namespace ui | 802 } // namespace ui |
| OLD | NEW |