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

Unified Diff: Source/core/dom/NoEventDispatchAssertion.h

Issue 301173006: Move NoEventDispatchAssertion class to its own file (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing include Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/NoEventDispatchAssertion.h
diff --git a/Source/core/dom/NoEventDispatchAssertion.h b/Source/core/dom/NoEventDispatchAssertion.h
new file mode 100644
index 0000000000000000000000000000000000000000..a495212c2751f15adc5a56a12872704e48ad220f
--- /dev/null
+++ b/Source/core/dom/NoEventDispatchAssertion.h
@@ -0,0 +1,76 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NoEventDispatchAssertion_h
+#define NoEventDispatchAssertion_h
+
+#include "wtf/MainThread.h"
+#include "wtf/TemporaryChange.h"
+
+namespace WebCore {
+
+#ifndef NDEBUG
+
+class NoEventDispatchAssertion {
+public:
+ NoEventDispatchAssertion()
+ {
+ if (!isMainThread())
+ return;
+ ++s_count;
+ }
+
+ ~NoEventDispatchAssertion()
+ {
+ if (!isMainThread())
+ return;
+ ASSERT(s_count);
+ --s_count;
+ }
+
+ static bool isEventDispatchForbidden()
+ {
+ if (!isMainThread())
+ return false;
+ return s_count;
+ }
+
+ // It's safe to dispatch events in SVGImage since there can't be any script
+ // listeners.
+ class AllowSVGImageEvents {
+ public:
+ AllowSVGImageEvents()
+ : m_change(s_count, 0)
+ {
+ }
+
+ ~AllowSVGImageEvents()
+ {
+ ASSERT(!s_count);
+ }
+
+ TemporaryChange<unsigned> m_change;
+ };
+
+private:
+ static unsigned s_count;
+};
+
+#else
+
+class NoEventDispatchAssertion {
+public:
+ NoEventDispatchAssertion() { }
+
+ class AllowSVGImageEvents {
+ public:
+ AllowSVGImageEvents() { }
+ };
+};
+
+#endif // NDEBUG
+
+} // namespace WebCore
+
+#endif // NoEventDispatchAssertion_h
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698