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 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2011
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Masayuki Nakano <masayuki@d-toybox.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsDOMCompositionEvent.h"
41 : #include "nsDOMClassInfoID.h"
42 :
43 0 : nsDOMCompositionEvent::nsDOMCompositionEvent(nsPresContext* aPresContext,
44 : nsCompositionEvent* aEvent)
45 : : nsDOMUIEvent(aPresContext, aEvent ? aEvent :
46 0 : new nsCompositionEvent(false, 0, nsnull))
47 : {
48 0 : NS_ASSERTION(mEvent->eventStructType == NS_COMPOSITION_EVENT,
49 : "event type mismatch");
50 :
51 0 : if (aEvent) {
52 0 : mEventIsInternal = false;
53 : } else {
54 0 : mEventIsInternal = true;
55 0 : mEvent->time = PR_Now();
56 :
57 : // XXX compositionstart is cancelable in draft of DOM3 Events.
58 : // However, it doesn't make sence for us, we cannot cancel composition
59 : // when we sends compositionstart event.
60 0 : mEvent->flags |= NS_EVENT_FLAG_CANT_CANCEL;
61 : }
62 :
63 0 : mData = static_cast<nsCompositionEvent*>(mEvent)->data;
64 : // TODO: Native event should have locale information.
65 0 : }
66 :
67 0 : nsDOMCompositionEvent::~nsDOMCompositionEvent()
68 : {
69 0 : if (mEventIsInternal) {
70 0 : delete static_cast<nsCompositionEvent*>(mEvent);
71 0 : mEvent = nsnull;
72 : }
73 0 : }
74 :
75 0 : NS_IMPL_ADDREF_INHERITED(nsDOMCompositionEvent, nsDOMUIEvent)
76 0 : NS_IMPL_RELEASE_INHERITED(nsDOMCompositionEvent, nsDOMUIEvent)
77 :
78 : DOMCI_DATA(CompositionEvent, nsDOMCompositionEvent)
79 :
80 0 : NS_INTERFACE_MAP_BEGIN(nsDOMCompositionEvent)
81 0 : NS_INTERFACE_MAP_ENTRY(nsIDOMCompositionEvent)
82 0 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CompositionEvent)
83 0 : NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
84 :
85 : NS_IMETHODIMP
86 0 : nsDOMCompositionEvent::GetData(nsAString& aData)
87 : {
88 0 : aData = mData;
89 0 : return NS_OK;
90 : }
91 :
92 : NS_IMETHODIMP
93 0 : nsDOMCompositionEvent::GetLocale(nsAString& aLocale)
94 : {
95 0 : aLocale = mLocale;
96 0 : return NS_OK;
97 : }
98 :
99 : NS_IMETHODIMP
100 0 : nsDOMCompositionEvent::InitCompositionEvent(const nsAString& aType,
101 : bool aCanBubble,
102 : bool aCancelable,
103 : nsIDOMWindow* aView,
104 : const nsAString& aData,
105 : const nsAString& aLocale)
106 : {
107 : nsresult rv =
108 0 : nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
109 0 : NS_ENSURE_SUCCESS(rv, rv);
110 :
111 0 : mData = aData;
112 0 : mLocale = aLocale;
113 0 : return NS_OK;
114 : }
115 :
116 : nsresult
117 0 : NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult,
118 : nsPresContext* aPresContext,
119 : nsCompositionEvent *aEvent)
120 : {
121 : nsDOMCompositionEvent* event =
122 0 : new nsDOMCompositionEvent(aPresContext, aEvent);
123 0 : return CallQueryInterface(event, aInstancePtrResult);
124 : }
|