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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "VRDisplayEvent.h"
8 #include "js/RootingAPI.h"
9 #include "mozilla/dom/Nullable.h"
10 #include "mozilla/dom/PrimitiveConversions.h"
11
12 using namespace mozilla::gfx;
13
14 namespace mozilla {
15 namespace dom {
16
17 NS_IMPL_CYCLE_COLLECTION_CLASS(VRDisplayEvent)
18
NS_IMPL_ADDREF_INHERITED(VRDisplayEvent,Event)19 NS_IMPL_ADDREF_INHERITED(VRDisplayEvent, Event)
20 NS_IMPL_RELEASE_INHERITED(VRDisplayEvent, Event)
21
22 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(VRDisplayEvent, Event)
23 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
24
25 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(VRDisplayEvent, Event)
26 NS_IMPL_CYCLE_COLLECTION_TRACE_END
27
28 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(VRDisplayEvent, Event)
29 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
30
31 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(VRDisplayEvent)
32 NS_INTERFACE_MAP_END_INHERITING(Event)
33
34 VRDisplayEvent::VRDisplayEvent(mozilla::dom::EventTarget* aOwner)
35 : Event(aOwner, nullptr, nullptr) {}
36
Display()37 VRDisplay* VRDisplayEvent::Display() { return mDisplay; }
38
WrapObjectInternal(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)39 JSObject* VRDisplayEvent::WrapObjectInternal(
40 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
41 return VRDisplayEvent_Binding::Wrap(aCx, this, aGivenProto);
42 }
43
Constructor(mozilla::dom::EventTarget * aOwner,const nsAString & aType,const VRDisplayEventInit & aEventInitDict)44 already_AddRefed<VRDisplayEvent> VRDisplayEvent::Constructor(
45 mozilla::dom::EventTarget* aOwner, const nsAString& aType,
46 const VRDisplayEventInit& aEventInitDict) {
47 RefPtr<VRDisplayEvent> e = new VRDisplayEvent(aOwner);
48 bool trusted = e->Init(aOwner);
49 e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
50 if (aEventInitDict.mReason.WasPassed()) {
51 e->mReason = Some(aEventInitDict.mReason.Value());
52 }
53 e->mDisplay = aEventInitDict.mDisplay;
54 e->SetTrusted(trusted);
55 e->SetComposed(aEventInitDict.mComposed);
56 return e.forget();
57 }
58
Constructor(const GlobalObject & aGlobal,const nsAString & aType,const VRDisplayEventInit & aEventInitDict)59 already_AddRefed<VRDisplayEvent> VRDisplayEvent::Constructor(
60 const GlobalObject& aGlobal, const nsAString& aType,
61 const VRDisplayEventInit& aEventInitDict) {
62 nsCOMPtr<mozilla::dom::EventTarget> owner =
63 do_QueryInterface(aGlobal.GetAsSupports());
64 return Constructor(owner, aType, aEventInitDict);
65 }
66
GetReason() const67 Nullable<VRDisplayEventReason> VRDisplayEvent::GetReason() const {
68 if (mReason.isSome()) {
69 return mReason.value();
70 }
71
72 return nullptr;
73 }
74
75 } // namespace dom
76 } // namespace mozilla
77