mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
reduce string usage by using atom version of method; r/sr=dbaron, bug=213101
This commit is contained in:
parent
1c3ea308da
commit
dbe0fc80cf
@ -1197,29 +1197,18 @@ nsresult
|
||||
nsHTMLEditRules::GetFormatString(nsIDOMNode *aNode, nsAString &outFormat)
|
||||
{
|
||||
if (!aNode) return NS_ERROR_NULL_POINTER;
|
||||
nsAutoString format;
|
||||
|
||||
|
||||
nsCOMPtr<nsIAtom> 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<nsIDOMNode>& 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"))) ||
|
||||
|
@ -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;
|
||||
|
||||
nsCOMPtr<nsIDOMElement>element;
|
||||
element = do_QueryInterface(aNode);
|
||||
nsCOMPtr<nsIDOMElement>element = 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<nsIAtom> tagAtom = getter_AddRefs(NS_NewAtom(tagName));
|
||||
nsCOMPtr<nsIAtom> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user