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

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: 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
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/svg/SVGDocumentExtensions.h" 84 #include "core/svg/SVGDocumentExtensions.h"
84 #include "platform/PlatformGestureEvent.h" 85 #include "platform/PlatformGestureEvent.h"
85 #include "platform/PlatformKeyboardEvent.h" 86 #include "platform/PlatformKeyboardEvent.h"
86 #include "platform/PlatformTouchEvent.h" 87 #include "platform/PlatformTouchEvent.h"
87 #include "platform/PlatformWheelEvent.h" 88 #include "platform/PlatformWheelEvent.h"
88 #include "platform/RuntimeEnabledFeatures.h" 89 #include "platform/RuntimeEnabledFeatures.h"
89 #include "platform/TraceEvent.h" 90 #include "platform/TraceEvent.h"
90 #include "platform/WindowsKeyboardCodes.h" 91 #include "platform/WindowsKeyboardCodes.h"
91 #include "platform/geometry/FloatPoint.h" 92 #include "platform/geometry/FloatPoint.h"
92 #include "platform/graphics/Image.h" 93 #include "platform/graphics/Image.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // we'd like to EventHandler::handleMousePressEvent to pass the event to the wid get and thus the 189 // we'd like to EventHandler::handleMousePressEvent to pass the event to the wid get and thus the
189 // event target node can't still be the shadow node. 190 // event target node can't still be the shadow node.
190 static inline bool shouldRefetchEventTarget(const MouseEventWithHitTestResults& mev) 191 static inline bool shouldRefetchEventTarget(const MouseEventWithHitTestResults& mev)
191 { 192 {
192 Node* targetNode = mev.innerNode(); 193 Node* targetNode = mev.innerNode();
193 if (!targetNode || !targetNode->parentNode()) 194 if (!targetNode || !targetNode->parentNode())
194 return true; 195 return true;
195 return targetNode->isShadowRoot() && isHTMLInputElement(*toShadowRoot(target Node)->host()); 196 return targetNode->isShadowRoot() && isHTMLInputElement(*toShadowRoot(target Node)->host());
196 } 197 }
197 198
199 void recomputeScrollChain(const LocalFrame& frame, const Node& scrollGestureHand lingNode,
200 WillBeHeapDeque<RefPtrWillBeMember<Element>>& scrollChain)
201 {
202 scrollChain.clear();
203 bool rootLayerScrolls = frame.settings() && frame.settings()->rootLayerScrol ls();
204 LayoutBox* curBox = scrollGestureHandlingNode.renderer()->enclosingBox();
205 bool addedDocumentElement = false;
206
207 while (curBox && (rootLayerScrolls || !curBox->isLayoutView())) {
208 Node* curNode = curBox->node();
209 curBox = curBox->containingBlock();
210 // FIXME: this should reject more elements.
211 if (!curNode || !curNode->isElementNode())
212 continue;
213 scrollChain.prepend(toElement(curNode));
214 if (curNode == frame.document()->documentElement())
215 addedDocumentElement = true;
216 }
217
218 if (!addedDocumentElement)
219 scrollChain.prepend(frame.document()->documentElement());
220 }
221
198 EventHandler::EventHandler(LocalFrame* frame) 222 EventHandler::EventHandler(LocalFrame* frame)
199 : m_frame(frame) 223 : m_frame(frame)
200 , m_mousePressed(false) 224 , m_mousePressed(false)
201 , m_capturesDragging(false) 225 , m_capturesDragging(false)
202 , m_mouseDownMayStartSelect(false) 226 , m_mouseDownMayStartSelect(false)
203 , m_mouseDownMayStartDrag(false) 227 , m_mouseDownMayStartDrag(false)
204 , m_mouseDownWasSingleClickInSelection(false) 228 , m_mouseDownWasSingleClickInSelection(false)
205 , m_selectionInitiationState(HaveNotStartedSelection) 229 , m_selectionInitiationState(HaveNotStartedSelection)
206 , m_hoverTimer(this, &EventHandler::hoverTimerFired) 230 , m_hoverTimer(this, &EventHandler::hoverTimerFired)
207 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired) 231 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
208 , m_mouseDownMayStartAutoscroll(false) 232 , m_mouseDownMayStartAutoscroll(false)
209 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d) 233 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d)
210 , m_svgPan(false) 234 , m_svgPan(false)
211 , m_resizeScrollableArea(nullptr) 235 , m_resizeScrollableArea(nullptr)
212 , m_eventHandlerWillResetCapturingMouseEventsNode(0) 236 , m_eventHandlerWillResetCapturingMouseEventsNode(0)
213 , m_clickCount(0) 237 , m_clickCount(0)
214 , m_shouldOnlyFireDragOverEvent(false) 238 , m_shouldOnlyFireDragOverEvent(false)
215 , m_mousePositionIsUnknown(true) 239 , m_mousePositionIsUnknown(true)
216 , m_mouseDownTimestamp(0) 240 , m_mouseDownTimestamp(0)
217 , m_widgetIsLatched(false) 241 , m_widgetIsLatched(false)
218 , m_touchPressed(false) 242 , m_touchPressed(false)
219 , m_scrollGestureHandlingNode(nullptr) 243 , m_scrollGestureHandlingNode(nullptr)
220 , m_lastGestureScrollOverWidget(false) 244 , m_lastGestureScrollOverWidget(false)
221 , m_maxMouseMovedDuration(0) 245 , m_maxMouseMovedDuration(0)
222 , m_longTapShouldInvokeContextMenu(false) 246 , m_longTapShouldInvokeContextMenu(false)
223 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 247 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
224 , m_lastShowPressTimestamp(0) 248 , m_lastShowPressTimestamp(0)
249 , m_deltaConsumedForScrollSequence(false)
225 { 250 {
226 } 251 }
227 252
228 EventHandler::~EventHandler() 253 EventHandler::~EventHandler()
229 { 254 {
230 ASSERT(!m_fakeMouseMoveEventTimer.isActive()); 255 ASSERT(!m_fakeMouseMoveEventTimer.isActive());
231 } 256 }
232 257
233 DEFINE_TRACE(EventHandler) 258 DEFINE_TRACE(EventHandler)
234 { 259 {
235 #if ENABLE(OILPAN) 260 #if ENABLE(OILPAN)
236 visitor->trace(m_mousePressNode); 261 visitor->trace(m_mousePressNode);
237 visitor->trace(m_capturingMouseEventsNode); 262 visitor->trace(m_capturingMouseEventsNode);
238 visitor->trace(m_nodeUnderMouse); 263 visitor->trace(m_nodeUnderMouse);
239 visitor->trace(m_lastNodeUnderMouse); 264 visitor->trace(m_lastNodeUnderMouse);
240 visitor->trace(m_lastMouseMoveEventSubframe); 265 visitor->trace(m_lastMouseMoveEventSubframe);
241 visitor->trace(m_lastScrollbarUnderMouse); 266 visitor->trace(m_lastScrollbarUnderMouse);
242 visitor->trace(m_clickNode); 267 visitor->trace(m_clickNode);
243 visitor->trace(m_dragTarget); 268 visitor->trace(m_dragTarget);
244 visitor->trace(m_frameSetBeingResized); 269 visitor->trace(m_frameSetBeingResized);
245 visitor->trace(m_latchedWheelEventNode); 270 visitor->trace(m_latchedWheelEventNode);
246 visitor->trace(m_previousWheelScrolledNode); 271 visitor->trace(m_previousWheelScrolledNode);
247 visitor->trace(m_scrollbarHandlingScrollGesture); 272 visitor->trace(m_scrollbarHandlingScrollGesture);
248 visitor->trace(m_targetForTouchID); 273 visitor->trace(m_targetForTouchID);
249 visitor->trace(m_touchSequenceDocument); 274 visitor->trace(m_touchSequenceDocument);
250 visitor->trace(m_scrollGestureHandlingNode); 275 visitor->trace(m_scrollGestureHandlingNode);
251 visitor->trace(m_previousGestureScrolledNode); 276 visitor->trace(m_previousGestureScrolledNode);
252 visitor->trace(m_lastDeferredTapElement); 277 visitor->trace(m_lastDeferredTapElement);
278 visitor->trace(m_currentScrollChain);
253 #endif 279 #endif
254 } 280 }
255 281
256 DragState& EventHandler::dragState() 282 DragState& EventHandler::dragState()
257 { 283 {
258 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<DragState>, state, (adoptPtrWillB eNoop(new DragState()))); 284 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<DragState>, state, (adoptPtrWillB eNoop(new DragState())));
259 return *state; 285 return *state;
260 } 286 }
261 287
262 void EventHandler::clear() 288 void EventHandler::clear()
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 setFrameWasScrolledByUser(); 963 setFrameWasScrolledByUser();
938 return true; 964 return true;
939 } 965 }
940 966
941 curBox = curBox->containingBlock(); 967 curBox = curBox->containingBlock();
942 } 968 }
943 969
944 return false; 970 return false;
945 } 971 }
946 972
973 void EventHandler::customizedScroll(ScrollState* scrollState, Node* startNode)
974 {
975 Node* node = startNode;
976
977 if (!node)
978 node = m_frame->document()->focusedElement();
979
980 if (!node)
981 node = m_mousePressNode.get();
982
983 if (!node || !node->renderer())
984 return;
985
986 if (m_currentScrollChain.isEmpty() && m_scrollGestureHandlingNode.get())
987 recomputeScrollChain(*m_frame, *m_scrollGestureHandlingNode.get(), m_cur rentScrollChain);
988 scrollState->setScrollChain(m_currentScrollChain);
989 scrollState->distributeToScrollChainDescendant();
990 }
991
947 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode) 992 bool EventHandler::bubblingScroll(ScrollDirection direction, ScrollGranularity g ranularity, Node* startingNode)
948 { 993 {
949 // The layout needs to be up to date to determine if we can scroll. We may b e 994 // The layout needs to be up to date to determine if we can scroll. We may b e
950 // here because of an onLoad event, in which case the final layout hasn't be en performed yet. 995 // here because of an onLoad event, in which case the final layout hasn't be en performed yet.
951 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 996 m_frame->document()->updateLayoutIgnorePendingStylesheets();
997 // FIXME: enable scroll customization in this case.
952 if (scroll(direction, granularity, startingNode)) 998 if (scroll(direction, granularity, startingNode))
953 return true; 999 return true;
954 LocalFrame* frame = m_frame; 1000 LocalFrame* frame = m_frame;
955 FrameView* view = frame->view(); 1001 FrameView* view = frame->view();
956 if (view && view->scroll(direction, granularity)) 1002 if (view && view->scroll(direction, granularity))
957 return true; 1003 return true;
958 Frame* parentFrame = frame->tree().parent(); 1004 Frame* parentFrame = frame->tree().parent();
959 if (!parentFrame || !parentFrame->isLocalFrame()) 1005 if (!parentFrame || !parentFrame->isLocalFrame())
960 return false; 1006 return false;
961 // FIXME: Broken for OOPI. 1007 // FIXME: Broken for OOPI.
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 2098
2053 // When the wheelEvent do not scroll, we trigger zoom in/out instead. 2099 // When the wheelEvent do not scroll, we trigger zoom in/out instead.
2054 if (!wheelEvent->canScroll()) 2100 if (!wheelEvent->canScroll())
2055 return; 2101 return;
2056 2102
2057 Node* stopNode = m_previousWheelScrolledNode.get(); 2103 Node* stopNode = m_previousWheelScrolledNode.get();
2058 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt); 2104 ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEve nt);
2059 2105
2060 // Break up into two scrolls if we need to. Diagonal movement on 2106 // Break up into two scrolls if we need to. Diagonal movement on
2061 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set). 2107 // a MacBook pro is an example of a 2-dimensional mouse wheel event (where b oth deltaX and deltaY can be set).
2108
2109 // FIXME: enable scroll customization in this case.
2062 if (scroll(ScrollRight, granularity, startNode, &stopNode, wheelEvent->delta X(), roundedIntPoint(wheelEvent->absoluteLocation()))) 2110 if (scroll(ScrollRight, granularity, startNode, &stopNode, wheelEvent->delta X(), roundedIntPoint(wheelEvent->absoluteLocation())))
2063 wheelEvent->setDefaultHandled(); 2111 wheelEvent->setDefaultHandled();
2064 2112
2065 if (scroll(ScrollDown, granularity, startNode, &stopNode, wheelEvent->deltaY (), roundedIntPoint(wheelEvent->absoluteLocation()))) 2113 if (scroll(ScrollDown, granularity, startNode, &stopNode, wheelEvent->deltaY (), roundedIntPoint(wheelEvent->absoluteLocation())))
2066 wheelEvent->setDefaultHandled(); 2114 wheelEvent->setDefaultHandled();
2067 2115
2068 if (!m_latchedWheelEventNode) 2116 if (!m_latchedWheelEventNode)
2069 m_previousWheelScrolledNode = stopNode; 2117 m_previousWheelScrolledNode = stopNode;
2070 } 2118 }
2071 2119
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2188 FrameView* view = m_frame->view(); 2236 FrameView* view = m_frame->view();
2189 LayoutPoint viewPoint = view->windowToContents(gestureEvent.position()); 2237 LayoutPoint viewPoint = view->windowToContents(gestureEvent.position());
2190 HitTestRequest request(HitTestRequest::ReadOnly); 2238 HitTestRequest request(HitTestRequest::ReadOnly);
2191 HitTestResult result(viewPoint); 2239 HitTestResult result(viewPoint);
2192 document->layoutView()->hitTest(request, result); 2240 document->layoutView()->hitTest(request, result);
2193 2241
2194 eventTarget = result.innerNode(); 2242 eventTarget = result.innerNode();
2195 2243
2196 m_lastGestureScrollOverWidget = result.isOverWidget(); 2244 m_lastGestureScrollOverWidget = result.isOverWidget();
2197 m_scrollGestureHandlingNode = eventTarget; 2245 m_scrollGestureHandlingNode = eventTarget;
2198 m_previousGestureScrolledNode = nullptr;
2199 2246
2200 if (!scrollbar) 2247 if (!scrollbar)
2201 scrollbar = result.scrollbar(); 2248 scrollbar = result.scrollbar();
2202 } 2249 }
2203 2250
2204 if (scrollbar) { 2251 if (scrollbar) {
2205 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent); 2252 bool eventSwallowed = scrollbar->gestureEvent(gestureEvent);
2206 if (gestureEvent.type() == PlatformEvent::GestureScrollEnd 2253 if (gestureEvent.type() == PlatformEvent::GestureScrollEnd
2207 || gestureEvent.type() == PlatformEvent::GestureFlingStart 2254 || gestureEvent.type() == PlatformEvent::GestureFlingStart
2208 || !eventSwallowed) { 2255 || !eventSwallowed) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 Widget* widget = toLayoutPart(renderer)->widget(); 2488 Widget* widget = toLayoutPart(renderer)->widget();
2442 2489
2443 if (!widget || !widget->isFrameView()) 2490 if (!widget || !widget->isFrameView())
2444 return false; 2491 return false;
2445 2492
2446 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent( gestureEvent); 2493 return toFrameView(widget)->frame().eventHandler().handleGestureScrollEvent( gestureEvent);
2447 } 2494 }
2448 2495
2449 bool EventHandler::handleGestureScrollEnd(const PlatformGestureEvent& gestureEve nt) { 2496 bool EventHandler::handleGestureScrollEnd(const PlatformGestureEvent& gestureEve nt) {
2450 RefPtrWillBeRawPtr<Node> node = m_scrollGestureHandlingNode; 2497 RefPtrWillBeRawPtr<Node> node = m_scrollGestureHandlingNode;
2498
2499 if (node) {
2500 if (passScrollGestureEventToWidget(gestureEvent, node->renderer()))
2501 return false;
2502 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2503 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2504 0, 0, 0, 0, 0, gestureEvent.inertial(), false, true, true);
2505 customizedScroll(scrollState.get(), node.get());
2506 }
2507 }
2508
2451 clearGestureScrollNodes(); 2509 clearGestureScrollNodes();
2452 2510 m_currentScrollChain.clear();
2453 if (node)
2454 passScrollGestureEventToWidget(gestureEvent, node->renderer());
2455
2456 return false; 2511 return false;
2457 } 2512 }
2458 2513
2459 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE vent) 2514 bool EventHandler::handleGestureScrollBegin(const PlatformGestureEvent& gestureE vent)
2460 { 2515 {
2461 Document* document = m_frame->document(); 2516 Document* document = m_frame->document();
2462 if (!document->layoutView()) 2517 if (!document->layoutView())
2463 return false; 2518 return false;
2464 2519
2465 FrameView* view = m_frame->view(); 2520 FrameView* view = m_frame->view();
2466 if (!view) 2521 if (!view)
2467 return false; 2522 return false;
2468 2523
2469 // If there's no renderer on the node, send the event to the nearest ancesto r with a renderer. 2524 // If there's no renderer on the node, send the event to the nearest ancesto r with a renderer.
2470 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s 2525 // Needed for <option> and <optgroup> elements so we can touch scroll <selec t>s
2471 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->renderer ()) 2526 while (m_scrollGestureHandlingNode && !m_scrollGestureHandlingNode->renderer ())
2472 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode(); 2527 m_scrollGestureHandlingNode = m_scrollGestureHandlingNode->parentOrShado wHostNode();
2473 2528
2474 if (!m_scrollGestureHandlingNode) 2529 if (!m_scrollGestureHandlingNode) {
2475 return false; 2530 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2531 m_scrollGestureHandlingNode = m_frame->document()->documentElement() ;
2532 else
2533 return false;
2534 }
2535 ASSERT(m_scrollGestureHandlingNode);
2476 2536
2477 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->re nderer()); 2537 passScrollGestureEventToWidget(gestureEvent, m_scrollGestureHandlingNode->re nderer());
2538 if (!RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2539 if (m_frame->isMainFrame())
2540 m_frame->host()->topControls().scrollBegin();
2541 return true;
2542 }
2478 2543
2479 if (m_frame->isMainFrame()) 2544 m_deltaConsumedForScrollSequence = false;
2480 m_frame->host()->topControls().scrollBegin(); 2545 m_currentScrollChain.clear();
2546 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2547 0, 0, 0, 0, 0, false, true, false, true);
2548 customizedScroll(scrollState.get(), m_scrollGestureHandlingNode.get());
2481 2549
2482 return true; 2550 return true;
2483 } 2551 }
2484 2552
2485 static bool scrollAreaOnBothAxes(const FloatSize& delta, ScrollableArea& view)
2486 {
2487 bool scrolledHorizontal = view.scroll(ScrollLeft, ScrollByPrecisePixel, delt a.width());
2488 bool scrolledVertical = view.scroll(ScrollUp, ScrollByPrecisePixel, delta.he ight());
2489 return scrolledHorizontal || scrolledVertical;
2490 }
2491
2492 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture Event) 2553 bool EventHandler::handleGestureScrollUpdate(const PlatformGestureEvent& gesture Event)
2493 { 2554 {
2494 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate); 2555 ASSERT(gestureEvent.type() == PlatformEvent::GestureScrollUpdate);
2495 2556
2496 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY()); 2557 FloatSize delta(gestureEvent.deltaX(), gestureEvent.deltaY());
2497 if (delta.isZero()) 2558 if (delta.isZero())
2498 return false; 2559 return false;
2499 2560
2500 Node* node = m_scrollGestureHandlingNode.get(); 2561 Node* node = m_scrollGestureHandlingNode.get();
2501 if (node) { 2562 if (node) {
2502 LayoutObject* renderer = node->renderer(); 2563 LayoutObject* renderer = node->renderer();
2503 if (!renderer) 2564 if (!renderer)
2504 return false; 2565 return false;
2505 2566
2506 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view()); 2567 RefPtrWillBeRawPtr<FrameView> protector(m_frame->view());
2507 2568
2508 Node* stopNode = nullptr; 2569 Node* stopNode = nullptr;
2509 2570
2510 // Try to send the event to the correct view. 2571 // Try to send the event to the correct view.
2511 if (passScrollGestureEventToWidget(gestureEvent, renderer)) { 2572 if (passScrollGestureEventToWidget(gestureEvent, renderer)) {
2512 if (gestureEvent.preventPropagation()) 2573 if (gestureEvent.preventPropagation())
2513 m_previousGestureScrolledNode = m_scrollGestureHandlingNode; 2574 m_previousGestureScrolledNode = m_scrollGestureHandlingNode;
2514 2575 m_deltaConsumedForScrollSequence = true;
2515 return true; 2576 return true;
2516 } 2577 }
2517 2578
2579 bool scrolled = false;
2580 if (RuntimeEnabledFeatures::scrollCustomizationEnabled()) {
2581 RefPtrWillBeRawPtr<ScrollState> scrollState = ScrollState::create(
2582 gestureEvent.deltaX(), gestureEvent.deltaY(),
2583 0, gestureEvent.velocityX(), gestureEvent.velocityY(),
2584 gestureEvent.inertial(), false, false, true,
2585 !gestureEvent.preventPropagation(), m_deltaConsumedForScrollSequ ence);
2586 // FIXME - check if its an element.
tdresser 2015/03/06 20:38:11 This needs to be done.
tdresser 2015/03/09 17:02:56 Done.
2587 scrollState->setCurrentNativeScrollingElement(toElement(m_previousGe stureScrolledNode.get()));
2588 customizedScroll(scrollState.get(), node);
2589 m_previousGestureScrolledNode = scrollState->currentNativeScrollingE lement();
2590 m_deltaConsumedForScrollSequence = scrollState->deltaConsumedForScro llSequence();
2518 2591
2519 if (gestureEvent.preventPropagation()) 2592 scrolled = scrollState->deltaX() != gestureEvent.deltaX()
2520 stopNode = m_previousGestureScrolledNode.get(); 2593 || scrollState->deltaY() != gestureEvent.deltaY();
2594 } else {
2595 if (gestureEvent.preventPropagation())
2596 stopNode = m_previousGestureScrolledNode.get();
2521 2597
2522 // First try to scroll the closest scrollable LayoutBox ancestor of |nod e|. 2598 // First try to scroll the closest scrollable LayoutBox ancestor of |node|.
2523 ScrollGranularity granularity = ScrollByPixel; 2599 ScrollGranularity granularity = ScrollByPixel;
2524 bool horizontalScroll = scroll(ScrollLeft, granularity, node, &stopNode, delta.width()); 2600 scrolled = scroll(ScrollLeft, granularity, node, &stopNode, delta.wi dth())
2525 bool verticalScroll = scroll(ScrollUp, granularity, node, &stopNode, del ta.height()); 2601 | scroll(ScrollUp, granularity, node, &stopNode, delta.height()) ;
2526 2602
2527 if (gestureEvent.preventPropagation()) 2603 if (gestureEvent.preventPropagation())
2528 m_previousGestureScrolledNode = stopNode; 2604 m_previousGestureScrolledNode = stopNode;
2529 2605 }
2530 if (horizontalScroll || verticalScroll) { 2606 if (scrolled) {
2531 setFrameWasScrolledByUser(); 2607 setFrameWasScrolledByUser();
2532 return true; 2608 return true;
2533 } 2609 }
2534 } 2610 }
2535 2611
2536 // If this is main frame, allow top controls to scroll first and update 2612 if (RuntimeEnabledFeatures::scrollCustomizationEnabled())
2537 // delta accordingly 2613 return false;
2538 bool consumed = false;
2539 if (m_frame->isMainFrame() && shouldTopControlsConsumeScroll(delta)) {
2540 FloatSize excessDelta = m_frame->host()->topControls().scrollBy(delta);
2541 consumed = excessDelta != delta;
2542 delta = excessDelta;
2543
2544 if (delta.isZero())
2545 return consumed;
2546 }
2547 2614
2548 // Try to scroll the frame view. 2615 // Try to scroll the frame view.
2549 FrameView* view = m_frame->view(); 2616 if (m_frame->applyScrollDelta(delta, false)) {
2550 if (!view)
2551 return consumed;
2552
2553 if (scrollAreaOnBothAxes(delta, *view)) {
2554 setFrameWasScrolledByUser(); 2617 setFrameWasScrolledByUser();
2555 return true; 2618 return true;
2556 } 2619 }
2557 2620
2558 // If this is the main frame and it didn't scroll, propagate up to the pinch viewport. 2621 return false;
2559 if (!m_frame->settings()->pinchVirtualViewportEnabled() || !m_frame->isMainF rame())
2560 return consumed;
2561
2562 if (scrollAreaOnBothAxes(delta, m_frame->host()->pinchViewport())) {
2563 setFrameWasScrolledByUser();
2564 return true;
2565 }
2566
2567 return consumed;
2568 } 2622 }
2569 2623
2570 void EventHandler::clearGestureScrollNodes() 2624 void EventHandler::clearGestureScrollNodes()
2571 { 2625 {
2572 m_scrollGestureHandlingNode = nullptr; 2626 m_scrollGestureHandlingNode = nullptr;
2573 m_previousGestureScrolledNode = nullptr; 2627 m_previousGestureScrolledNode = nullptr;
2574 } 2628 }
2575 2629
2576 bool EventHandler::isScrollbarHandlingGestures() const 2630 bool EventHandler::isScrollbarHandlingGestures() const
2577 { 2631 {
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 } 3441 }
3388 3442
3389 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event) 3443 void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event)
3390 { 3444 {
3391 ASSERT(event->type() == EventTypeNames::keypress); 3445 ASSERT(event->type() == EventTypeNames::keypress);
3392 3446
3393 if (event->ctrlKey() || event->metaKey() || event->altKey()) 3447 if (event->ctrlKey() || event->metaKey() || event->altKey())
3394 return; 3448 return;
3395 3449
3396 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward; 3450 ScrollDirection direction = event->shiftKey() ? ScrollBlockDirectionBackward : ScrollBlockDirectionForward;
3451 // FIXME: enable scroll customization in this case.
3397 if (scroll(direction, ScrollByPage)) { 3452 if (scroll(direction, ScrollByPage)) {
3398 event->setDefaultHandled(); 3453 event->setDefaultHandled();
3399 return; 3454 return;
3400 } 3455 }
3401 3456
3402 FrameView* view = m_frame->view(); 3457 FrameView* view = m_frame->view();
3403 if (!view) 3458 if (!view)
3404 return; 3459 return;
3405 3460
3406 if (view->scroll(direction, ScrollByPage)) 3461 if (view->scroll(direction, ScrollByPage))
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
3904 3959
3905 unsigned EventHandler::accessKeyModifiers() 3960 unsigned EventHandler::accessKeyModifiers()
3906 { 3961 {
3907 #if OS(MACOSX) 3962 #if OS(MACOSX)
3908 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; 3963 return PlatformEvent::CtrlKey | PlatformEvent::AltKey;
3909 #else 3964 #else
3910 return PlatformEvent::AltKey; 3965 return PlatformEvent::AltKey;
3911 #endif 3966 #endif
3912 } 3967 }
3913 3968
3914 bool EventHandler::shouldTopControlsConsumeScroll(FloatSize scrollDelta) const
3915 {
3916 // Always consume if it's in the direction to show the top controls.
3917 if (scrollDelta.height() > 0)
3918 return true;
3919
3920 // If it's in the direction to hide the top controls, only consume when the frame can also scroll.
3921 if (m_frame->view()->scrollPosition().y() < m_frame->view()->maximumScrollPo sition().y())
3922 return true;
3923
3924 return false;
3925 }
3926
3927
3928 } // namespace blink 3969 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698