From 1333f0d2fc4c200ccbf970b50a592266c4d18770 Mon Sep 17 00:00:00 2001 From: "brade%netscape.com" Date: Sat, 19 Jul 2003 08:51:54 +0000 Subject: [PATCH] reduce string usage by using atom version of method; r/sr=dbaron, bug=213101 --- editor/libeditor/html/nsHTMLEditRules.cpp | 29 +++++++---------------- editor/libeditor/html/nsHTMLEditor.cpp | 29 ++++++++--------------- 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 08ed54a2192..30fba6613e4 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -1197,29 +1197,18 @@ nsresult nsHTMLEditRules::GetFormatString(nsIDOMNode *aNode, nsAString &outFormat) { if (!aNode) return NS_ERROR_NULL_POINTER; - nsAutoString format; - + nsCOMPtr atom = mHTMLEditor->GetTag(aNode); - - if ( nsEditProperty::p == atom || - nsEditProperty::address == atom || - nsEditProperty::pre == atom ) + if (nsEditProperty::p == atom || + nsEditProperty::address == atom || + nsEditProperty::pre == atom || + nsHTMLEditUtils::IsHeader(aNode)) { - atom->ToString(format); - } - else if (nsHTMLEditUtils::IsHeader(aNode)) - { - nsAutoString tag; - nsEditor::GetTagString(aNode,tag); - ToLowerCase(tag); - format = tag; + atom->ToString(outFormat); } else - { - format.Truncate(); - } - - outFormat = format; + outFormat.Truncate(); + return NS_OK; } @@ -6698,8 +6687,8 @@ nsHTMLEditRules::RemoveBlockStyle(nsCOMArray& arrayOfNodes) if (NS_FAILED(res)) return res; } else if (nsHTMLEditUtils::IsTable(curNode) || + nsHTMLEditUtils::IsTableRow(curNode) || (curNodeTag.Equals(NS_LITERAL_STRING("tbody"))) || - (curNodeTag.Equals(NS_LITERAL_STRING("tr"))) || (curNodeTag.Equals(NS_LITERAL_STRING("td"))) || nsHTMLEditUtils::IsList(curNode) || (curNodeTag.Equals(NS_LITERAL_STRING("li"))) || diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 569771b03e4..3abf0936fb6 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -127,7 +127,6 @@ #include "nsEditorUtils.h" #include "nsIStyleSet.h" #include "nsIPref.h" -#include "nsParserCIID.h" #include "nsITextContent.h" #include "nsWSRunObject.h" #include "nsHTMLObjectResizer.h" @@ -565,28 +564,20 @@ nsHTMLEditor::NodeIsBlockStatic(nsIDOMNode *aNode, PRBool *aIsBlock) { if (!aNode || !aIsBlock) { return NS_ERROR_NULL_POINTER; } + *aIsBlock = PR_FALSE; + #define USE_PARSER_FOR_BLOCKNESS 1 #ifdef USE_PARSER_FOR_BLOCKNESS nsresult rv; - nsCOMPtrelement; - element = do_QueryInterface(aNode); + nsCOMPtrelement = do_QueryInterface(aNode); if (!element) { // We don't have an element -- probably a text node - *aIsBlock = PR_FALSE; return NS_OK; } - *aIsBlock = PR_FALSE; - - // Get the node name and atom: - nsAutoString tagName; - rv = element->GetTagName(tagName); - if (NS_FAILED(rv)) return rv; - - ToLowerCase(tagName); - nsCOMPtr tagAtom = getter_AddRefs(NS_NewAtom(tagName)); + nsCOMPtr tagAtom = nsEditor::GetTag(aNode); if (!tagAtom) return NS_ERROR_NULL_POINTER; if (!sParserService) { @@ -611,13 +602,8 @@ nsHTMLEditor::NodeIsBlockStatic(nsIDOMNode *aNode, PRBool *aIsBlock) return NS_OK; } - // This sucks. The parser service's isBlock requires a string, - // so we have to get the name atom, convert it into a string, call - // the parser service to get the id, in order to call the parser - // service to ask about blockness. - // Harish is working on a more efficient API we can use. PRInt32 id; - rv = sParserService->HTMLStringTagToId(tagName, &id); + rv = sParserService->HTMLAtomTagToId(tagAtom, &id); if (NS_FAILED(rv)) return rv; rv = sParserService->IsBlock(id, *aIsBlock); @@ -652,6 +638,11 @@ nsHTMLEditor::NodeIsBlockStatic(nsIDOMNode *aNode, PRBool *aIsBlock) if (!(*aIsBlock)) { nsAutoString assertmsg (NS_LITERAL_STRING("Parser and editor disagree on blockness: ")); + + nsAutoString tagName; + rv = element->GetTagName(tagName); + if (NS_FAILED(rv)) return rv; + assertmsg.Append(tagName); char* assertstr = ToNewCString(assertmsg); NS_ASSERTION(*aIsBlock, assertstr);