Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: third_party/WebKit/Source/core/input/MouseEventManager.cpp

Issue 2687193004: Tie DragState to DragController. (Closed)
Patch Set: tidy up DragState resetting Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 if (!quad.containsPoint(view->rootFrameToContents(m_lastKnownMousePosition))) 549 if (!quad.containsPoint(view->rootFrameToContents(m_lastKnownMousePosition)))
550 return; 550 return;
551 551
552 dispatchFakeMouseMoveEventSoon(); 552 dispatchFakeMouseMoveEventSoon();
553 } 553 }
554 554
555 WebInputEventResult MouseEventManager::handleMousePressEvent( 555 WebInputEventResult MouseEventManager::handleMousePressEvent(
556 const MouseEventWithHitTestResults& event) { 556 const MouseEventWithHitTestResults& event) {
557 TRACE_EVENT0("blink", "MouseEventManager::handleMousePressEvent"); 557 TRACE_EVENT0("blink", "MouseEventManager::handleMousePressEvent");
558 558
559 // Reset drag state. 559 resetDragState();
560 dragState().m_dragSrc = nullptr;
561
562 cancelFakeMouseMoveEvent(); 560 cancelFakeMouseMoveEvent();
563 561
564 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 562 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
565 563
566 if (FrameView* frameView = m_frame->view()) { 564 if (FrameView* frameView = m_frame->view()) {
567 if (frameView->isPointInScrollbarCorner( 565 if (frameView->isPointInScrollbarCorner(
568 flooredIntPoint(event.event().positionInRootFrame()))) 566 flooredIntPoint(event.event().positionInRootFrame())))
569 return WebInputEventResult::NotHandled; 567 return WebInputEventResult::NotHandled;
570 } 568 }
571 569
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 WebInputEvent::MouseMove, gestureEvent, 663 WebInputEvent::MouseMove, gestureEvent,
666 WebPointerProperties::Button::Left, 1, 664 WebPointerProperties::Button::Left, 1,
667 modifiers | WebInputEvent::Modifiers::LeftButtonDown | 665 modifiers | WebInputEvent::Modifiers::LeftButtonDown |
668 WebInputEvent::Modifiers::IsCompatibilityEventForTouch, 666 WebInputEvent::Modifiers::IsCompatibilityEventForTouch,
669 TimeTicks::Now().InSeconds()); 667 TimeTicks::Now().InSeconds());
670 HitTestRequest request(HitTestRequest::ReadOnly); 668 HitTestRequest request(HitTestRequest::ReadOnly);
671 MouseEventWithHitTestResults mev = 669 MouseEventWithHitTestResults mev =
672 EventHandlingUtil::performMouseEventHitTest(m_frame, request, 670 EventHandlingUtil::performMouseEventHitTest(m_frame, request,
673 mouseDragEvent); 671 mouseDragEvent);
674 m_mouseDownMayStartDrag = true; 672 m_mouseDownMayStartDrag = true;
675 dragState().m_dragSrc = nullptr; 673 resetDragState();
676 m_mouseDownPos = m_frame->view()->rootFrameToContents( 674 m_mouseDownPos = m_frame->view()->rootFrameToContents(
677 flooredIntPoint(mouseDragEvent.positionInRootFrame())); 675 flooredIntPoint(mouseDragEvent.positionInRootFrame()));
678 return handleDrag(mev, DragInitiator::Touch); 676 return handleDrag(mev, DragInitiator::Touch);
679 } 677 }
680 return false; 678 return false;
681 } 679 }
682 680
683 void MouseEventManager::focusDocumentView() { 681 void MouseEventManager::focusDocumentView() {
684 Page* page = m_frame->page(); 682 Page* page = m_frame->page();
685 if (!page) 683 if (!page)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 DragController::SelectionDragPolicy selectionDragPolicy = 769 DragController::SelectionDragPolicy selectionDragPolicy =
772 TimeTicks::FromSeconds(event.event().timeStampSeconds()) - 770 TimeTicks::FromSeconds(event.event().timeStampSeconds()) -
773 m_mouseDownTimestamp < 771 m_mouseDownTimestamp <
774 kTextDragDelay 772 kTextDragDelay
775 ? DragController::DelayedSelectionDragResolution 773 ? DragController::DelayedSelectionDragResolution
776 : DragController::ImmediateSelectionDragResolution; 774 : DragController::ImmediateSelectionDragResolution;
777 dragState().m_dragSrc = m_frame->page()->dragController().draggableNode( 775 dragState().m_dragSrc = m_frame->page()->dragController().draggableNode(
778 m_frame, node, m_mouseDownPos, selectionDragPolicy, 776 m_frame, node, m_mouseDownPos, selectionDragPolicy,
779 dragState().m_dragType); 777 dragState().m_dragType);
780 } else { 778 } else {
781 dragState().m_dragSrc = nullptr; 779 resetDragState();
782 } 780 }
783 781
784 if (!dragState().m_dragSrc) 782 if (!dragState().m_dragSrc)
785 m_mouseDownMayStartDrag = false; // no element is draggable 783 m_mouseDownMayStartDrag = false; // no element is draggable
786 } 784 }
787 785
788 if (!m_mouseDownMayStartDrag) { 786 if (!m_mouseDownMayStartDrag) {
789 return initiator == DragInitiator::Mouse && 787 return initiator == DragInitiator::Mouse &&
790 !m_frame->eventHandler() 788 !m_frame->eventHandler()
791 .selectionController() 789 .selectionController()
792 .mouseDownMayStartSelect() && 790 .mouseDownMayStartSelect() &&
793 !m_mouseDownMayStartAutoscroll; 791 !m_mouseDownMayStartAutoscroll;
794 } 792 }
795 793
796 // We are starting a text/image/url drag, so the cursor should be an arrow 794 // We are starting a text/image/url drag, so the cursor should be an arrow
797 // FIXME <rdar://7577595>: Custom cursors aren't supported during drag and 795 // FIXME <rdar://7577595>: Custom cursors aren't supported during drag and
798 // drop (default to pointer). 796 // drop (default to pointer).
799 m_frame->view()->setCursor(pointerCursor()); 797 m_frame->view()->setCursor(pointerCursor());
800 798
801 if (initiator == DragInitiator::Mouse && 799 if (initiator == DragInitiator::Mouse &&
802 !dragThresholdExceeded( 800 !dragThresholdExceeded(
803 flooredIntPoint(event.event().positionInRootFrame()))) { 801 flooredIntPoint(event.event().positionInRootFrame()))) {
804 dragState().m_dragSrc = nullptr; 802 resetDragState();
805 return true; 803 return true;
806 } 804 }
807 805
808 // Once we're past the drag threshold, we don't want to treat this gesture as 806 // Once we're past the drag threshold, we don't want to treat this gesture as
809 // a click. 807 // a click.
810 invalidateClick(); 808 invalidateClick();
811 809
812 if (!tryStartDrag(event)) { 810 if (!tryStartDrag(event)) {
813 // Something failed to start the drag, clean up. 811 // Something failed to start the drag, clean up.
814 clearDragDataTransfer(); 812 clearDragDataTransfer();
815 dragState().m_dragSrc = nullptr; 813 resetDragState();
816 } 814 }
817 815
818 m_mouseDownMayStartDrag = false; 816 m_mouseDownMayStartDrag = false;
819 // Whether or not the drag actually started, no more default handling (like 817 // Whether or not the drag actually started, no more default handling (like
820 // selection). 818 // selection).
821 return true; 819 return true;
822 } 820 }
823 821
824 DataTransfer* MouseEventManager::createDraggingDataTransfer() const { 822 DataTransfer* MouseEventManager::createDraggingDataTransfer() const {
825 return DataTransfer::create(DataTransfer::DragAndDrop, DataTransferWritable, 823 return DataTransfer::create(DataTransfer::DragAndDrop, DataTransferWritable,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 } 913 }
916 914
917 void MouseEventManager::dragSourceEndedAt(const WebMouseEvent& event, 915 void MouseEventManager::dragSourceEndedAt(const WebMouseEvent& event,
918 DragOperation operation) { 916 DragOperation operation) {
919 if (dragState().m_dragSrc) { 917 if (dragState().m_dragSrc) {
920 dragState().m_dragDataTransfer->setDestinationOperation(operation); 918 dragState().m_dragDataTransfer->setDestinationOperation(operation);
921 // The return value is ignored because dragend is not cancelable. 919 // The return value is ignored because dragend is not cancelable.
922 dispatchDragSrcEvent(EventTypeNames::dragend, event); 920 dispatchDragSrcEvent(EventTypeNames::dragend, event);
923 } 921 }
924 clearDragDataTransfer(); 922 clearDragDataTransfer();
925 dragState().m_dragSrc = nullptr; 923 resetDragState();
926 // In case the drag was ended due to an escape key press we need to ensure 924 // In case the drag was ended due to an escape key press we need to ensure
927 // that consecutive mousemove events don't reinitiate the drag and drop. 925 // that consecutive mousemove events don't reinitiate the drag and drop.
928 m_mouseDownMayStartDrag = false; 926 m_mouseDownMayStartDrag = false;
929 } 927 }
930 928
931 DragState& MouseEventManager::dragState() { 929 DragState& MouseEventManager::dragState() {
932 DEFINE_STATIC_LOCAL(DragState, state, (new DragState)); 930 DCHECK(m_frame->page());
933 return state; 931 return m_frame->page()->dragController().dragState();
932 }
933
934 void MouseEventManager::resetDragState() {
935 if (!m_frame->page())
936 return;
937 dragState().m_dragSrc = nullptr;
934 } 938 }
935 939
936 bool MouseEventManager::dragThresholdExceeded( 940 bool MouseEventManager::dragThresholdExceeded(
937 const IntPoint& dragLocationInRootFrame) const { 941 const IntPoint& dragLocationInRootFrame) const {
938 FrameView* view = m_frame->view(); 942 FrameView* view = m_frame->view();
939 if (!view) 943 if (!view)
940 return false; 944 return false;
941 IntPoint dragLocation = view->rootFrameToContents(dragLocationInRootFrame); 945 IntPoint dragLocation = view->rootFrameToContents(dragLocationInRootFrame);
942 IntSize delta = dragLocation - m_mouseDownPos; 946 IntSize delta = dragLocation - m_mouseDownPos;
943 947
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 1007
1004 void MouseEventManager::setClickCount(int clickCount) { 1008 void MouseEventManager::setClickCount(int clickCount) {
1005 m_clickCount = clickCount; 1009 m_clickCount = clickCount;
1006 } 1010 }
1007 1011
1008 bool MouseEventManager::mouseDownMayStartDrag() { 1012 bool MouseEventManager::mouseDownMayStartDrag() {
1009 return m_mouseDownMayStartDrag; 1013 return m_mouseDownMayStartDrag;
1010 } 1014 }
1011 1015
1012 } // namespace blink 1016 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/input/MouseEventManager.h ('k') | third_party/WebKit/Source/core/page/DragController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698