Diff
Modified: trunk/LayoutTests/ChangeLog (184434 => 184435)
--- trunk/LayoutTests/ChangeLog 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/LayoutTests/ChangeLog 2015-05-16 18:16:26 UTC (rev 184435)
@@ -1,3 +1,13 @@
+2015-05-15 Sam Weinig <s...@webkit.org>
+
+ Add getElementById to DocumentFragment
+ https://bugs.webkit.org/show_bug.cgi?id=145094
+
+ Reviewed by Alexey Proskuryakov.
+
+ * fast/dom/DocumentFragment/getElementById-expected.txt: Added.
+ * fast/dom/DocumentFragment/getElementById.html: Added.
+
2015-05-15 Antti Koivisto <an...@apple.com>
When redirecting to data URL use HTTP response for same origin policy checks
Added: trunk/LayoutTests/fast/dom/DocumentFragment/getElementById-expected.txt (0 => 184435)
--- trunk/LayoutTests/fast/dom/DocumentFragment/getElementById-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/DocumentFragment/getElementById-expected.txt 2015-05-16 18:16:26 UTC (rev 184435)
@@ -0,0 +1,15 @@
+Tests that getElementById() API is exposed on DocumentFragment nodes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS fragment.getElementById('divID') is div
+PASS fragment.getElementById('aID') is a
+PASS fragment.getElementById('notInFragment') is null
+PASS fragment.getElementById('doesNotExist') is null
+PASS fragment.getElementById('duplicateId1') is span
+PASS fragment.getElementById('duplicateId2') is h1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/DocumentFragment/getElementById.html (0 => 184435)
--- trunk/LayoutTests/fast/dom/DocumentFragment/getElementById.html (rev 0)
+++ trunk/LayoutTests/fast/dom/DocumentFragment/getElementById.html 2015-05-16 18:16:26 UTC (rev 184435)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<div id="notInFragment"></div>
+<div id="duplicateId1"></div>
+<script>
+
+description("Tests that getElementById() API is exposed on DocumentFragment nodes.");
+
+var fragment = new DocumentFragment();
+var div = document.createElement("div");
+div.id = "divID";
+fragment.appendChild(div);
+var a = document.createElement("a");
+a.id = "aID";
+div.appendChild(a);
+var span = document.createElement("span");
+span.id = "duplicateId1";
+div.appendChild(span);
+var h1 = document.createElement("h1");
+h1.id = "duplicateId2";
+div.appendChild(h1);
+var h2 = document.createElement("h2");
+h2.id = "duplicateId2";
+div.appendChild(h2);
+
+shouldBe("fragment.getElementById('divID')", "div");
+shouldBe("fragment.getElementById('aID')", "a");
+shouldBeNull("fragment.getElementById('notInFragment')");
+shouldBeNull("fragment.getElementById('doesNotExist')");
+
+// Duplicate ID cases.
+shouldBe("fragment.getElementById('duplicateId1')", "span"); // Should return the Element *inside* the DocumentFragment.
+shouldBe("fragment.getElementById('duplicateId2')", "h1"); // Should return the first matching Element in case of duplicate.
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/CMakeLists.txt (184434 => 184435)
--- trunk/Source/WebCore/CMakeLists.txt 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/CMakeLists.txt 2015-05-16 18:16:26 UTC (rev 184435)
@@ -411,6 +411,7 @@
dom/NodeFilter.idl
dom/NodeIterator.idl
dom/NodeList.idl
+ dom/NonElementParentNode.idl
dom/NonDocumentTypeChildNode.idl
dom/OverflowEvent.idl
dom/PageTransitionEvent.idl
Modified: trunk/Source/WebCore/ChangeLog (184434 => 184435)
--- trunk/Source/WebCore/ChangeLog 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/ChangeLog 2015-05-16 18:16:26 UTC (rev 184435)
@@ -1,3 +1,43 @@
+2015-05-15 Sam Weinig <s...@webkit.org>
+
+ Add getElementById to DocumentFragment
+ https://bugs.webkit.org/show_bug.cgi?id=145094
+
+ Reviewed by Alexey Proskuryakov.
+
+ Match the latest DOM standard and other browsers by adding getElementById
+ to DocumentFragment in addition to Document and SVGSVGElement. Add NonElementParentNode
+ interface that the DOM standard defines.
+
+ Test: fast/dom/DocumentFragment/getElementById.html
+
+ * DerivedSources.make:
+ * WebCore.xcodeproj/project.pbxproj:
+ Add NonElementParentNode.idl
+
+ * dom/Document.idl:
+ Mark Document as implementing NonElementParentNode and remove now redundant getElementById
+ declaration.
+
+ * dom/DocumentFragment.cpp:
+ (WebCore::DocumentFragment::getElementById):
+ * dom/DocumentFragment.h:
+ Add implementation of getElementById for DocumentFragments. Add a fast path for ShadowRoots
+ which can take advantage of the fact that they are TreeScopes to use the elements by id cache
+ in TreeScrope.
+
+ * dom/DocumentFragment.idl:
+ Mark DocumentFragment as implementing NonElementParentNode.
+
+ * dom/NonElementParentNode.idl: Copied from Source/WebCore/dom/NonDocumentTypeChildNode.idl.
+ Added.
+
+ * svg/SVGSVGElement.cpp:
+ (WebCore::SVGSVGElement::getElementById):
+ * svg/SVGSVGElement.h:
+ * svg/SVGSVGElement.idl:
+ Convert to taking an AtomicString to match other getElementByIds.
+
2015-05-15 Antti Koivisto <an...@apple.com>
When redirecting to data URL use HTTP response for same origin policy checks
Modified: trunk/Source/WebCore/DerivedSources.make (184434 => 184435)
--- trunk/Source/WebCore/DerivedSources.make 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/DerivedSources.make 2015-05-16 18:16:26 UTC (rev 184435)
@@ -299,6 +299,7 @@
$(WebCore)/dom/NodeFilter.idl \
$(WebCore)/dom/NodeIterator.idl \
$(WebCore)/dom/NodeList.idl \
+ $(WebCore)/dom/NonElementParentNode.idl \
$(WebCore)/dom/NonDocumentTypeChildNode.idl \
$(WebCore)/dom/OverflowEvent.idl \
$(WebCore)/dom/PageTransitionEvent.idl \
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (184434 => 184435)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-05-16 18:16:26 UTC (rev 184435)
@@ -9818,6 +9818,7 @@
7C6136F71710C35200FF4A57 /* InFilesCompiler.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = InFilesCompiler.pm; path = scripts/InFilesCompiler.pm; sourceTree = "<group>"; };
7C6136F81710C35200FF4A57 /* InFilesParser.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = InFilesParser.pm; path = scripts/InFilesParser.pm; sourceTree = "<group>"; };
7C6136F91710C35200FF4A57 /* StaticString.pm */ = {isa = PBXFileReference; lastKnownFileType = text.script.perl; name = StaticString.pm; path = scripts/StaticString.pm; sourceTree = "<group>"; };
+ 7C6752BA1B06E82000C279CB /* NonElementParentNode.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NonElementParentNode.idl; sourceTree = "<group>"; };
7C73FB05191EF416007DE061 /* UserMessageHandlersNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserMessageHandlersNamespace.cpp; sourceTree = "<group>"; };
7C73FB06191EF417007DE061 /* UserMessageHandlersNamespace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserMessageHandlersNamespace.h; sourceTree = "<group>"; };
7C73FB09191EF49F007DE061 /* UserMessageHandlersNamespace.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = UserMessageHandlersNamespace.idl; sourceTree = "<group>"; };
@@ -23171,6 +23172,7 @@
E43105BA16750F1600DB2FB8 /* NodeTraversal.h */,
9382AAB10D8C386100F357A6 /* NodeWithIndex.h */,
8369E58F1AFDD0300087DF68 /* NonDocumentTypeChildNode.idl */,
+ 7C6752BA1B06E82000C279CB /* NonElementParentNode.idl */,
1A0D57340A5C77FE007EDD4C /* OverflowEvent.cpp */,
1A0D57350A5C77FE007EDD4C /* OverflowEvent.h */,
1A0D57380A5C7812007EDD4C /* OverflowEvent.idl */,
Modified: trunk/Source/WebCore/dom/Document.idl (184434 => 184435)
--- trunk/Source/WebCore/dom/Document.idl 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/dom/Document.idl 2015-05-16 18:16:26 UTC (rev 184435)
@@ -52,7 +52,6 @@
[TreatNullAs=NullString,Default=Undefined] optional DOMString qualifiedName);
[ObjCLegacyUnnamedParameters] NodeList getElementsByTagNameNS([TreatNullAs=NullString,Default=Undefined] optional DOMString namespaceURI,
[Default=Undefined] optional DOMString localName);
- Element getElementById([Default=Undefined,ObjCExplicitAtomicString,RequiresExistingAtomicString] optional DOMString elementId);
// DOM Level 3 Core
@@ -343,3 +342,4 @@
};
Document implements ParentNode;
+Document implements NonElementParentNode;
Modified: trunk/Source/WebCore/dom/DocumentFragment.cpp (184434 => 184435)
--- trunk/Source/WebCore/dom/DocumentFragment.cpp 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/dom/DocumentFragment.cpp 2015-05-16 18:16:26 UTC (rev 184435)
@@ -24,6 +24,7 @@
#include "DocumentFragment.h"
#include "Document.h"
+#include "ElementDescendantIterator.h"
#include "HTMLDocumentParser.h"
#include "Page.h"
#include "Settings.h"
@@ -91,4 +92,19 @@
return XMLDocumentParser::parseDocumentFragment(source, *this, contextElement, parserContentPolicy);
}
+Element* DocumentFragment::getElementById(const AtomicString& id) const
+{
+ // Fast path for ShadowRoot, where we are both a DocumentFragment and a TreeScope.
+ if (isTreeScope())
+ return treeScope().getElementById(id);
+
+ // Otherwise, fall back to iterating all of the element descendants.
+ for (auto& element : elementDescendants(*this)) {
+ if (element.getIdAttribute() == id)
+ return const_cast<Element*>(&element);
+ }
+
+ return nullptr;
}
+
+}
Modified: trunk/Source/WebCore/dom/DocumentFragment.h (184434 => 184435)
--- trunk/Source/WebCore/dom/DocumentFragment.h 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/dom/DocumentFragment.h 2015-05-16 18:16:26 UTC (rev 184435)
@@ -39,6 +39,9 @@
virtual bool canContainRangeEndPoint() const override final { return true; }
virtual bool isTemplateContent() const { return false; }
+ // From the NonElementParentNode interface - https://dom.spec.whatwg.org/#interface-nonelementparentnode
+ Element* getElementById(const AtomicString&) const;
+
protected:
DocumentFragment(Document&, ConstructionType = CreateContainer);
virtual String nodeName() const override final;
Modified: trunk/Source/WebCore/dom/DocumentFragment.idl (184434 => 184435)
--- trunk/Source/WebCore/dom/DocumentFragment.idl 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/dom/DocumentFragment.idl 2015-05-16 18:16:26 UTC (rev 184435)
@@ -17,10 +17,11 @@
* Boston, MA 02110-1301, USA.
*/
- [
+[
Constructor,
ConstructorCallWith=Document
- ] interface DocumentFragment : Node {
+] interface DocumentFragment : Node {
};
DocumentFragment implements ParentNode;
+DocumentFragment implements NonElementParentNode;
Copied: trunk/Source/WebCore/dom/NonElementParentNode.idl (from rev 184419, trunk/Source/WebCore/dom/NonDocumentTypeChildNode.idl) (0 => 184435)
--- trunk/Source/WebCore/dom/NonElementParentNode.idl (rev 0)
+++ trunk/Source/WebCore/dom/NonElementParentNode.idl 2015-05-16 18:16:26 UTC (rev 184435)
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+// https://dom.spec.whatwg.org/#interface-nonelementparentnode
+[
+ NoInterfaceObject,
+] interface NonElementParentNode {
+ Element getElementById([Default=Undefined,ObjCExplicitAtomicString,RequiresExistingAtomicString] optional DOMString elementId);
+};
Modified: trunk/Source/WebCore/svg/SVGSVGElement.cpp (184434 => 184435)
--- trunk/Source/WebCore/svg/SVGSVGElement.cpp 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/svg/SVGSVGElement.cpp 2015-05-16 18:16:26 UTC (rev 184435)
@@ -670,7 +670,7 @@
// getElementById on SVGSVGElement is restricted to only the child subtree defined by the <svg> element.
// See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement
-Element* SVGSVGElement::getElementById(const String& id)
+Element* SVGSVGElement::getElementById(const AtomicString& id)
{
Element* element = treeScope().getElementById(id);
if (element && element->isDescendantOf(this))
Modified: trunk/Source/WebCore/svg/SVGSVGElement.h (184434 => 184435)
--- trunk/Source/WebCore/svg/SVGSVGElement.h 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/svg/SVGSVGElement.h 2015-05-16 18:16:26 UTC (rev 184435)
@@ -97,7 +97,7 @@
static SVGTransform createSVGTransform();
static SVGTransform createSVGTransformFromMatrix(const SVGMatrix&);
- Element* getElementById(const String&);
+ Element* getElementById(const AtomicString&);
SVGZoomAndPanType zoomAndPan() const;
void setZoomAndPan(unsigned short);
Modified: trunk/Source/WebCore/svg/SVGSVGElement.idl (184434 => 184435)
--- trunk/Source/WebCore/svg/SVGSVGElement.idl 2015-05-16 13:53:21 UTC (rev 184434)
+++ trunk/Source/WebCore/svg/SVGSVGElement.idl 2015-05-16 18:16:26 UTC (rev 184435)
@@ -67,7 +67,8 @@
SVGRect createSVGRect();
SVGTransform createSVGTransform();
SVGTransform createSVGTransformFromMatrix([Default=Undefined] optional SVGMatrix matrix);
- Element getElementById([Default=Undefined] optional DOMString elementId);
+
+ Element getElementById([Default=Undefined, RequiresExistingAtomicString] optional DOMString elementId);
};
SVGSVGElement implements SVGExternalResourcesRequired;