diff --git a/engine/bindings/scripts/dart_types.py b/engine/bindings/scripts/dart_types.py index caaf17a47977afe573640f127aca17ab63b213a7..ccc4509ee2d7fdadd6845785e5dea4e822452936 100644 --- a/engine/bindings/scripts/dart_types.py +++ b/engine/bindings/scripts/dart_types.py @@ -413,21 +413,10 @@ def dart_value_to_cpp_value_array_or_sequence(native_array_element_type, variabl # and is used to provide a human-readable exception message if index is None: index = 0 # special case, meaning "setter" -# else: -# index += 1 # human-readable index - if (native_array_element_type.is_interface_type): - this_cpp_type = None - ref_ptr_type = 'RefPtr' - # FIXME(vsm): We're not using ref_ptr_type.... - expression_format = '{variable_name} = DartConverter>::FromArguments(args, {index}, exception)' - add_includes_for_type(native_array_element_type) - else: - ref_ptr_type = None - this_cpp_type = native_array_element_type.cpp_type - expression_format = '{variable_name} = DartConverter>::FromArguments(args, {index}, exception)' - + this_cpp_type = native_array_element_type.cpp_type + expression_format = '{variable_name} = DartConverter>::FromArguments(args, {index}, exception)' expression = expression_format.format(native_array_element_type=native_array_element_type.name, - cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, + cpp_type=this_cpp_type, index=index, variable_name=variable_name) return expression diff --git a/engine/core/core.gni b/engine/core/core.gni index 24d23bddb9446eb5def11e0f31ecf224b034f41f..6f2a740fbeefca6de9e67cc01abd390d6a610e7a 100644 --- a/engine/core/core.gni +++ b/engine/core/core.gni @@ -338,7 +338,6 @@ sky_core_files = [ "dom/CharacterData.h", "dom/ChildListMutationScope.cpp", "dom/ChildListMutationScope.h", - "dom/ChildNode.h", "dom/ClientRect.cpp", "dom/ClientRect.h", "dom/ClientRectList.cpp", @@ -458,7 +457,6 @@ sky_core_files = [ "dom/NodeTraversal.cpp", "dom/NodeTraversal.h", "dom/NodeWithIndex.h", - "dom/ParentNode.h", "dom/Position.cpp", "dom/Position.h", "dom/PositionIterator.cpp", @@ -1195,6 +1193,7 @@ core_idl_files = get_path_info([ "dom/MutationRecord.idl", "dom/Node.idl", "dom/NodeList.idl", + "dom/ParentNode.idl", "dom/Range.idl", "dom/RequestAnimationFrameCallback.idl", "dom/shadow/ShadowRoot.idl", @@ -1288,8 +1287,6 @@ core_dependency_idl_files = "animation/DocumentAnimation.idl", "animation/ElementAnimation.idl", "css/DocumentFontFaceSet.idl", - "dom/ChildNode.idl", - "dom/ParentNode.idl", "dom/URLUtils.idl", "dom/URLUtilsReadOnly.idl", "events/EventListener.idl", diff --git a/engine/core/dom/CharacterData.idl b/engine/core/dom/CharacterData.idl index 7132d6de9505d1112aac4904df147358f35aad8d..f75f40ad1bb08f2dc4a6d638eff7160c3fbfd1f5 100644 --- a/engine/core/dom/CharacterData.idl +++ b/engine/core/dom/CharacterData.idl @@ -30,6 +30,3 @@ interface CharacterData : Node { [RaisesException] void deleteData(unsigned long offset, unsigned long length); [RaisesException] void replaceData(unsigned long offset, unsigned long length, DOMString data); }; - -CharacterData implements ChildNode; - diff --git a/engine/core/dom/ChildNode.idl b/engine/core/dom/ChildNode.idl deleted file mode 100644 index ca6fa53266e3187e84544cda9b0d3f28d55e0e65..0000000000000000000000000000000000000000 --- a/engine/core/dom/ChildNode.idl +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. - * Copyright (C) 2006 Samuel Weinig - * Copyright (C) 2013 Samsung Electronics. 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 - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -// http://dom.spec.whatwg.org/#interface-childnode - -[ - LegacyTreatAsPartialInterface, - NoInterfaceObject, // Always used on target of 'implements' -] interface ChildNode { - readonly attribute Element previousElementSibling; - readonly attribute Element nextElementSibling; - [RaisesException, CustomElementCallbacks] void remove(); -}; diff --git a/engine/core/dom/ContainerNode.cpp b/engine/core/dom/ContainerNode.cpp index aaf3be37000e22471a68c2ed4b14ce083790edc2..97f3708d03789a6e8d0fc22c1da1a2f450866ee8 100644 --- a/engine/core/dom/ContainerNode.cpp +++ b/engine/core/dom/ContainerNode.cpp @@ -51,7 +51,7 @@ static void collectChildrenAndRemoveFromOldParent(Node& node, NodeVector& nodes, { if (node.isDocumentFragment()) { DocumentFragment& fragment = toDocumentFragment(node); - getChildNodes(fragment, nodes); + appendChildNodes(fragment, nodes); fragment.removeChildren(); return; } @@ -325,7 +325,7 @@ void ContainerNode::willRemoveChild(Node& child) void ContainerNode::willRemoveChildren() { NodeVector children; - getChildNodes(*this, children); + appendChildNodes(*this, children); ChildListMutationScope mutation(*this); for (NodeVector::const_iterator it = children.begin(); it != children.end(); ++it) { @@ -869,6 +869,72 @@ void ContainerNode::setHovered(bool over) } } +Element* ContainerNode::firstElementChild() const +{ + return ElementTraversal::firstChild(*this); +} + +Element* ContainerNode::lastElementChild() const +{ + return ElementTraversal::lastChild(*this); +} + +Vector> ContainerNode::getChildNodes() const +{ + Vector> result; + for (Node* node = firstChild(); node; node = node->nextSibling()) + result.append(node); + return result; +} + +Vector> ContainerNode::getChildElements() const +{ + Vector> result; + for (Element* element = ElementTraversal::firstWithin(*this); element; element = ElementTraversal::next(*element, this)) + result.append(element); + return result; +} + +void ContainerNode::append(Vector>& nodes, ExceptionState& es) +{ + RefPtr protect(this); + for (auto& node : nodes) { + appendChild(node.release(), es); + if (es.had_exception()) + return; + } +} + +void ContainerNode::prepend(Vector>& nodes, ExceptionState& es) +{ + RefPtr protect(this); + RefPtr refChild = m_firstChild; + for (auto& node : nodes) { + insertBefore(node.release(), refChild.get(), es); + if (es.had_exception()) + return; + } +} + +PassRefPtr ContainerNode::prependChild(PassRefPtr node, ExceptionState& es) +{ + return insertBefore(node, m_firstChild, es); +} + +PassRefPtr ContainerNode::setChild(PassRefPtr node, ExceptionState& es) +{ + RefPtr protect(this); + removeChildren(); + return appendChild(node, es); +} + +void ContainerNode::setChildren(Vector>& nodes, ExceptionState& es) +{ + RefPtr protect(this); + removeChildren(); + append(nodes, es); +} + unsigned ContainerNode::countChildren() const { unsigned count = 0; diff --git a/engine/core/dom/ContainerNode.h b/engine/core/dom/ContainerNode.h index 3c947b2e98eb92052ab6f130eaa800a3f3e9120f..bc9108d363699bf723c811c6a172e21449a29595 100644 --- a/engine/core/dom/ContainerNode.h +++ b/engine/core/dom/ContainerNode.h @@ -43,6 +43,7 @@ const int initialNodeVectorSize = 11; typedef Vector, initialNodeVectorSize> NodeVector; class ContainerNode : public Node { + DEFINE_WRAPPERTYPEINFO(); public: virtual ~ContainerNode(); @@ -50,6 +51,21 @@ public: Node* lastChild() const { return m_lastChild; } bool hasChildren() const { return m_firstChild; } + Element* firstElementChild() const; + Element* lastElementChild() const; + + Vector> getChildNodes() const; + Vector> getChildElements() const; + + // These functions release the nodes from |nodes|. + void append(Vector>& nodes, ExceptionState&); + void prepend(Vector>& nodes, ExceptionState&); + PassRefPtr prependChild(PassRefPtr node, ExceptionState&); + + void removeChildren(); + PassRefPtr setChild(PassRefPtr node, ExceptionState&); + void setChildren(Vector>& nodes, ExceptionState&); + bool hasOneChild() const { return m_firstChild && !m_firstChild->nextSibling(); } bool hasOneTextChild() const { return hasOneChild() && m_firstChild->isTextNode(); } @@ -69,7 +85,6 @@ public: // They don't send DOM mutation events or handle reparenting. void parserAppendChild(PassRefPtr); - void removeChildren(); void cloneChildNodes(ContainerNode* clone); @@ -216,7 +231,7 @@ inline bool Node::isTreeScope() const return &treeScope().rootNode() == this; } -inline void getChildNodes(ContainerNode& node, NodeVector& nodes) +inline void appendChildNodes(ContainerNode& node, NodeVector& nodes) { ASSERT(!nodes.size()); for (Node* child = node.firstChild(); child; child = child->nextSibling()) diff --git a/engine/core/dom/Document.idl b/engine/core/dom/Document.idl index a765e19e7ad0c206c4c0e65c7c463b7fac89c267..e8bd346c0811d53f65c94197a72fdb015c19cfe2 100644 --- a/engine/core/dom/Document.idl +++ b/engine/core/dom/Document.idl @@ -25,7 +25,7 @@ typedef (CanvasRenderingContext2D or WebGLRenderingContext) RenderingContext; [ Constructor(), ConstructorCallWith=Document, -] interface Document : Node { +] interface Document : ParentNode { readonly attribute Element documentElement; [CustomElementCallbacks, RaisesException] Element createElement(DOMString tagName); @@ -75,5 +75,3 @@ typedef (CanvasRenderingContext2D or WebGLRenderingContext) RenderingContext; readonly attribute HTMLScriptElement currentScript; }; - -Document implements ParentNode; diff --git a/engine/core/dom/DocumentFragment.idl b/engine/core/dom/DocumentFragment.idl index 005032a254e262464d636cccd1c2edcc3782e932..febab1d9c4c5345a7b55e65c4309b57a56dd1a40 100644 --- a/engine/core/dom/DocumentFragment.idl +++ b/engine/core/dom/DocumentFragment.idl @@ -20,9 +20,7 @@ [ Constructor, ConstructorCallWith=Document, -] interface DocumentFragment : Node { +] interface DocumentFragment : ParentNode { // NonElementParentNode API. Element getElementById(DOMString elementId); }; - -DocumentFragment implements ParentNode; diff --git a/engine/core/dom/Element.h b/engine/core/dom/Element.h index 4b046b80b0047a8769b49a6b83c17b593d533a58..fbfe3298813c430319c29d7012eaab7957d0288e 100644 --- a/engine/core/dom/Element.h +++ b/engine/core/dom/Element.h @@ -76,6 +76,9 @@ public: bool hasAttribute(const AtomicString& name) const; const AtomicString& getAttribute(const AtomicString& name) const; void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionState&); + void setAttribute(const AtomicString& name, ExceptionState& es) { + setAttribute(name, String(), es); + } void removeAttribute(const AtomicString& name); void removeAttribute(const QualifiedName&); diff --git a/engine/core/dom/Element.idl b/engine/core/dom/Element.idl index 47d4b6952dd45d7abe3aad6877939c85417ffce5..6d7d122aad93b2df793f65cc26af44bc6f85a9cb 100644 --- a/engine/core/dom/Element.idl +++ b/engine/core/dom/Element.idl @@ -1,75 +1,36 @@ -/* - * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. - * Copyright (C) 2006 Samuel Weinig - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -[ - SpecialWrapFor=HTMLElement, -] interface Element : Node { - readonly attribute DOMString? tagName; - - DOMString? getAttribute(DOMString name); - [RaisesException, CustomElementCallbacks] void setAttribute(DOMString name, DOMString value); - [CustomElementCallbacks] void removeAttribute(DOMString name); - boolean hasAttribute(DOMString name); - boolean hasAttributes(); - sequence getAttributes(); - - readonly attribute CSSStyleDeclaration style; - - [Reflect] attribute DOMString id; - readonly attribute DOMString? localName; - - [RaisesException] boolean matches(DOMString selectors); - - readonly attribute long offsetLeft; - readonly attribute long offsetTop; - readonly attribute long offsetWidth; - readonly attribute long offsetHeight; - readonly attribute Element offsetParent; - readonly attribute long clientLeft; - readonly attribute long clientTop; - readonly attribute long clientWidth; - readonly attribute long clientHeight; - - void focus(); - void blur(); - - readonly attribute DOMTokenList classList; - - [RaisesException] ShadowRoot ensureShadowRoot(); - readonly attribute ShadowRoot shadowRoot; - NodeList getDestinationInsertionPoints(); - - // CSSOM View Module API - ClientRectList getClientRects(); - ClientRect getBoundingClientRect(); - - [Reflect] attribute DOMString lang; - attribute DOMString dir; - - [CustomElementCallbacks] attribute long tabIndex; - - [CustomElementCallbacks, RaisesException=Setter] attribute DOMString contentEditable; - readonly attribute boolean isContentEditable; - - attribute boolean spellcheck; +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +interface Element : ParentNode { + readonly attribute DOMString tagName; + + boolean hasAttribute(DOMString name); + [TreatReturnedNullStringAs=Null] DOMString getAttribute(DOMString name); + [RaisesException] void setAttribute(DOMString name, optional DOMString value); + void removeAttribute(DOMString name); + + sequence getAttributes(); + + readonly attribute ShadowRoot shadowRoot; + + // TODO(abarth): Move to Node. + readonly attribute CSSStyleDeclaration style; + + // TODO(abarth): Remove these when we implement more of the system. + [RaisesException] boolean matches(DOMString selectors); + void focus(); + void blur(); + attribute long tabIndex; + readonly attribute DOMTokenList classList; + [RaisesException] ShadowRoot ensureShadowRoot(); + readonly attribute long offsetLeft; + readonly attribute long offsetTop; + readonly attribute long offsetWidth; + readonly attribute long offsetHeight; + readonly attribute Element offsetParent; + readonly attribute long clientLeft; + readonly attribute long clientTop; + readonly attribute long clientWidth; + readonly attribute long clientHeight; }; - -Element implements ParentNode; -Element implements ChildNode; diff --git a/engine/core/dom/Node.cpp b/engine/core/dom/Node.cpp index 6ff1d2c4ee935c46e4b4327b91585d8c90026f4b..60f5fe971ed64e0b8cb02cc43b90f172d971d148 100644 --- a/engine/core/dom/Node.cpp +++ b/engine/core/dom/Node.cpp @@ -379,6 +379,58 @@ PassRefPtr Node::appendChild(PassRefPtr newChild, ExceptionState& ex return nullptr; } +Element* Node::previousElementSibling() +{ + return ElementTraversal::previousSibling(*this); +} + +Element* Node::nextElementSibling() +{ + return ElementTraversal::nextSibling(*this); +} + +void Node::newInsertBefore(Vector>& nodes, ExceptionState& es) +{ + RefPtr parent = parentNode(); + if (!parent) + return; + RefPtr protect(this); + for (auto& node : nodes) { + parent->insertBefore(node.release(), this, es); + if (es.had_exception()) + return; + } +} + +void Node::newInsertAfter(Vector>& nodes, ExceptionState& es) +{ + RefPtr parent = this->parentNode(); + if (!parent) + return; + RefPtr reference = m_next; + for (auto& node : nodes) { + parent->insertBefore(node.release(), reference.get(), es); + if (es.had_exception()) + return; + } +} + +void Node::replaceWith(Vector>& nodes, ExceptionState& es) +{ + RefPtr parent = this->parentNode(); + if (!parent) + return; + RefPtr reference = m_next; + remove(es); + if (es.had_exception()) + return; + for (auto& node : nodes) { + parent->insertBefore(node, reference.get(), es); + if (es.had_exception()) + return; + } +} + void Node::remove(ExceptionState& exceptionState) { if (ContainerNode* parent = parentNode()) @@ -862,7 +914,7 @@ Document* Node::ownerDocument() const return doc == this ? 0 : doc; } -ContainerNode* Node::ownerScope() const +ContainerNode* Node::owner() const { if (inDocument()) return &treeScope().rootNode(); diff --git a/engine/core/dom/Node.h b/engine/core/dom/Node.h index 357b8248eac1fa9d47e5e5607016b5081d0c97be..4518265a9915677e534f3dc13a55d7169e5a2c9d 100644 --- a/engine/core/dom/Node.h +++ b/engine/core/dom/Node.h @@ -144,6 +144,14 @@ public: Node* firstChild() const; Node* lastChild() const; + Element* previousElementSibling(); + Element* nextElementSibling(); + + // These functions release the nodes from |nodes|. + void newInsertBefore(Vector>& nodes, ExceptionState&); + void newInsertAfter(Vector>& nodes, ExceptionState&); + void replaceWith(Vector>& nodes, ExceptionState&); + void remove(ExceptionState&); // These should all actually return a node, but this is only important for language bindings, @@ -340,7 +348,7 @@ public: return *m_treeScope; } - ContainerNode* ownerScope() const; + ContainerNode* owner() const; bool inActiveDocument() const; diff --git a/engine/core/dom/Node.idl b/engine/core/dom/Node.idl index e90583dafa8e496784d7687964458feb89a69ee8..8ed0c1472b60364f0b7b0e42c376ba495146a60e 100644 --- a/engine/core/dom/Node.idl +++ b/engine/core/dom/Node.idl @@ -1,58 +1,25 @@ -/* - * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. - * Copyright (C) 2006 Samuel Weinig - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. -[ - DependentLifetime, -] interface Node : EventTarget { - readonly attribute Node parentNode; - readonly attribute Node firstChild; - readonly attribute Node lastChild; - readonly attribute Node previousSibling; - readonly attribute Node nextSibling; - readonly attribute Document ownerDocument; +interface Node : EventTarget { + // TODO(abarth): This should actually be a named argument. + Node cloneNode(optional boolean deep); - // TODO(esprehn): This should return TreeScope in Sky, but we don't have - // a TreeScope type yet. - readonly attribute Node ownerScope; + readonly attribute ParentNode owner; + readonly attribute ParentNode parentNode; + readonly attribute Element parentElement; - [CustomElementCallbacks, RaisesException, TypeChecking=Interface] Node insertBefore(Node newChild, Node? refChild); - [CustomElementCallbacks, RaisesException, TypeChecking=Interface] Node replaceChild(Node newChild, Node oldChild); - [CustomElementCallbacks, RaisesException, TypeChecking=Interface] Node removeChild(Node oldChild); - [CustomElementCallbacks, RaisesException, TypeChecking=Interface] Node appendChild(Node newChild); + readonly attribute Node nextSibling; + readonly attribute Node previousSibling; + readonly attribute Element nextElementSibling; + readonly attribute Element previousElementSibling; - [ImplementedAs=hasChildren] boolean hasChildNodes(); - [CustomElementCallbacks] Node cloneNode(optional boolean deep); + [RaisesException, ImplementedAs=newInsertBefore] void insertBefore(sequence nodes); + [RaisesException, ImplementedAs=newInsertAfter] void insertAfter(sequence nodes); + [RaisesException] void replaceWith(sequence nodes); - [TreatReturnedNullStringAs=Null, TreatNullAs=NullString, TreatUndefinedAs=NullString, CustomElementCallbacks] attribute DOMString textContent; + [RaisesException] void remove(); - boolean contains(Node other); - - // DocumentPosition - const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; - const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02; - const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; - const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; - const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; - const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; - - unsigned short compareDocumentPosition(Node other); - - readonly attribute Element parentElement; + [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] attribute DOMString textContent; }; diff --git a/engine/core/dom/ParentNode.h b/engine/core/dom/ParentNode.h deleted file mode 100644 index 929dd323c6460b6eddaf6b7252e52862d5fad4cd..0000000000000000000000000000000000000000 --- a/engine/core/dom/ParentNode.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2013 Samsung Electronics. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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. - */ - -#ifndef SKY_ENGINE_CORE_DOM_PARENTNODE_H_ -#define SKY_ENGINE_CORE_DOM_PARENTNODE_H_ - -#include "sky/engine/core/dom/ContainerNode.h" -#include "sky/engine/core/dom/ElementTraversal.h" -#include "sky/engine/platform/heap/Handle.h" - -namespace blink { - -class ParentNode { -public: - static Element* firstElementChild(ContainerNode& node) - { - return ElementTraversal::firstChild(node); - } - - static Element* lastElementChild(ContainerNode& node) - { - return ElementTraversal::lastChild(node); - } - - static unsigned childElementCount(ContainerNode& node) - { - unsigned count = 0; - for (Element* child = ElementTraversal::firstChild(node); child; child = ElementTraversal::nextSibling(*child)) - ++count; - return count; - } - - static PassRefPtr querySelector(ContainerNode& node, const AtomicString& selectors, ExceptionState& exceptionState) - { - return node.querySelector(selectors, exceptionState); - } - - static PassRefPtr querySelectorAll(ContainerNode& node, const AtomicString& selectors, ExceptionState& exceptionState) - { - return node.querySelectorAll(selectors, exceptionState); - } -}; - -} // namespace blink - -#endif // SKY_ENGINE_CORE_DOM_PARENTNODE_H_ diff --git a/engine/core/dom/ParentNode.idl b/engine/core/dom/ParentNode.idl index c153b32a299a6b8ef4c1e7ed560f8261ce02efb8..519ca5076fae6bf89809a98642fb0705e81cb323 100644 --- a/engine/core/dom/ParentNode.idl +++ b/engine/core/dom/ParentNode.idl @@ -1,42 +1,28 @@ -/* - * Copyright (C) 2013 Samsung Electronics. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "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 THE COPYRIGHT - * OWNER 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. - */ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. [ - LegacyTreatAsPartialInterface, - NoInterfaceObject, // Always used on target of 'implements' -] interface ParentNode { - readonly attribute Element firstElementChild; - readonly attribute Element lastElementChild; - readonly attribute unsigned long childElementCount; + ImplementedAs=ContainerNode, +] interface ParentNode : Node { + readonly attribute Node firstChild; + readonly attribute Node lastChild; + readonly attribute Element firstElementChild; + readonly attribute Element lastElementChild; - // NodeSelector - Selector API - [RaisesException] Element querySelector(DOMString selectors); - [RaisesException] NodeList querySelectorAll(DOMString selectors); + sequence getChildNodes(); + sequence getChildElements(); + + [RaisesException] void append(sequence nodes); + [RaisesException] Node appendChild(Node nodes); + [RaisesException] void prepend(sequence nodes); + [RaisesException] Node prependChild(Node nodes); + + void removeChildren(); + [RaisesException] Node setChild(Node node); + [RaisesException] void setChildren(sequence nodes); + + // TODO(abarth): Remove when we have the selector object. + [RaisesException] Element querySelector(DOMString selectors); + [RaisesException] NodeList querySelectorAll(DOMString selectors); }; diff --git a/engine/core/editing/RemoveNodePreservingChildrenCommand.cpp b/engine/core/editing/RemoveNodePreservingChildrenCommand.cpp index 9f991dbc853be6ea6d9b43ec3af37001e7e9ad53..b375646ed466940c3fcf271b8f20956991e13a00 100644 --- a/engine/core/editing/RemoveNodePreservingChildrenCommand.cpp +++ b/engine/core/editing/RemoveNodePreservingChildrenCommand.cpp @@ -43,7 +43,7 @@ void RemoveNodePreservingChildrenCommand::doApply() { if (m_node->isContainerNode()) { NodeVector children; - getChildNodes(toContainerNode(*m_node), children); + appendChildNodes(toContainerNode(*m_node), children); size_t size = children.size(); for (size_t i = 0; i < size; ++i) { diff --git a/engine/core/editing/SplitElementCommand.cpp b/engine/core/editing/SplitElementCommand.cpp index 0c427f4792895ccd562e4f8e240cb16283b15f9c..c9b556094dfa0519a8de95eddc2120d50edb95c4 100644 --- a/engine/core/editing/SplitElementCommand.cpp +++ b/engine/core/editing/SplitElementCommand.cpp @@ -83,7 +83,7 @@ void SplitElementCommand::doUnapply() return; NodeVector children; - getChildNodes(*m_element1, children); + appendChildNodes(*m_element1, children); RefPtr refChild = m_element2->firstChild(); diff --git a/engine/tonic/dart_converter.h b/engine/tonic/dart_converter.h index 381af62d658ed695dffe2463b097070723c7eac5..2982589da56a95b3703c248bfb7d12825e1b16a8 100644 --- a/engine/tonic/dart_converter.h +++ b/engine/tonic/dart_converter.h @@ -248,9 +248,10 @@ struct DartConverter> { Dart_ListLength(handle, &length); result.reserveCapacity(length); for (intptr_t i = 0; i < length; ++i) { - Dart_Handle element = Dart_ListGetAt(handle, i); - DCHECK(!Dart_IsError(element)); - result.append(DartConverter::FromDart(element)); + Dart_Handle item = Dart_ListGetAt(handle, i); + DCHECK(!Dart_IsError(item)); + DCHECK(item); + result.append(DartConverter::FromDart(item)); } return result; } diff --git a/engine/tonic/dart_wrappable.cc b/engine/tonic/dart_wrappable.cc index 6c7e3a15267fff3b4a7c22cbbdb5dafe79cffc24..1bf69d4cf5b023ba6101340539b1f5c3b40edcde 100644 --- a/engine/tonic/dart_wrappable.cc +++ b/engine/tonic/dart_wrappable.cc @@ -50,9 +50,9 @@ void DartWrappable::FinalizeDartWrapper(void* isolate_callback_data, } DartWrappable* DartConverterWrappable::FromDart(Dart_Handle handle) { - intptr_t* peer = 0; + intptr_t peer = 0; Dart_Handle result = - Dart_GetNativeInstanceField(handle, DartWrappable::kPeerIndex, peer); + Dart_GetNativeInstanceField(handle, DartWrappable::kPeerIndex, &peer); if (Dart_IsError(result)) return nullptr; return reinterpret_cast(peer); diff --git a/engine/tonic/dart_wrappable.h b/engine/tonic/dart_wrappable.h index dba0f182b0275aeac62ca01d9b743337791da0a3..f070d7f50576ac9c4690b68f32a1dfc1193bca13 100644 --- a/engine/tonic/dart_wrappable.h +++ b/engine/tonic/dart_wrappable.h @@ -126,6 +126,10 @@ struct DartConverter> { static Dart_Handle ToDart(RefPtr val) { return DartConverter::ToDart(val.get()); } + + static RefPtr FromDart(Dart_Handle handle) { + return DartConverter::FromDart(handle); + } }; template diff --git a/tests/dom/document-child-mutations.sky b/tests/dom/document-child-mutations.sky index 7aecd2b9a27766eb33ff5e000226441d18121ad0..1ffe1eff5c93626c9a44f5b9e82433adb6717c5f 100644 --- a/tests/dom/document-child-mutations.sky +++ b/tests/dom/document-child-mutations.sky @@ -22,7 +22,7 @@ void main() { var oldChild = doc.appendChild(doc.createElement("div")); expect(childElementCount(doc), equals(1)); var newChild = doc.createElement("div"); - doc.replaceChild(newChild, oldChild); + oldChild.replaceWith([newChild]); expect(childElementCount(doc), equals(1)); expect(newChild.parentNode, equals(doc)); expect(oldChild.parentNode, isNull); @@ -33,7 +33,7 @@ void main() { expect(childElementCount(doc), equals(0)); expect(childNodeCount(doc), equals(1)); var newChild = doc.createElement("div"); - doc.replaceChild(newChild, oldChild); + oldChild.replaceWith([newChild]); expect(childElementCount(doc), equals(1)); expect(childNodeCount(doc), equals(1)); expect(newChild.parentNode, equals(doc)); @@ -44,7 +44,7 @@ void main() { var oldChild = doc.appendChild(doc.createElement("div")); expect(childElementCount(doc), equals(1)); var newChild = new Text(" text "); - doc.replaceChild(newChild, oldChild); + oldChild.replaceWith([newChild]); expect(childElementCount(doc), equals(0)); expect(childNodeCount(doc), equals(1)); expect(newChild.parentNode, equals(doc)); @@ -68,7 +68,7 @@ void main() { fragment.appendChild(new Text(" text ")); var newChild = fragment.appendChild(doc.createElement("div")); fragment.appendChild(new Text(" ")); - doc.replaceChild(fragment, oldChild); + oldChild.replaceWith([fragment]); expect(childElementCount(doc), equals(1)); expect(childNodeCount(doc), equals(3)); expect(newChild.parentNode, equals(doc)); diff --git a/tests/dom/ownerScope.sky b/tests/dom/ownerScope.sky index d5793790004d97068ae96b75c134a0377aa91a79..fb163b55aa2ef339c8b8159f401b8c37c9debb5a 100644 --- a/tests/dom/ownerScope.sky +++ b/tests/dom/ownerScope.sky @@ -11,14 +11,13 @@ void main() { test("should return null for elements not a child of a scope", () { var doc = new Document(); var element = doc.createElement("div"); - expect(element.ownerScope, isNull); + expect(element.owner, isNull); }); test("should return the document for elements in the document scope", () { var doc = new Document(); var element = doc.createElement("div"); doc.appendChild(element); - expect(element.ownerScope, equals(element.ownerDocument)); - expect(element.ownerScope, equals(doc)); + expect(element.owner, equals(doc)); }); test("should return the shadow root for elements in the shadow root scope", () { var doc = new Document(); @@ -26,26 +25,26 @@ void main() { var child = doc.createElement("div"); var shadowRoot = host.ensureShadowRoot(); shadowRoot.appendChild(child); - expect(child.ownerScope, equals(shadowRoot)); + expect(child.owner, equals(shadowRoot)); }); test("should return self for a shadow root or document", () { var doc = new Document(); var host = doc.createElement("div"); doc.appendChild(host); var shadowRoot = host.ensureShadowRoot(); - expect(shadowRoot.ownerScope, equals(shadowRoot)); - expect(doc.ownerScope, equals(doc)); + expect(shadowRoot.owner, equals(shadowRoot)); + expect(doc.owner, equals(doc)); }); test("should dynamically update", () { var doc = new Document(); var host = doc.createElement("div"); var child = doc.createElement("div"); var shadowRoot = host.ensureShadowRoot(); - expect(child.ownerScope, isNull); + expect(child.owner, isNull); shadowRoot.appendChild(child); - expect(child.ownerScope, equals(shadowRoot)); + expect(child.owner, equals(shadowRoot)); child.remove(); - expect(child.ownerScope, isNull); + expect(child.owner, isNull); }); } diff --git a/tests/dom/replaceChild-expected.txt b/tests/dom/replaceChild-expected.txt index 41f5ebc94c535ccaae1e4aa477d83f7f0b4f8719..21a0cce4319752df22ba3f188252c10389153d18 100644 --- a/tests/dom/replaceChild-expected.txt +++ b/tests/dom/replaceChild-expected.txt @@ -1,9 +1,8 @@ CONSOLE: unittest-suite-wait-for-done -CONSOLE: PASS: should throw with invalid arguments CONSOLE: PASS: should replace elements CONSOLE: PASS: should replace text CONSOLE: PASS: should replace children with a fragment CONSOLE: -CONSOLE: All 4 tests passed. +CONSOLE: All 3 tests passed. CONSOLE: unittest-suite-success DONE diff --git a/tests/dom/replaceChild.sky b/tests/dom/replaceChild.sky index e1ecef42130d5cf7fb783acfaeb8e7e95cd77094..8342eda84da05a9d9c68445a959443478b7c0a51 100644 --- a/tests/dom/replaceChild.sky +++ b/tests/dom/replaceChild.sky @@ -12,30 +12,11 @@ void main() { var childElementCount = DomUtils.childElementCount; var childNodeCount = DomUtils.childNodeCount; - test("should throw with invalid arguments", () { - var parent = document.createElement("div"); - expect(() { - parent.replaceChild(); - }, throws); - // expect(() { - // parent.replaceChild(null, null); - // }, throws); - expect(() { - parent.replaceChild({tagName: "div"}); - }, throws); - // expect(() { - // parent.replaceChild(null, document.createElement("div")); - // }, throws); - expect(() { - parent.replaceChild(document.createElement("div"), {tagName: "div"}); - }, throws); - }); - test("should replace elements", () { var parent = document.createElement("div"); var oldChild = parent.appendChild(document.createElement("div")); var newChild = document.createElement("div"); - parent.replaceChild(newChild, oldChild); + oldChild.replaceWith([newChild]); expect(oldChild.parentNode, isNull); expect(newChild.parentNode, equals(parent)); }); @@ -44,7 +25,7 @@ void main() { var parent = document.createElement("div"); var oldChild = parent.appendChild(new Text(" it's a text ")); var newChild = document.createElement("div"); - parent.replaceChild(newChild, oldChild); + oldChild.replaceWith([newChild]); expect(oldChild.parentNode, isNull); expect(newChild.parentNode, equals(parent)); }); @@ -58,7 +39,7 @@ void main() { var parent = document.createElement("div"); var oldChild = parent.appendChild(document.createElement("div")); var lastChild = parent.appendChild(document.createElement("div")); - parent.replaceChild(fragment, oldChild); + oldChild.replaceWith([fragment]); expect(child1.parentNode, equals(parent)); expect(child2.parentNode, equals(parent)); expect(child3.parentNode, equals(parent)); diff --git a/tests/editing/delete_block_contents.sky b/tests/editing/delete_block_contents.sky index 8552e9d1e68806e8602104d903d7bccbd58f1c56..d7c041a68d151ddf5d2942af1a0800c37ce20bc8 100644 --- a/tests/editing/delete_block_contents.sky +++ b/tests/editing/delete_block_contents.sky @@ -20,9 +20,7 @@ void main() { d.appendChild(new Text('bbb')); var newHeight = elem.offsetHeight; - while (elem.firstChild != null) { - elem.removeChild(elem.firstChild); - } + elem.removeChildren(); new Timer(Duration.ZERO, expectAsync(() { expect(elem.offsetHeight, equals(originalHeight)); diff --git a/tests/lowlevel/bug-438036.sky b/tests/lowlevel/bug-438036.sky index 35f7815ea8d252469405f5eab3ceea31a41169f6..d18c7dd0d577ae1e5a40a4464958ef7f383ab658 100644 --- a/tests/lowlevel/bug-438036.sky +++ b/tests/lowlevel/bug-438036.sky @@ -26,7 +26,7 @@ void main() { test("should grow height to 200px", () { var target = document.querySelectorAll('div').item(1); - target.id = 'high'; + target.setAttribute("id", "high"); expect(window.getComputedStyle(target).getPropertyValue("height"), equals("200px")); }); diff --git a/tests/lowlevel/query-selector.sky b/tests/lowlevel/query-selector.sky index 64cf473d03810674f232d86e468cbf29750b56f4..502a798fc50ccbd0298f6cf5d0ba4733598a6cf2 100644 --- a/tests/lowlevel/query-selector.sky +++ b/tests/lowlevel/query-selector.sky @@ -36,13 +36,13 @@ main() { test("should find elements by id", () { expect(query("#id5"), isNotNull); - expect(query("#id5").id, equals("id5")); + expect(query("#id5").getAttribute("id"), equals("id5")); expect(query("#id5").classList.toString(), equals("class5")); // FIXME(sky): Do we still want to allow multiple id stuff like this? expect(queryAll("#id5").length, equals(2)); expect(queryAll("#id5").item(0), equals(query("#id5"))); expect(queryAll("#id5").item(1), isNot(equals(query("#id5")))); - expect(queryAll("#id5").item(1).id, equals("id5")); + expect(queryAll("#id5").item(1).getAttribute("id"), equals("id5")); }); test("should find elements by tag name", () { @@ -55,7 +55,7 @@ main() { test("should find an element by compound selector", () { expect(query("tag-name-6.class6#id6"), isNotNull); - expect(query("tag-name-6.class6#id6").id, equals("id6")); + expect(query("tag-name-6.class6#id6").getAttribute("id"), equals("id6")); expect(query("tag-name-6.class6#id6").classList.toString(), equals("class6")); expect(query("tag-name-6.class6#id6").tagName, equals("tag-name-6")); }); @@ -63,21 +63,21 @@ main() { test("should find all elements by compound selector", () { expect(queryAll("tag-name-3.class7"), isNotNull); expect(queryAll("tag-name-3.class7").length, equals(3)); - expect(queryAll("tag-name-3.class7").item(0).id, equals("tag1")); - expect(queryAll("tag-name-3.class7").item(1).id, equals("tag2")); + expect(queryAll("tag-name-3.class7").item(0).getAttribute("id"), equals("tag1")); + expect(queryAll("tag-name-3.class7").item(1).getAttribute("id"), equals("tag2")); }); test("should find all elements by attribute presence selector", () { expect(queryAll("[testAttr]"), isNotNull); expect(queryAll("[testAttr]").length, equals(2)); - expect(queryAll("[testAttr]").item(0).id, equals("id5")); - expect(queryAll("[testAttr]").item(1).id, equals("id6")); + expect(queryAll("[testAttr]").item(0).getAttribute("id"), equals("id5")); + expect(queryAll("[testAttr]").item(1).getAttribute("id"), equals("id6")); }); test("should find all elements by attribute value selector", () { expect(queryAll("[testAttr='the value']"), isNotNull); expect(queryAll("[testAttr='the value']").length, equals(1)); - expect(queryAll("[testAttr='the value']").item(0).id, equals("id6")); + expect(queryAll("[testAttr='the value']").item(0).getAttribute("id"), equals("id6")); }); } diff --git a/tests/lowlevel/style-basic-expected.txt b/tests/lowlevel/style-basic-expected.txt index ad806cfe0ca5f2960178a7c1df098249c171d5a1..6f86aef35e671d59536a5b8dd5eb87d90656ef6a 100644 --- a/tests/lowlevel/style-basic-expected.txt +++ b/tests/lowlevel/style-basic-expected.txt @@ -1,6 +1,6 @@ PASS:
order was 1 -PASS:
order was 2 -PASS: order was 3 -PASS:
order was 4 +PASS:
order was 2 +PASS: order was 3 +PASS:
order was 4 PASS:
order was 5 PASS: order was 6 diff --git a/tests/lowlevel/style-basic.sky b/tests/lowlevel/style-basic.sky index 154dcc8d4d396fd20a1f950bb7a384683a619de8..fdf6b9316892c93b8fd3a1115b0294d17a25b376 100644 --- a/tests/lowlevel/style-basic.sky +++ b/tests/lowlevel/style-basic.sky @@ -26,7 +26,7 @@ var tests = document.getElementById("tests"); var log = document.getElementById("log"); var i = 1; - for (var element = tests.firstElementChild; element != null; element = element.nextElementSibling) { + for (Element element = tests.firstElementChild; element != null; element = element.nextElementSibling) { var order = int.parse(window.getComputedStyle(element).getPropertyValue("order")); var div = document.createElement("div"); var text = (order == i) ? "PASS" : "FAIL"; @@ -34,7 +34,7 @@ + element.tagName + " class=" + element.classList.toString() - + " id=" + element.id + + " id=" + element.getAttribute("id").toString() + "> order was " + order.toString(); if (order != i)