michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/EventListenerManager.h" michael@0: #include "mozilla/dom/EventTarget.h" michael@0: #include "nsThreadUtils.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: void michael@0: EventTarget::RemoveEventListener(const nsAString& aType, michael@0: EventListener* aListener, michael@0: bool aUseCapture, michael@0: ErrorResult& aRv) michael@0: { michael@0: EventListenerManager* elm = GetExistingListenerManager(); michael@0: if (elm) { michael@0: elm->RemoveEventListener(aType, aListener, aUseCapture); michael@0: } michael@0: } michael@0: michael@0: EventHandlerNonNull* michael@0: EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString) michael@0: { michael@0: EventListenerManager* elm = GetExistingListenerManager(); michael@0: return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr; michael@0: } michael@0: michael@0: void michael@0: EventTarget::SetEventHandler(const nsAString& aType, michael@0: EventHandlerNonNull* aHandler, michael@0: ErrorResult& aRv) michael@0: { michael@0: if (!StringBeginsWith(aType, NS_LITERAL_STRING("on"))) { michael@0: aRv.Throw(NS_ERROR_INVALID_ARG); michael@0: return; michael@0: } michael@0: if (NS_IsMainThread()) { michael@0: nsCOMPtr type = do_GetAtom(aType); michael@0: SetEventHandler(type, EmptyString(), aHandler); michael@0: return; michael@0: } michael@0: SetEventHandler(nullptr, michael@0: Substring(aType, 2), // Remove "on" michael@0: aHandler); michael@0: } michael@0: michael@0: void michael@0: EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString, michael@0: EventHandlerNonNull* aHandler) michael@0: { michael@0: GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla