dom/events/CommandEvent.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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))
    19 {
    20   mEvent->time = PR_Now();
    21   if (aEvent) {
    22     mEventIsInternal = false;
    23   } else {
    24     mEventIsInternal = true;
    25   }
    26 }
    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)
    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 }
    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);
    56   mEvent->AsCommandEvent()->command = do_GetAtom(aCommand);
    57   return NS_OK;
    58 }
    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)
    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