2013-04-16 14:16:08 -07: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/. */
|
|
|
|
|
2014-03-16 23:56:53 -07:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2013-04-16 14:16:08 -07:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2013-08-27 15:39:02 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2013-04-16 14:16:08 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
void
|
|
|
|
EventTarget::RemoveEventListener(const nsAString& aType,
|
2013-09-23 17:25:17 -07:00
|
|
|
EventListener* aListener,
|
2013-04-16 14:16:08 -07:00
|
|
|
bool aUseCapture,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
2013-04-16 14:16:08 -07:00
|
|
|
if (elm) {
|
|
|
|
elm->RemoveEventListener(aType, aListener, aUseCapture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 10:07:16 -07:00
|
|
|
EventHandlerNonNull*
|
2013-08-16 03:06:24 -07:00
|
|
|
EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
|
2013-05-09 10:07:16 -07:00
|
|
|
{
|
2014-03-16 23:56:53 -07:00
|
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
2013-08-16 03:06:24 -07:00
|
|
|
return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
|
2013-05-09 10:07:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-16 03:06:24 -07:00
|
|
|
EventTarget::SetEventHandler(const nsAString& aType,
|
|
|
|
EventHandlerNonNull* aHandler,
|
2013-09-17 04:01:28 -07:00
|
|
|
ErrorResult& aRv)
|
2013-05-09 10:07:16 -07:00
|
|
|
{
|
2013-09-17 04:01:28 -07:00
|
|
|
if (!StringBeginsWith(aType, NS_LITERAL_STRING("on"))) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
2013-08-16 03:06:24 -07:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsIAtom> type = do_GetAtom(aType);
|
2013-09-17 04:01:28 -07:00
|
|
|
SetEventHandler(type, EmptyString(), aHandler);
|
|
|
|
return;
|
2013-08-16 03:06:24 -07:00
|
|
|
}
|
2013-09-17 04:01:28 -07:00
|
|
|
SetEventHandler(nullptr,
|
|
|
|
Substring(aType, 2), // Remove "on"
|
|
|
|
aHandler);
|
2013-08-16 03:06:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
|
2013-09-17 04:01:28 -07:00
|
|
|
EventHandlerNonNull* aHandler)
|
2013-08-16 03:06:24 -07:00
|
|
|
{
|
2013-10-22 16:32:04 -07:00
|
|
|
GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
|
2013-05-09 10:07:16 -07:00
|
|
|
}
|
|
|
|
|
2013-04-16 14:16:08 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|