| OLD | NEW |
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // TODO(crbug.com/653490): Read these values from the OS. |
| 63 #if OS(MACOSX) | 63 #if OS(MACOSX) |
| 64 const int kDragThresholdX = 3; | 64 const int kDragThresholdX = 3; |
| 65 const int kDragThresholdY = 3; | 65 const int kDragThresholdY = 3; |
| 66 const double kTextDragDelay = 0.15; | 66 const TimeDelta kTextDragDelay = TimeDelta::FromSecondsD(0.15); |
| 67 #else | 67 #else |
| 68 const int kDragThresholdX = 4; | 68 const int kDragThresholdX = 4; |
| 69 const int kDragThresholdY = 4; | 69 const int kDragThresholdY = 4; |
| 70 const double kTextDragDelay = 0.0; | 70 const TimeDelta kTextDragDelay = TimeDelta::FromSecondsD(0.0); |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 enum class DragInitiator { Mouse, Touch }; | 75 enum class DragInitiator { Mouse, Touch }; |
| 76 | 76 |
| 77 MouseEventManager::MouseEventManager(LocalFrame& frame, | 77 MouseEventManager::MouseEventManager(LocalFrame& frame, |
| 78 ScrollManager& scrollManager) | 78 ScrollManager& scrollManager) |
| 79 : m_frame(frame), | 79 : m_frame(frame), |
| 80 m_scrollManager(scrollManager), | 80 m_scrollManager(scrollManager), |
| 81 m_fakeMouseMoveEventTimer( | 81 m_fakeMouseMoveEventTimer( |
| 82 this, | 82 this, |
| 83 &MouseEventManager::fakeMouseMoveEventTimerFired) { | 83 &MouseEventManager::fakeMouseMoveEventTimerFired) { |
| 84 clear(); | 84 clear(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void MouseEventManager::clear() { | 87 void MouseEventManager::clear() { |
| 88 m_nodeUnderMouse = nullptr; | 88 m_nodeUnderMouse = nullptr; |
| 89 m_mousePressNode = nullptr; | 89 m_mousePressNode = nullptr; |
| 90 m_mouseDownMayStartAutoscroll = false; | 90 m_mouseDownMayStartAutoscroll = false; |
| 91 m_mouseDownMayStartDrag = false; | 91 m_mouseDownMayStartDrag = false; |
| 92 m_capturesDragging = false; | 92 m_capturesDragging = false; |
| 93 m_isMousePositionUnknown = true; | 93 m_isMousePositionUnknown = true; |
| 94 m_lastKnownMousePosition = IntPoint(); | 94 m_lastKnownMousePosition = IntPoint(); |
| 95 m_lastKnownMouseGlobalPosition = IntPoint(); | 95 m_lastKnownMouseGlobalPosition = IntPoint(); |
| 96 m_mousePressed = false; | 96 m_mousePressed = false; |
| 97 m_clickCount = 0; | 97 m_clickCount = 0; |
| 98 m_clickNode = nullptr; | 98 m_clickNode = nullptr; |
| 99 m_mouseDownPos = IntPoint(); | 99 m_mouseDownPos = IntPoint(); |
| 100 m_mouseDownTimestamp = 0; | 100 m_mouseDownTimestamp = TimeTicks(); |
| 101 m_mouseDown = PlatformMouseEvent(); | 101 m_mouseDown = PlatformMouseEvent(); |
| 102 m_svgPan = false; | 102 m_svgPan = false; |
| 103 m_dragStartPos = LayoutPoint(); | 103 m_dragStartPos = LayoutPoint(); |
| 104 m_fakeMouseMoveEventTimer.stop(); | 104 m_fakeMouseMoveEventTimer.stop(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 MouseEventManager::~MouseEventManager() = default; | 107 MouseEventManager::~MouseEventManager() = default; |
| 108 | 108 |
| 109 DEFINE_TRACE(MouseEventManager) { | 109 DEFINE_TRACE(MouseEventManager) { |
| 110 visitor->trace(m_frame); | 110 visitor->trace(m_frame); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // Don't dispatch a synthetic mouse move event if the mouse cursor is not | 297 // Don't dispatch a synthetic mouse move event if the mouse cursor is not |
| 298 // visible to the user. | 298 // visible to the user. |
| 299 if (!m_frame->page()->isCursorVisible()) | 299 if (!m_frame->page()->isCursorVisible()) |
| 300 return; | 300 return; |
| 301 | 301 |
| 302 PlatformMouseEvent fakeMouseMoveEvent( | 302 PlatformMouseEvent fakeMouseMoveEvent( |
| 303 m_lastKnownMousePosition, m_lastKnownMouseGlobalPosition, | 303 m_lastKnownMousePosition, m_lastKnownMouseGlobalPosition, |
| 304 WebPointerProperties::Button::NoButton, PlatformEvent::MouseMoved, 0, | 304 WebPointerProperties::Button::NoButton, PlatformEvent::MouseMoved, 0, |
| 305 static_cast<PlatformEvent::Modifiers>( | 305 static_cast<PlatformEvent::Modifiers>( |
| 306 KeyboardEventManager::getCurrentModifierState()), | 306 KeyboardEventManager::getCurrentModifierState()), |
| 307 PlatformMouseEvent::RealOrIndistinguishable, | 307 PlatformMouseEvent::RealOrIndistinguishable, TimeTicks::Now(), |
| 308 monotonicallyIncreasingTime(), WebPointerProperties::PointerType::Mouse); | 308 WebPointerProperties::PointerType::Mouse); |
| 309 Vector<PlatformMouseEvent> coalescedEvents; | 309 Vector<PlatformMouseEvent> coalescedEvents; |
| 310 m_frame->eventHandler().handleMouseMoveEvent(fakeMouseMoveEvent, | 310 m_frame->eventHandler().handleMouseMoveEvent(fakeMouseMoveEvent, |
| 311 coalescedEvents); | 311 coalescedEvents); |
| 312 } | 312 } |
| 313 | 313 |
| 314 void MouseEventManager::cancelFakeMouseMoveEvent() { | 314 void MouseEventManager::cancelFakeMouseMoveEvent() { |
| 315 m_fakeMouseMoveEventTimer.stop(); | 315 m_fakeMouseMoveEventTimer.stop(); |
| 316 } | 316 } |
| 317 | 317 |
| 318 void MouseEventManager::setNodeUnderMouse( | 318 void MouseEventManager::setNodeUnderMouse( |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 IntPoint adjustedPoint = gestureEvent.position(); | 649 IntPoint adjustedPoint = gestureEvent.position(); |
| 650 unsigned modifiers = gestureEvent.getModifiers(); | 650 unsigned modifiers = gestureEvent.getModifiers(); |
| 651 | 651 |
| 652 // TODO(mustaq): Suppressing long-tap MouseEvents could break | 652 // TODO(mustaq): Suppressing long-tap MouseEvents could break |
| 653 // drag-drop. Will do separately because of the risk. crbug.com/606938. | 653 // drag-drop. Will do separately because of the risk. crbug.com/606938. |
| 654 PlatformMouseEvent mouseDownEvent( | 654 PlatformMouseEvent mouseDownEvent( |
| 655 adjustedPoint, gestureEvent.globalPosition(), | 655 adjustedPoint, gestureEvent.globalPosition(), |
| 656 WebPointerProperties::Button::Left, PlatformEvent::MousePressed, 1, | 656 WebPointerProperties::Button::Left, PlatformEvent::MousePressed, 1, |
| 657 static_cast<PlatformEvent::Modifiers>(modifiers | | 657 static_cast<PlatformEvent::Modifiers>(modifiers | |
| 658 PlatformEvent::LeftButtonDown), | 658 PlatformEvent::LeftButtonDown), |
| 659 PlatformMouseEvent::FromTouch, WTF::monotonicallyIncreasingTime(), | 659 PlatformMouseEvent::FromTouch, TimeTicks::Now(), |
| 660 WebPointerProperties::PointerType::Mouse); | 660 WebPointerProperties::PointerType::Mouse); |
| 661 m_mouseDown = mouseDownEvent; | 661 m_mouseDown = mouseDownEvent; |
| 662 | 662 |
| 663 PlatformMouseEvent mouseDragEvent( | 663 PlatformMouseEvent mouseDragEvent( |
| 664 adjustedPoint, gestureEvent.globalPosition(), | 664 adjustedPoint, gestureEvent.globalPosition(), |
| 665 WebPointerProperties::Button::Left, PlatformEvent::MouseMoved, 1, | 665 WebPointerProperties::Button::Left, PlatformEvent::MouseMoved, 1, |
| 666 static_cast<PlatformEvent::Modifiers>(modifiers | | 666 static_cast<PlatformEvent::Modifiers>(modifiers | |
| 667 PlatformEvent::LeftButtonDown), | 667 PlatformEvent::LeftButtonDown), |
| 668 PlatformMouseEvent::FromTouch, WTF::monotonicallyIncreasingTime(), | 668 PlatformMouseEvent::FromTouch, TimeTicks::Now(), |
| 669 WebPointerProperties::PointerType::Mouse); | 669 WebPointerProperties::PointerType::Mouse); |
| 670 HitTestRequest request(HitTestRequest::ReadOnly); | 670 HitTestRequest request(HitTestRequest::ReadOnly); |
| 671 MouseEventWithHitTestResults mev = | 671 MouseEventWithHitTestResults mev = |
| 672 EventHandlingUtil::performMouseEventHitTest(m_frame, request, | 672 EventHandlingUtil::performMouseEventHitTest(m_frame, request, |
| 673 mouseDragEvent); | 673 mouseDragEvent); |
| 674 m_mouseDownMayStartDrag = true; | 674 m_mouseDownMayStartDrag = true; |
| 675 dragState().m_dragSrc = nullptr; | 675 dragState().m_dragSrc = nullptr; |
| 676 m_mouseDownPos = | 676 m_mouseDownPos = |
| 677 m_frame->view()->rootFrameToContents(mouseDragEvent.position()); | 677 m_frame->view()->rootFrameToContents(mouseDragEvent.position()); |
| 678 return handleDrag(mev, DragInitiator::Touch); | 678 return handleDrag(mev, DragInitiator::Touch); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 | 993 |
| 994 void MouseEventManager::setClickCount(int clickCount) { | 994 void MouseEventManager::setClickCount(int clickCount) { |
| 995 m_clickCount = clickCount; | 995 m_clickCount = clickCount; |
| 996 } | 996 } |
| 997 | 997 |
| 998 bool MouseEventManager::mouseDownMayStartDrag() { | 998 bool MouseEventManager::mouseDownMayStartDrag() { |
| 999 return m_mouseDownMayStartDrag; | 999 return m_mouseDownMayStartDrag; |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 } // namespace blink | 1002 } // namespace blink |
| OLD | NEW |