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

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, 8 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 m_nodeUnderMouse = nullptr; 292 m_nodeUnderMouse = nullptr;
293 m_lastNodeUnderMouse = nullptr; 293 m_lastNodeUnderMouse = nullptr;
294 m_lastMouseMoveEventSubframe = nullptr; 294 m_lastMouseMoveEventSubframe = nullptr;
295 m_lastScrollbarUnderMouse = nullptr; 295 m_lastScrollbarUnderMouse = nullptr;
296 m_clickCount = 0; 296 m_clickCount = 0;
297 m_clickNode = nullptr; 297 m_clickNode = nullptr;
298 m_frameSetBeingResized = nullptr; 298 m_frameSetBeingResized = nullptr;
299 m_dragTarget = nullptr; 299 m_dragTarget = nullptr;
300 m_shouldOnlyFireDragOverEvent = false; 300 m_shouldOnlyFireDragOverEvent = false;
301 m_mousePositionIsUnknown = true; 301 m_mousePositionIsUnknown = true;
302 m_unusedDelta = IntPoint();
303 m_accumulatedRootOverscroll = IntPoint();
302 m_lastKnownMousePosition = IntPoint(); 304 m_lastKnownMousePosition = IntPoint();
303 m_lastKnownMouseGlobalPosition = IntPoint(); 305 m_lastKnownMouseGlobalPosition = IntPoint();
304 m_lastMouseDownUserGestureToken.clear(); 306 m_lastMouseDownUserGestureToken.clear();
305 m_mousePressNode = nullptr; 307 m_mousePressNode = nullptr;
306 m_mousePressed = false; 308 m_mousePressed = false;
307 m_capturesDragging = false; 309 m_capturesDragging = false;
308 m_capturingMouseEventsNode = nullptr; 310 m_capturingMouseEventsNode = nullptr;
309 m_latchedWheelEventNode = nullptr; 311 m_latchedWheelEventNode = nullptr;
310 m_previousWheelScrolledNode = nullptr; 312 m_previousWheelScrolledNode = nullptr;
311 m_targetForTouchID.clear(); 313 m_targetForTouchID.clear();
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 921
920 return result; 922 return result;
921 } 923 }
922 924
923 void EventHandler::stopAutoscroll() 925 void EventHandler::stopAutoscroll()
924 { 926 {
925 if (AutoscrollController* controller = autoscrollController()) 927 if (AutoscrollController* controller = autoscrollController())
926 controller->stopAutoscroll(); 928 controller->stopAutoscroll();
927 } 929 }
928 930
929 bool EventHandler::scroll(ScrollDirection direction, ScrollGranularity granulari ty, Node* startNode, Node** stopNode, float delta, IntPoint absolutePoint) 931 bool EventHandler::scroll(ScrollDirection direction, ScrollGranularity granulari ty, Node* startNode, Node** stopNode, float delta, IntPoint absolutePoint, int* unusedDelta)
930 { 932 {
931 if (!delta) 933 if (!delta)
932 return false; 934 return false;
933 935
934 Node* node = startNode; 936 Node* node = startNode;
935 937
936 if (!node) 938 if (!node)
937 node = m_frame->document()->focusedElement(); 939 node = m_frame->document()->focusedElement();
938 940
939 if (!node) 941 if (!node)
940 node = m_mousePressNode.get(); 942 node = m_mousePressNode.get();
941 943
942 if (!node || !node->layoutObject()) 944 if (!node || !node->layoutObject())
943 return false; 945 return false;
944 946
945 bool rootLayerScrolls = m_frame->settings() && m_frame->settings()->rootLaye rScrolls(); 947 bool rootLayerScrolls = m_frame->settings() && m_frame->settings()->rootLaye rScrolls();
946 LayoutBox* curBox = node->layoutObject()->enclosingBox(); 948 LayoutBox* curBox = node->layoutObject()->enclosingBox();
947 while (curBox && (rootLayerScrolls || !curBox->isLayoutView())) { 949 while (curBox && (rootLayerScrolls || !curBox->isLayoutView())) {
948 ScrollDirection physicalDirection = toPhysicalDirection( 950 ScrollDirection physicalDirection = toPhysicalDirection(
949 direction, curBox->isHorizontalWritingMode(), curBox->style()->isFli ppedBlocksWritingMode()); 951 direction, curBox->isHorizontalWritingMode(), curBox->style()->isFli ppedBlocksWritingMode());
950 952
951 // If we're at the stopNode, we should try to scroll it but we shouldn't bubble past it 953 // If we're at the stopNode, we should try to scroll it but we shouldn't bubble past it
952 bool shouldStopBubbling = stopNode && *stopNode && curBox->node() == *st opNode; 954 bool shouldStopBubbling = stopNode && *stopNode && curBox->node() == *st opNode;
953 bool didScroll = curBox->scroll(physicalDirection, granularity, delta); 955 bool didScroll = curBox->scroll(physicalDirection, granularity, delta);
956 IntPoint cbUnusedDelta = curBox->unUsedDelta();
957 if (direction == ScrollUp)
958 *unusedDelta = cbUnusedDelta.y();
959 else if (direction == ScrollLeft)
960 *unusedDelta = cbUnusedDelta.x();
majidvp 2015/04/23 18:25:08 Overscroll should happen only if the document's ma
MuVen 2015/04/27 12:53:46 if (m_frame->isMainFrame()) condition will accumul
954 961
955 if (didScroll && stopNode) 962 if (didScroll && stopNode)
956 *stopNode = curBox->node(); 963 *stopNode = curBox->node();
957 964
958 if (didScroll || shouldStopBubbling) { 965 if (didScroll || shouldStopBubbling) {
959 setFrameWasScrolledByUser(); 966 setFrameWasScrolledByUser();
960 return true; 967 return true;
961 } 968 }
962 969
963 curBox = curBox->containingBlock(); 970 curBox = curBox->containingBlock();
(...skipping 25 matching lines...) Expand all
989 FrameView* view = frame->view(); 996 FrameView* view = frame->view();
990 if (view && view->scroll(direction, granularity)) 997 if (view && view->scroll(direction, granularity))
991 return true; 998 return true;
992 Frame* parentFrame = frame->tree().parent(); 999 Frame* parentFrame = frame->tree().parent();
993 if (!parentFrame || !parentFrame->isLocalFrame()) 1000 if (!parentFrame || !parentFrame->isLocalFrame())
994 return false; 1001 return false;
995 // FIXME: Broken for OOPI. 1002 // FIXME: Broken for OOPI.
996 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g ranularity, m_frame->deprecatedLocalOwner()); 1003 return toLocalFrame(parentFrame)->eventHandler().bubblingScroll(direction, g ranularity, m_frame->deprecatedLocalOwner());
997 } 1004 }
998 1005
1006 IntPoint EventHandler::unusedDelta() const
1007 {
1008 return m_unusedDelta;
1009 }
1010
1011 IntPoint EventHandler::accumaltedRootOverScroll() const
1012 {
1013 return m_accumulatedRootOverscroll;
1014 }
1015
1016 void EventHandler::resetOverScrollParams()
1017 {
1018 m_unusedDelta = m_accumulatedRootOverscroll = IntPoint();
majidvp 2015/04/23 18:25:08 Scroll deltas should use |FloatSize| and not |IntP
MuVen 2015/04/27 12:53:46 Done.
1019 }
1020
999 IntPoint EventHandler::lastKnownMousePosition() const 1021 IntPoint EventHandler::lastKnownMousePosition() const
1000 { 1022 {
1001 return m_lastKnownMousePosition; 1023 return m_lastKnownMousePosition;
1002 } 1024 }
1003 1025
1004 static LocalFrame* subframeForTargetNode(Node* node) 1026 static LocalFrame* subframeForTargetNode(Node* node)
1005 { 1027 {
1006 if (!node) 1028 if (!node)
1007 return nullptr; 1029 return nullptr;
1008 1030
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 return true; 2381 return true;
2360 } 2382 }
2361 2383
2362 if (eventTarget) { 2384 if (eventTarget) {
2363 bool eventSwallowed = handleScrollGestureOnResizer(eventTarget.get(), ge stureEvent); 2385 bool eventSwallowed = handleScrollGestureOnResizer(eventTarget.get(), ge stureEvent);
2364 if (!eventSwallowed) 2386 if (!eventSwallowed)
2365 eventSwallowed = eventTarget->dispatchGestureEvent(gestureEvent); 2387 eventSwallowed = eventTarget->dispatchGestureEvent(gestureEvent);
2366 if (eventSwallowed) 2388 if (eventSwallowed)
2367 return true; 2389 return true;
2368 } 2390 }
2369
2370 switch (gestureEvent.type()) { 2391 switch (gestureEvent.type()) {
2371 case PlatformEvent::GestureScrollBegin: 2392 case PlatformEvent::GestureScrollBegin:
2372 return handleGestureScrollBegin(gestureEvent); 2393 return handleGestureScrollBegin(gestureEvent);
2373 case PlatformEvent::GestureScrollUpdate: 2394 case PlatformEvent::GestureScrollUpdate:
2374 return handleGestureScrollUpdate(gestureEvent); 2395 return handleGestureScrollUpdate(gestureEvent);
2375 case PlatformEvent::GestureScrollEnd: 2396 case PlatformEvent::GestureScrollEnd:
2376 return handleGestureScrollEnd(gestureEvent); 2397 return handleGestureScrollEnd(gestureEvent);
2377 case PlatformEvent::GestureFlingStart: 2398 case PlatformEvent::GestureFlingStart:
2378 case PlatformEvent::GesturePinchBegin: 2399 case PlatformEvent::GesturePinchBegin:
2379 case PlatformEvent::GesturePinchEnd: 2400 case PlatformEvent::GesturePinchEnd:
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 passScrollGestureEventToWidget(gestureEvent, node->layoutObject()); 2625 passScrollGestureEventToWidget(gestureEvent, node->layoutObject());
2605 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) { 2626 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2606 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create( 2627 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2607 0, 0, 0, 0, 0, gestureEvent.inertial(), /* isBeginning */ 2628 0, 0, 0, 0, 0, gestureEvent.inertial(), /* isBeginning */
2608 false, /* isEnding */ true, /* fromUserInput */ true); 2629 false, /* isEnding */ true, /* fromUserInput */ true);
2609 customizedScroll(*node.get(), *scrollState); 2630 customizedScroll(*node.get(), *scrollState);
2610 } 2631 }
2611 } 2632 }
2612 2633
2613 clearGestureScrollNodes(); 2634 clearGestureScrollNodes();
2635 resetOverScrollParams();
2614 return false; 2636 return false;
2615 } 2637 }
2616 2638
2617 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE vent) 2639 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE vent)
2618 { 2640 {
2619 Document* document = m_frame->document(); 2641 Document* document = m_frame->document();
2620 if (!document->layoutView()) 2642 if (!document->layoutView())
2621 return false; 2643 return false;
2622 2644
2623 FrameView* view = m_frame->view(); 2645 FrameView* view = m_frame->view();
2624 if (!view) 2646 if (!view)
2625 return false; 2647 return false;
2626 2648
2627 // If there's no renderer on the node, send the event to the nearest ancesto r with a renderer. 2649 // If there's no renderer on the node, send the event to the nearest ancesto r with a renderer.
2628 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s 2650 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s
2629 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb ject()) 2651 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb ject())
2630 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode(); 2652 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode();
2631 2653
2632 if (!m_scrollGestureHandlingNode) { 2654 if (!m_scrollGestureHandlingNode) {
2633 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) 2655 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2634 m_scrollGestureHandlingNode = m_frame->document()->documentElement() ; 2656 m_scrollGestureHandlingNode = m_frame->document()->documentElement() ;
2635 else 2657 else
2636 return false; 2658 return false;
2637 } 2659 }
2638 ASSERT(m_scrollGestureHandlingNode); 2660 ASSERT(m_scrollGestureHandlingNode);
2639
2640 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la youtObject()); 2661 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la youtObject());
2641 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) { 2662 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2642 m_currentScrollChain.clear(); 2663 m_currentScrollChain.clear();
2643 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create( 2664 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2644 0, 0, 0, 0, 0, /* inInertialPhase */ false, /* isBeginning */ 2665 0, 0, 0, 0, 0, /* inInertialPhase */ false, /* isBeginning */
2645 true, /* isEnding */ false, /* fromUserInput */ true); 2666 true, /* isEnding */ false, /* fromUserInput */ true);
2646 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState); 2667 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState);
2647 } else { 2668 } else {
2648 if (m_frame->isMainFrame()) 2669 if (m_frame->isMainFrame())
2649 m_frame->host()->topControls().scrollBegin(); 2670 m_frame->host()->topControls().scrollBegin();
2650 } 2671 }
2672
2673 resetOverScrollParams();
2651 return true; 2674 return true;
2652 } 2675 }
2653 2676
2654 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture Event) 2677 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture Event)
2655 { 2678 {
2656 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate); 2679 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate);
2657 2680
2658 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY()); 2681 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY());
2659 if (delta.isZero()) 2682 if (delta.isZero())
2660 return false; 2683 return false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2695 // The ScrollState needs to know what the current 2718 // The ScrollState needs to know what the current
2696 // native scrolling element is, so that for an 2719 // native scrolling element is, so that for an
2697 // inertial scroll that shouldn't propagate, only the 2720 // inertial scroll that shouldn't propagate, only the
2698 // currently scrolling element responds. 2721 // currently scrolling element responds.
2699 ASSERT(m_previousGestureScrolledNode->isElementNode()); 2722 ASSERT(m_previousGestureScrolledNode->isElementNode());
2700 scrollState->setCurrentNativeScrollingElement(toElement(m_previo usGestureScrolledNode.get())); 2723 scrollState->setCurrentNativeScrollingElement(toElement(m_previo usGestureScrolledNode.get()));
2701 } 2724 }
2702 customizedScroll(*node, *scrollState); 2725 customizedScroll(*node, *scrollState);
2703 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement(); 2726 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement();
2704 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence(); 2727 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence();
2705 scrolled = scrollState->deltaX() != gestureEvent.deltaX() 2728 scrolled = scrollState->deltaX() != gestureEvent.deltaX()
majidvp 2015/04/23 18:25:09 We should also handle the case where scroll custom
majidvp 2015/04/23 18:59:02 Muven, I think you can ignore the Scroll customiza
MuVen 2015/04/27 12:53:46 Done.
2706 || scrollState->deltaY() != gestureEvent.deltaY(); 2729 || scrollState->deltaY() != gestureEvent.deltaY();
2707 } else { 2730 } else {
2708 if (gestureEvent.preventPropagation()) 2731 if (gestureEvent.preventPropagation())
2709 stopNode = m_previousGestureScrolledNode.get(); 2732 stopNode = m_previousGestureScrolledNode.get();
2710 2733
2711 // First try to scroll the closest scrollable LayoutBox ancestor of |node|. 2734 // First try to scroll the closest scrollable LayoutBox ancestor of |node|.
2735 int uDelta;
2736 m_unusedDelta = IntPoint();
2712 ScrollGranularity granularity = ScrollByPrecisePixel; 2737 ScrollGranularity granularity = ScrollByPrecisePixel;
2713 bool horizontalScroll = scroll(ScrollLeft, granularity, node, &stopN ode, delta.width()); 2738 bool horizontalScroll = scroll(ScrollLeft, granularity, node, &stopN ode, delta.width(), IntPoint(), &uDelta);
2739 m_unusedDelta.setX(uDelta);
2714 if (!gestureEvent.preventPropagation()) 2740 if (!gestureEvent.preventPropagation())
2715 stopNode = nullptr; 2741 stopNode = nullptr;
2716 bool verticalScroll = scroll(ScrollUp, granularity, node, &stopNode, delta.height()); 2742 bool verticalScroll = scroll(ScrollUp, granularity, node, &stopNode, delta.height(), IntPoint(), &uDelta);
2743 m_unusedDelta.setY(uDelta);
2717 scrolled = horizontalScroll || verticalScroll; 2744 scrolled = horizontalScroll || verticalScroll;
2718 2745 m_accumulatedRootOverscroll = m_accumulatedRootOverscroll + m_unused Delta;
2719 if (gestureEvent.preventPropagation()) 2746 if (gestureEvent.preventPropagation())
2720 m_previousGestureScrolledNode = stopNode; 2747 m_previousGestureScrolledNode = stopNode;
2721 } 2748 }
2722 if (scrolled) { 2749 if (scrolled) {
2723 setFrameWasScrolledByUser(); 2750 setFrameWasScrolledByUser();
2724 return true; 2751 return true;
2725 } 2752 }
2726 } 2753 }
2727 2754
2728 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) 2755 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2729 return false; 2756 return false;
2730 2757
2731 // Try to scroll the frame view. 2758 // Try to scroll the frame view.
2732 if (m_frame->applyScrollDelta(delta, false)) { 2759 if (m_frame->applyScrollDelta(delta, false)) {
majidvp 2015/04/23 18:25:08 It is also possible to scroll main frame's framevi
2733 setFrameWasScrolledByUser(); 2760 setFrameWasScrolledByUser();
2734 return true; 2761 return true;
2735 } 2762 }
2736 2763
2737 return false; 2764 return false;
2738 } 2765 }
2739 2766
2740 void EventHandler::clearGestureScrollNodes() 2767 void EventHandler::clearGestureScrollNodes()
2741 { 2768 {
2742 m_scrollGestureHandlingNode = nullptr; 2769 m_scrollGestureHandlingNode = nullptr;
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
4084 unsigned EventHandler::accessKeyModifiers() 4111 unsigned EventHandler::accessKeyModifiers()
4085 { 4112 {
4086 #if OS(MACOSX) 4113 #if OS(MACOSX)
4087 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 4114 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
4088 #else 4115 #else
4089 return PlatformEvent::AltKey; 4116 return PlatformEvent::AltKey;
4090 #endif 4117 #endif
4091 } 4118 }
4092 4119
4093 } // namespace blink 4120 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698