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

Side by Side Diff: third_party/WebKit/Source/core/input/EventHandler.cpp

Issue 1915783002: Move overscroll logic out of EventHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make m_visualViewport a WeakMember Created 4 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 #include "core/loader/FrameLoaderClient.h" 76 #include "core/loader/FrameLoaderClient.h"
77 #include "core/page/AutoscrollController.h" 77 #include "core/page/AutoscrollController.h"
78 #include "core/page/ChromeClient.h" 78 #include "core/page/ChromeClient.h"
79 #include "core/page/DragController.h" 79 #include "core/page/DragController.h"
80 #include "core/page/DragState.h" 80 #include "core/page/DragState.h"
81 #include "core/page/FocusController.h" 81 #include "core/page/FocusController.h"
82 #include "core/page/FrameTree.h" 82 #include "core/page/FrameTree.h"
83 #include "core/page/Page.h" 83 #include "core/page/Page.h"
84 #include "core/page/SpatialNavigation.h" 84 #include "core/page/SpatialNavigation.h"
85 #include "core/page/TouchAdjustment.h" 85 #include "core/page/TouchAdjustment.h"
86 #include "core/page/scrolling/OverscrollController.h"
86 #include "core/page/scrolling/ScrollState.h" 87 #include "core/page/scrolling/ScrollState.h"
87 #include "core/paint/PaintLayer.h" 88 #include "core/paint/PaintLayer.h"
88 #include "core/style/ComputedStyle.h" 89 #include "core/style/ComputedStyle.h"
89 #include "core/svg/SVGDocumentExtensions.h" 90 #include "core/svg/SVGDocumentExtensions.h"
90 #include "platform/PlatformGestureEvent.h" 91 #include "platform/PlatformGestureEvent.h"
91 #include "platform/PlatformKeyboardEvent.h" 92 #include "platform/PlatformKeyboardEvent.h"
92 #include "platform/PlatformTouchEvent.h" 93 #include "platform/PlatformTouchEvent.h"
93 #include "platform/PlatformWheelEvent.h" 94 #include "platform/PlatformWheelEvent.h"
94 #include "platform/RuntimeEnabledFeatures.h" 95 #include "platform/RuntimeEnabledFeatures.h"
95 #include "platform/TraceEvent.h" 96 #include "platform/TraceEvent.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // The minimum amount of time an element stays active after a ShowPress 239 // The minimum amount of time an element stays active after a ShowPress
239 // This is roughly 9 frames, which should be long enough to be noticeable. 240 // This is roughly 9 frames, which should be long enough to be noticeable.
240 static const double minimumActiveInterval = 0.15; 241 static const double minimumActiveInterval = 0.15;
241 242
242 #if OS(MACOSX) 243 #if OS(MACOSX)
243 static const double TextDragDelay = 0.15; 244 static const double TextDragDelay = 0.15;
244 #else 245 #else
245 static const double TextDragDelay = 0.0; 246 static const double TextDragDelay = 0.0;
246 #endif 247 #endif
247 248
248 // Report Overscroll if OverscrollDelta is greater than minimumOverscrollDelta
249 // to maintain consistency as did in compositor.
250 static const float minimumOverscrollDelta = 0.1;
251
252 enum NoCursorChangeType { NoCursorChange }; 249 enum NoCursorChangeType { NoCursorChange };
253 250
254 enum class DragInitiator { Mouse, Touch }; 251 enum class DragInitiator { Mouse, Touch };
255 252
256 class OptionalCursor { 253 class OptionalCursor {
257 public: 254 public:
258 OptionalCursor(NoCursorChangeType) : m_isCursorChange(false) { } 255 OptionalCursor(NoCursorChangeType) : m_isCursorChange(false) { }
259 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs or) { } 256 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs or) { }
260 257
261 bool isCursorChange() const { return m_isCursorChange; } 258 bool isCursorChange() const { return m_isCursorChange; }
(...skipping 12 matching lines...) Expand all
274 , m_selectionController(SelectionController::create(*frame)) 271 , m_selectionController(SelectionController::create(*frame))
275 , m_hoverTimer(this, &EventHandler::hoverTimerFired) 272 , m_hoverTimer(this, &EventHandler::hoverTimerFired)
276 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired) 273 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
277 , m_mouseDownMayStartAutoscroll(false) 274 , m_mouseDownMayStartAutoscroll(false)
278 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d) 275 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d)
279 , m_svgPan(false) 276 , m_svgPan(false)
280 , m_resizeScrollableArea(nullptr) 277 , m_resizeScrollableArea(nullptr)
281 , m_eventHandlerWillResetCapturingMouseEventsNode(0) 278 , m_eventHandlerWillResetCapturingMouseEventsNode(0)
282 , m_clickCount(0) 279 , m_clickCount(0)
283 , m_shouldOnlyFireDragOverEvent(false) 280 , m_shouldOnlyFireDragOverEvent(false)
284 , m_accumulatedRootOverscroll(FloatSize())
285 , m_mousePositionIsUnknown(true) 281 , m_mousePositionIsUnknown(true)
286 , m_mouseDownTimestamp(0) 282 , m_mouseDownTimestamp(0)
287 , m_touchPressed(false) 283 , m_touchPressed(false)
288 , m_scrollGestureHandlingNode(nullptr) 284 , m_scrollGestureHandlingNode(nullptr)
289 , m_lastGestureScrollOverWidget(false) 285 , m_lastGestureScrollOverWidget(false)
290 , m_longTapShouldInvokeContextMenu(false) 286 , m_longTapShouldInvokeContextMenu(false)
291 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 287 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
292 , m_lastShowPressTimestamp(0) 288 , m_lastShowPressTimestamp(0)
293 , m_deltaConsumedForScrollSequence(false) 289 , m_deltaConsumedForScrollSequence(false)
294 { 290 {
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 } 2272 }
2277 2273
2278 if (mouseUpEventResult == WebInputEventResult::NotHandled) 2274 if (mouseUpEventResult == WebInputEventResult::NotHandled)
2279 mouseUpEventResult = handleMouseReleaseEvent(MouseEventWithHitTestResult s(fakeMouseUp, currentHitTest)); 2275 mouseUpEventResult = handleMouseReleaseEvent(MouseEventWithHitTestResult s(fakeMouseUp, currentHitTest));
2280 2276
2281 WebInputEventResult eventResult = mergeEventResult(mergeEventResult(mouseDow nEventResult, mouseUpEventResult), clickEventResult); 2277 WebInputEventResult eventResult = mergeEventResult(mergeEventResult(mouseDow nEventResult, mouseUpEventResult), clickEventResult);
2282 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame- >page()) { 2278 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame- >page()) {
2283 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion(); 2279 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion();
2284 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion(); 2280 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion();
2285 2281
2286 IntPoint tappedPositionInViewport = m_frame->page()->frameHost().visualV iewport().rootFrameToViewport(tappedPosition); 2282 IntPoint tappedPositionInViewport = frameHost()->visualViewport().rootFr ameToViewport(tappedPosition);
2287 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode, domTreeChanged || styleChanged); 2283 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode, domTreeChanged || styleChanged);
2288 } 2284 }
2289 return eventResult; 2285 return eventResult;
2290 } 2286 }
2291 2287
2292 WebInputEventResult EventHandler::handleGestureLongPress(const GestureEventWithH itTestResults& targetedEvent) 2288 WebInputEventResult EventHandler::handleGestureLongPress(const GestureEventWithH itTestResults& targetedEvent)
2293 { 2289 {
2294 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2290 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2295 IntPoint adjustedPoint = gestureEvent.position(); 2291 IntPoint adjustedPoint = gestureEvent.position();
2296 2292
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2440 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedFor ScrollSequence; 2436 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedFor ScrollSequence;
2441 ScrollState* scrollState = ScrollState::create(scrollStateData.release() ); 2437 ScrollState* scrollState = ScrollState::create(scrollStateData.release() );
2442 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState); 2438 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState);
2443 } else { 2439 } else {
2444 if (m_frame->isMainFrame()) 2440 if (m_frame->isMainFrame())
2445 m_frame->host()->topControls().scrollBegin(); 2441 m_frame->host()->topControls().scrollBegin();
2446 } 2442 }
2447 return WebInputEventResult::HandledSystem; 2443 return WebInputEventResult::HandledSystem;
2448 } 2444 }
2449 2445
2450 void EventHandler::resetOverscroll(bool didScrollX, bool didScrollY)
2451 {
2452 if (didScrollX)
2453 m_accumulatedRootOverscroll.setWidth(0);
2454 if (didScrollY)
2455 m_accumulatedRootOverscroll.setHeight(0);
2456 }
2457
2458 static inline FloatSize adjustOverscroll(FloatSize unusedDelta)
2459 {
2460 if (std::abs(unusedDelta.width()) < minimumOverscrollDelta)
2461 unusedDelta.setWidth(0);
2462 if (std::abs(unusedDelta.height()) < minimumOverscrollDelta)
2463 unusedDelta.setHeight(0);
2464
2465 return unusedDelta;
2466 }
2467
2468 void EventHandler::handleOverscroll(const ScrollResult& scrollResult, const Floa tPoint& positionInRootFrame, const FloatSize& velocityInRootFrame)
2469 {
2470 ASSERT(m_frame->isMainFrame());
2471 VisualViewport& visualViewport = m_frame->page()->frameHost().visualViewport ();
2472
2473 FloatSize unusedDelta(scrollResult.unusedScrollDeltaX, scrollResult.unusedSc rollDeltaY);
2474 unusedDelta = adjustOverscroll(unusedDelta);
2475
2476 FloatSize deltaInViewport = unusedDelta.scaledBy(visualViewport.scale());
2477 FloatSize velocityInViewport = velocityInRootFrame.scaledBy(visualViewport.s cale());
2478 FloatPoint positionInViewport =
2479 visualViewport.rootFrameToViewport(positionInRootFrame);
2480
2481 resetOverscroll(scrollResult.didScrollX, scrollResult.didScrollY);
2482 if (deltaInViewport != FloatSize()) {
2483 m_accumulatedRootOverscroll += deltaInViewport;
2484 m_frame->chromeClient().didOverscroll(deltaInViewport, m_accumulatedRoot Overscroll, positionInViewport, velocityInViewport);
2485 }
2486 }
2487
2488 bool EventHandler::isRootScroller(const Node& node) const 2446 bool EventHandler::isRootScroller(const Node& node) const
2489 { 2447 {
2490 // The root scroller is the one Element on the page designated to perform 2448 // The root scroller is the one Element on the page designated to perform
2491 // "viewport actions" like top controls movement and overscroll glow. 2449 // "viewport actions" like top controls movement and overscroll glow.
2492 2450
2493 if (!node.isElementNode() || node.document().ownerElement()) 2451 if (!node.isElementNode() || node.document().ownerElement())
2494 return false; 2452 return false;
2495 2453
2496 Element* scrollingElement = node.document().scrollingElement(); 2454 Element* scrollingElement = node.document().scrollingElement();
2497 return scrollingElement 2455 return scrollingElement
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 delta, 2534 delta,
2577 FloatPoint(gestureEvent.position()), 2535 FloatPoint(gestureEvent.position()),
2578 velocity, 2536 velocity,
2579 node, 2537 node,
2580 &stopNode, 2538 &stopNode,
2581 &consumed); 2539 &consumed);
2582 2540
2583 if (gestureEvent.preventPropagation()) 2541 if (gestureEvent.preventPropagation())
2584 m_previousGestureScrolledNode = stopNode; 2542 m_previousGestureScrolledNode = stopNode;
2585 2543
2586 if (!stopNode || !isRootScroller(*stopNode)) 2544 if ((!stopNode || !isRootScroller(*stopNode)) && frameHost()) {
2587 resetOverscroll(result.didScrollX, result.didScrollY); 2545 frameHost()->overscrollController().resetAccumulated(
2546 result.didScrollX, result.didScrollY);
2547 }
2588 2548
2589 if (consumed) 2549 if (consumed)
2590 return WebInputEventResult::HandledSystem; 2550 return WebInputEventResult::HandledSystem;
2591 } 2551 }
2592 } 2552 }
2593 2553
2594 return WebInputEventResult::NotHandled; 2554 return WebInputEventResult::NotHandled;
2595 } 2555 }
2596 2556
2597 void EventHandler::clearGestureScrollState() 2557 void EventHandler::clearGestureScrollState()
2598 { 2558 {
2599 m_scrollGestureHandlingNode = nullptr; 2559 m_scrollGestureHandlingNode = nullptr;
2600 m_previousGestureScrolledNode = nullptr; 2560 m_previousGestureScrolledNode = nullptr;
2601 m_deltaConsumedForScrollSequence = false; 2561 m_deltaConsumedForScrollSequence = false;
2602 m_currentScrollChain.clear(); 2562 m_currentScrollChain.clear();
2603 m_accumulatedRootOverscroll = FloatSize(); 2563
2564 if (FrameHost* host = frameHost())
2565 host->overscrollController().resetAccumulated(true, true);
2604 } 2566 }
2605 2567
2606 bool EventHandler::isScrollbarHandlingGestures() const 2568 bool EventHandler::isScrollbarHandlingGestures() const
2607 { 2569 {
2608 return m_scrollbarHandlingScrollGesture.get(); 2570 return m_scrollbarHandlingScrollGesture.get();
2609 } 2571 }
2610 2572
2611 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const 2573 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const
2612 { 2574 {
2613 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled()) 2575 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled())
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2962 #if OS(WIN) 2924 #if OS(WIN)
2963 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT); 2925 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT);
2964 #else 2926 #else
2965 int rightAligned = 0; 2927 int rightAligned = 0;
2966 #endif 2928 #endif
2967 IntPoint locationInRootFrame; 2929 IntPoint locationInRootFrame;
2968 2930
2969 Element* focusedElement = overrideTargetElement ? overrideTargetElement : do c->focusedElement(); 2931 Element* focusedElement = overrideTargetElement ? overrideTargetElement : do c->focusedElement();
2970 FrameSelection& selection = m_frame->selection(); 2932 FrameSelection& selection = m_frame->selection();
2971 Position start = selection.selection().start(); 2933 Position start = selection.selection().start();
2972 VisualViewport& visualViewport = m_frame->page()->frameHost().visualViewport (); 2934 VisualViewport& visualViewport = frameHost()->visualViewport();
2973 2935
2974 if (!overrideTargetElement && start.anchorNode() && (selection.rootEditableE lement() || selection.isRange())) { 2936 if (!overrideTargetElement && start.anchorNode() && (selection.rootEditableE lement() || selection.isRange())) {
2975 IntRect firstRect = m_frame->editor().firstRectForRange(selection.select ion().toNormalizedEphemeralRange()); 2937 IntRect firstRect = m_frame->editor().firstRectForRange(selection.select ion().toNormalizedEphemeralRange());
2976 2938
2977 int x = rightAligned ? firstRect.maxX() : firstRect.x(); 2939 int x = rightAligned ? firstRect.maxX() : firstRect.x();
2978 // In a multiline edit, firstRect.maxY() would endup on the next line, s o -1. 2940 // In a multiline edit, firstRect.maxY() would endup on the next line, s o -1.
2979 int y = firstRect.maxY() ? firstRect.maxY() - 1 : 0; 2941 int y = firstRect.maxY() ? firstRect.maxY() - 1 : 0;
2980 locationInRootFrame = view->contentsToRootFrame(IntPoint(x, y)); 2942 locationInRootFrame = view->contentsToRootFrame(IntPoint(x, y));
2981 } else if (focusedElement) { 2943 } else if (focusedElement) {
2982 IntRect clippedRect = focusedElement->boundsInViewport(); 2944 IntRect clippedRect = focusedElement->boundsInViewport();
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 4065
4104 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4066 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4105 { 4067 {
4106 #if OS(MACOSX) 4068 #if OS(MACOSX)
4107 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4069 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4108 #else 4070 #else
4109 return PlatformEvent::AltKey; 4071 return PlatformEvent::AltKey;
4110 #endif 4072 #endif
4111 } 4073 }
4112 4074
4075 FrameHost* EventHandler::frameHost()
4076 {
4077 if (!m_frame->page())
4078 return nullptr;
4079
4080 return &m_frame->page()->frameHost();
4081 }
4082
4113 } // namespace blink 4083 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698