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

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: Address 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return tap_details; 109 return tap_details;
110 } 110 }
111 111
112 } // namespace 112 } // namespace
113 113
114 // GestureProvider:::Config 114 // GestureProvider:::Config
115 115
116 GestureProvider::Config::Config() 116 GestureProvider::Config::Config()
117 : display(gfx::Display::kInvalidDisplayID, gfx::Rect(1, 1)), 117 : display(gfx::Display::kInvalidDisplayID, gfx::Rect(1, 1)),
118 disable_click_delay(false), 118 disable_click_delay(false),
119 gesture_begin_end_types_enabled(false) {} 119 gesture_begin_end_types_enabled(false) {}
jdduke (slow) 2014/05/22 18:06:35 Let's initialize the min_pinch_update_span_delta t
tdresser 2014/05/22 18:25:17 It's in ScaleGestureDetector::Config, but done.
120 120
121 GestureProvider::Config::~Config() {} 121 GestureProvider::Config::~Config() {}
122 122
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 20 matching lines...) Expand all
164 0, 165 0,
165 e.GetPointerCount(), 166 e.GetPointerCount(),
166 GetBoundingBox(e))); 167 GetBoundingBox(e)));
167 pinch_event_sent_ = false; 168 pinch_event_sent_ = false;
168 } 169 }
169 170
170 virtual bool OnScale(const ScaleGestureDetector& detector, 171 virtual bool OnScale(const ScaleGestureDetector& detector,
171 const MotionEvent& e) OVERRIDE { 172 const MotionEvent& e) OVERRIDE {
172 if (ignore_multitouch_events_ && !detector.InDoubleTapMode()) 173 if (ignore_multitouch_events_ && !detector.InDoubleTapMode())
173 return false; 174 return false;
175
174 if (!pinch_event_sent_) { 176 if (!pinch_event_sent_) {
175 pinch_event_sent_ = true; 177 pinch_event_sent_ = true;
176 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN, 178 provider_->Send(CreateGesture(ET_GESTURE_PINCH_BEGIN,
177 e.GetId(), 179 e.GetId(),
178 detector.GetEventTime(), 180 detector.GetEventTime(),
179 detector.GetFocusX(), 181 detector.GetFocusX(),
180 detector.GetFocusY(), 182 detector.GetFocusY(),
181 e.GetPointerCount(), 183 e.GetPointerCount(),
182 GetBoundingBox(e))); 184 GetBoundingBox(e)));
183 } 185 }
184 186
187 float span = detector.GetCurrentSpan();
188 bool pinch_occured = std::abs(span - detector.GetPreviousSpan()) >=
189 min_pinch_update_span_delta_;
190
jdduke (slow) 2014/05/22 18:06:35 You might consider merging all of this into: if (
tdresser 2014/05/22 18:25:17 Done.
191 if (!pinch_occured)
192 return false;
193
185 float scale = detector.GetScaleFactor(); 194 float scale = detector.GetScaleFactor();
186 if (scale == 1) 195 if (scale == 1)
187 return true; 196 return true;
188 197
189 if (detector.InDoubleTapMode()) { 198 if (detector.InDoubleTapMode()) {
190 // Relative changes in the double-tap scale factor computed by |detector| 199 // Relative changes in the double-tap scale factor computed by |detector|
191 // diminish as the touch moves away from the original double-tap focus. 200 // diminish as the touch moves away from the original double-tap focus.
192 // For historical reasons, Chrome has instead adopted a scale factor 201 // For historical reasons, Chrome has instead adopted a scale factor
193 // computation that is invariant to the focal distance, where 202 // computation that is invariant to the focal distance, where
194 // the scale delta remains constant if the touch velocity is constant. 203 // the scale delta remains constant if the touch velocity is constant.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 249
241 GestureProvider* const provider_; 250 GestureProvider* const provider_;
242 251
243 // Completely silence multi-touch (pinch) scaling events. Used in WebView when 252 // Completely silence multi-touch (pinch) scaling events. Used in WebView when
244 // zoom support is turned off. 253 // zoom support is turned off.
245 bool ignore_multitouch_events_; 254 bool ignore_multitouch_events_;
246 255
247 // Whether any pinch zoom event has been sent to native. 256 // Whether any pinch zoom event has been sent to native.
248 bool pinch_event_sent_; 257 bool pinch_event_sent_;
249 258
259 // The minimum change in span required before this is considered a pinch. See
260 // crbug.com/373318.
261 float min_pinch_update_span_delta_;
262
250 DISALLOW_COPY_AND_ASSIGN(ScaleGestureListenerImpl); 263 DISALLOW_COPY_AND_ASSIGN(ScaleGestureListenerImpl);
251 }; 264 };
252 265
253 // GestureProvider::GestureListener 266 // GestureProvider::GestureListener
254 267
255 class GestureProvider::GestureListenerImpl 268 class GestureProvider::GestureListenerImpl
256 : public GestureDetector::GestureListener, 269 : public GestureDetector::GestureListener,
257 public GestureDetector::DoubleTapListener { 270 public GestureDetector::DoubleTapListener {
258 public: 271 public:
259 GestureListenerImpl( 272 GestureListenerImpl(
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 if (current_down_event_) 788 if (current_down_event_)
776 return; 789 return;
777 790
778 const bool double_tap_enabled = double_tap_support_for_page_ && 791 const bool double_tap_enabled = double_tap_support_for_page_ &&
779 double_tap_support_for_platform_; 792 double_tap_support_for_platform_;
780 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 793 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
781 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); 794 scale_gesture_listener_->SetDoubleTapEnabled(double_tap_enabled);
782 } 795 }
783 796
784 } // namespace ui 797 } // 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