2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-01-26 00:36:18 +00:00
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
#include "HTMLEditUtils.h"
|
2014-12-02 05:07:42 +00:00
|
|
|
|
2016-07-07 04:44:32 +00:00
|
|
|
#include "TextEditUtils.h" // for TextEditUtils
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h" // for ArrayLength
|
2016-07-08 05:15:21 +00:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc.
|
2016-07-08 04:10:13 +00:00
|
|
|
#include "mozilla/EditorBase.h" // for EditorBase
|
2012-07-27 14:03:28 +00:00
|
|
|
#include "mozilla/dom/Element.h" // for Element, nsINode
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsAString.h" // for nsAString_internal::IsEmpty
|
2016-07-08 05:15:21 +00:00
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr, operator==, etc.
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsCaseTreatment.h"
|
2016-07-08 05:15:21 +00:00
|
|
|
#include "nsDebug.h" // for NS_PRECONDITION, etc.
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsError.h" // for NS_SUCCEEDED
|
2016-07-08 05:15:21 +00:00
|
|
|
#include "nsGkAtoms.h" // for nsGkAtoms, nsGkAtoms::a, etc.
|
2005-09-05 14:18:56 +00:00
|
|
|
#include "nsHTMLTags.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsIAtom.h" // for nsIAtom
|
|
|
|
#include "nsIDOMHTMLAnchorElement.h" // for nsIDOMHTMLAnchorElement
|
|
|
|
#include "nsIDOMNode.h" // for nsIDOMNode
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h" // for kNameSpaceID_None
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsLiteralString.h" // for NS_LITERAL_STRING
|
|
|
|
#include "nsString.h" // for nsAutoString
|
2000-01-26 00:36:18 +00:00
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
namespace mozilla {
|
2011-10-11 05:50:08 +00:00
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsInlineStyle() returns true if aNode is an inline style.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsInlineStyle(nsIDOMNode* aNode)
|
2003-07-28 20:31:08 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsInlineStyle(node);
|
2012-05-05 09:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsInlineStyle(nsINode* aNode)
|
2012-05-05 09:00:06 +00:00
|
|
|
{
|
2012-07-27 14:03:28 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::b,
|
|
|
|
nsGkAtoms::i,
|
|
|
|
nsGkAtoms::u,
|
|
|
|
nsGkAtoms::tt,
|
|
|
|
nsGkAtoms::s,
|
|
|
|
nsGkAtoms::strike,
|
|
|
|
nsGkAtoms::big,
|
|
|
|
nsGkAtoms::small,
|
|
|
|
nsGkAtoms::sub,
|
|
|
|
nsGkAtoms::sup,
|
|
|
|
nsGkAtoms::font);
|
2003-07-28 20:31:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsFormatNode() returns true if aNode is a format node.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsFormatNode(nsIDOMNode* aNode)
|
2003-07-28 20:31:08 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsFormatNode(node);
|
2012-05-05 09:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsFormatNode(nsINode* aNode)
|
2012-05-05 09:00:06 +00:00
|
|
|
{
|
2012-07-27 14:03:28 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::p,
|
|
|
|
nsGkAtoms::pre,
|
|
|
|
nsGkAtoms::h1,
|
|
|
|
nsGkAtoms::h2,
|
|
|
|
nsGkAtoms::h3,
|
|
|
|
nsGkAtoms::h4,
|
|
|
|
nsGkAtoms::h5,
|
|
|
|
nsGkAtoms::h6,
|
|
|
|
nsGkAtoms::address);
|
2003-07-28 20:31:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsNodeThatCanOutdent() returns true if aNode is a list, list item or
|
|
|
|
* blockquote.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsNodeThatCanOutdent(nsIDOMNode* aNode)
|
2003-07-28 20:31:08 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2016-07-08 04:10:13 +00:00
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = EditorBase::GetTag(aNode);
|
2014-08-29 11:43:24 +00:00
|
|
|
return (nodeAtom == nsGkAtoms::ul)
|
|
|
|
|| (nodeAtom == nsGkAtoms::ol)
|
|
|
|
|| (nodeAtom == nsGkAtoms::dl)
|
|
|
|
|| (nodeAtom == nsGkAtoms::li)
|
|
|
|
|| (nodeAtom == nsGkAtoms::dd)
|
|
|
|
|| (nodeAtom == nsGkAtoms::dt)
|
|
|
|
|| (nodeAtom == nsGkAtoms::blockquote);
|
2003-07-28 20:31:08 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsHeader() returns true if aNode is an html header.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsHeader(nsINode& aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode.IsAnyOfHTMLElements(nsGkAtoms::h1,
|
|
|
|
nsGkAtoms::h2,
|
|
|
|
nsGkAtoms::h3,
|
|
|
|
nsGkAtoms::h4,
|
|
|
|
nsGkAtoms::h5,
|
|
|
|
nsGkAtoms::h6);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2014-11-02 12:04:14 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsHeader(nsIDOMNode* aNode)
|
2014-11-02 12:04:14 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2014-11-02 12:04:14 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(node);
|
2014-11-02 12:04:14 +00:00
|
|
|
return IsHeader(*node);
|
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsParagraph() returns true if aNode is an html paragraph.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsParagraph(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::p);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsHR() returns true if aNode is an horizontal rule.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsHR(nsIDOMNode* aNode)
|
2001-12-11 22:22:47 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::hr);
|
2001-12-11 22:22:47 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsListItem() returns true if aNode is an html list item.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsListItem(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsListItem(node);
|
2012-01-25 07:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsListItem(nsINode* aNode)
|
2012-01-25 07:50:05 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::li,
|
|
|
|
nsGkAtoms::dd,
|
|
|
|
nsGkAtoms::dt);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsTableElement() returns true if aNode is an html table, td, tr, ...
|
|
|
|
*/
|
2012-02-01 10:54:22 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableElement(nsIDOMNode* aNode)
|
2000-08-13 23:53:34 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsTableElement(node);
|
2012-02-01 10:54:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableElement(nsINode* aNode)
|
2012-02-01 10:54:22 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::table,
|
|
|
|
nsGkAtoms::tr,
|
|
|
|
nsGkAtoms::td,
|
|
|
|
nsGkAtoms::th,
|
|
|
|
nsGkAtoms::thead,
|
|
|
|
nsGkAtoms::tfoot,
|
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::caption);
|
2000-08-13 23:53:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsTableElementButNotTable() returns true if aNode is an html td, tr, ...
|
|
|
|
* (doesn't include table)
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableElementButNotTable(nsIDOMNode* aNode)
|
2003-07-28 20:31:08 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsTableElementButNotTable(node);
|
2012-05-18 08:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableElementButNotTable(nsINode* aNode)
|
2012-05-18 08:29:39 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::tr,
|
|
|
|
nsGkAtoms::td,
|
|
|
|
nsGkAtoms::th,
|
|
|
|
nsGkAtoms::thead,
|
|
|
|
nsGkAtoms::tfoot,
|
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::caption);
|
2003-07-28 20:31:08 +00:00
|
|
|
}
|
2000-08-13 23:53:34 +00:00
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsTable() returns true if aNode is an html table.
|
|
|
|
*/
|
2014-04-28 11:54:46 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTable(nsIDOMNode* aNode)
|
2000-03-21 06:05:24 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::table);
|
2000-03-21 06:05:24 +00:00
|
|
|
}
|
|
|
|
|
2014-04-28 11:54:46 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTable(nsINode* aNode)
|
2014-04-28 11:54:46 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode && aNode->IsHTMLElement(nsGkAtoms::table);
|
2014-04-28 11:54:46 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsTableRow() returns true if aNode is an html tr.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableRow(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::tr);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsTableCell() returns true if aNode is an html td or th.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableCell(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsTableCell(node);
|
2012-01-25 07:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableCell(nsINode* aNode)
|
2012-01-25 07:50:05 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsTableCellOrCaption() returns true if aNode is an html td or th or caption.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsTableCellOrCaption(nsINode& aNode)
|
2000-08-13 23:53:34 +00:00
|
|
|
{
|
2016-05-01 13:10:39 +00:00
|
|
|
return aNode.IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th,
|
|
|
|
nsGkAtoms::caption);
|
2000-08-13 23:53:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsList() returns true if aNode is an html list.
|
|
|
|
*/
|
2012-01-25 07:50:05 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsList(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsList(node);
|
2012-01-25 07:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsList(nsINode* aNode)
|
2012-01-25 07:50:05 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::ul,
|
|
|
|
nsGkAtoms::ol,
|
|
|
|
nsGkAtoms::dl);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsOrderedList() returns true if aNode is an html ordered list.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsOrderedList(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::ol);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsUnorderedList() returns true if aNode is an html unordered list.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsUnorderedList(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::ul);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsBlockquote() returns true if aNode is an html blockquote node.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsBlockquote(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::blockquote);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsPre() returns true if aNode is an html pre node.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsPre(nsIDOMNode* aNode)
|
2000-02-25 04:39:30 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::pre);
|
2000-02-25 04:39:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsImage() returns true if aNode is an html image node.
|
|
|
|
*/
|
2014-11-02 12:04:13 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsImage(nsINode* aNode)
|
2014-11-02 12:04:13 +00:00
|
|
|
{
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode && aNode->IsHTMLElement(nsGkAtoms::img);
|
2014-11-02 12:04:13 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsImage(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::img);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsLink(nsIDOMNode *aNode)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2014-04-28 11:54:46 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsLink(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsLink(nsINode* aNode)
|
2014-04-28 11:54:46 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
|
2001-01-28 20:13:07 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
|
2016-10-24 02:27:45 +00:00
|
|
|
if (anchor) {
|
2001-01-28 20:13:07 +00:00
|
|
|
nsAutoString tmpText;
|
2014-04-28 11:54:46 +00:00
|
|
|
if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && !tmpText.IsEmpty()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2014-04-28 11:54:46 +00:00
|
|
|
}
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsNamedAnchor(nsIDOMNode *aNode)
|
2001-01-28 20:13:07 +00:00
|
|
|
{
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsNamedAnchor(node);
|
2012-01-25 07:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsNamedAnchor(nsINode* aNode)
|
2012-01-25 07:50:05 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
if (!aNode->IsHTMLElement(nsGkAtoms::a)) {
|
2012-01-25 07:50:05 +00:00
|
|
|
return false;
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
2012-01-25 07:50:05 +00:00
|
|
|
|
|
|
|
nsAutoString text;
|
2012-07-27 14:03:28 +00:00
|
|
|
return aNode->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
text) && !text.IsEmpty();
|
2001-01-28 20:13:07 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsDiv() returns true if aNode is an html div node.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsDiv(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
return EditorBase::NodeIsType(aNode, nsGkAtoms::div);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsMozDiv() returns true if aNode is an html div node with |type = _moz|.
|
|
|
|
*/
|
2015-05-28 15:58:42 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsMozDiv(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-07 04:44:32 +00:00
|
|
|
return IsDiv(aNode) && TextEditUtils::HasMozAttr(aNode);
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 12:25:16 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsMozDiv(nsINode* aNode)
|
2014-08-20 12:25:16 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode->IsHTMLElement(nsGkAtoms::div) &&
|
2016-07-07 04:44:32 +00:00
|
|
|
TextEditUtils::HasMozAttr(GetAsDOMNode(aNode));
|
2014-08-20 12:25:16 +00:00
|
|
|
}
|
2000-01-26 00:36:18 +00:00
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsMailCite() returns true if aNode is an html blockquote with |type=cite|.
|
|
|
|
*/
|
2012-05-05 09:00:06 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsMailCite(nsIDOMNode* aNode)
|
2000-01-26 00:36:18 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsMailCite(node);
|
2012-05-05 09:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsMailCite(nsINode* aNode)
|
2012-05-05 09:00:06 +00:00
|
|
|
{
|
2012-07-27 14:03:28 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-05-05 09:00:06 +00:00
|
|
|
|
2001-12-12 06:02:15 +00:00
|
|
|
// don't ask me why, but our html mailcites are id'd by "type=cite"...
|
2012-07-27 14:03:28 +00:00
|
|
|
if (aNode->IsElement() &&
|
|
|
|
aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("cite"),
|
|
|
|
eIgnoreCase)) {
|
2012-05-05 09:00:06 +00:00
|
|
|
return true;
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
2001-12-12 06:02:15 +00:00
|
|
|
|
|
|
|
// ... but our plaintext mailcites by "_moz_quote=true". go figure.
|
2012-07-27 14:03:28 +00:00
|
|
|
if (aNode->IsElement() &&
|
|
|
|
aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozquote,
|
|
|
|
NS_LITERAL_STRING("true"),
|
|
|
|
eIgnoreCase)) {
|
2012-05-05 09:00:06 +00:00
|
|
|
return true;
|
2001-12-12 06:02:15 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-01-26 00:36:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
/**
|
|
|
|
* IsFormWidget() returns true if aNode is a form widget of some kind.
|
|
|
|
*/
|
2012-01-25 07:50:05 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsFormWidget(nsIDOMNode* aNode)
|
2001-12-12 06:02:15 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2012-07-27 14:03:28 +00:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
|
|
|
return node && IsFormWidget(node);
|
2012-01-25 07:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsFormWidget(nsINode* aNode)
|
2012-01-25 07:50:05 +00:00
|
|
|
{
|
2012-07-27 14:03:28 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2015-03-03 11:08:59 +00:00
|
|
|
return aNode->IsAnyOfHTMLElements(nsGkAtoms::textarea,
|
|
|
|
nsGkAtoms::select,
|
|
|
|
nsGkAtoms::button,
|
|
|
|
nsGkAtoms::output,
|
|
|
|
nsGkAtoms::keygen,
|
|
|
|
nsGkAtoms::progress,
|
|
|
|
nsGkAtoms::meter,
|
|
|
|
nsGkAtoms::input);
|
2001-12-12 06:02:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::SupportsAlignAttr(nsIDOMNode* aNode)
|
2001-10-09 10:00:33 +00:00
|
|
|
{
|
2016-07-07 05:01:12 +00:00
|
|
|
MOZ_ASSERT(aNode);
|
2016-07-08 04:10:13 +00:00
|
|
|
nsCOMPtr<nsIAtom> nodeAtom = EditorBase::GetTag(aNode);
|
2014-08-29 11:43:24 +00:00
|
|
|
return (nodeAtom == nsGkAtoms::hr)
|
|
|
|
|| (nodeAtom == nsGkAtoms::table)
|
|
|
|
|| (nodeAtom == nsGkAtoms::tbody)
|
|
|
|
|| (nodeAtom == nsGkAtoms::tfoot)
|
|
|
|
|| (nodeAtom == nsGkAtoms::thead)
|
|
|
|
|| (nodeAtom == nsGkAtoms::tr)
|
|
|
|
|| (nodeAtom == nsGkAtoms::td)
|
|
|
|
|| (nodeAtom == nsGkAtoms::th)
|
|
|
|
|| (nodeAtom == nsGkAtoms::div)
|
|
|
|
|| (nodeAtom == nsGkAtoms::p)
|
|
|
|
|| (nodeAtom == nsGkAtoms::h1)
|
|
|
|
|| (nodeAtom == nsGkAtoms::h2)
|
|
|
|
|| (nodeAtom == nsGkAtoms::h3)
|
|
|
|
|| (nodeAtom == nsGkAtoms::h4)
|
|
|
|
|| (nodeAtom == nsGkAtoms::h5)
|
|
|
|
|| (nodeAtom == nsGkAtoms::h6);
|
2001-10-09 10:00:33 +00:00
|
|
|
}
|
2005-09-05 14:18:56 +00:00
|
|
|
|
|
|
|
// 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
|
2014-05-21 20:12:07 +00:00
|
|
|
#define GROUP_TOPLEVEL (1 << 1)
|
2005-09-05 14:18:56 +00:00
|
|
|
|
2011-07-23 09:45:38 +00:00
|
|
|
// base, link, meta, script, style, title
|
2005-09-05 14:18:56 +00:00
|
|
|
#define GROUP_HEAD_CONTENT (1 << 2)
|
|
|
|
|
|
|
|
// b, big, i, s, small, strike, tt, u
|
|
|
|
#define GROUP_FONTSTYLE (1 << 3)
|
|
|
|
|
2014-06-21 00:08:31 +00:00
|
|
|
// abbr, acronym, cite, code, datalist, del, dfn, em, ins, kbd, mark, rb, rp
|
|
|
|
// rt, rtc, ruby, samp, strong, var
|
2005-09-05 14:18:56 +00:00
|
|
|
#define GROUP_PHRASE (1 << 4)
|
|
|
|
|
2012-05-16 11:18:33 +00:00
|
|
|
// a, applet, basefont, bdo, br, font, iframe, img, map, meter, object, output,
|
2014-05-21 20:12:07 +00:00
|
|
|
// picture, progress, q, script, span, sub, sup
|
2005-09-05 14:18:56 +00:00
|
|
|
#define GROUP_SPECIAL (1 << 5)
|
|
|
|
|
|
|
|
// button, form, input, label, select, textarea
|
|
|
|
#define GROUP_FORMCONTROL (1 << 6)
|
|
|
|
|
2016-01-20 15:20:40 +00:00
|
|
|
// address, applet, article, aside, blockquote, button, center, del, details,
|
2016-12-23 15:01:50 +00:00
|
|
|
// dialog, dir, div, dl, fieldset, figure, footer, form, h1, h2, h3, h4, h5,
|
|
|
|
// h6, header, hgroup, hr, iframe, ins, main, map, menu, nav, noframes,
|
|
|
|
// noscript, object, ol, p, pre, table, section, summary, ul
|
2005-09-05 14:18:56 +00: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-10 05:16:56 +00:00
|
|
|
#define GROUP_OPTIONS (1 << 17)
|
2005-09-05 14:18:56 +00:00
|
|
|
|
|
|
|
// dd, dt
|
|
|
|
#define GROUP_DL_CONTENT (1 << 18)
|
|
|
|
|
|
|
|
// p
|
|
|
|
#define GROUP_P (1 << 19)
|
|
|
|
|
|
|
|
// text, whitespace, newline, comment
|
|
|
|
#define GROUP_LEAF (1 << 20)
|
|
|
|
|
2014-05-21 20:12:07 +00:00
|
|
|
// XXX This is because the editor does sublists illegally.
|
2005-09-05 14:18:56 +00:00
|
|
|
// ol, ul
|
|
|
|
#define GROUP_OL_UL (1 << 21)
|
|
|
|
|
2010-06-19 18:44:43 +00:00
|
|
|
// h1, h2, h3, h4, h5, h6
|
|
|
|
#define GROUP_HEADING (1 << 22)
|
|
|
|
|
2010-06-23 17:08:56 +00:00
|
|
|
// figcaption
|
|
|
|
#define GROUP_FIGCAPTION (1 << 23)
|
|
|
|
|
2014-05-21 20:12:07 +00:00
|
|
|
// picture members (img, source)
|
|
|
|
#define GROUP_PICTURE_CONTENT (1 << 24)
|
|
|
|
|
2005-09-05 14:18:56 +00:00
|
|
|
#define GROUP_INLINE_ELEMENT \
|
|
|
|
(GROUP_FONTSTYLE | GROUP_PHRASE | GROUP_SPECIAL | GROUP_FORMCONTROL | \
|
|
|
|
GROUP_LEAF)
|
|
|
|
|
|
|
|
#define GROUP_FLOW_ELEMENT (GROUP_INLINE_ELEMENT | GROUP_BLOCK)
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
struct ElementInfo final
|
2005-09-05 14:18:56 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
eHTMLTags mTag;
|
|
|
|
#endif
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mGroup;
|
|
|
|
uint32_t mCanContainGroups;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mIsContainer;
|
|
|
|
bool mCanContainSelf;
|
2005-09-05 14:18:56 +00: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
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
static const ElementInfo kElements[eHTMLTag_userdefined] = {
|
2011-10-17 14:59:28 +00: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,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_INLINE_ELEMENT | GROUP_P),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(applet, true, true, GROUP_SPECIAL | GROUP_BLOCK,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_FLOW_ELEMENT | GROUP_OBJECT_CONTENT),
|
2011-10-17 14:59:28 +00: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),
|
|
|
|
ELEM(audio, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
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(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,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_FLOW_ELEMENT),
|
2011-10-17 14:59:28 +00: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,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_NONE),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(colgroup, true, false, GROUP_NONE, GROUP_COLGROUP_CONTENT),
|
2013-12-02 10:26:12 +00:00
|
|
|
ELEM(content, true, false, GROUP_NONE, GROUP_INLINE_ELEMENT),
|
2013-02-26 20:19:05 +00:00
|
|
|
ELEM(data, true, false, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(datalist, true, false, GROUP_PHRASE,
|
2010-09-10 05:16:56 +00:00
|
|
|
GROUP_OPTIONS | GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(dd, true, false, GROUP_DL_CONTENT, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(del, true, true, GROUP_PHRASE | GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
2016-01-20 15:20:40 +00:00
|
|
|
ELEM(details, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(dfn, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
2016-12-23 15:01:50 +00:00
|
|
|
ELEM(dialog, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
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 17:08:56 +00:00
|
|
|
GROUP_FLOW_ELEMENT | GROUP_FIGCAPTION),
|
2011-10-17 14:59:28 +00: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 18:44:43 +00:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(h2, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 18:44:43 +00:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(h3, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 18:44:43 +00:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(h4, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 18:44:43 +00:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(h5, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 18:44:43 +00:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(h6, true, false, GROUP_BLOCK | GROUP_HEADING,
|
2010-06-19 18:44:43 +00:00
|
|
|
GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00: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,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_FLOW_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(image, false, false, GROUP_NONE, GROUP_NONE),
|
2014-05-21 20:12:07 +00:00
|
|
|
ELEM(img, false, false, GROUP_SPECIAL | GROUP_PICTURE_CONTENT, GROUP_NONE),
|
2011-10-17 14:59:28 +00:00
|
|
|
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),
|
2013-01-29 12:31:45 +00:00
|
|
|
ELEM(main, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
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),
|
2012-05-16 11:18:33 +00:00
|
|
|
ELEM(meter, true, false, GROUP_SPECIAL, GROUP_FLOW_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
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,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_FLOW_ELEMENT | GROUP_OBJECT_CONTENT),
|
|
|
|
// XXX Can contain self and ul because editor does sublists illegally.
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(ol, true, true, GROUP_BLOCK | GROUP_OL_UL,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_LI | GROUP_OL_UL),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(optgroup, true, false, GROUP_SELECT_CONTENT,
|
2010-09-10 05:16:56 +00:00
|
|
|
GROUP_OPTIONS),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(option, true, false,
|
2010-09-10 05:16:56 +00:00
|
|
|
GROUP_SELECT_CONTENT | GROUP_OPTIONS, GROUP_LEAF),
|
2011-10-17 14:59:28 +00: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),
|
2014-05-21 20:12:07 +00:00
|
|
|
ELEM(picture, true, false, GROUP_SPECIAL, GROUP_PICTURE_CONTENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
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),
|
2014-06-21 00:08:31 +00:00
|
|
|
ELEM(rb, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(rp, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(rt, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(rtc, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(ruby, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
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,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_LEAF),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(section, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
|
|
|
ELEM(select, true, false, GROUP_FORMCONTROL, GROUP_SELECT_CONTENT),
|
2013-12-21 06:43:58 +00:00
|
|
|
ELEM(shadow, true, false, GROUP_NONE, GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(small, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
2014-05-21 20:12:07 +00:00
|
|
|
ELEM(source, false, false, GROUP_PICTURE_CONTENT, GROUP_NONE),
|
2011-10-17 14:59:28 +00: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),
|
2016-01-20 15:20:40 +00:00
|
|
|
ELEM(summary, true, true, GROUP_BLOCK, GROUP_FLOW_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
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),
|
2013-03-26 07:15:23 +00:00
|
|
|
ELEM(template, false, false, GROUP_NONE, GROUP_NONE),
|
2013-02-22 15:07:42 +00:00
|
|
|
ELEM(time, true, false, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(title, true, false, GROUP_HEAD_CONTENT, GROUP_LEAF),
|
|
|
|
ELEM(tr, true, false, GROUP_TBODY_CONTENT, GROUP_TR_CONTENT),
|
2013-05-21 16:14:00 +00:00
|
|
|
ELEM(track, false, false, GROUP_NONE, GROUP_NONE),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(tt, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(u, true, true, GROUP_FONTSTYLE, GROUP_INLINE_ELEMENT),
|
2005-09-05 14:18:56 +00:00
|
|
|
// XXX Can contain self and ol because editor does sublists illegally.
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(ul, true, true, GROUP_BLOCK | GROUP_OL_UL,
|
2005-09-05 14:18:56 +00:00
|
|
|
GROUP_LI | GROUP_OL_UL),
|
2011-10-17 14:59:28 +00:00
|
|
|
ELEM(var, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
|
|
|
|
ELEM(video, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(wbr, false, false, GROUP_NONE, GROUP_NONE),
|
|
|
|
ELEM(xmp, false, false, GROUP_NONE, GROUP_NONE),
|
2005-09-05 14:18:56 +00:00
|
|
|
|
|
|
|
// These aren't elements.
|
2011-10-17 14:59:28 +00: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)
|
2005-09-05 14:18:56 +00:00
|
|
|
};
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::CanContain(int32_t aParent, int32_t aChild)
|
2005-09-05 14:18:56 +00:00
|
|
|
{
|
|
|
|
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-29 06:19:26 +00:00
|
|
|
static bool checked = false;
|
2005-09-05 14:18:56 +00:00
|
|
|
if (!checked) {
|
2011-10-17 14:59:28 +00:00
|
|
|
checked = true;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i;
|
2005-09-05 14:18:56 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t j;
|
2011-10-11 05:50:08 +00:00
|
|
|
for (j = 0; j < ArrayLength(kButtonExcludeKids); ++j) {
|
2005-09-05 14:18:56 +00:00
|
|
|
if (kButtonExcludeKids[j] == aChild) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-09-05 14:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated elements.
|
2010-10-21 21:12:49 +00:00
|
|
|
if (aChild == eHTMLTag_bgsound) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-09-05 14:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bug #67007, dont strip userdefined tags.
|
|
|
|
if (aChild == eHTMLTag_userdefined) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-09-05 14:18:56 +00:00
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
const ElementInfo& parent = kElements[aParent - 1];
|
2005-09-05 14:18:56 +00:00
|
|
|
if (aParent == aChild) {
|
|
|
|
return parent.mCanContainSelf;
|
|
|
|
}
|
|
|
|
|
2016-07-07 05:01:12 +00:00
|
|
|
const ElementInfo& child = kElements[aChild - 1];
|
2005-09-05 14:18:56 +00:00
|
|
|
return (parent.mCanContainGroups & child.mGroup) != 0;
|
2015-05-28 15:58:42 +00:00
|
|
|
}
|
2005-09-05 14:18:56 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2016-07-07 05:01:12 +00:00
|
|
|
HTMLEditUtils::IsContainer(int32_t aTag)
|
2005-09-05 14:18:56 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aTag > eHTMLTag_unknown && aTag <= eHTMLTag_userdefined,
|
|
|
|
"aTag out of range!");
|
|
|
|
|
|
|
|
return kElements[aTag - 1].mIsContainer;
|
|
|
|
}
|
2016-07-07 05:01:12 +00:00
|
|
|
|
|
|
|
} // namespace mozilla
|