tor-browser

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

FocusEvent.cpp (2287B)


      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/FocusEvent.h"
      8 
      9 #include "mozilla/ContentEvents.h"
     10 #include "prtime.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 FocusEvent::FocusEvent(EventTarget* aOwner, nsPresContext* aPresContext,
     15                       InternalFocusEvent* aEvent)
     16    : UIEvent(aOwner, aPresContext,
     17              aEvent ? aEvent : new InternalFocusEvent(false, eFocus)) {
     18  if (aEvent) {
     19    mEventIsInternal = false;
     20  } else {
     21    mEventIsInternal = true;
     22  }
     23 }
     24 
     25 already_AddRefed<EventTarget> FocusEvent::GetRelatedTarget() {
     26  return EnsureWebAccessibleRelatedTarget(
     27      mEvent->AsFocusEvent()->mRelatedTarget);
     28 }
     29 
     30 void FocusEvent::InitFocusEvent(const nsAString& aType, bool aCanBubble,
     31                                bool aCancelable, nsGlobalWindowInner* aView,
     32                                int32_t aDetail, EventTarget* aRelatedTarget) {
     33  MOZ_ASSERT(!mEvent->mFlags.mIsBeingDispatched);
     34 
     35  UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
     36  mEvent->AsFocusEvent()->mRelatedTarget = aRelatedTarget;
     37 }
     38 
     39 already_AddRefed<FocusEvent> FocusEvent::Constructor(
     40    const GlobalObject& aGlobal, const nsAString& aType,
     41    const FocusEventInit& aParam) {
     42  nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
     43  RefPtr<FocusEvent> e = new FocusEvent(t, nullptr, nullptr);
     44  bool trusted = e->Init(t);
     45  e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
     46                    aParam.mDetail, aParam.mRelatedTarget);
     47  e->SetTrusted(trusted);
     48  e->SetComposed(aParam.mComposed);
     49  return e.forget();
     50 }
     51 
     52 }  // namespace mozilla::dom
     53 
     54 using namespace mozilla;
     55 using namespace mozilla::dom;
     56 
     57 already_AddRefed<FocusEvent> NS_NewDOMFocusEvent(EventTarget* aOwner,
     58                                                 nsPresContext* aPresContext,
     59                                                 InternalFocusEvent* aEvent) {
     60  RefPtr<FocusEvent> it = new FocusEvent(aOwner, aPresContext, aEvent);
     61  return it.forget();
     62 }