Merge autoland to mozilla-central. a=merge
[gecko.git] / dom / events / FocusEvent.cpp
blobe00ce5ae327ac92720f0dfe74e6b8677ebebea8a
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;
24 already_AddRefed<EventTarget> FocusEvent::GetRelatedTarget() {
25 return EnsureWebAccessibleRelatedTarget(
26 mEvent->AsFocusEvent()->mRelatedTarget);
29 void FocusEvent::InitFocusEvent(const nsAString& aType, bool aCanBubble,
30 bool aCancelable, nsGlobalWindowInner* aView,
31 int32_t aDetail, EventTarget* aRelatedTarget) {
32 MOZ_ASSERT(!mEvent->mFlags.mIsBeingDispatched);
34 UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
35 mEvent->AsFocusEvent()->mRelatedTarget = aRelatedTarget;
38 already_AddRefed<FocusEvent> FocusEvent::Constructor(
39 const GlobalObject& aGlobal, const nsAString& aType,
40 const FocusEventInit& aParam) {
41 nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
42 RefPtr<FocusEvent> e = new FocusEvent(t, nullptr, nullptr);
43 bool trusted = e->Init(t);
44 e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
45 aParam.mDetail, aParam.mRelatedTarget);
46 e->SetTrusted(trusted);
47 e->SetComposed(aParam.mComposed);
48 return e.forget();
51 } // namespace mozilla::dom
53 using namespace mozilla;
54 using namespace mozilla::dom;
56 already_AddRefed<FocusEvent> NS_NewDOMFocusEvent(EventTarget* aOwner,
57 nsPresContext* aPresContext,
58 InternalFocusEvent* aEvent) {
59 RefPtr<FocusEvent> it = new FocusEvent(aOwner, aPresContext, aEvent);
60 return it.forget();