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

Side by Side Diff: sky/engine/core/dom/Node.cpp

Issue 924203002: Morph the APIs for Node, ParentNode, and Element closer to the specs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 372
373 PassRefPtr<Node> Node::appendChild(PassRefPtr<Node> newChild, ExceptionState& ex ceptionState) 373 PassRefPtr<Node> Node::appendChild(PassRefPtr<Node> newChild, ExceptionState& ex ceptionState)
374 { 374 {
375 if (isContainerNode()) 375 if (isContainerNode())
376 return toContainerNode(this)->appendChild(newChild, exceptionState); 376 return toContainerNode(this)->appendChild(newChild, exceptionState);
377 377
378 exceptionState.ThrowDOMException(HierarchyRequestError, "This node type does not support this method."); 378 exceptionState.ThrowDOMException(HierarchyRequestError, "This node type does not support this method.");
379 return nullptr; 379 return nullptr;
380 } 380 }
381 381
382 Element* Node::previousElementSibling()
383 {
384 return ElementTraversal::previousSibling(*this);
385 }
386
387 Element* Node::nextElementSibling()
388 {
389 return ElementTraversal::nextSibling(*this);
390 }
391
392 void Node::newInsertBefore(Vector<RefPtr<Node>>& nodes, ExceptionState& es)
393 {
394 RefPtr<Node> protect(this);
395 for (auto& node : nodes) {
396 ContainerNode* parent = parentNode();
397 if (!parent)
398 return;
399 parent->insertBefore(node.release(), this, es);
400 if (es.had_exception())
401 return;
402 }
403 }
404
405 void Node::newInsertAfter(Vector<RefPtr<Node>>& nodes, ExceptionState& es)
406 {
407 RefPtr<Node> refNode = this;
408 for (auto& node : nodes) {
eseidel 2015/02/14 00:12:23 Living the dream.
409 ContainerNode* parent = refNode->parentNode();
410 if (!parent)
411 return;
412 parent->insertBefore(node, refNode.get(), es);
413 if (es.had_exception())
414 return;
415 refNode = node.release();
esprehn 2015/02/13 23:53:48 This doesn't look right, why are you reffing and t
abarth-chromium 2015/02/13 23:59:45 The question is how should this code behave if the
esprehn 2015/02/14 01:09:25 There can't be mutations inside this loop.
abarth-chromium 2015/02/14 01:28:26 Ok, I'll change this to ASSERT that.
416 }
417 }
418
419 void Node::replaceWith(Vector<RefPtr<Node>>& nodes, ExceptionState& es)
420 {
421 if (RefPtr<Node> next = m_next) {
422 remove(es);
423 if (es.had_exception())
424 return;
425 next->newInsertBefore(nodes, es);
426 } else if (RefPtr<ContainerNode> parent = parentNode()) {
427 remove(es);
428 if (es.had_exception())
429 return;
430 parent->append(nodes, es);
esprehn 2015/02/13 23:53:48 You don't need this branch, we can just call inser
abarth-chromium 2015/02/13 23:59:45 I don't follow. Which function would you like me
esprehn 2015/02/14 01:09:24 Just always call RefPtr<Node> next = m_next; remo
abarth-chromium 2015/02/14 01:28:26 That doesn't work because |this| isn't a child of
431 }
432 }
433
382 void Node::remove(ExceptionState& exceptionState) 434 void Node::remove(ExceptionState& exceptionState)
383 { 435 {
384 if (ContainerNode* parent = parentNode()) 436 if (ContainerNode* parent = parentNode())
385 parent->removeChild(this, exceptionState); 437 parent->removeChild(this, exceptionState);
386 } 438 }
387 439
388 const AtomicString& Node::localName() const 440 const AtomicString& Node::localName() const
389 { 441 {
390 return nullAtom; 442 return nullAtom;
391 } 443 }
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 907 }
856 908
857 // FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node. 909 // FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node.
858 910
859 Document* Node::ownerDocument() const 911 Document* Node::ownerDocument() const
860 { 912 {
861 Document* doc = &document(); 913 Document* doc = &document();
862 return doc == this ? 0 : doc; 914 return doc == this ? 0 : doc;
863 } 915 }
864 916
865 ContainerNode* Node::ownerScope() const 917 ContainerNode* Node::owner() const
866 { 918 {
867 if (inDocument()) 919 if (inDocument())
868 return &treeScope().rootNode(); 920 return &treeScope().rootNode();
869 if (ShadowRoot* root = containingShadowRoot()) 921 if (ShadowRoot* root = containingShadowRoot())
870 return root; 922 return root;
871 return 0; 923 return 0;
872 } 924 }
873 925
874 String Node::textContent() const 926 String Node::textContent() const
875 { 927 {
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 node->showTreeForThis(); 1662 node->showTreeForThis();
1611 } 1663 }
1612 1664
1613 void showNodePath(const blink::Node* node) 1665 void showNodePath(const blink::Node* node)
1614 { 1666 {
1615 if (node) 1667 if (node)
1616 node->showNodePathForThis(); 1668 node->showNodePathForThis();
1617 } 1669 }
1618 1670
1619 #endif 1671 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698