editor cleanup of NodeIsType; r=kin, sr=darin, bug=209548

This commit is contained in:
brade%netscape.com 2003-07-15 13:47:15 +00:00
Родитель 5b000ba0c0
Коммит 898cdcb4b8
14 изменённых файлов: 162 добавлений и 236 удалений

Просмотреть файл

@ -59,6 +59,7 @@ EDITOR_ATOM(big, "big")
EDITOR_ATOM(i, "i")
EDITOR_ATOM(small, "small")
EDITOR_ATOM(strike, "strike")
EDITOR_ATOM(s, "s")
EDITOR_ATOM(sub, "sub")
EDITOR_ATOM(sup, "sup")
EDITOR_ATOM(tt, "tt")
@ -66,6 +67,7 @@ EDITOR_ATOM(u, "u")
EDITOR_ATOM(em, "em")
EDITOR_ATOM(strong, "strong")
EDITOR_ATOM(dfn, "dfn")
EDITOR_ATOM(blink, "blink")
EDITOR_ATOM(code, "code")
EDITOR_ATOM(samp, "samp")
EDITOR_ATOM(kbd, "kbd")
@ -93,6 +95,7 @@ EDITOR_ATOM(button, "button")
// block tags
EDITOR_ATOM(p, "p")
EDITOR_ATOM(div, "div")
EDITOR_ATOM(center, "center")
EDITOR_ATOM(blockquote, "blockquote")
EDITOR_ATOM(h1, "h1")
EDITOR_ATOM(h2, "h2")
@ -114,6 +117,7 @@ EDITOR_ATOM(address, "address")
// DTD, block?
EDITOR_ATOM(body, "body")
EDITOR_ATOM(head, "head")
EDITOR_ATOM(html, "html")
EDITOR_ATOM(tr, "tr")
EDITOR_ATOM(td, "td")
EDITOR_ATOM(th, "th")

Просмотреть файл

@ -3530,38 +3530,6 @@ nsEditor::IsBlockNode(nsIDOMNode *aNode)
return PR_FALSE;
}
PRBool
nsEditor::NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag)
{
nsCOMPtr<nsIDOMElement>element = do_QueryInterface(aNode);
if (element)
{
nsAutoString tag;
element->GetTagName(tag);
const char *tagStr;
aTag->GetUTF8String(&tagStr);
if (tag.EqualsIgnoreCase(tagStr))
{
return PR_TRUE;
}
}
return PR_FALSE;
}
PRBool
nsEditor::NodeIsType(nsIDOMNode *aNode, const nsAString &aTagStr)
{
nsCOMPtr<nsIDOMElement>element = do_QueryInterface(aNode);
if (element)
{
nsAutoString tag, tagStr(aTagStr);
element->GetTagName(tag);
if (tag.Equals(tagStr, nsCaseInsensitiveStringComparator()))
return PR_TRUE;
}
return PR_FALSE;
}
PRBool
nsEditor::CanContainTag(nsIDOMNode* aParent, const nsAString &aChildTag)
{

Просмотреть файл

@ -47,6 +47,7 @@
#include "nsIEditorIMESupport.h"
#include "nsIPhonetic.h"
#include "nsIAtom.h"
#include "nsIDOMDocument.h"
#include "nsISelection.h"
#include "nsIDOMCharacterData.h"
@ -454,8 +455,19 @@ public:
PRBool bNoBlockCrossing = PR_FALSE);
/** returns PR_TRUE if aNode is of the type implied by aTag */
static PRBool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag);
static PRBool NodeIsType(nsIDOMNode *aNode, const nsAString &aTag);
static inline PRBool NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag)
{
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode);
return (nodeAtom == aTag);
}
// we should get rid of this method if we can
static inline PRBool NodeIsTypeString(nsIDOMNode *aNode, const nsAString &aTag)
{
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode);
return nodeAtom && nodeAtom->Equals(aTag);
}
/** returns PR_TRUE if aParent can contain a child of type aTag */
PRBool CanContainTag(nsIDOMNode* aParent, const nsAString &aTag);

Просмотреть файл

@ -119,7 +119,7 @@ nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval)
node.swap(parentNode);
}
} while (!resultNode &&
!nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("html")));
!nsEditor::NodeIsType(node, nsEditProperty::html));
element = do_QueryInterface(resultNode );
*_retval = element;
@ -604,7 +604,7 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement,
PRBool hasStyleOrIdOrClass;
res = HasStyleOrIdOrClass(aElement, &hasStyleOrIdOrClass);
if (NS_FAILED(res)) return res;
if (!hasStyleOrIdOrClass && NodeIsType(node, NS_LITERAL_STRING("div"))) {
if (!hasStyleOrIdOrClass && nsHTMLEditUtils::IsDiv(node)) {
nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
if (!htmlRules) return NS_ERROR_FAILURE;
res = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement);

Просмотреть файл

@ -638,7 +638,7 @@ nsHTMLCSSUtils::RemoveCSSInlineStyle(nsIDOMNode *aNode, nsIAtom *aProperty, cons
nsresult res = RemoveCSSProperty(elem, aProperty, aPropertyValue, PR_FALSE);
if (NS_FAILED(res)) return res;
if (mHTMLEditor->NodeIsType(aNode, nsEditProperty::span)) {
if (nsEditor::NodeIsType(aNode, nsEditProperty::span)) {
PRInt32 attrCount;
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
res = content->GetAttrCount(attrCount);

Просмотреть файл

@ -2106,7 +2106,7 @@ void RemoveBodyAndHead(nsIDOMNode *aNode)
{
body = child;
}
else if (nsEditor::NodeIsType(child, NS_LITERAL_STRING("head")))
else if (nsEditor::NodeIsType(child, nsEditProperty::head))
{
head = child;
}

Просмотреть файл

@ -671,11 +671,11 @@ nsHTMLEditRules::GetListState(PRBool *aMixed, PRBool *aOL, PRBool *aUL, PRBool *
{
nsIDOMNode* curNode = arrayOfNodes[i];
if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::ul))
if (nsHTMLEditUtils::IsUnorderedList(curNode))
*aUL = PR_TRUE;
else if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::ol))
else if (nsHTMLEditUtils::IsOrderedList(curNode))
*aOL = PR_TRUE;
else if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::li))
else if (nsEditor::NodeIsType(curNode, nsEditProperty::li))
{
nsCOMPtr<nsIDOMNode> parent;
PRInt32 offset;
@ -686,9 +686,9 @@ nsHTMLEditRules::GetListState(PRBool *aMixed, PRBool *aOL, PRBool *aUL, PRBool *
else if (nsHTMLEditUtils::IsOrderedList(parent))
*aOL = PR_TRUE;
}
else if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::dl) ||
mHTMLEditor->NodeIsType(curNode,nsEditProperty::dt) ||
mHTMLEditor->NodeIsType(curNode,nsEditProperty::dd) )
else if (nsEditor::NodeIsType(curNode, nsEditProperty::dl) ||
nsEditor::NodeIsType(curNode, nsEditProperty::dt) ||
nsEditor::NodeIsType(curNode, nsEditProperty::dd) )
{
*aDL = PR_TRUE;
}
@ -723,21 +723,21 @@ nsHTMLEditRules::GetListItemState(PRBool *aMixed, PRBool *aLI, PRBool *aDT, PRBo
{
nsIDOMNode* curNode = arrayOfNodes[i];
if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::ul) ||
mHTMLEditor->NodeIsType(curNode,nsEditProperty::ol) ||
mHTMLEditor->NodeIsType(curNode,nsEditProperty::li) )
if (nsHTMLEditUtils::IsUnorderedList(curNode) ||
nsHTMLEditUtils::IsOrderedList(curNode) ||
nsEditor::NodeIsType(curNode, nsEditProperty::li) )
{
*aLI = PR_TRUE;
}
else if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::dt))
else if (nsEditor::NodeIsType(curNode, nsEditProperty::dt))
{
*aDT = PR_TRUE;
}
else if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::dd))
else if (nsEditor::NodeIsType(curNode, nsEditProperty::dd))
{
*aDD = PR_TRUE;
}
else if (mHTMLEditor->NodeIsType(curNode,nsEditProperty::dl))
else if (nsEditor::NodeIsType(curNode, nsEditProperty::dl))
{
// need to look inside dl and see which types of items it has
PRBool bDT, bDD;
@ -805,7 +805,7 @@ nsHTMLEditRules::GetAlignment(PRBool *aMixed, nsIHTMLEditor::EAlignment *aAlign)
// if we are in a text node, then that is the node of interest
nodeToExamine = parent;
}
else if (nsTextEditUtils::NodeIsType(parent,NS_LITERAL_STRING("html")) &&
else if (nsEditor::NodeIsType(parent, nsEditProperty::html) &&
offset == rootOffset)
{
// if we have selected the body, let's look at the first editable node
@ -3055,7 +3055,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection,
res = mHTMLEditor->MoveNode(curNode, curList, -1);
if (NS_FAILED(res)) return res;
// convert list item type if needed
if (!mHTMLEditor->NodeIsType(curNode,itemType))
if (!mHTMLEditor->NodeIsTypeString(curNode,itemType))
{
res = mHTMLEditor->ReplaceContainer(curNode, address_of(newBlock), itemType);
if (NS_FAILED(res)) return res;
@ -3076,7 +3076,7 @@ nsHTMLEditRules::WillMakeList(nsISelection *aSelection,
if (NS_FAILED(res)) return res;
}
}
if (!mHTMLEditor->NodeIsType(curNode,itemType))
if (!mHTMLEditor->NodeIsTypeString(curNode,itemType))
{
res = mHTMLEditor->ReplaceContainer(curNode, address_of(newBlock), itemType);
if (NS_FAILED(res)) return res;
@ -4143,13 +4143,13 @@ nsHTMLEditRules::ConvertListType(nsIDOMNode *aList,
aList->GetFirstChild(getter_AddRefs(child));
while (child)
{
if (nsHTMLEditUtils::IsListItem(child) && !mHTMLEditor->NodeIsType(child, aItemType))
if (nsHTMLEditUtils::IsListItem(child) && !nsEditor::NodeIsTypeString(child, aItemType))
{
res = mHTMLEditor->ReplaceContainer(child, address_of(temp), aItemType);
if (NS_FAILED(res)) return res;
child = temp;
}
else if (nsHTMLEditUtils::IsList(child) && !mHTMLEditor->NodeIsType(child, aListType))
else if (nsHTMLEditUtils::IsList(child) && !nsEditor::NodeIsTypeString(child, aListType))
{
res = ConvertListType(child, address_of(temp), aListType, aItemType);
if (NS_FAILED(res)) return res;
@ -4158,7 +4158,7 @@ nsHTMLEditRules::ConvertListType(nsIDOMNode *aList,
child->GetNextSibling(getter_AddRefs(temp));
child = temp;
}
if (!mHTMLEditor->NodeIsType(aList, aListType))
if (!nsEditor::NodeIsTypeString(aList, aListType))
{
res = mHTMLEditor->ReplaceContainer(aList, outList, aListType);
}
@ -5894,8 +5894,8 @@ nsHTMLEditRules::GetDefinitionListItemTypes(nsIDOMNode *aNode, PRBool &aDT, PRBo
res = aNode->GetFirstChild(getter_AddRefs(child));
while (child && NS_SUCCEEDED(res))
{
if (mHTMLEditor->NodeIsType(child,nsEditProperty::dt)) aDT = PR_TRUE;
else if (mHTMLEditor->NodeIsType(child,nsEditProperty::dd)) aDD = PR_TRUE;
if (nsEditor::NodeIsType(child, nsEditProperty::dt)) aDT = PR_TRUE;
else if (nsEditor::NodeIsType(child, nsEditProperty::dd)) aDD = PR_TRUE;
res = child->GetNextSibling(getter_AddRefs(temp));
child = temp;
}
@ -7703,21 +7703,21 @@ nsHTMLEditRules::RemoveEmptyNodes()
if (!nsTextEditUtils::IsBody(node))
{
// only consider certain nodes to be empty for purposes of removal
if ( (bIsMailCite = nsHTMLEditUtils::IsMailCite(node)) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("a")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("b")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("i")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("u")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("tt")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("s")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("strike")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("big")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("small")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("blink")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("sub")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("sup")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("font")) ||
nsHTMLEditUtils::IsList(node) ||
if ( (bIsMailCite = nsHTMLEditUtils::IsMailCite(node)) ||
nsEditor::NodeIsType(node, nsEditProperty::a) ||
nsEditor::NodeIsType(node, nsEditProperty::b) ||
nsEditor::NodeIsType(node, nsEditProperty::i) ||
nsEditor::NodeIsType(node, nsEditProperty::u) ||
nsEditor::NodeIsType(node, nsEditProperty::tt) ||
nsEditor::NodeIsType(node, nsEditProperty::s) ||
nsEditor::NodeIsType(node, nsEditProperty::strike) ||
nsHTMLEditUtils::IsBig(node) ||
nsHTMLEditUtils::IsSmall(node) ||
nsEditor::NodeIsType(node, nsEditProperty::blink) ||
nsEditor::NodeIsType(node, nsEditProperty::sub) ||
nsEditor::NodeIsType(node, nsEditProperty::sup) ||
nsEditor::NodeIsType(node, nsEditProperty::font) ||
nsHTMLEditUtils::IsList(node) ||
nsHTMLEditUtils::IsDiv(node) )
{
bIsCandidate = PR_TRUE;
@ -8427,7 +8427,7 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignTyp
if (NS_FAILED(res)) return res;
}
}
else if (nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("center"))
else if (nsEditor::NodeIsType(child, nsEditProperty::center)
|| nsHTMLEditUtils::IsDiv(child))
{
// this is a CENTER or a DIV element and we have to remove it
@ -8694,7 +8694,7 @@ nsHTMLEditRules::WillAbsolutePosition(nsISelection *aSelection, PRBool *aCancel,
res = mHTMLEditor->GetSelectionContainer(getter_AddRefs(focusElement));
if (focusElement) {
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(focusElement);
if (mHTMLEditor->NodeIsType(node, nsEditProperty::img)) {
if (nsHTMLEditUtils::IsImage(node)) {
mNewBlock = node;
return NS_OK;
}

Просмотреть файл

@ -42,6 +42,8 @@
#include "nsString.h"
#include "nsUnicharUtils.h"
#include "nsEditor.h"
#include "nsEditProperty.h"
#include "nsIAtom.h"
#include "nsIDOMNode.h"
#include "nsIContent.h"
#include "nsIDOMNodeList.h"
@ -52,7 +54,7 @@
PRBool
nsHTMLEditUtils::IsBig(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("big"));
return nsEditor::NodeIsType(node, nsEditProperty::big);
}
@ -61,7 +63,7 @@ nsHTMLEditUtils::IsBig(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsSmall(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("small"));
return nsEditor::NodeIsType(node, nsEditProperty::small);
}
@ -76,19 +78,13 @@ PRBool
nsHTMLEditUtils::IsHeader(nsIDOMNode *node)
{
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsHeader");
nsAutoString tag;
nsEditor::GetTagString(node,tag);
ToLowerCase(tag);
if ( (tag.Equals(NS_LITERAL_STRING("h1"))) ||
(tag.Equals(NS_LITERAL_STRING("h2"))) ||
(tag.Equals(NS_LITERAL_STRING("h3"))) ||
(tag.Equals(NS_LITERAL_STRING("h4"))) ||
(tag.Equals(NS_LITERAL_STRING("h5"))) ||
(tag.Equals(NS_LITERAL_STRING("h6"))) )
{
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
return (nodeAtom == nsEditProperty::h1)
|| (nodeAtom == nsEditProperty::h2)
|| (nodeAtom == nsEditProperty::h3)
|| (nodeAtom == nsEditProperty::h4)
|| (nodeAtom == nsEditProperty::h5)
|| (nodeAtom == nsEditProperty::h6);
}
@ -98,7 +94,7 @@ nsHTMLEditUtils::IsHeader(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsParagraph(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("p"));
return nsEditor::NodeIsType(node, nsEditProperty::p);
}
@ -108,7 +104,7 @@ nsHTMLEditUtils::IsParagraph(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsHR(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("hr"));
return nsEditor::NodeIsType(node, nsEditProperty::hr);
}
@ -119,16 +115,10 @@ PRBool
nsHTMLEditUtils::IsListItem(nsIDOMNode *node)
{
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsListItem");
nsAutoString tag;
nsEditor::GetTagString(node,tag);
ToLowerCase(tag);
if (tag.Equals(NS_LITERAL_STRING("li")) ||
tag.Equals(NS_LITERAL_STRING("dd")) ||
tag.Equals(NS_LITERAL_STRING("dt")))
{
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
return (nodeAtom == nsEditProperty::li)
|| (nodeAtom == nsEditProperty::dd)
|| (nodeAtom == nsEditProperty::dt);
}
@ -139,16 +129,15 @@ PRBool
nsHTMLEditUtils::IsTableElement(nsIDOMNode *node)
{
NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElement");
nsAutoString tagName;
nsEditor::GetTagString(node,tagName);
if (tagName.Equals(NS_LITERAL_STRING("table")) || tagName.Equals(NS_LITERAL_STRING("tr")) ||
tagName.Equals(NS_LITERAL_STRING("td")) || tagName.Equals(NS_LITERAL_STRING("th")) ||
tagName.Equals(NS_LITERAL_STRING("thead")) || tagName.Equals(NS_LITERAL_STRING("tfoot")) ||
tagName.Equals(NS_LITERAL_STRING("tbody")) || tagName.Equals(NS_LITERAL_STRING("caption")))
{
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
return (nodeAtom == nsEditProperty::table)
|| (nodeAtom == nsEditProperty::tr)
|| (nodeAtom == nsEditProperty::td)
|| (nodeAtom == nsEditProperty::th)
|| (nodeAtom == nsEditProperty::thead)
|| (nodeAtom == nsEditProperty::tfoot)
|| (nodeAtom == nsEditProperty::tbody)
|| (nodeAtom == nsEditProperty::caption);
}
@ -158,7 +147,7 @@ nsHTMLEditUtils::IsTableElement(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsTable(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("table"));
return nsEditor::NodeIsType(node, nsEditProperty::table);
}
///////////////////////////////////////////////////////////////////////////
@ -167,7 +156,7 @@ nsHTMLEditUtils::IsTable(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsTableRow(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("tr"));
return nsEditor::NodeIsType(node, nsEditProperty::tr);
}
@ -178,14 +167,9 @@ PRBool
nsHTMLEditUtils::IsTableCell(nsIDOMNode *node)
{
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableCell");
nsAutoString tag;
nsEditor::GetTagString(node,tag);
ToLowerCase(tag);
if (tag.Equals(NS_LITERAL_STRING("td")) || tag.Equals(NS_LITERAL_STRING("th")))
{
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
return (nodeAtom == nsEditProperty::td)
|| (nodeAtom == nsEditProperty::th);
}
@ -196,16 +180,10 @@ PRBool
nsHTMLEditUtils::IsTableCellOrCaption(nsIDOMNode *node)
{
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableCell");
nsAutoString tag;
nsEditor::GetTagString(node,tag);
ToLowerCase(tag);
if (tag.Equals(NS_LITERAL_STRING("td")) ||
tag.Equals(NS_LITERAL_STRING("th")) ||
tag.Equals(NS_LITERAL_STRING("caption")) )
{
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
return (nodeAtom == nsEditProperty::td)
|| (nodeAtom == nsEditProperty::th)
|| (nodeAtom == nsEditProperty::caption);
}
@ -216,16 +194,10 @@ PRBool
nsHTMLEditUtils::IsList(nsIDOMNode *node)
{
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsList");
nsAutoString tag;
nsEditor::GetTagString(node,tag);
ToLowerCase(tag);
if ( (tag.Equals(NS_LITERAL_STRING("dl"))) ||
(tag.Equals(NS_LITERAL_STRING("ol"))) ||
(tag.Equals(NS_LITERAL_STRING("ul"))) )
{
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
return (nodeAtom == nsEditProperty::ul)
|| (nodeAtom == nsEditProperty::ol)
|| (nodeAtom == nsEditProperty::dl);
}
@ -235,7 +207,7 @@ nsHTMLEditUtils::IsList(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsOrderedList(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("ol"));
return nsEditor::NodeIsType(node, nsEditProperty::ol);
}
@ -245,7 +217,7 @@ nsHTMLEditUtils::IsOrderedList(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsUnorderedList(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("ul"));
return nsEditor::NodeIsType(node, nsEditProperty::ul);
}
@ -255,7 +227,7 @@ nsHTMLEditUtils::IsUnorderedList(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsBlockquote(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("blockquote"));
return nsEditor::NodeIsType(node, nsEditProperty::blockquote);
}
@ -265,7 +237,7 @@ nsHTMLEditUtils::IsBlockquote(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsPre(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("pre"));
return nsEditor::NodeIsType(node, nsEditProperty::pre);
}
@ -275,7 +247,7 @@ nsHTMLEditUtils::IsPre(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsAddress(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("address"));
return nsEditor::NodeIsType(node, nsEditProperty::address);
}
@ -285,7 +257,7 @@ nsHTMLEditUtils::IsAddress(nsIDOMNode *node)
PRBool
nsHTMLEditUtils::IsImage(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("img"));
return nsEditor::NodeIsType(node, nsEditProperty::img);
}
PRBool
@ -323,7 +295,7 @@ nsHTMLEditUtils::IsNamedAnchor(nsIDOMNode *aNode)
PRBool
nsHTMLEditUtils::IsDiv(nsIDOMNode *node)
{
return nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("div"));
return nsEditor::NodeIsType(node, nsEditProperty::div);
}
@ -381,43 +353,32 @@ PRBool
nsHTMLEditUtils::IsFormWidget(nsIDOMNode *node)
{
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsFormWidget");
nsAutoString tag;
nsEditor::GetTagString(node,tag);
ToLowerCase(tag);
if (tag.Equals(NS_LITERAL_STRING("textarea")) ||
tag.Equals(NS_LITERAL_STRING("select")) ||
tag.Equals(NS_LITERAL_STRING("button")) ||
tag.Equals(NS_LITERAL_STRING("input")) )
{
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
return (nodeAtom == nsEditProperty::textarea)
|| (nodeAtom == nsEditProperty::select)
|| (nodeAtom == nsEditProperty::button)
|| (nodeAtom == nsEditProperty::input);
}
PRBool
nsHTMLEditUtils::SupportsAlignAttr(nsIDOMNode * aNode)
{
NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::SupportsAlignAttr");
nsAutoString tag;
nsEditor::GetTagString(aNode, tag);
ToLowerCase(tag);
if (tag.Equals(NS_LITERAL_STRING("hr")) ||
tag.Equals(NS_LITERAL_STRING("table")) ||
tag.Equals(NS_LITERAL_STRING("tbody")) ||
tag.Equals(NS_LITERAL_STRING("tfoot")) ||
tag.Equals(NS_LITERAL_STRING("thead")) ||
tag.Equals(NS_LITERAL_STRING("tr")) ||
tag.Equals(NS_LITERAL_STRING("td")) ||
tag.Equals(NS_LITERAL_STRING("th")) ||
tag.Equals(NS_LITERAL_STRING("div")) ||
tag.Equals(NS_LITERAL_STRING("p")) ||
tag.Equals(NS_LITERAL_STRING("h1")) ||
tag.Equals(NS_LITERAL_STRING("h2")) ||
tag.Equals(NS_LITERAL_STRING("h3")) ||
tag.Equals(NS_LITERAL_STRING("h4")) ||
tag.Equals(NS_LITERAL_STRING("h5")) ||
tag.Equals(NS_LITERAL_STRING("h6"))) {
return PR_TRUE;
}
return PR_FALSE;
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode);
return (nodeAtom == nsEditProperty::hr)
|| (nodeAtom == nsEditProperty::table)
|| (nodeAtom == nsEditProperty::tbody)
|| (nodeAtom == nsEditProperty::tfoot)
|| (nodeAtom == nsEditProperty::thead)
|| (nodeAtom == nsEditProperty::tr)
|| (nodeAtom == nsEditProperty::td)
|| (nodeAtom == nsEditProperty::th)
|| (nodeAtom == nsEditProperty::div)
|| (nodeAtom == nsEditProperty::p)
|| (nodeAtom == nsEditProperty::h1)
|| (nodeAtom == nsEditProperty::h2)
|| (nodeAtom == nsEditProperty::h3)
|| (nodeAtom == nsEditProperty::h4)
|| (nodeAtom == nsEditProperty::h5)
|| (nodeAtom == nsEditProperty::h6);
}

Просмотреть файл

@ -5932,7 +5932,7 @@ nsHTMLEditor::NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2)
nsCOMPtr<nsIAtom> atom2 = GetTag(aNode2);
if (atom1.get() == atom2.get()) {
if (useCSS && NodeIsType(aNode1, NS_LITERAL_STRING("span"))) {
if (useCSS && atom1 == nsEditProperty::span) {
if (mHTMLCSSUtils->ElementsSameStyle(aNode1, aNode2)) {
return PR_TRUE;
}
@ -6009,19 +6009,19 @@ nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNod
}
nsCOMPtr<nsIDOMNode> newStyles = nsnull, deepestStyle = nsnull;
while (child && (child != aPreviousBlock)) {
if (nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("b")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("i")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("u")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("tt")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("s")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("strike")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("big")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("small")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("blink")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("sub")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("sup")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("font")) ||
nsTextEditUtils::NodeIsType(child, NS_LITERAL_STRING("span"))) {
if (nsEditor::NodeIsType(child, nsEditProperty::b) ||
nsEditor::NodeIsType(child, nsEditProperty::i) ||
nsEditor::NodeIsType(child, nsEditProperty::u) ||
nsEditor::NodeIsType(child, nsEditProperty::tt) ||
nsEditor::NodeIsType(child, nsEditProperty::s) ||
nsEditor::NodeIsType(child, nsEditProperty::strike) ||
nsHTMLEditUtils::IsBig(child) ||
nsHTMLEditUtils::IsSmall(child) ||
nsEditor::NodeIsType(child, nsEditProperty::blink) ||
nsEditor::NodeIsType(child, nsEditProperty::sub) ||
nsEditor::NodeIsType(child, nsEditProperty::sup) ||
nsEditor::NodeIsType(child, nsEditProperty::font) ||
nsEditor::NodeIsType(child, nsEditProperty::span)) {
nsAutoString domTagName;
child->GetNodeName(domTagName);
ToLowerCase(domTagName);
@ -6073,7 +6073,7 @@ nsHTMLEditor::GetElementOrigin(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 &
pcontext->GetTwipsToPixels(&t2p);
if (NodeIsType(aElement, NS_LITERAL_STRING("hr"))) {
if (nsHTMLEditUtils::IsHR(aElement)) {
nsIFrame* childFrame;
//frame->FirstChild(pcontext, nsnull, &childFrame);
frame->GetNextSibling(&childFrame);

Просмотреть файл

@ -58,6 +58,7 @@
#include "nsIHTMLObjectResizer.h"
#include "nsEditProperty.h"
#include "nsTextEditUtils.h"
#include "nsHTMLEditUtils.h"
#include "nsIHTMLInlineTableEditor.h"
/*
@ -252,12 +253,12 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
}
}
if (nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("body")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("td")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("th")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("caption")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("tr")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("table")))
// XXX: should we call nsHTMLEditUtils::IsTableElement here?
// that also checks for thead, tbody, tfoot
if (nsTextEditUtils::IsBody(node) ||
nsHTMLEditUtils::IsTableCellOrCaption(node) ||
nsHTMLEditUtils::IsTableRow(node) ||
nsHTMLEditUtils::IsTable(node))
{
// This will place caret just inside table cell or at start of body
selection->Collapse(parent, offset);

Просмотреть файл

@ -438,14 +438,14 @@ nsHTMLEditor::SetInlinePropertyOnNode( nsIDOMNode *aNode,
res = tmp->GetParentNode(getter_AddRefs(mergeParent));
if (NS_FAILED(res)) return res;
if (previousSibling &&
nsTextEditUtils::NodeIsType(previousSibling, NS_LITERAL_STRING("span")) &&
nsEditor::NodeIsType(previousSibling, nsEditProperty::span) &&
NodesSameType(tmp, previousSibling))
{
res = JoinNodes(previousSibling, tmp, mergeParent);
if (NS_FAILED(res)) return res;
}
if (nextSibling &&
nsTextEditUtils::NodeIsType(nextSibling, NS_LITERAL_STRING("span")) &&
nsEditor::NodeIsType(nextSibling, nsEditProperty::span) &&
NodesSameType(tmp, nextSibling))
{
res = JoinNodes(tmp, nextSibling, mergeParent);
@ -756,7 +756,7 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode,
}
}
if ( aProperty == nsEditProperty::font && // or node is big or small and we are setting font size
(NodeIsType(aNode, nsEditProperty::big) || NodeIsType(aNode, nsEditProperty::small)) &&
(nsHTMLEditUtils::IsBig(aNode) || nsHTMLEditUtils::IsSmall(aNode)) &&
aAttribute->Equals(NS_LITERAL_STRING("size"),nsCaseInsensitiveStringComparator()))
{
res = RemoveContainer(aNode); // if we are setting font size, remove any nested bigs and smalls
@ -1668,7 +1668,7 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( PRInt32 aSizeChange,
// look for siblings that are correct type of node
nsCOMPtr<nsIDOMNode> sibling;
GetPriorHTMLSibling(node, address_of(sibling));
if (sibling && NodeIsType(sibling, nodeType))
if (sibling && NodeIsType(sibling, (aSizeChange==1) ? nsEditProperty::big : nsEditProperty::small))
{
// previous sib is already right kind of inline node; slide this over into it
res = MoveNode(node, sibling, -1);
@ -1676,7 +1676,7 @@ nsHTMLEditor::RelativeFontChangeOnTextNode( PRInt32 aSizeChange,
}
sibling = nsnull;
GetNextHTMLSibling(node, address_of(sibling));
if (sibling && NodeIsType(sibling, nodeType))
if (sibling && NodeIsType(sibling, (aSizeChange==1) ? nsEditProperty::big : nsEditProperty::small))
{
// following sib is already right kind of inline node; slide this over into it
res = MoveNode(node, sibling, 0);
@ -1794,7 +1794,7 @@ nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange,
// if we find one, move aNode into it.
nsCOMPtr<nsIDOMNode> sibling;
GetPriorHTMLSibling(aNode, address_of(sibling));
if (sibling && NodeIsType(sibling, NS_ConvertASCIItoUCS2(aSizeChange==1 ? "big" : "small")))
if (sibling && nsEditor::NodeIsType(sibling, (aSizeChange==1 ? nsEditProperty::big : nsEditProperty::small)))
{
// previous sib is already right kind of inline node; slide this over into it
res = MoveNode(aNode, sibling, -1);
@ -1802,7 +1802,7 @@ nsHTMLEditor::RelativeFontChangeOnNode( PRInt32 aSizeChange,
}
sibling = nsnull;
GetNextHTMLSibling(aNode, address_of(sibling));
if (sibling && NodeIsType(sibling, NS_ConvertASCIItoUCS2(aSizeChange==1 ? "big" : "small")))
if (sibling && nsEditor::NodeIsType(sibling, (aSizeChange==1 ? nsEditProperty::big : nsEditProperty::small)))
{
// following sib is already right kind of inline node; slide this over into it
res = MoveNode(aNode, sibling, 0);

Просмотреть файл

@ -231,7 +231,7 @@ nsHTMLEditor::CreateShadow(nsIDOMElement ** aReturn, nsIDOMNode * aParentNode,
{
// let's create an image through the element factory
nsAutoString name;
if (NodeIsType(aOriginalObject, NS_LITERAL_STRING("img")))
if (nsHTMLEditUtils::IsImage(aOriginalObject))
name = NS_LITERAL_STRING("img");
else
name = NS_LITERAL_STRING("span");
@ -531,7 +531,7 @@ nsHTMLEditor::StartResizing(nsIDOMElement *aHandle)
mActivatedHandle->SetAttribute(NS_LITERAL_STRING("_moz_activated"), NS_LITERAL_STRING("true"));
// do we want to preserve ratio or not?
PRBool preserveRatio = NodeIsType(mResizedObject, NS_LITERAL_STRING("img"));
PRBool preserveRatio = nsHTMLEditUtils::IsImage(mResizedObject);
nsresult result;
nsCOMPtr<nsIPrefBranch> prefBranch =
do_GetService(NS_PREFSERVICE_CONTRACTID, &result);
@ -804,7 +804,7 @@ nsHTMLEditor::SetShadowPosition(nsIDOMElement * aShadow,
{
SetAnonymousElementPosition(aOriginalObjectX, aOriginalObjectY, aShadow);
if(NodeIsType(aOriginalObject, NS_LITERAL_STRING("img"))) {
if (nsHTMLEditUtils::IsImage(aOriginalObject)) {
nsAutoString imageSource;
nsresult res = aOriginalObject->GetAttribute(NS_LITERAL_STRING("src"),
imageSource);

Просмотреть файл

@ -40,29 +40,11 @@
#include "nsEditor.h"
#include "nsPlaintextEditor.h"
#include "nsEditProperty.h"
#include "nsString.h"
#include "nsUnicharUtils.h"
/********************************************************
* helper methods from nsTextEditRules
********************************************************/
PRBool
nsTextEditUtils::NodeIsType(nsIDOMNode *aNode, const nsAString& aTag)
{
NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::NodeIsType");
if (aNode)
{
nsAutoString tag;
nsEditor::GetTagString(aNode,tag);
ToLowerCase(tag);
if (tag.Equals(aTag))
return PR_TRUE;
}
return PR_FALSE;
}
/********************************************************
* helper methods from nsTextEditRules
********************************************************/
@ -73,7 +55,7 @@ nsTextEditUtils::NodeIsType(nsIDOMNode *aNode, const nsAString& aTag)
PRBool
nsTextEditUtils::IsBody(nsIDOMNode *node)
{
return NodeIsType(node, NS_LITERAL_STRING("body"));
return nsEditor::NodeIsType(node, nsEditProperty::body);
}
@ -83,7 +65,7 @@ nsTextEditUtils::IsBody(nsIDOMNode *node)
PRBool
nsTextEditUtils::IsBreak(nsIDOMNode *node)
{
return NodeIsType(node, NS_LITERAL_STRING("br"));
return nsEditor::NodeIsType(node, nsEditProperty::br);
}

Просмотреть файл

@ -49,8 +49,6 @@ class nsPlaintextEditor;
class nsTextEditUtils
{
public:
static PRBool NodeIsType(nsIDOMNode *aNode, const nsAString& aTag);
// from nsTextEditRules:
static PRBool IsBody(nsIDOMNode *aNode);
static PRBool IsBreak(nsIDOMNode *aNode);