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

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

Issue 1799253002: Stricter user gestures for touch - measure and warn (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "core/events/DragEvent.h" 43 #include "core/events/DragEvent.h"
44 #include "core/events/EventPath.h" 44 #include "core/events/EventPath.h"
45 #include "core/events/GestureEvent.h" 45 #include "core/events/GestureEvent.h"
46 #include "core/events/KeyboardEvent.h" 46 #include "core/events/KeyboardEvent.h"
47 #include "core/events/MouseEvent.h" 47 #include "core/events/MouseEvent.h"
48 #include "core/events/PointerEvent.h" 48 #include "core/events/PointerEvent.h"
49 #include "core/events/TextEvent.h" 49 #include "core/events/TextEvent.h"
50 #include "core/events/TouchEvent.h" 50 #include "core/events/TouchEvent.h"
51 #include "core/events/WheelEvent.h" 51 #include "core/events/WheelEvent.h"
52 #include "core/fetch/ImageResource.h" 52 #include "core/fetch/ImageResource.h"
53 #include "core/frame/Deprecation.h"
53 #include "core/frame/EventHandlerRegistry.h" 54 #include "core/frame/EventHandlerRegistry.h"
54 #include "core/frame/FrameHost.h" 55 #include "core/frame/FrameHost.h"
55 #include "core/frame/FrameView.h" 56 #include "core/frame/FrameView.h"
56 #include "core/frame/LocalFrame.h" 57 #include "core/frame/LocalFrame.h"
57 #include "core/frame/Settings.h" 58 #include "core/frame/Settings.h"
59 #include "core/frame/UseCounter.h"
58 #include "core/frame/VisualViewport.h" 60 #include "core/frame/VisualViewport.h"
59 #include "core/html/HTMLCanvasElement.h" 61 #include "core/html/HTMLCanvasElement.h"
60 #include "core/html/HTMLDialogElement.h" 62 #include "core/html/HTMLDialogElement.h"
61 #include "core/html/HTMLFrameElementBase.h" 63 #include "core/html/HTMLFrameElementBase.h"
62 #include "core/html/HTMLFrameSetElement.h" 64 #include "core/html/HTMLFrameSetElement.h"
63 #include "core/html/HTMLInputElement.h" 65 #include "core/html/HTMLInputElement.h"
64 #include "core/input/InputDeviceCapabilities.h" 66 #include "core/input/InputDeviceCapabilities.h"
65 #include "core/input/TouchActionUtil.h" 67 #include "core/input/TouchActionUtil.h"
66 #include "core/layout/HitTestRequest.h" 68 #include "core/layout/HitTestRequest.h"
67 #include "core/layout/HitTestResult.h" 69 #include "core/layout/HitTestResult.h"
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 982
981 // For 4th/5th button in the mouse since Chrome does not yet send 983 // For 4th/5th button in the mouse since Chrome does not yet send
982 // button value to Blink but in some cases it does send the event. 984 // button value to Blink but in some cases it does send the event.
983 // This check is needed to suppress such an event (crbug.com/574959) 985 // This check is needed to suppress such an event (crbug.com/574959)
984 if (mouseEvent.button() == NoButton) 986 if (mouseEvent.button() == NoButton)
985 return WebInputEventResult::HandledSuppressed; 987 return WebInputEventResult::HandledSuppressed;
986 988
987 RawPtr<FrameView> protector(m_frame->view()); 989 RawPtr<FrameView> protector(m_frame->view());
988 990
989 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 991 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
990 m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToken = gestureIndicator.currentToken(); 992 m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToken = UserGestureIndicator::currentToken();
991 993
992 cancelFakeMouseMoveEvent(); 994 cancelFakeMouseMoveEvent();
993 if (m_eventHandlerWillResetCapturingMouseEventsNode) 995 if (m_eventHandlerWillResetCapturingMouseEventsNode)
994 m_capturingMouseEventsNode = nullptr; 996 m_capturingMouseEventsNode = nullptr;
995 m_mousePressed = true; 997 m_mousePressed = true;
996 m_capturesDragging = true; 998 m_capturesDragging = true;
997 setLastKnownMousePosition(mouseEvent); 999 setLastKnownMousePosition(mouseEvent);
998 m_mouseDownTimestamp = mouseEvent.timestamp(); 1000 m_mouseDownTimestamp = mouseEvent.timestamp();
999 m_mouseDownMayStartDrag = false; 1001 m_mouseDownMayStartDrag = false;
1000 selectionController().setMouseDownMayStartSelect(false); 1002 selectionController().setMouseDownMayStartSelect(false);
(...skipping 2751 matching lines...) Expand 10 before | Expand all | Expand 10 after
3752 if (freshTouchEvents) { 3754 if (freshTouchEvents) {
3753 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should 3755 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should
3754 // have cleared the active document when we saw the last release. But we 3756 // have cleared the active document when we saw the last release. But we
3755 // have some tests that violate this, ClusterFuzz could trigger it, and 3757 // have some tests that violate this, ClusterFuzz could trigger it, and
3756 // there may be cases where the browser doesn't reliably release all 3758 // there may be cases where the browser doesn't reliably release all
3757 // touches. http://crbug.com/345372 tracks this. 3759 // touches. http://crbug.com/345372 tracks this.
3758 m_touchSequenceDocument.clear(); 3760 m_touchSequenceDocument.clear();
3759 m_touchSequenceUserGestureToken.clear(); 3761 m_touchSequenceUserGestureToken.clear();
3760 } 3762 }
3761 3763
3762 OwnPtr<UserGestureIndicator> gestureIndicator;
3763
3764 if (m_touchSequenceUserGestureToken)
3765 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequenceUser GestureToken.release()));
3766 else
3767 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture));
3768
3769 m_touchSequenceUserGestureToken = gestureIndicator->currentToken();
3770
3771 ASSERT(m_frame->view()); 3764 ASSERT(m_frame->view());
3772 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc hSequenceDocument->frame()->view())) { 3765 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc hSequenceDocument->frame()->view())) {
3773 // If the active touch document has no frame or view, it's probably bein g destroyed 3766 // If the active touch document has no frame or view, it's probably bein g destroyed
3774 // so we can't dispatch events. 3767 // so we can't dispatch events.
3775 return WebInputEventResult::NotHandled; 3768 return WebInputEventResult::NotHandled;
3776 } 3769 }
3777 3770
3778 // First do hit tests for any new touch points. 3771 // First do hit tests for any new touch points.
3779 for (unsigned i = 0; i < points.size(); ++i) { 3772 for (unsigned i = 0; i < points.size(); ++i) {
3780 const PlatformTouchPoint& point = points[i]; 3773 const PlatformTouchPoint& point = points[i];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3838 // document set to receive the events, then we can skip all the rest of 3831 // document set to receive the events, then we can skip all the rest of
3839 // this work. 3832 // this work.
3840 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !ha sTouchHandlers(m_touchSequenceDocument->frameHost()->eventHandlerRegistry()) || !m_touchSequenceDocument->frame()) { 3833 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !ha sTouchHandlers(m_touchSequenceDocument->frameHost()->eventHandlerRegistry()) || !m_touchSequenceDocument->frame()) {
3841 if (allTouchReleased) { 3834 if (allTouchReleased) {
3842 m_touchSequenceDocument.clear(); 3835 m_touchSequenceDocument.clear();
3843 m_touchSequenceUserGestureToken.clear(); 3836 m_touchSequenceUserGestureToken.clear();
3844 } 3837 }
3845 return WebInputEventResult::NotHandled; 3838 return WebInputEventResult::NotHandled;
3846 } 3839 }
3847 3840
3841 // Whether a touch should be considered a "user gesture" or not is a tricky question.
3842 // https://docs.google.com/document/d/1oF1T3O7_E4t1PYHV6gyCwHxOi3ystm0eSL5xZ u7nvOg/edit#
3843 // TODO(rbyers): Disable user gesture in some cases but retain logging for n ow (crbug.com/582140).
3844 OwnPtr<UserGestureIndicator> gestureIndicator;
3845 if (event.touchPoints().size() == 1
3846 && event.touchPoints()[0].state() == PlatformTouchPoint::TouchReleased
3847 && !event.causesScrollingIfUncanceled()) {
3848 // This is a touchend corresponding to a tap, definitely a user gesture.
dtapuska 2016/04/06 16:26:57 I think this might need a comment that the callbac
3849 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture));
3850 } else {
3851 // This is some other touch event that perhaps shouldn't be considered a user gesture.
3852 if (m_touchSequenceUserGestureToken)
3853 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence UserGestureToken.release(), &m_touchSequenceDocument->frame()->eventHandler()));
3854 else
3855 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce ssingUserGesture, &m_touchSequenceDocument->frame()->eventHandler()));
3856 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken();
3857 }
3858
3848 // Compute and store the common info used by both PointerEvent and TouchEven t. 3859 // Compute and store the common info used by both PointerEvent and TouchEven t.
3849 HeapVector<TouchInfo> touchInfos(points.size()); 3860 HeapVector<TouchInfo> touchInfos(points.size());
3850 3861
3851 for (unsigned i = 0; i < points.size(); ++i) { 3862 for (unsigned i = 0; i < points.size(); ++i) {
3852 const PlatformTouchPoint& point = points[i]; 3863 const PlatformTouchPoint& point = points[i];
3853 PlatformTouchPoint::TouchState pointState = point.state(); 3864 PlatformTouchPoint::TouchState pointState = point.state();
3854 RawPtr<EventTarget> touchTarget = nullptr; 3865 RawPtr<EventTarget> touchTarget = nullptr;
3855 String regionID; 3866 String regionID;
3856 3867
3857 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) { 3868 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3935 m_inPointerCanceledState = true; 3946 m_inPointerCanceledState = true;
3936 sendPointerCancels(touchInfos); 3947 sendPointerCancels(touchInfos);
3937 } 3948 }
3938 } else if (allTouchReleased) { 3949 } else if (allTouchReleased) {
3939 m_inPointerCanceledState = false; 3950 m_inPointerCanceledState = false;
3940 } 3951 }
3941 3952
3942 return eventResult; 3953 return eventResult;
3943 } 3954 }
3944 3955
3956 void EventHandler::userGestureUsed()
3957 {
3958 // This is invoked for UserGestureIndicators created in handleTouchEvent whi ch perhaps represent
3959 // touch actions which shouldn't be considered a user-gesture.
3960 UseCounter::count(m_frame, UseCounter::TouchDragUserGestureUsed);
3961 Deprecation::countDeprecationCrossOriginIframe(m_frame, UseCounter::TouchDra gUserGestureUsedCrossOrigin);
3962 }
3963
3945 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event) 3964 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event)
3946 { 3965 {
3947 m_mousePositionIsUnknown = false; 3966 m_mousePositionIsUnknown = false;
3948 m_lastKnownMousePosition = event.position(); 3967 m_lastKnownMousePosition = event.position();
3949 m_lastKnownMouseGlobalPosition = event.globalPosition(); 3968 m_lastKnownMouseGlobalPosition = event.globalPosition();
3950 } 3969 }
3951 3970
3952 WebInputEventResult EventHandler::passMousePressEventToSubframe(MouseEventWithHi tTestResults& mev, LocalFrame* subframe) 3971 WebInputEventResult EventHandler::passMousePressEventToSubframe(MouseEventWithHi tTestResults& mev, LocalFrame* subframe)
3953 { 3972 {
3954 selectionController().passMousePressEventToSubframe(mev); 3973 selectionController().passMousePressEventToSubframe(mev);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3992 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4011 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
3993 { 4012 {
3994 #if OS(MACOSX) 4013 #if OS(MACOSX)
3995 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4014 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
3996 #else 4015 #else
3997 return PlatformEvent::AltKey; 4016 return PlatformEvent::AltKey;
3998 #endif 4017 #endif
3999 } 4018 }
4000 4019
4001 } // namespace blink 4020 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/EventHandler.h ('k') | third_party/WebKit/Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698