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 #ifndef CustomEvent_h__
8 #define CustomEvent_h__
9 
10 #include "mozilla/dom/Event.h"
11 #include "nsIDOMCustomEvent.h"
12 
13 namespace mozilla {
14 namespace dom {
15 
16 struct CustomEventInit;
17 
18 class CustomEvent final : public Event, public nsIDOMCustomEvent {
19  private:
20   virtual ~CustomEvent();
21 
22   JS::Heap<JS::Value> mDetail;
23 
24  public:
25   explicit CustomEvent(mozilla::dom::EventTarget* aOwner,
26                        nsPresContext* aPresContext = nullptr,
27                        mozilla::WidgetEvent* aEvent = nullptr);
28 
29   NS_DECL_ISUPPORTS_INHERITED
30   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CustomEvent, Event)
31   NS_FORWARD_TO_EVENT
32   NS_DECL_NSIDOMCUSTOMEVENT
33 
34   static already_AddRefed<CustomEvent> Constructor(
35       const GlobalObject& aGlobal, const nsAString& aType,
36       const CustomEventInit& aParam, ErrorResult& aRv);
37 
38   virtual JSObject* WrapObjectInternal(
39       JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
40 
41   void GetDetail(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval);
42 
43   void InitCustomEvent(JSContext* aCx, const nsAString& aType, bool aCanBubble,
44                        bool aCancelable, JS::Handle<JS::Value> aDetail,
45                        ErrorResult& aRv);
46 };
47 
48 }  // namespace dom
49 }  // namespace mozilla
50 
51 already_AddRefed<mozilla::dom::CustomEvent> NS_NewDOMCustomEvent(
52     mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
53     mozilla::WidgetEvent* aEvent);
54 
55 #endif  // CustomEvent_h__
56