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

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: Tweaks 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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 989
988 // For 4th/5th button in the mouse since Chrome does not yet send 990 // For 4th/5th button in the mouse since Chrome does not yet send
989 // button value to Blink but in some cases it does send the event. 991 // button value to Blink but in some cases it does send the event.
990 // This check is needed to suppress such an event (crbug.com/574959) 992 // This check is needed to suppress such an event (crbug.com/574959)
991 if (mouseEvent.button() == NoButton) 993 if (mouseEvent.button() == NoButton)
992 return WebInputEventResult::HandledSuppressed; 994 return WebInputEventResult::HandledSuppressed;
993 995
994 RawPtr<FrameView> protector(m_frame->view()); 996 RawPtr<FrameView> protector(m_frame->view());
995 997
996 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); 998 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture);
997 m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToken = gestureIndicator.currentToken(); 999 m_frame->localFrameRoot()->eventHandler().m_lastMouseDownUserGestureToken = UserGestureIndicator::currentToken();
998 1000
999 cancelFakeMouseMoveEvent(); 1001 cancelFakeMouseMoveEvent();
1000 if (m_eventHandlerWillResetCapturingMouseEventsNode) 1002 if (m_eventHandlerWillResetCapturingMouseEventsNode)
1001 m_capturingMouseEventsNode = nullptr; 1003 m_capturingMouseEventsNode = nullptr;
1002 m_mousePressed = true; 1004 m_mousePressed = true;
1003 m_capturesDragging = true; 1005 m_capturesDragging = true;
1004 setLastKnownMousePosition(mouseEvent); 1006 setLastKnownMousePosition(mouseEvent);
1005 m_mouseDownTimestamp = mouseEvent.timestamp(); 1007 m_mouseDownTimestamp = mouseEvent.timestamp();
1006 m_mouseDownMayStartDrag = false; 1008 m_mouseDownMayStartDrag = false;
1007 selectionController().setMouseDownMayStartSelect(false); 1009 selectionController().setMouseDownMayStartSelect(false);
(...skipping 2758 matching lines...) Expand 10 before | Expand all | Expand 10 after
3766 if (freshTouchEvents) { 3768 if (freshTouchEvents) {
3767 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should 3769 // Ideally we'd ASSERT !m_touchSequenceDocument here since we should
3768 // have cleared the active document when we saw the last release. But we 3770 // have cleared the active document when we saw the last release. But we
3769 // have some tests that violate this, ClusterFuzz could trigger it, and 3771 // have some tests that violate this, ClusterFuzz could trigger it, and
3770 // there may be cases where the browser doesn't reliably release all 3772 // there may be cases where the browser doesn't reliably release all
3771 // touches. http://crbug.com/345372 tracks this. 3773 // touches. http://crbug.com/345372 tracks this.
3772 m_touchSequenceDocument.clear(); 3774 m_touchSequenceDocument.clear();
3773 m_touchSequenceUserGestureToken.clear(); 3775 m_touchSequenceUserGestureToken.clear();
3774 } 3776 }
3775 3777
3776 OwnPtr<UserGestureIndicator> gestureIndicator;
3777
3778 if (m_touchSequenceUserGestureToken)
3779 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequenceUser GestureToken.release()));
3780 else
3781 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture));
3782
3783 m_touchSequenceUserGestureToken = gestureIndicator->currentToken();
3784
3785 ASSERT(m_frame->view()); 3778 ASSERT(m_frame->view());
3786 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc hSequenceDocument->frame()->view())) { 3779 if (m_touchSequenceDocument && (!m_touchSequenceDocument->frame() || !m_touc hSequenceDocument->frame()->view())) {
3787 // If the active touch document has no frame or view, it's probably bein g destroyed 3780 // If the active touch document has no frame or view, it's probably bein g destroyed
3788 // so we can't dispatch events. 3781 // so we can't dispatch events.
3789 return WebInputEventResult::NotHandled; 3782 return WebInputEventResult::NotHandled;
3790 } 3783 }
3791 3784
3792 // First do hit tests for any new touch points. 3785 // First do hit tests for any new touch points.
3793 for (unsigned i = 0; i < points.size(); ++i) { 3786 for (unsigned i = 0; i < points.size(); ++i) {
3794 const PlatformTouchPoint& point = points[i]; 3787 const PlatformTouchPoint& point = points[i];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3852 // document set to receive the events, then we can skip all the rest of 3845 // document set to receive the events, then we can skip all the rest of
3853 // this work. 3846 // this work.
3854 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !ha sTouchHandlers(m_touchSequenceDocument->frameHost()->eventHandlerRegistry()) || !m_touchSequenceDocument->frame()) { 3847 if (!m_touchSequenceDocument || !m_touchSequenceDocument->frameHost() || !ha sTouchHandlers(m_touchSequenceDocument->frameHost()->eventHandlerRegistry()) || !m_touchSequenceDocument->frame()) {
3855 if (allTouchReleased) { 3848 if (allTouchReleased) {
3856 m_touchSequenceDocument.clear(); 3849 m_touchSequenceDocument.clear();
3857 m_touchSequenceUserGestureToken.clear(); 3850 m_touchSequenceUserGestureToken.clear();
3858 } 3851 }
3859 return WebInputEventResult::NotHandled; 3852 return WebInputEventResult::NotHandled;
3860 } 3853 }
3861 3854
3855 // Whether a touch should be considered a "user gesture" or not is a tricky question.
3856 // https://docs.google.com/document/d/1oF1T3O7_E4t1PYHV6gyCwHxOi3ystm0eSL5xZ u7nvOg/edit#
3857 // TODO(rbyers): Disable user gesture in some cases but retain logging for n ow (crbug.com/582140).
3858 OwnPtr<UserGestureIndicator> gestureIndicator;
3859 if (event.touchPoints().size() == 1
3860 && event.touchPoints()[0].state() == PlatformTouchPoint::TouchReleased
3861 && !event.causesScrollingIfUncanceled()) {
3862 // This is a touchend corresponding to a tap, definitely a user gesture. So don't supply
3863 // a UserGestureUtilizedCallback.
3864 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture));
3865 } else {
3866 // This is some other touch event that perhaps shouldn't be considered a user gesture. So
3867 // use a UserGestureUtilizedCallback to get metrics / deprecation warnin gs.
3868 if (m_touchSequenceUserGestureToken)
3869 gestureIndicator = adoptPtr(new UserGestureIndicator(m_touchSequence UserGestureToken.release(), &m_touchSequenceDocument->frame()->eventHandler()));
3870 else
3871 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProce ssingUserGesture, &m_touchSequenceDocument->frame()->eventHandler()));
3872 m_touchSequenceUserGestureToken = UserGestureIndicator::currentToken();
3873 }
3874
3862 // Compute and store the common info used by both PointerEvent and TouchEven t. 3875 // Compute and store the common info used by both PointerEvent and TouchEven t.
3863 HeapVector<TouchInfo> touchInfos(points.size()); 3876 HeapVector<TouchInfo> touchInfos(points.size());
3864 3877
3865 for (unsigned i = 0; i < points.size(); ++i) { 3878 for (unsigned i = 0; i < points.size(); ++i) {
3866 const PlatformTouchPoint& point = points[i]; 3879 const PlatformTouchPoint& point = points[i];
3867 PlatformTouchPoint::TouchState pointState = point.state(); 3880 PlatformTouchPoint::TouchState pointState = point.state();
3868 RawPtr<EventTarget> touchTarget = nullptr; 3881 RawPtr<EventTarget> touchTarget = nullptr;
3869 String regionID; 3882 String regionID;
3870 3883
3871 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) { 3884 if (pointState == PlatformTouchPoint::TouchReleased || pointState == Pla tformTouchPoint::TouchCancelled) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 m_inPointerCanceledState = true; 3962 m_inPointerCanceledState = true;
3950 sendPointerCancels(touchInfos); 3963 sendPointerCancels(touchInfos);
3951 } 3964 }
3952 } else if (allTouchReleased) { 3965 } else if (allTouchReleased) {
3953 m_inPointerCanceledState = false; 3966 m_inPointerCanceledState = false;
3954 } 3967 }
3955 3968
3956 return eventResult; 3969 return eventResult;
3957 } 3970 }
3958 3971
3972 void EventHandler::userGestureUtilized()
3973 {
3974 // This is invoked for UserGestureIndicators created in handleTouchEvent whi ch perhaps represent
3975 // touch actions which shouldn't be considered a user-gesture.
3976 UseCounter::count(m_frame, UseCounter::TouchDragUserGestureUsed);
3977 Deprecation::countDeprecationCrossOriginIframe(m_frame, UseCounter::TouchDra gUserGestureUsedCrossOrigin);
3978 }
3979
3959 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event) 3980 void EventHandler::setLastKnownMousePosition(const PlatformMouseEvent& event)
3960 { 3981 {
3961 m_mousePositionIsUnknown = false; 3982 m_mousePositionIsUnknown = false;
3962 m_lastKnownMousePosition = event.position(); 3983 m_lastKnownMousePosition = event.position();
3963 m_lastKnownMouseGlobalPosition = event.globalPosition(); 3984 m_lastKnownMouseGlobalPosition = event.globalPosition();
3964 } 3985 }
3965 3986
3966 WebInputEventResult EventHandler::passMousePressEventToSubframe(MouseEventWithHi tTestResults& mev, LocalFrame* subframe) 3987 WebInputEventResult EventHandler::passMousePressEventToSubframe(MouseEventWithHi tTestResults& mev, LocalFrame* subframe)
3967 { 3988 {
3968 selectionController().passMousePressEventToSubframe(mev); 3989 selectionController().passMousePressEventToSubframe(mev);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4006 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4027 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4007 { 4028 {
4008 #if OS(MACOSX) 4029 #if OS(MACOSX)
4009 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4030 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4010 #else 4031 #else
4011 return PlatformEvent::AltKey; 4032 return PlatformEvent::AltKey;
4012 #endif 4033 #endif
4013 } 4034 }
4014 4035
4015 } // namespace blink 4036 } // 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