summaryrefslogtreecommitdiff
path: root/Source/WebCore/html/HTMLStyleElement.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-02-03 09:55:33 +0100
committerSimon Hausmann <simon.hausmann@nokia.com>2012-02-03 09:55:33 +0100
commitcd44dc59cdfc39534aef4d417e9f3c412e3be139 (patch)
tree8d89889ba95ed6ec9322e733846cc9cce9d7dff1 /Source/WebCore/html/HTMLStyleElement.cpp
parentd11f84f5b5cdc0d92a08af01b13472fdd5f9acb9 (diff)
downloadqtwebkit-cd44dc59cdfc39534aef4d417e9f3c412e3be139.tar.gz
Imported WebKit commit fce473cb4d55aa9fe9d0b0322a2fffecb731b961 (http://svn.webkit.org/repository/webkit/trunk@106560)
Diffstat (limited to 'Source/WebCore/html/HTMLStyleElement.cpp')
-rw-r--r--Source/WebCore/html/HTMLStyleElement.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/Source/WebCore/html/HTMLStyleElement.cpp b/Source/WebCore/html/HTMLStyleElement.cpp
index 9efe80aa0..cc1fa2300 100644
--- a/Source/WebCore/html/HTMLStyleElement.cpp
+++ b/Source/WebCore/html/HTMLStyleElement.cpp
@@ -38,12 +38,17 @@ using namespace HTMLNames;
inline HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser)
: HTMLElement(tagName, document)
, StyleElement(document, createdByParser)
+#if ENABLE(STYLE_SCOPED)
+ , m_isRegisteredWithScopingNode(false)
+#endif
{
ASSERT(hasTagName(styleTag));
}
HTMLStyleElement::~HTMLStyleElement()
{
+ // During tear-down, willRemove isn't called, so m_isRegisteredWithScopingNode may still be set here.
+ // Therefore we can't ASSERT(!m_isRegisteredWithScopingNode).
StyleElement::clearDocumentData(document(), this);
}
@@ -56,6 +61,15 @@ void HTMLStyleElement::parseMappedAttribute(Attribute* attr)
{
if (attr->name() == titleAttr && m_sheet)
m_sheet->setTitle(attr->value());
+#if ENABLE(STYLE_SCOPED)
+ else if (attr->name() == scopedAttr) {
+ if (!attr->isNull() && !m_isRegisteredWithScopingNode && inDocument())
+ registerWithScopingNode();
+ else if (attr->isNull() && m_isRegisteredWithScopingNode)
+ unregisterWithScopingNode();
+
+ }
+#endif
else
HTMLElement::parseMappedAttribute(attr);
}
@@ -66,18 +80,82 @@ void HTMLStyleElement::finishParsingChildren()
HTMLElement::finishParsingChildren();
}
+#if ENABLE(STYLE_SCOPED)
+void HTMLStyleElement::registerWithScopingNode()
+{
+ // Note: We cannot rely on the 'scoped' element already being present when this method is invoked.
+ // Therefore we cannot rely on scoped()!
+ ASSERT(!m_isRegisteredWithScopingNode);
+ ASSERT(inDocument());
+ if (!m_isRegisteredWithScopingNode) {
+ Element* scope = parentElement();
+ if (!scope)
+ return;
+
+ scope->registerScopedHTMLStyleChild();
+ scope->setNeedsStyleRecalc();
+ if (inDocument() && !document()->parsing() && document()->renderer())
+ document()->styleSelectorChanged(DeferRecalcStyle);
+
+ m_isRegisteredWithScopingNode = true;
+ }
+}
+
+void HTMLStyleElement::unregisterWithScopingNode()
+{
+ // Note: We cannot rely on the 'scoped' element still being present when this method is invoked.
+ // Therefore we cannot rely on scoped()!
+ ASSERT(m_isRegisteredWithScopingNode);
+ if (m_isRegisteredWithScopingNode) {
+ Element* scope = parentElement();
+ ASSERT(scope);
+ if (scope) {
+ ASSERT(scope->hasScopedHTMLStyleChild());
+ scope->unregisterScopedHTMLStyleChild();
+ scope->setNeedsStyleRecalc();
+ }
+ if (inDocument() && !document()->parsing() && document()->renderer())
+ document()->styleSelectorChanged(DeferRecalcStyle);
+
+ m_isRegisteredWithScopingNode = false;
+ }
+}
+#endif
+
void HTMLStyleElement::insertedIntoDocument()
{
HTMLElement::insertedIntoDocument();
StyleElement::insertedIntoDocument(document(), this);
+#if ENABLE(STYLE_SCOPED)
+ if (scoped() && !m_isRegisteredWithScopingNode)
+ registerWithScopingNode();
+#endif
}
void HTMLStyleElement::removedFromDocument()
{
+#if ENABLE(STYLE_SCOPED)
+ ASSERT(!m_isRegisteredWithScopingNode);
+#endif
HTMLElement::removedFromDocument();
StyleElement::removedFromDocument(document(), this);
}
+
+#if ENABLE(STYLE_SCOPED)
+void HTMLStyleElement::willRemove()
+{
+ // In the current implementation, <style scoped> is only registered if the node is in the document.
+ // That is, because willRemove() is also called if an ancestor is removed from the document.
+ // Now, if we want to register <style scoped> even if it's not inDocument,
+ // we'd need to find a way to discern whether that is the case, or whether <style scoped> itself is about to be removed.
+ ASSERT(!scoped() || !inDocument() || m_isRegisteredWithScopingNode);
+ if (m_isRegisteredWithScopingNode)
+ unregisterWithScopingNode();
+ HTMLElement::willRemove();
+}
+#endif
+
void HTMLStyleElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
StyleElement::childrenChanged(this);