Bug 1121473, define the list of void tags only in one place, r=hsivonen

This commit is contained in:
Olli Pettay 2015-01-19 13:17:22 +02:00
parent dc1ab061e4
commit 63728de068
5 changed files with 26 additions and 42 deletions

View File

@ -2548,12 +2548,8 @@ ShouldEscape(nsIContent* aParent)
}
static inline bool
IsVoidTag(Element* aElement)
IsVoidTag(nsIAtom* aTag)
{
if (!aElement->IsHTML()) {
return false;
}
static const nsIAtom* voidElements[] = {
nsGkAtoms::area, nsGkAtoms::base, nsGkAtoms::basefont,
nsGkAtoms::bgsound, nsGkAtoms::br, nsGkAtoms::col,
@ -2572,11 +2568,10 @@ IsVoidTag(Element* aElement)
sFilter.add(voidElements[i]);
}
}
nsIAtom* tag = aElement->Tag();
if (sFilter.mightContain(tag)) {
if (sFilter.mightContain(aTag)) {
for (uint32_t i = 0; i < ArrayLength(voidElements); ++i) {
if (tag == voidElements[i]) {
if (aTag == voidElements[i]) {
return true;
}
}
@ -2584,6 +2579,22 @@ IsVoidTag(Element* aElement)
return false;
}
static inline bool
IsVoidTag(Element* aElement)
{
if (!aElement->IsHTML()) {
return false;
}
return IsVoidTag(aElement->Tag());
}
/* static */
bool
FragmentOrElement::IsHTMLVoid(nsIAtom* aLocalName)
{
return aLocalName && IsVoidTag(aLocalName);
}
static bool
Serialize(FragmentOrElement* aRoot, bool aDescendentsOnly, nsAString& aOut)
{

View File

@ -269,6 +269,10 @@ public:
static void MarkUserData(void* aObject, nsIAtom* aKey, void* aChild,
void *aData);
/**
* Is the HTML local name a void element?
*/
static bool IsHTMLVoid(nsIAtom* aLocalName);
protected:
virtual ~FragmentOrElement();

View File

@ -1543,32 +1543,6 @@ nsContentUtils::IsHTMLBlock(nsIAtom* aLocalName)
(aLocalName == nsGkAtoms::xmp);
}
/* static */
bool
nsContentUtils::IsHTMLVoid(nsIAtom* aLocalName)
{
return
(aLocalName == nsGkAtoms::area) ||
(aLocalName == nsGkAtoms::base) ||
(aLocalName == nsGkAtoms::basefont) ||
(aLocalName == nsGkAtoms::bgsound) ||
(aLocalName == nsGkAtoms::br) ||
(aLocalName == nsGkAtoms::col) ||
(aLocalName == nsGkAtoms::command) ||
(aLocalName == nsGkAtoms::embed) ||
(aLocalName == nsGkAtoms::frame) ||
(aLocalName == nsGkAtoms::hr) ||
(aLocalName == nsGkAtoms::img) ||
(aLocalName == nsGkAtoms::input) ||
(aLocalName == nsGkAtoms::keygen) ||
(aLocalName == nsGkAtoms::link) ||
(aLocalName == nsGkAtoms::meta) ||
(aLocalName == nsGkAtoms::param) ||
(aLocalName == nsGkAtoms::source) ||
(aLocalName == nsGkAtoms::track) ||
(aLocalName == nsGkAtoms::wbr);
}
/* static */
bool
nsContentUtils::ParseIntMarginValue(const nsAString& aString, nsIntMargin& result)

View File

@ -363,11 +363,6 @@ public:
*/
static bool IsHTMLBlock(nsIAtom* aLocalName);
/**
* Is the HTML local name a void element?
*/
static bool IsHTMLVoid(nsIAtom* aLocalName);
enum ParseHTMLIntegerResultFlags {
eParseHTMLInteger_NoFlags = 0,
eParseHTMLInteger_IsPercent = 1 << 0,

View File

@ -351,7 +351,7 @@ nsPlainTextSerializer::AppendElementStart(Element* aElement,
nsresult rv;
nsIAtom* id = GetIdForContent(mElement);
bool isContainer = !nsContentUtils::IsHTMLVoid(id);
bool isContainer = !FragmentOrElement::IsHTMLVoid(id);
mOutputString = &aStr;
@ -384,7 +384,7 @@ nsPlainTextSerializer::AppendElementEnd(Element* aElement,
nsresult rv;
nsIAtom* id = GetIdForContent(mElement);
bool isContainer = !nsContentUtils::IsHTMLVoid(id);
bool isContainer = !FragmentOrElement::IsHTMLVoid(id);
mOutputString = &aStr;