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

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

Issue 1056983004: OverscrollGlow for mainThread-{BLINK CHANGES} (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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 /* 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 , m_selectionInitiationState(HaveNotStartedSelection) 226 , m_selectionInitiationState(HaveNotStartedSelection)
227 , m_hoverTimer(this, &EventHandler::hoverTimerFired) 227 , m_hoverTimer(this, &EventHandler::hoverTimerFired)
228 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired) 228 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
229 , m_mouseDownMayStartAutoscroll(false) 229 , m_mouseDownMayStartAutoscroll(false)
230 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d) 230 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d)
231 , m_svgPan(false) 231 , m_svgPan(false)
232 , m_resizeScrollableArea(nullptr) 232 , m_resizeScrollableArea(nullptr)
233 , m_eventHandlerWillResetCapturingMouseEventsNode(0) 233 , m_eventHandlerWillResetCapturingMouseEventsNode(0)
234 , m_clickCount(0) 234 , m_clickCount(0)
235 , m_shouldOnlyFireDragOverEvent(false) 235 , m_shouldOnlyFireDragOverEvent(false)
236 , m_unusedDelta(FloatSize())
237 , m_accumulatedRootOverscroll(FloatSize())
236 , m_mousePositionIsUnknown(true) 238 , m_mousePositionIsUnknown(true)
237 , m_mouseDownTimestamp(0) 239 , m_mouseDownTimestamp(0)
238 , m_widgetIsLatched(false) 240 , m_widgetIsLatched(false)
239 , m_touchPressed(false) 241 , m_touchPressed(false)
240 , m_scrollGestureHandlingNode(nullptr) 242 , m_scrollGestureHandlingNode(nullptr)
241 , m_lastGestureScrollOverWidget(false) 243 , m_lastGestureScrollOverWidget(false)
242 , m_maxMouseMovedDuration(0) 244 , m_maxMouseMovedDuration(0)
243 , m_longTapShouldInvokeContextMenu(false) 245 , m_longTapShouldInvokeContextMenu(false)
244 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 246 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
245 , m_lastShowPressTimestamp(0) 247 , m_lastShowPressTimestamp(0)
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 919
918 return result; 920 return result;
919 } 921 }
920 922
921 void EventHandler::stopAutoscroll() 923 void EventHandler::stopAutoscroll()
922 { 924 {
923 if (AutoscrollController* controller = autoscrollController()) 925 if (AutoscrollController* controller = autoscrollController())
924 controller->stopAutoscroll(); 926 controller->stopAutoscroll();
925 } 927 }
926 928
927 bool EventHandler::scroll(ScrollDirection direction, ScrollGranularity granulari ty, Node* startNode, Node** stopNode, float delta, IntPoint absolutePoint) 929 ScrollResultOneDimensional EventHandler::scroll(ScrollDirection direction, Scrol lGranularity granularity, Node* startNode, Node** stopNode, float delta, IntPoin t absolutePoint)
928 { 930 {
929 if (!delta) 931 if (!delta)
930 return false; 932 return ScrollResultOneDimensional(false);
931 933
932 Node* node = startNode; 934 Node* node = startNode;
933 935
934 if (!node) 936 if (!node)
935 node = m_frame->document()->focusedElement(); 937 node = m_frame->document()->focusedElement();
936 938
937 if (!node) 939 if (!node)
938 node = m_mousePressNode.get(); 940 node = m_mousePressNode.get();
939 941
940 if (!node || !node->layoutObject()) 942 if (!node || !node->layoutObject())
941 return false; 943 return ScrollResultOneDimensional(false, delta);
942 944
943 LayoutBox* curBox = node->layoutObject()->enclosingBox(); 945 LayoutBox* curBox = node->layoutObject()->enclosingBox();
944 while (curBox && !curBox->isLayoutView()) { 946 while (curBox && !curBox->isLayoutView()) {
945 ScrollDirectionPhysical physicalDirection = toPhysicalDirection( 947 ScrollDirectionPhysical physicalDirection = toPhysicalDirection(
946 direction, curBox->isHorizontalWritingMode(), curBox->style()->isFli ppedBlocksWritingMode()); 948 direction, curBox->isHorizontalWritingMode(), curBox->style()->isFli ppedBlocksWritingMode());
947 949
948 // If we're at the stopNode, we should try to scroll it but we shouldn't bubble past it 950 // If we're at the stopNode, we should try to scroll it but we shouldn't bubble past it
949 bool shouldStopBubbling = stopNode && *stopNode && curBox->node() == *st opNode; 951 bool shouldStopBubbling = stopNode && *stopNode && curBox->node() == *st opNode;
950 bool didScroll = curBox->scroll(physicalDirection, granularity, delta); 952 ScrollResultOneDimensional result = curBox->scroll(physicalDirection, gr anularity, delta);
951 953
952 if (didScroll && stopNode) 954 if (result.didScroll && stopNode)
953 *stopNode = curBox->node(); 955 *stopNode = curBox->node();
954 956
955 if (didScroll || shouldStopBubbling) { 957 if (result.didScroll || shouldStopBubbling) {
956 setFrameWasScrolledByUser(); 958 setFrameWasScrolledByUser();
957 return true; 959 result.didScroll = true;
960 return result;
958 } 961 }
959 962
960 curBox = curBox->containingBlock(); 963 curBox = curBox->containingBlock();
961 } 964 }
962 965
963 return false; 966 return ScrollResultOneDimensional(false, delta);
964 } 967 }
965 968
966 void EventHandler::customizedScroll(const Node& startNode, ScrollState& scrollSt ate) 969 void EventHandler::customizedScroll(const Node& startNode, ScrollState& scrollSt ate)
967 { 970 {
968 if (scrollState.fullyConsumed()) 971 if (scrollState.fullyConsumed())
969 return; 972 return;
970 973
971 if (m_currentScrollChain.isEmpty()) 974 if (m_currentScrollChain.isEmpty())
972 recomputeScrollChain(*m_frame, startNode, m_currentScrollChain); 975 recomputeScrollChain(*m_frame, startNode, m_currentScrollChain);
973 scrollState.setScrollChain(m_currentScrollChain); 976 scrollState.setScrollChain(m_currentScrollChain);
974 scrollState.distributeToScrollChainDescendant(); 977 scrollState.distributeToScrollChainDescendant();
975 } 978 }
976 979
977 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode) 980 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode)
978 { 981 {
979 // The layout needs to be up to date to determine if we can scroll. We may b e 982 // The layout needs to be up to date to determine if we can scroll. We may b e
980 // here because of an onLoad event, in which case the final layout hasn't be en performed yet. 983 // here because of an onLoad event, in which case the final layout hasn't be en performed yet.
981 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 984 m_frame->document()->updateLayoutIgnorePendingStylesheets();
982 // FIXME: enable scroll customization in this case. See crbug.com/410974. 985 // FIXME: enable scroll customization in this case. See crbug.com/410974.
983 if (scroll(direction, granularity, startingNode)) 986 if (scroll(direction, granularity, startingNode).didScroll)
984 return true; 987 return true;
985 LocalFrame* frame = m_frame; 988 LocalFrame* frame = m_frame;
986 FrameView* view = frame->view(); 989 FrameView* view = frame->view();
987 if (view) { 990 if (view) {
988 ScrollDirectionPhysical physicalDirection = 991 ScrollDirectionPhysical physicalDirection =
989 toPhysicalDirection(direction, view->isVerticalDocument(), view->isF lippedDocument()); 992 toPhysicalDirection(direction, view->isVerticalDocument(), view->isF lippedDocument());
990 if (view->scrollableArea()->scroll(physicalDirection, granularity)) { 993 if (view->scrollableArea()->scroll(physicalDirection, granularity).didSc roll) {
991 setFrameWasScrolledByUser(); 994 setFrameWasScrolledByUser();
992 return true; 995 return true;
993 } 996 }
994 } 997 }
995 998
996 Frame* parentFrame = frame->tree().parent(); 999 Frame* parentFrame = frame->tree().parent();
997 if (!parentFrame || !parentFrame->isLocalFrame()) 1000 if (!parentFrame || !parentFrame->isLocalFrame())
998 return false; 1001 return false;
999 // FIXME: Broken for OOPI. 1002 // FIXME: Broken for OOPI.
1000 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g ranularity, m_frame->deprecatedLocalOwner()); 1003 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g ranularity, m_frame->deprecatedLocalOwner());
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 2200
2198 Node* stopNode = m_previousWheelScrolledNode.get(); 2201 Node* stopNode = m_previousWheelScrolledNode.get();
2199 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt); 2202 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt);
2200 IntPoint absolutePosition = roundedIntPoint(wheelEvent->absoluteLocation()); 2203 IntPoint absolutePosition = roundedIntPoint(wheelEvent->absoluteLocation());
2201 2204
2202 // Break up into two scrolls if we need to. Diagonal movement on 2205 // Break up into two scrolls if we need to. Diagonal movement on
2203 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set). 2206 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set).
2204 2207
2205 // FIXME: enable scroll customization in this case. See crbug.com/410974. 2208 // FIXME: enable scroll customization in this case. See crbug.com/410974.
2206 if (wheelEvent->railsMode() != Event::RailsModeVertical 2209 if (wheelEvent->railsMode() != Event::RailsModeVertical
2207 && scroll(ScrollRightIgnoringWritingMode, granularity, startNode, &stopN ode, wheelEvent->deltaX(), absolutePosition)) 2210 && scroll(ScrollRightIgnoringWritingMode, granularity, startNode, &stopN ode, wheelEvent->deltaX(), absolutePosition).didScroll)
2208 wheelEvent->setDefaultHandled(); 2211 wheelEvent->setDefaultHandled();
2209 2212
2210 if (wheelEvent->railsMode() != Event::RailsModeHorizontal 2213 if (wheelEvent->railsMode() != Event::RailsModeHorizontal
2211 && scroll(ScrollDownIgnoringWritingMode, granularity, startNode, &stopNo de, wheelEvent->deltaY(), absolutePosition)) 2214 && scroll(ScrollDownIgnoringWritingMode, granularity, startNode, &stopNo de, wheelEvent->deltaY(), absolutePosition).didScroll)
2212 wheelEvent->setDefaultHandled(); 2215 wheelEvent->setDefaultHandled();
2213 2216
2214 if (!m_latchedWheelEventNode) 2217 if (!m_latchedWheelEventNode)
2215 m_previousWheelScrolledNode = stopNode; 2218 m_previousWheelScrolledNode = stopNode;
2216 } 2219 }
2217 2220
2218 bool EventHandler::handleGestureShowPress() 2221 bool EventHandler::handleGestureShowPress()
2219 { 2222 {
2220 m_lastShowPressTimestamp = WTF::currentTime(); 2223 m_lastShowPressTimestamp = WTF::currentTime();
2221 2224
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
2702 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement(); 2705 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement();
2703 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence(); 2706 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence();
2704 scrolled = scrollState->deltaX() != gestureEvent.deltaX() 2707 scrolled = scrollState->deltaX() != gestureEvent.deltaX()
2705 || scrollState->deltaY() != gestureEvent.deltaY(); 2708 || scrollState->deltaY() != gestureEvent.deltaY();
2706 } else { 2709 } else {
2707 if (gestureEvent.preventPropagation()) 2710 if (gestureEvent.preventPropagation())
2708 stopNode = m_previousGestureScrolledNode.get(); 2711 stopNode = m_previousGestureScrolledNode.get();
2709 2712
2710 // First try to scroll the closest scrollable LayoutBox ancestor of |node|. 2713 // First try to scroll the closest scrollable LayoutBox ancestor of |node|.
2711 ScrollGranularity granularity = ScrollByPrecisePixel; 2714 ScrollGranularity granularity = ScrollByPrecisePixel;
2712 bool horizontalScroll = scroll(ScrollLeftIgnoringWritingMode, granul arity, node, &stopNode, delta.width()); 2715 m_unusedDelta = FloatSize();
2716 ScrollResultOneDimensional result = scroll(ScrollLeftIgnoringWriting Mode, granularity, node, &stopNode, delta.width());
2717 bool horizontalScroll = result.didScroll;
2713 if (!gestureEvent.preventPropagation()) 2718 if (!gestureEvent.preventPropagation())
2714 stopNode = nullptr; 2719 stopNode = nullptr;
2715 bool verticalScroll = scroll(ScrollUpIgnoringWritingMode, granularit y, node, &stopNode, delta.height()); 2720 result = scroll(ScrollUpIgnoringWritingMode, granularity, node, &sto pNode, delta.height());
2721 bool verticalScroll = result.didScroll;
2716 scrolled = horizontalScroll || verticalScroll; 2722 scrolled = horizontalScroll || verticalScroll;
2717 2723
2718 if (gestureEvent.preventPropagation()) 2724 if (gestureEvent.preventPropagation())
2719 m_previousGestureScrolledNode = stopNode; 2725 m_previousGestureScrolledNode = stopNode;
2726
2727 if (horizontalScroll) {
2728 m_accumulatedRootOverscroll.setWidth(0);
2729 m_unusedDelta.setWidth(0);
2730 }
2731 if (verticalScroll) {
2732 m_accumulatedRootOverscroll.setHeight(0);
2733 m_unusedDelta.setHeight(0);
2734 }
2720 } 2735 }
2721 if (scrolled) { 2736 if (scrolled) {
2722 setFrameWasScrolledByUser(); 2737 setFrameWasScrolledByUser();
2723 return true; 2738 return true;
2724 } 2739 }
2725 } 2740 }
2726 2741
2727 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) 2742 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2728 return false; 2743 return false;
2729 2744
2730 // Try to scroll the frame view. 2745 // Try to scroll the frame view.
2731 if (m_frame->applyScrollDelta(delta, false)) { 2746 ScrollResult resultScrollDelta = m_frame->applyScrollDelta(delta, false);
majidvp 2015/05/29 19:14:19 s/resultScrollDelta/scrollResult/
majidvp 2015/05/29 19:14:19 I think you need to have the rest logic for oversc
MuVen 2015/06/01 13:29:26 Done.
2747 m_unusedDelta.setWidth(resultScrollDelta.unusedScrollDeltaX);
2748 m_unusedDelta.setHeight(resultScrollDelta.unusedScrollDeltaY);
2749 if (m_frame->isMainFrame() && m_unusedDelta != FloatSize()) {
2750 m_accumulatedRootOverscroll += m_unusedDelta;
2751 FloatPoint position = FloatPoint(gestureEvent.position().x(), gestureEve nt.position().y());
2752 FloatSize velocity = FloatSize(gestureEvent.velocityX(), gestureEvent.ve locityY());
2753 m_frame->chromeClient().didOverscroll(m_unusedDelta, m_accumulatedRootOv erscroll, position, velocity);
2754 }
2755
2756 if (resultScrollDelta.didScroll) {
2732 setFrameWasScrolledByUser(); 2757 setFrameWasScrolledByUser();
2733 return true; 2758 return true;
2734 } 2759 }
2735 2760
2736 return false; 2761 return false;
2737 } 2762 }
2738 2763
2739 void EventHandler::clearGestureScrollNodes() 2764 void EventHandler::clearGestureScrollNodes()
2740 { 2765 {
2741 m_scrollGestureHandlingNode = nullptr; 2766 m_scrollGestureHandlingNode = nullptr;
2742 m_previousGestureScrolledNode = nullptr; 2767 m_previousGestureScrolledNode = nullptr;
2743 m_deltaConsumedForScrollSequence = false; 2768 m_deltaConsumedForScrollSequence = false;
2744 m_currentScrollChain.clear(); 2769 m_currentScrollChain.clear();
2770 m_accumulatedRootOverscroll = FloatSize();
2771 m_unusedDelta = FloatSize();
2745 } 2772 }
2746 2773
2747 bool EventHandler::isScrollbarHandlingGestures() const 2774 bool EventHandler::isScrollbarHandlingGestures() const
2748 { 2775 {
2749 return m_scrollbarHandlingScrollGesture.get(); 2776 return m_scrollbarHandlingScrollGesture.get();
2750 } 2777 }
2751 2778
2752 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const 2779 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const
2753 { 2780 {
2754 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled()) 2781 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled())
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
3637 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event) 3664 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event)
3638 { 3665 {
3639 ASSERT(event->type() == EventTypeNames::keypress); 3666 ASSERT(event->type() == EventTypeNames::keypress);
3640 3667
3641 if (event->ctrlKey() || event->metaKey() || event->altKey()) 3668 if (event->ctrlKey() || event->metaKey() || event->altKey())
3642 return; 3669 return;
3643 3670
3644 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward; 3671 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward;
3645 3672
3646 // FIXME: enable scroll customization in this case. See crbug.com/410974. 3673 // FIXME: enable scroll customization in this case. See crbug.com/410974.
3647 if (scroll(direction, ScrollByPage)) { 3674 if (scroll(direction, ScrollByPage).didScroll) {
3648 event->setDefaultHandled(); 3675 event->setDefaultHandled();
3649 return; 3676 return;
3650 } 3677 }
3651 3678
3652 FrameView* view = m_frame->view(); 3679 FrameView* view = m_frame->view();
3653 if (!view) 3680 if (!view)
3654 return; 3681 return;
3655 3682
3656 ScrollDirectionPhysical physicalDirection = 3683 ScrollDirectionPhysical physicalDirection =
3657 toPhysicalDirection(direction, view->isVerticalDocument(), view->isFlipp edDocument()); 3684 toPhysicalDirection(direction, view->isVerticalDocument(), view->isFlipp edDocument());
3658 3685
3659 if (view->scrollableArea()->scroll(physicalDirection, ScrollByPage)) 3686 if (view->scrollableArea()->scroll(physicalDirection, ScrollByPage).didScrol l)
3660 event->setDefaultHandled(); 3687 event->setDefaultHandled();
3661 } 3688 }
3662 3689
3663 void EventHandler::defaultBackspaceEventHandler(KeyboardEvent* event) 3690 void EventHandler::defaultBackspaceEventHandler(KeyboardEvent* event)
3664 { 3691 {
3665 ASSERT(event->type() == EventTypeNames::keydown); 3692 ASSERT(event->type() == EventTypeNames::keydown);
3666 3693
3667 if (event->ctrlKey() || event->metaKey() || event->altKey()) 3694 if (event->ctrlKey() || event->metaKey() || event->altKey())
3668 return; 3695 return;
3669 3696
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
4172 unsigned EventHandler::accessKeyModifiers() 4199 unsigned EventHandler::accessKeyModifiers()
4173 { 4200 {
4174 #if OS(MACOSX) 4201 #if OS(MACOSX)
4175 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 4202 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
4176 #else 4203 #else
4177 return PlatformEvent::AltKey; 4204 return PlatformEvent::AltKey;
4178 #endif 4205 #endif
4179 } 4206 }
4180 4207
4181 } // namespace blink 4208 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698