Diff
Modified: trunk/LayoutTests/ChangeLog (118803 => 118804)
--- trunk/LayoutTests/ChangeLog 2012-05-29 17:46:03 UTC (rev 118803)
+++ trunk/LayoutTests/ChangeLog 2012-05-29 17:50:03 UTC (rev 118804)
@@ -1,3 +1,13 @@
+2012-05-29 MORITA Hajime <[email protected]>
+
+ ShadowRoot.getElementById() returns removed node.
+ https://bugs.webkit.org/show_bug.cgi?id=62184
+
+ Reviewed by Dimitri Glazkov.
+
+ * fast/dom/shadow/get-element-by-id-in-shadow-mutation-expected.txt: Added.
+ * fast/dom/shadow/get-element-by-id-in-shadow-mutation.html: Added.
+
2012-05-29 Alexey Proskuryakov <[email protected]>
* platform/mac/Skipped: Skipping a heap profiler test (unsupported functionality).
Added: trunk/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-mutation-expected.txt (0 => 118804)
--- trunk/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-mutation-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-mutation-expected.txt 2012-05-29 17:50:03 UTC (rev 118804)
@@ -0,0 +1,16 @@
+Tests to ensure that ShadowRoot.getElementById works even after mutation
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS null is shadow.getElementById('foo')
+PASS e0a is shadow.getElementById('foo')
+PASS e0b is shadow.getElementById('foo')
+PASS e0c is shadow.getElementById('foo')
+PASS e0b is shadow.getElementById('foo')
+PASS e0a is shadow.getElementById('foo')
+PASS null is shadow.getElementById('foo')
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-mutation.html (0 => 118804)
--- trunk/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-mutation.html (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/get-element-by-id-in-shadow-mutation.html 2012-05-29 17:50:03 UTC (rev 118804)
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="host"></div>
+<script>
+description("Tests to ensure that ShadowRoot.getElementById works even after mutation");
+
+var host = document.getElementById("host");
+var shadow = new WebKitShadowRoot(host);
+
+shouldBe("null", "shadow.getElementById('foo')");
+
+e0a = document.createElement("div");
+e0a.id = "foo";
+shadow.appendChild(e0a);
+shouldBe("e0a", "shadow.getElementById('foo')");
+
+e0b = document.createElement("span");
+e0b.id = "foo";
+shadow.insertBefore(e0b, e0a);
+shouldBe("e0b", "shadow.getElementById('foo')");
+
+e0c = document.createElement("p");
+e0c.id = "foo";
+e0cParent = document.createElement("div");
+e0cParent.appendChild(e0c);
+shadow.insertBefore(e0cParent, e0b);
+shouldBe("e0c", "shadow.getElementById('foo')");
+
+shadow.removeChild(e0cParent);
+shouldBe("e0b", "shadow.getElementById('foo')");
+shadow.removeChild(e0b);
+shouldBe("e0a", "shadow.getElementById('foo')");
+shadow.removeChild(e0a);
+shouldBe("null", "shadow.getElementById('foo')");
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (118803 => 118804)
--- trunk/Source/WebCore/ChangeLog 2012-05-29 17:46:03 UTC (rev 118803)
+++ trunk/Source/WebCore/ChangeLog 2012-05-29 17:50:03 UTC (rev 118804)
@@ -1,3 +1,28 @@
+2012-05-29 MORITA Hajime <[email protected]>
+
+ ShadowRoot.getElementById() returns removed node.
+ https://bugs.webkit.org/show_bug.cgi?id=62184
+
+ Deregitration of m_elementsById map is done at Element::removedFrom()
+ But the tree scope of the removed node is already reset from a shadow root
+ to a document.
+
+ This change lookup the old shadow root through its parent node and
+ deregitrater the node against it.
+
+ Reviewed by Dimitri Glazkov.
+
+ Test: fast/dom/shadow/get-element-by-id-in-shadow-mutation.html
+
+ * dom/Element.cpp:
+ (WebCore::treeScopeOfParent):
+ (WebCore):
+ (WebCore::Element::removedFrom):
+ * dom/Element.h:
+ (Element):
+ (WebCore::Element::updateId):
+ (WebCore):
+
2012-05-29 Dana Jansens <[email protected]>
[chromium] Unoccluded area in surfaces should always be clipped to the rootScissorRect
Modified: trunk/Source/WebCore/dom/Element.cpp (118803 => 118804)
--- trunk/Source/WebCore/dom/Element.cpp 2012-05-29 17:46:03 UTC (rev 118803)
+++ trunk/Source/WebCore/dom/Element.cpp 2012-05-29 17:50:03 UTC (rev 118804)
@@ -914,6 +914,14 @@
return InsertionDone;
}
+static inline TreeScope* treeScopeOfParent(Node* node, ContainerNode* insertionPoint)
+{
+ if (Node* parent = node->parentNode())
+ parent->treeScope();
+ return insertionPoint->treeScope();
+}
+
+
void Element::removedFrom(ContainerNode* insertionPoint)
{
#if ENABLE(FULLSCREEN_API)
@@ -925,8 +933,8 @@
if (insertionPoint->inDocument()) {
const AtomicString& idValue = getIdAttribute();
- if (!idValue.isNull())
- updateId(idValue, nullAtom);
+ if (!idValue.isNull() && inDocument())
+ updateId(treeScopeOfParent(this, insertionPoint), idValue, nullAtom);
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull())
Modified: trunk/Source/WebCore/dom/Element.h (118803 => 118804)
--- trunk/Source/WebCore/dom/Element.h 2012-05-29 17:46:03 UTC (rev 118803)
+++ trunk/Source/WebCore/dom/Element.h 2012-05-29 17:50:03 UTC (rev 118804)
@@ -303,6 +303,7 @@
virtual String title() const;
void updateId(const AtomicString& oldId, const AtomicString& newId);
+ void updateId(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
void updateName(const AtomicString& oldName, const AtomicString& newName);
void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
@@ -587,7 +588,14 @@
if (oldId == newId)
return;
- TreeScope* scope = treeScope();
+ updateId(treeScope(), oldId, newId);
+}
+
+inline void Element::updateId(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
+{
+ ASSERT(inDocument());
+ ASSERT(oldId != newId);
+
if (!oldId.isEmpty())
scope->removeElementById(oldId, this);
if (!newId.isEmpty())