dom/events/CompositionEvent.cpp

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:9fa2044cfcf4
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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/CompositionEvent.h"
8 #include "mozilla/TextEvents.h"
9 #include "prtime.h"
10
11 namespace mozilla {
12 namespace dom {
13
14 CompositionEvent::CompositionEvent(EventTarget* aOwner,
15 nsPresContext* aPresContext,
16 WidgetCompositionEvent* aEvent)
17 : UIEvent(aOwner, aPresContext,
18 aEvent ? aEvent : new WidgetCompositionEvent(false, 0, nullptr))
19 {
20 NS_ASSERTION(mEvent->eventStructType == NS_COMPOSITION_EVENT,
21 "event type mismatch");
22
23 if (aEvent) {
24 mEventIsInternal = false;
25 } else {
26 mEventIsInternal = true;
27 mEvent->time = PR_Now();
28
29 // XXX compositionstart is cancelable in draft of DOM3 Events.
30 // However, it doesn't make sence for us, we cannot cancel composition
31 // when we sends compositionstart event.
32 mEvent->mFlags.mCancelable = false;
33 }
34
35 mData = mEvent->AsCompositionEvent()->data;
36 // TODO: Native event should have locale information.
37 }
38
39 NS_IMPL_ADDREF_INHERITED(CompositionEvent, UIEvent)
40 NS_IMPL_RELEASE_INHERITED(CompositionEvent, UIEvent)
41
42 NS_INTERFACE_MAP_BEGIN(CompositionEvent)
43 NS_INTERFACE_MAP_ENTRY(nsIDOMCompositionEvent)
44 NS_INTERFACE_MAP_END_INHERITING(UIEvent)
45
46 NS_IMETHODIMP
47 CompositionEvent::GetData(nsAString& aData)
48 {
49 aData = mData;
50 return NS_OK;
51 }
52
53 NS_IMETHODIMP
54 CompositionEvent::GetLocale(nsAString& aLocale)
55 {
56 aLocale = mLocale;
57 return NS_OK;
58 }
59
60 NS_IMETHODIMP
61 CompositionEvent::InitCompositionEvent(const nsAString& aType,
62 bool aCanBubble,
63 bool aCancelable,
64 nsIDOMWindow* aView,
65 const nsAString& aData,
66 const nsAString& aLocale)
67 {
68 nsresult rv = UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
69 NS_ENSURE_SUCCESS(rv, rv);
70
71 mData = aData;
72 mLocale = aLocale;
73 return NS_OK;
74 }
75
76 } // namespace dom
77 } // namespace mozilla
78
79 using namespace mozilla;
80 using namespace mozilla::dom;
81
82 nsresult
83 NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult,
84 EventTarget* aOwner,
85 nsPresContext* aPresContext,
86 WidgetCompositionEvent* aEvent)
87 {
88 CompositionEvent* event = new CompositionEvent(aOwner, aPresContext, aEvent);
89 return CallQueryInterface(event, aInstancePtrResult);
90 }

mercurial