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/MouseEventManager.h" | 5 #include "core/input/MouseEventManager.h" |
6 | 6 |
7 #include "core/clipboard/DataObject.h" | 7 #include "core/clipboard/DataObject.h" |
8 #include "core/clipboard/DataTransfer.h" | 8 #include "core/clipboard/DataTransfer.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
10 #include "core/dom/ElementTraversal.h" | 10 #include "core/dom/ElementTraversal.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 node_under_mouse_ = nullptr; | 87 node_under_mouse_ = nullptr; |
88 mouse_press_node_ = nullptr; | 88 mouse_press_node_ = nullptr; |
89 mouse_down_may_start_autoscroll_ = false; | 89 mouse_down_may_start_autoscroll_ = false; |
90 mouse_down_may_start_drag_ = false; | 90 mouse_down_may_start_drag_ = false; |
91 captures_dragging_ = false; | 91 captures_dragging_ = false; |
92 is_mouse_position_unknown_ = true; | 92 is_mouse_position_unknown_ = true; |
93 last_known_mouse_position_ = IntPoint(); | 93 last_known_mouse_position_ = IntPoint(); |
94 last_known_mouse_global_position_ = IntPoint(); | 94 last_known_mouse_global_position_ = IntPoint(); |
95 mouse_pressed_ = false; | 95 mouse_pressed_ = false; |
96 click_count_ = 0; | 96 click_count_ = 0; |
97 click_node_ = nullptr; | 97 click_element_ = nullptr; |
98 mouse_down_pos_ = IntPoint(); | 98 mouse_down_pos_ = IntPoint(); |
99 mouse_down_timestamp_ = TimeTicks(); | 99 mouse_down_timestamp_ = TimeTicks(); |
100 mouse_down_ = WebMouseEvent(); | 100 mouse_down_ = WebMouseEvent(); |
101 svg_pan_ = false; | 101 svg_pan_ = false; |
102 drag_start_pos_ = LayoutPoint(); | 102 drag_start_pos_ = LayoutPoint(); |
103 fake_mouse_move_event_timer_.Stop(); | 103 fake_mouse_move_event_timer_.Stop(); |
104 ResetDragState(); | 104 ResetDragState(); |
105 } | 105 } |
106 | 106 |
107 MouseEventManager::~MouseEventManager() = default; | 107 MouseEventManager::~MouseEventManager() = default; |
108 | 108 |
109 DEFINE_TRACE(MouseEventManager) { | 109 DEFINE_TRACE(MouseEventManager) { |
110 visitor->Trace(frame_); | 110 visitor->Trace(frame_); |
111 visitor->Trace(scroll_manager_); | 111 visitor->Trace(scroll_manager_); |
112 visitor->Trace(node_under_mouse_); | 112 visitor->Trace(node_under_mouse_); |
113 visitor->Trace(mouse_press_node_); | 113 visitor->Trace(mouse_press_node_); |
114 visitor->Trace(click_node_); | 114 visitor->Trace(click_element_); |
115 SynchronousMutationObserver::Trace(visitor); | 115 SynchronousMutationObserver::Trace(visitor); |
116 } | 116 } |
117 | 117 |
118 MouseEventManager::MouseEventBoundaryEventDispatcher:: | 118 MouseEventManager::MouseEventBoundaryEventDispatcher:: |
119 MouseEventBoundaryEventDispatcher(MouseEventManager* mouse_event_manager, | 119 MouseEventBoundaryEventDispatcher(MouseEventManager* mouse_event_manager, |
120 const WebMouseEvent* web_mouse_event, | 120 const WebMouseEvent* web_mouse_event, |
121 EventTarget* exited_target, | 121 EventTarget* exited_target, |
122 const String& canvas_region_id) | 122 const String& canvas_region_id) |
123 : mouse_event_manager_(mouse_event_manager), | 123 : mouse_event_manager_(mouse_event_manager), |
124 web_mouse_event_(web_mouse_event), | 124 web_mouse_event_(web_mouse_event), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 target_node = FlatTreeTraversal::Parent(*target_node); | 226 target_node = FlatTreeTraversal::Parent(*target_node); |
227 | 227 |
228 SetNodeUnderMouse(target_node, canvas_region_id, web_mouse_event); | 228 SetNodeUnderMouse(target_node, canvas_region_id, web_mouse_event); |
229 | 229 |
230 return DispatchMouseEvent(node_under_mouse_, event_type, web_mouse_event, | 230 return DispatchMouseEvent(node_under_mouse_, event_type, web_mouse_event, |
231 canvas_region_id, nullptr); | 231 canvas_region_id, nullptr); |
232 } | 232 } |
233 | 233 |
234 WebInputEventResult MouseEventManager::DispatchMouseClickIfNeeded( | 234 WebInputEventResult MouseEventManager::DispatchMouseClickIfNeeded( |
235 const MouseEventWithHitTestResults& mev, | 235 const MouseEventWithHitTestResults& mev, |
236 Node* release_node) { | 236 Element& mouse_release_target) { |
237 // We only prevent click event when the click may cause contextmenu to popup. | 237 // We only prevent click event when the click may cause contextmenu to popup. |
238 // However, we always send auxclick. | 238 // However, we always send auxclick. |
239 bool context_menu_event = | 239 bool context_menu_event = |
240 !RuntimeEnabledFeatures::auxclickEnabled() && | 240 !RuntimeEnabledFeatures::auxclickEnabled() && |
241 mev.Event().button == WebPointerProperties::Button::kRight; | 241 mev.Event().button == WebPointerProperties::Button::kRight; |
242 #if OS(MACOSX) | 242 #if OS(MACOSX) |
243 // FIXME: The Mac port achieves the same behavior by checking whether the | 243 // FIXME: The Mac port achieves the same behavior by checking whether the |
244 // context menu is currently open in WebPage::mouseEvent(). Consider merging | 244 // context menu is currently open in WebPage::mouseEvent(). Consider merging |
245 // the implementations. | 245 // the implementations. |
246 if (mev.Event().button == WebPointerProperties::Button::kLeft && | 246 if (mev.Event().button == WebPointerProperties::Button::kLeft && |
247 mev.Event().GetModifiers() & WebInputEvent::Modifiers::kControlKey) | 247 mev.Event().GetModifiers() & WebInputEvent::Modifiers::kControlKey) |
248 context_menu_event = true; | 248 context_menu_event = true; |
249 #endif | 249 #endif |
250 | 250 |
251 WebInputEventResult click_event_result = WebInputEventResult::kNotHandled; | |
252 const bool should_dispatch_click_event = | 251 const bool should_dispatch_click_event = |
253 click_count_ > 0 && !context_menu_event && release_node && click_node_ && | 252 click_count_ > 0 && !context_menu_event && click_element_ && |
254 release_node->CanParticipateInFlatTree() && | 253 mouse_release_target.CanParticipateInFlatTree() && |
255 click_node_->CanParticipateInFlatTree() && | 254 click_element_->CanParticipateInFlatTree() && |
256 !(frame_->GetEventHandler() | 255 !(frame_->GetEventHandler() |
257 .GetSelectionController() | 256 .GetSelectionController() |
258 .HasExtendedSelection() && | 257 .HasExtendedSelection() && |
259 IsLinkSelection(mev)); | 258 IsLinkSelection(mev)); |
260 if (should_dispatch_click_event) { | 259 if (!should_dispatch_click_event) |
261 Node* click_target_node = nullptr; | 260 return WebInputEventResult::kNotHandled; |
262 if (click_node_ == release_node) { | 261 |
263 click_target_node = click_node_; | 262 Node* click_target_node = nullptr; |
264 } else if (click_node_->GetDocument() == release_node->GetDocument()) { | 263 if (click_element_ == mouse_release_target) { |
265 // Updates distribution because a 'mouseup' event listener can make the | 264 click_target_node = click_element_; |
266 // tree dirty at dispatchMouseEvent() invocation above. | 265 } else if (click_element_->GetDocument() == |
267 // Unless distribution is updated, commonAncestor would hit ASSERT. | 266 mouse_release_target.GetDocument()) { |
268 click_node_->UpdateDistribution(); | 267 // Updates distribution because a 'mouseup' event listener can make the |
269 release_node->UpdateDistribution(); | 268 // tree dirty at dispatchMouseEvent() invocation above. |
270 click_target_node = release_node->CommonAncestor( | 269 // Unless distribution is updated, commonAncestor would hit ASSERT. |
271 *click_node_, EventHandlingUtil::ParentForClickEvent); | 270 click_element_->UpdateDistribution(); |
272 } | 271 mouse_release_target.UpdateDistribution(); |
273 if (click_target_node) { | 272 click_target_node = mouse_release_target.CommonAncestor( |
274 click_event_result = DispatchMouseEvent( | 273 *click_element_, EventHandlingUtil::ParentForClickEvent); |
275 click_target_node, | |
276 !RuntimeEnabledFeatures::auxclickEnabled() || | |
277 (mev.Event().button == WebPointerProperties::Button::kLeft) | |
278 ? EventTypeNames::click | |
279 : EventTypeNames::auxclick, | |
280 mev.Event(), mev.CanvasRegionId(), nullptr); | |
281 } | |
282 } | 274 } |
283 return click_event_result; | 275 if (!click_target_node) |
| 276 return WebInputEventResult::kNotHandled; |
| 277 return DispatchMouseEvent( |
| 278 click_target_node, |
| 279 !RuntimeEnabledFeatures::auxclickEnabled() || |
| 280 (mev.Event().button == WebPointerProperties::Button::kLeft) |
| 281 ? EventTypeNames::click |
| 282 : EventTypeNames::auxclick, |
| 283 mev.Event(), mev.CanvasRegionId(), nullptr); |
284 } | 284 } |
285 | 285 |
286 void MouseEventManager::FakeMouseMoveEventTimerFired(TimerBase* timer) { | 286 void MouseEventManager::FakeMouseMoveEventTimerFired(TimerBase* timer) { |
287 TRACE_EVENT0("input", "MouseEventManager::fakeMouseMoveEventTimerFired"); | 287 TRACE_EVENT0("input", "MouseEventManager::fakeMouseMoveEventTimerFired"); |
288 DCHECK(timer == &fake_mouse_move_event_timer_); | 288 DCHECK(timer == &fake_mouse_move_event_timer_); |
289 DCHECK(!mouse_pressed_); | 289 DCHECK(!mouse_pressed_); |
290 | 290 |
291 if (is_mouse_position_unknown_) | 291 if (is_mouse_position_unknown_) |
292 return; | 292 return; |
293 | 293 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 if (last_node_under_mouse && | 374 if (last_node_under_mouse && |
375 last_node_under_mouse->GetDocument() != frame_->GetDocument()) { | 375 last_node_under_mouse->GetDocument() != frame_->GetDocument()) { |
376 last_node_under_mouse = nullptr; | 376 last_node_under_mouse = nullptr; |
377 } | 377 } |
378 | 378 |
379 SendBoundaryEvents(last_node_under_mouse, node_under_mouse_, canvas_region_id, | 379 SendBoundaryEvents(last_node_under_mouse, node_under_mouse_, canvas_region_id, |
380 web_mouse_event); | 380 web_mouse_event); |
381 } | 381 } |
382 | 382 |
383 void MouseEventManager::NodeChildrenWillBeRemoved(ContainerNode& container) { | 383 void MouseEventManager::NodeChildrenWillBeRemoved(ContainerNode& container) { |
384 if (container == click_node_) | 384 if (container == click_element_) |
385 return; | 385 return; |
386 if (!container.IsShadowIncludingInclusiveAncestorOf(click_node_.Get())) | 386 if (!container.IsShadowIncludingInclusiveAncestorOf(click_element_.Get())) |
387 return; | 387 return; |
388 click_node_ = nullptr; | 388 click_element_ = nullptr; |
389 } | 389 } |
390 | 390 |
391 void MouseEventManager::NodeWillBeRemoved(Node& node_to_be_removed) { | 391 void MouseEventManager::NodeWillBeRemoved(Node& node_to_be_removed) { |
392 if (node_to_be_removed.IsShadowIncludingInclusiveAncestorOf( | 392 if (node_to_be_removed.IsShadowIncludingInclusiveAncestorOf( |
393 click_node_.Get())) { | 393 click_element_.Get())) { |
394 // We don't dispatch click events if the mousedown node is removed | 394 // We don't dispatch click events if the mousedown node is removed |
395 // before a mouseup event. It is compatible with IE and Firefox. | 395 // before a mouseup event. It is compatible with IE and Firefox. |
396 click_node_ = nullptr; | 396 click_element_ = nullptr; |
397 } | 397 } |
398 } | 398 } |
399 | 399 |
400 Node* MouseEventManager::GetNodeUnderMouse() { | 400 Node* MouseEventManager::GetNodeUnderMouse() { |
401 return node_under_mouse_; | 401 return node_under_mouse_; |
402 } | 402 } |
403 | 403 |
404 WebInputEventResult MouseEventManager::HandleMouseFocus( | 404 WebInputEventResult MouseEventManager::HandleMouseFocus( |
405 const HitTestResult& hit_test_result, | 405 const HitTestResult& hit_test_result, |
406 InputDeviceCapabilities* source_capabilities) { | 406 InputDeviceCapabilities* source_capabilities) { |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 if (!svg_pan_) | 998 if (!svg_pan_) |
999 return false; | 999 return false; |
1000 svg_pan_ = !is_release_event; | 1000 svg_pan_ = !is_release_event; |
1001 frame_->GetDocument()->AccessSVGExtensions().UpdatePan( | 1001 frame_->GetDocument()->AccessSVGExtensions().UpdatePan( |
1002 frame_->View()->RootFrameToContents(last_known_mouse_position_)); | 1002 frame_->View()->RootFrameToContents(last_known_mouse_position_)); |
1003 return true; | 1003 return true; |
1004 } | 1004 } |
1005 | 1005 |
1006 void MouseEventManager::InvalidateClick() { | 1006 void MouseEventManager::InvalidateClick() { |
1007 click_count_ = 0; | 1007 click_count_ = 0; |
1008 click_node_ = nullptr; | 1008 click_element_ = nullptr; |
1009 } | 1009 } |
1010 | 1010 |
1011 bool MouseEventManager::MousePressed() { | 1011 bool MouseEventManager::MousePressed() { |
1012 return mouse_pressed_; | 1012 return mouse_pressed_; |
1013 } | 1013 } |
1014 | 1014 |
1015 void MouseEventManager::SetMousePressed(bool mouse_pressed) { | 1015 void MouseEventManager::SetMousePressed(bool mouse_pressed) { |
1016 mouse_pressed_ = mouse_pressed; | 1016 mouse_pressed_ = mouse_pressed; |
1017 } | 1017 } |
1018 | 1018 |
1019 bool MouseEventManager::CapturesDragging() const { | 1019 bool MouseEventManager::CapturesDragging() const { |
1020 return captures_dragging_; | 1020 return captures_dragging_; |
1021 } | 1021 } |
1022 | 1022 |
1023 void MouseEventManager::SetCapturesDragging(bool captures_dragging) { | 1023 void MouseEventManager::SetCapturesDragging(bool captures_dragging) { |
1024 captures_dragging_ = captures_dragging; | 1024 captures_dragging_ = captures_dragging; |
1025 } | 1025 } |
1026 | 1026 |
1027 Node* MouseEventManager::MousePressNode() { | 1027 Node* MouseEventManager::MousePressNode() { |
1028 return mouse_press_node_; | 1028 return mouse_press_node_; |
1029 } | 1029 } |
1030 | 1030 |
1031 void MouseEventManager::SetMousePressNode(Node* node) { | 1031 void MouseEventManager::SetMousePressNode(Node* node) { |
1032 mouse_press_node_ = node; | 1032 mouse_press_node_ = node; |
1033 } | 1033 } |
1034 | 1034 |
1035 void MouseEventManager::SetClickNode(Node* node) { | 1035 void MouseEventManager::SetClickElement(Element* element) { |
1036 SetContext(node ? node->ownerDocument() : nullptr); | 1036 SetContext(element ? element->ownerDocument() : nullptr); |
1037 click_node_ = node; | 1037 click_element_ = element; |
1038 } | 1038 } |
1039 | 1039 |
1040 void MouseEventManager::SetClickCount(int click_count) { | 1040 void MouseEventManager::SetClickCount(int click_count) { |
1041 click_count_ = click_count; | 1041 click_count_ = click_count; |
1042 } | 1042 } |
1043 | 1043 |
1044 bool MouseEventManager::MouseDownMayStartDrag() { | 1044 bool MouseEventManager::MouseDownMayStartDrag() { |
1045 return mouse_down_may_start_drag_; | 1045 return mouse_down_may_start_drag_; |
1046 } | 1046 } |
1047 | 1047 |
1048 } // namespace blink | 1048 } // namespace blink |
OLD | NEW |