1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/CommandEvent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/dom/CommandEvent.h" 1.10 +#include "mozilla/MiscEvents.h" 1.11 +#include "prtime.h" 1.12 + 1.13 +namespace mozilla { 1.14 +namespace dom { 1.15 + 1.16 +CommandEvent::CommandEvent(EventTarget* aOwner, 1.17 + nsPresContext* aPresContext, 1.18 + WidgetCommandEvent* aEvent) 1.19 + : Event(aOwner, aPresContext, 1.20 + aEvent ? aEvent : 1.21 + new WidgetCommandEvent(false, nullptr, nullptr, nullptr)) 1.22 +{ 1.23 + mEvent->time = PR_Now(); 1.24 + if (aEvent) { 1.25 + mEventIsInternal = false; 1.26 + } else { 1.27 + mEventIsInternal = true; 1.28 + } 1.29 +} 1.30 + 1.31 +NS_INTERFACE_MAP_BEGIN(CommandEvent) 1.32 + NS_INTERFACE_MAP_ENTRY(nsIDOMCommandEvent) 1.33 +NS_INTERFACE_MAP_END_INHERITING(Event) 1.34 + 1.35 +NS_IMPL_ADDREF_INHERITED(CommandEvent, Event) 1.36 +NS_IMPL_RELEASE_INHERITED(CommandEvent, Event) 1.37 + 1.38 +NS_IMETHODIMP 1.39 +CommandEvent::GetCommand(nsAString& aCommand) 1.40 +{ 1.41 + nsIAtom* command = mEvent->AsCommandEvent()->command; 1.42 + if (command) { 1.43 + command->ToString(aCommand); 1.44 + } else { 1.45 + aCommand.Truncate(); 1.46 + } 1.47 + return NS_OK; 1.48 +} 1.49 + 1.50 +NS_IMETHODIMP 1.51 +CommandEvent::InitCommandEvent(const nsAString& aTypeArg, 1.52 + bool aCanBubbleArg, 1.53 + bool aCancelableArg, 1.54 + const nsAString& aCommand) 1.55 +{ 1.56 + nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); 1.57 + NS_ENSURE_SUCCESS(rv, rv); 1.58 + 1.59 + mEvent->AsCommandEvent()->command = do_GetAtom(aCommand); 1.60 + return NS_OK; 1.61 +} 1.62 + 1.63 +} // namespace dom 1.64 +} // namespace mozilla 1.65 + 1.66 +using namespace mozilla; 1.67 +using namespace mozilla::dom; 1.68 + 1.69 +nsresult 1.70 +NS_NewDOMCommandEvent(nsIDOMEvent** aInstancePtrResult, 1.71 + EventTarget* aOwner, 1.72 + nsPresContext* aPresContext, 1.73 + WidgetCommandEvent* aEvent) 1.74 +{ 1.75 + CommandEvent* it = new CommandEvent(aOwner, aPresContext, aEvent); 1.76 + NS_ADDREF(it); 1.77 + *aInstancePtrResult = static_cast<Event*>(it); 1.78 + return NS_OK; 1.79 +}