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

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

Issue 2401503002: Align drag threshold across content types. (Closed)
Patch Set: Addressed nits. Created 4 years, 2 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 | « third_party/WebKit/Source/core/input/MouseEventManager.h ('k') | 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/input/MouseEventManager.h" 5 #include "core/input/MouseEventManager.h"
6 6
7 #include "core/clipboard/DataObject.h" 7 #include "core/clipboard/DataObject.h"
8 #include "core/clipboard/DataTransfer.h" 8 #include "core/clipboard/DataTransfer.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/ElementTraversal.h" 10 #include "core/dom/ElementTraversal.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 String region = canvas->getIdFromControl(element); 52 String region = canvas->getIdFromControl(element);
53 PlatformMouseEvent newMouseEvent = mouseEvent; 53 PlatformMouseEvent newMouseEvent = mouseEvent;
54 newMouseEvent.setRegion(region); 54 newMouseEvent.setRegion(region);
55 return newMouseEvent; 55 return newMouseEvent;
56 } 56 }
57 57
58 // The amount of time to wait before sending a fake mouse event triggered 58 // The amount of time to wait before sending a fake mouse event triggered
59 // during a scroll. 59 // during a scroll.
60 const double kFakeMouseMoveInterval = 0.1; 60 const double kFakeMouseMoveInterval = 0.1;
61 61
62 // TODO(crbug.com/653490): Read these values from the OS.
62 #if OS(MACOSX) 63 #if OS(MACOSX)
64 const int kDragThresholdX = 3;
65 const int kDragThresholdY = 3;
63 const double kTextDragDelay = 0.15; 66 const double kTextDragDelay = 0.15;
64 #else 67 #else
68 const int kDragThresholdX = 4;
69 const int kDragThresholdY = 4;
65 const double kTextDragDelay = 0.0; 70 const double kTextDragDelay = 0.0;
66 #endif 71 #endif
67 72
68 // The link drag hysteresis is much larger than the others because there
69 // needs to be enough space to cancel the link press without starting a link
70 // drag, and because dragging links is rare.
71 const int kLinkDragHysteresis = 40;
72 const int kImageDragHysteresis = 5;
73 const int kTextDragHysteresis = 3;
74 const int kGeneralDragHysteresis = 3;
75
76 } // namespace 73 } // namespace
77 74
78 enum class DragInitiator { Mouse, Touch }; 75 enum class DragInitiator { Mouse, Touch };
79 76
80 MouseEventManager::MouseEventManager(LocalFrame* frame, 77 MouseEventManager::MouseEventManager(LocalFrame* frame,
81 ScrollManager* scrollManager) 78 ScrollManager* scrollManager)
82 : m_frame(frame), 79 : m_frame(frame),
83 m_scrollManager(scrollManager), 80 m_scrollManager(scrollManager),
84 m_fakeMouseMoveEventTimer( 81 m_fakeMouseMoveEventTimer(
85 this, 82 this,
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 .mouseDownMayStartSelect() && 772 .mouseDownMayStartSelect() &&
776 !m_mouseDownMayStartAutoscroll; 773 !m_mouseDownMayStartAutoscroll;
777 } 774 }
778 775
779 // We are starting a text/image/url drag, so the cursor should be an arrow 776 // We are starting a text/image/url drag, so the cursor should be an arrow
780 // FIXME <rdar://7577595>: Custom cursors aren't supported during drag and 777 // FIXME <rdar://7577595>: Custom cursors aren't supported during drag and
781 // drop (default to pointer). 778 // drop (default to pointer).
782 m_frame->view()->setCursor(pointerCursor()); 779 m_frame->view()->setCursor(pointerCursor());
783 780
784 if (initiator == DragInitiator::Mouse && 781 if (initiator == DragInitiator::Mouse &&
785 !dragHysteresisExceeded(event.event().position())) 782 !dragThresholdExceeded(event.event().position()))
786 return true; 783 return true;
787 784
788 // Once we're past the hysteresis point, we don't want to treat this gesture 785 // Once we're past the drag threshold, we don't want to treat this gesture as
789 // as a click 786 // a click.
790 invalidateClick(); 787 invalidateClick();
791 788
792 if (!tryStartDrag(event)) { 789 if (!tryStartDrag(event)) {
793 // Something failed to start the drag, clean up. 790 // Something failed to start the drag, clean up.
794 clearDragDataTransfer(); 791 clearDragDataTransfer();
795 dragState().m_dragSrc = nullptr; 792 dragState().m_dragSrc = nullptr;
796 } 793 }
797 794
798 m_mouseDownMayStartDrag = false; 795 m_mouseDownMayStartDrag = false;
799 // Whether or not the drag actually started, no more default handling (like 796 // Whether or not the drag actually started, no more default handling (like
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 // In case the drag was ended due to an escape key press we need to ensure 920 // In case the drag was ended due to an escape key press we need to ensure
924 // that consecutive mousemove events don't reinitiate the drag and drop. 921 // that consecutive mousemove events don't reinitiate the drag and drop.
925 m_mouseDownMayStartDrag = false; 922 m_mouseDownMayStartDrag = false;
926 } 923 }
927 924
928 DragState& MouseEventManager::dragState() { 925 DragState& MouseEventManager::dragState() {
929 DEFINE_STATIC_LOCAL(DragState, state, (new DragState)); 926 DEFINE_STATIC_LOCAL(DragState, state, (new DragState));
930 return state; 927 return state;
931 } 928 }
932 929
933 bool MouseEventManager::dragHysteresisExceeded( 930 bool MouseEventManager::dragThresholdExceeded(
934 const IntPoint& dragLocationInRootFrame) const { 931 const IntPoint& dragLocationInRootFrame) const {
935 FrameView* view = m_frame->view(); 932 FrameView* view = m_frame->view();
936 if (!view) 933 if (!view)
937 return false; 934 return false;
938 IntPoint dragLocation = view->rootFrameToContents(dragLocationInRootFrame); 935 IntPoint dragLocation = view->rootFrameToContents(dragLocationInRootFrame);
939 IntSize delta = dragLocation - m_mouseDownPos; 936 IntSize delta = dragLocation - m_mouseDownPos;
940 937
941 int threshold = kGeneralDragHysteresis; 938 // WebKit's drag thresholds depend on the type of object being dragged. If we
942 switch (dragState().m_dragType) { 939 // want to revive that behavior, we can multiply the threshold constants with
943 case DragSourceActionSelection: 940 // a number based on dragState().m_dragType.
944 threshold = kTextDragHysteresis;
945 break;
946 case DragSourceActionImage:
947 threshold = kImageDragHysteresis;
948 break;
949 case DragSourceActionLink:
950 threshold = kLinkDragHysteresis;
951 break;
952 case DragSourceActionDHTML:
953 break;
954 case DragSourceActionNone:
955 NOTREACHED();
956 }
957 941
958 return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold; 942 return abs(delta.width()) >= kDragThresholdX ||
943 abs(delta.height()) >= kDragThresholdY;
959 } 944 }
960 945
961 void MouseEventManager::clearDragHeuristicState() { 946 void MouseEventManager::clearDragHeuristicState() {
962 // Used to prevent mouseMoveEvent from initiating a drag before 947 // Used to prevent mouseMoveEvent from initiating a drag before
963 // the mouse is pressed again. 948 // the mouse is pressed again.
964 m_mousePressed = false; 949 m_mousePressed = false;
965 m_capturesDragging = false; 950 m_capturesDragging = false;
966 m_mouseDownMayStartDrag = false; 951 m_mouseDownMayStartDrag = false;
967 m_mouseDownMayStartAutoscroll = false; 952 m_mouseDownMayStartAutoscroll = false;
968 } 953 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 996
1012 void MouseEventManager::setClickCount(int clickCount) { 997 void MouseEventManager::setClickCount(int clickCount) {
1013 m_clickCount = clickCount; 998 m_clickCount = clickCount;
1014 } 999 }
1015 1000
1016 bool MouseEventManager::mouseDownMayStartDrag() { 1001 bool MouseEventManager::mouseDownMayStartDrag() {
1017 return m_mouseDownMayStartDrag; 1002 return m_mouseDownMayStartDrag;
1018 } 1003 }
1019 1004
1020 } // namespace blink 1005 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/MouseEventManager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698