2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-04-17 01:16:08 +04:00
|
|
|
/* 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-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2013-04-17 01:16:08 +04:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2013-08-28 02:39:02 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2013-04-17 01:16:08 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
void
|
|
|
|
EventTarget::RemoveEventListener(const nsAString& aType,
|
2013-09-24 04:25:17 +04:00
|
|
|
EventListener* aListener,
|
2013-04-17 01:16:08 +04:00
|
|
|
bool aUseCapture,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
2013-04-17 01:16:08 +04:00
|
|
|
if (elm) {
|
|
|
|
elm->RemoveEventListener(aType, aListener, aUseCapture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 21:07:16 +04:00
|
|
|
EventHandlerNonNull*
|
2013-08-16 14:06:24 +04:00
|
|
|
EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
|
2013-05-09 21:07:16 +04:00
|
|
|
{
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
2013-08-16 14:06:24 +04:00
|
|
|
return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
|
2013-05-09 21:07:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-16 14:06:24 +04:00
|
|
|
EventTarget::SetEventHandler(const nsAString& aType,
|
|
|
|
EventHandlerNonNull* aHandler,
|
2013-09-17 15:01:28 +04:00
|
|
|
ErrorResult& aRv)
|
2013-05-09 21:07:16 +04:00
|
|
|
{
|
2013-09-17 15:01:28 +04:00
|
|
|
if (!StringBeginsWith(aType, NS_LITERAL_STRING("on"))) {
|
|
|
|
aRv.Throw(NS_ERROR_INVALID_ARG);
|
|
|
|
return;
|
|
|
|
}
|
2013-08-16 14:06:24 +04:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
nsCOMPtr<nsIAtom> type = do_GetAtom(aType);
|
2013-09-17 15:01:28 +04:00
|
|
|
SetEventHandler(type, EmptyString(), aHandler);
|
|
|
|
return;
|
2013-08-16 14:06:24 +04:00
|
|
|
}
|
2013-09-17 15:01:28 +04:00
|
|
|
SetEventHandler(nullptr,
|
|
|
|
Substring(aType, 2), // Remove "on"
|
|
|
|
aHandler);
|
2013-08-16 14:06:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
|
2013-09-17 15:01:28 +04:00
|
|
|
EventHandlerNonNull* aHandler)
|
2013-08-16 14:06:24 +04:00
|
|
|
{
|
2013-10-23 03:32:04 +04:00
|
|
|
GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
|
2013-05-09 21:07:16 +04:00
|
|
|
}
|
|
|
|
|
2013-04-17 01:16:08 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|