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

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

Issue 2573073003: Collapse the API surface on WebInputEvent via accessor functions. (Closed)
Patch Set: Fix nits Created 3 years, 11 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 // 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/dom/DocumentUserGestureToken.h" 8 #include "core/dom/DocumentUserGestureToken.h"
9 #include "core/editing/SelectionController.h" 9 #include "core/editing/SelectionController.h"
10 #include "core/events/GestureEvent.h" 10 #include "core/events/GestureEvent.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 DispatchEventResult gestureDomEventResult = 90 DispatchEventResult gestureDomEventResult =
91 eventTarget->dispatchEvent(gestureDomEvent); 91 eventTarget->dispatchEvent(gestureDomEvent);
92 if (gestureDomEventResult != DispatchEventResult::NotCanceled) { 92 if (gestureDomEventResult != DispatchEventResult::NotCanceled) {
93 DCHECK(gestureDomEventResult != 93 DCHECK(gestureDomEventResult !=
94 DispatchEventResult::CanceledByEventHandler); 94 DispatchEventResult::CanceledByEventHandler);
95 return EventHandlingUtil::toWebInputEventResult(gestureDomEventResult); 95 return EventHandlingUtil::toWebInputEventResult(gestureDomEventResult);
96 } 96 }
97 } 97 }
98 } 98 }
99 99
100 switch (gestureEvent.type) { 100 switch (gestureEvent.type()) {
101 case WebInputEvent::GestureTapDown: 101 case WebInputEvent::GestureTapDown:
102 return handleGestureTapDown(targetedEvent); 102 return handleGestureTapDown(targetedEvent);
103 case WebInputEvent::GestureTap: 103 case WebInputEvent::GestureTap:
104 return handleGestureTap(targetedEvent); 104 return handleGestureTap(targetedEvent);
105 case WebInputEvent::GestureShowPress: 105 case WebInputEvent::GestureShowPress:
106 return handleGestureShowPress(); 106 return handleGestureShowPress();
107 case WebInputEvent::GestureLongPress: 107 case WebInputEvent::GestureLongPress:
108 return handleGestureLongPress(targetedEvent); 108 return handleGestureLongPress(targetedEvent);
109 case WebInputEvent::GestureLongTap: 109 case WebInputEvent::GestureLongTap:
110 return handleGestureLongTap(targetedEvent); 110 return handleGestureLongTap(targetedEvent);
(...skipping 18 matching lines...) Expand all
129 m_pointerEventManager->primaryPointerdownCanceled( 129 m_pointerEventManager->primaryPointerdownCanceled(
130 targetedEvent.event().uniqueTouchEventId); 130 targetedEvent.event().uniqueTouchEventId);
131 return WebInputEventResult::NotHandled; 131 return WebInputEventResult::NotHandled;
132 } 132 }
133 133
134 WebInputEventResult GestureManager::handleGestureTap( 134 WebInputEventResult GestureManager::handleGestureTap(
135 const GestureEventWithHitTestResults& targetedEvent) { 135 const GestureEventWithHitTestResults& targetedEvent) {
136 FrameView* frameView(m_frame->view()); 136 FrameView* frameView(m_frame->view());
137 const WebGestureEvent& gestureEvent = targetedEvent.event(); 137 const WebGestureEvent& gestureEvent = targetedEvent.event();
138 HitTestRequest::HitTestRequestType hitType = 138 HitTestRequest::HitTestRequestType hitType =
139 getHitTypeForGestureType(gestureEvent.type); 139 getHitTypeForGestureType(gestureEvent.type());
140 uint64_t preDispatchDomTreeVersion = m_frame->document()->domTreeVersion(); 140 uint64_t preDispatchDomTreeVersion = m_frame->document()->domTreeVersion();
141 uint64_t preDispatchStyleVersion = m_frame->document()->styleVersion(); 141 uint64_t preDispatchStyleVersion = m_frame->document()->styleVersion();
142 142
143 HitTestResult currentHitTest = targetedEvent.hitTestResult(); 143 HitTestResult currentHitTest = targetedEvent.hitTestResult();
144 144
145 // We use the adjusted position so the application isn't surprised to see a 145 // We use the adjusted position so the application isn't surprised to see a
146 // event with co-ordinates outside the target's bounds. 146 // event with co-ordinates outside the target's bounds.
147 IntPoint adjustedPoint = frameView->rootFrameToContents( 147 IntPoint adjustedPoint = frameView->rootFrameToContents(
148 flooredIntPoint(gestureEvent.positionInRootFrame())); 148 flooredIntPoint(gestureEvent.positionInRootFrame()));
149 149
150 const unsigned modifiers = gestureEvent.modifiers; 150 const unsigned modifiers = gestureEvent.modifiers();
151 151
152 if (!m_suppressMouseEventsFromGestures) { 152 if (!m_suppressMouseEventsFromGestures) {
153 PlatformMouseEvent fakeMouseMove( 153 PlatformMouseEvent fakeMouseMove(
154 gestureEvent, WebPointerProperties::Button::NoButton, 154 gestureEvent, WebPointerProperties::Button::NoButton,
155 PlatformEvent::MouseMoved, 155 PlatformEvent::MouseMoved,
156 /* clickCount */ 0, static_cast<PlatformEvent::Modifiers>(modifiers), 156 /* clickCount */ 0, static_cast<PlatformEvent::Modifiers>(modifiers),
157 PlatformMouseEvent::FromTouch, 157 PlatformMouseEvent::FromTouch,
158 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds), 158 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds()),
159 WebPointerProperties::PointerType::Mouse); 159 WebPointerProperties::PointerType::Mouse);
160 m_mouseEventManager->setMousePositionAndDispatchMouseEvent( 160 m_mouseEventManager->setMousePositionAndDispatchMouseEvent(
161 currentHitTest.innerNode(), EventTypeNames::mousemove, fakeMouseMove); 161 currentHitTest.innerNode(), EventTypeNames::mousemove, fakeMouseMove);
162 } 162 }
163 163
164 // Do a new hit-test in case the mousemove event changed the DOM. 164 // Do a new hit-test in case the mousemove event changed the DOM.
165 // Note that if the original hit test wasn't over an element (eg. was over a 165 // Note that if the original hit test wasn't over an element (eg. was over a
166 // scrollbar) we don't want to re-hit-test because it may be in the wrong 166 // scrollbar) we don't want to re-hit-test because it may be in the wrong
167 // frame (and there's no way the page could have seen the event anyway). Also 167 // frame (and there's no way the page could have seen the event anyway). Also
168 // note that the position of the frame may have changed, so we need to 168 // note that the position of the frame may have changed, so we need to
(...skipping 22 matching lines...) Expand all
191 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode); 191 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode);
192 192
193 m_mouseEventManager->setClickNode(tappedNonTextNode); 193 m_mouseEventManager->setClickNode(tappedNonTextNode);
194 194
195 PlatformMouseEvent fakeMouseDown( 195 PlatformMouseEvent fakeMouseDown(
196 gestureEvent, WebPointerProperties::Button::Left, 196 gestureEvent, WebPointerProperties::Button::Left,
197 PlatformEvent::MousePressed, gestureEvent.tapCount(), 197 PlatformEvent::MousePressed, gestureEvent.tapCount(),
198 static_cast<PlatformEvent::Modifiers>(modifiers | 198 static_cast<PlatformEvent::Modifiers>(modifiers |
199 PlatformEvent::LeftButtonDown), 199 PlatformEvent::LeftButtonDown),
200 PlatformMouseEvent::FromTouch, 200 PlatformMouseEvent::FromTouch,
201 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds), 201 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds()),
202 WebPointerProperties::PointerType::Mouse); 202 WebPointerProperties::PointerType::Mouse);
203 203
204 // TODO(mustaq): We suppress MEs plus all it's side effects. What would that 204 // TODO(mustaq): We suppress MEs plus all it's side effects. What would that
205 // mean for for TEs? What's the right balance here? crbug.com/617255 205 // mean for for TEs? What's the right balance here? crbug.com/617255
206 WebInputEventResult mouseDownEventResult = 206 WebInputEventResult mouseDownEventResult =
207 WebInputEventResult::HandledSuppressed; 207 WebInputEventResult::HandledSuppressed;
208 if (!m_suppressMouseEventsFromGestures) { 208 if (!m_suppressMouseEventsFromGestures) {
209 m_mouseEventManager->setClickCount(gestureEvent.tapCount()); 209 m_mouseEventManager->setClickCount(gestureEvent.tapCount());
210 210
211 mouseDownEventResult = 211 mouseDownEventResult =
212 m_mouseEventManager->setMousePositionAndDispatchMouseEvent( 212 m_mouseEventManager->setMousePositionAndDispatchMouseEvent(
213 currentHitTest.innerNode(), EventTypeNames::mousedown, 213 currentHitTest.innerNode(), EventTypeNames::mousedown,
214 fakeMouseDown); 214 fakeMouseDown);
215 m_selectionController->initializeSelectionState(); 215 m_selectionController->initializeSelectionState();
216 if (mouseDownEventResult == WebInputEventResult::NotHandled) 216 if (mouseDownEventResult == WebInputEventResult::NotHandled)
217 mouseDownEventResult = m_mouseEventManager->handleMouseFocus( 217 mouseDownEventResult = m_mouseEventManager->handleMouseFocus(
218 currentHitTest, 218 currentHitTest,
219 InputDeviceCapabilities::firesTouchEventsSourceCapabilities()); 219 InputDeviceCapabilities::firesTouchEventsSourceCapabilities());
220 if (mouseDownEventResult == WebInputEventResult::NotHandled) 220 if (mouseDownEventResult == WebInputEventResult::NotHandled)
221 mouseDownEventResult = m_mouseEventManager->handleMousePressEvent( 221 mouseDownEventResult = m_mouseEventManager->handleMousePressEvent(
222 MouseEventWithHitTestResults(fakeMouseDown, currentHitTest)); 222 MouseEventWithHitTestResults(fakeMouseDown, currentHitTest));
223 } 223 }
224 224
225 if (currentHitTest.innerNode()) { 225 if (currentHitTest.innerNode()) {
226 DCHECK(gestureEvent.type == WebInputEvent::GestureTap); 226 DCHECK(gestureEvent.type() == WebInputEvent::GestureTap);
227 HitTestResult result = currentHitTest; 227 HitTestResult result = currentHitTest;
228 result.setToShadowHostIfInUserAgentShadowRoot(); 228 result.setToShadowHostIfInUserAgentShadowRoot();
229 m_frame->chromeClient().onMouseDown(result.innerNode()); 229 m_frame->chromeClient().onMouseDown(result.innerNode());
230 } 230 }
231 231
232 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. 232 // FIXME: Use a hit-test cache to avoid unnecessary hit tests.
233 // http://crbug.com/398920 233 // http://crbug.com/398920
234 if (currentHitTest.innerNode()) { 234 if (currentHitTest.innerNode()) {
235 LocalFrame* mainFrame = m_frame->localFrameRoot(); 235 LocalFrame* mainFrame = m_frame->localFrameRoot();
236 if (mainFrame && mainFrame->view()) 236 if (mainFrame && mainFrame->view())
237 mainFrame->view()->updateAllLifecyclePhases(); 237 mainFrame->view()->updateAllLifecyclePhases();
238 adjustedPoint = frameView->rootFrameToContents(tappedPosition); 238 adjustedPoint = frameView->rootFrameToContents(tappedPosition);
239 currentHitTest = EventHandlingUtil::hitTestResultInFrame( 239 currentHitTest = EventHandlingUtil::hitTestResultInFrame(
240 m_frame, adjustedPoint, hitType); 240 m_frame, adjustedPoint, hitType);
241 } 241 }
242 242
243 PlatformMouseEvent fakeMouseUp( 243 PlatformMouseEvent fakeMouseUp(
244 gestureEvent, WebPointerProperties::Button::Left, 244 gestureEvent, WebPointerProperties::Button::Left,
245 PlatformEvent::MouseReleased, gestureEvent.tapCount(), 245 PlatformEvent::MouseReleased, gestureEvent.tapCount(),
246 static_cast<PlatformEvent::Modifiers>(modifiers), 246 static_cast<PlatformEvent::Modifiers>(modifiers),
247 PlatformMouseEvent::FromTouch, 247 PlatformMouseEvent::FromTouch,
248 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds), 248 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds()),
249 WebPointerProperties::PointerType::Mouse); 249 WebPointerProperties::PointerType::Mouse);
250 WebInputEventResult mouseUpEventResult = 250 WebInputEventResult mouseUpEventResult =
251 m_suppressMouseEventsFromGestures 251 m_suppressMouseEventsFromGestures
252 ? WebInputEventResult::HandledSuppressed 252 ? WebInputEventResult::HandledSuppressed
253 : m_mouseEventManager->setMousePositionAndDispatchMouseEvent( 253 : m_mouseEventManager->setMousePositionAndDispatchMouseEvent(
254 currentHitTest.innerNode(), EventTypeNames::mouseup, 254 currentHitTest.innerNode(), EventTypeNames::mouseup,
255 fakeMouseUp); 255 fakeMouseUp);
256 256
257 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled; 257 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled;
258 if (tappedNonTextNode) { 258 if (tappedNonTextNode) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 const GestureEventWithHitTestResults& targetedEvent) { 351 const GestureEventWithHitTestResults& targetedEvent) {
352 Node* innerNode = targetedEvent.hitTestResult().innerNode(); 352 Node* innerNode = targetedEvent.hitTestResult().innerNode();
353 if (innerNode && innerNode->layoutObject()) 353 if (innerNode && innerNode->layoutObject())
354 m_selectionController->handleGestureTwoFingerTap(targetedEvent); 354 m_selectionController->handleGestureTwoFingerTap(targetedEvent);
355 return sendContextMenuEventForGesture(targetedEvent); 355 return sendContextMenuEventForGesture(targetedEvent);
356 } 356 }
357 357
358 WebInputEventResult GestureManager::sendContextMenuEventForGesture( 358 WebInputEventResult GestureManager::sendContextMenuEventForGesture(
359 const GestureEventWithHitTestResults& targetedEvent) { 359 const GestureEventWithHitTestResults& targetedEvent) {
360 const WebGestureEvent& gestureEvent = targetedEvent.event(); 360 const WebGestureEvent& gestureEvent = targetedEvent.event();
361 unsigned modifiers = gestureEvent.modifiers; 361 unsigned modifiers = gestureEvent.modifiers();
362 362
363 if (!m_suppressMouseEventsFromGestures) { 363 if (!m_suppressMouseEventsFromGestures) {
364 // Send MouseMoved event prior to handling (https://crbug.com/485290). 364 // Send MouseMoved event prior to handling (https://crbug.com/485290).
365 PlatformMouseEvent fakeMouseMove( 365 PlatformMouseEvent fakeMouseMove(
366 gestureEvent, WebPointerProperties::Button::NoButton, 366 gestureEvent, WebPointerProperties::Button::NoButton,
367 PlatformEvent::MouseMoved, 367 PlatformEvent::MouseMoved,
368 /* clickCount */ 0, static_cast<PlatformEvent::Modifiers>(modifiers), 368 /* clickCount */ 0, static_cast<PlatformEvent::Modifiers>(modifiers),
369 PlatformMouseEvent::FromTouch, 369 PlatformMouseEvent::FromTouch,
370 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds), 370 TimeTicks::FromSeconds(gestureEvent.timeStampSeconds()),
371 WebPointerProperties::PointerType::Mouse); 371 WebPointerProperties::PointerType::Mouse);
372 m_mouseEventManager->setMousePositionAndDispatchMouseEvent( 372 m_mouseEventManager->setMousePositionAndDispatchMouseEvent(
373 targetedEvent.hitTestResult().innerNode(), EventTypeNames::mousemove, 373 targetedEvent.hitTestResult().innerNode(), EventTypeNames::mousemove,
374 fakeMouseMove); 374 fakeMouseMove);
375 } 375 }
376 376
377 PlatformEvent::EventType eventType = PlatformEvent::MousePressed; 377 PlatformEvent::EventType eventType = PlatformEvent::MousePressed;
378 if (m_frame->settings() && m_frame->settings()->getShowContextMenuOnMouseUp()) 378 if (m_frame->settings() && m_frame->settings()->getShowContextMenuOnMouseUp())
379 eventType = PlatformEvent::MouseReleased; 379 eventType = PlatformEvent::MouseReleased;
380 380
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return nullptr; 424 return nullptr;
425 425
426 return &m_frame->page()->frameHost(); 426 return &m_frame->page()->frameHost();
427 } 427 }
428 428
429 TimeTicks GestureManager::getLastShowPressTimestamp() const { 429 TimeTicks GestureManager::getLastShowPressTimestamp() const {
430 return m_lastShowPressTimestamp; 430 return m_lastShowPressTimestamp;
431 } 431 }
432 432
433 } // namespace blink 433 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698