From 6733a9c1fef8795df6c34ff3abbd88fb82c91d88 Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Tue, 17 Apr 2012 02:55:40 +0000 Subject: [PATCH] [Shadow DOM] InsertionPoint should have isActive() member function. https://bugs.webkit.org/show_bug.cgi?id=82010 Patch by Takashi Sakamoto 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 --- .../shadow/shadow-contents-fallback-dynamic.html | 6 ++-- .../fast/dom/shadow/shadow-contents-fallback.html | 8 ++--- Source/WebCore/ChangeLog | 39 ++++++++++++++++++++++ Source/WebCore/dom/NodeRenderingContext.cpp | 10 ++++-- Source/WebCore/html/shadow/InsertionPoint.cpp | 22 +++++++++--- Source/WebCore/html/shadow/InsertionPoint.h | 1 + 6 files changed, 71 insertions(+), 15 deletions(-) diff --git a/LayoutTests/fast/dom/shadow/shadow-contents-fallback-dynamic.html b/LayoutTests/fast/dom/shadow/shadow-contents-fallback-dynamic.html index 1fea94f..7f82dc9 100644 --- a/LayoutTests/fast/dom/shadow/shadow-contents-fallback-dynamic.html +++ b/LayoutTests/fast/dom/shadow/shadow-contents-fallback-dynamic.html @@ -342,7 +342,7 @@ function testComplexReplace(callIfDone) { function testContentInContent(callIfDone) { document.getElementById('expect-container').innerHTML = - "
{SHADOW: S1S2}
"; + "
{SHADOW: CONTENT 2 FALLBACK}
"; var target = document.createElement('div'); target.appendChild(createSpanWithText('S1')); @@ -373,7 +373,7 @@ function testContentInContent(callIfDone) { function testContentInContentFallback(callIfDone) { document.getElementById('expect-container').innerHTML = - "
{SHADOW: CONTENT 2 FALLBACK}
"; + "
{SHADOW: CONTENT 2 FALLBACK}
"; var target = document.createElement('div'); target.appendChild(createSpanWithText('S1')); @@ -404,7 +404,7 @@ function testContentInContentFallback(callIfDone) { function testContentInContentFallbackDirect(callIfDone) { document.getElementById('expect-container').innerHTML = - "
CONTENT 2 FALLBACK
"; + "
CONTENT 2 FALLBACK
"; var target = document.createElement('div'); target.appendChild(createSpanWithText('S1')); diff --git a/LayoutTests/fast/dom/shadow/shadow-contents-fallback.html b/LayoutTests/fast/dom/shadow/shadow-contents-fallback.html index 13ff51e..89ed22f 100644 --- a/LayoutTests/fast/dom/shadow/shadow-contents-fallback.html +++ b/LayoutTests/fast/dom/shadow/shadow-contents-fallback.html @@ -267,7 +267,7 @@ function testContentInContent() { document.getElementById('actual-container').appendChild(target); document.getElementById('expect-container').innerHTML = - "
{SHADOW: S1S2}
"; + "
{SHADOW: CONTENT 2 FALLBACK}
"; } function testContentInContentFallback() { @@ -290,7 +290,7 @@ function testContentInContentFallback() { document.getElementById('actual-container').appendChild(target); document.getElementById('expect-container').innerHTML = - "
{SHADOW: CONTENT 2 FALLBACK}
"; + "
{SHADOW: CONTENT 2 FALLBACK}
"; } function testContentInContentFallbackWithDisplayNone() { @@ -316,7 +316,7 @@ function testContentInContentFallbackWithDisplayNone() { document.getElementById('actual-container').appendChild(target); document.getElementById('expect-container').innerHTML = - "
{SHADOW: CONTENT 2 FALLBACK}
"; + "
{SHADOW: CONTENT 2 FALLBACK}
"; } function testContentInContentFallbackDirect() { @@ -337,7 +337,7 @@ function testContentInContentFallbackDirect() { document.getElementById('actual-container').appendChild(target); document.getElementById('expect-container').innerHTML = - "
CONTENT 2 FALLBACK
"; + "
CONTENT 2 FALLBACK
"; } var testFuncs = [ diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 132fe4f..d60534e 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,42 @@ +2012-04-16 Takashi Sakamoto + + [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 Type tags in NodeFlags could be compressed diff --git a/Source/WebCore/dom/NodeRenderingContext.cpp b/Source/WebCore/dom/NodeRenderingContext.cpp index 41c77ec..145e56a 100644 --- a/Source/WebCore/dom/NodeRenderingContext.cpp +++ b/Source/WebCore/dom/NodeRenderingContext.cpp @@ -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; } diff --git a/Source/WebCore/html/shadow/InsertionPoint.cpp b/Source/WebCore/html/shadow/InsertionPoint.cpp index 32f24f4..70af85e 100644 --- a/Source/WebCore/html/shadow/InsertionPoint.cpp +++ b/Source/WebCore/html/shadow/InsertionPoint.cpp @@ -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) diff --git a/Source/WebCore/html/shadow/InsertionPoint.h b/Source/WebCore/html/shadow/InsertionPoint.h index 74b1a20..1da8c80 100644 --- a/Source/WebCore/html/shadow/InsertionPoint.h +++ b/Source/WebCore/html/shadow/InsertionPoint.h @@ -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; -- 2.7.4