summaryrefslogtreecommitdiffstats
path: root/WebCore/html/HTMLElementStack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/html/HTMLElementStack.cpp')
-rw-r--r--WebCore/html/HTMLElementStack.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/WebCore/html/HTMLElementStack.cpp b/WebCore/html/HTMLElementStack.cpp
index 2f1b792..d1a1752 100644
--- a/WebCore/html/HTMLElementStack.cpp
+++ b/WebCore/html/HTMLElementStack.cpp
@@ -62,6 +62,7 @@ inline bool isListItemScopeMarker(Element* element)
|| element->hasTagName(olTag)
|| element->hasTagName(ulTag);
}
+
inline bool isTableScopeMarker(Element* element)
{
return element->hasTagName(tableTag)
@@ -76,6 +77,12 @@ inline bool isTableBodyScopeMarker(Element* element)
|| element->hasTagName(htmlTag);
}
+inline bool isTableRowScopeMarker(Element* element)
+{
+ return element->hasTagName(trTag)
+ || element->hasTagName(htmlTag);
+}
+
}
HTMLElementStack::ElementRecord::ElementRecord(PassRefPtr<Element> element, PassOwnPtr<ElementRecord> next)
@@ -136,6 +143,12 @@ void HTMLElementStack::pop()
popCommon();
}
+void HTMLElementStack::popUntilElementWithNamespace(const AtomicString& namespaceURI)
+{
+ while (top()->namespaceURI() != namespaceURI)
+ pop();
+}
+
void HTMLElementStack::popUntil(const AtomicString& tagName)
{
while (!top()->hasLocalName(tagName)) {
@@ -145,12 +158,24 @@ void HTMLElementStack::popUntil(const AtomicString& tagName)
}
}
+void HTMLElementStack::popUntilPopped(const AtomicString& tagName)
+{
+ popUntil(tagName);
+ pop();
+}
+
void HTMLElementStack::popUntil(Element* element)
{
while (top() != element)
pop();
}
+void HTMLElementStack::popUntilPopped(Element* element)
+{
+ popUntil(element);
+ pop();
+}
+
void HTMLElementStack::popUntilTableScopeMarker()
{
// http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#clear-the-stack-back-to-a-table-context
@@ -165,6 +190,13 @@ void HTMLElementStack::popUntilTableBodyScopeMarker()
pop();
}
+void HTMLElementStack::popUntilTableRowScopeMarker()
+{
+ // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#clear-the-stack-back-to-a-table-row-context
+ while (!isTableRowScopeMarker(top()))
+ pop();
+}
+
void HTMLElementStack::pushHTMLHtmlElement(PassRefPtr<Element> element)
{
ASSERT(!m_top); // <html> should always be the bottom of the stack.
@@ -226,14 +258,24 @@ void HTMLElementStack::insertAbove(PassRefPtr<Element> element, ElementRecord* r
HTMLElementStack::ElementRecord* HTMLElementStack::topRecord() const
{
+ ASSERT(m_top);
return m_top.get();
}
Element* HTMLElementStack::top() const
{
+ ASSERT(m_top->element());
return m_top->element();
}
+Element* HTMLElementStack::oneBelowTop() const
+{
+ // We should never be calling this if it could be 0.
+ ASSERT(m_top);
+ ASSERT(m_top->next());
+ return m_top->next()->element();
+}
+
Element* HTMLElementStack::bottom() const
{
return htmlElement();
@@ -297,6 +339,19 @@ bool inScopeCommon(HTMLElementStack::ElementRecord* top, const AtomicString& tar
return false;
}
+bool HTMLElementStack::hasOnlyHTMLElementsInScope() const
+{
+ for (ElementRecord* record = m_top.get(); record; record = record->next()) {
+ Element* element = record->element();
+ if (element->namespaceURI() != xhtmlNamespaceURI)
+ return false;
+ if (isScopeMarker(element))
+ return true;
+ }
+ ASSERT_NOT_REACHED(); // <html> is always on the stack and is a scope marker.
+ return true;
+}
+
bool HTMLElementStack::inScope(Element* targetElement) const
{
for (ElementRecord* pos = m_top.get(); pos; pos = pos->next()) {
@@ -315,16 +370,34 @@ bool HTMLElementStack::inScope(const AtomicString& targetTag) const
return inScopeCommon<isScopeMarker>(m_top.get(), targetTag);
}
+bool HTMLElementStack::inScope(const QualifiedName& tagName) const
+{
+ // FIXME: Is localName() right for non-html elements?
+ return inScope(tagName.localName());
+}
+
bool HTMLElementStack::inListItemScope(const AtomicString& targetTag) const
{
return inScopeCommon<isListItemScopeMarker>(m_top.get(), targetTag);
}
+bool HTMLElementStack::inListItemScope(const QualifiedName& tagName) const
+{
+ // FIXME: Is localName() right for non-html elements?
+ return inListItemScope(tagName.localName());
+}
+
bool HTMLElementStack::inTableScope(const AtomicString& targetTag) const
{
return inScopeCommon<isTableScopeMarker>(m_top.get(), targetTag);
}
+bool HTMLElementStack::inTableScope(const QualifiedName& tagName) const
+{
+ // FIXME: Is localName() right for non-html elements?
+ return inTableScope(tagName.localName());
+}
+
Element* HTMLElementStack::htmlElement() const
{
ASSERT(m_htmlElement);
@@ -376,4 +449,14 @@ void HTMLElementStack::removeNonTopCommon(Element* element)
ASSERT_NOT_REACHED();
}
+#ifndef NDEBUG
+
+void HTMLElementStack::show()
+{
+ for (ElementRecord* record = m_top.get(); record; record = record->next())
+ record->element()->showNode();
+}
+
+#endif
+
}