Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / events / XULCommandEvent.cpp
blobb561cd3fb698f76028ca9a3f921361ee7684bb7c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/XULCommandEvent.h"
8 #include "prtime.h"
10 namespace mozilla::dom {
12 XULCommandEvent::XULCommandEvent(EventTarget* aOwner,
13 nsPresContext* aPresContext,
14 WidgetInputEvent* aEvent)
15 : UIEvent(
16 aOwner, aPresContext,
17 aEvent ? aEvent : new WidgetInputEvent(false, eVoidEvent, nullptr)),
18 mInputSource(0) {
19 if (aEvent) {
20 mEventIsInternal = false;
21 } else {
22 mEventIsInternal = true;
26 NS_IMPL_ADDREF_INHERITED(XULCommandEvent, UIEvent)
27 NS_IMPL_RELEASE_INHERITED(XULCommandEvent, UIEvent)
29 NS_IMPL_CYCLE_COLLECTION_INHERITED(XULCommandEvent, UIEvent, mSourceEvent)
31 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XULCommandEvent)
32 NS_INTERFACE_MAP_END_INHERITING(UIEvent)
34 bool XULCommandEvent::AltKey() { return mEvent->AsInputEvent()->IsAlt(); }
36 bool XULCommandEvent::CtrlKey() { return mEvent->AsInputEvent()->IsControl(); }
38 bool XULCommandEvent::ShiftKey() { return mEvent->AsInputEvent()->IsShift(); }
40 bool XULCommandEvent::MetaKey() { return mEvent->AsInputEvent()->IsMeta(); }
42 uint16_t XULCommandEvent::InputSource() { return mInputSource; }
44 void XULCommandEvent::InitCommandEvent(
45 const nsAString& aType, bool aCanBubble, bool aCancelable,
46 nsGlobalWindowInner* aView, int32_t aDetail, bool aCtrlKey, bool aAltKey,
47 bool aShiftKey, bool aMetaKey, int16_t aButton, Event* aSourceEvent,
48 uint16_t aInputSource, ErrorResult& aRv) {
49 if (NS_WARN_IF(mEvent->mFlags.mIsBeingDispatched)) {
50 return;
53 UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
55 mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey,
56 aMetaKey);
57 mSourceEvent = aSourceEvent;
58 mInputSource = aInputSource;
59 mButton = aButton;
62 } // namespace mozilla::dom
64 using namespace mozilla;
65 using namespace mozilla::dom;
67 already_AddRefed<XULCommandEvent> NS_NewDOMXULCommandEvent(
68 EventTarget* aOwner, nsPresContext* aPresContext,
69 WidgetInputEvent* aEvent) {
70 RefPtr<XULCommandEvent> it =
71 new XULCommandEvent(aOwner, aPresContext, aEvent);
72 return it.forget();