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 mozilla_dom_CompositionEvent_h_
8 #define mozilla_dom_CompositionEvent_h_
9 
10 #include "mozilla/dom/CompositionEventBinding.h"
11 #include "mozilla/dom/TextClause.h"
12 #include "mozilla/dom/TypedArray.h"
13 #include "mozilla/dom/UIEvent.h"
14 #include "mozilla/EventForwards.h"
15 
16 namespace mozilla {
17 namespace dom {
18 
19 typedef nsTArray<RefPtr<TextClause>> TextClauseArray;
20 
21 class CompositionEvent : public UIEvent {
22  public:
23   CompositionEvent(EventTarget* aOwner, nsPresContext* aPresContext,
24                    WidgetCompositionEvent* aEvent);
25 
26   NS_DECL_ISUPPORTS_INHERITED
27   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CompositionEvent, UIEvent)
28 
29   static already_AddRefed<CompositionEvent> Constructor(
30       const GlobalObject& aGlobal, const nsAString& aType,
31       const CompositionEventInit& aParam);
32 
WrapObjectInternal(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)33   virtual JSObject* WrapObjectInternal(
34       JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
35     return CompositionEvent_Binding::Wrap(aCx, this, aGivenProto);
36   }
37 
38   void InitCompositionEvent(const nsAString& aType, bool aCanBubble,
39                             bool aCancelable, nsGlobalWindowInner* aView,
40                             const nsAString& aData, const nsAString& aLocale);
41   void GetData(nsAString&) const;
42   void GetLocale(nsAString&) const;
43   void GetRanges(TextClauseArray& aRanges);
44 
45  protected:
46   ~CompositionEvent() = default;
47 
48   nsString mData;
49   nsString mLocale;
50   TextClauseArray mRanges;
51 };
52 
53 }  // namespace dom
54 }  // namespace mozilla
55 
56 already_AddRefed<mozilla::dom::CompositionEvent> NS_NewDOMCompositionEvent(
57     mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
58     mozilla::WidgetCompositionEvent* aEvent);
59 
60 #endif  // mozilla_dom_CompositionEvent_h_
61