From 93fd4993627a72c7f87c72a341330df217eafe4a Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Tue, 11 Jul 2000 19:51:36 +0000 Subject: [PATCH] fix for 43366; r=kin --- editor/base/IMETextTxn.cpp | 6 +++++ editor/base/IMETextTxn.h | 2 ++ editor/base/nsEditor.cpp | 39 +++++++++++++++++++++++++--- editor/base/nsEditor.h | 1 + editor/libeditor/base/IMETextTxn.cpp | 6 +++++ editor/libeditor/base/IMETextTxn.h | 2 ++ editor/libeditor/base/nsEditor.cpp | 39 +++++++++++++++++++++++++--- editor/libeditor/base/nsEditor.h | 1 + 8 files changed, 88 insertions(+), 8 deletions(-) diff --git a/editor/base/IMETextTxn.cpp b/editor/base/IMETextTxn.cpp index a86ecc303c4..0736c822fcf 100644 --- a/editor/base/IMETextTxn.cpp +++ b/editor/base/IMETextTxn.cpp @@ -192,6 +192,12 @@ NS_IMETHODIMP IMETextTxn::Write(nsIOutputStream *aOutputStream) return NS_OK; } +NS_IMETHODIMP IMETextTxn::MarkFixed(void) +{ + mFixed = PR_TRUE; + return NS_OK; +} + NS_IMETHODIMP IMETextTxn::GetUndoString(nsString *aString) { NS_ASSERTION(aString, "illegal value- null ptr- aString"); diff --git a/editor/base/IMETextTxn.h b/editor/base/IMETextTxn.h index 04e3cbafbbd..e5f32893de8 100644 --- a/editor/base/IMETextTxn.h +++ b/editor/base/IMETextTxn.h @@ -86,6 +86,8 @@ public: NS_IMETHOD GetRedoString(nsString *aString); + NS_IMETHOD MarkFixed(void); + // nsISupports declarations // override QueryInterface to handle IMETextTxn request diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 58c2a8f6eda..2573e00ae6d 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -2335,6 +2335,15 @@ nsEditor::ForceCompositionEnd() return NS_OK; } + +NS_IMETHODIMP +nsEditor::Composing(PRBool *aInIMEMode) +{ + if (!aInIMEMode) return NS_ERROR_NULL_POINTER; + *aInIMEMode = mInIMEMode; + return NS_OK; +} + #ifdef XP_MAC #pragma mark - #pragma mark public nsEditor methods @@ -2636,7 +2645,7 @@ NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInse { result = CreateTxnForInsertText(aStringToInsert, aTextNode, aOffset, (InsertTextTxn**)&txn); } - if (NS_FAILED(result)) return result; + if (NS_FAILED(result)) return result; // we potentially leak txn here? // let listeners know whats up PRInt32 i; @@ -2653,9 +2662,6 @@ NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInse BeginUpdateViewBatch(); result = Do(txn); - // The transaction system (if any) has taken ownwership of txns. - // aggTxn released at end of routine. - NS_IF_RELEASE(txn); EndUpdateViewBatch(); // let listeners know what happened @@ -2669,6 +2675,31 @@ NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInse } } + // Added some cruft here for bug 43366. Layout was crashing because we left an + // empty text node lying around in the document. So I delete empty text nodes + // caused by IME. I have to mark the IME transaction as "fixed", which means + // that furure ime txns won't merge with it. This is because we don't want + // future ime txns trying to put their text into a node that is no longer in + // the document. This does not break undo/redo, because all these txns are + // wrapped in a parent PlaceHolder txn, and placeholder txns are already + // savvy to having multiple ime txns inside them. + + // delete empty ime text node if there is one + if (mInIMEMode && mIMETextNode) + { + PRUint32 len; + mIMETextNode->GetLength(&len); + if (!len) + { + DeleteNode(mIMETextNode); + mIMETextNode = nsnull; + ((IMETextTxn*)txn)->MarkFixed(); // mark the ime txn "fixed" + } + } + + // The transaction system (if any) has taken ownwership of txns. + // aggTxn released at end of routine. + NS_IF_RELEASE(txn); return result; } diff --git a/editor/base/nsEditor.h b/editor/base/nsEditor.h index e3f0e2c3597..846083bfc53 100644 --- a/editor/base/nsEditor.h +++ b/editor/base/nsEditor.h @@ -300,6 +300,7 @@ public: NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIPrivateTextRangeList* aTextRangeList,nsTextEventReply* aReply); NS_IMETHOD EndComposition(void); NS_IMETHOD ForceCompositionEnd(void); + NS_IMETHOD Composing(PRBool *aInIMEMode); public: diff --git a/editor/libeditor/base/IMETextTxn.cpp b/editor/libeditor/base/IMETextTxn.cpp index a86ecc303c4..0736c822fcf 100644 --- a/editor/libeditor/base/IMETextTxn.cpp +++ b/editor/libeditor/base/IMETextTxn.cpp @@ -192,6 +192,12 @@ NS_IMETHODIMP IMETextTxn::Write(nsIOutputStream *aOutputStream) return NS_OK; } +NS_IMETHODIMP IMETextTxn::MarkFixed(void) +{ + mFixed = PR_TRUE; + return NS_OK; +} + NS_IMETHODIMP IMETextTxn::GetUndoString(nsString *aString) { NS_ASSERTION(aString, "illegal value- null ptr- aString"); diff --git a/editor/libeditor/base/IMETextTxn.h b/editor/libeditor/base/IMETextTxn.h index 04e3cbafbbd..e5f32893de8 100644 --- a/editor/libeditor/base/IMETextTxn.h +++ b/editor/libeditor/base/IMETextTxn.h @@ -86,6 +86,8 @@ public: NS_IMETHOD GetRedoString(nsString *aString); + NS_IMETHOD MarkFixed(void); + // nsISupports declarations // override QueryInterface to handle IMETextTxn request diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 58c2a8f6eda..2573e00ae6d 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -2335,6 +2335,15 @@ nsEditor::ForceCompositionEnd() return NS_OK; } + +NS_IMETHODIMP +nsEditor::Composing(PRBool *aInIMEMode) +{ + if (!aInIMEMode) return NS_ERROR_NULL_POINTER; + *aInIMEMode = mInIMEMode; + return NS_OK; +} + #ifdef XP_MAC #pragma mark - #pragma mark public nsEditor methods @@ -2636,7 +2645,7 @@ NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInse { result = CreateTxnForInsertText(aStringToInsert, aTextNode, aOffset, (InsertTextTxn**)&txn); } - if (NS_FAILED(result)) return result; + if (NS_FAILED(result)) return result; // we potentially leak txn here? // let listeners know whats up PRInt32 i; @@ -2653,9 +2662,6 @@ NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInse BeginUpdateViewBatch(); result = Do(txn); - // The transaction system (if any) has taken ownwership of txns. - // aggTxn released at end of routine. - NS_IF_RELEASE(txn); EndUpdateViewBatch(); // let listeners know what happened @@ -2669,6 +2675,31 @@ NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInse } } + // Added some cruft here for bug 43366. Layout was crashing because we left an + // empty text node lying around in the document. So I delete empty text nodes + // caused by IME. I have to mark the IME transaction as "fixed", which means + // that furure ime txns won't merge with it. This is because we don't want + // future ime txns trying to put their text into a node that is no longer in + // the document. This does not break undo/redo, because all these txns are + // wrapped in a parent PlaceHolder txn, and placeholder txns are already + // savvy to having multiple ime txns inside them. + + // delete empty ime text node if there is one + if (mInIMEMode && mIMETextNode) + { + PRUint32 len; + mIMETextNode->GetLength(&len); + if (!len) + { + DeleteNode(mIMETextNode); + mIMETextNode = nsnull; + ((IMETextTxn*)txn)->MarkFixed(); // mark the ime txn "fixed" + } + } + + // The transaction system (if any) has taken ownwership of txns. + // aggTxn released at end of routine. + NS_IF_RELEASE(txn); return result; } diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index e3f0e2c3597..846083bfc53 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -300,6 +300,7 @@ public: NS_IMETHOD SetCompositionString(const nsString& aCompositionString, nsIPrivateTextRangeList* aTextRangeList,nsTextEventReply* aReply); NS_IMETHOD EndComposition(void); NS_IMETHOD ForceCompositionEnd(void); + NS_IMETHOD Composing(PRBool *aInIMEMode); public: