dom/events/EventTarget.cpp

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:6dcdd8b73bcf
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "mozilla/EventListenerManager.h"
7 #include "mozilla/dom/EventTarget.h"
8 #include "nsThreadUtils.h"
9
10 namespace mozilla {
11 namespace dom {
12
13 void
14 EventTarget::RemoveEventListener(const nsAString& aType,
15 EventListener* aListener,
16 bool aUseCapture,
17 ErrorResult& aRv)
18 {
19 EventListenerManager* elm = GetExistingListenerManager();
20 if (elm) {
21 elm->RemoveEventListener(aType, aListener, aUseCapture);
22 }
23 }
24
25 EventHandlerNonNull*
26 EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
27 {
28 EventListenerManager* elm = GetExistingListenerManager();
29 return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
30 }
31
32 void
33 EventTarget::SetEventHandler(const nsAString& aType,
34 EventHandlerNonNull* aHandler,
35 ErrorResult& aRv)
36 {
37 if (!StringBeginsWith(aType, NS_LITERAL_STRING("on"))) {
38 aRv.Throw(NS_ERROR_INVALID_ARG);
39 return;
40 }
41 if (NS_IsMainThread()) {
42 nsCOMPtr<nsIAtom> type = do_GetAtom(aType);
43 SetEventHandler(type, EmptyString(), aHandler);
44 return;
45 }
46 SetEventHandler(nullptr,
47 Substring(aType, 2), // Remove "on"
48 aHandler);
49 }
50
51 void
52 EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
53 EventHandlerNonNull* aHandler)
54 {
55 GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
56 }
57
58 } // namespace dom
59 } // namespace mozilla

mercurial