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

Side by Side Diff: Source/core/input/EventHandler.cpp

Issue 1157303006: Prevent synthetic mouse moves from firing during trackpad scroll. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase. Created 5 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 using namespace HTMLNames; 100 using namespace HTMLNames;
101 101
102 // The link drag hysteresis is much larger than the others because there 102 // The link drag hysteresis is much larger than the others because there
103 // needs to be enough space to cancel the link press without starting a link dra g, 103 // needs to be enough space to cancel the link press without starting a link dra g,
104 // and because dragging links is rare. 104 // and because dragging links is rare.
105 static const int LinkDragHysteresis = 40; 105 static const int LinkDragHysteresis = 40;
106 static const int ImageDragHysteresis = 5; 106 static const int ImageDragHysteresis = 5;
107 static const int TextDragHysteresis = 3; 107 static const int TextDragHysteresis = 3;
108 static const int GeneralDragHysteresis = 3; 108 static const int GeneralDragHysteresis = 3;
109 109
110 // The amount of time to wait before sending a fake mouse event, triggered 110 // The amount of time to wait before sending a fake mouse event triggered
111 // during a scroll. The short interval is used if the content responds to the mo use events quickly enough, 111 // during a scroll.
112 // otherwise the long interval is used. 112 static const double fakeMouseMoveInterval = 0.1;
113 static const double fakeMouseMoveShortInterval = 0.1;
114 static const double fakeMouseMoveLongInterval = 0.250;
115 113
116 // The amount of time to wait for a cursor update on style and layout changes 114 // The amount of time to wait for a cursor update on style and layout changes
117 // Set to 50Hz, no need to be faster than common screen refresh rate 115 // Set to 50Hz, no need to be faster than common screen refresh rate
118 static const double cursorUpdateInterval = 0.02; 116 static const double cursorUpdateInterval = 0.02;
119 117
120 static const int maximumCursorSize = 128; 118 static const int maximumCursorSize = 128;
121 119
122 // It's pretty unlikely that a scale of less than one would ever be used. But al l we really 120 // It's pretty unlikely that a scale of less than one would ever be used. But al l we really
123 // need to ensure here is that the scale isn't so small that integer overflow ca n occur when 121 // need to ensure here is that the scale isn't so small that integer overflow ca n occur when
124 // dividing cursor sizes (limited above) by the scale. 122 // dividing cursor sizes (limited above) by the scale.
(...skipping 19 matching lines...) Expand all
144 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs or) { } 142 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs or) { }
145 143
146 bool isCursorChange() const { return m_isCursorChange; } 144 bool isCursorChange() const { return m_isCursorChange; }
147 const Cursor& cursor() const { ASSERT(m_isCursorChange); return m_cursor; } 145 const Cursor& cursor() const { ASSERT(m_isCursorChange); return m_cursor; }
148 146
149 private: 147 private:
150 bool m_isCursorChange; 148 bool m_isCursorChange;
151 Cursor m_cursor; 149 Cursor m_cursor;
152 }; 150 };
153 151
154 class MaximumDurationTracker {
155 public:
156 explicit MaximumDurationTracker(double *maxDuration)
157 : m_maxDuration(maxDuration)
158 , m_start(monotonicallyIncreasingTime())
159 {
160 }
161
162 ~MaximumDurationTracker()
163 {
164 *m_maxDuration = max(*m_maxDuration, monotonicallyIncreasingTime() - m_s tart);
165 }
166
167 private:
168 double* m_maxDuration;
169 double m_start;
170 };
171
172 static inline ScrollGranularity wheelGranularityToScrollGranularity(WheelEvent* event) 152 static inline ScrollGranularity wheelGranularityToScrollGranularity(WheelEvent* event)
173 { 153 {
174 unsigned deltaMode = event->deltaMode(); 154 unsigned deltaMode = event->deltaMode();
175 if (deltaMode == WheelEvent::DOM_DELTA_PAGE) 155 if (deltaMode == WheelEvent::DOM_DELTA_PAGE)
176 return ScrollByPage; 156 return ScrollByPage;
177 if (deltaMode == WheelEvent::DOM_DELTA_LINE) 157 if (deltaMode == WheelEvent::DOM_DELTA_LINE)
178 return ScrollByLine; 158 return ScrollByLine;
179 ASSERT(deltaMode == WheelEvent::DOM_DELTA_PIXEL); 159 ASSERT(deltaMode == WheelEvent::DOM_DELTA_PIXEL);
180 return event->hasPreciseScrollingDeltas() ? ScrollByPrecisePixel : ScrollByP ixel; 160 return event->hasPreciseScrollingDeltas() ? ScrollByPrecisePixel : ScrollByP ixel;
181 } 161 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 , m_eventHandlerWillResetCapturingMouseEventsNode(0) 209 , m_eventHandlerWillResetCapturingMouseEventsNode(0)
230 , m_clickCount(0) 210 , m_clickCount(0)
231 , m_shouldOnlyFireDragOverEvent(false) 211 , m_shouldOnlyFireDragOverEvent(false)
232 , m_accumulatedRootOverscroll(FloatSize()) 212 , m_accumulatedRootOverscroll(FloatSize())
233 , m_mousePositionIsUnknown(true) 213 , m_mousePositionIsUnknown(true)
234 , m_mouseDownTimestamp(0) 214 , m_mouseDownTimestamp(0)
235 , m_widgetIsLatched(false) 215 , m_widgetIsLatched(false)
236 , m_touchPressed(false) 216 , m_touchPressed(false)
237 , m_scrollGestureHandlingNode(nullptr) 217 , m_scrollGestureHandlingNode(nullptr)
238 , m_lastGestureScrollOverWidget(false) 218 , m_lastGestureScrollOverWidget(false)
239 , m_maxMouseMovedDuration(0)
240 , m_longTapShouldInvokeContextMenu(false) 219 , m_longTapShouldInvokeContextMenu(false)
241 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 220 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
242 , m_lastShowPressTimestamp(0) 221 , m_lastShowPressTimestamp(0)
243 , m_deltaConsumedForScrollSequence(false) 222 , m_deltaConsumedForScrollSequence(false)
244 { 223 {
245 } 224 }
246 225
247 EventHandler::~EventHandler() 226 EventHandler::~EventHandler()
248 { 227 {
249 ASSERT(!m_fakeMouseMoveEventTimer.isActive()); 228 ASSERT(!m_fakeMouseMoveEventTimer.isActive());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 m_capturingMouseEventsNode = nullptr; 285 m_capturingMouseEventsNode = nullptr;
307 m_latchedWheelEventNode = nullptr; 286 m_latchedWheelEventNode = nullptr;
308 m_previousWheelScrolledNode = nullptr; 287 m_previousWheelScrolledNode = nullptr;
309 m_targetForTouchID.clear(); 288 m_targetForTouchID.clear();
310 m_touchSequenceDocument.clear(); 289 m_touchSequenceDocument.clear();
311 m_touchSequenceUserGestureToken.clear(); 290 m_touchSequenceUserGestureToken.clear();
312 m_scrollGestureHandlingNode = nullptr; 291 m_scrollGestureHandlingNode = nullptr;
313 m_lastGestureScrollOverWidget = false; 292 m_lastGestureScrollOverWidget = false;
314 m_previousGestureScrolledNode = nullptr; 293 m_previousGestureScrolledNode = nullptr;
315 m_scrollbarHandlingScrollGesture = nullptr; 294 m_scrollbarHandlingScrollGesture = nullptr;
316 m_maxMouseMovedDuration = 0;
317 m_touchPressed = false; 295 m_touchPressed = false;
318 m_pointerIdManager.clear(); 296 m_pointerIdManager.clear();
319 m_mouseDownMayStartDrag = false; 297 m_mouseDownMayStartDrag = false;
320 m_lastShowPressTimestamp = 0; 298 m_lastShowPressTimestamp = 0;
321 m_lastDeferredTapElement = nullptr; 299 m_lastDeferredTapElement = nullptr;
322 m_eventHandlerWillResetCapturingMouseEventsNode = false; 300 m_eventHandlerWillResetCapturingMouseEventsNode = false;
323 m_mouseDownMayStartAutoscroll = false; 301 m_mouseDownMayStartAutoscroll = false;
324 m_svgPan = false; 302 m_svgPan = false;
325 m_mouseDownPos = IntPoint(); 303 m_mouseDownPos = IntPoint();
326 m_mouseDownTimestamp = 0; 304 m_mouseDownTimestamp = 0;
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 } 1012 }
1035 1013
1036 return nullptr; 1014 return nullptr;
1037 } 1015 }
1038 1016
1039 bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& event) 1017 bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& event)
1040 { 1018 {
1041 TRACE_EVENT0("blink", "EventHandler::handleMouseMoveEvent"); 1019 TRACE_EVENT0("blink", "EventHandler::handleMouseMoveEvent");
1042 1020
1043 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 1021 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
1044 MaximumDurationTracker maxDurationTracker(&m_maxMouseMovedDuration);
1045 1022
1046 HitTestResult hoveredNode = HitTestResult(); 1023 HitTestResult hoveredNode = HitTestResult();
1047 bool result = handleMouseMoveOrLeaveEvent(event, &hoveredNode); 1024 bool result = handleMouseMoveOrLeaveEvent(event, &hoveredNode);
1048 1025
1049 Page* page = m_frame->page(); 1026 Page* page = m_frame->page();
1050 if (!page) 1027 if (!page)
1051 return result; 1028 return result;
1052 1029
1053 if (DeprecatedPaintLayer* layer = layerForNode(hoveredNode.innerNode())) { 1030 if (DeprecatedPaintLayer* layer = layerForNode(hoveredNode.innerNode())) {
1054 if (ScrollableArea* layerScrollableArea = associatedScrollableArea(layer )) 1031 if (ScrollableArea* layerScrollableArea = associatedScrollableArea(layer ))
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2775 if (m_mousePressed) 2752 if (m_mousePressed)
2776 return; 2753 return;
2777 2754
2778 if (m_mousePositionIsUnknown) 2755 if (m_mousePositionIsUnknown)
2779 return; 2756 return;
2780 2757
2781 Settings* settings = m_frame->settings(); 2758 Settings* settings = m_frame->settings();
2782 if (settings && !settings->deviceSupportsMouse()) 2759 if (settings && !settings->deviceSupportsMouse())
2783 return; 2760 return;
2784 2761
2785 // If the content has ever taken longer than fakeMouseMoveShortInterval we 2762 // Reschedule the timer, to prevent dispatching mouse move events
2786 // reschedule the timer and use a longer time. This will cause the content 2763 // during a scroll. This avoids a potential source of scroll jank.
2787 // to receive these moves only after the user is done scrolling, reducing 2764 if (m_fakeMouseMoveEventTimer.isActive())
2788 // pauses during the scroll. 2765 m_fakeMouseMoveEventTimer.stop();
2789 if (m_maxMouseMovedDuration > fakeMouseMoveShortInterval) { 2766 m_fakeMouseMoveEventTimer.startOneShot(fakeMouseMoveInterval, FROM_HERE);
2790 if (m_fakeMouseMoveEventTimer.isActive())
2791 m_fakeMouseMoveEventTimer.stop();
2792 m_fakeMouseMoveEventTimer.startOneShot(fakeMouseMoveLongInterval, FROM_H ERE);
2793 } else {
2794 if (!m_fakeMouseMoveEventTimer.isActive())
2795 m_fakeMouseMoveEventTimer.startOneShot(fakeMouseMoveShortInterval, F ROM_HERE);
2796 }
2797 } 2767 }
2798 2768
2799 void EventHandler::dispatchFakeMouseMoveEventSoonInQuad(const FloatQuad& quad) 2769 void EventHandler::dispatchFakeMouseMoveEventSoonInQuad(const FloatQuad& quad)
2800 { 2770 {
2801 FrameView* view = m_frame->view(); 2771 FrameView* view = m_frame->view();
2802 if (!view) 2772 if (!view)
2803 return; 2773 return;
2804 2774
2805 if (!quad.containsPoint(view->rootFrameToContents(m_lastKnownMousePosition)) ) 2775 if (!quad.containsPoint(view->rootFrameToContents(m_lastKnownMousePosition)) )
2806 return; 2776 return;
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
3889 unsigned EventHandler::accessKeyModifiers() 3859 unsigned EventHandler::accessKeyModifiers()
3890 { 3860 {
3891 #if OS(MACOSX) 3861 #if OS(MACOSX)
3892 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3862 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3893 #else 3863 #else
3894 return PlatformEvent::AltKey; 3864 return PlatformEvent::AltKey;
3895 #endif 3865 #endif
3896 } 3866 }
3897 3867
3898 } // namespace blink 3868 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698