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"
|
2016-04-26 11:23:17 +03:00
|
|
|
#include "mozilla/dom/EventTargetBinding.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,
|
2016-04-26 11:23:17 +03:00
|
|
|
const EventListenerOptionsOrBoolean& aOptions,
|
2013-04-17 01:16:08 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
2013-04-17 01:16:08 +04:00
|
|
|
if (elm) {
|
2016-04-26 11:23:17 +03:00
|
|
|
elm->RemoveEventListener(aType, aListener, aOptions);
|
2013-04-17 01:16:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()) {
|
2016-03-29 02:09:43 +03:00
|
|
|
nsCOMPtr<nsIAtom> type = NS_Atomize(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
|
|
|
}
|
|
|
|
|
2015-09-17 13:16:20 +03:00
|
|
|
bool
|
2016-05-06 13:39:10 +03:00
|
|
|
EventTarget::IsApzAware() const
|
2015-09-17 13:16:20 +03:00
|
|
|
{
|
|
|
|
EventListenerManager* elm = GetExistingListenerManager();
|
|
|
|
return elm && elm->HasApzAwareListeners();
|
|
|
|
}
|
|
|
|
|
2016-04-07 15:49:12 +03:00
|
|
|
bool
|
|
|
|
EventTarget::DispatchEvent(JSContext* aCx,
|
|
|
|
Event& aEvent,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
aRv = DispatchEvent(&aEvent, &result);
|
|
|
|
return !aEvent.DefaultPrevented(aCx);
|
|
|
|
}
|
|
|
|
|
2013-04-17 01:16:08 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|