tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

XULCommandEvent.cpp (2501B)


      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/. */
      6 
      7 #include "mozilla/dom/XULCommandEvent.h"
      8 
      9 #include "prtime.h"
     10 
     11 namespace mozilla::dom {
     12 
     13 XULCommandEvent::XULCommandEvent(EventTarget* aOwner,
     14                                 nsPresContext* aPresContext,
     15                                 WidgetInputEvent* aEvent)
     16    : UIEvent(
     17          aOwner, aPresContext,
     18          aEvent ? aEvent : new WidgetInputEvent(false, eVoidEvent, nullptr)),
     19      mInputSource(0) {
     20  if (aEvent) {
     21    mEventIsInternal = false;
     22  } else {
     23    mEventIsInternal = true;
     24  }
     25 }
     26 
     27 NS_IMPL_ADDREF_INHERITED(XULCommandEvent, UIEvent)
     28 NS_IMPL_RELEASE_INHERITED(XULCommandEvent, UIEvent)
     29 
     30 NS_IMPL_CYCLE_COLLECTION_INHERITED(XULCommandEvent, UIEvent, mSourceEvent)
     31 
     32 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(XULCommandEvent)
     33 NS_INTERFACE_MAP_END_INHERITING(UIEvent)
     34 
     35 bool XULCommandEvent::AltKey() { return mEvent->AsInputEvent()->IsAlt(); }
     36 
     37 bool XULCommandEvent::CtrlKey() { return mEvent->AsInputEvent()->IsControl(); }
     38 
     39 bool XULCommandEvent::ShiftKey() { return mEvent->AsInputEvent()->IsShift(); }
     40 
     41 bool XULCommandEvent::MetaKey() { return mEvent->AsInputEvent()->IsMeta(); }
     42 
     43 uint16_t XULCommandEvent::InputSource() { return mInputSource; }
     44 
     45 void XULCommandEvent::InitCommandEvent(
     46    const nsAString& aType, bool aCanBubble, bool aCancelable,
     47    nsGlobalWindowInner* aView, int32_t aDetail, bool aCtrlKey, bool aAltKey,
     48    bool aShiftKey, bool aMetaKey, int16_t aButton, Event* aSourceEvent,
     49    uint16_t aInputSource, ErrorResult& aRv) {
     50  if (NS_WARN_IF(mEvent->mFlags.mIsBeingDispatched)) {
     51    return;
     52  }
     53 
     54  UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
     55 
     56  mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey,
     57                                             aMetaKey);
     58  mSourceEvent = aSourceEvent;
     59  mInputSource = aInputSource;
     60  mButton = aButton;
     61 }
     62 
     63 }  // namespace mozilla::dom
     64 
     65 using namespace mozilla;
     66 using namespace mozilla::dom;
     67 
     68 already_AddRefed<XULCommandEvent> NS_NewDOMXULCommandEvent(
     69    EventTarget* aOwner, nsPresContext* aPresContext,
     70    WidgetInputEvent* aEvent) {
     71  RefPtr<XULCommandEvent> it =
     72      new XULCommandEvent(aOwner, aPresContext, aEvent);
     73  return it.forget();
     74 }