/src/mozilla-central/dom/events/FocusEvent.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | FocusEvent::FocusEvent(EventTarget* aOwner, |
15 | | nsPresContext* aPresContext, |
16 | | InternalFocusEvent* aEvent) |
17 | | : UIEvent(aOwner, aPresContext, |
18 | | aEvent ? aEvent : new InternalFocusEvent(false, eFocus)) |
19 | 0 | { |
20 | 0 | if (aEvent) { |
21 | 0 | mEventIsInternal = false; |
22 | 0 | } else { |
23 | 0 | mEventIsInternal = true; |
24 | 0 | mEvent->mTime = PR_Now(); |
25 | 0 | } |
26 | 0 | } |
27 | | |
28 | | already_AddRefed<EventTarget> |
29 | | FocusEvent::GetRelatedTarget() |
30 | 0 | { |
31 | 0 | return |
32 | 0 | EnsureWebAccessibleRelatedTarget(mEvent->AsFocusEvent()->mRelatedTarget); |
33 | 0 | } |
34 | | |
35 | | void |
36 | | FocusEvent::InitFocusEvent(const nsAString& aType, |
37 | | bool aCanBubble, |
38 | | bool aCancelable, |
39 | | nsGlobalWindowInner* aView, |
40 | | int32_t aDetail, |
41 | | EventTarget* aRelatedTarget) |
42 | 0 | { |
43 | 0 | MOZ_ASSERT(!mEvent->mFlags.mIsBeingDispatched); |
44 | 0 |
|
45 | 0 | UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail); |
46 | 0 | mEvent->AsFocusEvent()->mRelatedTarget = aRelatedTarget; |
47 | 0 | } |
48 | | |
49 | | already_AddRefed<FocusEvent> |
50 | | FocusEvent::Constructor(const GlobalObject& aGlobal, |
51 | | const nsAString& aType, |
52 | | const FocusEventInit& aParam, |
53 | | ErrorResult& aRv) |
54 | 0 | { |
55 | 0 | nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); |
56 | 0 | RefPtr<FocusEvent> e = new FocusEvent(t, nullptr, nullptr); |
57 | 0 | bool trusted = e->Init(t); |
58 | 0 | e->InitFocusEvent(aType, aParam.mBubbles, aParam.mCancelable, aParam.mView, |
59 | 0 | aParam.mDetail, aParam.mRelatedTarget); |
60 | 0 | e->SetTrusted(trusted); |
61 | 0 | e->SetComposed(aParam.mComposed); |
62 | 0 | return e.forget(); |
63 | 0 | } |
64 | | |
65 | | } // namespace dom |
66 | | } // namespace mozilla |
67 | | |
68 | | using namespace mozilla; |
69 | | using namespace mozilla::dom; |
70 | | |
71 | | already_AddRefed<FocusEvent> |
72 | | NS_NewDOMFocusEvent(EventTarget* aOwner, |
73 | | nsPresContext* aPresContext, |
74 | | InternalFocusEvent* aEvent) |
75 | 0 | { |
76 | 0 | RefPtr<FocusEvent> it = new FocusEvent(aOwner, aPresContext, aEvent); |
77 | 0 | return it.forget(); |
78 | 0 | } |