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 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 } | 886 } |
887 | 887 |
888 return false; | 888 return false; |
889 } | 889 } |
890 | 890 |
891 // Returns if we should continue "default processing", i.e., whether | 891 // Returns if we should continue "default processing", i.e., whether |
892 // eventhandler canceled. | 892 // eventhandler canceled. |
893 WebInputEventResult MouseEventManager::DispatchDragSrcEvent( | 893 WebInputEventResult MouseEventManager::DispatchDragSrcEvent( |
894 const AtomicString& event_type, | 894 const AtomicString& event_type, |
895 const WebMouseEvent& event) { | 895 const WebMouseEvent& event) { |
896 return DispatchDragEvent(event_type, GetDragState().drag_src_.Get(), event, | 896 return DispatchDragEvent(event_type, GetDragState().drag_src_.Get(), nullptr, |
897 GetDragState().drag_data_transfer_.Get()); | 897 event, GetDragState().drag_data_transfer_.Get()); |
898 } | 898 } |
899 | 899 |
900 WebInputEventResult MouseEventManager::DispatchDragEvent( | 900 WebInputEventResult MouseEventManager::DispatchDragEvent( |
901 const AtomicString& event_type, | 901 const AtomicString& event_type, |
902 Node* drag_target, | 902 Node* drag_target, |
| 903 Node* related_target, |
903 const WebMouseEvent& event, | 904 const WebMouseEvent& event, |
904 DataTransfer* data_transfer) { | 905 DataTransfer* data_transfer) { |
905 FrameView* view = frame_->View(); | 906 FrameView* view = frame_->View(); |
906 | |
907 // FIXME: We might want to dispatch a dragleave even if the view is gone. | 907 // FIXME: We might want to dispatch a dragleave even if the view is gone. |
908 if (!view) | 908 if (!view) |
909 return WebInputEventResult::kNotHandled; | 909 return WebInputEventResult::kNotHandled; |
910 | 910 |
| 911 // We should be setting relatedTarget correctly following the spec: |
| 912 // https://html.spec.whatwg.org/multipage/interaction.html#dragevent |
| 913 // At the same time this should prevent exposing a node from another document. |
| 914 if (related_target && |
| 915 related_target->GetDocument() != drag_target->GetDocument()) |
| 916 related_target = nullptr; |
| 917 |
911 const bool cancelable = event_type != EventTypeNames::dragleave && | 918 const bool cancelable = event_type != EventTypeNames::dragleave && |
912 event_type != EventTypeNames::dragend; | 919 event_type != EventTypeNames::dragend; |
913 | 920 |
914 IntPoint position = FlooredIntPoint(event.PositionInRootFrame()); | 921 IntPoint position = FlooredIntPoint(event.PositionInRootFrame()); |
915 IntPoint movement = FlooredIntPoint(event.MovementInRootFrame()); | 922 IntPoint movement = FlooredIntPoint(event.MovementInRootFrame()); |
916 DragEvent* me = DragEvent::Create( | 923 DragEvent* me = DragEvent::Create( |
917 event_type, true, cancelable, frame_->GetDocument()->domWindow(), 0, | 924 event_type, true, cancelable, frame_->GetDocument()->domWindow(), 0, |
918 event.PositionInScreen().x, event.PositionInScreen().y, position.X(), | 925 event.PositionInScreen().x, event.PositionInScreen().y, position.X(), |
919 position.Y(), movement.X(), movement.Y(), | 926 position.Y(), movement.X(), movement.Y(), |
920 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), 0, | 927 static_cast<WebInputEvent::Modifiers>(event.GetModifiers()), 0, |
921 MouseEvent::WebInputEventModifiersToButtons(event.GetModifiers()), | 928 MouseEvent::WebInputEventModifiersToButtons(event.GetModifiers()), |
922 nullptr, TimeTicks::FromSeconds(event.TimeStampSeconds()), data_transfer, | 929 related_target, TimeTicks::FromSeconds(event.TimeStampSeconds()), |
| 930 data_transfer, |
923 event.FromTouch() ? MouseEvent::kFromTouch | 931 event.FromTouch() ? MouseEvent::kFromTouch |
924 : MouseEvent::kRealOrIndistinguishable); | 932 : MouseEvent::kRealOrIndistinguishable); |
925 | 933 |
926 return EventHandlingUtil::ToWebInputEventResult( | 934 return EventHandlingUtil::ToWebInputEventResult( |
927 drag_target->DispatchEvent(me)); | 935 drag_target->DispatchEvent(me)); |
928 } | 936 } |
929 | 937 |
930 void MouseEventManager::ClearDragDataTransfer() { | 938 void MouseEventManager::ClearDragDataTransfer() { |
931 if (!frame_->GetPage()) | 939 if (!frame_->GetPage()) |
932 return; | 940 return; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1040 |
1033 void MouseEventManager::SetClickCount(int click_count) { | 1041 void MouseEventManager::SetClickCount(int click_count) { |
1034 click_count_ = click_count; | 1042 click_count_ = click_count; |
1035 } | 1043 } |
1036 | 1044 |
1037 bool MouseEventManager::MouseDownMayStartDrag() { | 1045 bool MouseEventManager::MouseDownMayStartDrag() { |
1038 return mouse_down_may_start_drag_; | 1046 return mouse_down_may_start_drag_; |
1039 } | 1047 } |
1040 | 1048 |
1041 } // namespace blink | 1049 } // namespace blink |
OLD | NEW |