Bug 1025824 - Fix mHwcLayerMap handling r=sushil
[gecko.git] / dom / events / CommandEvent.cpp
blob956d8ff790dc49bbde6cc601cc0f0483e1fc17eb
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/. */
6 #include "mozilla/dom/CommandEvent.h"
7 #include "mozilla/MiscEvents.h"
8 #include "prtime.h"
10 namespace mozilla {
11 namespace dom {
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))
20 mEvent->time = PR_Now();
21 if (aEvent) {
22 mEventIsInternal = false;
23 } else {
24 mEventIsInternal = true;
28 NS_INTERFACE_MAP_BEGIN(CommandEvent)
29 NS_INTERFACE_MAP_ENTRY(nsIDOMCommandEvent)
30 NS_INTERFACE_MAP_END_INHERITING(Event)
32 NS_IMPL_ADDREF_INHERITED(CommandEvent, Event)
33 NS_IMPL_RELEASE_INHERITED(CommandEvent, Event)
35 NS_IMETHODIMP
36 CommandEvent::GetCommand(nsAString& aCommand)
38 nsIAtom* command = mEvent->AsCommandEvent()->command;
39 if (command) {
40 command->ToString(aCommand);
41 } else {
42 aCommand.Truncate();
44 return NS_OK;
47 NS_IMETHODIMP
48 CommandEvent::InitCommandEvent(const nsAString& aTypeArg,
49 bool aCanBubbleArg,
50 bool aCancelableArg,
51 const nsAString& aCommand)
53 nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
54 NS_ENSURE_SUCCESS(rv, rv);
56 mEvent->AsCommandEvent()->command = do_GetAtom(aCommand);
57 return NS_OK;
60 } // namespace dom
61 } // namespace mozilla
63 using namespace mozilla;
64 using namespace mozilla::dom;
66 nsresult
67 NS_NewDOMCommandEvent(nsIDOMEvent** aInstancePtrResult,
68 EventTarget* aOwner,
69 nsPresContext* aPresContext,
70 WidgetCommandEvent* aEvent)
72 CommandEvent* it = new CommandEvent(aOwner, aPresContext, aEvent);
73 NS_ADDREF(it);
74 *aInstancePtrResult = static_cast<Event*>(it);
75 return NS_OK;