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/dom/CommandEvent.h" michael@0: #include "mozilla/MiscEvents.h" michael@0: #include "prtime.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: CommandEvent::CommandEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetCommandEvent* aEvent) michael@0: : Event(aOwner, aPresContext, michael@0: aEvent ? aEvent : michael@0: new WidgetCommandEvent(false, nullptr, nullptr, nullptr)) michael@0: { michael@0: mEvent->time = PR_Now(); michael@0: if (aEvent) { michael@0: mEventIsInternal = false; michael@0: } else { michael@0: mEventIsInternal = true; michael@0: } michael@0: } michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(CommandEvent) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMCommandEvent) michael@0: NS_INTERFACE_MAP_END_INHERITING(Event) michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(CommandEvent, Event) michael@0: NS_IMPL_RELEASE_INHERITED(CommandEvent, Event) michael@0: michael@0: NS_IMETHODIMP michael@0: CommandEvent::GetCommand(nsAString& aCommand) michael@0: { michael@0: nsIAtom* command = mEvent->AsCommandEvent()->command; michael@0: if (command) { michael@0: command->ToString(aCommand); michael@0: } else { michael@0: aCommand.Truncate(); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: CommandEvent::InitCommandEvent(const nsAString& aTypeArg, michael@0: bool aCanBubbleArg, michael@0: bool aCancelableArg, michael@0: const nsAString& aCommand) michael@0: { michael@0: nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: mEvent->AsCommandEvent()->command = do_GetAtom(aCommand); michael@0: return NS_OK; michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::dom; michael@0: michael@0: nsresult michael@0: NS_NewDOMCommandEvent(nsIDOMEvent** aInstancePtrResult, michael@0: EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetCommandEvent* aEvent) michael@0: { michael@0: CommandEvent* it = new CommandEvent(aOwner, aPresContext, aEvent); michael@0: NS_ADDREF(it); michael@0: *aInstancePtrResult = static_cast(it); michael@0: return NS_OK; michael@0: }