1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_widget_WindowEvent_h
8 #define mozilla_widget_WindowEvent_h
10 #include "nsThreadUtils.h"
11 #include "mozilla/jni/Natives.h"
16 // An Event subclass that guards against stale events.
17 // (See the implmentation of mozilla::jni::detail::ProxyNativeCall for info
18 // about the default template parameters for this class)
19 template <typename Lambda
, bool IsStatic
= Lambda::isStatic
,
20 typename InstanceType
= typename
Lambda::ThisArgType
,
21 class Impl
= typename
Lambda::TargetClass
>
22 class WindowEvent
: public Runnable
{
25 // Static calls are never stale.
29 return jni::NativePtrTraits
<Impl
>::IsStale(mInstance
);
33 const InstanceType mInstance
;
36 WindowEvent(Lambda
&& aLambda
, InstanceType
&& aInstance
)
37 : Runnable("mozilla::widget::WindowEvent"),
38 mLambda(std::move(aLambda
)),
39 mInstance(std::forward
<InstanceType
>(aInstance
)) {}
41 explicit WindowEvent(Lambda
&& aLambda
)
42 : Runnable("mozilla::widget::WindowEvent"),
43 mLambda(std::move(aLambda
)),
44 mInstance(mLambda
.GetThisArg()) {}
46 NS_IMETHOD
Run() override
{
55 } // namespace mozilla
57 #endif // mozilla_widget_WindowEvent_h