Chromium Code Reviews| 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 appendChild(convertNodesIntoNode(nodes, document()), exceptionState); | |
|
philipj_slow
2015/07/09 14:48:45
Can you make the same change here for consistency?
| |
| 549 } | |
| 550 | |
| 551 void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState) | |
| 552 { | |
| 553 Node* parent = parentNode(); | |
| 554 if (!parent) | |
| 555 return; | |
| 556 Node* viablePreviousSibling = findViablePreviousSibling(*this, nodes); | |
| 557 RefPtrWillBeRawPtr<Node> node = convertNodesIntoNode(nodes, document()); | |
| 558 parent->insertBefore(node, viablePreviousSibling ? viablePreviousSibling->ne xtSibling() : parent->firstChild(), exceptionState); | |
| 559 } | |
| 560 | |
| 561 void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptio nState) | |
| 562 { | |
| 563 Node* parent = parentNode(); | |
| 564 if (!parent) | |
| 565 return; | |
| 566 Node* viableNextSibling = findViableNextSibling(*this, nodes); | |
| 567 parent->insertBefore(convertNodesIntoNode(nodes, document()), viableNextSibl ing, exceptionState); | |
|
philipj_slow
2015/07/09 14:48:45
And here.
| |
| 568 } | |
| 569 | |
| 570 void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& ex ceptionState) | |
| 571 { | |
| 572 Node* parent = parentNode(); | |
| 573 if (!parent) | |
| 574 return; | |
| 575 Node* viableNextSibling = findViableNextSibling(*this, nodes); | |
| 576 RefPtrWillBeRawPtr<Node> node = convertNodesIntoNode(nodes, document()); | |
| 577 if (parent == parentNode()) | |
| 578 parent->replaceChild(node, this, exceptionState); | |
| 579 else | |
| 580 parent->insertBefore(node, viableNextSibling, exceptionState); | |
| 581 } | |
| 582 | |
| 495 void Node::remove(ExceptionState& exceptionState) | 583 void Node::remove(ExceptionState& exceptionState) |
| 496 { | 584 { |
| 497 if (ContainerNode* parent = parentNode()) | 585 if (ContainerNode* parent = parentNode()) |
| 498 parent->removeChild(this, exceptionState); | 586 parent->removeChild(this, exceptionState); |
| 499 } | 587 } |
| 500 | 588 |
| 501 void Node::normalize() | 589 void Node::normalize() |
| 502 { | 590 { |
| 503 updateDistribution(); | 591 updateDistribution(); |
| 504 | 592 |
| (...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2417 | 2505 |
| 2418 void showNodePath(const blink::Node* node) | 2506 void showNodePath(const blink::Node* node) |
| 2419 { | 2507 { |
| 2420 if (node) | 2508 if (node) |
| 2421 node->showNodePathForThis(); | 2509 node->showNodePathForThis(); |
| 2422 else | 2510 else |
| 2423 fprintf(stderr, "Cannot showNodePath for (nil)\n"); | 2511 fprintf(stderr, "Cannot showNodePath for (nil)\n"); |
| 2424 } | 2512 } |
| 2425 | 2513 |
| 2426 #endif | 2514 #endif |
| OLD | NEW |