1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=78: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Ilya Konstantinov (mozilla-code@future.shiny.co.il)
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.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsDOMTextEvent.h"
41 #include "nsContentUtils.h"
42 #include "nsPrivateTextRange.h"
44 nsDOMTextEvent::nsDOMTextEvent(nsPresContext
* aPresContext
,
46 : nsDOMUIEvent(aPresContext
, aEvent
? aEvent
:
47 new nsTextEvent(PR_FALSE
, 0, nsnull
))
49 NS_ASSERTION(mEvent
->eventStructType
== NS_TEXT_EVENT
, "event type mismatch");
52 mEventIsInternal
= PR_FALSE
;
55 mEventIsInternal
= PR_TRUE
;
56 mEvent
->time
= PR_Now();
60 // extract the IME composition string
62 nsTextEvent
*te
= static_cast<nsTextEvent
*>(mEvent
);
66 // build the range list -- ranges need to be DOM-ified since the
67 // IME transaction will hold a ref, the widget representation
70 mTextRange
= new nsPrivateTextRangeList(te
->rangeCount
);
74 for(i
= 0; i
< te
->rangeCount
; i
++) {
75 nsRefPtr
<nsPrivateTextRange
> tempPrivateTextRange
= new
76 nsPrivateTextRange(te
->rangeArray
[i
].mStartOffset
,
77 te
->rangeArray
[i
].mEndOffset
,
78 te
->rangeArray
[i
].mRangeType
);
80 if (tempPrivateTextRange
) {
81 mTextRange
->AppendTextRange(tempPrivateTextRange
);
87 NS_IMPL_ADDREF_INHERITED(nsDOMTextEvent
, nsDOMUIEvent
)
88 NS_IMPL_RELEASE_INHERITED(nsDOMTextEvent
, nsDOMUIEvent
)
90 NS_INTERFACE_MAP_BEGIN(nsDOMTextEvent
)
91 NS_INTERFACE_MAP_ENTRY(nsIPrivateTextEvent
)
92 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent
)
94 NS_METHOD
nsDOMTextEvent::GetText(nsString
& aText
)
100 NS_METHOD_(already_AddRefed
<nsIPrivateTextRangeList
>) nsDOMTextEvent::GetInputRange()
102 if (mEvent
->message
== NS_TEXT_TEXT
) {
103 nsRefPtr
<nsPrivateTextRangeList
> textRange
= mTextRange
;
104 nsPrivateTextRangeList
*textRangePtr
= nsnull
;
105 textRange
.swap(textRangePtr
);
111 NS_METHOD_(nsTextEventReply
*) nsDOMTextEvent::GetEventReply()
113 if (mEvent
->message
== NS_TEXT_TEXT
) {
114 return &(static_cast<nsTextEvent
*>(mEvent
)->theReply
);
119 nsresult
NS_NewDOMTextEvent(nsIDOMEvent
** aInstancePtrResult
,
120 nsPresContext
* aPresContext
,
123 nsDOMTextEvent
* it
= new nsDOMTextEvent(aPresContext
, aEvent
);
125 return NS_ERROR_OUT_OF_MEMORY
;
128 return CallQueryInterface(it
, aInstancePtrResult
);