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