2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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 the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2012-01-24 23:50:05 -08:00
|
|
|
#include "nsHTMLEditUtils.h"
|
|
|
|
|
|
|
|
#include "mozilla/Assertions.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
2012-01-24 23:50:05 -08:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsTextEditUtils.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsEditor.h"
|
|
|
|
#include "nsEditProperty.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
|
|
|
#include "nsHTMLTags.h"
|
|
|
|
|
2011-10-10 22:50:08 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsBig(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::big);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsInlineStyle true if node is an inline style
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsInlineStyle(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsInlineStyle");
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
|
|
|
|
return (nodeAtom == nsEditProperty::b)
|
|
|
|
|| (nodeAtom == nsEditProperty::i)
|
|
|
|
|| (nodeAtom == nsEditProperty::u)
|
|
|
|
|| (nodeAtom == nsEditProperty::tt)
|
|
|
|
|| (nodeAtom == nsEditProperty::s)
|
|
|
|
|| (nodeAtom == nsEditProperty::strike)
|
|
|
|
|| (nodeAtom == nsEditProperty::big)
|
|
|
|
|| (nodeAtom == nsEditProperty::small)
|
|
|
|
|| (nodeAtom == nsEditProperty::blink)
|
|
|
|
|| (nodeAtom == nsEditProperty::sub)
|
|
|
|
|| (nodeAtom == nsEditProperty::sup)
|
|
|
|
|| (nodeAtom == nsEditProperty::font);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsFormatNode true if node is a format node
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsFormatNode(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsFormatNode");
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
|
|
|
|
return (nodeAtom == nsEditProperty::p)
|
|
|
|
|| (nodeAtom == nsEditProperty::pre)
|
|
|
|
|| (nodeAtom == nsEditProperty::h1)
|
|
|
|
|| (nodeAtom == nsEditProperty::h2)
|
|
|
|
|| (nodeAtom == nsEditProperty::h3)
|
|
|
|
|| (nodeAtom == nsEditProperty::h4)
|
|
|
|
|| (nodeAtom == nsEditProperty::h5)
|
|
|
|
|| (nodeAtom == nsEditProperty::h6)
|
|
|
|
|| (nodeAtom == nsEditProperty::address);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsNodeThatCanOutdent true if node is a list, list item, or blockquote
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsNodeThatCanOutdent(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsNodeThatCanOutdent");
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
|
|
|
|
return (nodeAtom == nsEditProperty::ul)
|
|
|
|
|| (nodeAtom == nsEditProperty::ol)
|
|
|
|
|| (nodeAtom == nsEditProperty::dl)
|
|
|
|
|| (nodeAtom == nsEditProperty::li)
|
|
|
|
|| (nodeAtom == nsEditProperty::dd)
|
|
|
|
|| (nodeAtom == nsEditProperty::dt)
|
|
|
|
|| (nodeAtom == nsEditProperty::blockquote);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsSmall(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::small);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* helper methods from nsHTMLEditRules
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsHeader: true if node an html header
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsHeader(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsHeader");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsParagraph: true if node an html paragraph
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsParagraph(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsHR: true if node an horizontal rule
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsHR(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::hr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsListItem: true if node an html list item
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsListItem(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsListItem");
|
2012-01-24 23:50:05 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(node);
|
|
|
|
return element && IsListItem(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLEditUtils::IsListItem(dom::Element* node)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(node);
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = node->Tag();
|
2007-03-22 10:30:00 -07:00
|
|
|
return (nodeAtom == nsEditProperty::li)
|
|
|
|
|| (nodeAtom == nsEditProperty::dd)
|
|
|
|
|| (nodeAtom == nsEditProperty::dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTableElement: true if node an html table, td, tr, ...
|
|
|
|
//
|
2012-02-01 02:54:22 -08:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsTableElement(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElement");
|
2012-02-01 02:54:22 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(node);
|
|
|
|
return element && IsTableElement(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLEditUtils::IsTableElement(dom::Element* node)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(node);
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = node->Tag();
|
2007-03-22 10:30:00 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTableElementButNotTable: true if node an html td, tr, ... (doesn't include table)
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsTableElementButNotTable(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditor::IsTableElementButNotTable");
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
|
|
|
|
return (nodeAtom == nsEditProperty::tr)
|
|
|
|
|| (nodeAtom == nsEditProperty::td)
|
|
|
|
|| (nodeAtom == nsEditProperty::th)
|
|
|
|
|| (nodeAtom == nsEditProperty::thead)
|
|
|
|
|| (nodeAtom == nsEditProperty::tfoot)
|
|
|
|
|| (nodeAtom == nsEditProperty::tbody)
|
|
|
|
|| (nodeAtom == nsEditProperty::caption);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTable: true if node an html table
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsTable(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::table);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTableRow: true if node an html tr
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsTableRow(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTableCell: true if node an html td or th
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsTableCell(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableCell");
|
2012-01-24 23:50:05 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(node);
|
|
|
|
return element && IsTableCell(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLEditUtils::IsTableCell(dom::Element* node)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(node);
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = node->Tag();
|
2007-03-22 10:30:00 -07:00
|
|
|
return (nodeAtom == nsEditProperty::td)
|
|
|
|
|| (nodeAtom == nsEditProperty::th);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsTableCell: true if node an html td or th
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsTableCellOrCaption(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsTableCell");
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(node);
|
|
|
|
return (nodeAtom == nsEditProperty::td)
|
|
|
|
|| (nodeAtom == nsEditProperty::th)
|
|
|
|
|| (nodeAtom == nsEditProperty::caption);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsList: true if node an html list
|
|
|
|
//
|
2012-01-24 23:50:05 -08:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsList(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsList");
|
2012-01-24 23:50:05 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(node);
|
|
|
|
return element && IsList(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLEditUtils::IsList(dom::Element* node)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(node);
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = node->Tag();
|
2007-03-22 10:30:00 -07:00
|
|
|
return (nodeAtom == nsEditProperty::ul)
|
|
|
|
|| (nodeAtom == nsEditProperty::ol)
|
|
|
|
|| (nodeAtom == nsEditProperty::dl);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsOrderedList: true if node an html ordered list
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsOrderedList(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::ol);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsUnorderedList: true if node an html unordered list
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsUnorderedList(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::ul);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsBlockquote: true if node an html blockquote node
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsBlockquote(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::blockquote);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsPre: true if node an html pre node
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsPre(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::pre);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsImage: true if node an html image node
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsImage(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::img);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsLink(nsIDOMNode *aNode)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(aNode, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
|
|
|
|
if (anchor)
|
|
|
|
{
|
|
|
|
nsAutoString tmpText;
|
|
|
|
if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && !tmpText.IsEmpty())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsNamedAnchor(nsIDOMNode *aNode)
|
|
|
|
{
|
2012-01-24 23:50:05 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
|
|
|
|
return element && IsNamedAnchor(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLEditUtils::IsNamedAnchor(dom::Element* aNode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
if (!aNode->IsHTML(nsGkAtoms::a)) {
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-01-24 23:50:05 -08:00
|
|
|
|
|
|
|
nsAutoString text;
|
|
|
|
return aNode->GetAttr(kNameSpaceID_None, nsGkAtoms::name, text) &&
|
|
|
|
!text.IsEmpty();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsDiv: true if node an html div node
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsDiv(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
return nsEditor::NodeIsType(node, nsEditProperty::div);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsMozDiv: true if node an html div node with type = _moz
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsMozDiv(nsIDOMNode *node)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
if (IsDiv(node) && nsTextEditUtils::HasMozAttr(node)) return true;
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsMailCite: true if node an html blockquote with type=cite
|
|
|
|
//
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsMailCite(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsMailCite");
|
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(node);
|
2011-07-14 14:06:37 -07:00
|
|
|
if (!elem) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-07-14 14:06:37 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString attrName (NS_LITERAL_STRING("type"));
|
|
|
|
|
|
|
|
// don't ask me why, but our html mailcites are id'd by "type=cite"...
|
|
|
|
nsAutoString attrVal;
|
|
|
|
nsresult res = elem->GetAttribute(attrName, attrVal);
|
|
|
|
ToLowerCase(attrVal);
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
if (attrVal.EqualsLiteral("cite"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ... but our plaintext mailcites by "_moz_quote=true". go figure.
|
|
|
|
attrName.AssignLiteral("_moz_quote");
|
|
|
|
res = elem->GetAttribute(attrName, attrVal);
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
ToLowerCase(attrVal);
|
|
|
|
if (attrVal.EqualsLiteral("true"))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// IsFormWidget: true if node is a form widget of some kind
|
|
|
|
//
|
2012-01-24 23:50:05 -08:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsFormWidget(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(node, "null node passed to nsHTMLEditUtils::IsFormWidget");
|
2012-01-24 23:50:05 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(node);
|
|
|
|
return element && IsFormWidget(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLEditUtils::IsFormWidget(dom::Element* node)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(node);
|
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = node->Tag();
|
2007-03-22 10:30:00 -07:00
|
|
|
return (nodeAtom == nsEditProperty::textarea)
|
|
|
|
|| (nodeAtom == nsEditProperty::select)
|
|
|
|
|| (nodeAtom == nsEditProperty::button)
|
2010-04-26 00:42:00 -07:00
|
|
|
|| (nodeAtom == nsEditProperty::output)
|
2010-10-21 14:12:49 -07:00
|
|
|
|| (nodeAtom == nsEditProperty::keygen)
|
2011-04-09 10:22:02 -07:00
|
|
|
|| (nodeAtom == nsEditProperty::progress)
|
2007-03-22 10:30:00 -07:00
|
|
|
|| (nodeAtom == nsEditProperty::input);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::SupportsAlignAttr(nsIDOMNode * aNode)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::SupportsAlignAttr");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We use bitmasks to test containment of elements. Elements are marked to be
|
|
|
|
// in certain groups by setting the mGroup member of the nsElementInfo struct
|
|
|
|
// to the corresponding GROUP_ values (OR'ed together). Similarly, elements are
|
|
|
|
// marked to allow containment of certain groups by setting the
|
|
|
|
// mCanContainGroups member of the nsElementInfo struct to the corresponding
|
|
|
|
// GROUP_ values (OR'ed together).
|
|
|
|
// Testing containment then simply consists of checking whether the
|
|
|
|
// mCanContainGroups bitmask of an element and the mGroup bitmask of a
|
|
|
|
// potential child overlap.
|
|
|
|
|
|
|
|
#define GROUP_NONE 0
|
|
|
|
|
|
|
|
// body, head, html
|
|
|
|
#define GROUP_TOPLEVEL (1 << 1)
|
|
|
|
|
2011-07-23 02:45:38 -07:00
|
|
|
// base, link, meta, script, style, title
|
2007-03-22 10:30:00 -07:00
|
|
|
#define GROUP_HEAD_CONTENT (1 << 2)
|
|
|
|
|
|
|
|
// b, big, i, s, small, strike, tt, u
|
|
|
|
#define GROUP_FONTSTYLE (1 << 3)
|
|
|
|
|
2010-09-09 22:16:56 -07:00
|
|
|
// abbr, acronym, cite, code, datalist, del, dfn, em, ins, kbd, mark, samp,
|
|
|
|
// strong, var
|
2007-03-22 10:30:00 -07:00
|
|
|
#define GROUP_PHRASE (1 << 4)
|
|
|
|
|
2011-04-09 10:22:02 -07:00
|
|
|
// a, applet, basefont, bdo, br, font, iframe, img, map, object, output,
|
|
|
|
// progress, q, script, span, sub, sup
|
2007-03-22 10:30:00 -07:00
|
|
|
#define GROUP_SPECIAL (1 << 5)
|
|
|
|
|
|
|
|
// button, form, input, label, select, textarea
|
|
|
|
#define GROUP_FORMCONTROL (1 << 6)
|
|
|
|
|
2010-06-19 11:44:43 -07:00
|
|
|
// address, applet, article, aside, blockquote, button, center, del, dir, div,
|
2010-06-23 10:08:56 -07:00
|
|
|
// dl, fieldset, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup,
|
2011-07-23 02:45:38 -07:00
|
|
|
// hr, iframe, ins, map, menu, nav, noframes, noscript, object, ol, p,
|
2010-06-23 10:08:56 -07:00
|
|
|
// pre, table, section, ul
|
2007-03-22 10:30:00 -07:00
|
|
|
#define GROUP_BLOCK (1 << 7)
|
|
|
|
|
|
|
|
// frame, frameset
|
|
|
|
#define GROUP_FRAME (1 << 8)
|
|
|
|
|
|
|
|
// col, tbody
|
|
|
|
#define GROUP_TABLE_CONTENT (1 << 9)
|
|
|
|
|
|
|
|
// tr
|
|
|
|
#define GROUP_TBODY_CONTENT (1 << 10)
|
|
|
|
|
|
|
|
// td, th
|
|
|
|
#define GROUP_TR_CONTENT (1 << 11)
|
|
|
|
|
|
|
|
// col
|
|
|
|
#define GROUP_COLGROUP_CONTENT (1 << 12)
|
|
|
|
|
|
|
|
// param
|
|
|
|
#define GROUP_OBJECT_CONTENT (1 << 13)
|
|
|
|
|
|
|
|
// li
|
|
|
|
#define GROUP_LI (1 << 14)
|
|
|
|
|
|
|
|
// area
|
|
|
|
#define GROUP_MAP_CONTENT (1 << 15)
|
|
|
|
|
|
|
|
// optgroup, option
|
|
|
|
#define GROUP_SELECT_CONTENT (1 << 16)
|
|
|
|
|
|
|
|
// option
|
2010-09-09 22:16:56 -07:00
|
|
|
#define GROUP_OPTIONS (1 << 17)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// dd, dt
|
|
|
|
#define GROUP_DL_CONTENT (1 << 18)
|
|
|
|
|
|
|
|
// p
|
|
|
|
#define GROUP_P (1 << 19)
|
|
|
|
|
|
|
|
// text, whitespace, newline, comment
|
|
|
|
#define GROUP_LEAF (1 << 20)
|
|
|
|
|
|
|
|
// XXX This is because the editor does sublists illegally.
|
|
|
|
// ol, ul
|
|
|
|
#define GROUP_OL_UL (1 << 21)
|
|
|
|
|
2010-06-19 11:44:43 -07:00
|
|
|
// h1, h2, h3, h4, h5, h6
|
|
|
|
#define GROUP_HEADING (1 << 22)
|
|
|
|
|
2010-06-23 10:08:56 -07:00
|
|
|
// figcaption
|
|
|
|
#define GROUP_FIGCAPTION (1 << 23)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define GROUP_INLINE_ELEMENT \
|
|
|
|
(GROUP_FONTSTYLE | GROUP_PHRASE | GROUP_SPECIAL | GROUP_FORMCONTROL | \
|
|
|
|
GROUP_LEAF)
|
|
|
|
|
|
|
|
#define GROUP_FLOW_ELEMENT (GROUP_INLINE_ELEMENT | GROUP_BLOCK)
|
|
|
|
|
|
|
|
struct nsElementInfo
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
eHTMLTags mTag;
|
|
|
|
#endif
|
|
|
|
PRUint32 mGroup;
|
|
|
|
PRUint32 mCanContainGroups;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsContainer;
|
|
|
|
bool mCanContainSelf;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define ELEM(_tag, _isContainer, _canContainSelf, _group, _canContainGroups) \
|
|
|
|
{ eHTMLTag_##_tag, _group, _canContainGroups, _isContainer, _canContainSelf }
|
|
|
|
#else
|
|
|
|
#define ELEM(_tag, _isContainer, _canContainSelf, _group, _canContainGroups) \
|
|
|
|
{ _group, _canContainGroups, _isContainer, _canContainSelf }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const nsElementInfo kElements[eHTMLTag_userdefined] = {
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(a, true, false, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(abbr, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(acronym, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(address, true, true, GROUP_BLOCK,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_INLINE_ELEMENT | GROUP_P),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(applet, true, true, GROUP_SPECIAL | GROUP_BLOCK,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_FLOW_ELEMENT | GROUP_OBJECT_CONTENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(area, false, false, GROUP_MAP_CONTENT, GROUP_NONE),
|
|
|
|
ELEM(article, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(aside, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
2008-07-09 01:22:20 -07:00
|
|
|
#if defined(MOZ_MEDIA)
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(audio, false, false, GROUP_NONE, GROUP_NONE),
|
2008-07-09 01:22:20 -07:00
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(b, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(base, false, false, GROUP_HEAD_CONTENT, GROUP_NONE),
|
|
|
|
ELEM(basefont, false, false, GROUP_SPECIAL, GROUP_NONE),
|
|
|
|
ELEM(bdo, true, true, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(bgsound, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(big, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(blink, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(blockquote, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(body, true, true, GROUP_TOPLEVEL, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(br, false, false, GROUP_SPECIAL, GROUP_NONE),
|
|
|
|
ELEM(button, true, true, GROUP_FORMCONTROL | GROUP_BLOCK,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_FLOW_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(canvas, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(caption, true, true, GROUP_NONE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(center, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(cite, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(code, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(col, false, false, GROUP_TABLE_CONTENT | GROUP_COLGROUP_CONTENT,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_NONE),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(colgroup, true, false, GROUP_NONE, GROUP_COLGROUP_CONTENT),
|
|
|
|
ELEM(datalist, true, false, GROUP_PHRASE,
|
2010-09-09 22:16:56 -07:00
|
|
|
GROUP_OPTIONS | GROUP_INLINE_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(dd, true, false, GROUP_DL_CONTENT, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(del, true, true, GROUP_PHRASE | GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(dfn, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(dir, true, false, GROUP_BLOCK, GROUP_LI),
|
|
|
|
ELEM(div, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(dl, true, false, GROUP_BLOCK, GROUP_DL_CONTENT),
|
|
|
|
ELEM(dt, true, true, GROUP_DL_CONTENT, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(em, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(embed, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(fieldset, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(figcaption, true, false, GROUP_FIGCAPTION, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(figure, true, true, GROUP_BLOCK,
|
2010-06-23 10:08:56 -07:00
|
|
|
GROUP_FLOW_ELEMENT | GROUP_FIGCAPTION),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(font, true, true, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(footer, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(form, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(frame, false, false, GROUP_FRAME, GROUP_NONE),
|
|
|
|
ELEM(frameset, true, true, GROUP_FRAME, GROUP_FRAME),
|
|
|
|
ELEM(h1, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 11:44:43 -07:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(h2, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 11:44:43 -07:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(h3, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 11:44:43 -07:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(h4, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 11:44:43 -07:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(h5, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 11:44:43 -07:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(h6, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 11:44:43 -07:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(head, true, false, GROUP_TOPLEVEL, GROUP_HEAD_CONTENT),
|
|
|
|
ELEM(header, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(hgroup, true, false, GROUP_BLOCK, GROUP_HEADING),
|
|
|
|
ELEM(hr, false, false, GROUP_BLOCK, GROUP_NONE),
|
|
|
|
ELEM(html, true, false, GROUP_TOPLEVEL, GROUP_TOPLEVEL),
|
|
|
|
ELEM(i, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(iframe, true, true, GROUP_SPECIAL | GROUP_BLOCK,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_FLOW_ELEMENT),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(image, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(img, false, false, GROUP_SPECIAL, GROUP_NONE),
|
|
|
|
ELEM(input, false, false, GROUP_FORMCONTROL, GROUP_NONE),
|
|
|
|
ELEM(ins, true, true, GROUP_PHRASE | GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(kbd, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(keygen, false, false, GROUP_FORMCONTROL, GROUP_NONE),
|
|
|
|
ELEM(label, true, false, GROUP_FORMCONTROL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(legend, true, true, GROUP_NONE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(li, true, false, GROUP_LI, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(link, false, false, GROUP_HEAD_CONTENT, GROUP_NONE),
|
|
|
|
ELEM(listing, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(map, true, true, GROUP_SPECIAL, GROUP_BLOCK | GROUP_MAP_CONTENT),
|
|
|
|
ELEM(mark, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(marquee, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(menu, true, true, GROUP_BLOCK, GROUP_LI | GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(menuitem, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(meta, false, false, GROUP_HEAD_CONTENT, GROUP_NONE),
|
|
|
|
ELEM(multicol, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(nav, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(nobr, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(noembed, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(noframes, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(noscript, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(object, true, true, GROUP_SPECIAL | GROUP_BLOCK,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_FLOW_ELEMENT | GROUP_OBJECT_CONTENT),
|
|
|
|
// XXX Can contain self and ul because editor does sublists illegally.
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(ol, true, true, GROUP_BLOCK | GROUP_OL_UL,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_LI | GROUP_OL_UL),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(optgroup, true, false, GROUP_SELECT_CONTENT,
|
2010-09-09 22:16:56 -07:00
|
|
|
GROUP_OPTIONS),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(option, true, false,
|
2010-09-09 22:16:56 -07:00
|
|
|
GROUP_SELECT_CONTENT | GROUP_OPTIONS, GROUP_LEAF),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(output, true, true, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(p, true, false, GROUP_BLOCK | GROUP_P, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(param, false, false, GROUP_OBJECT_CONTENT, GROUP_NONE),
|
|
|
|
ELEM(plaintext, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(pre, true, true, GROUP_BLOCK, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(progress, true, false, GROUP_SPECIAL, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(q, true, true, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(s, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(samp, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(script, true, false, GROUP_HEAD_CONTENT | GROUP_SPECIAL,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_LEAF),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(section, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(select, true, false, GROUP_FORMCONTROL, GROUP_SELECT_CONTENT),
|
|
|
|
ELEM(small, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
2008-07-09 01:22:20 -07:00
|
|
|
#if defined(MOZ_MEDIA)
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(source, false, false, GROUP_NONE, GROUP_NONE),
|
2008-07-09 01:22:20 -07:00
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(span, true, true, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(strike, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(strong, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(style, true, false, GROUP_HEAD_CONTENT, GROUP_LEAF),
|
|
|
|
ELEM(sub, true, true, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(sup, true, true, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(table, true, false, GROUP_BLOCK, GROUP_TABLE_CONTENT),
|
|
|
|
ELEM(tbody, true, false, GROUP_TABLE_CONTENT, GROUP_TBODY_CONTENT),
|
|
|
|
ELEM(td, true, false, GROUP_TR_CONTENT, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(textarea, true, false, GROUP_FORMCONTROL, GROUP_LEAF),
|
|
|
|
ELEM(tfoot, true, false, GROUP_NONE, GROUP_TBODY_CONTENT),
|
|
|
|
ELEM(th, true, false, GROUP_TR_CONTENT, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(thead, true, false, GROUP_NONE, GROUP_TBODY_CONTENT),
|
|
|
|
ELEM(title, true, false, GROUP_HEAD_CONTENT, GROUP_LEAF),
|
|
|
|
ELEM(tr, true, false, GROUP_TBODY_CONTENT, GROUP_TR_CONTENT),
|
|
|
|
ELEM(tt, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(u, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX Can contain self and ol because editor does sublists illegally.
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(ul, true, true, GROUP_BLOCK | GROUP_OL_UL,
|
2007-03-22 10:30:00 -07:00
|
|
|
GROUP_LI | GROUP_OL_UL),
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(var, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
2008-07-09 01:22:20 -07:00
|
|
|
#if defined(MOZ_MEDIA)
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(video, false, false, GROUP_NONE, GROUP_NONE),
|
2008-07-09 01:22:20 -07:00
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(wbr, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(xmp, false, false, GROUP_NONE, GROUP_NONE),
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// These aren't elements.
|
2011-10-17 07:59:28 -07:00
|
|
|
ELEM(text, false, false, GROUP_LEAF, GROUP_NONE),
|
|
|
|
ELEM(whitespace, false, false, GROUP_LEAF, GROUP_NONE),
|
|
|
|
ELEM(newline, false, false, GROUP_LEAF, GROUP_NONE),
|
|
|
|
ELEM(comment, false, false, GROUP_LEAF, GROUP_NONE),
|
|
|
|
ELEM(entity, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(doctypeDecl, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(markupDecl, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(instruction, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
|
|
|
|
ELEM(userdefined, true, false, GROUP_NONE, GROUP_FLOW_ELEMENT)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::CanContain(PRInt32 aParent, PRInt32 aChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aParent > eHTMLTag_unknown && aParent <= eHTMLTag_userdefined,
|
|
|
|
"aParent out of range!");
|
|
|
|
NS_ASSERTION(aChild > eHTMLTag_unknown && aChild <= eHTMLTag_userdefined,
|
|
|
|
"aChild out of range!");
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool checked = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!checked) {
|
2011-10-17 07:59:28 -07:00
|
|
|
checked = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = 1; i <= eHTMLTag_userdefined; ++i) {
|
|
|
|
NS_ASSERTION(kElements[i - 1].mTag == i,
|
|
|
|
"You need to update kElements (missing tags).");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Special-case button.
|
|
|
|
if (aParent == eHTMLTag_button) {
|
|
|
|
static const eHTMLTags kButtonExcludeKids[] = {
|
|
|
|
eHTMLTag_a,
|
|
|
|
eHTMLTag_fieldset,
|
|
|
|
eHTMLTag_form,
|
|
|
|
eHTMLTag_iframe,
|
|
|
|
eHTMLTag_input,
|
|
|
|
eHTMLTag_select,
|
|
|
|
eHTMLTag_textarea
|
|
|
|
};
|
|
|
|
|
|
|
|
PRUint32 j;
|
2011-10-10 22:50:08 -07:00
|
|
|
for (j = 0; j < ArrayLength(kButtonExcludeKids); ++j) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (kButtonExcludeKids[j] == aChild) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated elements.
|
2010-10-21 14:12:49 -07:00
|
|
|
if (aChild == eHTMLTag_bgsound) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bug #67007, dont strip userdefined tags.
|
|
|
|
if (aChild == eHTMLTag_userdefined) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsElementInfo& parent = kElements[aParent - 1];
|
|
|
|
if (aParent == aChild) {
|
|
|
|
return parent.mCanContainSelf;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsElementInfo& child = kElements[aChild - 1];
|
|
|
|
return (parent.mCanContainGroups & child.mGroup) != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLEditUtils::IsContainer(PRInt32 aTag)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aTag > eHTMLTag_unknown && aTag <= eHTMLTag_userdefined,
|
|
|
|
"aTag out of range!");
|
|
|
|
|
|
|
|
return kElements[aTag - 1].mIsContainer;
|
|
|
|
}
|