[Shadow DOM] InsertionPoint should have isActive() member function.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2012 02:55:40 +0000 (02:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Apr 2012 02:55:40 +0000 (02:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82010

Patch by Takashi Sakamoto <tasak@google.com> on 2012-04-16
Reviewed by Hajime Morita.

This patch adds isActive public member function to InsertionPoint and
makes InsertionPoint elements consider whether active or not.
If an InsertionPoint is inactive, the element is not shadow boundary
and is needed to be rendered.
c.f. https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#dfn-active-insertion-point

Test: update existing tests, i.e.
LayoutTests/fast/dom/shadow/shadow-contents-fallback-dynamic.html and
LayoutTests/fast/dom/shadow/shadow-contents-fallback.html

* html/shadow/InsertionPoint.cpp:
(WebCore::InsertionPoint::isActive):
A new public method for checking whether an insertion point is active or inactive.
If active, returns true. Otherwise, false.
(WebCore::InsertionPoint::isShadowBoundary):
Make the method consider whether an insertin point is active or inactive.
(WebCore::InsertionPoint::rendererIsNeeded):
Changed to return true If an insertion point is inactive.
(WebCore::InsertionPoint::attach):
Changed to call only HTMLElement::attach If an insertion point is inactive.
(WebCore::InsertionPoint::detach):
Changed to call only HTMLElement::detach If an insertion point is inactive.
* html/shadow/InsertionPoint.h:
(InsertionPoint):
Added isActive public method.
* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::NodeRenderingContext):
Changed to take into account an insertion point's activeness when parent is an insertion point.
(WebCore::NodeRenderingContext::firstRendererOf):
(WebCore::NodeRenderingContext::lastRendererOf):
Changed to take into account an insertion point's activeness.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114334 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/fast/dom/shadow/shadow-contents-fallback-dynamic.html
LayoutTests/fast/dom/shadow/shadow-contents-fallback.html
Source/WebCore/ChangeLog
Source/WebCore/dom/NodeRenderingContext.cpp
Source/WebCore/html/shadow/InsertionPoint.cpp
Source/WebCore/html/shadow/InsertionPoint.h

index 1fea94f..7f82dc9 100644 (file)
@@ -342,7 +342,7 @@ function testComplexReplace(callIfDone) {
 
 function testContentInContent(callIfDone) {
     document.getElementById('expect-container').innerHTML =
-        "<div>{SHADOW: <span>S1</span><span>S2</span>}</div>";
+        "<div>{SHADOW: <content><span>CONTENT 2 FALLBACK</span></content>}</div>";
 
     var target = document.createElement('div');
     target.appendChild(createSpanWithText('S1'));
@@ -373,7 +373,7 @@ function testContentInContent(callIfDone) {
 
 function testContentInContentFallback(callIfDone) {
     document.getElementById('expect-container').innerHTML =
-        "<div>{SHADOW: <span>CONTENT 2 FALLBACK</span>}</div>";
+        "<div>{SHADOW: <content><span>CONTENT 2 FALLBACK</span></content>}</div>";
 
     var target = document.createElement('div');
     target.appendChild(createSpanWithText('S1'));
@@ -404,7 +404,7 @@ function testContentInContentFallback(callIfDone) {
 
 function testContentInContentFallbackDirect(callIfDone) {
     document.getElementById('expect-container').innerHTML =
-        "<div><span>CONTENT 2 FALLBACK</span></div>";
+        "<div><content><span>CONTENT 2 FALLBACK</span></content></div>";
 
     var target = document.createElement('div');
     target.appendChild(createSpanWithText('S1'));
index 13ff51e..89ed22f 100644 (file)
@@ -267,7 +267,7 @@ function testContentInContent() {
 
     document.getElementById('actual-container').appendChild(target);
     document.getElementById('expect-container').innerHTML =
-        "<div>{SHADOW: <span>S1</span><span>S2</span>}</div>";
+        "<div>{SHADOW: <content><span>CONTENT 2 FALLBACK</span></content>}</div>";
 }
 
 function testContentInContentFallback() {
@@ -290,7 +290,7 @@ function testContentInContentFallback() {
 
     document.getElementById('actual-container').appendChild(target);
     document.getElementById('expect-container').innerHTML =
-        "<div>{SHADOW: <span>CONTENT 2 FALLBACK</span>}</div>";
+        "<div>{SHADOW: <content><span>CONTENT 2 FALLBACK</span></content>}</div>";
 }
 
 function testContentInContentFallbackWithDisplayNone() {
@@ -316,7 +316,7 @@ function testContentInContentFallbackWithDisplayNone() {
 
     document.getElementById('actual-container').appendChild(target);
     document.getElementById('expect-container').innerHTML =
-        "<div>{SHADOW: <span>CONTENT 2 FALLBACK</span>}</div>";
+        "<div>{SHADOW: <content><span>CONTENT 2 FALLBACK</span></content>}</div>";
 }
 
 function testContentInContentFallbackDirect() {
@@ -337,7 +337,7 @@ function testContentInContentFallbackDirect() {
 
     document.getElementById('actual-container').appendChild(target);
     document.getElementById('expect-container').innerHTML =
-        "<div><span>CONTENT 2 FALLBACK</span></div>";
+        "<div><content><span>CONTENT 2 FALLBACK</span></content></div>";
 }
 
 var testFuncs = [
index 132fe4f..d60534e 100644 (file)
@@ -1,3 +1,42 @@
+2012-04-16  Takashi Sakamoto  <tasak@google.com>
+
+        [Shadow DOM] InsertionPoint should have isActive() member function.
+        https://bugs.webkit.org/show_bug.cgi?id=82010
+
+        Reviewed by Hajime Morita.
+
+        This patch adds isActive public member function to InsertionPoint and
+        makes InsertionPoint elements consider whether active or not.
+        If an InsertionPoint is inactive, the element is not shadow boundary
+        and is needed to be rendered.
+        c.f. https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#dfn-active-insertion-point
+
+        Test: update existing tests, i.e.
+        LayoutTests/fast/dom/shadow/shadow-contents-fallback-dynamic.html and
+        LayoutTests/fast/dom/shadow/shadow-contents-fallback.html
+
+        * html/shadow/InsertionPoint.cpp:
+        (WebCore::InsertionPoint::isActive):
+        A new public method for checking whether an insertion point is active or inactive.
+        If active, returns true. Otherwise, false.
+        (WebCore::InsertionPoint::isShadowBoundary):
+        Make the method consider whether an insertin point is active or inactive.
+        (WebCore::InsertionPoint::rendererIsNeeded):
+        Changed to return true If an insertion point is inactive.
+        (WebCore::InsertionPoint::attach):
+        Changed to call only HTMLElement::attach If an insertion point is inactive.
+        (WebCore::InsertionPoint::detach):
+        Changed to call only HTMLElement::detach If an insertion point is inactive.
+        * html/shadow/InsertionPoint.h:
+        (InsertionPoint):
+        Added isActive public method.
+        * dom/NodeRenderingContext.cpp:
+        (WebCore::NodeRenderingContext::NodeRenderingContext):
+        Changed to take into account an insertion point's activeness when parent is an insertion point.
+        (WebCore::NodeRenderingContext::firstRendererOf):
+        (WebCore::NodeRenderingContext::lastRendererOf):
+        Changed to take into account an insertion point's activeness.
+
 2012-04-16  MORITA Hajime  <morrita@google.com>
 
         Type tags in NodeFlags could be compressed
index 41c77ec..145e56a 100644 (file)
@@ -101,7 +101,11 @@ NodeRenderingContext::NodeRenderingContext(Node* node)
                 m_phase = AttachingNotFallbacked;
             else
                 m_phase = AttachingFallbacked;
-            m_parentNodeForRenderingAndStyle = NodeRenderingContext(parent).parentNodeForRenderingAndStyle();
+
+            if (toInsertionPoint(parent)->isActive())
+                m_parentNodeForRenderingAndStyle = NodeRenderingContext(parent).parentNodeForRenderingAndStyle();
+            else
+                m_parentNodeForRenderingAndStyle = parent;
             return;
         }
     }
@@ -202,7 +206,7 @@ static inline RenderObject* firstRendererOf(Node* node)
             return node->renderer();
         }
 
-        if (isInsertionPoint(node)) {
+        if (isInsertionPoint(node) && toInsertionPoint(node)->isActive()) {
             if (RenderObject* first = firstRendererOfInsertionPoint(toInsertionPoint(node)))
                 return first;
         }
@@ -220,7 +224,7 @@ static inline RenderObject* lastRendererOf(Node* node)
                 continue;
             return node->renderer();
         }
-        if (isInsertionPoint(node)) {
+        if (isInsertionPoint(node) && toInsertionPoint(node)->isActive()) {
             if (RenderObject* last = lastRendererOfInsertionPoint(toInsertionPoint(node)))
                 return last;
         }
index 32f24f4..70af85e 100644 (file)
@@ -48,9 +48,8 @@ InsertionPoint::~InsertionPoint()
 
 void InsertionPoint::attach()
 {
-    TreeScope* scope = treeScope();
-    if (scope->rootNode()->isShadowRoot()) {
-        ShadowRoot* root = toShadowRoot(scope->rootNode());
+    if (isShadowBoundary()) {
+        ShadowRoot* root = toShadowRoot(treeScope()->rootNode());
         if (doesSelectFromHostChildren()) {
             distributeHostChildren(root->tree());
             attachDistributedNode();
@@ -66,7 +65,8 @@ void InsertionPoint::attach()
 
 void InsertionPoint::detach()
 {
-    if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
+    ShadowRoot* root = toShadowRoot(shadowTreeRootNode());
+    if (root && isActive()) {
         ShadowTree* tree = root->tree();
 
         if (doesSelectFromHostChildren())
@@ -97,7 +97,19 @@ ShadowRoot* InsertionPoint::assignedFrom() const
 
 bool InsertionPoint::isShadowBoundary() const
 {
-    return treeScope()->rootNode()->isShadowRoot();
+    return treeScope()->rootNode()->isShadowRoot() && isActive();
+}
+
+bool InsertionPoint::isActive() const
+{
+    const Node* node = parentNode();
+    while (node) {
+        if (WebCore::isInsertionPoint(node))
+            return false;
+
+        node = node->parentNode();
+    }
+    return true;
 }
 
 bool InsertionPoint::rendererIsNeeded(const NodeRenderingContext& context)
index 74b1a20..1da8c80 100644 (file)
@@ -45,6 +45,7 @@ public:
     const HTMLContentSelectionList* selections() const { return &m_selections; }
     bool hasSelection() const { return m_selections.first(); }
     bool isShadowBoundary() const;
+    bool isActive() const;
 
     virtual const AtomicString& select() const = 0;
     virtual bool isSelectValid() const = 0;