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/GestureManager.h" | 5 #include "core/input/GestureManager.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/editing/SelectionController.h" | 8 #include "core/editing/SelectionController.h" |
9 #include "core/events/GestureEvent.h" | 9 #include "core/events/GestureEvent.h" |
10 #include "core/frame/FrameHost.h" | 10 #include "core/frame/FrameHost.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return handleGestureTapDown(targetedEvent); | 97 return handleGestureTapDown(targetedEvent); |
98 case PlatformEvent::GestureTap: | 98 case PlatformEvent::GestureTap: |
99 return handleGestureTap(targetedEvent); | 99 return handleGestureTap(targetedEvent); |
100 case PlatformEvent::GestureShowPress: | 100 case PlatformEvent::GestureShowPress: |
101 return handleGestureShowPress(); | 101 return handleGestureShowPress(); |
102 case PlatformEvent::GestureLongPress: | 102 case PlatformEvent::GestureLongPress: |
103 return handleGestureLongPress(targetedEvent); | 103 return handleGestureLongPress(targetedEvent); |
104 case PlatformEvent::GestureLongTap: | 104 case PlatformEvent::GestureLongTap: |
105 return handleGestureLongTap(targetedEvent); | 105 return handleGestureLongTap(targetedEvent); |
106 case PlatformEvent::GestureTwoFingerTap: | 106 case PlatformEvent::GestureTwoFingerTap: |
107 return m_frame->eventHandler().sendContextMenuEventForGesture(targetedEv
ent); | 107 return handleGestureTwoFingerTap(targetedEvent); |
108 case PlatformEvent::GesturePinchBegin: | 108 case PlatformEvent::GesturePinchBegin: |
109 case PlatformEvent::GesturePinchEnd: | 109 case PlatformEvent::GesturePinchEnd: |
110 case PlatformEvent::GesturePinchUpdate: | 110 case PlatformEvent::GesturePinchUpdate: |
111 case PlatformEvent::GestureTapDownCancel: | 111 case PlatformEvent::GestureTapDownCancel: |
112 case PlatformEvent::GestureTapUnconfirmed: | 112 case PlatformEvent::GestureTapUnconfirmed: |
113 break; | 113 break; |
114 default: | 114 default: |
115 NOTREACHED(); | 115 NOTREACHED(); |
116 } | 116 } |
117 | 117 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 m_longTapShouldInvokeContextMenu = true; | 259 m_longTapShouldInvokeContextMenu = true; |
260 return WebInputEventResult::HandledSystem; | 260 return WebInputEventResult::HandledSystem; |
261 } | 261 } |
262 IntPoint hitTestPoint = m_frame->view()->rootFrameToContents(gestureEvent.po
sition()); | 262 IntPoint hitTestPoint = m_frame->view()->rootFrameToContents(gestureEvent.po
sition()); |
263 HitTestResult result = m_frame->eventHandler().hitTestResultAtPoint(hitTestP
oint); | 263 HitTestResult result = m_frame->eventHandler().hitTestResultAtPoint(hitTestP
oint); |
264 if (m_selectionController->handleGestureLongPress(gestureEvent, result)) { | 264 if (m_selectionController->handleGestureLongPress(gestureEvent, result)) { |
265 m_frame->eventHandler().focusDocumentView(); | 265 m_frame->eventHandler().focusDocumentView(); |
266 return WebInputEventResult::HandledSystem; | 266 return WebInputEventResult::HandledSystem; |
267 } | 267 } |
268 | 268 |
269 return m_frame->eventHandler().sendContextMenuEventForGesture(targetedEvent)
; | 269 return sendContextMenuEventForGesture(targetedEvent); |
270 } | 270 } |
271 | 271 |
272 WebInputEventResult GestureManager::handleGestureLongTap(const GestureEventWithH
itTestResults& targetedEvent) | 272 WebInputEventResult GestureManager::handleGestureLongTap(const GestureEventWithH
itTestResults& targetedEvent) |
273 { | 273 { |
274 #if !OS(ANDROID) | 274 #if !OS(ANDROID) |
275 if (m_longTapShouldInvokeContextMenu) { | 275 if (m_longTapShouldInvokeContextMenu) { |
276 m_longTapShouldInvokeContextMenu = false; | 276 m_longTapShouldInvokeContextMenu = false; |
277 return m_frame->eventHandler().sendContextMenuEventForGesture(targetedEv
ent); | 277 return sendContextMenuEventForGesture(targetedEvent); |
278 } | 278 } |
279 #endif | 279 #endif |
280 return WebInputEventResult::NotHandled; | 280 return WebInputEventResult::NotHandled; |
281 } | 281 } |
282 | 282 |
| 283 WebInputEventResult GestureManager::handleGestureTwoFingerTap(const GestureEvent
WithHitTestResults& targetedEvent) |
| 284 { |
| 285 return sendContextMenuEventForGesture(targetedEvent); |
| 286 } |
| 287 |
| 288 WebInputEventResult GestureManager::sendContextMenuEventForGesture(const Gesture
EventWithHitTestResults& targetedEvent) |
| 289 { |
| 290 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); |
| 291 unsigned modifiers = gestureEvent.getModifiers(); |
| 292 |
| 293 if (!m_suppressMouseEventsFromGestures) { |
| 294 // Send MouseMoved event prior to handling (https://crbug.com/485290). |
| 295 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.g
lobalPosition(), |
| 296 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0, |
| 297 static_cast<PlatformEvent::Modifiers>(modifiers), |
| 298 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerP
roperties::PointerType::Mouse); |
| 299 m_frame->eventHandler().dispatchMouseEvent( |
| 300 EventTypeNames::mousemove, targetedEvent.hitTestResult().innerNode()
, 0, fakeMouseMove); |
| 301 } |
| 302 |
| 303 PlatformEvent::EventType eventType = PlatformEvent::MousePressed; |
| 304 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp()) |
| 305 eventType = PlatformEvent::MouseReleased; |
| 306 |
| 307 // To simulate right-click behavior, we send a right mouse down and then con
text menu event. |
| 308 // TODO(crbug.com/579564): Maybe we should not send mouse down at all |
| 309 PlatformMouseEvent mouseEvent(targetedEvent.event().position(), targetedEven
t.event().globalPosition(), RightButton, eventType, 1, |
| 310 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::RightBu
ttonDown), |
| 311 PlatformMouseEvent::FromTouch, WTF::monotonicallyIncreasingTime(), WebPo
interProperties::PointerType::Mouse); |
| 312 if (!m_suppressMouseEventsFromGestures) { |
| 313 // FIXME: Send HitTestResults to avoid redundant hit tests. |
| 314 m_frame->eventHandler().handleMousePressEvent(mouseEvent); |
| 315 } |
| 316 |
| 317 return m_frame->eventHandler().sendContextMenuEvent(mouseEvent); |
| 318 // We do not need to send a corresponding mouse release because in case of |
| 319 // right-click, the context menu takes capture and consumes all events. |
| 320 } |
| 321 |
283 WebInputEventResult GestureManager::handleGestureShowPress() | 322 WebInputEventResult GestureManager::handleGestureShowPress() |
284 { | 323 { |
285 m_lastShowPressTimestamp = WTF::monotonicallyIncreasingTime(); | 324 m_lastShowPressTimestamp = WTF::monotonicallyIncreasingTime(); |
286 | 325 |
287 FrameView* view = m_frame->view(); | 326 FrameView* view = m_frame->view(); |
288 if (!view) | 327 if (!view) |
289 return WebInputEventResult::NotHandled; | 328 return WebInputEventResult::NotHandled; |
290 if (ScrollAnimatorBase* scrollAnimator = view->existingScrollAnimator()) | 329 if (ScrollAnimatorBase* scrollAnimator = view->existingScrollAnimator()) |
291 scrollAnimator->cancelAnimation(); | 330 scrollAnimator->cancelAnimation(); |
292 const FrameView::ScrollableAreaSet* areas = view->scrollableAreas(); | 331 const FrameView::ScrollableAreaSet* areas = view->scrollableAreas(); |
(...skipping 14 matching lines...) Expand all Loading... |
307 | 346 |
308 return &m_frame->page()->frameHost(); | 347 return &m_frame->page()->frameHost(); |
309 } | 348 } |
310 | 349 |
311 double GestureManager::getLastShowPressTimestamp() const | 350 double GestureManager::getLastShowPressTimestamp() const |
312 { | 351 { |
313 return m_lastShowPressTimestamp; | 352 return m_lastShowPressTimestamp; |
314 } | 353 } |
315 | 354 |
316 } // namespace blink | 355 } // namespace blink |
OLD | NEW |