dom/events/CommandEvent.cpp

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:294d7a1d98a0
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/dom/CommandEvent.h"
7 #include "mozilla/MiscEvents.h"
8 #include "prtime.h"
9
10 namespace mozilla {
11 namespace dom {
12
13 CommandEvent::CommandEvent(EventTarget* aOwner,
14 nsPresContext* aPresContext,
15 WidgetCommandEvent* aEvent)
16 : Event(aOwner, aPresContext,
17 aEvent ? aEvent :
18 new WidgetCommandEvent(false, nullptr, nullptr, nullptr))
19 {
20 mEvent->time = PR_Now();
21 if (aEvent) {
22 mEventIsInternal = false;
23 } else {
24 mEventIsInternal = true;
25 }
26 }
27
28 NS_INTERFACE_MAP_BEGIN(CommandEvent)
29 NS_INTERFACE_MAP_ENTRY(nsIDOMCommandEvent)
30 NS_INTERFACE_MAP_END_INHERITING(Event)
31
32 NS_IMPL_ADDREF_INHERITED(CommandEvent, Event)
33 NS_IMPL_RELEASE_INHERITED(CommandEvent, Event)
34
35 NS_IMETHODIMP
36 CommandEvent::GetCommand(nsAString& aCommand)
37 {
38 nsIAtom* command = mEvent->AsCommandEvent()->command;
39 if (command) {
40 command->ToString(aCommand);
41 } else {
42 aCommand.Truncate();
43 }
44 return NS_OK;
45 }
46
47 NS_IMETHODIMP
48 CommandEvent::InitCommandEvent(const nsAString& aTypeArg,
49 bool aCanBubbleArg,
50 bool aCancelableArg,
51 const nsAString& aCommand)
52 {
53 nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
54 NS_ENSURE_SUCCESS(rv, rv);
55
56 mEvent->AsCommandEvent()->command = do_GetAtom(aCommand);
57 return NS_OK;
58 }
59
60 } // namespace dom
61 } // namespace mozilla
62
63 using namespace mozilla;
64 using namespace mozilla::dom;
65
66 nsresult
67 NS_NewDOMCommandEvent(nsIDOMEvent** aInstancePtrResult,
68 EventTarget* aOwner,
69 nsPresContext* aPresContext,
70 WidgetCommandEvent* aEvent)
71 {
72 CommandEvent* it = new CommandEvent(aOwner, aPresContext, aEvent);
73 NS_ADDREF(it);
74 *aInstancePtrResult = static_cast<Event*>(it);
75 return NS_OK;
76 }

mercurial