OLD | NEW |
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 static const double minimumActiveInterval = 0.15; | 133 static const double minimumActiveInterval = 0.15; |
134 | 134 |
135 #if OS(MACOSX) | 135 #if OS(MACOSX) |
136 static const double TextDragDelay = 0.15; | 136 static const double TextDragDelay = 0.15; |
137 #else | 137 #else |
138 static const double TextDragDelay = 0.0; | 138 static const double TextDragDelay = 0.0; |
139 #endif | 139 #endif |
140 | 140 |
141 enum NoCursorChangeType { NoCursorChange }; | 141 enum NoCursorChangeType { NoCursorChange }; |
142 | 142 |
| 143 enum class DragInitiator { Mouse, Touch }; |
| 144 |
143 class OptionalCursor { | 145 class OptionalCursor { |
144 public: | 146 public: |
145 OptionalCursor(NoCursorChangeType) : m_isCursorChange(false) { } | 147 OptionalCursor(NoCursorChangeType) : m_isCursorChange(false) { } |
146 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs
or) { } | 148 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs
or) { } |
147 | 149 |
148 bool isCursorChange() const { return m_isCursorChange; } | 150 bool isCursorChange() const { return m_isCursorChange; } |
149 const Cursor& cursor() const { ASSERT(m_isCursorChange); return m_cursor; } | 151 const Cursor& cursor() const { ASSERT(m_isCursorChange); return m_cursor; } |
150 | 152 |
151 private: | 153 private: |
152 bool m_isCursorChange; | 154 bool m_isCursorChange; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 , m_eventHandlerWillResetCapturingMouseEventsNode(0) | 216 , m_eventHandlerWillResetCapturingMouseEventsNode(0) |
215 , m_clickCount(0) | 217 , m_clickCount(0) |
216 , m_shouldOnlyFireDragOverEvent(false) | 218 , m_shouldOnlyFireDragOverEvent(false) |
217 , m_mousePositionIsUnknown(true) | 219 , m_mousePositionIsUnknown(true) |
218 , m_mouseDownTimestamp(0) | 220 , m_mouseDownTimestamp(0) |
219 , m_widgetIsLatched(false) | 221 , m_widgetIsLatched(false) |
220 , m_touchPressed(false) | 222 , m_touchPressed(false) |
221 , m_scrollGestureHandlingNode(nullptr) | 223 , m_scrollGestureHandlingNode(nullptr) |
222 , m_lastGestureScrollOverWidget(false) | 224 , m_lastGestureScrollOverWidget(false) |
223 , m_maxMouseMovedDuration(0) | 225 , m_maxMouseMovedDuration(0) |
224 , m_didStartDrag(false) | |
225 , m_longTapShouldInvokeContextMenu(false) | 226 , m_longTapShouldInvokeContextMenu(false) |
226 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) | 227 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) |
227 , m_lastShowPressTimestamp(0) | 228 , m_lastShowPressTimestamp(0) |
228 { | 229 { |
229 } | 230 } |
230 | 231 |
231 EventHandler::~EventHandler() | 232 EventHandler::~EventHandler() |
232 { | 233 { |
233 ASSERT(!m_fakeMouseMoveEventTimer.isActive()); | 234 ASSERT(!m_fakeMouseMoveEventTimer.isActive()); |
234 } | 235 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 m_latchedWheelEventNode = nullptr; | 290 m_latchedWheelEventNode = nullptr; |
290 m_previousWheelScrolledNode = nullptr; | 291 m_previousWheelScrolledNode = nullptr; |
291 m_targetForTouchID.clear(); | 292 m_targetForTouchID.clear(); |
292 m_touchSequenceDocument.clear(); | 293 m_touchSequenceDocument.clear(); |
293 m_touchSequenceUserGestureToken.clear(); | 294 m_touchSequenceUserGestureToken.clear(); |
294 m_scrollGestureHandlingNode = nullptr; | 295 m_scrollGestureHandlingNode = nullptr; |
295 m_lastGestureScrollOverWidget = false; | 296 m_lastGestureScrollOverWidget = false; |
296 m_previousGestureScrolledNode = nullptr; | 297 m_previousGestureScrolledNode = nullptr; |
297 m_scrollbarHandlingScrollGesture = nullptr; | 298 m_scrollbarHandlingScrollGesture = nullptr; |
298 m_maxMouseMovedDuration = 0; | 299 m_maxMouseMovedDuration = 0; |
299 m_didStartDrag = false; | |
300 m_touchPressed = false; | 300 m_touchPressed = false; |
301 m_mouseDownMayStartSelect = false; | 301 m_mouseDownMayStartSelect = false; |
302 m_mouseDownMayStartDrag = false; | 302 m_mouseDownMayStartDrag = false; |
303 m_lastShowPressTimestamp = 0; | 303 m_lastShowPressTimestamp = 0; |
304 m_lastDeferredTapElement = nullptr; | 304 m_lastDeferredTapElement = nullptr; |
305 m_eventHandlerWillResetCapturingMouseEventsNode = false; | 305 m_eventHandlerWillResetCapturingMouseEventsNode = false; |
306 m_mouseDownWasSingleClickInSelection = false; | 306 m_mouseDownWasSingleClickInSelection = false; |
307 m_selectionInitiationState = HaveNotStartedSelection; | 307 m_selectionInitiationState = HaveNotStartedSelection; |
308 m_mouseDownMayStartAutoscroll = false; | 308 m_mouseDownMayStartAutoscroll = false; |
309 m_svgPan = false; | 309 m_svgPan = false; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 return swallowEvent; | 646 return swallowEvent; |
647 } | 647 } |
648 | 648 |
649 bool EventHandler::handleMouseDraggedEvent(const MouseEventWithHitTestResults& e
vent) | 649 bool EventHandler::handleMouseDraggedEvent(const MouseEventWithHitTestResults& e
vent) |
650 { | 650 { |
651 TRACE_EVENT0("blink", "EventHandler::handleMouseDraggedEvent"); | 651 TRACE_EVENT0("blink", "EventHandler::handleMouseDraggedEvent"); |
652 | 652 |
653 if (!m_mousePressed) | 653 if (!m_mousePressed) |
654 return false; | 654 return false; |
655 | 655 |
656 if (handleDrag(event, ShouldCheckDragHysteresis)) | 656 if (handleDrag(event, DragInitiator::Mouse)) |
657 return true; | 657 return true; |
658 | 658 |
659 Node* targetNode = event.innerNode(); | 659 Node* targetNode = event.innerNode(); |
660 if (event.event().button() != LeftButton || !targetNode) | 660 if (event.event().button() != LeftButton || !targetNode) |
661 return false; | 661 return false; |
662 | 662 |
663 RenderObject* renderer = targetNode->renderer(); | 663 RenderObject* renderer = targetNode->renderer(); |
664 if (!renderer) { | 664 if (!renderer) { |
665 Node* parent = NodeRenderingTraversal::parent(targetNode); | 665 Node* parent = NodeRenderingTraversal::parent(targetNode); |
666 if (!parent) | 666 if (!parent) |
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2307 m_longTapShouldInvokeContextMenu = false; | 2307 m_longTapShouldInvokeContextMenu = false; |
2308 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_
frame->view()) { | 2308 if (m_frame->settings() && m_frame->settings()->touchDragDropEnabled() && m_
frame->view()) { |
2309 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi
tion(), LeftButton, PlatformEvent::MousePressed, 1, | 2309 PlatformMouseEvent mouseDownEvent(adjustedPoint, gestureEvent.globalPosi
tion(), LeftButton, PlatformEvent::MousePressed, 1, |
2310 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey
(), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); | 2310 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey
(), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); |
2311 m_mouseDown = mouseDownEvent; | 2311 m_mouseDown = mouseDownEvent; |
2312 | 2312 |
2313 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi
tion(), LeftButton, PlatformEvent::MouseMoved, 1, | 2313 PlatformMouseEvent mouseDragEvent(adjustedPoint, gestureEvent.globalPosi
tion(), LeftButton, PlatformEvent::MouseMoved, 1, |
2314 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey
(), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); | 2314 gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey
(), gestureEvent.metaKey(), PlatformMouseEvent::FromTouch, WTF::currentTime()); |
2315 HitTestRequest request(HitTestRequest::ReadOnly); | 2315 HitTestRequest request(HitTestRequest::ReadOnly); |
2316 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE
vent); | 2316 MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseDragE
vent); |
2317 m_didStartDrag = false; | |
2318 m_mouseDownMayStartDrag = true; | 2317 m_mouseDownMayStartDrag = true; |
2319 dragState().m_dragSrc = nullptr; | 2318 dragState().m_dragSrc = nullptr; |
2320 m_mouseDownPos = m_frame->view()->windowToContents(mouseDragEvent.positi
on()); | 2319 m_mouseDownPos = m_frame->view()->windowToContents(mouseDragEvent.positi
on()); |
2321 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); | 2320 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); |
2322 handleDrag(mev, DontCheckDragHysteresis); | 2321 if (handleDrag(mev, DragInitiator::Touch)) { |
2323 if (m_didStartDrag) { | |
2324 m_longTapShouldInvokeContextMenu = true; | 2322 m_longTapShouldInvokeContextMenu = true; |
2325 return true; | 2323 return true; |
2326 } | 2324 } |
2327 } | 2325 } |
2328 #if OS(ANDROID) | 2326 #if OS(ANDROID) |
2329 bool shouldLongPressSelectWord = true; | 2327 bool shouldLongPressSelectWord = true; |
2330 #else | 2328 #else |
2331 bool shouldLongPressSelectWord = m_frame->settings() && m_frame->settings()-
>touchEditingEnabled(); | 2329 bool shouldLongPressSelectWord = m_frame->settings() && m_frame->settings()-
>touchEditingEnabled(); |
2332 #endif | 2330 #endif |
2333 if (shouldLongPressSelectWord) { | 2331 if (shouldLongPressSelectWord) { |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3194 if (dragState().m_dragSrc && !dragState().m_dragSrc->inDocument()) | 3192 if (dragState().m_dragSrc && !dragState().m_dragSrc->inDocument()) |
3195 dragState().m_dragSrc = rootEditableElement; | 3193 dragState().m_dragSrc = rootEditableElement; |
3196 } | 3194 } |
3197 | 3195 |
3198 // returns if we should continue "default processing", i.e., whether eventhandle
r canceled | 3196 // returns if we should continue "default processing", i.e., whether eventhandle
r canceled |
3199 bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const Pla
tformMouseEvent& event) | 3197 bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const Pla
tformMouseEvent& event) |
3200 { | 3198 { |
3201 return !dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, dra
gState().m_dragDataTransfer.get()); | 3199 return !dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, dra
gState().m_dragDataTransfer.get()); |
3202 } | 3200 } |
3203 | 3201 |
3204 bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, CheckDr
agHysteresis checkDragHysteresis) | 3202 bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event, DragIni
tiator initiator) |
3205 { | 3203 { |
3206 ASSERT(event.event().type() == PlatformEvent::MouseMoved); | 3204 ASSERT(event.event().type() == PlatformEvent::MouseMoved); |
3207 // Callers must protect the reference to FrameView, since this function may
dispatch DOM | 3205 // Callers must protect the reference to FrameView, since this function may
dispatch DOM |
3208 // events, causing page/FrameView to go away. | 3206 // events, causing page/FrameView to go away. |
3209 ASSERT(m_frame); | 3207 ASSERT(m_frame); |
3210 ASSERT(m_frame->view()); | 3208 ASSERT(m_frame->view()); |
3211 if (!m_frame->page()) | 3209 if (!m_frame->page()) |
3212 return false; | 3210 return false; |
3213 | 3211 |
| 3212 // FIXME: Does this ever get hit?? |
3214 if (event.event().button() != LeftButton || event.event().type() != Platform
Event::MouseMoved) { | 3213 if (event.event().button() != LeftButton || event.event().type() != Platform
Event::MouseMoved) { |
3215 // If we allowed the other side of the bridge to handle a drag | 3214 // If we allowed the other side of the bridge to handle a drag |
3216 // last time, then m_mousePressed might still be set. So we | 3215 // last time, then m_mousePressed might still be set. So we |
3217 // clear it now to make sure the next move after a drag | 3216 // clear it now to make sure the next move after a drag |
3218 // doesn't look like a drag. | 3217 // doesn't look like a drag. |
3219 m_mousePressed = false; | 3218 m_mousePressed = false; |
3220 return false; | 3219 return false; |
3221 } | 3220 } |
3222 | 3221 |
3223 if (m_mouseDownMayStartDrag) { | 3222 if (m_mouseDownMayStartDrag) { |
3224 HitTestRequest request(HitTestRequest::ReadOnly); | 3223 HitTestRequest request(HitTestRequest::ReadOnly); |
3225 HitTestResult result(m_mouseDownPos); | 3224 HitTestResult result(m_mouseDownPos); |
3226 m_frame->contentRenderer()->hitTest(request, result); | 3225 m_frame->contentRenderer()->hitTest(request, result); |
3227 Node* node = result.innerNode(); | 3226 Node* node = result.innerNode(); |
3228 if (node) { | 3227 if (node) { |
3229 DragController::SelectionDragPolicy selectionDragPolicy = event.even
t().timestamp() - m_mouseDownTimestamp < TextDragDelay | 3228 DragController::SelectionDragPolicy selectionDragPolicy = event.even
t().timestamp() - m_mouseDownTimestamp < TextDragDelay |
3230 ? DragController::DelayedSelectionDragResolution | 3229 ? DragController::DelayedSelectionDragResolution |
3231 : DragController::ImmediateSelectionDragResolution; | 3230 : DragController::ImmediateSelectionDragResolution; |
3232 dragState().m_dragSrc = m_frame->page()->dragController().draggableN
ode(m_frame, node, m_mouseDownPos, selectionDragPolicy, dragState().m_dragType); | 3231 dragState().m_dragSrc = m_frame->page()->dragController().draggableN
ode(m_frame, node, m_mouseDownPos, selectionDragPolicy, dragState().m_dragType); |
3233 } else { | 3232 } else { |
3234 dragState().m_dragSrc = nullptr; | 3233 dragState().m_dragSrc = nullptr; |
3235 } | 3234 } |
3236 | 3235 |
3237 if (!dragState().m_dragSrc) | 3236 if (!dragState().m_dragSrc) |
3238 m_mouseDownMayStartDrag = false; // no element is draggable | 3237 m_mouseDownMayStartDrag = false; // no element is draggable |
3239 } | 3238 } |
3240 | 3239 |
3241 if (!m_mouseDownMayStartDrag) | 3240 if (!m_mouseDownMayStartDrag) |
3242 return !mouseDownMayStartSelect() && !m_mouseDownMayStartAutoscroll; | 3241 return initiator == DragInitiator::Mouse && !mouseDownMayStartSelect() &
& !m_mouseDownMayStartAutoscroll; |
3243 | 3242 |
3244 // We are starting a text/image/url drag, so the cursor should be an arrow | 3243 // We are starting a text/image/url drag, so the cursor should be an arrow |
3245 // FIXME <rdar://7577595>: Custom cursors aren't supported during drag and d
rop (default to pointer). | 3244 // FIXME <rdar://7577595>: Custom cursors aren't supported during drag and d
rop (default to pointer). |
3246 m_frame->view()->setCursor(pointerCursor()); | 3245 m_frame->view()->setCursor(pointerCursor()); |
3247 | 3246 |
3248 if (checkDragHysteresis == ShouldCheckDragHysteresis && !dragHysteresisExcee
ded(event.event().position())) | 3247 if (initiator == DragInitiator::Mouse && !dragHysteresisExceeded(event.event
().position())) |
3249 return true; | 3248 return true; |
3250 | 3249 |
3251 // Once we're past the hysteresis point, we don't want to treat this gesture
as a click | 3250 // Once we're past the hysteresis point, we don't want to treat this gesture
as a click |
3252 invalidateClick(); | 3251 invalidateClick(); |
3253 | 3252 |
3254 if (!tryStartDrag(event)) { | 3253 if (!tryStartDrag(event)) { |
3255 // Something failed to start the drag, clean up. | 3254 // Something failed to start the drag, clean up. |
3256 clearDragDataTransfer(); | 3255 clearDragDataTransfer(); |
3257 dragState().m_dragSrc = nullptr; | 3256 dragState().m_dragSrc = nullptr; |
3258 } | 3257 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3296 // Do that by checking if m_dragSrc is still set. | 3295 // Do that by checking if m_dragSrc is still set. |
3297 m_mouseDownMayStartDrag = dispatchDragSrcEvent(EventTypeNames::dragstart, m_
mouseDown) | 3296 m_mouseDownMayStartDrag = dispatchDragSrcEvent(EventTypeNames::dragstart, m_
mouseDown) |
3298 && !m_frame->selection().isInPasswordField() && dragState().m_dragSrc; | 3297 && !m_frame->selection().isInPasswordField() && dragState().m_dragSrc; |
3299 | 3298 |
3300 // Invalidate clipboard here against anymore pasteboard writing for security
. The drag | 3299 // Invalidate clipboard here against anymore pasteboard writing for security
. The drag |
3301 // image can still be changed as we drag, but not the pasteboard data. | 3300 // image can still be changed as we drag, but not the pasteboard data. |
3302 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferImageWritable); | 3301 dragState().m_dragDataTransfer->setAccessPolicy(DataTransferImageWritable); |
3303 | 3302 |
3304 if (m_mouseDownMayStartDrag) { | 3303 if (m_mouseDownMayStartDrag) { |
3305 // Dispatching the event could cause Page to go away. Make sure it's sti
ll valid before trying to use DragController. | 3304 // Dispatching the event could cause Page to go away. Make sure it's sti
ll valid before trying to use DragController. |
3306 m_didStartDrag = m_frame->page() && dragController.startDrag(m_frame, dr
agState(), event.event(), m_mouseDownPos); | 3305 if (m_frame->page() && dragController.startDrag(m_frame, dragState(), ev
ent.event(), m_mouseDownPos)) |
3307 // FIXME: This seems pretty useless now. The gesture code uses this as a
signal for | |
3308 // whether or not the drag started, but perhaps it can simply use the re
turn value from | |
3309 // handleDrag(), even though it doesn't mean exactly the same thing. | |
3310 if (m_didStartDrag) | |
3311 return true; | 3306 return true; |
3312 // Drag was canned at the last minute - we owe m_dragSrc a DRAGEND event | 3307 // Drag was canned at the last minute - we owe m_dragSrc a DRAGEND event |
3313 dispatchDragSrcEvent(EventTypeNames::dragend, event.event()); | 3308 dispatchDragSrcEvent(EventTypeNames::dragend, event.event()); |
3314 } | 3309 } |
3315 | 3310 |
3316 return false; | 3311 return false; |
3317 } | 3312 } |
3318 | 3313 |
3319 bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEve
nt, TextEventInputType inputType) | 3314 bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEve
nt, TextEventInputType inputType) |
3320 { | 3315 { |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3871 unsigned EventHandler::accessKeyModifiers() | 3866 unsigned EventHandler::accessKeyModifiers() |
3872 { | 3867 { |
3873 #if OS(MACOSX) | 3868 #if OS(MACOSX) |
3874 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; | 3869 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; |
3875 #else | 3870 #else |
3876 return PlatformEvent::AltKey; | 3871 return PlatformEvent::AltKey; |
3877 #endif | 3872 #endif |
3878 } | 3873 } |
3879 | 3874 |
3880 } // namespace blink | 3875 } // namespace blink |
OLD | NEW |