2013-04-16 21:16:08 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/EventTarget.h"
|
|
|
|
#include "nsEventListenerManager.h"
|
2013-08-27 22:39:02 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2013-04-16 21:16:08 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
void
|
|
|
|
EventTarget::RemoveEventListener(const nsAString& aType,
|
2013-09-24 00:25:17 +00:00
|
|
|
EventListener* aListener,
|
2013-04-16 21:16:08 +00:00
|
|
|
bool aUseCapture,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2013-10-22 23:32:04 +00:00
|
|
|
nsEventListenerManager* elm = GetExistingListenerManager();
|
2013-04-16 21:16:08 +00:00
|
|
|
if (elm) {
|
|
|
|
elm->RemoveEventListener(aType, aListener, aUseCapture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 17:07:16 +00:00
|
|
|
EventHandlerNonNull*
|
2013-08-16 10:06:24 +00:00
|
|
|
EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
|
2013-05-09 17:07:16 +00:00
|
|
|
{
|
2013-10-22 23:32:04 +00:00
|
|
|
nsEventListenerManager* elm = GetExistingListenerManager();
|
2013-08-16 10:06:24 +00:00
|
|
|
return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
|
2013-05-09 17:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-16 10:06:24 +00:00
|
|
|
EventTarget::SetEventHandler(const nsAString& aType,
|
|
|
|
EventHandlerNonNull* aHandler,
|
2013-09-17 11:01:28 +00:00
|
|
|
ErrorResult& aRv)
|
2013-05-09 17:07:16 +00:00
|
|
|
{
|
2013-09-17 11:01:28 +00:00
|
|
|
if (!StringBeginsWith(aType, NS_LITERAL_STRING("on"))) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
2013-08-16 10:06:24 +00:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsIAtom> type = do_GetAtom(aType);
|
2013-09-17 11:01:28 +00:00
|
|
|
SetEventHandler(type, EmptyString(), aHandler);
|
|
|
|
return;
|
2013-08-16 10:06:24 +00:00
|
|
|
}
|
2013-09-17 11:01:28 +00:00
|
|
|
SetEventHandler(nullptr,
|
|
|
|
Substring(aType, 2), // Remove "on"
|
|
|
|
aHandler);
|
2013-08-16 10:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
|
2013-09-17 11:01:28 +00:00
|
|
|
EventHandlerNonNull* aHandler)
|
2013-08-16 10:06:24 +00:00
|
|
|
{
|
2013-10-22 23:32:04 +00:00
|
|
|
GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
|
2013-05-09 17:07:16 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 21:16:08 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|