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

Side by Side Diff: ui/events/gesture_detection/gesture_provider.cc

Issue 298823006: [Aura] Reduce frequency of PinchUpdate events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Jared's comments. Created 6 years, 7 months 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 | Annotate | Revision Log
OLDNEW
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
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) {}
134 135
135 bool OnTouchEvent(const MotionEvent& event) { 136 bool OnTouchEvent(const MotionEvent& event) {
136 // TODO: Need to deal with multi-touch transition. 137 // TODO: Need to deal with multi-touch transition.
137 const bool in_scale_gesture = IsScaleGestureDetectionInProgress(); 138 const bool in_scale_gesture = IsScaleGestureDetectionInProgress();
138 bool handled = scale_gesture_detector_.OnTouchEvent(event); 139 bool handled = scale_gesture_detector_.OnTouchEvent(event);
139 if (!in_scale_gesture && 140 if (!in_scale_gesture &&
140 (event.GetAction() == MotionEvent::ACTION_UP || 141 (event.GetAction() == MotionEvent::ACTION_UP ||
141 event.GetAction() == MotionEvent::ACTION_CANCEL)) { 142 event.GetAction() == MotionEvent::ACTION_CANCEL)) {
142 return false; 143 return false;
143 } 144 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 pinch_event_sent_ = true; 176 pinch_event_sent_ = true;
176 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, 177 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN,
177 e.GetId(), 178 e.GetId(),
178 detector.GetEventTime(), 179 detector.GetEventTime(),
179 detector.GetFocusX(), 180 detector.GetFocusX(),
180 detector.GetFocusY(), 181 detector.GetFocusY(),
181 e.GetPointerCount(), 182 e.GetPointerCount(),
182 GetBoundingBox(e))); 183 GetBoundingBox(e)));
183 } 184 }
184 185
186 if (std::abs(detector.GetCurrentSpan() - detector.GetPreviousSpan()) <
187 min_pinch_update_span_delta_) {
188 return false;
189 }
190
185 float scale = detector.GetScaleFactor(); 191 float scale = detector.GetScaleFactor();
186 if (scale == 1) 192 if (scale == 1)
187 return true; 193 return true;
188 194
189 if (detector.InDoubleTapMode()) { 195 if (detector.InDoubleTapMode()) {
190 // Relative changes in the double-tap scale factor computed by |detector| 196 // Relative changes in the double-tap scale factor computed by |detector|
191 // diminish as the touch moves away from the original double-tap focus. 197 // diminish as the touch moves away from the original double-tap focus.
192 // For historical reasons, Chrome has instead adopted a scale factor 198 // For historical reasons, Chrome has instead adopted a scale factor
193 // computation that is invariant to the focal distance, where 199 // computation that is invariant to the focal distance, where
194 // the scale delta remains constant if the touch velocity is constant. 200 // the scale delta remains constant if the touch velocity is constant.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 246
241 GestureProvider* const provider_; 247 GestureProvider* const provider_;
242 248
243 // Completely silence multi-touch (pinch) scaling events. Used in WebView when 249 // Completely silence multi-touch (pinch) scaling events. Used in WebView when
244 // zoom support is turned off. 250 // zoom support is turned off.
245 bool ignore_multitouch_events_; 251 bool ignore_multitouch_events_;
246 252
247 // Whether any pinch zoom event has been sent to native. 253 // Whether any pinch zoom event has been sent to native.
248 bool pinch_event_sent_; 254 bool pinch_event_sent_;
249 255
256 // The minimum change in span required before this is considered a pinch. See
257 // crbug.com/373318.
258 float min_pinch_update_span_delta_;
259
250 DISALLOW_COPY_AND_ASSIGN(ScaleGestureListenerImpl); 260 DISALLOW_COPY_AND_ASSIGN(ScaleGestureListenerImpl);
251 }; 261 };
252 262
253 // GestureProvider::GestureListener 263 // GestureProvider::GestureListener
254 264
255 class GestureProvider::GestureListenerImpl 265 class GestureProvider::GestureListenerImpl
256 : public GestureDetector::GestureListener, 266 : public GestureDetector::GestureListener,
257 public GestureDetector::DoubleTapListener { 267 public GestureDetector::DoubleTapListener {
258 public: 268 public:
259 GestureListenerImpl( 269 GestureListenerImpl(
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 if (current_down_event_) 785 if (current_down_event_)
776 return; 786 return;
777 787
778 const bool double_tap_enabled = double_tap_support_for_page_ && 788 const bool double_tap_enabled = double_tap_support_for_page_ &&
779 double_tap_support_for_platform_; 789 double_tap_support_for_platform_;
780 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 790 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
781 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 791 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
782 } 792 }
783 793
784 } // namespace ui 794 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_config_helper_aura.cc ('k') | ui/events/gesture_detection/gesture_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698