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

Side by Side Diff: third_party/WebKit/Source/core/dom/ContainerNode.cpp

Issue 1511523002: Align HTMLImageElement relevant mutations to spec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix removal issue when a text node is between <source> and <img> Created 5 years 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, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 if (tail) 525 if (tail)
526 tail->setNextSibling(n); 526 tail->setNextSibling(n);
527 else 527 else
528 head = n; 528 head = n;
529 529
530 tail = n; 530 tail = n;
531 } else { 531 } else {
532 RefPtrWillBeRawPtr<Node> protect(n); // removedFromDocument may remo ve all references to this node. 532 RefPtrWillBeRawPtr<Node> protect(n); // removedFromDocument may remo ve all references to this node.
533 container.document().adoptIfNeeded(*n); 533 container.document().adoptIfNeeded(*n);
534 if (n->inDocument()) 534 if (n->inDocument())
535 container.notifyNodeRemoved(*n); 535 container.notifyNodeRemoved(*n, next);
536 } 536 }
537 } 537 }
538 538
539 container.setLastChild(nullptr); 539 container.setLastChild(nullptr);
540 } 540 }
541 #endif 541 #endif
542 542
543 DEFINE_TRACE(ContainerNode) 543 DEFINE_TRACE(ContainerNode)
544 { 544 {
545 visitor->trace(m_firstChild); 545 visitor->trace(m_firstChild);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 exceptionState.throwDOMException(NotFoundError, "The node to be removed is no longer a child of this node. Perhaps it was moved in response to a mutatio n?"); 584 exceptionState.throwDOMException(NotFoundError, "The node to be removed is no longer a child of this node. Perhaps it was moved in response to a mutatio n?");
585 return nullptr; 585 return nullptr;
586 } 586 }
587 587
588 { 588 {
589 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; 589 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates;
590 590
591 Node* prev = child->previousSibling(); 591 Node* prev = child->previousSibling();
592 Node* next = child->nextSibling(); 592 Node* next = child->nextSibling();
593 removeBetween(prev, next, *child); 593 removeBetween(prev, next, *child);
594 notifyNodeRemoved(*child); 594 notifyNodeRemoved(*child, next);
595 childrenChanged(ChildrenChange::forRemoval(*child, prev, next, ChildrenC hangeSourceAPI)); 595 childrenChanged(ChildrenChange::forRemoval(*child, prev, next, ChildrenC hangeSourceAPI));
596 } 596 }
597 dispatchSubtreeModifiedEvent(); 597 dispatchSubtreeModifiedEvent();
598 return child; 598 return child;
599 } 599 }
600 600
601 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol dChild) 601 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol dChild)
602 { 602 {
603 EventDispatchForbiddenScope assertNoEventDispatch; 603 EventDispatchForbiddenScope assertNoEventDispatch;
604 604
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 return; 636 return;
637 637
638 ChildListMutationScope(*this).willRemoveChild(oldChild); 638 ChildListMutationScope(*this).willRemoveChild(oldChild);
639 oldChild.notifyMutationObserversNodeWillDetach(); 639 oldChild.notifyMutationObserversNodeWillDetach();
640 640
641 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; 641 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates;
642 Node* prev = oldChild.previousSibling(); 642 Node* prev = oldChild.previousSibling();
643 Node* next = oldChild.nextSibling(); 643 Node* next = oldChild.nextSibling();
644 removeBetween(prev, next, oldChild); 644 removeBetween(prev, next, oldChild);
645 645
646 notifyNodeRemoved(oldChild); 646 notifyNodeRemoved(oldChild, next);
647 childrenChanged(ChildrenChange::forRemoval(oldChild, prev, next, ChildrenCha ngeSourceParser)); 647 childrenChanged(ChildrenChange::forRemoval(oldChild, prev, next, ChildrenCha ngeSourceParser));
648 } 648 }
649 649
650 // This differs from other remove functions because it forcibly removes all the children, 650 // This differs from other remove functions because it forcibly removes all the children,
651 // regardless of read-only status or event exceptions, e.g. 651 // regardless of read-only status or event exceptions, e.g.
652 void ContainerNode::removeChildren(SubtreeModificationAction action) 652 void ContainerNode::removeChildren(SubtreeModificationAction action)
653 { 653 {
654 if (!m_firstChild) 654 if (!m_firstChild)
655 return; 655 return;
656 656
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; 688 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates;
689 689
690 { 690 {
691 EventDispatchForbiddenScope assertNoEventDispatch; 691 EventDispatchForbiddenScope assertNoEventDispatch;
692 ScriptForbiddenScope forbidScript; 692 ScriptForbiddenScope forbidScript;
693 693
694 #if !ENABLE(OILPAN) 694 #if !ENABLE(OILPAN)
695 removedChildren.reserveInitialCapacity(countChildren()); 695 removedChildren.reserveInitialCapacity(countChildren());
696 #endif 696 #endif
697 while (RefPtrWillBeRawPtr<Node> child = m_firstChild) { 697 while (RefPtrWillBeRawPtr<Node> child = m_firstChild) {
698 removeBetween(0, child->nextSibling(), *child); 698 Node* next = child->nextSibling();
699 removeBetween(nullptr, next, *child);
699 #if !ENABLE(OILPAN) 700 #if !ENABLE(OILPAN)
700 removedChildren.append(child.get()); 701 removedChildren.append(child.get());
701 #endif 702 #endif
702 notifyNodeRemoved(*child); 703 notifyNodeRemoved(*child, next);
703 } 704 }
704 } 705 }
705 706
706 ChildrenChange change = {AllChildrenRemoved, nullptr, nullptr, ChildrenC hangeSourceAPI}; 707 ChildrenChange change = {AllChildrenRemoved, nullptr, nullptr, ChildrenC hangeSourceAPI};
707 childrenChanged(change); 708 childrenChanged(change);
708 } 709 }
709 710
710 if (action == DispatchSubtreeModifiedEvent) 711 if (action == DispatchSubtreeModifiedEvent)
711 dispatchSubtreeModifiedEvent(); 712 dispatchSubtreeModifiedEvent();
712 } 713 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 // into detached subtrees that are not in a shadow tree. 841 // into detached subtrees that are not in a shadow tree.
841 if (!inDocument() && !isInShadowTree() && !node.isContainerNode()) 842 if (!inDocument() && !isInShadowTree() && !node.isContainerNode())
842 continue; 843 continue;
843 if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.inserted Into(this)) 844 if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.inserted Into(this))
844 postInsertionNotificationTargets.append(&node); 845 postInsertionNotificationTargets.append(&node);
845 for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; sha dowRoot = shadowRoot->olderShadowRoot()) 846 for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; sha dowRoot = shadowRoot->olderShadowRoot())
846 notifyNodeInsertedInternal(*shadowRoot, postInsertionNotificationTar gets); 847 notifyNodeInsertedInternal(*shadowRoot, postInsertionNotificationTar gets);
847 } 848 }
848 } 849 }
849 850
850 void ContainerNode::notifyNodeRemoved(Node& root) 851 void ContainerNode::notifyNodeRemoved(Node& root, Node* next)
851 { 852 {
852 ScriptForbiddenScope forbidScript; 853 ScriptForbiddenScope forbidScript;
853 EventDispatchForbiddenScope assertNoEventDispatch; 854 EventDispatchForbiddenScope assertNoEventDispatch;
854 855
855 for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) { 856 for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) {
856 // As an optimization we skip notifying Text nodes and other leaf nodes 857 // As an optimization we skip notifying Text nodes and other leaf nodes
857 // of removal when they're not in the Document tree and not in a shadow root since the virtual 858 // of removal when they're not in the Document tree and not in a shadow root since the virtual
858 // call to removedFrom is not needed. 859 // call to removedFrom is not needed.
859 if (!node.isContainerNode() && !node.isInTreeScope()) 860 if (!node.isContainerNode() && !node.isInTreeScope())
860 continue; 861 continue;
861 node.removedFrom(this); 862 node.removedFrom(this, node == root ? next : node.nextSibling());
esprehn 2015/12/14 22:49:42 Please revert this change, plumbing next through t
862 for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; sha dowRoot = shadowRoot->olderShadowRoot()) 863 for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; sha dowRoot = shadowRoot->olderShadowRoot())
863 notifyNodeRemoved(*shadowRoot); 864 notifyNodeRemoved(*shadowRoot, next);
864 } 865 }
865 } 866 }
866 867
867 void ContainerNode::attach(const AttachContext& context) 868 void ContainerNode::attach(const AttachContext& context)
868 { 869 {
869 attachChildren(context); 870 attachChildren(context);
870 clearChildNeedsStyleRecalc(); 871 clearChildNeedsStyleRecalc();
871 Node::attach(context); 872 Node::attach(context);
872 } 873 }
873 874
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 return true; 1529 return true;
1529 1530
1530 if (node->isElementNode() && toElement(node)->shadow()) 1531 if (node->isElementNode() && toElement(node)->shadow())
1531 return true; 1532 return true;
1532 1533
1533 return false; 1534 return false;
1534 } 1535 }
1535 #endif 1536 #endif
1536 1537
1537 } // namespace blink 1538 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698