Bug 1688354 [wpt PR 27298] - Treat 'rem' as an absolute unit for font size, a=testonly
[gecko.git] / dom / events / FocusEvent.cpp
blob1e801cf4ff0598bebeb65d2ec2a7f3cbfc36ec79
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::dom {
13 FocusEvent::FocusEvent(EventTarget* aOwner, nsPresContext* aPresContext,
14 InternalFocusEvent* aEvent)
15 : UIEvent(aOwner, aPresContext,
16 aEvent ? aEvent : new InternalFocusEvent(false, eFocus)) {
17 if (aEvent) {
18 mEventIsInternal = false;
19 } else {
20 mEventIsInternal = true;
21 mEvent->mTime = PR_Now();
25 already_AddRefed<EventTarget> FocusEvent::GetRelatedTarget() {
26 return EnsureWebAccessibleRelatedTarget(
27 mEvent->AsFocusEvent()->mRelatedTarget);
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);
35 UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
36 mEvent->AsFocusEvent()->mRelatedTarget = aRelatedTarget;
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();
52 } // namespace mozilla::dom
54 using namespace mozilla;
55 using namespace mozilla::dom;
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();