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

Side by Side Diff: Source/core/page/EventHandler.cpp

Issue 46353003: Switch AutoscrollController to use animation system instead of timer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@gclient
Patch Set: Created 7 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies)
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "core/events/ThreadLocalEventNames.h" 50 #include "core/events/ThreadLocalEventNames.h"
51 #include "core/events/TouchEvent.h" 51 #include "core/events/TouchEvent.h"
52 #include "core/events/WheelEvent.h" 52 #include "core/events/WheelEvent.h"
53 #include "core/fetch/ImageResource.h" 53 #include "core/fetch/ImageResource.h"
54 #include "core/html/HTMLDialogElement.h" 54 #include "core/html/HTMLDialogElement.h"
55 #include "core/html/HTMLFrameElementBase.h" 55 #include "core/html/HTMLFrameElementBase.h"
56 #include "core/html/HTMLFrameSetElement.h" 56 #include "core/html/HTMLFrameSetElement.h"
57 #include "core/html/HTMLInputElement.h" 57 #include "core/html/HTMLInputElement.h"
58 #include "core/loader/FrameLoader.h" 58 #include "core/loader/FrameLoader.h"
59 #include "core/loader/FrameLoaderClient.h" 59 #include "core/loader/FrameLoaderClient.h"
60 #include "core/page/AutoscrollController.h"
60 #include "core/page/BackForwardClient.h" 61 #include "core/page/BackForwardClient.h"
61 #include "core/page/Chrome.h" 62 #include "core/page/Chrome.h"
62 #include "core/page/DragController.h" 63 #include "core/page/DragController.h"
63 #include "core/page/DragState.h" 64 #include "core/page/DragState.h"
64 #include "core/page/EditorClient.h" 65 #include "core/page/EditorClient.h"
65 #include "core/page/FocusController.h" 66 #include "core/page/FocusController.h"
66 #include "core/frame/Frame.h" 67 #include "core/frame/Frame.h"
67 #include "core/page/FrameTree.h" 68 #include "core/page/FrameTree.h"
68 #include "core/frame/FrameView.h" 69 #include "core/frame/FrameView.h"
69 #include "core/page/MouseEventWithHitTestResults.h" 70 #include "core/page/MouseEventWithHitTestResults.h"
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 return false; 696 return false;
696 697
697 renderer = parent->renderer(); 698 renderer = parent->renderer();
698 if (!renderer || !renderer->isListBox()) 699 if (!renderer || !renderer->isListBox())
699 return false; 700 return false;
700 } 701 }
701 702
702 m_mouseDownMayStartDrag = false; 703 m_mouseDownMayStartDrag = false;
703 704
704 if (m_mouseDownMayStartAutoscroll && !panScrollInProgress()) { 705 if (m_mouseDownMayStartAutoscroll && !panScrollInProgress()) {
705 if (Page* page = m_frame->page()) { 706 if (AutoscrollController* controller = autoscrollController()) {
706 page->startAutoscrollForSelection(renderer); 707 controller->startAutoscrollForSelection(renderer);
707 m_mouseDownMayStartAutoscroll = false; 708 m_mouseDownMayStartAutoscroll = false;
708 } 709 }
709 } 710 }
710 711
711 if (m_selectionInitiationState != ExtendedSelection) { 712 if (m_selectionInitiationState != ExtendedSelection) {
712 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent); 713 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent);
713 HitTestResult result(m_mouseDownPos); 714 HitTestResult result(m_mouseDownPos);
714 m_frame->document()->renderView()->hitTest(request, result); 715 m_frame->document()->renderView()->hitTest(request, result);
715 716
716 updateSelectionForMouseDrag(result); 717 updateSelectionForMouseDrag(result);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 794
794 if (m_frame->selection().granularity() != CharacterGranularity) 795 if (m_frame->selection().granularity() != CharacterGranularity)
795 newSelection.expandUsingGranularity(m_frame->selection().granularity()); 796 newSelection.expandUsingGranularity(m_frame->selection().granularity());
796 797
797 m_frame->selection().setNonDirectionalSelectionIfNeeded(newSelection, m_fram e->selection().granularity(), 798 m_frame->selection().setNonDirectionalSelectionIfNeeded(newSelection, m_fram e->selection().granularity(),
798 FrameSelection::AdjustEndpointsAtBidiBoundary); 799 FrameSelection::AdjustEndpointsAtBidiBoundary);
799 } 800 }
800 801
801 bool EventHandler::handleMouseReleaseEvent(const MouseEventWithHitTestResults& e vent) 802 bool EventHandler::handleMouseReleaseEvent(const MouseEventWithHitTestResults& e vent)
802 { 803 {
803 Page* page = m_frame->page(); 804 AutoscrollController* controller = autoscrollController();
804 if (page && page->autoscrollInProgress()) 805 if (controller && controller->autoscrollInProgress())
805 stopAutoscrollTimer(); 806 stopAutoscroll();
806 807
807 // Used to prevent mouseMoveEvent from initiating a drag before 808 // Used to prevent mouseMoveEvent from initiating a drag before
808 // the mouse is pressed again. 809 // the mouse is pressed again.
809 m_mousePressed = false; 810 m_mousePressed = false;
810 m_capturesDragging = false; 811 m_capturesDragging = false;
811 m_mouseDownMayStartDrag = false; 812 m_mouseDownMayStartDrag = false;
812 m_mouseDownMayStartSelect = false; 813 m_mouseDownMayStartSelect = false;
813 m_mouseDownMayStartAutoscroll = false; 814 m_mouseDownMayStartAutoscroll = false;
814 m_mouseDownWasInSubframe = false; 815 m_mouseDownWasInSubframe = false;
815 816
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 848
848 return handled; 849 return handled;
849 } 850 }
850 851
851 #if OS(WIN) 852 #if OS(WIN)
852 853
853 void EventHandler::startPanScrolling(RenderObject* renderer) 854 void EventHandler::startPanScrolling(RenderObject* renderer)
854 { 855 {
855 if (!renderer->isBox()) 856 if (!renderer->isBox())
856 return; 857 return;
857 Page* page = m_frame->page(); 858 AutoscrollController* controller = autoscrollController();
858 if (!page) 859 if (!controller)
859 return; 860 return;
860 page->startPanScrolling(toRenderBox(renderer), lastKnownMousePosition()); 861 controller->startPanScrolling(toRenderBox(renderer), lastKnownMousePosition( ));
861 invalidateClick(); 862 invalidateClick();
862 } 863 }
863 864
864 #endif // OS(WIN) 865 #endif // OS(WIN)
865 866
867 AutoscrollController* EventHandler::autoscrollController() const
868 {
869 Page* page = m_frame->page();
870 if (!page)
871 return 0;
872 return &page->autoscrollController();
esprehn 2013/11/01 19:37:37 We usually write: if (Page* page = m_frame->page(
873 }
874
866 bool EventHandler::panScrollInProgress() const 875 bool EventHandler::panScrollInProgress() const
867 { 876 {
868 Page* page = m_frame->page(); 877 return autoscrollController() && autoscrollController()->panScrollInProgress ();
869 return page && page->panScrollInProgress();
870 } 878 }
871 879
872 HitTestResult EventHandler::hitTestResultAtPoint(const LayoutPoint& point, HitTe stRequest::HitTestRequestType hitType, const LayoutSize& padding) 880 HitTestResult EventHandler::hitTestResultAtPoint(const LayoutPoint& point, HitTe stRequest::HitTestRequestType hitType, const LayoutSize& padding)
873 { 881 {
874 // We always send hitTestResultAtPoint to the main frame if we have one, 882 // We always send hitTestResultAtPoint to the main frame if we have one,
875 // otherwise we might hit areas that are obscured by higher frames. 883 // otherwise we might hit areas that are obscured by higher frames.
876 if (Page* page = m_frame->page()) { 884 if (Page* page = m_frame->page()) {
877 Frame* mainFrame = page->mainFrame(); 885 Frame* mainFrame = page->mainFrame();
878 if (m_frame != mainFrame) { 886 if (m_frame != mainFrame) {
879 FrameView* frameView = m_frame->view(); 887 FrameView* frameView = m_frame->view();
(...skipping 21 matching lines...) Expand all
901 m_frame->contentRenderer()->hitTest(request, result); 909 m_frame->contentRenderer()->hitTest(request, result);
902 if (!request.readOnly()) 910 if (!request.readOnly())
903 m_frame->document()->updateHoverActiveState(request, result.innerElement ()); 911 m_frame->document()->updateHoverActiveState(request, result.innerElement ());
904 912
905 if (request.disallowsShadowContent()) 913 if (request.disallowsShadowContent())
906 result.setToNodesInDocumentTreeScope(); 914 result.setToNodesInDocumentTreeScope();
907 915
908 return result; 916 return result;
909 } 917 }
910 918
911 void EventHandler::stopAutoscrollTimer() 919 void EventHandler::stopAutoscroll()
912 { 920 {
913 Page* page = m_frame->page(); 921 if (AutoscrollController* controller = autoscrollController())
914 if (!page) 922 controller->stopAutoscroll();
915 return;
916 page->stopAutoscrollTimer();
917 } 923 }
918 924
919 Node* EventHandler::mousePressNode() const 925 Node* EventHandler::mousePressNode() const
920 { 926 {
921 return m_mousePressNode.get(); 927 return m_mousePressNode.get();
922 } 928 }
923 929
924 bool EventHandler::scrollOverflow(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode) 930 bool EventHandler::scrollOverflow(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode)
925 { 931 {
926 Node* node = startingNode; 932 Node* node = startingNode;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 m_capturesDragging = subframe->eventHandler().capturesDragging(); 1353 m_capturesDragging = subframe->eventHandler().capturesDragging();
1348 if (m_mousePressed && m_capturesDragging) { 1354 if (m_mousePressed && m_capturesDragging) {
1349 m_capturingMouseEventsNode = mev.targetNode(); 1355 m_capturingMouseEventsNode = mev.targetNode();
1350 m_eventHandlerWillResetCapturingMouseEventsNode = true; 1356 m_eventHandlerWillResetCapturingMouseEventsNode = true;
1351 } 1357 }
1352 invalidateClick(); 1358 invalidateClick();
1353 return true; 1359 return true;
1354 } 1360 }
1355 1361
1356 #if OS(WIN) 1362 #if OS(WIN)
1357 // We store whether pan scrolling is in progress before calling stopAutoscro llTimer() 1363 // We store whether pan scrolling is in progress before calling stopAutoscro ll()
1358 // because it will set m_autoscrollType to NoAutoscroll on return. 1364 // because it will set m_autoscrollType to NoAutoscroll on return.
1359 bool isPanScrollInProgress = panScrollInProgress(); 1365 bool isPanScrollInProgress = panScrollInProgress();
1360 stopAutoscrollTimer(); 1366 stopAutoscroll();
1361 if (isPanScrollInProgress) { 1367 if (isPanScrollInProgress) {
1362 // We invalidate the click when exiting pan scrolling so that we don't i nadvertently navigate 1368 // We invalidate the click when exiting pan scrolling so that we don't i nadvertently navigate
1363 // away from the current page (e.g. the click was on a hyperlink). See < rdar://problem/6095023>. 1369 // away from the current page (e.g. the click was on a hyperlink). See < rdar://problem/6095023>.
1364 invalidateClick(); 1370 invalidateClick();
1365 return true; 1371 return true;
1366 } 1372 }
1367 #endif 1373 #endif
1368 1374
1369 m_clickCount = mouseEvent.clickCount(); 1375 m_clickCount = mouseEvent.clickCount();
1370 m_clickNode = mev.targetNode(); 1376 m_clickNode = mev.targetNode();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 1651
1646 OwnPtr<UserGestureIndicator> gestureIndicator; 1652 OwnPtr<UserGestureIndicator> gestureIndicator;
1647 1653
1648 if (m_frame->tree().top()->eventHandler().m_lastMouseDownUserGestureToken) 1654 if (m_frame->tree().top()->eventHandler().m_lastMouseDownUserGestureToken)
1649 gestureIndicator = adoptPtr(new UserGestureIndicator(m_frame->tree().top ()->eventHandler().m_lastMouseDownUserGestureToken.release())); 1655 gestureIndicator = adoptPtr(new UserGestureIndicator(m_frame->tree().top ()->eventHandler().m_lastMouseDownUserGestureToken.release()));
1650 else 1656 else
1651 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture)); 1657 gestureIndicator = adoptPtr(new UserGestureIndicator(DefinitelyProcessin gUserGesture));
1652 1658
1653 #if OS(WIN) 1659 #if OS(WIN)
1654 if (Page* page = m_frame->page()) 1660 if (Page* page = m_frame->page())
1655 page->handleMouseReleaseForPanScrolling(m_frame, mouseEvent); 1661 page->autoscrollController().handleMouseReleaseForPanScrolling(m_frame, mouseEvent);
1656 #endif 1662 #endif
1657 1663
1658 m_mousePressed = false; 1664 m_mousePressed = false;
1659 setLastKnownMousePosition(mouseEvent); 1665 setLastKnownMousePosition(mouseEvent);
1660 1666
1661 if (m_svgPan) { 1667 if (m_svgPan) {
1662 m_svgPan = false; 1668 m_svgPan = false;
1663 toSVGDocument(m_frame->document())->updatePan(m_frame->view()->windowToC ontents(m_lastKnownMousePosition)); 1669 toSVGDocument(m_frame->document())->updatePan(m_frame->view()->windowToC ontents(m_lastKnownMousePosition));
1664 return true; 1670 return true;
1665 } 1671 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 return false; 1822 return false;
1817 1823
1818 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::DisallowSh adowContent); 1824 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::DisallowSh adowContent);
1819 MouseEventWithHitTestResults mev = prepareMouseEvent(request, event); 1825 MouseEventWithHitTestResults mev = prepareMouseEvent(request, event);
1820 1826
1821 // Drag events should never go to text nodes (following IE, and proper mouse over/out dispatch) 1827 // Drag events should never go to text nodes (following IE, and proper mouse over/out dispatch)
1822 RefPtr<Node> newTarget = mev.targetNode(); 1828 RefPtr<Node> newTarget = mev.targetNode();
1823 if (newTarget && newTarget->isTextNode()) 1829 if (newTarget && newTarget->isTextNode())
1824 newTarget = EventPath::parent(newTarget.get()); 1830 newTarget = EventPath::parent(newTarget.get());
1825 1831
1826 if (Page* page = m_frame->page()) 1832 if (AutoscrollController* controller = autoscrollController())
1827 page->updateDragAndDrop(newTarget.get(), event.position(), event.timesta mp()); 1833 controller->updateDragAndDrop(newTarget.get(), event.position(), event.t imestamp());
1828 1834
1829 if (m_dragTarget != newTarget) { 1835 if (m_dragTarget != newTarget) {
1830 // FIXME: this ordering was explicitly chosen to match WinIE. However, 1836 // FIXME: this ordering was explicitly chosen to match WinIE. However,
1831 // it is sometimes incorrect when dragging within subframes, as seen wit h 1837 // it is sometimes incorrect when dragging within subframes, as seen wit h
1832 // LayoutTests/fast/events/drag-in-frames.html. 1838 // LayoutTests/fast/events/drag-in-frames.html.
1833 // 1839 //
1834 // Moreover, this ordering conforms to section 7.9.4 of the HTML 5 spec. <http://dev.w3.org/html5/spec/Overview.html#drag-and-drop-processing-model>. 1840 // Moreover, this ordering conforms to section 7.9.4 of the HTML 5 spec. <http://dev.w3.org/html5/spec/Overview.html#drag-and-drop-processing-model>.
1835 Frame* targetFrame; 1841 Frame* targetFrame;
1836 if (targetIsFrame(newTarget.get(), targetFrame)) { 1842 if (targetIsFrame(newTarget.get(), targetFrame)) {
1837 if (targetFrame) 1843 if (targetFrame)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 if (targetFrame) 1908 if (targetFrame)
1903 preventedDefault = targetFrame->eventHandler().performDragAndDrop(ev ent, clipboard); 1909 preventedDefault = targetFrame->eventHandler().performDragAndDrop(ev ent, clipboard);
1904 } else if (m_dragTarget.get()) 1910 } else if (m_dragTarget.get())
1905 preventedDefault = dispatchDragEvent(EventTypeNames::drop, m_dragTarget. get(), event, clipboard); 1911 preventedDefault = dispatchDragEvent(EventTypeNames::drop, m_dragTarget. get(), event, clipboard);
1906 clearDragState(); 1912 clearDragState();
1907 return preventedDefault; 1913 return preventedDefault;
1908 } 1914 }
1909 1915
1910 void EventHandler::clearDragState() 1916 void EventHandler::clearDragState()
1911 { 1917 {
1912 stopAutoscrollTimer(); 1918 stopAutoscroll();
1913 m_dragTarget = 0; 1919 m_dragTarget = 0;
1914 m_capturingMouseEventsNode = 0; 1920 m_capturingMouseEventsNode = 0;
1915 m_shouldOnlyFireDragOverEvent = false; 1921 m_shouldOnlyFireDragOverEvent = false;
1916 } 1922 }
1917 1923
1918 void EventHandler::setCapturingMouseEventsNode(PassRefPtr<Node> n) 1924 void EventHandler::setCapturingMouseEventsNode(PassRefPtr<Node> n)
1919 { 1925 {
1920 m_capturingMouseEventsNode = n; 1926 m_capturingMouseEventsNode = n;
1921 m_eventHandlerWillResetCapturingMouseEventsNode = false; 1927 m_eventHandlerWillResetCapturingMouseEventsNode = false;
1922 } 1928 }
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 return false; 3017 return false;
3012 } 3018 }
3013 3019
3014 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL) 3020 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL)
3015 capsLockStateMayHaveChanged(); 3021 capsLockStateMayHaveChanged();
3016 3022
3017 #if OS(WIN) 3023 #if OS(WIN)
3018 if (panScrollInProgress()) { 3024 if (panScrollInProgress()) {
3019 // If a key is pressed while the panScroll is in progress then we want t o stop 3025 // If a key is pressed while the panScroll is in progress then we want t o stop
3020 if (initialKeyEvent.type() == PlatformEvent::KeyDown || initialKeyEvent. type() == PlatformEvent::RawKeyDown) 3026 if (initialKeyEvent.type() == PlatformEvent::KeyDown || initialKeyEvent. type() == PlatformEvent::RawKeyDown)
3021 stopAutoscrollTimer(); 3027 stopAutoscroll();
3022 3028
3023 // If we were in panscroll mode, we swallow the key event 3029 // If we were in panscroll mode, we swallow the key event
3024 return true; 3030 return true;
3025 } 3031 }
3026 #endif 3032 #endif
3027 3033
3028 // Check for cases where we are too early for events -- possible unmatched k ey up 3034 // Check for cases where we are too early for events -- possible unmatched k ey up
3029 // from pressing return in the location bar. 3035 // from pressing return in the location bar.
3030 RefPtr<Node> node = eventTargetNodeForDocument(m_frame->document()); 3036 RefPtr<Node> node = eventTargetNodeForDocument(m_frame->document());
3031 if (!node) 3037 if (!node)
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
3870 unsigned EventHandler::accessKeyModifiers() 3876 unsigned EventHandler::accessKeyModifiers()
3871 { 3877 {
3872 #if OS(MACOSX) 3878 #if OS(MACOSX)
3873 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3879 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3874 #else 3880 #else
3875 return PlatformEvent::AltKey; 3881 return PlatformEvent::AltKey;
3876 #endif 3882 #endif
3877 } 3883 }
3878 3884
3879 } // namespace WebCore 3885 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698