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

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: Made ChromeClient a traced Member<> Created 4 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #include "core/loader/FrameLoaderClient.h" 77 #include "core/loader/FrameLoaderClient.h"
78 #include "core/page/AutoscrollController.h" 78 #include "core/page/AutoscrollController.h"
79 #include "core/page/ChromeClient.h" 79 #include "core/page/ChromeClient.h"
80 #include "core/page/DragController.h" 80 #include "core/page/DragController.h"
81 #include "core/page/DragState.h" 81 #include "core/page/DragState.h"
82 #include "core/page/FocusController.h" 82 #include "core/page/FocusController.h"
83 #include "core/page/FrameTree.h" 83 #include "core/page/FrameTree.h"
84 #include "core/page/Page.h" 84 #include "core/page/Page.h"
85 #include "core/page/SpatialNavigation.h" 85 #include "core/page/SpatialNavigation.h"
86 #include "core/page/TouchAdjustment.h" 86 #include "core/page/TouchAdjustment.h"
87 #include "core/page/scrolling/OverscrollController.h"
87 #include "core/page/scrolling/ScrollState.h" 88 #include "core/page/scrolling/ScrollState.h"
88 #include "core/paint/PaintLayer.h" 89 #include "core/paint/PaintLayer.h"
89 #include "core/style/ComputedStyle.h" 90 #include "core/style/ComputedStyle.h"
90 #include "core/svg/SVGDocumentExtensions.h" 91 #include "core/svg/SVGDocumentExtensions.h"
91 #include "platform/Histogram.h" 92 #include "platform/Histogram.h"
92 #include "platform/PlatformGestureEvent.h" 93 #include "platform/PlatformGestureEvent.h"
93 #include "platform/PlatformKeyboardEvent.h" 94 #include "platform/PlatformKeyboardEvent.h"
94 #include "platform/PlatformTouchEvent.h" 95 #include "platform/PlatformTouchEvent.h"
95 #include "platform/PlatformWheelEvent.h" 96 #include "platform/PlatformWheelEvent.h"
96 #include "platform/RuntimeEnabledFeatures.h" 97 #include "platform/RuntimeEnabledFeatures.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // The minimum amount of time an element stays active after a ShowPress 288 // The minimum amount of time an element stays active after a ShowPress
288 // This is roughly 9 frames, which should be long enough to be noticeable. 289 // This is roughly 9 frames, which should be long enough to be noticeable.
289 static const double minimumActiveInterval = 0.15; 290 static const double minimumActiveInterval = 0.15;
290 291
291 #if OS(MACOSX) 292 #if OS(MACOSX)
292 static const double TextDragDelay = 0.15; 293 static const double TextDragDelay = 0.15;
293 #else 294 #else
294 static const double TextDragDelay = 0.0; 295 static const double TextDragDelay = 0.0;
295 #endif 296 #endif
296 297
297 // Report Overscroll if OverscrollDelta is greater than minimumOverscrollDelta
298 // to maintain consistency as did in compositor.
299 static const float minimumOverscrollDelta = 0.1;
300
301 enum NoCursorChangeType { NoCursorChange }; 298 enum NoCursorChangeType { NoCursorChange };
302 299
303 enum class DragInitiator { Mouse, Touch }; 300 enum class DragInitiator { Mouse, Touch };
304 301
305 class OptionalCursor { 302 class OptionalCursor {
306 public: 303 public:
307 OptionalCursor(NoCursorChangeType) : m_isCursorChange(false) { } 304 OptionalCursor(NoCursorChangeType) : m_isCursorChange(false) { }
308 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs or) { } 305 OptionalCursor(const Cursor& cursor) : m_isCursorChange(true), m_cursor(curs or) { }
309 306
310 bool isCursorChange() const { return m_isCursorChange; } 307 bool isCursorChange() const { return m_isCursorChange; }
(...skipping 12 matching lines...) Expand all
323 , m_selectionController(SelectionController::create(*frame)) 320 , m_selectionController(SelectionController::create(*frame))
324 , m_hoverTimer(this, &EventHandler::hoverTimerFired) 321 , m_hoverTimer(this, &EventHandler::hoverTimerFired)
325 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired) 322 , m_cursorUpdateTimer(this, &EventHandler::cursorUpdateTimerFired)
326 , m_mouseDownMayStartAutoscroll(false) 323 , m_mouseDownMayStartAutoscroll(false)
327 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d) 324 , m_fakeMouseMoveEventTimer(this, &EventHandler::fakeMouseMoveEventTimerFire d)
328 , m_svgPan(false) 325 , m_svgPan(false)
329 , m_resizeScrollableArea(nullptr) 326 , m_resizeScrollableArea(nullptr)
330 , m_eventHandlerWillResetCapturingMouseEventsNode(0) 327 , m_eventHandlerWillResetCapturingMouseEventsNode(0)
331 , m_clickCount(0) 328 , m_clickCount(0)
332 , m_shouldOnlyFireDragOverEvent(false) 329 , m_shouldOnlyFireDragOverEvent(false)
333 , m_accumulatedRootOverscroll(FloatSize())
334 , m_mousePositionIsUnknown(true) 330 , m_mousePositionIsUnknown(true)
335 , m_mouseDownTimestamp(0) 331 , m_mouseDownTimestamp(0)
336 , m_touchPressed(false) 332 , m_touchPressed(false)
337 , m_scrollGestureHandlingNode(nullptr) 333 , m_scrollGestureHandlingNode(nullptr)
338 , m_lastGestureScrollOverWidget(false) 334 , m_lastGestureScrollOverWidget(false)
339 , m_longTapShouldInvokeContextMenu(false) 335 , m_longTapShouldInvokeContextMenu(false)
340 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired) 336 , m_activeIntervalTimer(this, &EventHandler::activeIntervalTimerFired)
341 , m_lastShowPressTimestamp(0) 337 , m_lastShowPressTimestamp(0)
342 , m_deltaConsumedForScrollSequence(false) 338 , m_deltaConsumedForScrollSequence(false)
343 , m_waitingForFirstTouchMove(false) 339 , m_waitingForFirstTouchMove(false)
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 } 2321 }
2326 2322
2327 if (mouseUpEventResult == WebInputEventResult::NotHandled) 2323 if (mouseUpEventResult == WebInputEventResult::NotHandled)
2328 mouseUpEventResult = handleMouseReleaseEvent(MouseEventWithHitTestResult s(fakeMouseUp, currentHitTest)); 2324 mouseUpEventResult = handleMouseReleaseEvent(MouseEventWithHitTestResult s(fakeMouseUp, currentHitTest));
2329 2325
2330 WebInputEventResult eventResult = mergeEventResult(mergeEventResult(mouseDow nEventResult, mouseUpEventResult), clickEventResult); 2326 WebInputEventResult eventResult = mergeEventResult(mergeEventResult(mouseDow nEventResult, mouseUpEventResult), clickEventResult);
2331 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame- >page()) { 2327 if (eventResult == WebInputEventResult::NotHandled && tappedNode && m_frame- >page()) {
2332 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion(); 2328 bool domTreeChanged = preDispatchDomTreeVersion != m_frame->document()-> domTreeVersion();
2333 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion(); 2329 bool styleChanged = preDispatchStyleVersion != m_frame->document()->styl eVersion();
2334 2330
2335 IntPoint tappedPositionInViewport = m_frame->page()->frameHost().visualV iewport().rootFrameToViewport(tappedPosition); 2331 IntPoint tappedPositionInViewport = frameHost()->visualViewport().rootFr ameToViewport(tappedPosition);
2336 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode, domTreeChanged || styleChanged); 2332 m_frame->chromeClient().showUnhandledTapUIIfNeeded(tappedPositionInViewp ort, tappedNode, domTreeChanged || styleChanged);
2337 } 2333 }
2338 return eventResult; 2334 return eventResult;
2339 } 2335 }
2340 2336
2341 WebInputEventResult EventHandler::handleGestureLongPress(const GestureEventWithH itTestResults& targetedEvent) 2337 WebInputEventResult EventHandler::handleGestureLongPress(const GestureEventWithH itTestResults& targetedEvent)
2342 { 2338 {
2343 const PlatformGestureEvent& gestureEvent = targetedEvent.event(); 2339 const PlatformGestureEvent& gestureEvent = targetedEvent.event();
2344 IntPoint adjustedPoint = gestureEvent.position(); 2340 IntPoint adjustedPoint = gestureEvent.position();
2345 2341
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2489 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedFor ScrollSequence; 2485 scrollStateData->delta_consumed_for_scroll_sequence = m_deltaConsumedFor ScrollSequence;
2490 ScrollState* scrollState = ScrollState::create(scrollStateData.release() ); 2486 ScrollState* scrollState = ScrollState::create(scrollStateData.release() );
2491 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState); 2487 customizedScroll(*m_scrollGestureHandlingNode.get(), *scrollState);
2492 } else { 2488 } else {
2493 if (m_frame->isMainFrame()) 2489 if (m_frame->isMainFrame())
2494 m_frame->host()->topControls().scrollBegin(); 2490 m_frame->host()->topControls().scrollBegin();
2495 } 2491 }
2496 return WebInputEventResult::HandledSystem; 2492 return WebInputEventResult::HandledSystem;
2497 } 2493 }
2498 2494
2499 void EventHandler::resetOverscroll(bool didScrollX, bool didScrollY)
2500 {
2501 if (didScrollX)
2502 m_accumulatedRootOverscroll.setWidth(0);
2503 if (didScrollY)
2504 m_accumulatedRootOverscroll.setHeight(0);
2505 }
2506
2507 static inline FloatSize adjustOverscroll(FloatSize unusedDelta)
2508 {
2509 if (std::abs(unusedDelta.width()) < minimumOverscrollDelta)
2510 unusedDelta.setWidth(0);
2511 if (std::abs(unusedDelta.height()) < minimumOverscrollDelta)
2512 unusedDelta.setHeight(0);
2513
2514 return unusedDelta;
2515 }
2516
2517 void EventHandler::handleOverscroll(const ScrollResult& scrollResult, const Floa tPoint& positionInRootFrame, const FloatSize& velocityInRootFrame)
2518 {
2519 ASSERT(m_frame->isMainFrame());
2520 VisualViewport& visualViewport = m_frame->page()->frameHost().visualViewport ();
2521
2522 FloatSize unusedDelta(scrollResult.unusedScrollDeltaX, scrollResult.unusedSc rollDeltaY);
2523 unusedDelta = adjustOverscroll(unusedDelta);
2524
2525 FloatSize deltaInViewport = unusedDelta.scaledBy(visualViewport.scale());
2526 FloatSize velocityInViewport = velocityInRootFrame.scaledBy(visualViewport.s cale());
2527 FloatPoint positionInViewport =
2528 visualViewport.rootFrameToViewport(positionInRootFrame);
2529
2530 resetOverscroll(scrollResult.didScrollX, scrollResult.didScrollY);
2531 if (deltaInViewport != FloatSize()) {
2532 m_accumulatedRootOverscroll += deltaInViewport;
2533 m_frame->chromeClient().didOverscroll(deltaInViewport, m_accumulatedRoot Overscroll, positionInViewport, velocityInViewport);
2534 }
2535 }
2536
2537 bool EventHandler::isRootScroller(const Node& node) const 2495 bool EventHandler::isRootScroller(const Node& node) const
2538 { 2496 {
2539 // The root scroller is the one Element on the page designated to perform 2497 // The root scroller is the one Element on the page designated to perform
2540 // "viewport actions" like top controls movement and overscroll glow. 2498 // "viewport actions" like top controls movement and overscroll glow.
2541 2499
2542 if (!node.isElementNode() || node.document().ownerElement()) 2500 if (!node.isElementNode() || node.document().ownerElement())
2543 return false; 2501 return false;
2544 2502
2545 Element* scrollingElement = node.document().scrollingElement(); 2503 Element* scrollingElement = node.document().scrollingElement();
2546 return scrollingElement 2504 return scrollingElement
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2625 delta, 2583 delta,
2626 FloatPoint(gestureEvent.position()), 2584 FloatPoint(gestureEvent.position()),
2627 velocity, 2585 velocity,
2628 node, 2586 node,
2629 &stopNode, 2587 &stopNode,
2630 &consumed); 2588 &consumed);
2631 2589
2632 if (gestureEvent.preventPropagation()) 2590 if (gestureEvent.preventPropagation())
2633 m_previousGestureScrolledNode = stopNode; 2591 m_previousGestureScrolledNode = stopNode;
2634 2592
2635 if (!stopNode || !isRootScroller(*stopNode)) 2593 if ((!stopNode || !isRootScroller(*stopNode)) && frameHost()) {
2636 resetOverscroll(result.didScrollX, result.didScrollY); 2594 frameHost()->overscrollController().resetAccumulated(
2595 result.didScrollX, result.didScrollY);
2596 }
2637 2597
2638 if (consumed) 2598 if (consumed)
2639 return WebInputEventResult::HandledSystem; 2599 return WebInputEventResult::HandledSystem;
2640 } 2600 }
2641 } 2601 }
2642 2602
2643 return WebInputEventResult::NotHandled; 2603 return WebInputEventResult::NotHandled;
2644 } 2604 }
2645 2605
2646 void EventHandler::clearGestureScrollState() 2606 void EventHandler::clearGestureScrollState()
2647 { 2607 {
2648 m_scrollGestureHandlingNode = nullptr; 2608 m_scrollGestureHandlingNode = nullptr;
2649 m_previousGestureScrolledNode = nullptr; 2609 m_previousGestureScrolledNode = nullptr;
2650 m_deltaConsumedForScrollSequence = false; 2610 m_deltaConsumedForScrollSequence = false;
2651 m_currentScrollChain.clear(); 2611 m_currentScrollChain.clear();
2652 m_accumulatedRootOverscroll = FloatSize(); 2612
2613 if (FrameHost* host = frameHost())
2614 host->overscrollController().resetAccumulated(true, true);
dtapuska 2016/04/26 13:53:11 Can you add /*resetX*/, /*resetY*/ comments so it
bokan 2016/04/26 16:09:53 Done. (Used vars instead of comments)
2653 } 2615 }
2654 2616
2655 bool EventHandler::isScrollbarHandlingGestures() const 2617 bool EventHandler::isScrollbarHandlingGestures() const
2656 { 2618 {
2657 return m_scrollbarHandlingScrollGesture.get(); 2619 return m_scrollbarHandlingScrollGesture.get();
2658 } 2620 }
2659 2621
2660 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const 2622 bool EventHandler::shouldApplyTouchAdjustment(const PlatformGestureEvent& event) const
2661 { 2623 {
2662 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled()) 2624 if (m_frame->settings() && !m_frame->settings()->touchAdjustmentEnabled())
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 #if OS(WIN) 2973 #if OS(WIN)
3012 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT); 2974 int rightAligned = ::GetSystemMetrics(SM_MENUDROPALIGNMENT);
3013 #else 2975 #else
3014 int rightAligned = 0; 2976 int rightAligned = 0;
3015 #endif 2977 #endif
3016 IntPoint locationInRootFrame; 2978 IntPoint locationInRootFrame;
3017 2979
3018 Element* focusedElement = overrideTargetElement ? overrideTargetElement : do c->focusedElement(); 2980 Element* focusedElement = overrideTargetElement ? overrideTargetElement : do c->focusedElement();
3019 FrameSelection& selection = m_frame->selection(); 2981 FrameSelection& selection = m_frame->selection();
3020 Position start = selection.selection().start(); 2982 Position start = selection.selection().start();
3021 VisualViewport& visualViewport = m_frame->page()->frameHost().visualViewport (); 2983 VisualViewport& visualViewport = frameHost()->visualViewport();
3022 2984
3023 if (!overrideTargetElement && start.anchorNode() && (selection.rootEditableE lement() || selection.isRange())) { 2985 if (!overrideTargetElement && start.anchorNode() && (selection.rootEditableE lement() || selection.isRange())) {
3024 IntRect firstRect = m_frame->editor().firstRectForRange(selection.select ion().toNormalizedEphemeralRange()); 2986 IntRect firstRect = m_frame->editor().firstRectForRange(selection.select ion().toNormalizedEphemeralRange());
3025 2987
3026 int x = rightAligned ? firstRect.maxX() : firstRect.x(); 2988 int x = rightAligned ? firstRect.maxX() : firstRect.x();
3027 // In a multiline edit, firstRect.maxY() would endup on the next line, s o -1. 2989 // In a multiline edit, firstRect.maxY() would endup on the next line, s o -1.
3028 int y = firstRect.maxY() ? firstRect.maxY() - 1 : 0; 2990 int y = firstRect.maxY() ? firstRect.maxY() - 1 : 0;
3029 locationInRootFrame = view->contentsToRootFrame(IntPoint(x, y)); 2991 locationInRootFrame = view->contentsToRootFrame(IntPoint(x, y));
3030 } else if (focusedElement) { 2992 } else if (focusedElement) {
3031 IntRect clippedRect = focusedElement->boundsInViewport(); 2993 IntRect clippedRect = focusedElement->boundsInViewport();
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
4169 4131
4170 PlatformEvent::Modifiers EventHandler::accessKeyModifiers() 4132 PlatformEvent::Modifiers EventHandler::accessKeyModifiers()
4171 { 4133 {
4172 #if OS(MACOSX) 4134 #if OS(MACOSX)
4173 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey); 4135 return static_cast<PlatformEvent::Modifiers>(PlatformEvent::CtrlKey | Platfo rmEvent::AltKey);
4174 #else 4136 #else
4175 return PlatformEvent::AltKey; 4137 return PlatformEvent::AltKey;
4176 #endif 4138 #endif
4177 } 4139 }
4178 4140
4141 FrameHost* EventHandler::frameHost()
4142 {
4143 if (!m_frame->page())
4144 return nullptr;
4145
4146 return &m_frame->page()->frameHost();
4147 }
4148
4179 } // namespace blink 4149 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698