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 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 485 |
486 PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC
hild, ExceptionState& exceptionState) | 486 PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC
hild, ExceptionState& exceptionState) |
487 { | 487 { |
488 if (isContainerNode()) | 488 if (isContainerNode()) |
489 return toContainerNode(this)->appendChild(newChild, exceptionState); | 489 return toContainerNode(this)->appendChild(newChild, exceptionState); |
490 | 490 |
491 exceptionState.throwDOMException(HierarchyRequestError, "This node type does
not support this method."); | 491 exceptionState.throwDOMException(HierarchyRequestError, "This node type does
not support this method."); |
492 return nullptr; | 492 return nullptr; |
493 } | 493 } |
494 | 494 |
495 static bool isNodeInNodes(const Node& node, const HeapVector<NodeOrString>& node
s) | |
496 { | |
497 for (const NodeOrString& nodeOrString : nodes) { | |
498 if (nodeOrString.isNode() && nodeOrString.getAsNode() == &node) | |
499 return true; | |
500 } | |
501 return false; | |
502 } | |
503 | |
504 static Node* findViablePreviousSibling(const Node& node, const HeapVector<NodeOr
String>& nodes) | |
505 { | |
506 for (Node* sibling = node.previousSibling(); sibling; sibling = sibling->pre
viousSibling()) { | |
507 if (!isNodeInNodes(*sibling, nodes)) | |
508 return sibling; | |
509 } | |
510 return nullptr; | |
511 } | |
512 | |
513 static Node* findViableNextSibling(const Node& node, const HeapVector<NodeOrStri
ng>& nodes) | |
514 { | |
515 for (Node* sibling = node.nextSibling(); sibling; sibling = sibling->nextSib
ling()) { | |
516 if (!isNodeInNodes(*sibling, nodes)) | |
517 return sibling; | |
518 } | |
519 return nullptr; | |
520 } | |
521 | |
522 static PassRefPtrWillBeRawPtr<Node> nodeOrStringToNode(const NodeOrString& nodeO
rString, Document& document) | |
523 { | |
524 if (nodeOrString.isNode()) | |
525 return nodeOrString.getAsNode(); | |
526 return Text::create(document, nodeOrString.getAsString()); | |
527 } | |
528 | |
529 static PassRefPtrWillBeRawPtr<Node> convertNodesIntoNode(const HeapVector<NodeOr
String>& nodes, Document& document) | |
530 { | |
531 if (nodes.size() == 1) | |
532 return nodeOrStringToNode(nodes[0], document); | |
533 | |
534 RefPtrWillBeRawPtr<Node> fragment = DocumentFragment::create(document); | |
535 for (const NodeOrString& nodeOrString : nodes) | |
536 fragment->appendChild(nodeOrStringToNode(nodeOrString, document), ASSERT
_NO_EXCEPTION); | |
537 return fragment.release(); | |
538 } | |
539 | |
540 void Node::prepend(const HeapVector<NodeOrString>& nodes, ExceptionState& except
ionState) | |
541 { | |
542 RefPtrWillBeRawPtr<Node> node = convertNodesIntoNode(nodes, document()); | |
543 insertBefore(node, firstChild(), exceptionState); | |
544 } | |
545 | |
546 void Node::append(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti
onState) | |
547 { | |
548 RefPtrWillBeRawPtr<Node> node = convertNodesIntoNode(nodes, document()); | |
549 appendChild(node, exceptionState); | |
550 } | |
551 | |
552 void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti
onState) | |
553 { | |
554 Node* parent = parentNode(); | |
555 if (!parent) | |
556 return; | |
557 Node* viablePreviousSibling = findViablePreviousSibling(*this, nodes); | |
558 RefPtrWillBeRawPtr<Node> node = convertNodesIntoNode(nodes, document()); | |
559 parent->insertBefore(node, viablePreviousSibling ? viablePreviousSibling->ne
xtSibling() : parent->firstChild(), exceptionState); | |
560 } | |
561 | |
562 void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptio
nState) | |
563 { | |
564 Node* parent = parentNode(); | |
565 if (!parent) | |
566 return; | |
567 Node* viableNextSibling = findViableNextSibling(*this, nodes); | |
568 RefPtrWillBeRawPtr<Node> node = convertNodesIntoNode(nodes, document()); | |
569 parent->insertBefore(node, viableNextSibling, exceptionState); | |
570 } | |
571 | |
572 void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& ex
ceptionState) | |
573 { | |
574 Node* parent = parentNode(); | |
575 if (!parent) | |
576 return; | |
577 Node* viableNextSibling = findViableNextSibling(*this, nodes); | |
578 RefPtrWillBeRawPtr<Node> node = convertNodesIntoNode(nodes, document()); | |
579 if (parent == parentNode()) | |
580 parent->replaceChild(node, this, exceptionState); | |
581 else | |
582 parent->insertBefore(node, viableNextSibling, exceptionState); | |
583 } | |
584 | |
585 void Node::remove(ExceptionState& exceptionState) | 495 void Node::remove(ExceptionState& exceptionState) |
586 { | 496 { |
587 if (ContainerNode* parent = parentNode()) | 497 if (ContainerNode* parent = parentNode()) |
588 parent->removeChild(this, exceptionState); | 498 parent->removeChild(this, exceptionState); |
589 } | 499 } |
590 | 500 |
591 void Node::normalize() | 501 void Node::normalize() |
592 { | 502 { |
593 updateDistribution(); | 503 updateDistribution(); |
594 | 504 |
(...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2507 | 2417 |
2508 void showNodePath(const blink::Node* node) | 2418 void showNodePath(const blink::Node* node) |
2509 { | 2419 { |
2510 if (node) | 2420 if (node) |
2511 node->showNodePathForThis(); | 2421 node->showNodePathForThis(); |
2512 else | 2422 else |
2513 fprintf(stderr, "Cannot showNodePath for (nil)\n"); | 2423 fprintf(stderr, "Cannot showNodePath for (nil)\n"); |
2514 } | 2424 } |
2515 | 2425 |
2516 #endif | 2426 #endif |
OLD | NEW |