| 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, 2010, 2011 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
| 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| 11 * License as published by the Free Software Foundation; either | 11 * License as published by the Free Software Foundation; either |
| 12 * version 2 of the License, or (at your option) any later version. | 12 * version 2 of the License, or (at your option) any later version. |
| 13 * | 13 * |
| 14 * This library is distributed in the hope that it will be useful, | 14 * This library is distributed in the hope that it will be useful, |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 * Library General Public License for more details. | 17 * Library General Public License for more details. |
| 18 * | 18 * |
| 19 * You should have received a copy of the GNU Library General Public License | 19 * You should have received a copy of the GNU Library General Public License |
| 20 * along with this library; see the file COPYING.LIB. If not, write to | 20 * along with this library; see the file COPYING.LIB. If not, write to |
| 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 * Boston, MA 02110-1301, USA. | 22 * Boston, MA 02110-1301, USA. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 #include "core/dom/Node.h" | 26 #include "core/dom/Node.h" |
| 27 | 27 |
| 28 #include "HTMLNames.h" | 28 #include "HTMLNames.h" |
| 29 #include "XMLNames.h" | 29 #include "XMLNames.h" |
| 30 #include "bindings/v8/ExceptionMessages.h" | |
| 31 #include "bindings/v8/ExceptionState.h" | 30 #include "bindings/v8/ExceptionState.h" |
| 32 #include "core/accessibility/AXObjectCache.h" | 31 #include "core/accessibility/AXObjectCache.h" |
| 33 #include "core/dom/Attr.h" | 32 #include "core/dom/Attr.h" |
| 34 #include "core/dom/Attribute.h" | 33 #include "core/dom/Attribute.h" |
| 35 #include "core/dom/ChildListMutationScope.h" | 34 #include "core/dom/ChildListMutationScope.h" |
| 36 #include "core/dom/ChildNodeList.h" | 35 #include "core/dom/ChildNodeList.h" |
| 37 #include "core/dom/ClassNodeList.h" | 36 #include "core/dom/ClassNodeList.h" |
| 38 #include "core/dom/DOMImplementation.h" | 37 #include "core/dom/DOMImplementation.h" |
| 39 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 40 #include "core/dom/DocumentFragment.h" | 39 #include "core/dom/DocumentFragment.h" |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 446 } |
| 448 | 447 |
| 449 return lastChild(); | 448 return lastChild(); |
| 450 } | 449 } |
| 451 | 450 |
| 452 void Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionStat
e& exceptionState) | 451 void Node::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionStat
e& exceptionState) |
| 453 { | 452 { |
| 454 if (isContainerNode()) | 453 if (isContainerNode()) |
| 455 toContainerNode(this)->insertBefore(newChild, refChild, exceptionState); | 454 toContainerNode(this)->insertBefore(newChild, refChild, exceptionState); |
| 456 else | 455 else |
| 457 exceptionState.throwDOMException(HierarchyRequestError, ExceptionMessage
s::failedToExecute("insertBefore", "Node", "This node type does not support this
method.")); | 456 exceptionState.throwDOMException(HierarchyRequestError, "This node type
does not support this method."); |
| 458 } | 457 } |
| 459 | 458 |
| 460 void Node::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionStat
e& exceptionState) | 459 void Node::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionStat
e& exceptionState) |
| 461 { | 460 { |
| 462 if (isContainerNode()) | 461 if (isContainerNode()) |
| 463 toContainerNode(this)->replaceChild(newChild, oldChild, exceptionState); | 462 toContainerNode(this)->replaceChild(newChild, oldChild, exceptionState); |
| 464 else | 463 else |
| 465 exceptionState.throwDOMException(HierarchyRequestError, ExceptionMessage
s::failedToExecute("replaceChild", "Node", "This node type does not support this
method.")); | 464 exceptionState.throwDOMException(HierarchyRequestError, "This node type
does not support this method."); |
| 466 } | 465 } |
| 467 | 466 |
| 468 void Node::removeChild(Node* oldChild, ExceptionState& exceptionState) | 467 void Node::removeChild(Node* oldChild, ExceptionState& exceptionState) |
| 469 { | 468 { |
| 470 if (isContainerNode()) | 469 if (isContainerNode()) |
| 471 toContainerNode(this)->removeChild(oldChild, exceptionState); | 470 toContainerNode(this)->removeChild(oldChild, exceptionState); |
| 472 else | 471 else |
| 473 exceptionState.throwDOMException(NotFoundError, ExceptionMessages::faile
dToExecute("removeChild", "Node", "This node type does not support this method."
)); | 472 exceptionState.throwDOMException(NotFoundError, "This node type does not
support this method."); |
| 474 } | 473 } |
| 475 | 474 |
| 476 void Node::appendChild(PassRefPtr<Node> newChild, ExceptionState& exceptionState
) | 475 void Node::appendChild(PassRefPtr<Node> newChild, ExceptionState& exceptionState
) |
| 477 { | 476 { |
| 478 if (isContainerNode()) | 477 if (isContainerNode()) |
| 479 toContainerNode(this)->appendChild(newChild, exceptionState); | 478 toContainerNode(this)->appendChild(newChild, exceptionState); |
| 480 else | 479 else |
| 481 exceptionState.throwDOMException(HierarchyRequestError, ExceptionMessage
s::failedToExecute("appendChild", "Node", "This node type does not support this
method.")); | 480 exceptionState.throwDOMException(HierarchyRequestError, "This node type
does not support this method."); |
| 482 } | 481 } |
| 483 | 482 |
| 484 void Node::remove(ExceptionState& exceptionState) | 483 void Node::remove(ExceptionState& exceptionState) |
| 485 { | 484 { |
| 486 if (ContainerNode* parent = parentNode()) | 485 if (ContainerNode* parent = parentNode()) |
| 487 parent->removeChild(this, exceptionState); | 486 parent->removeChild(this, exceptionState); |
| 488 } | 487 } |
| 489 | 488 |
| 490 void Node::normalize() | 489 void Node::normalize() |
| 491 { | 490 { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 514 { | 513 { |
| 515 // For nodes other than elements and attributes, the prefix is always null | 514 // For nodes other than elements and attributes, the prefix is always null |
| 516 return nullAtom; | 515 return nullAtom; |
| 517 } | 516 } |
| 518 | 517 |
| 519 void Node::setPrefix(const AtomicString& /*prefix*/, ExceptionState& exceptionSt
ate) | 518 void Node::setPrefix(const AtomicString& /*prefix*/, ExceptionState& exceptionSt
ate) |
| 520 { | 519 { |
| 521 // The spec says that for nodes other than elements and attributes, prefix i
s always null. | 520 // The spec says that for nodes other than elements and attributes, prefix i
s always null. |
| 522 // It does not say what to do when the user tries to set the prefix on anoth
er type of | 521 // It does not say what to do when the user tries to set the prefix on anoth
er type of |
| 523 // node, however Mozilla throws a NamespaceError exception. | 522 // node, however Mozilla throws a NamespaceError exception. |
| 524 exceptionState.throwDOMException(NamespaceError, ExceptionMessages::failedTo
Set("prefix", "Node", "Prefixes are only supported on element and attribute node
s.")); | 523 exceptionState.throwDOMException(NamespaceError, "Prefixes are only supporte
d on element and attribute nodes."); |
| 525 } | 524 } |
| 526 | 525 |
| 527 const AtomicString& Node::localName() const | 526 const AtomicString& Node::localName() const |
| 528 { | 527 { |
| 529 return nullAtom; | 528 return nullAtom; |
| 530 } | 529 } |
| 531 | 530 |
| 532 const AtomicString& Node::namespaceURI() const | 531 const AtomicString& Node::namespaceURI() const |
| 533 { | 532 { |
| 534 return nullAtom; | 533 return nullAtom; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 { | 830 { |
| 832 rareData()->clearNodeLists(); | 831 rareData()->clearNodeLists(); |
| 833 } | 832 } |
| 834 | 833 |
| 835 void Node::checkSetPrefix(const AtomicString& prefix, ExceptionState& exceptionS
tate) | 834 void Node::checkSetPrefix(const AtomicString& prefix, ExceptionState& exceptionS
tate) |
| 836 { | 835 { |
| 837 // Perform error checking as required by spec for setting Node.prefix. Used
by | 836 // Perform error checking as required by spec for setting Node.prefix. Used
by |
| 838 // Element::setPrefix() and Attr::setPrefix() | 837 // Element::setPrefix() and Attr::setPrefix() |
| 839 | 838 |
| 840 if (!prefix.isEmpty() && !Document::isValidName(prefix)) { | 839 if (!prefix.isEmpty() && !Document::isValidName(prefix)) { |
| 841 exceptionState.throwDOMException(InvalidCharacterError, ExceptionMessage
s::failedToSet("prefix", "Node", "The prefix '" + prefix + "' is not a valid nam
e.")); | 840 exceptionState.throwDOMException(InvalidCharacterError, "The prefix '" +
prefix + "' is not a valid name."); |
| 842 return; | 841 return; |
| 843 } | 842 } |
| 844 | 843 |
| 845 // FIXME: Raise NamespaceError if prefix is malformed per the Namespaces in
XML specification. | 844 // FIXME: Raise NamespaceError if prefix is malformed per the Namespaces in
XML specification. |
| 846 | 845 |
| 847 const AtomicString& nodeNamespaceURI = namespaceURI(); | 846 const AtomicString& nodeNamespaceURI = namespaceURI(); |
| 848 if (nodeNamespaceURI.isEmpty() && !prefix.isEmpty()) { | 847 if (nodeNamespaceURI.isEmpty() && !prefix.isEmpty()) { |
| 849 exceptionState.throwDOMException(NamespaceError, ExceptionMessages::fail
edToSet("prefix", "Node", "No namespace is set, so a namespace prefix may not be
set.")); | 848 exceptionState.throwDOMException(NamespaceError, "No namespace is set, s
o a namespace prefix may not be set."); |
| 850 return; | 849 return; |
| 851 } | 850 } |
| 852 | 851 |
| 853 if (prefix == xmlAtom && nodeNamespaceURI != XMLNames::xmlNamespaceURI) { | 852 if (prefix == xmlAtom && nodeNamespaceURI != XMLNames::xmlNamespaceURI) { |
| 854 exceptionState.throwDOMException(NamespaceError, ExceptionMessages::fail
edToSet("prefix", "Node", "The prefix '" + xmlAtom + "' may not be set on namesp
ace '" + nodeNamespaceURI + "'.")); | 853 exceptionState.throwDOMException(NamespaceError, "The prefix '" + xmlAto
m + "' may not be set on namespace '" + nodeNamespaceURI + "'."); |
| 855 return; | 854 return; |
| 856 } | 855 } |
| 857 // Attribute-specific checks are in Attr::setPrefix(). | 856 // Attribute-specific checks are in Attr::setPrefix(). |
| 858 } | 857 } |
| 859 | 858 |
| 860 bool Node::isDescendantOf(const Node *other) const | 859 bool Node::isDescendantOf(const Node *other) const |
| 861 { | 860 { |
| 862 // Return true if other is an ancestor of this, otherwise false | 861 // Return true if other is an ancestor of this, otherwise false |
| 863 if (!other || !other->hasChildNodes() || inDocument() != other->inDocument()
) | 862 if (!other || !other->hasChildNodes() || inDocument() != other->inDocument()
) |
| 864 return false; | 863 return false; |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 | 1279 |
| 1281 PassRefPtr<RadioNodeList> Node::radioNodeList(const AtomicString& name) | 1280 PassRefPtr<RadioNodeList> Node::radioNodeList(const AtomicString& name) |
| 1282 { | 1281 { |
| 1283 ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag)); | 1282 ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag)); |
| 1284 return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeLi
st>(this, RadioNodeListType, name); | 1283 return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeLi
st>(this, RadioNodeListType, name); |
| 1285 } | 1284 } |
| 1286 | 1285 |
| 1287 PassRefPtr<Element> Node::querySelector(const AtomicString& selectors, Exception
State& exceptionState) | 1286 PassRefPtr<Element> Node::querySelector(const AtomicString& selectors, Exception
State& exceptionState) |
| 1288 { | 1287 { |
| 1289 if (selectors.isEmpty()) { | 1288 if (selectors.isEmpty()) { |
| 1290 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT
oExecute("querySelector", "Node", "The provided selector is empty.")); | 1289 exceptionState.throwDOMException(SyntaxError, "The provided selector is
empty."); |
| 1291 return 0; | 1290 return 0; |
| 1292 } | 1291 } |
| 1293 | 1292 |
| 1294 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors
, document(), exceptionState); | 1293 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors
, document(), exceptionState); |
| 1295 if (!selectorQuery) | 1294 if (!selectorQuery) |
| 1296 return 0; | 1295 return 0; |
| 1297 return selectorQuery->queryFirst(*this); | 1296 return selectorQuery->queryFirst(*this); |
| 1298 } | 1297 } |
| 1299 | 1298 |
| 1300 PassRefPtr<NodeList> Node::querySelectorAll(const AtomicString& selectors, Excep
tionState& exceptionState) | 1299 PassRefPtr<NodeList> Node::querySelectorAll(const AtomicString& selectors, Excep
tionState& exceptionState) |
| 1301 { | 1300 { |
| 1302 if (selectors.isEmpty()) { | 1301 if (selectors.isEmpty()) { |
| 1303 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT
oExecute("querySelectorAll", "Node", "The provided selector is empty.")); | 1302 exceptionState.throwDOMException(SyntaxError, "The provided selector is
empty."); |
| 1304 return 0; | 1303 return 0; |
| 1305 } | 1304 } |
| 1306 | 1305 |
| 1307 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors
, document(), exceptionState); | 1306 SelectorQuery* selectorQuery = document().selectorQueryCache().add(selectors
, document(), exceptionState); |
| 1308 if (!selectorQuery) | 1307 if (!selectorQuery) |
| 1309 return 0; | 1308 return 0; |
| 1310 return selectorQuery->queryAll(*this); | 1309 return selectorQuery->queryAll(*this); |
| 1311 } | 1310 } |
| 1312 | 1311 |
| 1313 Document* Node::ownerDocument() const | 1312 Document* Node::ownerDocument() const |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2671 node->showTreeForThis(); | 2670 node->showTreeForThis(); |
| 2672 } | 2671 } |
| 2673 | 2672 |
| 2674 void showNodePath(const WebCore::Node* node) | 2673 void showNodePath(const WebCore::Node* node) |
| 2675 { | 2674 { |
| 2676 if (node) | 2675 if (node) |
| 2677 node->showNodePathForThis(); | 2676 node->showNodePathForThis(); |
| 2678 } | 2677 } |
| 2679 | 2678 |
| 2680 #endif | 2679 #endif |
| OLD | NEW |