Bug 601299: Find RegExpStatics in cx->globalObject if necessary. (r=mrbkap)
[mozilla-central.git] / content / events / src / nsDOMTextEvent.cpp
blobcac870a2d1130194d37a6ff1796301ae0ea2d8f3
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
14 * License.
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.
23 * Contributor(s):
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,
45 nsTextEvent* aEvent)
46 : nsDOMUIEvent(aPresContext, aEvent ? aEvent :
47 new nsTextEvent(PR_FALSE, 0, nsnull))
49 NS_ASSERTION(mEvent->eventStructType == NS_TEXT_EVENT, "event type mismatch");
51 if (aEvent) {
52 mEventIsInternal = PR_FALSE;
54 else {
55 mEventIsInternal = PR_TRUE;
56 mEvent->time = PR_Now();
60 // extract the IME composition string
62 nsTextEvent *te = static_cast<nsTextEvent*>(mEvent);
63 mText = te->theText;
66 // build the range list -- ranges need to be DOM-ified since the
67 // IME transaction will hold a ref, the widget representation
68 // isn't persistent
70 mTextRange = new nsPrivateTextRangeList(te->rangeCount);
71 if (mTextRange) {
72 PRUint16 i;
74 for(i = 0; i < te->rangeCount; i++) {
75 nsRefPtr<nsPrivateTextRange> tempPrivateTextRange = new
76 nsPrivateTextRange(te->rangeArray[i]);
78 if (tempPrivateTextRange) {
79 mTextRange->AppendTextRange(tempPrivateTextRange);
85 NS_IMPL_ADDREF_INHERITED(nsDOMTextEvent, nsDOMUIEvent)
86 NS_IMPL_RELEASE_INHERITED(nsDOMTextEvent, nsDOMUIEvent)
88 NS_INTERFACE_MAP_BEGIN(nsDOMTextEvent)
89 NS_INTERFACE_MAP_ENTRY(nsIPrivateTextEvent)
90 NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
92 NS_METHOD nsDOMTextEvent::GetText(nsString& aText)
94 aText = mText;
95 return NS_OK;
98 NS_METHOD_(already_AddRefed<nsIPrivateTextRangeList>) nsDOMTextEvent::GetInputRange()
100 if (mEvent->message == NS_TEXT_TEXT) {
101 nsRefPtr<nsPrivateTextRangeList> textRange = mTextRange;
102 nsPrivateTextRangeList *textRangePtr = nsnull;
103 textRange.swap(textRangePtr);
104 return textRangePtr;
106 return nsnull;
109 nsresult NS_NewDOMTextEvent(nsIDOMEvent** aInstancePtrResult,
110 nsPresContext* aPresContext,
111 nsTextEvent *aEvent)
113 nsDOMTextEvent* it = new nsDOMTextEvent(aPresContext, aEvent);
114 if (nsnull == it) {
115 return NS_ERROR_OUT_OF_MEMORY;
118 return CallQueryInterface(it, aInstancePtrResult);