Skip to content

Commit

Permalink
Send "isMonitoringWheelEvents" to the UI process
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=249450
rdar://103434051

Reviewed by Brent Fulgham.

A test can do:
    eventSender.monitorWheelEvents();
    eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, 'began', 'none');

which means that we need to be able to start monitoring wheel events (in the
UI process if UI-side compositing is enabled) before the IPC to synthesize the
first wheel event is received.

Code exists to update the "isMonitoringWheelEvents" state on ScrollingTree via
scrolling tree commits (which reach the UI process after each rendering update),
but that's too late for this case; we need a direct IPC call.

So when EventSender::monitorWheelEvents() is called in the web process, post
an "EventSender" message which is handled by TestController::didReceiveMessageFromInjectedBundle()
and passed to EventSenderProxy, which gets it to RemoteScrollingCoordinatorProxy via
WKWebView testing SPI, and WebPageProxy. RemoteScrollingCoordinatorProxy can then set
state on the ScrollingTree in the UI process.

* Source/WebCore/page/scrolling/ScrollingTree.h:
(WebCore::ScrollingTree::setIsMonitoringWheelEvents):
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _startMonitoringWheelEvents]):
* Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.cpp:
(WebKit::RemoteScrollingCoordinatorProxy::startMonitoringWheelEventsForTesting):
* Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::startMonitoringWheelEventsForTesting):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Tools/WebKitTestRunner/EventSenderProxy.h:
* Tools/WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
(WTR::EventSendingController::monitorWheelEvents):
* Tools/WebKitTestRunner/InjectedBundle/ios/EventSenderProxyIOS.mm:
(WTR::EventSenderProxy::monitorWheelEvents):
* Tools/WebKitTestRunner/TestController.cpp:
(WTR::TestController::didReceiveMessageFromInjectedBundle):
* Tools/WebKitTestRunner/gtk/EventSenderProxyGtk.cpp:
(WTR::EventSenderProxy::monitorWheelEvents):
* Tools/WebKitTestRunner/libwpe/EventSenderProxyLibWPE.cpp:
(WTR::EventSenderProxy::monitorWheelEvents):
* Tools/WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::monitorWheelEvents):
* Tools/WebKitTestRunner/win/EventSenderProxyWin.cpp:
(WTR::EventSenderProxy::monitorWheelEvents):

Canonical link: https://commits.webkit.org/258002@main
  • Loading branch information
smfr committed Dec 16, 2022
1 parent 05e5d95 commit e505e7f
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/page/scrolling/ScrollingTree.h
Expand Up @@ -213,6 +213,7 @@ class ScrollingTree : public ThreadSafeRefCounted<ScrollingTree> {
WEBCORE_EXPORT String scrollingTreeAsText(OptionSet<ScrollingStateTreeAsTextBehavior> = { });

bool isMonitoringWheelEvents() const { return m_isMonitoringWheelEvents; }
void setIsMonitoringWheelEvents(bool b) { m_isMonitoringWheelEvents = b; }
bool inCommitTreeState() const { return m_inCommitTreeState; }

void scrollBySimulatingWheelEventForTesting(ScrollingNodeID, FloatSize);
Expand Down
Expand Up @@ -91,6 +91,7 @@ struct WKAppPrivacyReportTestingData {
- (void)_setThrottleStateForTesting:(int)type;

- (void)_doAfterProcessingAllPendingMouseEvents:(dispatch_block_t)action;
- (void)_startMonitoringWheelEvents;

+ (void)_setApplicationBundleIdentifier:(NSString *)bundleIdentifier;
+ (void)_clearApplicationBundleIdentifierTestingOverride;
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm
Expand Up @@ -293,6 +293,11 @@ - (void)_doAfterProcessingAllPendingMouseEvents:(dispatch_block_t)action
});
}

- (void)_startMonitoringWheelEvents
{
_page->startMonitoringWheelEventsForTesting();
}

+ (void)_setApplicationBundleIdentifier:(NSString *)bundleIdentifier
{
WebCore::setApplicationBundleIdentifierOverride(String(bundleIdentifier));
Expand Down
Expand Up @@ -286,6 +286,11 @@ void RemoteScrollingCoordinatorProxy::reportSynchronousScrollingReasonsChanged(M
m_webPageProxy.logScrollingEvent(static_cast<uint32_t>(PerformanceLoggingClient::ScrollingEvent::SwitchedScrollingMode), timestamp, reasons.toRaw());
}

void RemoteScrollingCoordinatorProxy::startMonitoringWheelEventsForTesting()
{
m_scrollingTree->setIsMonitoringWheelEvents(true);
}

} // namespace WebKit

#endif // ENABLE(UI_SIDE_COMPOSITING)
Expand Up @@ -33,6 +33,7 @@
#include "RemoteScrollingUIState.h"
#include <WebCore/GraphicsLayer.h>
#include <WebCore/ScrollSnapOffsetsInfo.h>
#include <WebCore/WheelEventTestMonitor.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
#include <wtf/WeakPtr.h>
Expand Down Expand Up @@ -124,6 +125,8 @@ class RemoteScrollingCoordinatorProxy : public CanMakeWeakPtr<RemoteScrollingCoo
void reportExposedUnfilledArea(MonotonicTime, unsigned unfilledArea);
void reportSynchronousScrollingReasonsChanged(MonotonicTime, OptionSet<WebCore::SynchronousScrollingReason>);

void startMonitoringWheelEventsForTesting();

protected:
RemoteScrollingTree* scrollingTree() const { return m_scrollingTree.get(); }

Expand Down
8 changes: 8 additions & 0 deletions Source/WebKit/UIProcess/WebPageProxy.cpp
Expand Up @@ -3072,6 +3072,14 @@ void WebPageProxy::handleWheelEvent(const NativeWebWheelEvent& event)
}
}

void WebPageProxy::startMonitoringWheelEventsForTesting()
{
#if ENABLE(ASYNC_SCROLLING) && PLATFORM(COCOA)
if (m_scrollingCoordinatorProxy)
m_scrollingCoordinatorProxy->startMonitoringWheelEventsForTesting();
#endif
}

#if HAVE(CVDISPLAYLINK)
void WebPageProxy::wheelEventHysteresisUpdated(PAL::HysteresisState)
{
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/WebPageProxy.h
Expand Up @@ -1053,6 +1053,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>

bool isProcessingWheelEvents() const;
void handleWheelEvent(const NativeWebWheelEvent&);
void startMonitoringWheelEventsForTesting();

bool isProcessingKeyboardEvents() const;
bool handleKeyboardEvent(const NativeWebKeyboardEvent&);
Expand Down
1 change: 1 addition & 0 deletions Tools/WebKitTestRunner/EventSenderProxy.h
Expand Up @@ -68,6 +68,7 @@ class EventSenderProxy {
void setWheelHasPreciseDeltas(bool);
#endif
void continuousMouseScrollBy(int x, int y, bool paged);
void monitorWheelEvents();

#if PLATFORM(MAC)
enum class WheelEventPhase : uint8_t {
Expand Down
Expand Up @@ -516,6 +516,10 @@ void EventSendingController::monitorWheelEvents(MonitorWheelEventsOptions* optio
m_sentWheelPhaseEndOrCancel = false;
m_sentWheelMomentumPhaseEnd = false;
WKBundlePageStartMonitoringScrollOperations(page, options ? options->resetLatching : true);

auto body = adoptWK(WKMutableDictionaryCreate());
setValue(body, "SubMessage", "MonitorWheelEvents");
postPageMessage("EventSender", body);
}

struct ScrollCompletionCallbackData {
Expand Down
Expand Up @@ -99,6 +99,10 @@
{
}

void EventSenderProxy::monitorWheelEvents()
{
}

#if ENABLE(TOUCH_EVENTS)

void EventSenderProxy::addTouchPoint(int x, int y)
Expand Down
5 changes: 5 additions & 0 deletions Tools/WebKitTestRunner/TestController.cpp
Expand Up @@ -1861,6 +1861,11 @@ void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName
return;
}

if (WKStringIsEqualToUTF8CString(subMessageName, "MonitorWheelEvents")) {
m_eventSenderProxy->monitorWheelEvents();
return;
}

#if PLATFORM(GTK)
if (WKStringIsEqualToUTF8CString(subMessageName, "SetWheelHasPreciseDeltas")) {
auto hasPreciseDeltas = booleanValue(dictionary, "HasPreciseDeltas");
Expand Down
4 changes: 4 additions & 0 deletions Tools/WebKitTestRunner/gtk/EventSenderProxyGtk.cpp
Expand Up @@ -312,6 +312,10 @@ void EventSenderProxy::continuousMouseScrollBy(int horizontal, int vertical, boo
horizontal / pixelsPerScrollTick, vertical / pixelsPerScrollTick, m_position.x, m_position.y, WheelEventPhase::NoPhase, WheelEventPhase::NoPhase, m_hasPreciseDeltas);
}

void EventSenderProxy::monitorWheelEvents()
{
}

void EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases(int horizontal, int vertical, int phase, int momentum)
{
WheelEventPhase eventPhase = WheelEventPhase::NoPhase;
Expand Down
4 changes: 4 additions & 0 deletions Tools/WebKitTestRunner/libwpe/EventSenderProxyLibWPE.cpp
Expand Up @@ -194,6 +194,10 @@ void EventSenderProxy::continuousMouseScrollBy(int, int, bool)
{
}

void EventSenderProxy::monitorWheelEvents()
{
}

void EventSenderProxy::leapForward(int milliseconds)
{
m_time += milliseconds / 1000.0;
Expand Down
6 changes: 6 additions & 0 deletions Tools/WebKitTestRunner/mac/EventSenderProxy.mm
Expand Up @@ -39,6 +39,7 @@
#import <WebKit/WKPagePrivate.h>
#import <WebKit/WKWebView.h>
#import <WebKit/WKWebViewPrivate.h>
#import <WebKit/WKWebViewPrivateForTesting.h>
#import <pal/spi/cocoa/IOKitSPI.h>
#import <wtf/RetainPtr.h>
#import <wtf/cocoa/TypeCastsCocoa.h>
Expand Down Expand Up @@ -823,6 +824,11 @@ static CGMomentumScrollPhase cgMomentumPhaseFromPhase(EventSenderProxy::WheelEve
}
}

void EventSenderProxy::monitorWheelEvents()
{
[m_testController->mainWebView()->platformView() _startMonitoringWheelEvents];
}

#if ENABLE(MAC_GESTURE_EVENTS)

void EventSenderProxy::scaleGestureStart(double scale)
Expand Down
4 changes: 4 additions & 0 deletions Tools/WebKitTestRunner/win/EventSenderProxyWin.cpp
Expand Up @@ -149,6 +149,10 @@ void EventSenderProxy::continuousMouseScrollBy(int, int, bool)
{
}

void EventSenderProxy::monitorWheelEvents()
{
}

void EventSenderProxy::leapForward(int milliseconds)
{
Sleep(milliseconds);
Expand Down

0 comments on commit e505e7f

Please sign in to comment.