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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 HitTestResult currentHitTest = targetedEvent.hitTestResult(); | 137 HitTestResult currentHitTest = targetedEvent.hitTestResult(); |
138 | 138 |
139 // We use the adjusted position so the application isn't surprised to see a
event with | 139 // We use the adjusted position so the application isn't surprised to see a
event with |
140 // co-ordinates outside the target's bounds. | 140 // co-ordinates outside the target's bounds. |
141 IntPoint adjustedPoint = frameView->rootFrameToContents(gestureEvent.positio
n()); | 141 IntPoint adjustedPoint = frameView->rootFrameToContents(gestureEvent.positio
n()); |
142 | 142 |
143 const unsigned modifiers = gestureEvent.getModifiers(); | 143 const unsigned modifiers = gestureEvent.getModifiers(); |
144 | 144 |
145 if (!m_suppressMouseEventsFromGestures) { | 145 if (!m_suppressMouseEventsFromGestures) { |
146 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.g
lobalPosition(), | 146 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.g
lobalPosition(), |
147 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0, | 147 WebPointerProperties::Button::NoButton, PlatformEvent::MouseMoved, /
* clickCount */ 0, |
148 static_cast<PlatformEvent::Modifiers>(modifiers), | 148 static_cast<PlatformEvent::Modifiers>(modifiers), |
149 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerP
roperties::PointerType::Mouse); | 149 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerP
roperties::PointerType::Mouse); |
150 m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mousemove, cu
rrentHitTest.innerNode(), 0, fakeMouseMove); | 150 m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mousemove, cu
rrentHitTest.innerNode(), 0, fakeMouseMove); |
151 } | 151 } |
152 | 152 |
153 // Do a new hit-test in case the mousemove event changed the DOM. | 153 // Do a new hit-test in case the mousemove event changed the DOM. |
154 // Note that if the original hit test wasn't over an element (eg. was over a
scrollbar) we | 154 // Note that if the original hit test wasn't over an element (eg. was over a
scrollbar) we |
155 // don't want to re-hit-test because it may be in the wrong frame (and there
's no way the page | 155 // 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). | 156 // 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 | 157 // Also note that the position of the frame may have changed, so we need to
recompute the content |
(...skipping 11 matching lines...) Expand all Loading... |
169 Node* tappedNode = currentHitTest.innerNode(); | 169 Node* tappedNode = currentHitTest.innerNode(); |
170 IntPoint tappedPosition = gestureEvent.position(); | 170 IntPoint tappedPosition = gestureEvent.position(); |
171 Node* tappedNonTextNode = tappedNode; | 171 Node* tappedNonTextNode = tappedNode; |
172 | 172 |
173 if (tappedNonTextNode && tappedNonTextNode->isTextNode()) | 173 if (tappedNonTextNode && tappedNonTextNode->isTextNode()) |
174 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode); | 174 tappedNonTextNode = FlatTreeTraversal::parent(*tappedNonTextNode); |
175 | 175 |
176 m_frame->eventHandler().setClickNode(tappedNonTextNode); | 176 m_frame->eventHandler().setClickNode(tappedNonTextNode); |
177 | 177 |
178 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa
lPosition(), | 178 PlatformMouseEvent fakeMouseDown(gestureEvent.position(), gestureEvent.globa
lPosition(), |
179 LeftButton, PlatformEvent::MousePressed, gestureEvent.tapCount(), | 179 WebPointerProperties::Button::Left, PlatformEvent::MousePressed, gesture
Event.tapCount(), |
180 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::LeftBut
tonDown), | 180 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::LeftBut
tonDown), |
181 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope
rties::PointerType::Mouse); | 181 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope
rties::PointerType::Mouse); |
182 | 182 |
183 // TODO(mustaq): We suppress MEs plus all it's side effects. What would that | 183 // TODO(mustaq): We suppress MEs plus all it's side effects. What would that |
184 // mean for for TEs? What's the right balance here? crbug.com/617255 | 184 // mean for for TEs? What's the right balance here? crbug.com/617255 |
185 WebInputEventResult mouseDownEventResult = WebInputEventResult::HandledSuppr
essed; | 185 WebInputEventResult mouseDownEventResult = WebInputEventResult::HandledSuppr
essed; |
186 if (!m_suppressMouseEventsFromGestures) { | 186 if (!m_suppressMouseEventsFromGestures) { |
187 mouseDownEventResult = m_frame->eventHandler().dispatchMouseEvent(EventT
ypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMo
useDown); | 187 mouseDownEventResult = m_frame->eventHandler().dispatchMouseEvent(EventT
ypeNames::mousedown, currentHitTest.innerNode(), gestureEvent.tapCount(), fakeMo
useDown); |
188 m_selectionController->initializeSelectionState(); | 188 m_selectionController->initializeSelectionState(); |
189 if (mouseDownEventResult == WebInputEventResult::NotHandled) | 189 if (mouseDownEventResult == WebInputEventResult::NotHandled) |
(...skipping 12 matching lines...) Expand all Loading... |
202 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug.
com/398920 | 202 // FIXME: Use a hit-test cache to avoid unnecessary hit tests. http://crbug.
com/398920 |
203 if (currentHitTest.innerNode()) { | 203 if (currentHitTest.innerNode()) { |
204 LocalFrame* mainFrame = m_frame->localFrameRoot(); | 204 LocalFrame* mainFrame = m_frame->localFrameRoot(); |
205 if (mainFrame && mainFrame->view()) | 205 if (mainFrame && mainFrame->view()) |
206 mainFrame->view()->updateAllLifecyclePhases(); | 206 mainFrame->view()->updateAllLifecyclePhases(); |
207 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); | 207 adjustedPoint = frameView->rootFrameToContents(gestureEvent.position()); |
208 currentHitTest = EventHandler::hitTestResultInFrame(m_frame, adjustedPoi
nt, hitType); | 208 currentHitTest = EventHandler::hitTestResultInFrame(m_frame, adjustedPoi
nt, hitType); |
209 } | 209 } |
210 | 210 |
211 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP
osition(), | 211 PlatformMouseEvent fakeMouseUp(gestureEvent.position(), gestureEvent.globalP
osition(), |
212 LeftButton, PlatformEvent::MouseReleased, gestureEvent.tapCount(), | 212 WebPointerProperties::Button::Left, PlatformEvent::MouseReleased, gestur
eEvent.tapCount(), |
213 static_cast<PlatformEvent::Modifiers>(modifiers), | 213 static_cast<PlatformEvent::Modifiers>(modifiers), |
214 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope
rties::PointerType::Mouse); | 214 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerPrope
rties::PointerType::Mouse); |
215 WebInputEventResult mouseUpEventResult = m_suppressMouseEventsFromGestures | 215 WebInputEventResult mouseUpEventResult = m_suppressMouseEventsFromGestures |
216 ? WebInputEventResult::HandledSuppressed | 216 ? WebInputEventResult::HandledSuppressed |
217 : m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mouseup, cu
rrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp); | 217 : m_frame->eventHandler().dispatchMouseEvent(EventTypeNames::mouseup, cu
rrentHitTest.innerNode(), gestureEvent.tapCount(), fakeMouseUp); |
218 | 218 |
219 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled; | 219 WebInputEventResult clickEventResult = WebInputEventResult::NotHandled; |
220 if (tappedNonTextNode) { | 220 if (tappedNonTextNode) { |
221 if (currentHitTest.innerNode()) { | 221 if (currentHitTest.innerNode()) { |
222 // Updates distribution because a mouseup (or mousedown) event liste
ner can make the | 222 // Updates distribution because a mouseup (or mousedown) event liste
ner can make the |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 286 } |
287 | 287 |
288 WebInputEventResult GestureManager::sendContextMenuEventForGesture(const Gesture
EventWithHitTestResults& targetedEvent) | 288 WebInputEventResult GestureManager::sendContextMenuEventForGesture(const Gesture
EventWithHitTestResults& targetedEvent) |
289 { | 289 { |
290 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); | 290 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); |
291 unsigned modifiers = gestureEvent.getModifiers(); | 291 unsigned modifiers = gestureEvent.getModifiers(); |
292 | 292 |
293 if (!m_suppressMouseEventsFromGestures) { | 293 if (!m_suppressMouseEventsFromGestures) { |
294 // Send MouseMoved event prior to handling (https://crbug.com/485290). | 294 // Send MouseMoved event prior to handling (https://crbug.com/485290). |
295 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.g
lobalPosition(), | 295 PlatformMouseEvent fakeMouseMove(gestureEvent.position(), gestureEvent.g
lobalPosition(), |
296 NoButton, PlatformEvent::MouseMoved, /* clickCount */ 0, | 296 WebPointerProperties::Button::NoButton, PlatformEvent::MouseMoved, /
* clickCount */ 0, |
297 static_cast<PlatformEvent::Modifiers>(modifiers), | 297 static_cast<PlatformEvent::Modifiers>(modifiers), |
298 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerP
roperties::PointerType::Mouse); | 298 PlatformMouseEvent::FromTouch, gestureEvent.timestamp(), WebPointerP
roperties::PointerType::Mouse); |
299 m_frame->eventHandler().dispatchMouseEvent( | 299 m_frame->eventHandler().dispatchMouseEvent( |
300 EventTypeNames::mousemove, targetedEvent.hitTestResult().innerNode()
, 0, fakeMouseMove); | 300 EventTypeNames::mousemove, targetedEvent.hitTestResult().innerNode()
, 0, fakeMouseMove); |
301 } | 301 } |
302 | 302 |
303 PlatformEvent::EventType eventType = PlatformEvent::MousePressed; | 303 PlatformEvent::EventType eventType = PlatformEvent::MousePressed; |
304 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp()) | 304 if (m_frame->settings() && m_frame->settings()->showContextMenuOnMouseUp()) |
305 eventType = PlatformEvent::MouseReleased; | 305 eventType = PlatformEvent::MouseReleased; |
306 | 306 |
307 // To simulate right-click behavior, we send a right mouse down and then con
text menu event. | 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 | 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, | 309 PlatformMouseEvent mouseEvent(targetedEvent.event().position(), targetedEven
t.event().globalPosition(), WebPointerProperties::Button::Right, eventType, 1, |
310 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::RightBu
ttonDown), | 310 static_cast<PlatformEvent::Modifiers>(modifiers | PlatformEvent::RightBu
ttonDown), |
311 PlatformMouseEvent::FromTouch, WTF::monotonicallyIncreasingTime(), WebPo
interProperties::PointerType::Mouse); | 311 PlatformMouseEvent::FromTouch, WTF::monotonicallyIncreasingTime(), WebPo
interProperties::PointerType::Mouse); |
312 if (!m_suppressMouseEventsFromGestures) { | 312 if (!m_suppressMouseEventsFromGestures) { |
313 // FIXME: Send HitTestResults to avoid redundant hit tests. | 313 // FIXME: Send HitTestResults to avoid redundant hit tests. |
314 m_frame->eventHandler().handleMousePressEvent(mouseEvent); | 314 m_frame->eventHandler().handleMousePressEvent(mouseEvent); |
315 } | 315 } |
316 | 316 |
317 return m_frame->eventHandler().sendContextMenuEvent(mouseEvent); | 317 return m_frame->eventHandler().sendContextMenuEvent(mouseEvent); |
318 // We do not need to send a corresponding mouse release because in case of | 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. | 319 // right-click, the context menu takes capture and consumes all events. |
(...skipping 26 matching lines...) Expand all Loading... |
346 | 346 |
347 return &m_frame->page()->frameHost(); | 347 return &m_frame->page()->frameHost(); |
348 } | 348 } |
349 | 349 |
350 double GestureManager::getLastShowPressTimestamp() const | 350 double GestureManager::getLastShowPressTimestamp() const |
351 { | 351 { |
352 return m_lastShowPressTimestamp; | 352 return m_lastShowPressTimestamp; |
353 } | 353 } |
354 | 354 |
355 } // namespace blink | 355 } // namespace blink |
OLD | NEW |