Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: Source/core/dom/Node.cpp

Issue 1085843002: Implement DOM: prepend, append, before, after & replaceWith (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 LayoutObject* layoutObject = m_data.m_rareData->layoutObject(); 375 LayoutObject* layoutObject = m_data.m_rareData->layoutObject();
376 if (isElementNode()) 376 if (isElementNode())
377 delete static_cast<ElementRareData*>(m_data.m_rareData); 377 delete static_cast<ElementRareData*>(m_data.m_rareData);
378 else 378 else
379 delete static_cast<NodeRareData*>(m_data.m_rareData); 379 delete static_cast<NodeRareData*>(m_data.m_rareData);
380 m_data.m_layoutObject = layoutObject; 380 m_data.m_layoutObject = layoutObject;
381 clearFlag(HasRareDataFlag); 381 clearFlag(HasRareDataFlag);
382 } 382 }
383 #endif 383 #endif
384 384
385 PassRefPtrWillBeRawPtr<Node> Node::mutationMethodMacro(const HeapVector<NodeOrSt ring>& nodes)
386 {
387 RefPtrWillBeRawPtr<Node> node;
388 if (nodes.size() == 1) {
philipj_slow 2015/06/09 12:48:32 If the bindings guarantees that nodes.size()!=0 he
Paritosh Kumar 2015/06/12 15:55:37 Updated as per new specs.
389 if (nodes[0].isNode())
390 node = nodes[0].getAsNode();
391 else
392 node = Text::create(document(), nodes[0].getAsString());
393 } else {
394 node = DocumentFragment::create(document());
395 for (const NodeOrString& nodeOrString : nodes) {
396 if (nodeOrString.isNode())
397 node->appendChild(nodeOrString.getAsNode(), ASSERT_NO_EXCEPTION) ;
398 else
399 node->appendChild(Text::create(document(), nodeOrString.getAsStr ing()), ASSERT_NO_EXCEPTION);
400 }
401 }
402 return node.release();
403 }
404
385 Node* Node::toNode() 405 Node* Node::toNode()
386 { 406 {
387 return this; 407 return this;
388 } 408 }
389 409
390 short Node::tabIndex() const 410 short Node::tabIndex() const
391 { 411 {
392 return 0; 412 return 0;
393 } 413 }
394 414
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 514
495 PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC hild, ExceptionState& exceptionState) 515 PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC hild, ExceptionState& exceptionState)
496 { 516 {
497 if (isContainerNode()) 517 if (isContainerNode())
498 return toContainerNode(this)->appendChild(newChild, exceptionState); 518 return toContainerNode(this)->appendChild(newChild, exceptionState);
499 519
500 exceptionState.throwDOMException(HierarchyRequestError, "This node type does not support this method."); 520 exceptionState.throwDOMException(HierarchyRequestError, "This node type does not support this method.");
501 return nullptr; 521 return nullptr;
502 } 522 }
503 523
524 void Node::prepend(const HeapVector<NodeOrString>& nodes, ExceptionState& except ionState)
525 {
526 RefPtrWillBeRawPtr<Node> nodeToPrepend = mutationMethodMacro(nodes);
527 this->insertBefore(nodeToPrepend, this->firstChild(), exceptionState);
528 }
529
530 void Node::append(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState)
531 {
532 RefPtrWillBeRawPtr<Node> nodeToAppend = mutationMethodMacro(nodes);
533 this->appendChild(nodeToAppend, exceptionState);
534 }
535
536 void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState)
537 {
538 Node* parent = parentNode();
539 if (!parent)
540 return;
541 RefPtrWillBeRawPtr<Node> nodeToInsert = mutationMethodMacro(nodes);
542 parent->insertBefore(nodeToInsert, this, exceptionState);
543 }
544
545 void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptio nState)
546 {
547 Node* parent = parentNode();
548 if (!parent)
549 return;
550 RefPtrWillBeRawPtr<Node> nodeToInsert = mutationMethodMacro(nodes);
551 parent->insertBefore(nodeToInsert, this->nextSibling(), exceptionState);
552 }
553
554 void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& ex ceptionState)
555 {
556 Node* parent = parentNode();
557 if (!parent)
558 return;
559 RefPtrWillBeRawPtr<Node> nodeToReplaceWith = mutationMethodMacro(nodes);
560 parent->replaceChild(nodeToReplaceWith, this, exceptionState);
561 }
562
504 void Node::remove(ExceptionState& exceptionState) 563 void Node::remove(ExceptionState& exceptionState)
505 { 564 {
506 if (ContainerNode* parent = parentNode()) 565 if (ContainerNode* parent = parentNode())
507 parent->removeChild(this, exceptionState); 566 parent->removeChild(this, exceptionState);
508 } 567 }
509 568
510 void Node::normalize() 569 void Node::normalize()
511 { 570 {
512 updateDistribution(); 571 updateDistribution();
513 572
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 2561
2503 void showNodePath(const blink::Node* node) 2562 void showNodePath(const blink::Node* node)
2504 { 2563 {
2505 if (node) 2564 if (node)
2506 node->showNodePathForThis(); 2565 node->showNodePathForThis();
2507 else 2566 else
2508 fprintf(stderr, "Cannot showNodePath for (nil)\n"); 2567 fprintf(stderr, "Cannot showNodePath for (nil)\n");
2509 } 2568 }
2510 2569
2511 #endif 2570 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698