OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights
reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights
reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 namespace blink { | 44 namespace blink { |
45 | 45 |
46 #if ENABLE(ASSERT) | 46 #if ENABLE(ASSERT) |
47 unsigned EventDispatchForbiddenScope::s_count = 0; | 47 unsigned EventDispatchForbiddenScope::s_count = 0; |
48 #endif | 48 #endif |
49 | 49 |
50 static void collectChildrenAndRemoveFromOldParent(Node& node, NodeVector& nodes,
ExceptionState& exceptionState) | 50 static void collectChildrenAndRemoveFromOldParent(Node& node, NodeVector& nodes,
ExceptionState& exceptionState) |
51 { | 51 { |
52 if (node.isDocumentFragment()) { | 52 if (node.isDocumentFragment()) { |
53 DocumentFragment& fragment = toDocumentFragment(node); | 53 DocumentFragment& fragment = toDocumentFragment(node); |
54 getChildNodes(fragment, nodes); | 54 appendChildNodes(fragment, nodes); |
55 fragment.removeChildren(); | 55 fragment.removeChildren(); |
56 return; | 56 return; |
57 } | 57 } |
58 nodes.append(&node); | 58 nodes.append(&node); |
59 if (ContainerNode* oldParent = node.parentNode()) | 59 if (ContainerNode* oldParent = node.parentNode()) |
60 oldParent->removeChild(&node, exceptionState); | 60 oldParent->removeChild(&node, exceptionState); |
61 } | 61 } |
62 | 62 |
63 void ContainerNode::removeDetachedChildren() | 63 void ContainerNode::removeDetachedChildren() |
64 { | 64 { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 { | 318 { |
319 ASSERT(child.parentNode() == this); | 319 ASSERT(child.parentNode() == this); |
320 ChildListMutationScope(*this).willRemoveChild(child); | 320 ChildListMutationScope(*this).willRemoveChild(child); |
321 child.notifyMutationObserversNodeWillDetach(); | 321 child.notifyMutationObserversNodeWillDetach(); |
322 document().nodeWillBeRemoved(child); // e.g. mutation event listener can cre
ate a new range. | 322 document().nodeWillBeRemoved(child); // e.g. mutation event listener can cre
ate a new range. |
323 } | 323 } |
324 | 324 |
325 void ContainerNode::willRemoveChildren() | 325 void ContainerNode::willRemoveChildren() |
326 { | 326 { |
327 NodeVector children; | 327 NodeVector children; |
328 getChildNodes(*this, children); | 328 appendChildNodes(*this, children); |
329 | 329 |
330 ChildListMutationScope mutation(*this); | 330 ChildListMutationScope mutation(*this); |
331 for (NodeVector::const_iterator it = children.begin(); it != children.end();
++it) { | 331 for (NodeVector::const_iterator it = children.begin(); it != children.end();
++it) { |
332 ASSERT(*it); | 332 ASSERT(*it); |
333 Node& child = **it; | 333 Node& child = **it; |
334 mutation.willRemoveChild(child); | 334 mutation.willRemoveChild(child); |
335 child.notifyMutationObserversNodeWillDetach(); | 335 child.notifyMutationObserversNodeWillDetach(); |
336 } | 336 } |
337 } | 337 } |
338 | 338 |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 setNeedsStyleRecalc(LocalStyleChange); | 862 setNeedsStyleRecalc(LocalStyleChange); |
863 return; | 863 return; |
864 } | 864 } |
865 | 865 |
866 if (styleChangeType() < SubtreeStyleChange) { | 866 if (styleChangeType() < SubtreeStyleChange) { |
867 if (renderStyle()->affectedByHover()) | 867 if (renderStyle()->affectedByHover()) |
868 setNeedsStyleRecalc(LocalStyleChange); | 868 setNeedsStyleRecalc(LocalStyleChange); |
869 } | 869 } |
870 } | 870 } |
871 | 871 |
| 872 Element* ContainerNode::firstElementChild() const |
| 873 { |
| 874 return ElementTraversal::firstChild(*this); |
| 875 } |
| 876 |
| 877 Element* ContainerNode::lastElementChild() const |
| 878 { |
| 879 return ElementTraversal::lastChild(*this); |
| 880 } |
| 881 |
| 882 Vector<RefPtr<Node>> ContainerNode::getChildNodes() const |
| 883 { |
| 884 Vector<RefPtr<Node>> result; |
| 885 for (Node* node = firstChild(); node; node = node->nextSibling()) |
| 886 result.append(node); |
| 887 return result; |
| 888 } |
| 889 |
| 890 Vector<RefPtr<Element>> ContainerNode::getChildElements() const |
| 891 { |
| 892 Vector<RefPtr<Element>> result; |
| 893 for (Element* element = ElementTraversal::firstWithin(*this); element; eleme
nt = ElementTraversal::next(*element, this)) |
| 894 result.append(element); |
| 895 return result; |
| 896 } |
| 897 |
| 898 void ContainerNode::append(Vector<RefPtr<Node>>& nodes, ExceptionState& es) |
| 899 { |
| 900 RefPtr<ContainerNode> protect(this); |
| 901 for (auto& node : nodes) { |
| 902 appendChild(node.release(), es); |
| 903 if (es.had_exception()) |
| 904 return; |
| 905 } |
| 906 } |
| 907 |
| 908 void ContainerNode::prepend(Vector<RefPtr<Node>>& nodes, ExceptionState& es) |
| 909 { |
| 910 RefPtr<ContainerNode> protect(this); |
| 911 RefPtr<Node> refChild = m_firstChild; |
| 912 for (auto& node : nodes) { |
| 913 insertBefore(node.release(), refChild.get(), es); |
| 914 if (es.had_exception()) |
| 915 return; |
| 916 } |
| 917 } |
| 918 |
| 919 PassRefPtr<Node> ContainerNode::prependChild(PassRefPtr<Node> node, ExceptionSta
te& es) |
| 920 { |
| 921 return insertBefore(node, m_firstChild, es); |
| 922 } |
| 923 |
| 924 PassRefPtr<Node> ContainerNode::setChild(PassRefPtr<Node> node, ExceptionState&
es) |
| 925 { |
| 926 RefPtr<ContainerNode> protect(this); |
| 927 removeChildren(); |
| 928 return appendChild(node, es); |
| 929 } |
| 930 |
| 931 void ContainerNode::setChildren(Vector<RefPtr<Node>>& nodes, ExceptionState& es) |
| 932 { |
| 933 RefPtr<ContainerNode> protect(this); |
| 934 removeChildren(); |
| 935 append(nodes, es); |
| 936 } |
| 937 |
872 unsigned ContainerNode::countChildren() const | 938 unsigned ContainerNode::countChildren() const |
873 { | 939 { |
874 unsigned count = 0; | 940 unsigned count = 0; |
875 Node *n; | 941 Node *n; |
876 for (n = firstChild(); n; n = n->nextSibling()) | 942 for (n = firstChild(); n; n = n->nextSibling()) |
877 count++; | 943 count++; |
878 return count; | 944 return count; |
879 } | 945 } |
880 | 946 |
881 PassRefPtr<Element> ContainerNode::querySelector(const AtomicString& selectors,
ExceptionState& exceptionState) | 947 PassRefPtr<Element> ContainerNode::querySelector(const AtomicString& selectors,
ExceptionState& exceptionState) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 return true; | 1011 return true; |
946 | 1012 |
947 if (node->isElementNode() && toElement(node)->shadow()) | 1013 if (node->isElementNode() && toElement(node)->shadow()) |
948 return true; | 1014 return true; |
949 | 1015 |
950 return false; | 1016 return false; |
951 } | 1017 } |
952 #endif | 1018 #endif |
953 | 1019 |
954 } // namespace blink | 1020 } // namespace blink |
OLD | NEW |