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
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 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Ilya Konstantinov (mozilla-code@future.shiny.co.il)
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 "nsDOMTextEvent.h"
41 : #include "nsContentUtils.h"
42 : #include "nsPrivateTextRange.h"
43 :
44 0 : nsDOMTextEvent::nsDOMTextEvent(nsPresContext* aPresContext,
45 : nsTextEvent* aEvent)
46 : : nsDOMUIEvent(aPresContext, aEvent ? aEvent :
47 0 : new nsTextEvent(false, 0, nsnull))
48 : {
49 0 : NS_ASSERTION(mEvent->eventStructType == NS_TEXT_EVENT, "event type mismatch");
50 :
51 0 : if (aEvent) {
52 0 : mEventIsInternal = false;
53 : }
54 : else {
55 0 : mEventIsInternal = true;
56 0 : mEvent->time = PR_Now();
57 : }
58 :
59 : //
60 : // extract the IME composition string
61 : //
62 0 : nsTextEvent *te = static_cast<nsTextEvent*>(mEvent);
63 0 : mText = te->theText;
64 :
65 : //
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
69 : //
70 0 : mTextRange = new nsPrivateTextRangeList(te->rangeCount);
71 0 : if (mTextRange) {
72 : PRUint16 i;
73 :
74 0 : for(i = 0; i < te->rangeCount; i++) {
75 : nsRefPtr<nsPrivateTextRange> tempPrivateTextRange = new
76 0 : nsPrivateTextRange(te->rangeArray[i]);
77 :
78 0 : if (tempPrivateTextRange) {
79 0 : mTextRange->AppendTextRange(tempPrivateTextRange);
80 : }
81 : }
82 : }
83 0 : }
84 :
85 0 : NS_IMPL_ADDREF_INHERITED(nsDOMTextEvent, nsDOMUIEvent)
86 0 : NS_IMPL_RELEASE_INHERITED(nsDOMTextEvent, nsDOMUIEvent)
87 :
88 0 : NS_INTERFACE_MAP_BEGIN(nsDOMTextEvent)
89 0 : NS_INTERFACE_MAP_ENTRY(nsIPrivateTextEvent)
90 0 : NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
91 :
92 0 : NS_METHOD nsDOMTextEvent::GetText(nsString& aText)
93 : {
94 0 : aText = mText;
95 0 : return NS_OK;
96 : }
97 :
98 0 : NS_METHOD_(already_AddRefed<nsIPrivateTextRangeList>) nsDOMTextEvent::GetInputRange()
99 : {
100 0 : if (mEvent->message == NS_TEXT_TEXT) {
101 0 : nsRefPtr<nsPrivateTextRangeList> textRange = mTextRange;
102 0 : nsPrivateTextRangeList *textRangePtr = nsnull;
103 0 : textRange.swap(textRangePtr);
104 0 : return textRangePtr;
105 : }
106 0 : return nsnull;
107 : }
108 :
109 0 : nsresult NS_NewDOMTextEvent(nsIDOMEvent** aInstancePtrResult,
110 : nsPresContext* aPresContext,
111 : nsTextEvent *aEvent)
112 : {
113 0 : nsDOMTextEvent* it = new nsDOMTextEvent(aPresContext, aEvent);
114 0 : if (nsnull == it) {
115 0 : return NS_ERROR_OUT_OF_MEMORY;
116 : }
117 :
118 0 : return CallQueryInterface(it, aInstancePtrResult);
119 : }
|