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

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

Issue 2255323004: Create MouseEventManager and EventHandlingUtil (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make all *Manager classes GarbageCollected Created 4 years, 3 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/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"
11 #include "core/frame/FrameView.h" 11 #include "core/frame/FrameView.h"
12 #include "core/frame/Settings.h" 12 #include "core/frame/Settings.h"
13 #include "core/frame/VisualViewport.h" 13 #include "core/frame/VisualViewport.h"
14 #include "core/input/EventHandler.h" 14 #include "core/input/EventHandler.h"
15 #include "core/input/EventHandlingUtil.h"
15 #include "core/page/ChromeClient.h" 16 #include "core/page/ChromeClient.h"
16 #include "core/page/Page.h" 17 #include "core/page/Page.h"
17 18
18 namespace blink { 19 namespace blink {
19 20
20 GestureManager::GestureManager(LocalFrame* frame, ScrollManager* scrollManager, 21 GestureManager::GestureManager(LocalFrame* frame, ScrollManager* scrollManager,
21 PointerEventManager* pointerEventManager, 22 PointerEventManager* pointerEventManager,
22 SelectionController* selectionController) 23 SelectionController* selectionController)
23 : m_frame(frame) 24 : m_frame(frame)
24 , m_scrollManager(scrollManager) 25 , m_scrollManager(scrollManager)
(...skipping 11 matching lines...) Expand all
36 { 37 {
37 m_suppressMouseEventsFromGestures = false; 38 m_suppressMouseEventsFromGestures = false;
38 m_longTapShouldInvokeContextMenu = false; 39 m_longTapShouldInvokeContextMenu = false;
39 m_lastShowPressTimestamp = 0; 40 m_lastShowPressTimestamp = 0;
40 } 41 }
41 42
42 DEFINE_TRACE(GestureManager) 43 DEFINE_TRACE(GestureManager)
43 { 44 {
44 visitor->trace(m_frame); 45 visitor->trace(m_frame);
45 visitor->trace(m_selectionController); 46 visitor->trace(m_selectionController);
47 visitor->trace(m_pointerEventManager);
48 visitor->trace(m_scrollManager);
46 } 49 }
47 50
48 HitTestRequest::HitTestRequestType GestureManager::getHitTypeForGestureType(Plat formEvent::EventType type) 51 HitTestRequest::HitTestRequestType GestureManager::getHitTypeForGestureType(Plat formEvent::EventType type)
49 { 52 {
50 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEvent; 53 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEvent;
51 switch (type) { 54 switch (type) {
52 case PlatformEvent::GestureShowPress: 55 case PlatformEvent::GestureShowPress:
53 case PlatformEvent::GestureTapUnconfirmed: 56 case PlatformEvent::GestureTapUnconfirmed:
54 return hitType | HitTestRequest::Active; 57 return hitType | HitTestRequest::Active;
55 case PlatformEvent::GestureTapDownCancel: 58 case PlatformEvent::GestureTapDownCancel:
(...skipping 24 matching lines...) Expand all
80 83
81 if (m_scrollManager->canHandleGestureEvent(targetedEvent)) 84 if (m_scrollManager->canHandleGestureEvent(targetedEvent))
82 return WebInputEventResult::HandledSuppressed; 85 return WebInputEventResult::HandledSuppressed;
83 86
84 if (eventTarget) { 87 if (eventTarget) {
85 GestureEvent* gestureDomEvent = GestureEvent::create(eventTarget->docume nt().domWindow(), gestureEvent); 88 GestureEvent* gestureDomEvent = GestureEvent::create(eventTarget->docume nt().domWindow(), gestureEvent);
86 if (gestureDomEvent) { 89 if (gestureDomEvent) {
87 DispatchEventResult gestureDomEventResult = eventTarget->dispatchEve nt(gestureDomEvent); 90 DispatchEventResult gestureDomEventResult = eventTarget->dispatchEve nt(gestureDomEvent);
88 if (gestureDomEventResult != DispatchEventResult::NotCanceled) { 91 if (gestureDomEventResult != DispatchEventResult::NotCanceled) {
89 DCHECK(gestureDomEventResult != DispatchEventResult::CanceledByE ventHandler); 92 DCHECK(gestureDomEventResult != DispatchEventResult::CanceledByE ventHandler);
90 return EventHandler::toWebInputEventResult(gestureDomEventResult ); 93 return EventHandlingUtil::toWebInputEventResult(gestureDomEventR esult);
91 } 94 }
92 } 95 }
93 } 96 }
94 97
95 switch (gestureEvent.type()) { 98 switch (gestureEvent.type()) {
96 case PlatformEvent::GestureTapDown: 99 case PlatformEvent::GestureTapDown:
97 return handleGestureTapDown(targetedEvent); 100 return handleGestureTapDown(targetedEvent);
98 case PlatformEvent::GestureTap: 101 case PlatformEvent::GestureTap:
99 return handleGestureTap(targetedEvent); 102 return handleGestureTap(targetedEvent);
100 case PlatformEvent::GestureShowPress: 103 case PlatformEvent::GestureShowPress:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // don't want to re-hit-test because it may be in the wrong frame (and there 's no way the page 158 // don't want to re-hit-test because it may be in the wrong frame (and there 's no way the page
156 // could have seen the event anyway). 159 // could have seen the event anyway).
157 // Also note that the position of the frame may have changed, so we need to recompute the content 160 // Also note that the position of the frame may have changed, so we need to recompute the content
158 // co-ordinates (updating layout/style as hitTestResultAtPoint normally woul d). 161 // co-ordinates (updating layout/style as hitTestResultAtPoint normally woul d).
159 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 162 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
160 if (currentHitTest.innerNode()) { 163 if (currentHitTest.innerNode()) {
161 LocalFrame* mainFrame = m_frame->localFrameRoot(); 164 LocalFrame* mainFrame = m_frame->localFrameRoot();
162 if (mainFrame && mainFrame->view()) 165 if (mainFrame && mainFrame->view())
163 mainFrame->view()->updateLifecycleToCompositingCleanPlusScrolling(); 166 mainFrame->view()->updateLifecycleToCompositingCleanPlusScrolling();
164 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); 167 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position());
165 currentHitTest = EventHandler::hitTestResultInFrame(m_frame, adjustedPoi nt, hitType); 168 currentHitTest = EventHandlingUtil::hitTestResultInFrame(m_frame, adjust edPoint, hitType);
166 } 169 }
167 170
168 // Capture data for showUnhandledTapUIIfNeeded. 171 // Capture data for showUnhandledTapUIIfNeeded.
169 Node* tappedNode = currentHitTest.innerNode(); 172 Node* tappedNode = currentHitTest.innerNode();
170 IntPoint tappedPosition = gestureEvent.position(); 173 IntPoint tappedPosition = gestureEvent.position();
171 Node* tappedNonTextNode = tappedNode; 174 Node* tappedNonTextNode = tappedNode;
172 175
173 if (tappedNonTextNode && tappedNonTextNode->isTextNode()) 176 if (tappedNonTextNode && tappedNonTextNode->isTextNode())
174 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode); 177 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode);
175 178
(...skipping 22 matching lines...) Expand all
198 result.setToShadowHostIfInUserAgentShadowRoot(); 201 result.setToShadowHostIfInUserAgentShadowRoot();
199 m_frame->chromeClient().onMouseDown(result.innerNode()); 202 m_frame->chromeClient().onMouseDown(result.innerNode());
200 } 203 }
201 204
202 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920 205 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug. com/398920
203 if (currentHitTest.innerNode()) { 206 if (currentHitTest.innerNode()) {
204 LocalFrame* mainFrame = m_frame->localFrameRoot(); 207 LocalFrame* mainFrame = m_frame->localFrameRoot();
205 if (mainFrame && mainFrame->view()) 208 if (mainFrame && mainFrame->view())
206 mainFrame->view()->updateAllLifecyclePhases(); 209 mainFrame->view()->updateAllLifecyclePhases();
207 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); 210 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position());
208 currentHitTest = EventHandler::hitTestResultInFrame(m_frame, adjustedPoi nt, hitType); 211 currentHitTest = EventHandlingUtil::hitTestResultInFrame(m_frame, adjust edPoint, hitType);
209 } 212 }
210 213
211 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(), 214 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP osition(),
212 WebPointerProperties::Button::Left, PlatformEvent::MouseReleased, gestur eEvent.tapCount(), 215 WebPointerProperties::Button::Left, PlatformEvent::MouseReleased, gestur eEvent.tapCount(),
213 static_cast<PlatformEvent::Modifiers>(modifiers), 216 static_cast<PlatformEvent::Modifiers>(modifiers),
214 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope rties::PointerType::Mouse); 217 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope rties::PointerType::Mouse);
215 WebInputEventResult mouseUpEventResult = m_suppressMouseEventsFromGestures 218 WebInputEventResult mouseUpEventResult = m_suppressMouseEventsFromGestures
216 ? WebInputEventResult::HandledSuppressed 219 ? WebInputEventResult::HandledSuppressed
217 : m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mouseup, cu rrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp); 220 : m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mouseup, cu rrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp);
218 221
219 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled; 222 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled;
220 if (tappedNonTextNode) { 223 if (tappedNonTextNode) {
221 if (currentHitTest.innerNode()) { 224 if (currentHitTest.innerNode()) {
222 // Updates distribution because a mouseup (or mousedown) event liste ner can make the 225 // Updates distribution because a mouseup (or mousedown) event liste ner can make the
223 // tree dirty at dispatchMouseEvent() invocation above. 226 // tree dirty at dispatchMouseEvent() invocation above.
224 // Unless distribution is updated, commonAncestor would hit DCHECK. 227 // Unless distribution is updated, commonAncestor would hit DCHECK.
225 // Both tappedNonTextNode and currentHitTest.innerNode()) don't need to be updated 228 // Both tappedNonTextNode and currentHitTest.innerNode()) don't need to be updated
226 // because commonAncestor() will exit early if their documents are d ifferent. 229 // because commonAncestor() will exit early if their documents are d ifferent.
227 tappedNonTextNode->updateDistribution(); 230 tappedNonTextNode->updateDistribution();
228 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* tappedNonTextNode, EventHandler::parentForClickEvent); 231 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(* tappedNonTextNode, EventHandler::parentForClickEvent);
229 clickEventResult = m_frame->eventHandler().dispatchMouseEvent(EventT ypeNames::click, clickTargetNode, gestureEvent.tapCount(), fakeMouseUp); 232 clickEventResult = m_frame->eventHandler().dispatchMouseEvent(EventT ypeNames::click, clickTargetNode, gestureEvent.tapCount(), fakeMouseUp);
230 } 233 }
231 m_frame->eventHandler().setClickNode(nullptr); 234 m_frame->eventHandler().setClickNode(nullptr);
232 } 235 }
233 236
234 if (mouseUpEventResult == WebInputEventResult::NotHandled) 237 if (mouseUpEventResult == WebInputEventResult::NotHandled)
235 mouseUpEventResult = m_frame->eventHandler().handleMouseReleaseEvent(Mou seEventWithHitTestResults(fakeMouseUp, currentHitTest)); 238 mouseUpEventResult = m_frame->eventHandler().handleMouseReleaseEvent(Mou seEventWithHitTestResults(fakeMouseUp, currentHitTest));
236 m_frame->eventHandler().clearDragHeuristicState(); 239 m_frame->eventHandler().clearDragHeuristicState();
237 240
238 WebInputEventResult eventResult = EventHandler::mergeEventResult(EventHandle r::mergeEventResult(mouseDownEventResult, mouseUpEventResult), clickEventResult) ; 241 WebInputEventResult eventResult = EventHandlingUtil::mergeEventResult(EventH andlingUtil::mergeEventResult(mouseDownEventResult, mouseUpEventResult), clickEv entResult);
239 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame- >page()) { 242 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame- >page()) {
240 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion(); 243 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion();
241 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion(); 244 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion();
242 245
243 IntPoint tappedPositionInViewport = frameHost()->visualViewport().rootFr ameToViewport(tappedPosition); 246 IntPoint tappedPositionInViewport = frameHost()->visualViewport().rootFr ameToViewport(tappedPosition);
244 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode, domTreeChanged || styleChanged); 247 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode, domTreeChanged || styleChanged);
245 } 248 }
246 return eventResult; 249 return eventResult;
247 } 250 }
248 251
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 355
353 return &m_frame->page()->frameHost(); 356 return &m_frame->page()->frameHost();
354 } 357 }
355 358
356 double GestureManager::getLastShowPressTimestamp() const 359 double GestureManager::getLastShowPressTimestamp() const
357 { 360 {
358 return m_lastShowPressTimestamp; 361 return m_lastShowPressTimestamp;
359 } 362 }
360 363
361 } // namespace blink 364 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698