| 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" |
| 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) |
| 25 , m_pointerEventManager(pointerEventManager) | 26 , m_pointerEventManager(pointerEventManager) |
| 26 , m_selectionController(selectionController) | 27 , m_selectionController(selectionController) |
| 27 { | 28 { |
| 28 clear(); | 29 clear(); |
| 29 } | 30 } |
| 30 | 31 |
| 31 GestureManager::~GestureManager() | |
| 32 { | |
| 33 } | |
| 34 | |
| 35 void GestureManager::clear() | 32 void GestureManager::clear() |
| 36 { | 33 { |
| 37 m_suppressMouseEventsFromGestures = false; | 34 m_suppressMouseEventsFromGestures = false; |
| 38 m_longTapShouldInvokeContextMenu = false; | 35 m_longTapShouldInvokeContextMenu = false; |
| 39 m_lastShowPressTimestamp = 0; | 36 m_lastShowPressTimestamp = 0; |
| 40 } | 37 } |
| 41 | 38 |
| 42 DEFINE_TRACE(GestureManager) | 39 DEFINE_TRACE(GestureManager) |
| 43 { | 40 { |
| 44 visitor->trace(m_frame); | 41 visitor->trace(m_frame); |
| 45 visitor->trace(m_selectionController); | 42 visitor->trace(m_selectionController); |
| 43 visitor->trace(m_pointerEventManager); |
| 44 visitor->trace(m_scrollManager); |
| 46 } | 45 } |
| 47 | 46 |
| 48 HitTestRequest::HitTestRequestType GestureManager::getHitTypeForGestureType(Plat
formEvent::EventType type) | 47 HitTestRequest::HitTestRequestType GestureManager::getHitTypeForGestureType(Plat
formEvent::EventType type) |
| 49 { | 48 { |
| 50 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEvent; | 49 HitTestRequest::HitTestRequestType hitType = HitTestRequest::TouchEvent; |
| 51 switch (type) { | 50 switch (type) { |
| 52 case PlatformEvent::GestureShowPress: | 51 case PlatformEvent::GestureShowPress: |
| 53 case PlatformEvent::GestureTapUnconfirmed: | 52 case PlatformEvent::GestureTapUnconfirmed: |
| 54 return hitType | HitTestRequest::Active; | 53 return hitType | HitTestRequest::Active; |
| 55 case PlatformEvent::GestureTapDownCancel: | 54 case PlatformEvent::GestureTapDownCancel: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 80 | 79 |
| 81 if (m_scrollManager->canHandleGestureEvent(targetedEvent)) | 80 if (m_scrollManager->canHandleGestureEvent(targetedEvent)) |
| 82 return WebInputEventResult::HandledSuppressed; | 81 return WebInputEventResult::HandledSuppressed; |
| 83 | 82 |
| 84 if (eventTarget) { | 83 if (eventTarget) { |
| 85 GestureEvent* gestureDomEvent = GestureEvent::create(eventTarget->docume
nt().domWindow(), gestureEvent); | 84 GestureEvent* gestureDomEvent = GestureEvent::create(eventTarget->docume
nt().domWindow(), gestureEvent); |
| 86 if (gestureDomEvent) { | 85 if (gestureDomEvent) { |
| 87 DispatchEventResult gestureDomEventResult = eventTarget->dispatchEve
nt(gestureDomEvent); | 86 DispatchEventResult gestureDomEventResult = eventTarget->dispatchEve
nt(gestureDomEvent); |
| 88 if (gestureDomEventResult != DispatchEventResult::NotCanceled) { | 87 if (gestureDomEventResult != DispatchEventResult::NotCanceled) { |
| 89 DCHECK(gestureDomEventResult != DispatchEventResult::CanceledByE
ventHandler); | 88 DCHECK(gestureDomEventResult != DispatchEventResult::CanceledByE
ventHandler); |
| 90 return EventHandler::toWebInputEventResult(gestureDomEventResult
); | 89 return EventHandlingUtil::toWebInputEventResult(gestureDomEventR
esult); |
| 91 } | 90 } |
| 92 } | 91 } |
| 93 } | 92 } |
| 94 | 93 |
| 95 switch (gestureEvent.type()) { | 94 switch (gestureEvent.type()) { |
| 96 case PlatformEvent::GestureTapDown: | 95 case PlatformEvent::GestureTapDown: |
| 97 return handleGestureTapDown(targetedEvent); | 96 return handleGestureTapDown(targetedEvent); |
| 98 case PlatformEvent::GestureTap: | 97 case PlatformEvent::GestureTap: |
| 99 return handleGestureTap(targetedEvent); | 98 return handleGestureTap(targetedEvent); |
| 100 case PlatformEvent::GestureShowPress: | 99 case PlatformEvent::GestureShowPress: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // don't want to re-hit-test because it may be in the wrong frame (and there
's no way the page | 154 // 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). | 155 // 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 | 156 // 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). | 157 // 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 | 158 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug.
com/398920 |
| 160 if (currentHitTest.innerNode()) { | 159 if (currentHitTest.innerNode()) { |
| 161 LocalFrame* mainFrame = m_frame->localFrameRoot(); | 160 LocalFrame* mainFrame = m_frame->localFrameRoot(); |
| 162 if (mainFrame && mainFrame->view()) | 161 if (mainFrame && mainFrame->view()) |
| 163 mainFrame->view()->updateLifecycleToCompositingCleanPlusScrolling(); | 162 mainFrame->view()->updateLifecycleToCompositingCleanPlusScrolling(); |
| 164 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); | 163 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); |
| 165 currentHitTest = EventHandler::hitTestResultInFrame(m_frame, adjustedPoi
nt, hitType); | 164 currentHitTest = EventHandlingUtil::hitTestResultInFrame(m_frame, adjust
edPoint, hitType); |
| 166 } | 165 } |
| 167 | 166 |
| 168 // Capture data for showUnhandledTapUIIfNeeded. | 167 // Capture data for showUnhandledTapUIIfNeeded. |
| 169 Node* tappedNode = currentHitTest.innerNode(); | 168 Node* tappedNode = currentHitTest.innerNode(); |
| 170 IntPoint tappedPosition = gestureEvent.position(); | 169 IntPoint tappedPosition = gestureEvent.position(); |
| 171 Node* tappedNonTextNode = tappedNode; | 170 Node* tappedNonTextNode = tappedNode; |
| 172 | 171 |
| 173 if (tappedNonTextNode && tappedNonTextNode->isTextNode()) | 172 if (tappedNonTextNode && tappedNonTextNode->isTextNode()) |
| 174 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode); | 173 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode); |
| 175 | 174 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 198 result.setToShadowHostIfInUserAgentShadowRoot(); | 197 result.setToShadowHostIfInUserAgentShadowRoot(); |
| 199 m_frame->chromeClient().onMouseDown(result.innerNode()); | 198 m_frame->chromeClient().onMouseDown(result.innerNode()); |
| 200 } | 199 } |
| 201 | 200 |
| 202 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug.
com/398920 | 201 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug.
com/398920 |
| 203 if (currentHitTest.innerNode()) { | 202 if (currentHitTest.innerNode()) { |
| 204 LocalFrame* mainFrame = m_frame->localFrameRoot(); | 203 LocalFrame* mainFrame = m_frame->localFrameRoot(); |
| 205 if (mainFrame && mainFrame->view()) | 204 if (mainFrame && mainFrame->view()) |
| 206 mainFrame->view()->updateAllLifecyclePhases(); | 205 mainFrame->view()->updateAllLifecyclePhases(); |
| 207 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); | 206 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); |
| 208 currentHitTest = EventHandler::hitTestResultInFrame(m_frame, adjustedPoi
nt, hitType); | 207 currentHitTest = EventHandlingUtil::hitTestResultInFrame(m_frame, adjust
edPoint, hitType); |
| 209 } | 208 } |
| 210 | 209 |
| 211 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP
osition(), | 210 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP
osition(), |
| 212 WebPointerProperties::Button::Left, PlatformEvent::MouseReleased, gestur
eEvent.tapCount(), | 211 WebPointerProperties::Button::Left, PlatformEvent::MouseReleased, gestur
eEvent.tapCount(), |
| 213 static_cast<PlatformEvent::Modifiers>(modifiers), | 212 static_cast<PlatformEvent::Modifiers>(modifiers), |
| 214 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope
rties::PointerType::Mouse); | 213 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope
rties::PointerType::Mouse); |
| 215 WebInputEventResult mouseUpEventResult = m_suppressMouseEventsFromGestures | 214 WebInputEventResult mouseUpEventResult = m_suppressMouseEventsFromGestures |
| 216 ? WebInputEventResult::HandledSuppressed | 215 ? WebInputEventResult::HandledSuppressed |
| 217 : m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mouseup, cu
rrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp); | 216 : m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mouseup, cu
rrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp); |
| 218 | 217 |
| 219 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled; | 218 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled; |
| 220 if (tappedNonTextNode) { | 219 if (tappedNonTextNode) { |
| 221 if (currentHitTest.innerNode()) { | 220 if (currentHitTest.innerNode()) { |
| 222 // Updates distribution because a mouseup (or mousedown) event liste
ner can make the | 221 // Updates distribution because a mouseup (or mousedown) event liste
ner can make the |
| 223 // tree dirty at dispatchMouseEvent() invocation above. | 222 // tree dirty at dispatchMouseEvent() invocation above. |
| 224 // Unless distribution is updated, commonAncestor would hit DCHECK. | 223 // Unless distribution is updated, commonAncestor would hit DCHECK. |
| 225 // Both tappedNonTextNode and currentHitTest.innerNode()) don't need
to be updated | 224 // Both tappedNonTextNode and currentHitTest.innerNode()) don't need
to be updated |
| 226 // because commonAncestor() will exit early if their documents are d
ifferent. | 225 // because commonAncestor() will exit early if their documents are d
ifferent. |
| 227 tappedNonTextNode->updateDistribution(); | 226 tappedNonTextNode->updateDistribution(); |
| 228 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(*
tappedNonTextNode, EventHandler::parentForClickEvent); | 227 Node* clickTargetNode = currentHitTest.innerNode()->commonAncestor(*
tappedNonTextNode, EventHandler::parentForClickEvent); |
| 229 clickEventResult = m_frame->eventHandler().dispatchMouseEvent(EventT
ypeNames::click, clickTargetNode, gestureEvent.tapCount(), fakeMouseUp); | 228 clickEventResult = m_frame->eventHandler().dispatchMouseEvent(EventT
ypeNames::click, clickTargetNode, gestureEvent.tapCount(), fakeMouseUp); |
| 230 } | 229 } |
| 231 m_frame->eventHandler().setClickNode(nullptr); | 230 m_frame->eventHandler().setClickNode(nullptr); |
| 232 } | 231 } |
| 233 | 232 |
| 234 if (mouseUpEventResult == WebInputEventResult::NotHandled) | 233 if (mouseUpEventResult == WebInputEventResult::NotHandled) |
| 235 mouseUpEventResult = m_frame->eventHandler().handleMouseReleaseEvent(Mou
seEventWithHitTestResults(fakeMouseUp, currentHitTest)); | 234 mouseUpEventResult = m_frame->eventHandler().handleMouseReleaseEvent(Mou
seEventWithHitTestResults(fakeMouseUp, currentHitTest)); |
| 236 m_frame->eventHandler().clearDragHeuristicState(); | 235 m_frame->eventHandler().clearDragHeuristicState(); |
| 237 | 236 |
| 238 WebInputEventResult eventResult = EventHandler::mergeEventResult(EventHandle
r::mergeEventResult(mouseDownEventResult, mouseUpEventResult), clickEventResult)
; | 237 WebInputEventResult eventResult = EventHandlingUtil::mergeEventResult(EventH
andlingUtil::mergeEventResult(mouseDownEventResult, mouseUpEventResult), clickEv
entResult); |
| 239 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame-
>page()) { | 238 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame-
>page()) { |
| 240 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()->
domTreeVersion(); | 239 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()->
domTreeVersion(); |
| 241 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl
eVersion(); | 240 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl
eVersion(); |
| 242 | 241 |
| 243 IntPoint tappedPositionInViewport = frameHost()->visualViewport().rootFr
ameToViewport(tappedPosition); | 242 IntPoint tappedPositionInViewport = frameHost()->visualViewport().rootFr
ameToViewport(tappedPosition); |
| 244 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp
ort, tappedNode, domTreeChanged || styleChanged); | 243 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp
ort, tappedNode, domTreeChanged || styleChanged); |
| 245 } | 244 } |
| 246 return eventResult; | 245 return eventResult; |
| 247 } | 246 } |
| 248 | 247 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 355 |
| 357 return &m_frame->page()->frameHost(); | 356 return &m_frame->page()->frameHost(); |
| 358 } | 357 } |
| 359 | 358 |
| 360 double GestureManager::getLastShowPressTimestamp() const | 359 double GestureManager::getLastShowPressTimestamp() const |
| 361 { | 360 { |
| 362 return m_lastShowPressTimestamp; | 361 return m_lastShowPressTimestamp; |
| 363 } | 362 } |
| 364 | 363 |
| 365 } // namespace blink | 364 } // namespace blink |
| OLD | NEW |