Bug 1572460 - Refactor `selection` out of the `InspectorFront`. r=yulia
[gecko.git] / dom / events / FocusEvent.cpp
blob69cc179d3ac66ac7820c0765938c0ed1989e1e1f
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/FocusEvent.h"
8 #include "mozilla/ContentEvents.h"
9 #include "prtime.h"
11 namespace mozilla {
12 namespace dom {
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 mEvent->mTime = PR_Now();
26 already_AddRefed<EventTarget> FocusEvent::GetRelatedTarget() {
27 return EnsureWebAccessibleRelatedTarget(
28 mEvent->AsFocusEvent()->mRelatedTarget);
31 void FocusEvent::InitFocusEvent(const nsAString& aType, bool aCanBubble,
32 bool aCancelable, nsGlobalWindowInner* aView,
33 int32_t aDetail, EventTarget* aRelatedTarget) {
34 MOZ_ASSERT(!mEvent->mFlags.mIsBeingDispatched);
36 UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
37 mEvent->AsFocusEvent()->mRelatedTarget = aRelatedTarget;
40 already_AddRefed<FocusEvent> FocusEvent::Constructor(
41 const GlobalObject& aGlobal, const nsAString& aType,
42 const FocusEventInit& aParam, ErrorResult& aRv) {
43 nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
44 RefPtr<FocusEvent> e = new FocusEvent(t, nullptr, nullptr);
45 bool trusted = e->Init(t);
46 e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
47 aParam.mDetail, aParam.mRelatedTarget);
48 e->SetTrusted(trusted);
49 e->SetComposed(aParam.mComposed);
50 return e.forget();
53 } // namespace dom
54 } // namespace mozilla
56 using namespace mozilla;
57 using namespace mozilla::dom;
59 already_AddRefed<FocusEvent> NS_NewDOMFocusEvent(EventTarget* aOwner,
60 nsPresContext* aPresContext,
61 InternalFocusEvent* aEvent) {
62 RefPtr<FocusEvent> it = new FocusEvent(aOwner, aPresContext, aEvent);
63 return it.forget();