Line data Source code
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 : #include "mozilla/ContentEvents.h"
9 : #include "prtime.h"
10 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 21 : NS_IMPL_ISUPPORTS_INHERITED(FocusEvent, UIEvent, nsIDOMFocusEvent)
15 :
16 5 : FocusEvent::FocusEvent(EventTarget* aOwner,
17 : nsPresContext* aPresContext,
18 5 : InternalFocusEvent* aEvent)
19 : : UIEvent(aOwner, aPresContext,
20 5 : aEvent ? aEvent : new InternalFocusEvent(false, eFocus))
21 : {
22 5 : if (aEvent) {
23 5 : mEventIsInternal = false;
24 : } else {
25 0 : mEventIsInternal = true;
26 0 : mEvent->mTime = PR_Now();
27 : }
28 5 : }
29 :
30 : NS_IMETHODIMP
31 0 : FocusEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
32 : {
33 0 : NS_ENSURE_ARG_POINTER(aRelatedTarget);
34 0 : *aRelatedTarget = GetRelatedTarget().take();
35 0 : return NS_OK;
36 : }
37 :
38 : already_AddRefed<EventTarget>
39 0 : FocusEvent::GetRelatedTarget()
40 : {
41 : return
42 0 : EnsureWebAccessibleRelatedTarget(mEvent->AsFocusEvent()->mRelatedTarget);
43 : }
44 :
45 : void
46 0 : FocusEvent::InitFocusEvent(const nsAString& aType,
47 : bool aCanBubble,
48 : bool aCancelable,
49 : nsGlobalWindow* aView,
50 : int32_t aDetail,
51 : EventTarget* aRelatedTarget)
52 : {
53 0 : MOZ_ASSERT(!mEvent->mFlags.mIsBeingDispatched);
54 :
55 0 : UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail);
56 0 : mEvent->AsFocusEvent()->mRelatedTarget = aRelatedTarget;
57 0 : }
58 :
59 : already_AddRefed<FocusEvent>
60 0 : FocusEvent::Constructor(const GlobalObject& aGlobal,
61 : const nsAString& aType,
62 : const FocusEventInit& aParam,
63 : ErrorResult& aRv)
64 : {
65 0 : nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
66 0 : RefPtr<FocusEvent> e = new FocusEvent(t, nullptr, nullptr);
67 0 : bool trusted = e->Init(t);
68 0 : e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView,
69 0 : aParam.mDetail, aParam.mRelatedTarget);
70 0 : e->SetTrusted(trusted);
71 0 : e->SetComposed(aParam.mComposed);
72 0 : return e.forget();
73 : }
74 :
75 : } // namespace dom
76 : } // namespace mozilla
77 :
78 : using namespace mozilla;
79 : using namespace mozilla::dom;
80 :
81 : already_AddRefed<FocusEvent>
82 5 : NS_NewDOMFocusEvent(EventTarget* aOwner,
83 : nsPresContext* aPresContext,
84 : InternalFocusEvent* aEvent)
85 : {
86 10 : RefPtr<FocusEvent> it = new FocusEvent(aOwner, aPresContext, aEvent);
87 10 : return it.forget();
88 : }
|