2000-01-26 03:36:18 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsHTMLEditUtils.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsEditor.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* helper methods from nsTextEditRules
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBody: true if node an html body node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsBody(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsBody");
|
2000-06-22 09:39:54 +04:00
|
|
|
if (node)
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
2000-06-22 09:39:54 +04:00
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
|
|
|
if (tag.EqualsWithConversion("body"))
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-01-26 03:36:18 +03:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBreak: true if node an html break node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsBreak(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsBreak");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("br"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-08 15:53:34 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBreak: true if node an html break node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsBig(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsBig");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("big"))
|
2000-02-08 15:53:34 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBreak: true if node an html break node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsSmall(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsSmall");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("small"))
|
2000-02-08 15:53:34 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-26 03:36:18 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsMozBR: true if node an html br node with type = _moz
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsMozBR(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsMozBR");
|
|
|
|
if (IsBreak(node) && HasMozAttr(node)) return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// HasMozAttr: true if node has type attribute = _moz
|
|
|
|
// (used to indicate the div's and br's we use in
|
|
|
|
// mail compose rules)
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::HasMozAttr(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::HasMozAttr");
|
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
|
|
|
|
if (elem)
|
|
|
|
{
|
2000-04-18 11:52:02 +04:00
|
|
|
nsAutoString typeAttrName; typeAttrName.AssignWithConversion("type");
|
2000-01-26 03:36:18 +03:00
|
|
|
nsAutoString typeAttrVal;
|
|
|
|
nsresult res = elem->GetAttribute(typeAttrName, typeAttrVal);
|
|
|
|
typeAttrVal.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (NS_SUCCEEDED(res) && (typeAttrVal.EqualsWithConversion("_moz")))
|
2000-01-26 03:36:18 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-02-25 07:39:30 +03:00
|
|
|
|
2000-01-26 03:36:18 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// InBody: true if node is a descendant of the body
|
|
|
|
//
|
|
|
|
PRBool
|
2000-05-04 12:33:48 +04:00
|
|
|
nsHTMLEditUtils::InBody(nsIDOMNode *node, nsIEditor *editor)
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
2000-05-04 12:33:48 +04:00
|
|
|
if ( node )
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
2000-05-04 12:33:48 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> bodyElement;
|
|
|
|
nsresult res = editor->GetRootElement(getter_AddRefs(bodyElement));
|
|
|
|
if (NS_FAILED(res) || !bodyElement)
|
|
|
|
return res?res:NS_ERROR_NULL_POINTER;
|
|
|
|
nsCOMPtr<nsIDOMNode> bodyNode = do_QueryInterface(bodyElement);
|
|
|
|
nsCOMPtr<nsIDOMNode> tmp;
|
|
|
|
nsCOMPtr<nsIDOMNode> p = node;
|
|
|
|
while (p && p!= bodyNode)
|
|
|
|
{
|
|
|
|
if (NS_FAILED(p->GetParentNode(getter_AddRefs(tmp))) || !tmp)
|
|
|
|
return PR_FALSE;
|
|
|
|
p = tmp;
|
|
|
|
}
|
2000-01-26 03:36:18 +03:00
|
|
|
}
|
2000-05-04 12:33:48 +04:00
|
|
|
return PR_TRUE;
|
2000-01-26 03:36:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* helper methods from nsHTMLEditRules
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsHeader: true if node an html header
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsHeader(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsHeader");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if ( (tag.EqualsWithConversion("h1")) ||
|
|
|
|
(tag.EqualsWithConversion("h2")) ||
|
|
|
|
(tag.EqualsWithConversion("h3")) ||
|
|
|
|
(tag.EqualsWithConversion("h4")) ||
|
|
|
|
(tag.EqualsWithConversion("h5")) ||
|
|
|
|
(tag.EqualsWithConversion("h6")) )
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsParagraph: true if node an html paragraph
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsParagraph(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsParagraph");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("p"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsListItem: true if node an html list item
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsListItem(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsListItem");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
if (tag.EqualsWithConversion("li") ||
|
|
|
|
tag.EqualsWithConversion("dd") ||
|
|
|
|
tag.EqualsWithConversion("dt"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2000-03-21 09:05:24 +03:00
|
|
|
// IsTable: true if node an html table
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsTable(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTable");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("table"))
|
2000-03-21 09:05:24 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTableRow: true if node an html tr
|
2000-01-26 03:36:18 +03:00
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsTableRow(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableRow");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("tr"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTableCell: true if node an html td or th
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsTableCell(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableCell");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("td") || tag.EqualsWithConversion("th"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsList: true if node an html list
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsList(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsList");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
if ( (tag.EqualsWithConversion("dl")) ||
|
|
|
|
(tag.EqualsWithConversion("ol")) ||
|
2000-04-18 11:52:02 +04:00
|
|
|
(tag.EqualsWithConversion("ul")) )
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
// IsOrderedList: true if node an html ordered list
|
2000-01-26 03:36:18 +03:00
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsOrderedList(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsOrderedList");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("ol"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
// IsUnorderedList: true if node an html unordered list
|
2000-01-26 03:36:18 +03:00
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsUnorderedList(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsUnorderedList");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("ul"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsDefinitionList: true if node an html definition list
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsDefinitionList(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsDefinitionList");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
|
|
|
if (tag.EqualsWithConversion("dl"))
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-26 03:36:18 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBlockquote: true if node an html blockquote node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsBlockquote(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsBlockquote");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("blockquote"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 07:39:30 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsPre: true if node an html pre node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsPre(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsPre");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("pre"))
|
2000-02-25 07:39:30 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsAddress: true if node an html address node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsAddress(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsAddress");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("address"))
|
2000-02-25 07:39:30 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-26 03:36:18 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsAnchor: true if node an html anchor node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsAnchor(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsAnchor");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("a"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsImage: true if node an html image node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsImage(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsImage");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("img"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsDiv: true if node an html div node
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsDiv(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsDiv");
|
|
|
|
nsAutoString tag;
|
|
|
|
nsEditor::GetTagString(node,tag);
|
|
|
|
tag.ToLowerCase();
|
2000-04-18 11:52:02 +04:00
|
|
|
if (tag.EqualsWithConversion("div"))
|
2000-01-26 03:36:18 +03:00
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsNormalDiv: true if node an html div node, without type = _moz
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsNormalDiv(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
if (IsDiv(node) && !nsHTMLEditUtils::HasMozAttr(node)) return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsMozDiv: true if node an html div node with type = _moz
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsMozDiv(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
if (IsDiv(node) && HasMozAttr(node)) return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsMailCite: true if node an html blockquote with type=cite
|
|
|
|
//
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsMailCite(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsMailCite");
|
|
|
|
if (IsBlockquote(node))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> bqElem = do_QueryInterface(node);
|
2000-04-18 11:52:02 +04:00
|
|
|
nsAutoString typeAttrName; typeAttrName.AssignWithConversion("type");
|
2000-01-26 03:36:18 +03:00
|
|
|
nsAutoString typeAttrVal;
|
|
|
|
nsresult res = bqElem->GetAttribute(typeAttrName, typeAttrVal);
|
|
|
|
typeAttrVal.ToLowerCase();
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
2000-04-18 11:52:02 +04:00
|
|
|
if (typeAttrVal.EqualsWithConversion("cite", PR_TRUE, 4))
|
2000-01-26 03:36:18 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLEditUtils::IsDescendantOf(nsIDOMNode *aNode, nsIDOMNode *aParent)
|
|
|
|
{
|
|
|
|
if (!aNode && !aParent) return PR_FALSE;
|
|
|
|
if (aNode == aParent) return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> parent, node = do_QueryInterface(aNode);
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
res = node->GetParentNode(getter_AddRefs(parent));
|
|
|
|
if (NS_FAILED(res)) return PR_FALSE;
|
|
|
|
if (parent.get() == aParent) return PR_TRUE;
|
|
|
|
node = parent;
|
|
|
|
} while (parent);
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|