2001-09-20 00:02:59 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
1999-06-29 20:31:22 +00:00
|
|
|
*
|
2001-09-20 00:02:59 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
1999-11-06 03:43:54 +00:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2001-09-20 00:02:59 +00:00
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-06-29 20:31:22 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-06-29 20:31:22 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-20 00:02:59 +00:00
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
2001-09-20 00:02:59 +00:00
|
|
|
* Contributor(s):
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-20 00:02:59 +00:00
|
|
|
*/
|
1999-06-29 20:31:22 +00:00
|
|
|
|
|
|
|
#include "IMETextTxn.h"
|
|
|
|
#include "nsEditor.h"
|
|
|
|
#include "nsIDOMCharacterData.h"
|
1999-08-06 02:32:13 +00:00
|
|
|
#include "nsIPrivateTextRange.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
1999-06-29 20:31:22 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "EditAggregateTxn.h"
|
1999-10-27 00:10:03 +00:00
|
|
|
#include "nsLayoutCID.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsISelectionController.h"
|
1999-12-01 00:35:31 +00:00
|
|
|
|
|
|
|
// #define DEBUG_IMETXN
|
1999-10-27 00:10:03 +00:00
|
|
|
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
1999-06-29 20:31:22 +00:00
|
|
|
|
2000-09-14 11:45:01 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMSelectionIID, NS_ISELECTION_IID);
|
1999-06-29 20:31:22 +00:00
|
|
|
|
|
|
|
nsIAtom *IMETextTxn::gIMETextTxnName = nsnull;
|
|
|
|
|
|
|
|
nsresult IMETextTxn::ClassInit()
|
|
|
|
{
|
|
|
|
if (nsnull==gIMETextTxnName)
|
|
|
|
gIMETextTxnName = NS_NewAtom("NS_IMETextTxn");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-06 20:27:41 +00:00
|
|
|
nsresult IMETextTxn::ClassShutdown()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(gIMETextTxnName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-29 20:31:22 +00:00
|
|
|
IMETextTxn::IMETextTxn()
|
|
|
|
: EditTxn()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
IMETextTxn::~IMETextTxn()
|
|
|
|
{
|
1999-08-25 10:51:55 +00:00
|
|
|
mRangeList = do_QueryInterface(nsnull);
|
1999-06-29 20:31:22 +00:00
|
|
|
}
|
|
|
|
|
1999-08-25 10:51:55 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::Init(nsIDOMCharacterData *aElement,
|
|
|
|
PRUint32 aOffset,
|
|
|
|
PRUint32 aReplaceLength,
|
|
|
|
nsIPrivateTextRangeList *aTextRangeList,
|
2001-04-07 00:45:26 +00:00
|
|
|
const nsAReadableString &aStringToInsert,
|
2000-04-28 06:20:36 +00:00
|
|
|
nsWeakPtr aSelConWeak)
|
1999-06-29 20:31:22 +00:00
|
|
|
{
|
1999-10-18 14:48:41 +00:00
|
|
|
NS_ASSERTION(aElement, "illegal value- null ptr- aElement");
|
|
|
|
NS_ASSERTION(aTextRangeList, "illegal value- null ptr - aTextRangeList");
|
|
|
|
if((nsnull == aElement) || (nsnull == aTextRangeList))
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-06-29 20:31:22 +00:00
|
|
|
mElement = do_QueryInterface(aElement);
|
|
|
|
mOffset = aOffset;
|
|
|
|
mReplaceLength = aReplaceLength;
|
|
|
|
mStringToInsert = aStringToInsert;
|
2000-04-28 06:20:36 +00:00
|
|
|
mSelConWeak = aSelConWeak;
|
1999-06-29 20:31:22 +00:00
|
|
|
mRangeList = do_QueryInterface(aTextRangeList);
|
|
|
|
mFixed = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::DoTransaction(void)
|
1999-06-29 20:31:22 +00:00
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_IMETXN
|
|
|
|
printf("Do IME Text element = %p replace = %d len = %d\n", mElement.get(), mReplaceLength, mStringToInsert.Length());
|
|
|
|
#endif
|
|
|
|
|
2000-04-28 06:20:36 +00:00
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
|
|
|
|
if (!selCon) return NS_ERROR_NOT_INITIALIZED;
|
1999-08-25 10:51:55 +00:00
|
|
|
|
|
|
|
// advance caret: This requires the presentation shell to get the selection.
|
1999-10-27 00:10:03 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (mReplaceLength==0) {
|
1999-08-25 10:51:55 +00:00
|
|
|
result = mElement->InsertData(mOffset,mStringToInsert);
|
1999-10-27 00:10:03 +00:00
|
|
|
} else {
|
1999-08-25 10:51:55 +00:00
|
|
|
result = mElement->ReplaceData(mOffset,mReplaceLength,mStringToInsert);
|
1999-10-27 00:10:03 +00:00
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = CollapseTextSelection();
|
1999-08-25 10:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
1999-06-29 20:31:22 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::UndoTransaction(void)
|
1999-06-29 20:31:22 +00:00
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG_IMETXN
|
|
|
|
printf("Undo IME Text element = %p\n", mElement.get());
|
|
|
|
#endif
|
|
|
|
|
2000-04-28 06:20:36 +00:00
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
|
2000-04-27 07:37:12 +00:00
|
|
|
if (!selCon) return NS_ERROR_NOT_INITIALIZED;
|
1999-08-25 10:51:55 +00:00
|
|
|
|
1999-06-29 20:31:22 +00:00
|
|
|
nsresult result;
|
|
|
|
PRUint32 length = mStringToInsert.Length();
|
|
|
|
result = mElement->DeleteData(mOffset, length);
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
{ // set the selection to the insertion point where the string was removed
|
2000-09-14 11:45:01 +00:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
2000-04-27 07:37:12 +00:00
|
|
|
result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
1999-06-29 20:31:22 +00:00
|
|
|
if (NS_SUCCEEDED(result) && selection) {
|
1999-07-18 02:27:19 +00:00
|
|
|
result = selection->Collapse(mElement, mOffset);
|
1999-06-29 20:31:22 +00:00
|
|
|
NS_ASSERTION((NS_SUCCEEDED(result)), "selection could not be collapsed after undo of IME insert.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
|
1999-06-29 20:31:22 +00:00
|
|
|
{
|
1999-10-18 14:48:41 +00:00
|
|
|
NS_ASSERTION(aDidMerge, "illegal vaule- null ptr- aDidMerge");
|
|
|
|
NS_ASSERTION(aTransaction, "illegal vaule- null ptr- aTransaction");
|
|
|
|
if((nsnull == aDidMerge) || (nsnull == aTransaction))
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-08-25 10:51:55 +00:00
|
|
|
nsresult result;
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG_IMETXN
|
|
|
|
printf("Merge IME Text element = %p\n", mElement.get());
|
|
|
|
#endif
|
1999-06-29 20:31:22 +00:00
|
|
|
|
1999-08-25 10:51:55 +00:00
|
|
|
//
|
|
|
|
// check to make sure we have valid return pointers
|
|
|
|
//
|
|
|
|
if ((nsnull==aDidMerge) && (nsnull==aTransaction))
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// check to make sure we aren't fixed, if we are then nothing get's absorbed
|
|
|
|
//
|
|
|
|
if (mFixed) {
|
|
|
|
*aDidMerge = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// if aTransaction is another IMETextTxn then absorbe it
|
|
|
|
//
|
|
|
|
IMETextTxn* otherTxn = nsnull;
|
|
|
|
result = aTransaction->QueryInterface(IMETextTxn::GetCID(),(void**)&otherTxn);
|
2000-06-08 23:40:31 +00:00
|
|
|
if (otherTxn && NS_SUCCEEDED(result))
|
1999-08-25 10:51:55 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// we absorbe the next IME transaction by adopting it's insert string as our own
|
|
|
|
//
|
|
|
|
nsIPrivateTextRangeList* newTextRangeList;
|
|
|
|
otherTxn->GetData(mStringToInsert,&newTextRangeList);
|
|
|
|
mRangeList = do_QueryInterface(newTextRangeList);
|
|
|
|
*aDidMerge = PR_TRUE;
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG_IMETXN
|
|
|
|
printf("IMETextTxn assimilated IMETextTxn:%p\n", aTransaction);
|
|
|
|
#endif
|
1999-08-25 10:51:55 +00:00
|
|
|
NS_RELEASE(otherTxn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aDidMerge = PR_FALSE;
|
|
|
|
return NS_OK;
|
1999-06-29 20:31:22 +00:00
|
|
|
}
|
|
|
|
|
2000-07-11 19:51:36 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::MarkFixed(void)
|
|
|
|
{
|
|
|
|
mFixed = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-09 14:23:59 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::GetTxnDescription(nsAWritableString& aString)
|
1999-06-29 20:31:22 +00:00
|
|
|
{
|
2001-03-09 14:23:59 +00:00
|
|
|
aString.Assign(NS_LITERAL_STRING("IMETextTxn: "));
|
|
|
|
aString += mStringToInsert;
|
1999-06-29 20:31:22 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ============= nsISupports implementation ====================== */
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IMETextTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-07-15 19:13:46 +00:00
|
|
|
if (aIID.Equals(IMETextTxn::GetCID())) {
|
1999-06-29 20:31:22 +00:00
|
|
|
*aInstancePtr = (void*)(IMETextTxn*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return (EditTxn::QueryInterface(aIID, aInstancePtr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ============ protected methods ================== */
|
1999-10-27 00:10:03 +00:00
|
|
|
static SelectionType TextRangeToSelection(int aTextRangeType)
|
|
|
|
{
|
|
|
|
switch(aTextRangeType)
|
|
|
|
{
|
|
|
|
case nsIPrivateTextRange::TEXTRANGE_RAWINPUT:
|
2000-04-27 07:37:12 +00:00
|
|
|
return nsISelectionController::SELECTION_IME_RAWINPUT;
|
1999-10-27 00:10:03 +00:00
|
|
|
case nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT:
|
2000-04-27 07:37:12 +00:00
|
|
|
return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;
|
1999-10-27 00:10:03 +00:00
|
|
|
case nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT:
|
2000-04-27 07:37:12 +00:00
|
|
|
return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;
|
1999-10-27 00:10:03 +00:00
|
|
|
case nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
2000-04-27 07:37:12 +00:00
|
|
|
return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;
|
1999-10-27 00:10:03 +00:00
|
|
|
case nsIPrivateTextRange::TEXTRANGE_CARETPOSITION:
|
|
|
|
default:
|
2000-04-27 07:37:12 +00:00
|
|
|
return nsISelectionController::SELECTION_NORMAL;
|
1999-10-27 00:10:03 +00:00
|
|
|
};
|
|
|
|
}
|
1999-06-29 20:31:22 +00:00
|
|
|
|
1999-08-06 02:32:13 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::GetData(nsString& aResult,nsIPrivateTextRangeList** aTextRangeList)
|
1999-06-29 20:31:22 +00:00
|
|
|
{
|
1999-10-18 14:48:41 +00:00
|
|
|
NS_ASSERTION(aTextRangeList, "illegal value- null ptr- aTextRangeList");
|
|
|
|
if(nsnull == aTextRangeList)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-06-29 20:31:22 +00:00
|
|
|
aResult = mStringToInsert;
|
|
|
|
*aTextRangeList = mRangeList;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-27 00:10:03 +00:00
|
|
|
static SelectionType sel[4]=
|
|
|
|
{
|
2000-04-27 07:37:12 +00:00
|
|
|
nsISelectionController::SELECTION_IME_RAWINPUT,
|
|
|
|
nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT,
|
|
|
|
nsISelectionController::SELECTION_IME_CONVERTEDTEXT,
|
|
|
|
nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT
|
1999-10-27 00:10:03 +00:00
|
|
|
};
|
|
|
|
|
1999-06-29 20:31:22 +00:00
|
|
|
NS_IMETHODIMP IMETextTxn::CollapseTextSelection(void)
|
|
|
|
{
|
1999-08-25 10:51:55 +00:00
|
|
|
nsresult result;
|
|
|
|
PRUint16 textRangeListLength,selectionStart,selectionEnd,
|
1999-10-27 00:10:03 +00:00
|
|
|
textRangeType, i;
|
1999-08-25 10:51:55 +00:00
|
|
|
nsIPrivateTextRange* textRange;
|
|
|
|
|
1999-06-29 20:31:22 +00:00
|
|
|
|
1999-12-01 00:35:31 +00:00
|
|
|
#ifdef DEBUG_IMETXN
|
1999-08-25 10:51:55 +00:00
|
|
|
PRUint16 listlen,start,stop,type;
|
|
|
|
nsIPrivateTextRange* rangePtr;
|
|
|
|
result = mRangeList->GetLength(&listlen);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("nsIPrivateTextRangeList[%p]\n",mRangeList);
|
1999-08-25 10:51:55 +00:00
|
|
|
for (i=0;i<listlen;i++) {
|
|
|
|
(void)mRangeList->Item(i,&rangePtr);
|
|
|
|
rangePtr->GetRangeStart(&start);
|
|
|
|
rangePtr->GetRangeEnd(&stop);
|
|
|
|
rangePtr->GetRangeType(&type);
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("range[%d] start=%d end=%d type=",i,start,stop,type);
|
1999-10-27 00:10:03 +00:00
|
|
|
if (type==nsIPrivateTextRange::TEXTRANGE_RAWINPUT)
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("TEXTRANGE_RAWINPUT\n");
|
1999-10-27 00:10:03 +00:00
|
|
|
else if (type==nsIPrivateTextRange::TEXTRANGE_SELECTEDRAWTEXT)
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("TEXTRANGE_SELECTEDRAWTEXT\n");
|
1999-10-27 00:10:03 +00:00
|
|
|
else if (type==nsIPrivateTextRange::TEXTRANGE_CONVERTEDTEXT)
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("TEXTRANGE_CONVERTEDTEXT\n");
|
1999-10-27 00:10:03 +00:00
|
|
|
else if (type==nsIPrivateTextRange::TEXTRANGE_SELECTEDCONVERTEDTEXT)
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("TEXTRANGE_SELECTEDCONVERTEDTEXT\n");
|
1999-10-27 00:10:03 +00:00
|
|
|
else if (type==nsIPrivateTextRange::TEXTRANGE_CARETPOSITION)
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("TEXTRANGE_CARETPOSITION\n");
|
|
|
|
else printf("unknown constant\n");
|
1999-08-25 10:51:55 +00:00
|
|
|
}
|
1999-06-29 20:31:22 +00:00
|
|
|
#endif
|
1999-08-25 10:51:55 +00:00
|
|
|
|
|
|
|
//
|
1999-10-26 18:54:47 +00:00
|
|
|
// run through the text range list, if any
|
1999-08-25 10:51:55 +00:00
|
|
|
//
|
2000-04-28 06:20:36 +00:00
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryReferent(mSelConWeak);
|
2000-04-27 07:37:12 +00:00
|
|
|
if (!selCon) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
1999-10-27 00:10:03 +00:00
|
|
|
result = mRangeList->GetLength(&textRangeListLength);
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
return result;
|
2000-09-14 11:45:01 +00:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
2000-04-27 07:37:12 +00:00
|
|
|
result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
2000-09-14 11:45:01 +00:00
|
|
|
nsCOMPtr<nsISelection> imeSel;
|
1999-10-27 00:10:03 +00:00
|
|
|
if(NS_SUCCEEDED(result))
|
1999-08-25 10:51:55 +00:00
|
|
|
{
|
2000-09-14 11:45:01 +00:00
|
|
|
nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(selection));
|
|
|
|
result = selPriv->StartBatchChanges();
|
1999-10-27 00:10:03 +00:00
|
|
|
if (NS_SUCCEEDED(result))
|
1999-10-26 18:54:47 +00:00
|
|
|
{
|
1999-10-27 00:10:03 +00:00
|
|
|
for(PRInt8 selIdx = 0; selIdx < 4;selIdx++)
|
|
|
|
{
|
2000-04-27 07:37:12 +00:00
|
|
|
result = selCon->GetSelection(sel[selIdx], getter_AddRefs(imeSel));
|
1999-10-27 00:10:03 +00:00
|
|
|
if(NS_SUCCEEDED(result))
|
1999-10-26 18:54:47 +00:00
|
|
|
{
|
2000-09-14 11:45:01 +00:00
|
|
|
result = imeSel->RemoveAllRanges();
|
1999-10-27 00:10:03 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot ClearSelection");
|
|
|
|
// we just ignore the result and clean up the next one here
|
1999-10-26 18:54:47 +00:00
|
|
|
}
|
1999-08-25 10:51:55 +00:00
|
|
|
}
|
1999-10-27 00:10:03 +00:00
|
|
|
PRBool setCaret=PR_FALSE;
|
|
|
|
for(i=0;i<textRangeListLength;i++)
|
|
|
|
{
|
|
|
|
result = mRangeList->Item(i,&textRange);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get item");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
result = textRange->GetRangeType(&textRangeType);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range type");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
result = textRange->GetRangeStart(&selectionStart);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range start");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
result = textRange->GetRangeEnd(&selectionEnd);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "cannot get range end");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(nsIPrivateTextRange::TEXTRANGE_CARETPOSITION == textRangeType)
|
|
|
|
{
|
|
|
|
// Set the caret....
|
|
|
|
result = selection->Collapse(mElement,
|
|
|
|
mOffset+selectionStart);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot Collapse");
|
|
|
|
if(NS_SUCCEEDED(result))
|
|
|
|
setCaret = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
// NS_ASSERTION(selectionStart != selectionEnd, "end == start");
|
|
|
|
if(selectionStart == selectionEnd)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> newRange;
|
|
|
|
|
2000-04-27 07:37:12 +00:00
|
|
|
result= selCon->GetSelection(TextRangeToSelection(textRangeType),
|
1999-10-27 00:10:03 +00:00
|
|
|
getter_AddRefs(imeSel));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot get selction");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
result = nsComponentManager::CreateInstance(kRangeCID,
|
|
|
|
nsnull,
|
2000-01-11 20:49:15 +00:00
|
|
|
NS_GET_IID(nsIDOMRange),
|
1999-10-27 00:10:03 +00:00
|
|
|
getter_AddRefs(newRange));
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot create new nsIDOMRange");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
newRange->SetStart(mElement,mOffset+selectionStart);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetStart");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
newRange->SetEnd(mElement,mOffset+selectionEnd);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot SetEnd");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
imeSel->AddRange(newRange);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot AddRange");
|
|
|
|
if(NS_FAILED(result))
|
|
|
|
break;
|
|
|
|
|
|
|
|
} // if GetRangeEnd
|
|
|
|
} // for textRangeListLength
|
|
|
|
if(! setCaret) {
|
|
|
|
// set cursor
|
1999-08-25 10:51:55 +00:00
|
|
|
result = selection->Collapse(mElement,mOffset+mStringToInsert.Length());
|
1999-10-27 00:10:03 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot Collapse");
|
|
|
|
}
|
2000-09-14 11:45:01 +00:00
|
|
|
result = selPriv->EndBatchChanges();
|
1999-10-27 00:10:03 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(result), "Cannot EndBatchChanges");
|
|
|
|
} // if StartBatchChanges
|
|
|
|
} // if GetSelection
|
1999-08-25 10:51:55 +00:00
|
|
|
|
|
|
|
return result;
|
1999-06-29 20:31:22 +00:00
|
|
|
}
|
|
|
|
|