summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/WheelEventTestTrigger.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/page/WheelEventTestTrigger.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/page/WheelEventTestTrigger.cpp')
-rw-r--r--Source/WebCore/page/WheelEventTestTrigger.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/Source/WebCore/page/WheelEventTestTrigger.cpp b/Source/WebCore/page/WheelEventTestTrigger.cpp
new file mode 100644
index 000000000..39887f135
--- /dev/null
+++ b/Source/WebCore/page/WheelEventTestTrigger.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2015 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.
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
+ */
+
+#include "config.h"
+#include "WheelEventTestTrigger.h"
+
+#include "Logging.h"
+
+#if !LOG_DISABLED
+#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
+#endif
+
+namespace WebCore {
+
+WheelEventTestTrigger::WheelEventTestTrigger()
+ : m_testTriggerTimer(RunLoop::current(), this, &WheelEventTestTrigger::triggerTestTimerFired)
+{
+}
+
+void WheelEventTestTrigger::clearAllTestDeferrals()
+{
+ std::lock_guard<Lock> lock(m_testTriggerMutex);
+ m_deferTestTriggerReasons.clear();
+ m_testNotificationCallback = std::function<void()>();
+ m_testTriggerTimer.stop();
+ LOG(WheelEventTestTriggers, " (=) WheelEventTestTrigger::clearAllTestDeferrals: cleared all test state.");
+}
+
+void WheelEventTestTrigger::setTestCallbackAndStartNotificationTimer(std::function<void()> functionCallback)
+{
+ {
+ std::lock_guard<Lock> lock(m_testTriggerMutex);
+ m_testNotificationCallback = WTFMove(functionCallback);
+ }
+
+ if (!m_testTriggerTimer.isActive())
+ m_testTriggerTimer.startRepeating(1.0 / 60.0);
+}
+
+void WheelEventTestTrigger::deferTestsForReason(ScrollableAreaIdentifier identifier, DeferTestTriggerReason reason)
+{
+ std::lock_guard<Lock> lock(m_testTriggerMutex);
+ auto it = m_deferTestTriggerReasons.find(identifier);
+ if (it == m_deferTestTriggerReasons.end())
+ it = m_deferTestTriggerReasons.add(identifier, std::set<DeferTestTriggerReason>()).iterator;
+
+ LOG(WheelEventTestTriggers, " (=) WheelEventTestTrigger::deferTestsForReason: id=%p, reason=%d", identifier, reason);
+ it->value.insert(reason);
+}
+
+void WheelEventTestTrigger::removeTestDeferralForReason(ScrollableAreaIdentifier identifier, DeferTestTriggerReason reason)
+{
+ std::lock_guard<Lock> lock(m_testTriggerMutex);
+ auto it = m_deferTestTriggerReasons.find(identifier);
+ if (it == m_deferTestTriggerReasons.end())
+ return;
+
+ LOG(WheelEventTestTriggers, " (=) WheelEventTestTrigger::removeTestDeferralForReason: id=%p, reason=%d", identifier, reason);
+ it->value.erase(reason);
+
+ if (it->value.empty())
+ m_deferTestTriggerReasons.remove(it);
+}
+
+#if !LOG_DISABLED
+static void dumpState(WTF::HashMap<WheelEventTestTrigger::ScrollableAreaIdentifier, std::set<WheelEventTestTrigger::DeferTestTriggerReason>> reasons)
+{
+ LOG(WheelEventTestTriggers, " WheelEventTestTrigger::dumpState:");
+ for (const auto& scrollRegion : reasons) {
+ LOG(WheelEventTestTriggers, " For scroll region %p", scrollRegion.key);
+ StringBuilder reasons;
+ for (const auto& reason : scrollRegion.value) {
+ if (!reasons.isEmpty())
+ reasons.append(", ");
+ reasons.append(String::number(reason));
+ }
+ LOG(WheelEventTestTriggers, " Reasons: %s", reasons.toString().utf8().data());
+ }
+}
+#endif
+
+void WheelEventTestTrigger::triggerTestTimerFired()
+{
+ std::function<void()> functionCallback;
+
+ {
+ std::lock_guard<Lock> lock(m_testTriggerMutex);
+ if (!m_deferTestTriggerReasons.isEmpty()) {
+#if !LOG_DISABLED
+ if (isLogChannelEnabled("WheelEventTestTriggers"))
+ dumpState(m_deferTestTriggerReasons);
+#endif
+ return;
+ }
+
+ functionCallback = WTFMove(m_testNotificationCallback);
+ m_testNotificationCallback = std::function<void()>();
+ }
+
+ m_testTriggerTimer.stop();
+
+ LOG(WheelEventTestTriggers, " WheelEventTestTrigger::triggerTestTimerFired: FIRING TEST");
+ if (functionCallback)
+ functionCallback();
+}
+
+}