mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 984253 part.3 Rename nsEventHandler to mozilla::TypedEventHandler r=smaug
This commit is contained in:
parent
6a2234c047
commit
24af1645ff
@ -599,7 +599,7 @@ EventListenerManager::Listener*
|
|||||||
EventListenerManager::SetEventHandlerInternal(
|
EventListenerManager::SetEventHandlerInternal(
|
||||||
nsIAtom* aName,
|
nsIAtom* aName,
|
||||||
const nsAString& aTypeString,
|
const nsAString& aTypeString,
|
||||||
const nsEventHandler& aHandler,
|
const TypedEventHandler& aTypedHandler,
|
||||||
bool aPermitUntrustedEvents)
|
bool aPermitUntrustedEvents)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(aName || !aTypeString.IsEmpty());
|
MOZ_ASSERT(aName || !aTypeString.IsEmpty());
|
||||||
@ -615,7 +615,7 @@ EventListenerManager::SetEventHandlerInternal(
|
|||||||
|
|
||||||
nsCOMPtr<nsJSEventListener> jsListener;
|
nsCOMPtr<nsJSEventListener> jsListener;
|
||||||
NS_NewJSEventHandler(mTarget, aName,
|
NS_NewJSEventHandler(mTarget, aName,
|
||||||
aHandler, getter_AddRefs(jsListener));
|
aTypedHandler, getter_AddRefs(jsListener));
|
||||||
EventListenerHolder listenerHolder(jsListener);
|
EventListenerHolder listenerHolder(jsListener);
|
||||||
AddEventListenerInternal(listenerHolder, eventType, aName, aTypeString,
|
AddEventListenerInternal(listenerHolder, eventType, aName, aTypeString,
|
||||||
flags, true);
|
flags, true);
|
||||||
@ -626,9 +626,9 @@ EventListenerManager::SetEventHandlerInternal(
|
|||||||
MOZ_ASSERT(jsListener,
|
MOZ_ASSERT(jsListener,
|
||||||
"How can we have an event handler with no nsJSEventListener?");
|
"How can we have an event handler with no nsJSEventListener?");
|
||||||
|
|
||||||
bool same = jsListener->GetHandler() == aHandler;
|
bool same = jsListener->GetTypedEventHandler() == aTypedHandler;
|
||||||
// Possibly the same listener, but update still the context and scope.
|
// Possibly the same listener, but update still the context and scope.
|
||||||
jsListener->SetHandler(aHandler);
|
jsListener->SetHandler(aTypedHandler);
|
||||||
if (mTarget && !same && aName) {
|
if (mTarget && !same && aName) {
|
||||||
mTarget->EventListenerRemoved(aName);
|
mTarget->EventListenerRemoved(aName);
|
||||||
mTarget->EventListenerAdded(aName);
|
mTarget->EventListenerAdded(aName);
|
||||||
@ -636,7 +636,7 @@ EventListenerManager::SetEventHandlerInternal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set flag to indicate possible need for compilation later
|
// Set flag to indicate possible need for compilation later
|
||||||
listener->mHandlerIsString = !aHandler.HasEventHandler();
|
listener->mHandlerIsString = !aTypedHandler.HasEventHandler();
|
||||||
if (aPermitUntrustedEvents) {
|
if (aPermitUntrustedEvents) {
|
||||||
listener->mFlags.mAllowUntrustedEvents = true;
|
listener->mFlags.mAllowUntrustedEvents = true;
|
||||||
}
|
}
|
||||||
@ -747,7 +747,7 @@ EventListenerManager::SetEventHandler(nsIAtom* aName,
|
|||||||
|
|
||||||
Listener* listener = SetEventHandlerInternal(aName,
|
Listener* listener = SetEventHandlerInternal(aName,
|
||||||
EmptyString(),
|
EmptyString(),
|
||||||
nsEventHandler(),
|
TypedEventHandler(),
|
||||||
aPermitUntrustedEvents);
|
aPermitUntrustedEvents);
|
||||||
|
|
||||||
if (!aDeferCompilation) {
|
if (!aDeferCompilation) {
|
||||||
@ -786,7 +786,8 @@ EventListenerManager::CompileEventHandlerInternal(Listener* aListener,
|
|||||||
MOZ_ASSERT(aListener->GetJSListener());
|
MOZ_ASSERT(aListener->GetJSListener());
|
||||||
MOZ_ASSERT(aListener->mHandlerIsString, "Why are we compiling a non-string JS listener?");
|
MOZ_ASSERT(aListener->mHandlerIsString, "Why are we compiling a non-string JS listener?");
|
||||||
nsJSEventListener* jsListener = aListener->GetJSListener();
|
nsJSEventListener* jsListener = aListener->GetJSListener();
|
||||||
MOZ_ASSERT(!jsListener->GetHandler().HasEventHandler(), "What is there to compile?");
|
MOZ_ASSERT(!jsListener->GetTypedEventHandler().HasEventHandler(),
|
||||||
|
"What is there to compile?");
|
||||||
|
|
||||||
nsresult result = NS_OK;
|
nsresult result = NS_OK;
|
||||||
nsCOMPtr<nsIDocument> doc;
|
nsCOMPtr<nsIDocument> doc;
|
||||||
@ -1222,7 +1223,7 @@ EventListenerManager::SetEventHandler(nsIAtom* aEventName,
|
|||||||
|
|
||||||
// Untrusted events are always permitted for non-chrome script
|
// Untrusted events are always permitted for non-chrome script
|
||||||
// handlers.
|
// handlers.
|
||||||
SetEventHandlerInternal(aEventName, aTypeString, nsEventHandler(aHandler),
|
SetEventHandlerInternal(aEventName, aTypeString, TypedEventHandler(aHandler),
|
||||||
!mIsMainThreadELM ||
|
!mIsMainThreadELM ||
|
||||||
!nsContentUtils::IsCallerChrome());
|
!nsContentUtils::IsCallerChrome());
|
||||||
}
|
}
|
||||||
@ -1239,7 +1240,7 @@ EventListenerManager::SetEventHandler(OnErrorEventHandlerNonNull* aHandler)
|
|||||||
// Untrusted events are always permitted for non-chrome script
|
// Untrusted events are always permitted for non-chrome script
|
||||||
// handlers.
|
// handlers.
|
||||||
SetEventHandlerInternal(nsGkAtoms::onerror, EmptyString(),
|
SetEventHandlerInternal(nsGkAtoms::onerror, EmptyString(),
|
||||||
nsEventHandler(aHandler),
|
TypedEventHandler(aHandler),
|
||||||
!nsContentUtils::IsCallerChrome());
|
!nsContentUtils::IsCallerChrome());
|
||||||
} else {
|
} else {
|
||||||
if (!aHandler) {
|
if (!aHandler) {
|
||||||
@ -1249,7 +1250,7 @@ EventListenerManager::SetEventHandler(OnErrorEventHandlerNonNull* aHandler)
|
|||||||
|
|
||||||
// Untrusted events are always permitted.
|
// Untrusted events are always permitted.
|
||||||
SetEventHandlerInternal(nullptr, NS_LITERAL_STRING("error"),
|
SetEventHandlerInternal(nullptr, NS_LITERAL_STRING("error"),
|
||||||
nsEventHandler(aHandler), true);
|
TypedEventHandler(aHandler), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1265,13 +1266,13 @@ EventListenerManager::SetEventHandler(
|
|||||||
// Untrusted events are always permitted for non-chrome script
|
// Untrusted events are always permitted for non-chrome script
|
||||||
// handlers.
|
// handlers.
|
||||||
SetEventHandlerInternal(nsGkAtoms::onbeforeunload, EmptyString(),
|
SetEventHandlerInternal(nsGkAtoms::onbeforeunload, EmptyString(),
|
||||||
nsEventHandler(aHandler),
|
TypedEventHandler(aHandler),
|
||||||
!mIsMainThreadELM ||
|
!mIsMainThreadELM ||
|
||||||
!nsContentUtils::IsCallerChrome());
|
!nsContentUtils::IsCallerChrome());
|
||||||
}
|
}
|
||||||
|
|
||||||
const nsEventHandler*
|
const TypedEventHandler*
|
||||||
EventListenerManager::GetEventHandlerInternal(nsIAtom* aEventName,
|
EventListenerManager::GetTypedEventHandler(nsIAtom* aEventName,
|
||||||
const nsAString& aTypeString)
|
const nsAString& aTypeString)
|
||||||
{
|
{
|
||||||
uint32_t eventType = nsContentUtils::GetEventId(aEventName);
|
uint32_t eventType = nsContentUtils::GetEventId(aEventName);
|
||||||
@ -1287,12 +1288,8 @@ EventListenerManager::GetEventHandlerInternal(nsIAtom* aEventName,
|
|||||||
CompileEventHandlerInternal(listener, nullptr, nullptr);
|
CompileEventHandlerInternal(listener, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const nsEventHandler& handler = jsListener->GetHandler();
|
const TypedEventHandler& typedHandler = jsListener->GetTypedEventHandler();
|
||||||
if (handler.HasEventHandler()) {
|
return typedHandler.HasEventHandler() ? &typedHandler : nullptr;
|
||||||
return &handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
@ -1318,8 +1315,10 @@ EventListenerManager::MarkForCC()
|
|||||||
const Listener& listener = mListeners.ElementAt(i);
|
const Listener& listener = mListeners.ElementAt(i);
|
||||||
nsJSEventListener* jsListener = listener.GetJSListener();
|
nsJSEventListener* jsListener = listener.GetJSListener();
|
||||||
if (jsListener) {
|
if (jsListener) {
|
||||||
if (jsListener->GetHandler().HasEventHandler()) {
|
const TypedEventHandler& typedHandler =
|
||||||
JS::ExposeObjectToActiveJS(jsListener->GetHandler().Ptr()->Callable());
|
jsListener->GetTypedEventHandler();
|
||||||
|
if (typedHandler.HasEventHandler()) {
|
||||||
|
JS::ExposeObjectToActiveJS(typedHandler.Ptr()->Callable());
|
||||||
}
|
}
|
||||||
} else if (listener.mListenerType == Listener::eWrappedJSListener) {
|
} else if (listener.mListenerType == Listener::eWrappedJSListener) {
|
||||||
xpc_TryUnmarkWrappedGrayObject(listener.mListener.GetXPCOMCallback());
|
xpc_TryUnmarkWrappedGrayObject(listener.mListener.GetXPCOMCallback());
|
||||||
|
@ -449,7 +449,7 @@ protected:
|
|||||||
*/
|
*/
|
||||||
Listener* SetEventHandlerInternal(nsIAtom* aName,
|
Listener* SetEventHandlerInternal(nsIAtom* aName,
|
||||||
const nsAString& aTypeString,
|
const nsAString& aTypeString,
|
||||||
const nsEventHandler& aHandler,
|
const TypedEventHandler& aHandler,
|
||||||
bool aPermitUntrustedEvents);
|
bool aPermitUntrustedEvents);
|
||||||
|
|
||||||
bool IsDeviceType(uint32_t aType);
|
bool IsDeviceType(uint32_t aType);
|
||||||
@ -479,27 +479,24 @@ public:
|
|||||||
dom::EventHandlerNonNull* GetEventHandler(nsIAtom* aEventName,
|
dom::EventHandlerNonNull* GetEventHandler(nsIAtom* aEventName,
|
||||||
const nsAString& aTypeString)
|
const nsAString& aTypeString)
|
||||||
{
|
{
|
||||||
const nsEventHandler* handler =
|
const TypedEventHandler* typedHandler =
|
||||||
GetEventHandlerInternal(aEventName, aTypeString);
|
GetTypedEventHandler(aEventName, aTypeString);
|
||||||
return handler ? handler->EventHandler() : nullptr;
|
return typedHandler ? typedHandler->NormalEventHandler() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom::OnErrorEventHandlerNonNull* GetOnErrorEventHandler()
|
dom::OnErrorEventHandlerNonNull* GetOnErrorEventHandler()
|
||||||
{
|
{
|
||||||
const nsEventHandler* handler;
|
const TypedEventHandler* typedHandler = mIsMainThreadELM ?
|
||||||
if (mIsMainThreadELM) {
|
GetTypedEventHandler(nsGkAtoms::onerror, EmptyString()) :
|
||||||
handler = GetEventHandlerInternal(nsGkAtoms::onerror, EmptyString());
|
GetTypedEventHandler(nullptr, NS_LITERAL_STRING("error"));
|
||||||
} else {
|
return typedHandler ? typedHandler->OnErrorEventHandler() : nullptr;
|
||||||
handler = GetEventHandlerInternal(nullptr, NS_LITERAL_STRING("error"));
|
|
||||||
}
|
|
||||||
return handler ? handler->OnErrorEventHandler() : nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dom::OnBeforeUnloadEventHandlerNonNull* GetOnBeforeUnloadEventHandler()
|
dom::OnBeforeUnloadEventHandlerNonNull* GetOnBeforeUnloadEventHandler()
|
||||||
{
|
{
|
||||||
const nsEventHandler* handler =
|
const TypedEventHandler* typedHandler =
|
||||||
GetEventHandlerInternal(nsGkAtoms::onbeforeunload, EmptyString());
|
GetTypedEventHandler(nsGkAtoms::onbeforeunload, EmptyString());
|
||||||
return handler ? handler->OnBeforeUnloadEventHandler() : nullptr;
|
return typedHandler ? typedHandler->OnBeforeUnloadEventHandler() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -507,7 +504,7 @@ protected:
|
|||||||
* Helper method for implementing the various Get*EventHandler above. Will
|
* Helper method for implementing the various Get*EventHandler above. Will
|
||||||
* return null if we don't have an event handler for this event name.
|
* return null if we don't have an event handler for this event name.
|
||||||
*/
|
*/
|
||||||
const nsEventHandler* GetEventHandlerInternal(nsIAtom* aEventName,
|
const TypedEventHandler* GetTypedEventHandler(nsIAtom* aEventName,
|
||||||
const nsAString& aTypeString);
|
const nsAString& aTypeString);
|
||||||
|
|
||||||
void AddEventListener(const nsAString& aType,
|
void AddEventListener(const nsAString& aType,
|
||||||
|
@ -102,8 +102,9 @@ EventListenerInfo::GetJSVal(JSContext* aCx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsJSEventListener> jsl = do_QueryInterface(mListener);
|
nsCOMPtr<nsJSEventListener> jsl = do_QueryInterface(mListener);
|
||||||
if (jsl && jsl->GetHandler().HasEventHandler()) {
|
if (jsl && jsl->GetTypedEventHandler().HasEventHandler()) {
|
||||||
JS::Handle<JSObject*> handler(jsl->GetHandler().Ptr()->Callable());
|
JS::Handle<JSObject*> handler =
|
||||||
|
jsl->GetTypedEventHandler().Ptr()->Callable();
|
||||||
if (handler) {
|
if (handler) {
|
||||||
aAc.construct(aCx, handler);
|
aAc.construct(aCx, handler);
|
||||||
aJSVal.setObject(*handler);
|
aJSVal.setObject(*handler);
|
||||||
|
@ -45,9 +45,9 @@ using namespace mozilla::dom;
|
|||||||
*/
|
*/
|
||||||
nsJSEventListener::nsJSEventListener(nsISupports *aTarget,
|
nsJSEventListener::nsJSEventListener(nsISupports *aTarget,
|
||||||
nsIAtom* aType,
|
nsIAtom* aType,
|
||||||
const nsEventHandler& aHandler)
|
const TypedEventHandler& aTypedHandler)
|
||||||
: mEventName(aType)
|
: mEventName(aType)
|
||||||
, mHandler(aHandler)
|
, mTypedHandler(aTypedHandler)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsISupports> base = do_QueryInterface(aTarget);
|
nsCOMPtr<nsISupports> base = do_QueryInterface(aTarget);
|
||||||
mTarget = base.get();
|
mTarget = base.get();
|
||||||
@ -56,7 +56,7 @@ nsJSEventListener::nsJSEventListener(nsISupports *aTarget,
|
|||||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSEventListener)
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSEventListener)
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSEventListener)
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSEventListener)
|
||||||
tmp->mHandler.ForgetHandler();
|
tmp->mTypedHandler.ForgetHandler();
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsJSEventListener)
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsJSEventListener)
|
||||||
if (MOZ_UNLIKELY(cb.WantDebugInfo()) && tmp->mEventName) {
|
if (MOZ_UNLIKELY(cb.WantDebugInfo()) && tmp->mEventName) {
|
||||||
@ -68,7 +68,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsJSEventListener)
|
|||||||
} else {
|
} else {
|
||||||
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsJSEventListener, tmp->mRefCnt.get())
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsJSEventListener, tmp->mRefCnt.get())
|
||||||
}
|
}
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mHandler.Ptr())
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mTypedHandler.Ptr())
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||||
|
|
||||||
@ -113,15 +113,16 @@ nsJSEventListener::IsBlackForCC()
|
|||||||
{
|
{
|
||||||
// We can claim to be black if all the things we reference are
|
// We can claim to be black if all the things we reference are
|
||||||
// effectively black already.
|
// effectively black already.
|
||||||
return !mHandler.HasEventHandler() || !mHandler.Ptr()->HasGrayCallable();
|
return !mTypedHandler.HasEventHandler() ||
|
||||||
|
!mTypedHandler.Ptr()->HasGrayCallable();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||||
{
|
{
|
||||||
nsCOMPtr<EventTarget> target = do_QueryInterface(mTarget);
|
nsCOMPtr<EventTarget> target = do_QueryInterface(mTarget);
|
||||||
if (!target || !mHandler.HasEventHandler() ||
|
if (!target || !mTypedHandler.HasEventHandler() ||
|
||||||
!GetHandler().Ptr()->CallbackPreserveColor()) {
|
!GetTypedEventHandler().Ptr()->CallbackPreserveColor()) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,11 +131,11 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|||||||
bool isChromeHandler =
|
bool isChromeHandler =
|
||||||
isMainThread ?
|
isMainThread ?
|
||||||
nsContentUtils::GetObjectPrincipal(
|
nsContentUtils::GetObjectPrincipal(
|
||||||
GetHandler().Ptr()->CallbackPreserveColor()) ==
|
GetTypedEventHandler().Ptr()->CallbackPreserveColor()) ==
|
||||||
nsContentUtils::GetSystemPrincipal() :
|
nsContentUtils::GetSystemPrincipal() :
|
||||||
mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
|
mozilla::dom::workers::IsCurrentThreadRunningChromeWorker();
|
||||||
|
|
||||||
if (mHandler.Type() == nsEventHandler::eOnError) {
|
if (mTypedHandler.Type() == TypedEventHandler::eOnError) {
|
||||||
MOZ_ASSERT_IF(mEventName, mEventName == nsGkAtoms::onerror);
|
MOZ_ASSERT_IF(mEventName, mEventName == nsGkAtoms::onerror);
|
||||||
|
|
||||||
nsString errorMsg, file;
|
nsString errorMsg, file;
|
||||||
@ -167,7 +168,7 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsRefPtr<OnErrorEventHandlerNonNull> handler =
|
nsRefPtr<OnErrorEventHandlerNonNull> handler =
|
||||||
mHandler.OnErrorEventHandler();
|
mTypedHandler.OnErrorEventHandler();
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
bool handled = handler->Call(mTarget, msgOrEvent, fileName, lineNumber,
|
bool handled = handler->Call(mTarget, msgOrEvent, fileName, lineNumber,
|
||||||
columnNumber, error, rv);
|
columnNumber, error, rv);
|
||||||
@ -181,11 +182,11 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHandler.Type() == nsEventHandler::eOnBeforeUnload) {
|
if (mTypedHandler.Type() == TypedEventHandler::eOnBeforeUnload) {
|
||||||
MOZ_ASSERT(mEventName == nsGkAtoms::onbeforeunload);
|
MOZ_ASSERT(mEventName == nsGkAtoms::onbeforeunload);
|
||||||
|
|
||||||
nsRefPtr<OnBeforeUnloadEventHandlerNonNull> handler =
|
nsRefPtr<OnBeforeUnloadEventHandlerNonNull> handler =
|
||||||
mHandler.OnBeforeUnloadEventHandler();
|
mTypedHandler.OnBeforeUnloadEventHandler();
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
nsString retval;
|
nsString retval;
|
||||||
handler->Call(mTarget, *(aEvent->InternalDOMEvent()), retval, rv);
|
handler->Call(mTarget, *(aEvent->InternalDOMEvent()), retval, rv);
|
||||||
@ -213,9 +214,9 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_ASSERT(mHandler.Type() == nsEventHandler::eNormal);
|
MOZ_ASSERT(mTypedHandler.Type() == TypedEventHandler::eNormal);
|
||||||
ErrorResult rv;
|
ErrorResult rv;
|
||||||
nsRefPtr<EventHandlerNonNull> handler = mHandler.EventHandler();
|
nsRefPtr<EventHandlerNonNull> handler = mTypedHandler.NormalEventHandler();
|
||||||
JS::Value retval =
|
JS::Value retval =
|
||||||
handler->Call(mTarget, *(aEvent->InternalDOMEvent()), rv);
|
handler->Call(mTarget, *(aEvent->InternalDOMEvent()), rv);
|
||||||
if (rv.Failed()) {
|
if (rv.Failed()) {
|
||||||
@ -241,12 +242,12 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|||||||
nsresult
|
nsresult
|
||||||
NS_NewJSEventHandler(nsISupports* aTarget,
|
NS_NewJSEventHandler(nsISupports* aTarget,
|
||||||
nsIAtom* aEventType,
|
nsIAtom* aEventType,
|
||||||
const nsEventHandler& aHandler,
|
const TypedEventHandler& aTypedHandler,
|
||||||
nsJSEventListener** aReturn)
|
nsJSEventListener** aReturn)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG(aEventType || !NS_IsMainThread());
|
NS_ENSURE_ARG(aEventType || !NS_IsMainThread());
|
||||||
nsJSEventListener* it =
|
nsJSEventListener* it =
|
||||||
new nsJSEventListener(aTarget, aEventType, aHandler);
|
new nsJSEventListener(aTarget, aEventType, aTypedHandler);
|
||||||
NS_ADDREF(*aReturn = it);
|
NS_ADDREF(*aReturn = it);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -16,15 +16,11 @@
|
|||||||
#include "nsIDOMEventListener.h"
|
#include "nsIDOMEventListener.h"
|
||||||
#include "nsIScriptContext.h"
|
#include "nsIScriptContext.h"
|
||||||
|
|
||||||
class nsEventHandler
|
namespace mozilla {
|
||||||
|
|
||||||
|
class TypedEventHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef mozilla::dom::EventHandlerNonNull EventHandlerNonNull;
|
|
||||||
typedef mozilla::dom::OnBeforeUnloadEventHandlerNonNull
|
|
||||||
OnBeforeUnloadEventHandlerNonNull;
|
|
||||||
typedef mozilla::dom::OnErrorEventHandlerNonNull OnErrorEventHandlerNonNull;
|
|
||||||
typedef mozilla::dom::CallbackFunction CallbackFunction;
|
|
||||||
|
|
||||||
enum HandlerType
|
enum HandlerType
|
||||||
{
|
{
|
||||||
eUnset = 0,
|
eUnset = 0,
|
||||||
@ -34,27 +30,27 @@ public:
|
|||||||
eTypeBits = 0x3
|
eTypeBits = 0x3
|
||||||
};
|
};
|
||||||
|
|
||||||
nsEventHandler()
|
TypedEventHandler()
|
||||||
: mBits(0)
|
: mBits(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
nsEventHandler(EventHandlerNonNull* aHandler)
|
TypedEventHandler(dom::EventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
Assign(aHandler, eNormal);
|
Assign(aHandler, eNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsEventHandler(OnErrorEventHandlerNonNull* aHandler)
|
TypedEventHandler(dom::OnErrorEventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
Assign(aHandler, eOnError);
|
Assign(aHandler, eOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsEventHandler(OnBeforeUnloadEventHandlerNonNull* aHandler)
|
TypedEventHandler(dom::OnBeforeUnloadEventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
Assign(aHandler, eOnBeforeUnload);
|
Assign(aHandler, eOnBeforeUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsEventHandler(const nsEventHandler& aOther)
|
TypedEventHandler(const TypedEventHandler& aOther)
|
||||||
{
|
{
|
||||||
if (aOther.HasEventHandler()) {
|
if (aOther.HasEventHandler()) {
|
||||||
// Have to make sure we take our own ref
|
// Have to make sure we take our own ref
|
||||||
@ -64,7 +60,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~nsEventHandler()
|
~TypedEventHandler()
|
||||||
{
|
{
|
||||||
ReleaseHandler();
|
ReleaseHandler();
|
||||||
}
|
}
|
||||||
@ -79,7 +75,7 @@ public:
|
|||||||
return !!Ptr();
|
return !!Ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHandler(const nsEventHandler& aHandler)
|
void SetHandler(const TypedEventHandler& aHandler)
|
||||||
{
|
{
|
||||||
if (aHandler.HasEventHandler()) {
|
if (aHandler.HasEventHandler()) {
|
||||||
ReleaseHandler();
|
ReleaseHandler();
|
||||||
@ -89,47 +85,48 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventHandlerNonNull* EventHandler() const
|
dom::EventHandlerNonNull* NormalEventHandler() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(Type() == eNormal && Ptr());
|
MOZ_ASSERT(Type() == eNormal && Ptr());
|
||||||
return reinterpret_cast<EventHandlerNonNull*>(Ptr());
|
return reinterpret_cast<dom::EventHandlerNonNull*>(Ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHandler(EventHandlerNonNull* aHandler)
|
void SetHandler(dom::EventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
ReleaseHandler();
|
ReleaseHandler();
|
||||||
Assign(aHandler, eNormal);
|
Assign(aHandler, eNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnBeforeUnloadEventHandlerNonNull* OnBeforeUnloadEventHandler() const
|
dom::OnBeforeUnloadEventHandlerNonNull* OnBeforeUnloadEventHandler() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(Type() == eOnBeforeUnload);
|
MOZ_ASSERT(Type() == eOnBeforeUnload);
|
||||||
return reinterpret_cast<OnBeforeUnloadEventHandlerNonNull*>(Ptr());
|
return reinterpret_cast<dom::OnBeforeUnloadEventHandlerNonNull*>(Ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHandler(OnBeforeUnloadEventHandlerNonNull* aHandler)
|
void SetHandler(dom::OnBeforeUnloadEventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
ReleaseHandler();
|
ReleaseHandler();
|
||||||
Assign(aHandler, eOnBeforeUnload);
|
Assign(aHandler, eOnBeforeUnload);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnErrorEventHandlerNonNull* OnErrorEventHandler() const
|
dom::OnErrorEventHandlerNonNull* OnErrorEventHandler() const
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(Type() == eOnError);
|
MOZ_ASSERT(Type() == eOnError);
|
||||||
return reinterpret_cast<OnErrorEventHandlerNonNull*>(Ptr());
|
return reinterpret_cast<dom::OnErrorEventHandlerNonNull*>(Ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHandler(OnErrorEventHandlerNonNull* aHandler)
|
void SetHandler(dom::OnErrorEventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
ReleaseHandler();
|
ReleaseHandler();
|
||||||
Assign(aHandler, eOnError);
|
Assign(aHandler, eOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackFunction* Ptr() const
|
dom::CallbackFunction* Ptr() const
|
||||||
{
|
{
|
||||||
// Have to cast eTypeBits so we don't have to worry about
|
// Have to cast eTypeBits so we don't have to worry about
|
||||||
// promotion issues after the bitflip.
|
// promotion issues after the bitflip.
|
||||||
return reinterpret_cast<CallbackFunction*>(mBits & ~uintptr_t(eTypeBits));
|
return reinterpret_cast<dom::CallbackFunction*>(mBits &
|
||||||
|
~uintptr_t(eTypeBits));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForgetHandler()
|
void ForgetHandler()
|
||||||
@ -138,7 +135,7 @@ public:
|
|||||||
mBits = 0;
|
mBits = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const nsEventHandler& aOther) const
|
bool operator==(const TypedEventHandler& aOther) const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
Ptr() && aOther.Ptr() &&
|
Ptr() && aOther.Ptr() &&
|
||||||
@ -146,7 +143,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void operator=(const nsEventHandler&) MOZ_DELETE;
|
void operator=(const TypedEventHandler&) MOZ_DELETE;
|
||||||
|
|
||||||
void ReleaseHandler()
|
void ReleaseHandler()
|
||||||
{
|
{
|
||||||
@ -164,6 +161,8 @@ private:
|
|||||||
uintptr_t mBits;
|
uintptr_t mBits;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implemented by script event listeners. Used to retrieve the script object
|
* Implemented by script event listeners. Used to retrieve the script object
|
||||||
* corresponding to the event target and the handler itself.
|
* corresponding to the event target and the handler itself.
|
||||||
@ -182,7 +181,7 @@ public:
|
|||||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_JSEVENTLISTENER_IID)
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_JSEVENTLISTENER_IID)
|
||||||
|
|
||||||
nsJSEventListener(nsISupports* aTarget, nsIAtom* aType,
|
nsJSEventListener(nsISupports* aTarget, nsIAtom* aType,
|
||||||
const nsEventHandler& aHandler);
|
const mozilla::TypedEventHandler& aTypedHandler);
|
||||||
|
|
||||||
virtual ~nsJSEventListener()
|
virtual ~nsJSEventListener()
|
||||||
{
|
{
|
||||||
@ -204,14 +203,14 @@ public:
|
|||||||
mTarget = nullptr;
|
mTarget = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nsEventHandler& GetHandler() const
|
const mozilla::TypedEventHandler& GetTypedEventHandler() const
|
||||||
{
|
{
|
||||||
return mHandler;
|
return mTypedHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForgetHandler()
|
void ForgetHandler()
|
||||||
{
|
{
|
||||||
mHandler.ForgetHandler();
|
mTypedHandler.ForgetHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIAtom* EventName() const
|
nsIAtom* EventName() const
|
||||||
@ -221,21 +220,21 @@ public:
|
|||||||
|
|
||||||
// Set a handler for this event listener. The handler must already
|
// Set a handler for this event listener. The handler must already
|
||||||
// be bound to the right target.
|
// be bound to the right target.
|
||||||
void SetHandler(const nsEventHandler& aHandler)
|
void SetHandler(const mozilla::TypedEventHandler& aTypedHandler)
|
||||||
{
|
{
|
||||||
mHandler.SetHandler(aHandler);
|
mTypedHandler.SetHandler(aTypedHandler);
|
||||||
}
|
}
|
||||||
void SetHandler(mozilla::dom::EventHandlerNonNull* aHandler)
|
void SetHandler(mozilla::dom::EventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
mHandler.SetHandler(aHandler);
|
mTypedHandler.SetHandler(aHandler);
|
||||||
}
|
}
|
||||||
void SetHandler(mozilla::dom::OnBeforeUnloadEventHandlerNonNull* aHandler)
|
void SetHandler(mozilla::dom::OnBeforeUnloadEventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
mHandler.SetHandler(aHandler);
|
mTypedHandler.SetHandler(aHandler);
|
||||||
}
|
}
|
||||||
void SetHandler(mozilla::dom::OnErrorEventHandlerNonNull* aHandler)
|
void SetHandler(mozilla::dom::OnErrorEventHandlerNonNull* aHandler)
|
||||||
{
|
{
|
||||||
mHandler.SetHandler(aHandler);
|
mTypedHandler.SetHandler(aHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||||
@ -247,7 +246,7 @@ public:
|
|||||||
// - mTarget
|
// - mTarget
|
||||||
//
|
//
|
||||||
// The following members are not measured:
|
// The following members are not measured:
|
||||||
// - mHandler: may be shared with others
|
// - mTypedHandler: may be shared with others
|
||||||
// - mEventName: shared with others
|
// - mEventName: shared with others
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +262,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
nsISupports* mTarget;
|
nsISupports* mTarget;
|
||||||
nsCOMPtr<nsIAtom> mEventName;
|
nsCOMPtr<nsIAtom> mEventName;
|
||||||
nsEventHandler mHandler;
|
mozilla::TypedEventHandler mTypedHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsJSEventListener, NS_JSEVENTLISTENER_IID)
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsJSEventListener, NS_JSEVENTLISTENER_IID)
|
||||||
@ -274,7 +273,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsJSEventListener, NS_JSEVENTLISTENER_IID)
|
|||||||
*/
|
*/
|
||||||
nsresult NS_NewJSEventHandler(nsISupports* aTarget,
|
nsresult NS_NewJSEventHandler(nsISupports* aTarget,
|
||||||
nsIAtom* aType,
|
nsIAtom* aType,
|
||||||
const nsEventHandler& aHandler,
|
const mozilla::TypedEventHandler& aTypedHandler,
|
||||||
nsJSEventListener** aReturn);
|
nsJSEventListener** aReturn);
|
||||||
|
|
||||||
#endif // mozilla_JSEventHandler_h_
|
#endif // mozilla_JSEventHandler_h_
|
||||||
|
@ -322,12 +322,12 @@ nsXBLPrototypeHandler::ExecuteHandler(EventTarget* aTarget,
|
|||||||
nsRefPtr<EventHandlerNonNull> handlerCallback =
|
nsRefPtr<EventHandlerNonNull> handlerCallback =
|
||||||
new EventHandlerNonNull(bound, /* aIncumbentGlobal = */ nullptr);
|
new EventHandlerNonNull(bound, /* aIncumbentGlobal = */ nullptr);
|
||||||
|
|
||||||
nsEventHandler eventHandler(handlerCallback);
|
TypedEventHandler typedHandler(handlerCallback);
|
||||||
|
|
||||||
// Execute it.
|
// Execute it.
|
||||||
nsCOMPtr<nsJSEventListener> eventListener;
|
nsCOMPtr<nsJSEventListener> eventListener;
|
||||||
rv = NS_NewJSEventHandler(scriptTarget, onEventAtom,
|
rv = NS_NewJSEventHandler(scriptTarget, onEventAtom,
|
||||||
eventHandler,
|
typedHandler,
|
||||||
getter_AddRefs(eventListener));
|
getter_AddRefs(eventListener));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user