From b7dd11f7bb070f1f3ff60464a758e39f3e6ae690 Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Thu, 13 Apr 2000 21:50:19 +0000 Subject: [PATCH] Wrote RemoveAllInlineProperties() to deal with clearing out inline style, and also fixed a bunch of IME bugs. --- editor/base/nsEditor.cpp | 11 +++-- editor/base/nsEditor.h | 4 +- editor/base/nsEditorShell.cpp | 26 +----------- editor/base/nsHTMLEditRules.cpp | 22 ++++++---- editor/base/nsHTMLEditor.cpp | 52 ++++++++++++++++++----- editor/base/nsHTMLEditor.h | 7 ++- editor/base/nsTextEditRules.cpp | 12 +++--- editor/composer/src/nsEditorShell.cpp | 26 +----------- editor/libeditor/base/nsEditor.cpp | 11 +++-- editor/libeditor/base/nsEditor.h | 4 +- editor/libeditor/html/nsHTMLEditRules.cpp | 22 ++++++---- editor/libeditor/html/nsHTMLEditor.cpp | 52 ++++++++++++++++++----- editor/libeditor/html/nsHTMLEditor.h | 7 ++- editor/libeditor/text/nsTextEditRules.cpp | 12 +++--- 14 files changed, 148 insertions(+), 120 deletions(-) diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 30844b7f914..6f100640abc 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -96,7 +96,6 @@ #include "nsEditor.h" #include "nsEditorUtils.h" - #ifdef HACK_FORCE_REDRAW // INCLUDES FOR EVIL HACK TO FOR REDRAW // BEGIN @@ -2491,7 +2490,7 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString) } -NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, +NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert, nsCOMPtr *aInOutNode, PRInt32 *aInOutOffset, nsIDOMDocument *aDoc) @@ -2501,7 +2500,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, // if desired. if (!aInOutNode || !*aInOutNode || !aInOutOffset || !aDoc) return NS_ERROR_NULL_POINTER; - if (aStringToInsert.IsEmpty()) return NS_OK; + if (!mInIMEMode && aStringToInsert.IsEmpty()) return NS_OK; nsCOMPtr nodeAsText = do_QueryInterface(*aInOutNode); PRInt32 offset = *aInOutOffset; nsresult res; @@ -2520,7 +2519,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, if (NS_FAILED(res)) return res; offset = 0; } - res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); + res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); if (NS_FAILED(res)) return res; } else @@ -2528,7 +2527,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, if (nodeAsText) { // we are inserting text into an existing text node. - res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); + res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); if (NS_FAILED(res)) return res; *aInOutOffset += aStringToInsert.Length(); } @@ -2552,7 +2551,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, } -NS_IMETHODIMP nsEditor::JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert, +NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInsert, nsIDOMCharacterData *aTextNode, PRInt32 aOffset) { diff --git a/editor/base/nsEditor.h b/editor/base/nsEditor.h index 1a7607c1552..de35e1c5946 100644 --- a/editor/base/nsEditor.h +++ b/editor/base/nsEditor.h @@ -299,11 +299,11 @@ public: public: - NS_IMETHOD JoeInsertTextImpl(const nsString& aStringToInsert, + NS_IMETHOD InsertTextImpl(const nsString& aStringToInsert, nsCOMPtr *aInOutNode, PRInt32 *aInOutOffset, nsIDOMDocument *aDoc); - NS_IMETHOD JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert, + NS_IMETHOD InsertTextIntoTextNodeImpl(const nsString& aStringToInsert, nsIDOMCharacterData *aTextNode, PRInt32 aOffset); NS_IMETHOD DeleteSelectionImpl(EDirection aAction); diff --git a/editor/base/nsEditorShell.cpp b/editor/base/nsEditorShell.cpp index a6b9afde661..a578488ce23 100644 --- a/editor/base/nsEditorShell.cpp +++ b/editor/base/nsEditorShell.cpp @@ -854,17 +854,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) NS_IMETHODIMP nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr) { - // OK, I'm really hacking now. This is just so that we can accept 'all' as input. - // this logic should live elsewhere. - //TODO: FIX THIS! IT IS WRONG! IT DOESN'T CONSIDER ALL THE - // OTHER POSSIBLE TEXT ATTRIBUTES! - static const char* sAllKnownStyles[] = { - "b", - "i", - "u", - nsnull // this null is important - }; - + // OK, I'm really hacking now. This is just so that we can accept 'all' as input. nsAutoString allStr(prop); nsAutoString aAttr(attr); @@ -874,19 +864,7 @@ nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr) if (doingAll) { - nsAutoString thisAttr; - const char **tagName = sAllKnownStyles; - - while (*tagName) - { - thisAttr.Truncate(0); - thisAttr += (char *)(*tagName); - - err = RemoveOneProperty(thisAttr, aAttr); - - tagName ++; - } - + err = mEditor->RemoveAllInlineProperties(); } else { diff --git a/editor/base/nsHTMLEditRules.cpp b/editor/base/nsHTMLEditRules.cpp index 3075ab062c6..e1a68874864 100644 --- a/editor/base/nsHTMLEditRules.cpp +++ b/editor/base/nsHTMLEditRules.cpp @@ -210,9 +210,13 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) if (NS_FAILED(res)) return res; // merge any adjacent text nodes - res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange); - if (NS_FAILED(res)) return res; - + if ( (action != nsEditor::kOpInsertText && + action != nsEditor::kOpInsertIMEText) ) + { + res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange); + if (NS_FAILED(res)) return res; + } + // adjust whitespace for insert text and delete actions if ((action == nsEditor::kOpInsertText) || (action == nsEditor::kOpInsertIMEText) || @@ -404,7 +408,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, if (aAction == kInsertTextIME) { - res = mEditor->JoeInsertTextImpl(*inString, &selNode, &selOffset, doc); + res = mEditor->InsertTextImpl(*inString, &selNode, &selOffset, doc); if (NS_FAILED(res)) return res; } else // aAction == kInsertText @@ -462,12 +466,12 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, // is it a return? if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; } @@ -500,18 +504,18 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, // is it a tab? if (subStr.Equals("\t")) { - res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc); pos++; } // is it a return? else if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; } diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index a2cdf3b69ae..db206571b28 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -717,6 +717,12 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent) return TypedText(empty, eTypedBreak); // uses rules to figure out what to insert } } + else if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE) + { + // pass escape keypresses through as empty strings: needed forime support + nsAutoString empty; + return TypedText(empty, eTypedText); + } // if we got here we either fell out of the tab case or have a normal character. // Either way, treat as normal character. @@ -810,7 +816,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) return NS_OK; } -NS_IMETHODIMP nsHTMLEditor::JoeCreateBR(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, EDirection aSelect) +NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, EDirection aSelect) { if (!aInOutParent || !*aInOutParent || !aInOutOffset || !outBRNode) return NS_ERROR_NULL_POINTER; *outBRNode = nsnull; @@ -891,7 +897,7 @@ NS_IMETHODIMP nsHTMLEditor::CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPt { nsCOMPtr parent = aNode; PRInt32 offset = aOffset; - return JoeCreateBR(&parent, &offset, outBRNode, aSelect); + return CreateBRImpl(&parent, &offset, outBRNode, aSelect); } NS_IMETHODIMP nsHTMLEditor::InsertBR(nsCOMPtr *outBRNode) @@ -1255,7 +1261,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange, nsIAtom *aProperty, const nsString *aAttribute) { - if (!inRange || !aProperty) return NS_ERROR_NULL_POINTER; + if (!inRange) return NS_ERROR_NULL_POINTER; nsresult res; nsCOMPtr startNode, endNode, origStartNode; PRInt32 startOffset, endOffset, origStartOffset; @@ -1296,7 +1302,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange, nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr *aNode, PRInt32 *aOffset, - nsIAtom *aProperty, + nsIAtom *aProperty, // null here means we split all properties const nsString *aAttribute) { if (!aNode || !*aNode || !aOffset) return NS_ERROR_NULL_POINTER; @@ -1305,7 +1311,8 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr *aNode, PRInt32 offset; while (tmp && !nsHTMLEditUtils::IsBody(tmp)) { - if (NodeIsType(tmp, aProperty)) + if ( (aProperty && NodeIsType(tmp, aProperty)) || // node is the correct inline prop + (!aProperty && NodeIsProperty(tmp)) ) // or node is any prop, and we asked to split them all { // found a style node we need to split SplitNodeDeep(tmp, *aNode, *aOffset, &offset); @@ -1318,13 +1325,23 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr *aNode, } return NS_OK; } - + +PRBool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode) +{ + if (!aNode) return PR_FALSE; + if (!IsContainer(aNode)) return PR_FALSE; + if (!IsEditable(aNode)) return PR_FALSE; + if (!IsInlineNode(aNode)) return PR_FALSE; + if (NodeIsType(aNode, nsIEditProperty::a)) return PR_FALSE; + return PR_TRUE; +} + nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, - nsIAtom *aProperty, + nsIAtom *aProperty, // null here means remove all properties const nsString *aAttribute, PRBool aChildrenOnly) { - if (!aNode || !aProperty) return NS_ERROR_NULL_POINTER; + if (!aNode) return NS_ERROR_NULL_POINTER; if (IsTextNode(aNode)) return NS_OK; nsresult res = NS_OK; @@ -1341,7 +1358,9 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, } // then process the node itself - if (!aChildrenOnly && NodeIsType(aNode, aProperty)) + if ( !aChildrenOnly && + (aProperty && NodeIsType(aNode, aProperty)) || // node is prop we wasked for + (!aProperty && NodeIsProperty(aNode)) ) // or node is any prop and we asked for that { // if we weren't passed an attribute, then we want to // remove any matching inlinestyles entirely @@ -1773,9 +1792,19 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty, return result; } + +NS_IMETHODIMP nsHTMLEditor::RemoveAllInlineProperties() +{ + return RemoveInlinePropertyImpl(nsnull, nsnull); +} + NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute) { - if (!aProperty) return NS_ERROR_NULL_POINTER; + return RemoveInlinePropertyImpl(aProperty, aAttribute); +} + +nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute) +{ if (!mRules) return NS_ERROR_NOT_INITIALIZED; ForceCompositionEnd(); @@ -1790,7 +1819,8 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsStr if (isCollapsed) { // manipulating text attributes on a collapsed selection only sets state for the next text insertion - return mTypeInState->ClearProp(aProperty, *aAttribute); + if (aProperty) return mTypeInState->ClearProp(aProperty, *aAttribute); +// else return mTypeInState->ClearAllProps(); } nsAutoEditBatch batchIt(this); nsAutoRules beginRulesSniffing(this, kOpRemoveTextProperty, nsIEditor::eNext); diff --git a/editor/base/nsHTMLEditor.h b/editor/base/nsHTMLEditor.h index 647e584c9ce..f7f9fb194f5 100644 --- a/editor/base/nsHTMLEditor.h +++ b/editor/base/nsHTMLEditor.h @@ -103,6 +103,7 @@ public: const nsString *aValue, PRBool &aFirst, PRBool &aAny, PRBool &aAll); + NS_IMETHOD RemoveAllInlineProperties(); NS_IMETHOD RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute); NS_IMETHOD IncreaseFontSize(); NS_IMETHOD DecreaseFontSize(); @@ -356,7 +357,7 @@ protected: NS_IMETHOD TabInTable(PRBool inIsShift, PRBool *outHandled); NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr *outBRNode, EDirection aSelect = eNone); - NS_IMETHOD JoeCreateBR(nsCOMPtr *aInOutParent, + NS_IMETHOD CreateBRImpl(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, EDirection aSelect); @@ -488,7 +489,9 @@ protected: nsIAtom *aProperty, const nsString *aAttribute, PRBool aChildrenOnly = PR_FALSE); - + nsresult RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute); + + PRBool NodeIsProperty(nsIDOMNode *aNode); PRBool HasAttr(nsIDOMNode *aNode, const nsString *aAttribute); PRBool HasAttrVal(nsIDOMNode *aNode, const nsString *aAttribute, const nsString *aValue); PRBool IsAtFrontOfNode(nsIDOMNode *aNode, PRInt32 aOffset); diff --git a/editor/base/nsTextEditRules.cpp b/editor/base/nsTextEditRules.cpp index 064b92260e6..1ec9cb23303 100644 --- a/editor/base/nsTextEditRules.cpp +++ b/editor/base/nsTextEditRules.cpp @@ -610,7 +610,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, if (aAction == kInsertTextIME) { - res = mEditor->JoeInsertTextImpl(*outString, &selNode, &selOffset, doc); + res = mEditor->InsertTextImpl(*outString, &selNode, &selOffset, doc); if (NS_FAILED(res)) return res; } else // aAction == kInsertText @@ -662,12 +662,12 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, // is it a return? if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; } @@ -700,18 +700,18 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, // is it a tab? if (subStr.Equals("\t")) { - res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc); pos++; } // is it a return? else if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; } diff --git a/editor/composer/src/nsEditorShell.cpp b/editor/composer/src/nsEditorShell.cpp index a6b9afde661..a578488ce23 100644 --- a/editor/composer/src/nsEditorShell.cpp +++ b/editor/composer/src/nsEditorShell.cpp @@ -854,17 +854,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) NS_IMETHODIMP nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr) { - // OK, I'm really hacking now. This is just so that we can accept 'all' as input. - // this logic should live elsewhere. - //TODO: FIX THIS! IT IS WRONG! IT DOESN'T CONSIDER ALL THE - // OTHER POSSIBLE TEXT ATTRIBUTES! - static const char* sAllKnownStyles[] = { - "b", - "i", - "u", - nsnull // this null is important - }; - + // OK, I'm really hacking now. This is just so that we can accept 'all' as input. nsAutoString allStr(prop); nsAutoString aAttr(attr); @@ -874,19 +864,7 @@ nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr) if (doingAll) { - nsAutoString thisAttr; - const char **tagName = sAllKnownStyles; - - while (*tagName) - { - thisAttr.Truncate(0); - thisAttr += (char *)(*tagName); - - err = RemoveOneProperty(thisAttr, aAttr); - - tagName ++; - } - + err = mEditor->RemoveAllInlineProperties(); } else { diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 30844b7f914..6f100640abc 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -96,7 +96,6 @@ #include "nsEditor.h" #include "nsEditorUtils.h" - #ifdef HACK_FORCE_REDRAW // INCLUDES FOR EVIL HACK TO FOR REDRAW // BEGIN @@ -2491,7 +2490,7 @@ nsresult nsEditor::GetTextNodeTag(nsString& aOutString) } -NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, +NS_IMETHODIMP nsEditor::InsertTextImpl(const nsString& aStringToInsert, nsCOMPtr *aInOutNode, PRInt32 *aInOutOffset, nsIDOMDocument *aDoc) @@ -2501,7 +2500,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, // if desired. if (!aInOutNode || !*aInOutNode || !aInOutOffset || !aDoc) return NS_ERROR_NULL_POINTER; - if (aStringToInsert.IsEmpty()) return NS_OK; + if (!mInIMEMode && aStringToInsert.IsEmpty()) return NS_OK; nsCOMPtr nodeAsText = do_QueryInterface(*aInOutNode); PRInt32 offset = *aInOutOffset; nsresult res; @@ -2520,7 +2519,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, if (NS_FAILED(res)) return res; offset = 0; } - res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); + res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); if (NS_FAILED(res)) return res; } else @@ -2528,7 +2527,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, if (nodeAsText) { // we are inserting text into an existing text node. - res = JoeInsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); + res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset); if (NS_FAILED(res)) return res; *aInOutOffset += aStringToInsert.Length(); } @@ -2552,7 +2551,7 @@ NS_IMETHODIMP nsEditor::JoeInsertTextImpl(const nsString& aStringToInsert, } -NS_IMETHODIMP nsEditor::JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert, +NS_IMETHODIMP nsEditor::InsertTextIntoTextNodeImpl(const nsString& aStringToInsert, nsIDOMCharacterData *aTextNode, PRInt32 aOffset) { diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 1a7607c1552..de35e1c5946 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -299,11 +299,11 @@ public: public: - NS_IMETHOD JoeInsertTextImpl(const nsString& aStringToInsert, + NS_IMETHOD InsertTextImpl(const nsString& aStringToInsert, nsCOMPtr *aInOutNode, PRInt32 *aInOutOffset, nsIDOMDocument *aDoc); - NS_IMETHOD JoeInsertTextIntoTextNodeImpl(const nsString& aStringToInsert, + NS_IMETHOD InsertTextIntoTextNodeImpl(const nsString& aStringToInsert, nsIDOMCharacterData *aTextNode, PRInt32 aOffset); NS_IMETHOD DeleteSelectionImpl(EDirection aAction); diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 3075ab062c6..e1a68874864 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -210,9 +210,13 @@ nsHTMLEditRules::AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection) if (NS_FAILED(res)) return res; // merge any adjacent text nodes - res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange); - if (NS_FAILED(res)) return res; - + if ( (action != nsEditor::kOpInsertText && + action != nsEditor::kOpInsertIMEText) ) + { + res = mEditor->CollapseAdjacentTextNodes(mDocChangeRange); + if (NS_FAILED(res)) return res; + } + // adjust whitespace for insert text and delete actions if ((action == nsEditor::kOpInsertText) || (action == nsEditor::kOpInsertIMEText) || @@ -404,7 +408,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, if (aAction == kInsertTextIME) { - res = mEditor->JoeInsertTextImpl(*inString, &selNode, &selOffset, doc); + res = mEditor->InsertTextImpl(*inString, &selNode, &selOffset, doc); if (NS_FAILED(res)) return res; } else // aAction == kInsertText @@ -462,12 +466,12 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, // is it a return? if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; } @@ -500,18 +504,18 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction, // is it a tab? if (subStr.Equals("\t")) { - res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc); pos++; } // is it a return? else if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; } diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index a2cdf3b69ae..db206571b28 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -717,6 +717,12 @@ NS_IMETHODIMP nsHTMLEditor::EditorKeyPress(nsIDOMKeyEvent* aKeyEvent) return TypedText(empty, eTypedBreak); // uses rules to figure out what to insert } } + else if (keyCode == nsIDOMKeyEvent::DOM_VK_ESCAPE) + { + // pass escape keypresses through as empty strings: needed forime support + nsAutoString empty; + return TypedText(empty, eTypedText); + } // if we got here we either fell out of the tab case or have a normal character. // Either way, treat as normal character. @@ -810,7 +816,7 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(PRBool inIsShift, PRBool *outHandled) return NS_OK; } -NS_IMETHODIMP nsHTMLEditor::JoeCreateBR(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, EDirection aSelect) +NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, EDirection aSelect) { if (!aInOutParent || !*aInOutParent || !aInOutOffset || !outBRNode) return NS_ERROR_NULL_POINTER; *outBRNode = nsnull; @@ -891,7 +897,7 @@ NS_IMETHODIMP nsHTMLEditor::CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPt { nsCOMPtr parent = aNode; PRInt32 offset = aOffset; - return JoeCreateBR(&parent, &offset, outBRNode, aSelect); + return CreateBRImpl(&parent, &offset, outBRNode, aSelect); } NS_IMETHODIMP nsHTMLEditor::InsertBR(nsCOMPtr *outBRNode) @@ -1255,7 +1261,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange, nsIAtom *aProperty, const nsString *aAttribute) { - if (!inRange || !aProperty) return NS_ERROR_NULL_POINTER; + if (!inRange) return NS_ERROR_NULL_POINTER; nsresult res; nsCOMPtr startNode, endNode, origStartNode; PRInt32 startOffset, endOffset, origStartOffset; @@ -1296,7 +1302,7 @@ nsresult nsHTMLEditor::SplitStyleAboveRange(nsIDOMRange *inRange, nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr *aNode, PRInt32 *aOffset, - nsIAtom *aProperty, + nsIAtom *aProperty, // null here means we split all properties const nsString *aAttribute) { if (!aNode || !*aNode || !aOffset) return NS_ERROR_NULL_POINTER; @@ -1305,7 +1311,8 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr *aNode, PRInt32 offset; while (tmp && !nsHTMLEditUtils::IsBody(tmp)) { - if (NodeIsType(tmp, aProperty)) + if ( (aProperty && NodeIsType(tmp, aProperty)) || // node is the correct inline prop + (!aProperty && NodeIsProperty(tmp)) ) // or node is any prop, and we asked to split them all { // found a style node we need to split SplitNodeDeep(tmp, *aNode, *aOffset, &offset); @@ -1318,13 +1325,23 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr *aNode, } return NS_OK; } - + +PRBool nsHTMLEditor::NodeIsProperty(nsIDOMNode *aNode) +{ + if (!aNode) return PR_FALSE; + if (!IsContainer(aNode)) return PR_FALSE; + if (!IsEditable(aNode)) return PR_FALSE; + if (!IsInlineNode(aNode)) return PR_FALSE; + if (NodeIsType(aNode, nsIEditProperty::a)) return PR_FALSE; + return PR_TRUE; +} + nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, - nsIAtom *aProperty, + nsIAtom *aProperty, // null here means remove all properties const nsString *aAttribute, PRBool aChildrenOnly) { - if (!aNode || !aProperty) return NS_ERROR_NULL_POINTER; + if (!aNode) return NS_ERROR_NULL_POINTER; if (IsTextNode(aNode)) return NS_OK; nsresult res = NS_OK; @@ -1341,7 +1358,9 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, } // then process the node itself - if (!aChildrenOnly && NodeIsType(aNode, aProperty)) + if ( !aChildrenOnly && + (aProperty && NodeIsType(aNode, aProperty)) || // node is prop we wasked for + (!aProperty && NodeIsProperty(aNode)) ) // or node is any prop and we asked for that { // if we weren't passed an attribute, then we want to // remove any matching inlinestyles entirely @@ -1773,9 +1792,19 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty, return result; } + +NS_IMETHODIMP nsHTMLEditor::RemoveAllInlineProperties() +{ + return RemoveInlinePropertyImpl(nsnull, nsnull); +} + NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute) { - if (!aProperty) return NS_ERROR_NULL_POINTER; + return RemoveInlinePropertyImpl(aProperty, aAttribute); +} + +nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute) +{ if (!mRules) return NS_ERROR_NOT_INITIALIZED; ForceCompositionEnd(); @@ -1790,7 +1819,8 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInlineProperty(nsIAtom *aProperty, const nsStr if (isCollapsed) { // manipulating text attributes on a collapsed selection only sets state for the next text insertion - return mTypeInState->ClearProp(aProperty, *aAttribute); + if (aProperty) return mTypeInState->ClearProp(aProperty, *aAttribute); +// else return mTypeInState->ClearAllProps(); } nsAutoEditBatch batchIt(this); nsAutoRules beginRulesSniffing(this, kOpRemoveTextProperty, nsIEditor::eNext); diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index 647e584c9ce..f7f9fb194f5 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -103,6 +103,7 @@ public: const nsString *aValue, PRBool &aFirst, PRBool &aAny, PRBool &aAll); + NS_IMETHOD RemoveAllInlineProperties(); NS_IMETHOD RemoveInlineProperty(nsIAtom *aProperty, const nsString *aAttribute); NS_IMETHOD IncreaseFontSize(); NS_IMETHOD DecreaseFontSize(); @@ -356,7 +357,7 @@ protected: NS_IMETHOD TabInTable(PRBool inIsShift, PRBool *outHandled); NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr *outBRNode, EDirection aSelect = eNone); - NS_IMETHOD JoeCreateBR(nsCOMPtr *aInOutParent, + NS_IMETHOD CreateBRImpl(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, EDirection aSelect); @@ -488,7 +489,9 @@ protected: nsIAtom *aProperty, const nsString *aAttribute, PRBool aChildrenOnly = PR_FALSE); - + nsresult RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsString *aAttribute); + + PRBool NodeIsProperty(nsIDOMNode *aNode); PRBool HasAttr(nsIDOMNode *aNode, const nsString *aAttribute); PRBool HasAttrVal(nsIDOMNode *aNode, const nsString *aAttribute, const nsString *aValue); PRBool IsAtFrontOfNode(nsIDOMNode *aNode, PRInt32 aOffset); diff --git a/editor/libeditor/text/nsTextEditRules.cpp b/editor/libeditor/text/nsTextEditRules.cpp index 064b92260e6..1ec9cb23303 100644 --- a/editor/libeditor/text/nsTextEditRules.cpp +++ b/editor/libeditor/text/nsTextEditRules.cpp @@ -610,7 +610,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, if (aAction == kInsertTextIME) { - res = mEditor->JoeInsertTextImpl(*outString, &selNode, &selOffset, doc); + res = mEditor->InsertTextImpl(*outString, &selNode, &selOffset, doc); if (NS_FAILED(res)) return res; } else // aAction == kInsertText @@ -662,12 +662,12 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, // is it a return? if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; } @@ -700,18 +700,18 @@ nsTextEditRules::WillInsertText(PRInt32 aAction, // is it a tab? if (subStr.Equals("\t")) { - res = mEditor->JoeInsertTextImpl(tabString, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(tabString, &curNode, &curOffset, doc); pos++; } // is it a return? else if (subStr.Equals("\n")) { - res = mEditor->JoeCreateBR(&curNode, &curOffset, &unused, nsIEditor::eNone); + res = mEditor->CreateBRImpl(&curNode, &curOffset, &unused, nsIEditor::eNone); pos++; } else { - res = mEditor->JoeInsertTextImpl(subStr, &curNode, &curOffset, doc); + res = mEditor->InsertTextImpl(subStr, &curNode, &curOffset, doc); } if (NS_FAILED(res)) return res; }