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

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

Issue 988823003: Use scroll customization primitives for touch scrolling (behind REF). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address rbyers' nit. Created 5 years, 9 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
« no previous file with comments | « Source/core/page/EventHandler.h ('k') | Source/core/page/scrolling/ScrollState.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "core/page/Chrome.h" 73 #include "core/page/Chrome.h"
74 #include "core/page/ChromeClient.h" 74 #include "core/page/ChromeClient.h"
75 #include "core/page/DragController.h" 75 #include "core/page/DragController.h"
76 #include "core/page/DragState.h" 76 #include "core/page/DragState.h"
77 #include "core/page/EditorClient.h" 77 #include "core/page/EditorClient.h"
78 #include "core/page/FocusController.h" 78 #include "core/page/FocusController.h"
79 #include "core/page/FrameTree.h" 79 #include "core/page/FrameTree.h"
80 #include "core/page/Page.h" 80 #include "core/page/Page.h"
81 #include "core/page/SpatialNavigation.h" 81 #include "core/page/SpatialNavigation.h"
82 #include "core/page/TouchAdjustment.h" 82 #include "core/page/TouchAdjustment.h"
83 #include "core/page/scrolling/ScrollState.h"
83 #include "core/paint/DeprecatedPaintLayer.h" 84 #include "core/paint/DeprecatedPaintLayer.h"
84 #include "core/svg/SVGDocumentExtensions.h" 85 #include "core/svg/SVGDocumentExtensions.h"
85 #include "platform/PlatformGestureEvent.h" 86 #include "platform/PlatformGestureEvent.h"
86 #include "platform/PlatformKeyboardEvent.h" 87 #include "platform/PlatformKeyboardEvent.h"
87 #include "platform/PlatformTouchEvent.h" 88 #include "platform/PlatformTouchEvent.h"
88 #include "platform/PlatformWheelEvent.h" 89 #include "platform/PlatformWheelEvent.h"
89 #include "platform/RuntimeEnabledFeatures.h" 90 #include "platform/RuntimeEnabledFeatures.h"
90 #include "platform/TraceEvent.h" 91 #include "platform/TraceEvent.h"
91 #include "platform/WindowsKeyboardCodes.h" 92 #include "platform/WindowsKeyboardCodes.h"
92 #include "platform/geometry/FloatPoint.h" 93 #include "platform/geometry/FloatPoint.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // we'd like to EventHandler::handleMousePressEvent to pass the event to the wid get and thus the 190 // we'd like to EventHandler::handleMousePressEvent to pass the event to the wid get and thus the
190 // event target node can't still be the shadow node. 191 // event target node can't still be the shadow node.
191 static inline bool shouldRefetchEventTarget(const MouseEventWithHitTestResults& mev) 192 static inline bool shouldRefetchEventTarget(const MouseEventWithHitTestResults& mev)
192 { 193 {
193 Node* targetNode = mev.innerNode(); 194 Node* targetNode = mev.innerNode();
194 if (!targetNode || !targetNode->parentNode()) 195 if (!targetNode || !targetNode->parentNode())
195 return true; 196 return true;
196 return targetNode->isShadowRoot() && isHTMLInputElement(*toShadowRoot(target Node)->host()); 197 return targetNode->isShadowRoot() && isHTMLInputElement(*toShadowRoot(target Node)->host());
197 } 198 }
198 199
200 void recomputeScrollChain(const LocalFrame& frame, const Node& startNode,
201 WillBeHeapDeque<RefPtrWillBeMember<Element>>& scrollChain)
202 {
203 scrollChain.clear();
204
205 ASSERT(startNode.layoutObject());
206 LayoutBox* curBox = startNode.layoutObject()->enclosingBox();
207
208 // Scrolling propagates along the containing block chain.
209 while (curBox && !curBox->isLayoutView()) {
210 Node* curNode = curBox->node();
211 // FIXME: this should reject more elements, as part of crbug.com/410974.
212 if (curNode && curNode->isElementNode())
213 scrollChain.prepend(toElement(curNode));
214 curBox = curBox->containingBlock();
215 }
216
217 // FIXME: we should exclude the document in some cases, as part
218 // of crbug.com/410974.
219 scrollChain.prepend(frame.document()->documentElement());
220 }
221
199 EventHandler::EventHandler(LocalFrame* frame) 222 EventHandler::EventHandler(LocalFrame* frame)
200 : m_frame(frame) 223 : m_frame(frame)
201 , m_mousePressed(false) 224 , m_mousePressed(false)
202 , m_capturesDragging(false) 225 , m_capturesDragging(false)
203 , m_mouseDownMayStartSelect(false) 226 , m_mouseDownMayStartSelect(false)
204 , m_mouseDownMayStartDrag(false) 227 , m_mouseDownMayStartDrag(false)
205 , m_mouseDownWasSingleClickInSelection(false) 228 , m_mouseDownWasSingleClickInSelection(false)
206 , m_selectionInitiationState(HaveNotStartedSelection) 229 , m_selectionInitiationState(HaveNotStartedSelection)
207 , m_hoverTimer(this, &EventHandler::hoverTimerFired) 230 , m_hoverTimer(this, &EventHandler::hoverTimerFired)
208 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired) 231 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
209 , m_mouseDownMayStartAutoscroll(false) 232 , m_mouseDownMayStartAutoscroll(false)
210 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d) 233 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d)
211 , m_svgPan(false) 234 , m_svgPan(false)
212 , m_resizeScrollableArea(nullptr) 235 , m_resizeScrollableArea(nullptr)
213 , m_eventHandlerWillResetCapturingMouseEventsNode(0) 236 , m_eventHandlerWillResetCapturingMouseEventsNode(0)
214 , m_clickCount(0) 237 , m_clickCount(0)
215 , m_shouldOnlyFireDragOverEvent(false) 238 , m_shouldOnlyFireDragOverEvent(false)
216 , m_mousePositionIsUnknown(true) 239 , m_mousePositionIsUnknown(true)
217 , m_mouseDownTimestamp(0) 240 , m_mouseDownTimestamp(0)
218 , m_widgetIsLatched(false) 241 , m_widgetIsLatched(false)
219 , m_touchPressed(false) 242 , m_touchPressed(false)
220 , m_scrollGestureHandlingNode(nullptr) 243 , m_scrollGestureHandlingNode(nullptr)
221 , m_lastGestureScrollOverWidget(false) 244 , m_lastGestureScrollOverWidget(false)
222 , m_maxMouseMovedDuration(0) 245 , m_maxMouseMovedDuration(0)
223 , m_longTapShouldInvokeContextMenu(false) 246 , m_longTapShouldInvokeContextMenu(false)
224 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 247 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
225 , m_lastShowPressTimestamp(0) 248 , m_lastShowPressTimestamp(0)
249 , m_deltaConsumedForScrollSequence(false)
226 { 250 {
227 } 251 }
228 252
229 EventHandler::~EventHandler() 253 EventHandler::~EventHandler()
230 { 254 {
231 ASSERT(!m_fakeMouseMoveEventTimer.isActive()); 255 ASSERT(!m_fakeMouseMoveEventTimer.isActive());
232 } 256 }
233 257
234 DEFINE_TRACE(EventHandler) 258 DEFINE_TRACE(EventHandler)
235 { 259 {
236 #if ENABLE(OILPAN) 260 #if ENABLE(OILPAN)
237 visitor->trace(m_mousePressNode); 261 visitor->trace(m_mousePressNode);
238 visitor->trace(m_capturingMouseEventsNode); 262 visitor->trace(m_capturingMouseEventsNode);
239 visitor->trace(m_nodeUnderMouse); 263 visitor->trace(m_nodeUnderMouse);
240 visitor->trace(m_lastNodeUnderMouse); 264 visitor->trace(m_lastNodeUnderMouse);
241 visitor->trace(m_lastMouseMoveEventSubframe); 265 visitor->trace(m_lastMouseMoveEventSubframe);
242 visitor->trace(m_lastScrollbarUnderMouse); 266 visitor->trace(m_lastScrollbarUnderMouse);
243 visitor->trace(m_clickNode); 267 visitor->trace(m_clickNode);
244 visitor->trace(m_dragTarget); 268 visitor->trace(m_dragTarget);
245 visitor->trace(m_frameSetBeingResized); 269 visitor->trace(m_frameSetBeingResized);
246 visitor->trace(m_latchedWheelEventNode); 270 visitor->trace(m_latchedWheelEventNode);
247 visitor->trace(m_previousWheelScrolledNode); 271 visitor->trace(m_previousWheelScrolledNode);
248 visitor->trace(m_scrollbarHandlingScrollGesture); 272 visitor->trace(m_scrollbarHandlingScrollGesture);
249 visitor->trace(m_targetForTouchID); 273 visitor->trace(m_targetForTouchID);
250 visitor->trace(m_touchSequenceDocument); 274 visitor->trace(m_touchSequenceDocument);
251 visitor->trace(m_scrollGestureHandlingNode); 275 visitor->trace(m_scrollGestureHandlingNode);
252 visitor->trace(m_previousGestureScrolledNode); 276 visitor->trace(m_previousGestureScrolledNode);
253 visitor->trace(m_lastDeferredTapElement); 277 visitor->trace(m_lastDeferredTapElement);
278 visitor->trace(m_currentScrollChain);
254 #endif 279 #endif
255 } 280 }
256 281
257 DragState& EventHandler::dragState() 282 DragState& EventHandler::dragState()
258 { 283 {
259 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<DragState>, state, (adoptPtrWillB eNoop(new DragState()))); 284 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<DragState>, state, (adoptPtrWillB eNoop(new DragState())));
260 return *state; 285 return *state;
261 } 286 }
262 287
263 void EventHandler::clear() 288 void EventHandler::clear()
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 setFrameWasScrolledByUser(); 958 setFrameWasScrolledByUser();
934 return true; 959 return true;
935 } 960 }
936 961
937 curBox = curBox->containingBlock(); 962 curBox = curBox->containingBlock();
938 } 963 }
939 964
940 return false; 965 return false;
941 } 966 }
942 967
968 void EventHandler::customizedScroll(const Node& startNode, ScrollState& scrollSt ate)
969 {
970 if (scrollState.fullyConsumed())
971 return;
972
973 if (m_currentScrollChain.isEmpty())
974 recomputeScrollChain(*m_frame, startNode, m_currentScrollChain);
975 scrollState.setScrollChain(m_currentScrollChain);
976 scrollState.distributeToScrollChainDescendant();
977 }
978
943 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode) 979 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode)
944 { 980 {
945 // The layout needs to be up to date to determine if we can scroll. We may b e 981 // The layout needs to be up to date to determine if we can scroll. We may b e
946 // here because of an onLoad event, in which case the final layout hasn't be en performed yet. 982 // here because of an onLoad event, in which case the final layout hasn't be en performed yet.
947 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 983 m_frame->document()->updateLayoutIgnorePendingStylesheets();
984 // FIXME: enable scroll customization in this case. See crbug.com/410974.
948 if (scroll(direction, granularity, startingNode)) 985 if (scroll(direction, granularity, startingNode))
949 return true; 986 return true;
950 LocalFrame* frame = m_frame; 987 LocalFrame* frame = m_frame;
951 FrameView* view = frame->view(); 988 FrameView* view = frame->view();
952 if (view && view->scroll(direction, granularity)) 989 if (view && view->scroll(direction, granularity))
953 return true; 990 return true;
954 Frame* parentFrame = frame->tree().parent(); 991 Frame* parentFrame = frame->tree().parent();
955 if (!parentFrame || !parentFrame->isLocalFrame()) 992 if (!parentFrame || !parentFrame->isLocalFrame())
956 return false; 993 return false;
957 // FIXME: Broken for OOPI. 994 // FIXME: Broken for OOPI.
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 // When the wheelEvent do not scroll, we trigger zoom in/out instead. 2111 // When the wheelEvent do not scroll, we trigger zoom in/out instead.
2075 if (!wheelEvent->canScroll()) 2112 if (!wheelEvent->canScroll())
2076 return; 2113 return;
2077 2114
2078 Node* stopNode = m_previousWheelScrolledNode.get(); 2115 Node* stopNode = m_previousWheelScrolledNode.get();
2079 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt); 2116 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt);
2080 IntPoint absolutePosition = roundedIntPoint(wheelEvent->absoluteLocation()); 2117 IntPoint absolutePosition = roundedIntPoint(wheelEvent->absoluteLocation());
2081 2118
2082 // Break up into two scrolls if we need to. Diagonal movement on 2119 // Break up into two scrolls if we need to. Diagonal movement on
2083 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set). 2120 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set).
2121
2122 // FIXME: enable scroll customization in this case. See crbug.com/410974.
2084 if (wheelEvent->railsMode() != Event::RailsModeVertical 2123 if (wheelEvent->railsMode() != Event::RailsModeVertical
2085 && scroll(ScrollRight, granularity, startNode, &stopNode, wheelEvent->de ltaX(), absolutePosition)) 2124 && scroll(ScrollRight, granularity, startNode, &stopNode, wheelEvent->de ltaX(), absolutePosition))
2086 wheelEvent->setDefaultHandled(); 2125 wheelEvent->setDefaultHandled();
2087 2126
2088 if (wheelEvent->railsMode() != Event::RailsModeHorizontal 2127 if (wheelEvent->railsMode() != Event::RailsModeHorizontal
2089 && scroll(ScrollDown, granularity, startNode, &stopNode, wheelEvent->del taY(), absolutePosition)) 2128 && scroll(ScrollDown, granularity, startNode, &stopNode, wheelEvent->del taY(), absolutePosition))
2090 wheelEvent->setDefaultHandled(); 2129 wheelEvent->setDefaultHandled();
2091 2130
2092 if (!m_latchedWheelEventNode) 2131 if (!m_latchedWheelEventNode)
2093 m_previousWheelScrolledNode = stopNode; 2132 m_previousWheelScrolledNode = stopNode;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 Widget* widget = toLayoutPart(renderer)->widget(); 2506 Widget* widget = toLayoutPart(renderer)->widget();
2468 2507
2469 if (!widget || !widget->isFrameView()) 2508 if (!widget || !widget->isFrameView())
2470 return false; 2509 return false;
2471 2510
2472 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent( gestureEvent); 2511 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent( gestureEvent);
2473 } 2512 }
2474 2513
2475 bool EventHandler::handleGestureScrollEnd(const PlatformGestureEvent& gestureEve nt) { 2514 bool EventHandler::handleGestureScrollEnd(const PlatformGestureEvent& gestureEve nt) {
2476 RefPtrWillBeRawPtr<Node> node = m_scrollGestureHandlingNode; 2515 RefPtrWillBeRawPtr<Node> node = m_scrollGestureHandlingNode;
2516
2517 if (node) {
2518 passScrollGestureEventToWidget(gestureEvent, node->layoutObject());
2519 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2520 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2521 0, 0, 0, 0, 0, gestureEvent.inertial(), /* isBeginning */
2522 false, /* isEnding */ true, /* fromUserInput */ true);
2523 customizedScroll(*node.get(), *scrollState);
2524 }
2525 }
2526
2477 clearGestureScrollNodes(); 2527 clearGestureScrollNodes();
2478
2479 if (node)
2480 passScrollGestureEventToWidget(gestureEvent, node->layoutObject());
2481
2482 return false; 2528 return false;
2483 } 2529 }
2484 2530
2485 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE vent) 2531 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE vent)
2486 { 2532 {
2487 Document* document = m_frame->document(); 2533 Document* document = m_frame->document();
2488 if (!document->layoutView()) 2534 if (!document->layoutView())
2489 return false; 2535 return false;
2490 2536
2491 FrameView* view = m_frame->view(); 2537 FrameView* view = m_frame->view();
2492 if (!view) 2538 if (!view)
2493 return false; 2539 return false;
2494 2540
2495 // If there's no renderer on the node, send the event to the nearest ancesto r with a renderer. 2541 // If there's no renderer on the node, send the event to the nearest ancesto r with a renderer.
2496 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s 2542 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s
2497 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb ject()) 2543 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->layoutOb ject())
2498 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode(); 2544 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode();
2499 2545
2500 if (!m_scrollGestureHandlingNode) 2546 if (!m_scrollGestureHandlingNode) {
2501 return false; 2547 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2548 m_scrollGestureHandlingNode = m_frame->document()->documentElement() ;
2549 else
2550 return false;
2551 }
2552 ASSERT(m_scrollGestureHandlingNode);
2502 2553
2503 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la youtObject()); 2554 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->la youtObject());
2504 2555 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2505 if (m_frame->isMainFrame()) 2556 m_currentScrollChain.clear();
2506 m_frame->host()->topControls().scrollBegin(); 2557 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2507 2558 0, 0, 0, 0, 0, /* inInertialPhase */ false, /* isBeginning */
2559 true, /* isEnding */ false, /* fromUserInput */ true);
2560 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState);
2561 } else {
2562 if (m_frame->isMainFrame())
2563 m_frame->host()->topControls().scrollBegin();
2564 }
2508 return true; 2565 return true;
2509 } 2566 }
2510 2567
2511 static bool scrollAreaOnBothAxes(const FloatSize& delta, ScrollableArea& view)
2512 {
2513 bool scrolledHorizontal = view.scroll(ScrollLeft, ScrollByPrecisePixel, delt a.width());
2514 bool scrolledVertical = view.scroll(ScrollUp, ScrollByPrecisePixel, delta.he ight());
2515 return scrolledHorizontal || scrolledVertical;
2516 }
2517
2518 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture Event) 2568 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture Event)
2519 { 2569 {
2520 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate); 2570 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate);
2521 2571
2522 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY()); 2572 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY());
2523 if (delta.isZero()) 2573 if (delta.isZero())
2524 return false; 2574 return false;
2525 2575
2526 Node* node = m_scrollGestureHandlingNode.get(); 2576 Node* node = m_scrollGestureHandlingNode.get();
2527 if (node) { 2577 if (node) {
2528 LayoutObject* renderer = node->layoutObject(); 2578 LayoutObject* renderer = node->layoutObject();
2529 if (!renderer) 2579 if (!renderer)
2530 return false; 2580 return false;
2531 2581
2532 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2582 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2533 2583
2534 Node* stopNode = nullptr; 2584 Node* stopNode = nullptr;
2535 2585
2536 // Try to send the event to the correct view. 2586 // Try to send the event to the correct view.
2537 if (passScrollGestureEventToWidget(gestureEvent, renderer)) { 2587 if (passScrollGestureEventToWidget(gestureEvent, renderer)) {
2538 if (gestureEvent.preventPropagation()) 2588 if (gestureEvent.preventPropagation()
2589 && !RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2590 // This is an optimization which doesn't apply with
2591 // scroll customization enabled.
2539 m_previousGestureScrolledNode = m_scrollGestureHandlingNode; 2592 m_previousGestureScrolledNode = m_scrollGestureHandlingNode;
2540 2593 }
2594 // FIXME: we should allow simultaneous scrolling of nested
2595 // iframes along perpendicular axes. See crbug.com/466991.
2596 m_deltaConsumedForScrollSequence = true;
2541 return true; 2597 return true;
2542 } 2598 }
2543 2599
2600 bool scrolled = false;
2601 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2602 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2603 gestureEvent.deltaX(), gestureEvent.deltaY(),
2604 0, gestureEvent.velocityX(), gestureEvent.velocityY(),
2605 gestureEvent.inertial(), /* isBeginning */
2606 false, /* isEnding */ false, /* fromUserInput */ true,
2607 !gestureEvent.preventPropagation(), m_deltaConsumedForScrollSequ ence);
2608 if (m_previousGestureScrolledNode) {
2609 // The ScrollState needs to know what the current
2610 // native scrolling element is, so that for an
2611 // inertial scroll that shouldn't propagate, only the
2612 // currently scrolling element responds.
2613 ASSERT(m_previousGestureScrolledNode->isElementNode());
2614 scrollState->setCurrentNativeScrollingElement(toElement(m_previo usGestureScrolledNode.get()));
2615 }
2616 customizedScroll(*node, *scrollState);
2617 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement();
2618 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence();
2619 scrolled = scrollState->deltaX() != gestureEvent.deltaX()
2620 || scrollState->deltaY() != gestureEvent.deltaY();
2621 } else {
2622 if (gestureEvent.preventPropagation())
2623 stopNode = m_previousGestureScrolledNode.get();
2544 2624
2545 if (gestureEvent.preventPropagation()) 2625 // First try to scroll the closest scrollable LayoutBox ancestor of |node|.
2546 stopNode = m_previousGestureScrolledNode.get(); 2626 ScrollGranularity granularity = ScrollByPrecisePixel;
2627 bool horizontalScroll = scroll(ScrollLeft, granularity, node, &stopN ode, delta.width());
2628 if (!gestureEvent.preventPropagation())
2629 stopNode = nullptr;
2630 bool verticalScroll = scroll(ScrollUp, granularity, node, &stopNode, delta.height());
2631 scrolled = horizontalScroll || verticalScroll;
2547 2632
2548 // First try to scroll the closest scrollable LayoutBox ancestor of |nod e|. 2633 if (gestureEvent.preventPropagation())
2549 ScrollGranularity granularity = ScrollByPrecisePixel; 2634 m_previousGestureScrolledNode = stopNode;
2550 bool horizontalScroll = scroll(ScrollLeft, granularity, node, &stopNode, delta.width()); 2635 }
2551 bool verticalScroll = scroll(ScrollUp, granularity, node, &stopNode, del ta.height()); 2636 if (scrolled) {
2552
2553 if (gestureEvent.preventPropagation())
2554 m_previousGestureScrolledNode = stopNode;
2555
2556 if (horizontalScroll || verticalScroll) {
2557 setFrameWasScrolledByUser(); 2637 setFrameWasScrolledByUser();
2558 return true; 2638 return true;
2559 } 2639 }
2560 } 2640 }
2561 2641
2562 // If this is main frame, allow top controls to scroll first and update 2642 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2563 // delta accordingly 2643 return false;
2564 bool consumed = false;
2565 if (m_frame->isMainFrame() && shouldTopControlsConsumeScroll(delta)) {
2566 FloatSize excessDelta = m_frame->host()->topControls().scrollBy(delta);
2567 consumed = excessDelta != delta;
2568 delta = excessDelta;
2569
2570 if (delta.isZero())
2571 return consumed;
2572 }
2573 2644
2574 // Try to scroll the frame view. 2645 // Try to scroll the frame view.
2575 FrameView* view = m_frame->view(); 2646 if (m_frame->applyScrollDelta(delta, false)) {
2576 if (!view)
2577 return consumed;
2578
2579 if (scrollAreaOnBothAxes(delta, *view)) {
2580 setFrameWasScrolledByUser(); 2647 setFrameWasScrolledByUser();
2581 return true; 2648 return true;
2582 } 2649 }
2583 2650
2584 // If this is the main frame and it didn't scroll, propagate up to the pinch viewport. 2651 return false;
2585 if (!m_frame->isMainFrame())
2586 return consumed;
2587
2588 if (scrollAreaOnBothAxes(delta, m_frame->host()->pinchViewport())) {
2589 setFrameWasScrolledByUser();
2590 return true;
2591 }
2592
2593 return consumed;
2594 } 2652 }
2595 2653
2596 void EventHandler::clearGestureScrollNodes() 2654 void EventHandler::clearGestureScrollNodes()
2597 { 2655 {
2598 m_scrollGestureHandlingNode = nullptr; 2656 m_scrollGestureHandlingNode = nullptr;
2599 m_previousGestureScrolledNode = nullptr; 2657 m_previousGestureScrolledNode = nullptr;
2658 m_deltaConsumedForScrollSequence = false;
2659 m_currentScrollChain.clear();
2600 } 2660 }
2601 2661
2602 bool EventHandler::isScrollbarHandlingGestures() const 2662 bool EventHandler::isScrollbarHandlingGestures() const
2603 { 2663 {
2604 return m_scrollbarHandlingScrollGesture.get(); 2664 return m_scrollbarHandlingScrollGesture.get();
2605 } 2665 }
2606 2666
2607 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const 2667 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const
2608 { 2668 {
2609 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled()) 2669 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled())
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
3416 } 3476 }
3417 3477
3418 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event) 3478 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event)
3419 { 3479 {
3420 ASSERT(event->type() == EventTypeNames::keypress); 3480 ASSERT(event->type() == EventTypeNames::keypress);
3421 3481
3422 if (event->ctrlKey() || event->metaKey() || event->altKey()) 3482 if (event->ctrlKey() || event->metaKey() || event->altKey())
3423 return; 3483 return;
3424 3484
3425 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward; 3485 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward;
3486 // FIXME: enable scroll customization in this case. See crbug.com/410974.
3426 if (scroll(direction, ScrollByPage)) { 3487 if (scroll(direction, ScrollByPage)) {
3427 event->setDefaultHandled(); 3488 event->setDefaultHandled();
3428 return; 3489 return;
3429 } 3490 }
3430 3491
3431 FrameView* view = m_frame->view(); 3492 FrameView* view = m_frame->view();
3432 if (!view) 3493 if (!view)
3433 return; 3494 return;
3434 3495
3435 if (view->scroll(direction, ScrollByPage)) 3496 if (view->scroll(direction, ScrollByPage))
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
3932 3993
3933 unsigned EventHandler::accessKeyModifiers() 3994 unsigned EventHandler::accessKeyModifiers()
3934 { 3995 {
3935 #if OS(MACOSX) 3996 #if OS(MACOSX)
3936 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3997 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3937 #else 3998 #else
3938 return PlatformEvent::AltKey; 3999 return PlatformEvent::AltKey;
3939 #endif 4000 #endif
3940 } 4001 }
3941 4002
3942 bool EventHandler::shouldTopControlsConsumeScroll(FloatSize scrollDelta) const
3943 {
3944 // Always consume if it's in the direction to show the top controls.
3945 if (scrollDelta.height() > 0)
3946 return true;
3947
3948 // If it's in the direction to hide the top controls, only consume when the frame can also scroll.
3949 if (m_frame->view()->scrollPosition().y() < m_frame->view()->maximumScrollPo sition().y())
3950 return true;
3951
3952 return false;
3953 }
3954
3955
3956 } // namespace blink 4003 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/page/EventHandler.h ('k') | Source/core/page/scrolling/ScrollState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698