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

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: modified logic/tests Created 5 years, 7 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);
majidvp 2015/05/14 21:08:39 Shouldn't this return the delta?
MuVen 2015/05/26 09:58:35 Done.
942 944
943 LayoutBox* curBox = node->layoutObject()->enclosingBox(); 945 LayoutBox* curBox = node->layoutObject()->enclosingBox();
946 ScrollResultOneDimensional result(false);
944 while (curBox && !curBox->isLayoutView()) { 947 while (curBox && !curBox->isLayoutView()) {
945 ScrollDirection physicalDirection = toPhysicalDirection( 948 ScrollDirection physicalDirection = toPhysicalDirection(
946 direction, curBox->isHorizontalWritingMode(), curBox->style()->isFli ppedBlocksWritingMode()); 949 direction, curBox->isHorizontalWritingMode(), curBox->style()->isFli ppedBlocksWritingMode());
947 950
948 // If we're at the stopNode, we should try to scroll it but we shouldn't bubble past it 951 // 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; 952 bool shouldStopBubbling = stopNode && *stopNode && curBox->node() == *st opNode;
950 bool didScroll = curBox->scroll(physicalDirection, granularity, delta); 953 result = curBox->scroll(physicalDirection, granularity, delta);
951 954
952 if (didScroll && stopNode) 955 if (result.didScroll && stopNode)
953 *stopNode = curBox->node(); 956 *stopNode = curBox->node();
954 957
955 if (didScroll || shouldStopBubbling) { 958 if (result.didScroll || shouldStopBubbling) {
956 setFrameWasScrolledByUser(); 959 setFrameWasScrolledByUser();
957 return true; 960 if (!result.didScroll)
majidvp 2015/05/14 21:08:39 The if statement is redundant.
MuVen 2015/05/26 09:58:35 Done.
961 result.didScroll = true;
962 return result;
958 } 963 }
959 964
960 curBox = curBox->containingBlock(); 965 curBox = curBox->containingBlock();
961 } 966 }
962 967
963 return false; 968 return result;
majidvp 2015/05/14 21:08:39 Again, I feel this should return {false, delta} in
MuVen 2015/05/26 09:58:35 Done.
964 } 969 }
965 970
966 void EventHandler::customizedScroll(const Node& startNode, ScrollState& scrollSt ate) 971 void EventHandler::customizedScroll(const Node& startNode, ScrollState& scrollSt ate)
967 { 972 {
968 if (scrollState.fullyConsumed()) 973 if (scrollState.fullyConsumed())
969 return; 974 return;
970 975
971 if (m_currentScrollChain.isEmpty()) 976 if (m_currentScrollChain.isEmpty())
972 recomputeScrollChain(*m_frame, startNode, m_currentScrollChain); 977 recomputeScrollChain(*m_frame, startNode, m_currentScrollChain);
973 scrollState.setScrollChain(m_currentScrollChain); 978 scrollState.setScrollChain(m_currentScrollChain);
974 scrollState.distributeToScrollChainDescendant(); 979 scrollState.distributeToScrollChainDescendant();
975 } 980 }
976 981
977 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode) 982 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode)
978 { 983 {
979 // The layout needs to be up to date to determine if we can scroll. We may b e 984 // 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. 985 // here because of an onLoad event, in which case the final layout hasn't be en performed yet.
981 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 986 m_frame->document()->updateLayoutIgnorePendingStylesheets();
982 // FIXME: enable scroll customization in this case. See crbug.com/410974. 987 // FIXME: enable scroll customization in this case. See crbug.com/410974.
983 if (scroll(direction, granularity, startingNode)) 988 if (scroll(direction, granularity, startingNode).didScroll)
984 return true; 989 return true;
985 LocalFrame* frame = m_frame; 990 LocalFrame* frame = m_frame;
986 FrameView* view = frame->view(); 991 FrameView* view = frame->view();
987 if (view && view->scroll(direction, granularity)) { 992 if (view && view->scroll(direction, granularity).didScroll) {
988 setFrameWasScrolledByUser(); 993 setFrameWasScrolledByUser();
989 return true; 994 return true;
990 } 995 }
991 Frame* parentFrame = frame->tree().parent(); 996 Frame* parentFrame = frame->tree().parent();
992 if (!parentFrame || !parentFrame->isLocalFrame()) 997 if (!parentFrame || !parentFrame->isLocalFrame())
993 return false; 998 return false;
994 // FIXME: Broken for OOPI. 999 // FIXME: Broken for OOPI.
995 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g ranularity, m_frame->deprecatedLocalOwner()); 1000 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g ranularity, m_frame->deprecatedLocalOwner());
996 } 1001 }
997 1002
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 2198
2194 Node* stopNode = m_previousWheelScrolledNode.get(); 2199 Node* stopNode = m_previousWheelScrolledNode.get();
2195 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt); 2200 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt);
2196 IntPoint absolutePosition = roundedIntPoint(wheelEvent->absoluteLocation()); 2201 IntPoint absolutePosition = roundedIntPoint(wheelEvent->absoluteLocation());
2197 2202
2198 // Break up into two scrolls if we need to. Diagonal movement on 2203 // Break up into two scrolls if we need to. Diagonal movement on
2199 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set). 2204 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set).
2200 2205
2201 // FIXME: enable scroll customization in this case. See crbug.com/410974. 2206 // FIXME: enable scroll customization in this case. See crbug.com/410974.
2202 if (wheelEvent->railsMode() != Event::RailsModeVertical 2207 if (wheelEvent->railsMode() != Event::RailsModeVertical
2203 && scroll(ScrollRight, granularity, startNode, &stopNode, wheelEvent->de ltaX(), absolutePosition)) 2208 && scroll(ScrollRight, granularity, startNode, &stopNode, wheelEvent->de ltaX(), absolutePosition).didScroll)
2204 wheelEvent->setDefaultHandled(); 2209 wheelEvent->setDefaultHandled();
2205 2210
2206 if (wheelEvent->railsMode() != Event::RailsModeHorizontal 2211 if (wheelEvent->railsMode() != Event::RailsModeHorizontal
2207 && scroll(ScrollDown, granularity, startNode, &stopNode, wheelEvent->del taY(), absolutePosition)) 2212 && scroll(ScrollDown, granularity, startNode, &stopNode, wheelEvent->del taY(), absolutePosition).didScroll)
2208 wheelEvent->setDefaultHandled(); 2213 wheelEvent->setDefaultHandled();
2209 2214
2210 if (!m_latchedWheelEventNode) 2215 if (!m_latchedWheelEventNode)
2211 m_previousWheelScrolledNode = stopNode; 2216 m_previousWheelScrolledNode = stopNode;
2212 } 2217 }
2213 2218
2214 bool EventHandler::handleGestureShowPress() 2219 bool EventHandler::handleGestureShowPress()
2215 { 2220 {
2216 m_lastShowPressTimestamp = WTF::currentTime(); 2221 m_lastShowPressTimestamp = WTF::currentTime();
2217 2222
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement(); 2703 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement();
2699 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence(); 2704 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence();
2700 scrolled = scrollState->deltaX() != gestureEvent.deltaX() 2705 scrolled = scrollState->deltaX() != gestureEvent.deltaX()
2701 || scrollState->deltaY() != gestureEvent.deltaY(); 2706 || scrollState->deltaY() != gestureEvent.deltaY();
2702 } else { 2707 } else {
2703 if (gestureEvent.preventPropagation()) 2708 if (gestureEvent.preventPropagation())
2704 stopNode = m_previousGestureScrolledNode.get(); 2709 stopNode = m_previousGestureScrolledNode.get();
2705 2710
2706 // First try to scroll the closest scrollable LayoutBox ancestor of |node|. 2711 // First try to scroll the closest scrollable LayoutBox ancestor of |node|.
2707 ScrollGranularity granularity = ScrollByPrecisePixel; 2712 ScrollGranularity granularity = ScrollByPrecisePixel;
2708 bool horizontalScroll = scroll(ScrollLeft, granularity, node, &stopN ode, delta.width()); 2713 m_unusedDelta = FloatSize();
2714 ScrollResultOneDimensional result = scroll(ScrollLeft, granularity, node, &stopNode, delta.width());
2715 bool horizontalScroll = result.didScroll;
2709 if (!gestureEvent.preventPropagation()) 2716 if (!gestureEvent.preventPropagation())
2710 stopNode = nullptr; 2717 stopNode = nullptr;
2711 bool verticalScroll = scroll(ScrollUp, granularity, node, &stopNode, delta.height()); 2718 result = scroll(ScrollUp, granularity, node, &stopNode, delta.height ());
2719 bool verticalScroll = result.didScroll;
2712 scrolled = horizontalScroll || verticalScroll; 2720 scrolled = horizontalScroll || verticalScroll;
2713 2721
2714 if (gestureEvent.preventPropagation()) 2722 if (gestureEvent.preventPropagation())
2715 m_previousGestureScrolledNode = stopNode; 2723 m_previousGestureScrolledNode = stopNode;
2724
2725 if (horizontalScroll) {
2726 m_accumulatedRootOverscroll.setWidth(0);
2727 m_unusedDelta.setWidth(0);
2728 }
2729
2730 if (verticalScroll) {
2731 m_accumulatedRootOverscroll.setHeight(0);
2732 m_unusedDelta.setHeight(0);
2733 }
2716 } 2734 }
2717 if (scrolled) { 2735 if (scrolled) {
2718 setFrameWasScrolledByUser(); 2736 setFrameWasScrolledByUser();
2719 return true; 2737 return true;
2720 } 2738 }
2721 } 2739 }
2722 2740
2723 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) 2741 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2724 return false; 2742 return false;
2725 2743
2726 // Try to scroll the frame view. 2744 // Try to scroll the frame view.
2727 if (m_frame->applyScrollDelta(delta, false)) { 2745 ScrollResult resultScrollDelta = m_frame->applyScrollDelta(delta, false);
2746 m_unusedDelta.setWidth(resultScrollDelta.unusedScrollDeltaX);
MuVen 2015/05/14 12:34:21 modified the previous logic, m_unusedDelta.setWi
2747 m_unusedDelta.setHeight(resultScrollDelta.unusedScrollDeltaY);
2748 if (m_frame->isMainFrame() && m_unusedDelta != FloatSize()) {
2749 m_accumulatedRootOverscroll += m_unusedDelta;
2750 FloatPoint position = FloatPoint(gestureEvent.position().x(), gestureEve nt.position().y());
2751 FloatSize velocity = FloatSize(gestureEvent.velocityX(), gestureEvent.ve locityY());
2752 m_frame->chromeClient().didOverscroll(m_unusedDelta, m_accumulatedRootOv erscroll, position, velocity);
2753 }
2754
2755 if (resultScrollDelta.didScroll) {
2728 setFrameWasScrolledByUser(); 2756 setFrameWasScrolledByUser();
2729 return true; 2757 return true;
2730 } 2758 }
2731 2759
2732 return false; 2760 return false;
2733 } 2761 }
2734 2762
2735 void EventHandler::clearGestureScrollNodes() 2763 void EventHandler::clearGestureScrollNodes()
2736 { 2764 {
2737 m_scrollGestureHandlingNode = nullptr; 2765 m_scrollGestureHandlingNode = nullptr;
2738 m_previousGestureScrolledNode = nullptr; 2766 m_previousGestureScrolledNode = nullptr;
2739 m_deltaConsumedForScrollSequence = false; 2767 m_deltaConsumedForScrollSequence = false;
2740 m_currentScrollChain.clear(); 2768 m_currentScrollChain.clear();
2769 m_accumulatedRootOverscroll = FloatSize();
2770 m_unusedDelta = FloatSize();
2741 } 2771 }
2742 2772
2743 bool EventHandler::isScrollbarHandlingGestures() const 2773 bool EventHandler::isScrollbarHandlingGestures() const
2744 { 2774 {
2745 return m_scrollbarHandlingScrollGesture.get(); 2775 return m_scrollbarHandlingScrollGesture.get();
2746 } 2776 }
2747 2777
2748 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const 2778 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const
2749 { 2779 {
2750 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled()) 2780 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled())
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
3632 3662
3633 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event) 3663 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event)
3634 { 3664 {
3635 ASSERT(event->type() == EventTypeNames::keypress); 3665 ASSERT(event->type() == EventTypeNames::keypress);
3636 3666
3637 if (event->ctrlKey() || event->metaKey() || event->altKey()) 3667 if (event->ctrlKey() || event->metaKey() || event->altKey())
3638 return; 3668 return;
3639 3669
3640 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward; 3670 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward;
3641 // FIXME: enable scroll customization in this case. See crbug.com/410974. 3671 // FIXME: enable scroll customization in this case. See crbug.com/410974.
3642 if (scroll(direction, ScrollByPage)) { 3672 if (scroll(direction, ScrollByPage).didScroll) {
3643 event->setDefaultHandled(); 3673 event->setDefaultHandled();
3644 return; 3674 return;
3645 } 3675 }
3646 3676
3647 FrameView* view = m_frame->view(); 3677 FrameView* view = m_frame->view();
3648 if (!view) 3678 if (!view)
3649 return; 3679 return;
3650 3680
3651 if (view->scroll(direction, ScrollByPage)) 3681 if (view->scroll(direction, ScrollByPage).didScroll)
3652 event->setDefaultHandled(); 3682 event->setDefaultHandled();
3653 } 3683 }
3654 3684
3655 void EventHandler::defaultBackspaceEventHandler(KeyboardEvent* event) 3685 void EventHandler::defaultBackspaceEventHandler(KeyboardEvent* event)
3656 { 3686 {
3657 ASSERT(event->type() == EventTypeNames::keydown); 3687 ASSERT(event->type() == EventTypeNames::keydown);
3658 3688
3659 if (event->ctrlKey() || event->metaKey() || event->altKey()) 3689 if (event->ctrlKey() || event->metaKey() || event->altKey())
3660 return; 3690 return;
3661 3691
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
4164 unsigned EventHandler::accessKeyModifiers() 4194 unsigned EventHandler::accessKeyModifiers()
4165 { 4195 {
4166 #if OS(MACOSX) 4196 #if OS(MACOSX)
4167 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 4197 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
4168 #else 4198 #else
4169 return PlatformEvent::AltKey; 4199 return PlatformEvent::AltKey;
4170 #endif 4200 #endif
4171 } 4201 }
4172 4202
4173 } // namespace blink 4203 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698