haikuwebkit/Source/WebCore/page/scrolling/ScrollLatchingController.h

99 lines
3.3 KiB
C
Raw Permalink Normal View History

Rewrite main thread scroll latching logic https://bugs.webkit.org/show_bug.cgi?id=215979 Reviewed by Tim Horton. Source/WebCore: The existing main thread wheel event handling and latching logic had a number of issues, some of which were indicated via the FIXME comments added in r266016: - It tracked scrollable containers as ContainerNodes rather than ScrollableAreas - It fetched and used latched state from a different frame, causing an EventHandler to end up scrolling some unrelated frame. - Overflow scrolling ignored latched state. - The latching stack's purpose was unclear. This patch fixes those issues. The design is as follow: - Latching logic is moved into ScrollLatchingController, which is owned by Page. - ScrollLatchingController owns a stack of FrameState. - When receiving a wheel event, determineWheelEventTarget() identifies the target ScrollableArea, if any, for that frame only. - As hit-testing descends into subframes, state is pushed onto ScrollLatchingController's state stack. Frames with potential scrollers have a non-null ScrollableArea in their state. - The latched ScrollableArea is the top non-null ScrollableArea in this stack. - EventHandler consults ScrollLatchingController for select, overflow and frame scrolling. This change fixes an issue where scrolling over an overflow:scroll in the non-fast scrollable region would rubber-band the overflow, rather than the main page (tested by the adjusted fast/scrolling/mac/rubberband-overflow-in-wheel-region.html). Tests: fast/scrolling/latching/latched-scroll-remove-iframe.html * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * dom/Element.cpp: (WebCore::Element::removedFromAncestor): * page/EventHandler.cpp: (WebCore::EventHandler::EventHandler): (WebCore::EventHandler::determineWheelEventTarget): (WebCore::EventHandler::processWheelEventForScrolling): (WebCore::EventHandler::platformCompletePlatformWidgetWheelEvent): (WebCore::EventHandler::processWheelEventForScrollSnap): (WebCore::EventHandler::completeWidgetWheelEvent): (WebCore::EventHandler::handleWheelEvent): (WebCore::EventHandler::clearLatchedState): (WebCore::EventHandler::defaultWheelEventHandler): (WebCore::EventHandler::clearLatchedStateTimerFired): Deleted. (WebCore::EventHandler::clearOrScheduleClearingLatchedStateIfNeeded): Deleted. * page/EventHandler.h: * page/Page.cpp: (WebCore::Page::startMonitoringWheelEvents): (WebCore::Page::scrollLatchingController): (WebCore::Page::scrollLatchingControllerIfExists): (WebCore::Page::latchingState): Deleted. (WebCore::Page::pushNewLatchingState): Deleted. (WebCore::Page::resetLatchingState): Deleted. (WebCore::Page::popLatchingState): Deleted. (WebCore::Page::removeLatchingStateForTarget): Deleted. * page/Page.h: (WebCore::Page::latchingStateStack const): Deleted. * page/mac/EventHandlerMac.mm: (WebCore::EventHandler::determineWheelEventTarget): (WebCore::EventHandler::processWheelEventForScrolling): (WebCore::EventHandler::platformCompletePlatformWidgetWheelEvent): (WebCore::EventHandler::processWheelEventForScrollSnap): (WebCore::deltaIsPredominantlyVertical): Deleted. (WebCore::scrolledToEdgeInDominantDirection): Deleted. (WebCore::latchingIsLockedToPlatformFrame): Deleted. (WebCore::latchingIsLockedToAncestorOfThisFrame): Deleted. (WebCore::latchedToFrameOrBody): Deleted. (WebCore::EventHandler::clearOrScheduleClearingLatchedStateIfNeeded): Deleted. (WebCore::frameViewForLatchingState): Deleted. * page/scrolling/ScrollLatchingController.cpp: Added. (WebCore::ScrollLatchingController::ScrollLatchingController): (WebCore::ScrollLatchingController::clear): (WebCore::ScrollLatchingController::clearOrScheduleClearIfNeeded): (WebCore::ScrollLatchingController::clearTimerFired): (WebCore::ScrollLatchingController::receivedWheelEvent): (WebCore::ScrollLatchingController::latchingAllowsScrollingInFrame const): (WebCore::ScrollLatchingController::updateLatchingStateForFrame): (WebCore::ScrollLatchingController::getLatchingStateForFrame const): (WebCore::ScrollLatchingController::removeLatchingStateForTarget): (WebCore::ScrollLatchingController::removeLatchingStateForFrame): (WebCore::deltaIsPredominantlyVertical): (WebCore::ScrollLatchingController::shouldLatchToScrollableArea const): (WebCore::ScrollLatchingController::hasStateForFrame const): (WebCore::ScrollLatchingController::stateForFrame): (WebCore::ScrollLatchingController::stateForFrame const): (WebCore::ScrollLatchingController::dump const): (WebCore::operator<<): * page/scrolling/ScrollLatchingController.h: Added. (WebCore::ScrollLatchingController::cumulativeEventDelta const): * page/scrolling/ScrollLatchingState.cpp: Removed. * page/scrolling/ScrollLatchingState.h: Removed. * page/scrolling/ScrollingTreeLatchingController.cpp: (WebCore::ScrollingTreeLatchingController::receivedWheelEvent): (WebCore::ScrollingTreeLatchingController::nodeDidHandleEvent): * page/scrolling/ThreadedScrollingTree.cpp: (WebCore::ThreadedScrollingTree::handleWheelEventAfterMainThread): * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm: (WebCore::ScrollingTreeScrollingNodeDelegateMac::allowsHorizontalStretching const): (WebCore::ScrollingTreeScrollingNodeDelegateMac::allowsVerticalStretching const): (WebCore::newGestureIsStarting): Deleted. * platform/PlatformWheelEvent.h: (WebCore::PlatformWheelEvent::isGestureStart const): (WebCore::PlatformWheelEvent::isGestureContinuation const): (WebCore::PlatformWheelEvent::shouldResetLatching const): (WebCore::PlatformWheelEvent::isNonGestureEvent const): (WebCore::PlatformWheelEvent::shouldConsiderLatching const): Deleted. Renamed to isGestureStart(). This class should not prescribe latching behaviors. LayoutTests: Add a test for iframe unparenting in the middle of a latched scroll. * fast/scrolling/latching/latched-scroll-remove-iframe.html: Added. * fast/scrolling/latching/scroll-nested-iframe.html: 1000ms -> 0ms * fast/scrolling/mac/rubberband-overflow-in-wheel-region.html: Test needs to latch the overflow by scrolling down then up. Canonical link: https://commits.webkit.org/228769@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266333 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-08-30 17:25:15 +00:00
/*
* Copyright (C) 2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "FloatSize.h"
#include "ScrollTypes.h"
#include "Timer.h"
#include <wtf/RefPtr.h>
#include <wtf/WeakPtr.h>
#if ENABLE(WHEEL_EVENT_LATCHING)
namespace WTF {
class TextStream;
}
namespace WebCore {
class Element;
class Frame;
class PlatformWheelEvent;
class ScrollableArea;
class ScrollLatchingController {
WTF_MAKE_FAST_ALLOCATED;
public:
ScrollLatchingController();
~ScrollLatchingController();
void clear();
void receivedWheelEvent(const PlatformWheelEvent&);
FloatSize cumulativeEventDelta() const { return m_cumulativeEventDelta; }
// Frame containing latched scroller (may be the frame or some sub-scroller).
Frame* latchedFrame() const;
// Returns true if no frame is latched, or latching is in the given frame (in which case latchedScroller will be non-null).
bool latchingAllowsScrollingInFrame(const Frame&, WeakPtr<ScrollableArea>& latchedScroller) const;
void updateAndFetchLatchingStateForFrame(Frame&, const PlatformWheelEvent&, RefPtr<Element>& latchedElement, WeakPtr<ScrollableArea>&, bool& isOverWidget);
void removeLatchingStateForTarget(const Element&);
void removeLatchingStateForFrame(const Frame&);
void dump(WTF::TextStream&) const;
private:
struct FrameState {
WeakPtr<Element> wheelEventElement;
WeakPtr<ScrollableArea> scrollableArea;
Frame* frame { nullptr };
bool isOverWidget { false };
};
void clearOrScheduleClearIfNeeded(const PlatformWheelEvent&);
void clearTimerFired();
bool hasStateForFrame(const Frame&) const;
FrameState* stateForFrame(const Frame&);
const FrameState* stateForFrame(const Frame&) const;
bool shouldLatchToScrollableArea(const Frame&, ScrollableArea*, FloatSize) const;
FloatSize m_cumulativeEventDelta;
Vector<FrameState> m_frameStateStack;
Timer m_clearLatchingStateTimer;
};
WTF::TextStream& operator<<(WTF::TextStream&, const ScrollLatchingController&);
} // namespace WebCore
#endif // ENABLE(WHEEL_EVENT_LATCHING)