WheelEventTestMonitor.cpp [plain text]
#include "config.h"
#include "WheelEventTestMonitor.h"
#include "Logging.h"
#include <wtf/OptionSet.h>
#include <wtf/text/TextStream.h>
#if !LOG_DISABLED
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
#endif
namespace WebCore {
WheelEventTestMonitor::WheelEventTestMonitor()
: m_testForCompletionTimer(RunLoop::current(), this, &WheelEventTestMonitor::triggerTestTimerFired)
{
}
void WheelEventTestMonitor::clearAllTestDeferrals()
{
ASSERT(isMainThread());
m_deferCompletionReasons.clear();
m_completionCallback = nullptr;
m_testForCompletionTimer.stop();
LOG_WITH_STREAM(WheelEventTestMonitor, stream << " (=) WheelEventTestMonitor::clearAllTestDeferrals: cleared all test state.");
}
void WheelEventTestMonitor::setTestCallbackAndStartNotificationTimer(WTF::Function<void()>&& functionCallback)
{
ASSERT(isMainThread());
m_completionCallback = WTFMove(functionCallback);
if (!m_testForCompletionTimer.isActive())
m_testForCompletionTimer.startRepeating(1_s / 60.);
}
void WheelEventTestMonitor::deferForReason(ScrollableAreaIdentifier identifier, DeferReason reason)
{
ASSERT(isMainThread());
m_deferCompletionReasons.ensure(identifier, [] {
return OptionSet<DeferReason>();
}).iterator->value.add(reason);
LOG_WITH_STREAM(WheelEventTestMonitor, stream << " (=) WheelEventTestMonitor::deferForReason: id=" << identifier << ", reason=" << reason);
}
void WheelEventTestMonitor::removeDeferralForReason(ScrollableAreaIdentifier identifier, DeferReason reason)
{
ASSERT(isMainThread());
auto it = m_deferCompletionReasons.find(identifier);
if (it == m_deferCompletionReasons.end())
return;
LOG_WITH_STREAM(WheelEventTestMonitor, stream << " (=) WheelEventTestMonitor::removeDeferralForReason: id=" << identifier << ", reason=" << reason);
it->value.remove(reason);
if (it->value.isEmpty())
m_deferCompletionReasons.remove(it);
}
void WheelEventTestMonitor::triggerTestTimerFired()
{
ASSERT(isMainThread());
if (!m_deferCompletionReasons.isEmpty()) {
LOG_WITH_STREAM(WheelEventTestMonitor, stream << " WheelEventTestMonitor::triggerTestTimerFired - scrolling still active, reasons " << m_deferCompletionReasons);
return;
}
auto functionCallback = WTFMove(m_completionCallback);
m_testForCompletionTimer.stop();
LOG_WITH_STREAM(WheelEventTestMonitor, stream << " WheelEventTestMonitor::triggerTestTimerFired: scrolling is idle, FIRING TEST");
if (functionCallback)
functionCallback();
}
TextStream& operator<<(TextStream& ts, WheelEventTestMonitor::DeferReason reason)
{
switch (reason) {
case WheelEventTestMonitor::HandlingWheelEvent: ts << "handling wheel event"; break;
case WheelEventTestMonitor::RubberbandInProgress: ts << "rubberbanding"; break;
case WheelEventTestMonitor::ScrollSnapInProgress: ts << "scroll-snapping"; break;
case WheelEventTestMonitor::ScrollingThreadSyncNeeded: ts << "scrolling thread sync needed"; break;
case WheelEventTestMonitor::ContentScrollInProgress: ts << "content scrolling"; break;
}
return ts;
}
TextStream& operator<<(TextStream& ts, const WheelEventTestMonitor::ScrollableAreaReasonMap& reasonMap)
{
for (const auto& regionReasonsPair : reasonMap)
ts << " scroll region: " << regionReasonsPair.key << " reasons: " << regionReasonsPair.value;
return ts;
}
}