Title: [138756] trunk
Revision
138756
Author
ad...@chromium.org
Date
2013-01-03 15:41:16 -0800 (Thu, 03 Jan 2013)

Log Message

[HTMLTemplateElement] When adopting a template element, also adopt its content into the appropriate document
https://bugs.webkit.org/show_bug.cgi?id=106039

Reviewed by Eric Seidel.

Source/WebCore:

Implements the approach discussed in the spec bug:
https://www.w3.org/Bugs/Public/show_bug.cgi?id=20129

Test: fast/dom/HTMLTemplateElement/ownerDocument-adoptNode.html

* html/HTMLTemplateElement.cpp:
(WebCore::HTMLTemplateElement::didMoveToNewDocument):
* html/HTMLTemplateElement.h:
(HTMLTemplateElement):

LayoutTests:

* fast/dom/HTMLTemplateElement/ownerDocument-adoptNode-expected.txt: Added.
* fast/dom/HTMLTemplateElement/ownerDocument-adoptNode.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (138755 => 138756)


--- trunk/LayoutTests/ChangeLog	2013-01-03 23:28:48 UTC (rev 138755)
+++ trunk/LayoutTests/ChangeLog	2013-01-03 23:41:16 UTC (rev 138756)
@@ -1,3 +1,13 @@
+2013-01-03  Adam Klein  <ad...@chromium.org>
+
+        [HTMLTemplateElement] When adopting a template element, also adopt its content into the appropriate document
+        https://bugs.webkit.org/show_bug.cgi?id=106039
+
+        Reviewed by Eric Seidel.
+
+        * fast/dom/HTMLTemplateElement/ownerDocument-adoptNode-expected.txt: Added.
+        * fast/dom/HTMLTemplateElement/ownerDocument-adoptNode.html: Added.
+
 2013-01-03  Zoltan Horvath  <zol...@webkit.org>
 
         [CSS Regions] Don't apply region flow to fullscreen video playing

Added: trunk/LayoutTests/fast/dom/HTMLTemplateElement/ownerDocument-adoptNode-expected.txt (0 => 138756)


--- trunk/LayoutTests/fast/dom/HTMLTemplateElement/ownerDocument-adoptNode-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLTemplateElement/ownerDocument-adoptNode-expected.txt	2013-01-03 23:41:16 UTC (rev 138756)
@@ -0,0 +1,17 @@
+Adopting a template from another document should also switch the template content document
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Before adoption:
+PASS template.ownerDocument is not frameTemplate.ownerDocument
+PASS template.content.ownerDocument is not frameTemplate.content.ownerDocument
+
+After adoption:
+PASS template.ownerDocument is frameTemplate.ownerDocument
+PASS template.content.ownerDocument is frameTemplate.content.ownerDocument
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/HTMLTemplateElement/ownerDocument-adoptNode.html (0 => 138756)


--- trunk/LayoutTests/fast/dom/HTMLTemplateElement/ownerDocument-adoptNode.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLTemplateElement/ownerDocument-adoptNode.html	2013-01-03 23:41:16 UTC (rev 138756)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<body>
+<template><div></div></template>
+<iframe srcdoc="<template><div></div></template>" style="display:none"></iframe>
+<script src=""
+<script>
+description('Adopting a template from another document should also switch the template content document');
+
+var template = document.querySelector('template');
+var frameTemplate = frames[0].document.querySelector('template');
+
+debug('Before adoption:');
+shouldNotBe('template.ownerDocument', 'frameTemplate.ownerDocument');
+shouldNotBe('template.content.ownerDocument', 'frameTemplate.content.ownerDocument');
+frameTemplate = document.adoptNode(frameTemplate);
+debug('\nAfter adoption:');
+shouldBe('template.ownerDocument', 'frameTemplate.ownerDocument');
+shouldBe('template.content.ownerDocument', 'frameTemplate.content.ownerDocument');
+debug('');
+</script>
+<script src=""
+</body>

Modified: trunk/Source/WebCore/ChangeLog (138755 => 138756)


--- trunk/Source/WebCore/ChangeLog	2013-01-03 23:28:48 UTC (rev 138755)
+++ trunk/Source/WebCore/ChangeLog	2013-01-03 23:41:16 UTC (rev 138756)
@@ -1,3 +1,20 @@
+2013-01-03  Adam Klein  <ad...@chromium.org>
+
+        [HTMLTemplateElement] When adopting a template element, also adopt its content into the appropriate document
+        https://bugs.webkit.org/show_bug.cgi?id=106039
+
+        Reviewed by Eric Seidel.
+
+        Implements the approach discussed in the spec bug:
+        https://www.w3.org/Bugs/Public/show_bug.cgi?id=20129
+
+        Test: fast/dom/HTMLTemplateElement/ownerDocument-adoptNode.html
+
+        * html/HTMLTemplateElement.cpp:
+        (WebCore::HTMLTemplateElement::didMoveToNewDocument):
+        * html/HTMLTemplateElement.h:
+        (HTMLTemplateElement):
+
 2013-01-03  Zoltan Horvath  <zol...@webkit.org>
 
         [CSS Regions] Don't apply region flow to fullscreen video playing

Modified: trunk/Source/WebCore/html/HTMLTemplateElement.cpp (138755 => 138756)


--- trunk/Source/WebCore/html/HTMLTemplateElement.cpp	2013-01-03 23:28:48 UTC (rev 138755)
+++ trunk/Source/WebCore/html/HTMLTemplateElement.cpp	2013-01-03 23:41:16 UTC (rev 138756)
@@ -58,8 +58,6 @@
     return adoptRef(new HTMLTemplateElement(tagName, document));
 }
 
-// FIXME: https://www.w3.org/Bugs/Public/show_bug.cgi?id=20127 (prevent DOM hierarchy cycles).
-// FIXME: https://www.w3.org/Bugs/Public/show_bug.cgi?id=20129 (extended adoptNode to consider template.content).
 DocumentFragment* HTMLTemplateElement::content() const
 {
     if (!m_content)
@@ -79,6 +77,14 @@
     return clone.release();
 }
 
+void HTMLTemplateElement::didMoveToNewDocument(Document* oldDocument)
+{
+    HTMLElement::didMoveToNewDocument(oldDocument);
+    if (!m_content)
+        return;
+    document()->ensureTemplateContentsOwnerDocument()->adoptIfNeeded(m_content.get());
+}
+
 #ifndef NDEBUG
 const HTMLTemplateElement* toHTMLTemplateElement(const Node* node)
 {

Modified: trunk/Source/WebCore/html/HTMLTemplateElement.h (138755 => 138756)


--- trunk/Source/WebCore/html/HTMLTemplateElement.h	2013-01-03 23:28:48 UTC (rev 138755)
+++ trunk/Source/WebCore/html/HTMLTemplateElement.h	2013-01-03 23:41:16 UTC (rev 138756)
@@ -47,6 +47,7 @@
 
 private:
     virtual PassRefPtr<Node> cloneNode(bool deep) OVERRIDE;
+    virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
 
     HTMLTemplateElement(const QualifiedName&, Document*);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to