Diff
Modified: trunk/LayoutTests/ChangeLog (184033 => 184034)
--- trunk/LayoutTests/ChangeLog 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/LayoutTests/ChangeLog 2015-05-09 01:14:17 UTC (rev 184034)
@@ -1,3 +1,19 @@
+2015-05-08 Sam Weinig <[email protected]>
+
+ Element Traversal is not just Elements anymore
+ https://bugs.webkit.org/show_bug.cgi?id=144822
+
+ Reviewed by Simon Fraser.
+
+ Add new tests for element traversal functions on Document, DocumentFragment and CharacterData.
+
+ * fast/dom/element-traversal-on-character-data-expected.txt: Added.
+ * fast/dom/element-traversal-on-character-data.html: Added.
+ * fast/dom/element-traversal-on-document-expected.txt: Added.
+ * fast/dom/element-traversal-on-document-fragment-expected.txt: Added.
+ * fast/dom/element-traversal-on-document-fragment.html: Added.
+ * fast/dom/element-traversal-on-document.html: Added.
+
2015-05-08 Martin Robinson <[email protected]>
Unreviewed GTK+ gardening
Added: trunk/LayoutTests/fast/dom/element-traversal-on-character-data-expected.txt (0 => 184034)
--- trunk/LayoutTests/fast/dom/element-traversal-on-character-data-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/element-traversal-on-character-data-expected.txt 2015-05-09 01:14:17 UTC (rev 184034)
@@ -0,0 +1,15 @@
+This test checks the implementation of the element traversal APIs on CharacterData as part of the NonDocumentTypeChildNode interface.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS firstTextNode.previousElementSibling is null
+PASS firstTextNode.nextElementSibling is element
+PASS firstTextNode.nextElementSibling.nextElementSibling is null
+PASS lastTextNode.previousElementSibling is element
+PASS lastTextNode.previousElementSibling.previousElementSibling is null
+PASS lastTextNode.nextElementSibling is null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/element-traversal-on-character-data.html (0 => 184034)
--- trunk/LayoutTests/fast/dom/element-traversal-on-character-data.html (rev 0)
+++ trunk/LayoutTests/fast/dom/element-traversal-on-character-data.html 2015-05-09 01:14:17 UTC (rev 184034)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script>
+
+description("This test checks the implementation of the element traversal APIs on CharacterData as part of the NonDocumentTypeChildNode interface.");
+
+var children = document.createElement('div');
+var firstTextNode = document.createTextNode('first text node');
+children.appendChild(firstTextNode);
+var element = document.createElement('p');
+children.appendChild(element);
+children.appendChild(document.createComment("a comment"));
+var lastTextNode = document.createTextNode('last text node');
+children.appendChild(lastTextNode);
+children.appendChild(document.createComment("last comment"));
+
+shouldBe("firstTextNode.previousElementSibling", "null");
+shouldBe("firstTextNode.nextElementSibling", "element");
+shouldBe("firstTextNode.nextElementSibling.nextElementSibling", "null");
+shouldBe("lastTextNode.previousElementSibling", "element");
+shouldBe("lastTextNode.previousElementSibling.previousElementSibling", "null");
+shouldBe("lastTextNode.nextElementSibling", "null");
+
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/dom/element-traversal-on-document-expected.txt (0 => 184034)
--- trunk/LayoutTests/fast/dom/element-traversal-on-document-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/element-traversal-on-document-expected.txt 2015-05-09 01:14:17 UTC (rev 184034)
@@ -0,0 +1,21 @@
+This test checks the implementation of the element traversal APIs on Document as part of the ParentNode interface.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test with no children
+PASS noChildren.firstElementChild is null
+PASS noChildren.lastElementChild is null
+PASS noChildren.childElementCount is 0
+Test with no element children
+PASS noElementChildren.firstElementChild is null
+PASS noElementChildren.lastElementChild is null
+PASS noElementChildren.childElementCount is 0
+Test with elements
+PASS children.firstElementChild is child
+PASS children.lastElementChild is child
+PASS children.childElementCount is 1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/element-traversal-on-document-fragment-expected.txt (0 => 184034)
--- trunk/LayoutTests/fast/dom/element-traversal-on-document-fragment-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/element-traversal-on-document-fragment-expected.txt 2015-05-09 01:14:17 UTC (rev 184034)
@@ -0,0 +1,21 @@
+This test checks the implementation of the element traversal APIs on DocumentFragment as part of the ParentNode interface.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test with no children
+PASS noChildren.firstElementChild is null
+PASS noChildren.lastElementChild is null
+PASS noChildren.childElementCount is 0
+Test with no element children
+PASS noElementChildren.firstElementChild is null
+PASS noElementChildren.lastElementChild is null
+PASS noElementChildren.childElementCount is 0
+Test with elements
+PASS children.firstElementChild is first
+PASS children.lastElementChild is last
+PASS children.childElementCount is 2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/element-traversal-on-document-fragment.html (0 => 184034)
--- trunk/LayoutTests/fast/dom/element-traversal-on-document-fragment.html (rev 0)
+++ trunk/LayoutTests/fast/dom/element-traversal-on-document-fragment.html 2015-05-09 01:14:17 UTC (rev 184034)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script>
+
+description("This test checks the implementation of the element traversal APIs on DocumentFragment as part of the ParentNode interface.");
+
+debug('Test with no children');
+var noChildren = document.createDocumentFragment();
+shouldBe("noChildren.firstElementChild", "null");
+shouldBe("noChildren.lastElementChild", "null");
+shouldBe("noChildren.childElementCount", "0");
+
+debug('Test with no element children');
+var noElementChildren = document.createDocumentFragment();
+noElementChildren.appendChild(document.createComment("comment but not an element"));
+noElementChildren.appendChild(document.createTextNode("no elements here"));
+
+shouldBe("noElementChildren.firstElementChild", "null");
+shouldBe("noElementChildren.lastElementChild", "null");
+shouldBe("noElementChildren.childElementCount", "0");
+
+debug('Test with elements');
+var children = document.createDocumentFragment();
+children.appendChild(document.createComment("first comment"));
+var first = document.createElement('p');
+children.appendChild(first);
+children.appendChild(document.createComment("a comment"));
+var last = document.createElement('p');
+children.appendChild(last);
+children.appendChild(document.createComment("last comment"));
+
+shouldBe("children.firstElementChild", "first");
+shouldBe("children.lastElementChild", "last");
+shouldBe("children.childElementCount", "2");
+
+</script>
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/fast/dom/element-traversal-on-document.html (0 => 184034)
--- trunk/LayoutTests/fast/dom/element-traversal-on-document.html (rev 0)
+++ trunk/LayoutTests/fast/dom/element-traversal-on-document.html 2015-05-09 01:14:17 UTC (rev 184034)
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script>
+
+description("This test checks the implementation of the element traversal APIs on Document as part of the ParentNode interface.");
+
+function createEmptyDocument()
+{
+ var doc = document.implementation.createHTMLDocument();
+ while (doc.firstChild) {
+ doc.removeChild(doc.firstChild);
+ }
+ return doc;
+}
+
+debug('Test with no children');
+var noChildren = createEmptyDocument();
+shouldBe("noChildren.firstElementChild", "null");
+shouldBe("noChildren.lastElementChild", "null");
+shouldBe("noChildren.childElementCount", "0");
+
+debug('Test with no element children');
+var noElementChildren = createEmptyDocument();
+noElementChildren.appendChild(document.createComment("comment but not an element"));
+
+shouldBe("noElementChildren.firstElementChild", "null");
+shouldBe("noElementChildren.lastElementChild", "null");
+shouldBe("noElementChildren.childElementCount", "0");
+
+debug('Test with elements');
+var children = createEmptyDocument();
+children.appendChild(document.createComment("first comment"));
+var child = document.createElement('p');
+children.appendChild(child);
+children.appendChild(document.createComment("a comment"));
+
+shouldBe("children.firstElementChild", "child");
+shouldBe("children.lastElementChild", "child");
+shouldBe("children.childElementCount", "1");
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (184033 => 184034)
--- trunk/Source/WebCore/ChangeLog 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/ChangeLog 2015-05-09 01:14:17 UTC (rev 184034)
@@ -1,3 +1,56 @@
+2015-05-08 Sam Weinig <[email protected]>
+
+ Element Traversal is not just Elements anymore
+ https://bugs.webkit.org/show_bug.cgi?id=144822
+
+ Reviewed by Simon Fraser.
+
+ Match other browsers and the new DOM spec at https://dom.spec.whatwg.org by
+ exposing the element traversal methods on non-Elements.
+
+ - Makes firstElementChild, lastElementChild and childElementCount available on
+ Document and DocumentFragment in addition to Element.
+ - Makes nextElementSibling and previousElementSibling available on CharacterData
+ in addition to Element.
+
+ Tests: fast/dom/element-traversal-on-character-data.html
+ fast/dom/element-traversal-on-document-fragment.html
+ fast/dom/element-traversal-on-document.html
+
+ * dom/CharacterData.idl:
+ Expose nextElementSibling and previousElementSibling.
+
+ * dom/ContainerNode.cpp:
+ (WebCore::ContainerNode::firstElementChild):
+ (WebCore::ContainerNode::lastElementChild):
+ (WebCore::ContainerNode::childElementCount):
+ * dom/ContainerNode.h:
+ Move implementations of firstElementChild, lastElementChild and childElementCount here
+ from Element to make them shareable.
+
+ * dom/Document.idl:
+ * dom/DocumentFragment.idl:
+ Expose firstElementChild, lastElementChild and childElementCount.
+
+ * dom/Element.cpp:
+ (WebCore::Element::firstElementChild): Deleted.
+ (WebCore::Element::lastElementChild): Deleted.
+ (WebCore::Element::previousElementSibling): Deleted.
+ (WebCore::Element::nextElementSibling): Deleted.
+ (WebCore::Element::childElementCount): Deleted.
+ * dom/Element.h:
+ Move element traversal functions down to Node and ContainerNode.
+
+ * dom/Element.idl:
+ Update comments to indicate where these functions are defined now.
+
+ * dom/Node.cpp:
+ (WebCore::Node::previousElementSibling):
+ (WebCore::Node::nextElementSibling):
+ * dom/Node.h:
+ Move implementations of nextElementSibling and previousElementSibling here
+ from Element to make them shareable.
+
2015-05-08 Michael Catanzaro <[email protected]>, Martin Robinson <[email protected]>
[GTK] Checks for DEVELOPMENT_BUILD are all wrong
Modified: trunk/Source/WebCore/dom/CharacterData.idl (184033 => 184034)
--- trunk/Source/WebCore/dom/CharacterData.idl 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/CharacterData.idl 2015-05-09 01:14:17 UTC (rev 184034)
@@ -37,6 +37,11 @@
[ObjCLegacyUnnamedParameters, RaisesException] void replaceData([IsIndex, Default=Undefined] optional unsigned long offset,
[IsIndex, Default=Undefined] optional unsigned long length,
[Default=Undefined] optional DOMString data);
+
+ // From the NonDocumentTypeChildNode interface - https://dom.spec.whatwg.org/#nondocumenttypechildnode
+ // FIXME: Move this to a seperate NonDocumentTypeChildNode IDL file when one exists.
+ readonly attribute Element previousElementSibling;
+ readonly attribute Element nextElementSibling;
};
CharacterData implements ChildNode;
Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (184033 => 184034)
--- trunk/Source/WebCore/dom/ContainerNode.cpp 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp 2015-05-09 01:14:17 UTC (rev 184034)
@@ -911,4 +911,31 @@
return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, name);
}
+Element* ContainerNode::firstElementChild() const
+{
+ ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
+
+ return ElementTraversal::firstChild(*this);
+}
+
+Element* ContainerNode::lastElementChild() const
+{
+ ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
+
+ return ElementTraversal::lastChild(*this);
+}
+
+unsigned ContainerNode::childElementCount() const
+{
+ ASSERT(is<Document>(*this) || is<DocumentFragment>(*this) || is<Element>(*this));
+
+ unsigned count = 0;
+ Node* n = firstChild();
+ while (n) {
+ count += n->isElementNode();
+ n = n->nextSibling();
+ }
+ return count;
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/ContainerNode.h (184033 => 184034)
--- trunk/Source/WebCore/dom/ContainerNode.h 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/ContainerNode.h 2015-05-09 01:14:17 UTC (rev 184034)
@@ -145,6 +145,11 @@
RefPtr<NodeList> getElementsByClassName(const AtomicString& classNames);
RefPtr<RadioNodeList> radioNodeList(const AtomicString&);
+ // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
+ Element* firstElementChild() const;
+ Element* lastElementChild() const;
+ unsigned childElementCount() const;
+
protected:
explicit ContainerNode(Document&, ConstructionType = CreateContainer);
Modified: trunk/Source/WebCore/dom/Document.idl (184033 => 184034)
--- trunk/Source/WebCore/dom/Document.idl 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/Document.idl 2015-05-09 01:14:17 UTC (rev 184034)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2011, 2015 Apple Inc. All rights reserved.
* Copyright (C) 2006, 2007 Samuel Weinig <[email protected]>
*
* This library is free software; you can redistribute it and/or
@@ -342,6 +342,13 @@
// http://www.w3.org/TR/2014/WD-dom-20140204/#dom-document-origin
readonly attribute DOMString origin;
+ // http://dev.w3.org/csswg/cssom-view/#dom-document-scrollingelement
readonly attribute Element scrollingElement;
+
+ // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
+ // FIXME: Move this to a seperate ParentNode IDL file when one exists.
+ readonly attribute Element firstElementChild;
+ readonly attribute Element lastElementChild;
+ readonly attribute unsigned long childElementCount;
};
Modified: trunk/Source/WebCore/dom/DocumentFragment.idl (184033 => 184034)
--- trunk/Source/WebCore/dom/DocumentFragment.idl 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/DocumentFragment.idl 2015-05-09 01:14:17 UTC (rev 184034)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2008, 2015 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -24,5 +24,11 @@
// NodeSelector - Selector API
[RaisesException] Element querySelector(DOMString selectors);
[RaisesException] NodeList querySelectorAll(DOMString selectors);
+
+ // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
+ // FIXME: Move this to a seperate ParentNode IDL file when one exists.
+ readonly attribute Element firstElementChild;
+ readonly attribute Element lastElementChild;
+ readonly attribute unsigned long childElementCount;
};
Modified: trunk/Source/WebCore/dom/Element.cpp (184033 => 184034)
--- trunk/Source/WebCore/dom/Element.cpp 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/Element.cpp 2015-05-09 01:14:17 UTC (rev 184034)
@@ -2619,38 +2619,6 @@
elementRareData()->setAfterPseudoElement(nullptr);
}
-// ElementTraversal API
-Element* Element::firstElementChild() const
-{
- return ElementTraversal::firstChild(*this);
-}
-
-Element* Element::lastElementChild() const
-{
- return ElementTraversal::lastChild(*this);
-}
-
-Element* Element::previousElementSibling() const
-{
- return ElementTraversal::previousSibling(*this);
-}
-
-Element* Element::nextElementSibling() const
-{
- return ElementTraversal::nextSibling(*this);
-}
-
-unsigned Element::childElementCount() const
-{
- unsigned count = 0;
- Node* n = firstChild();
- while (n) {
- count += n->isElementNode();
- n = n->nextSibling();
- }
- return count;
-}
-
bool Element::matchesReadWritePseudoClass() const
{
return false;
Modified: trunk/Source/WebCore/dom/Element.h (184033 => 184034)
--- trunk/Source/WebCore/dom/Element.h 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/Element.h 2015-05-09 01:14:17 UTC (rev 184034)
@@ -371,13 +371,6 @@
bool childNeedsShadowWalker() const;
void didShadowTreeAwareChildrenChange();
- // ElementTraversal API
- Element* firstElementChild() const;
- Element* lastElementChild() const;
- Element* previousElementSibling() const;
- Element* nextElementSibling() const;
- unsigned childElementCount() const;
-
virtual bool matchesReadWritePseudoClass() const;
bool matches(const String& selectors, ExceptionCode&);
Element* closest(const String& selectors, ExceptionCode&);
Modified: trunk/Source/WebCore/dom/Element.idl (184033 => 184034)
--- trunk/Source/WebCore/dom/Element.idl 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/Element.idl 2015-05-09 01:14:17 UTC (rev 184034)
@@ -127,12 +127,16 @@
[RaisesException] Element closest(DOMString selectors);
[ImplementedAs=matches, RaisesException] boolean webkitMatchesSelector(DOMString selectors);
- // ElementTraversal API
+ // From the ParentNode interface - https://dom.spec.whatwg.org/#interface-parentnode
+ // FIXME: Move this to a seperate ParentNode IDL file when one exists.
readonly attribute Element firstElementChild;
readonly attribute Element lastElementChild;
+ readonly attribute unsigned long childElementCount;
+
+ // From the NonDocumentTypeChildNode interface - https://dom.spec.whatwg.org/#nondocumenttypechildnode
+ // FIXME: Move this to a seperate NonDocumentTypeChildNode IDL file when one exists.
readonly attribute Element previousElementSibling;
readonly attribute Element nextElementSibling;
- readonly attribute unsigned long childElementCount;
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
// CSSOM View Module API
Modified: trunk/Source/WebCore/dom/Node.cpp (184033 => 184034)
--- trunk/Source/WebCore/dom/Node.cpp 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/Node.cpp 2015-05-09 01:14:17 UTC (rev 184034)
@@ -43,6 +43,7 @@
#include "DocumentType.h"
#include "ElementIterator.h"
#include "ElementRareData.h"
+#include "ElementTraversal.h"
#include "EventDispatcher.h"
#include "EventException.h"
#include "EventHandler.h"
@@ -429,6 +430,20 @@
return n;
}
+Element* Node::previousElementSibling() const
+{
+ ASSERT(is<CharacterData>(*this) || is<Element>(*this));
+
+ return ElementTraversal::previousSibling(*this);
+}
+
+Element* Node::nextElementSibling() const
+{
+ ASSERT(is<CharacterData>(*this) || is<Element>(*this));
+
+ return ElementTraversal::nextSibling(*this);
+}
+
bool Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec)
{
if (!is<ContainerNode>(*this)) {
Modified: trunk/Source/WebCore/dom/Node.h (184033 => 184034)
--- trunk/Source/WebCore/dom/Node.h 2015-05-09 00:33:37 UTC (rev 184033)
+++ trunk/Source/WebCore/dom/Node.h 2015-05-09 01:14:17 UTC (rev 184034)
@@ -223,6 +223,10 @@
Node* lastDescendant() const;
Node* firstDescendant() const;
+ // From the NonDocumentTypeChildNode - https://dom.spec.whatwg.org/#nondocumenttypechildnode
+ Element* previousElementSibling() const;
+ Element* nextElementSibling() const;
+
// Other methods (not part of DOM)
bool isElementNode() const { return getFlag(IsElementFlag); }