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, 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 return nullptr; | 562 return nullptr; |
563 } | 563 } |
564 | 564 |
565 { | 565 { |
566 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; | 566 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; |
567 | 567 |
568 Node* prev = child->previousSibling(); | 568 Node* prev = child->previousSibling(); |
569 Node* next = child->nextSibling(); | 569 Node* next = child->nextSibling(); |
570 removeBetween(prev, next, *child); | 570 removeBetween(prev, next, *child); |
571 notifyNodeRemoved(*child); | 571 notifyNodeRemoved(*child); |
572 ChildrenChange change = {ChildRemoved, prev, next, ChildrenChangeSourceA
PI}; | 572 childrenChanged(ChildrenChange::forRemoval(*child, prev, next, ChildrenC
hangeSourceAPI)); |
573 childrenChanged(change); | |
574 } | 573 } |
575 dispatchSubtreeModifiedEvent(); | 574 dispatchSubtreeModifiedEvent(); |
576 return child; | 575 return child; |
577 } | 576 } |
578 | 577 |
579 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol
dChild) | 578 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol
dChild) |
580 { | 579 { |
581 NoEventDispatchAssertion assertNoEventDispatch; | 580 NoEventDispatchAssertion assertNoEventDispatch; |
582 | 581 |
583 ASSERT(oldChild.parentNode() == this); | 582 ASSERT(oldChild.parentNode() == this); |
(...skipping 25 matching lines...) Expand all Loading... |
609 Node* prev = oldChild.previousSibling(); | 608 Node* prev = oldChild.previousSibling(); |
610 Node* next = oldChild.nextSibling(); | 609 Node* next = oldChild.nextSibling(); |
611 | 610 |
612 oldChild.updateAncestorConnectedSubframeCountForRemoval(); | 611 oldChild.updateAncestorConnectedSubframeCountForRemoval(); |
613 | 612 |
614 ChildListMutationScope(*this).willRemoveChild(oldChild); | 613 ChildListMutationScope(*this).willRemoveChild(oldChild); |
615 oldChild.notifyMutationObserversNodeWillDetach(); | 614 oldChild.notifyMutationObserversNodeWillDetach(); |
616 | 615 |
617 removeBetween(prev, next, oldChild); | 616 removeBetween(prev, next, oldChild); |
618 | 617 |
619 ChildrenChange change = {ChildRemoved, prev, next, ChildrenChangeSourceParse
r}; | |
620 notifyNodeRemoved(oldChild); | 618 notifyNodeRemoved(oldChild); |
621 childrenChanged(change); | 619 childrenChanged(ChildrenChange::forRemoval(oldChild, prev, next, ChildrenCha
ngeSourceParser)); |
622 } | 620 } |
623 | 621 |
624 // this differs from other remove functions because it forcibly removes all the
children, | 622 // this differs from other remove functions because it forcibly removes all the
children, |
625 // regardless of read-only status or event exceptions, e.g. | 623 // regardless of read-only status or event exceptions, e.g. |
626 void ContainerNode::removeChildren() | 624 void ContainerNode::removeChildren() |
627 { | 625 { |
628 if (!m_firstChild) | 626 if (!m_firstChild) |
629 return; | 627 return; |
630 | 628 |
631 // The container node can be removed from event handlers. | 629 // The container node can be removed from event handlers. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 ASSERT(!root.isShadowRoot()); | 776 ASSERT(!root.isShadowRoot()); |
779 | 777 |
780 InspectorInstrumentation::didInsertDOMNode(&root); | 778 InspectorInstrumentation::didInsertDOMNode(&root); |
781 | 779 |
782 RefPtrWillBeRawPtr<Node> protect(this); | 780 RefPtrWillBeRawPtr<Node> protect(this); |
783 RefPtrWillBeRawPtr<Node> protectNode(root); | 781 RefPtrWillBeRawPtr<Node> protectNode(root); |
784 | 782 |
785 NodeVector postInsertionNotificationTargets; | 783 NodeVector postInsertionNotificationTargets; |
786 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); | 784 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); |
787 | 785 |
788 ChildrenChange change = {ChildInserted, root.previousSibling(), root.nextSib
ling(), source}; | 786 childrenChanged(ChildrenChange::forInsertion(root, source)); |
789 childrenChanged(change); | |
790 | 787 |
791 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { | 788 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { |
792 Node* targetNode = postInsertionNotificationTargets[i].get(); | 789 Node* targetNode = postInsertionNotificationTargets[i].get(); |
793 if (targetNode->inDocument()) | 790 if (targetNode->inDocument()) |
794 targetNode->didNotifySubtreeInsertionsToDocument(); | 791 targetNode->didNotifySubtreeInsertionsToDocument(); |
795 } | 792 } |
796 } | 793 } |
797 | 794 |
798 void ContainerNode::notifyNodeInsertedInternal(Node& root, NodeVector& postInser
tionNotificationTargets) | 795 void ContainerNode::notifyNodeInsertedInternal(Node& root, NodeVector& postInser
tionNotificationTargets) |
799 { | 796 { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 clearChildNeedsStyleRecalc(); | 842 clearChildNeedsStyleRecalc(); |
846 Node::detach(context); | 843 Node::detach(context); |
847 } | 844 } |
848 | 845 |
849 void ContainerNode::childrenChanged(const ChildrenChange& change) | 846 void ContainerNode::childrenChanged(const ChildrenChange& change) |
850 { | 847 { |
851 document().incDOMTreeVersion(); | 848 document().incDOMTreeVersion(); |
852 if (!change.byParser && change.type != TextChanged) | 849 if (!change.byParser && change.type != TextChanged) |
853 document().updateRangesAfterChildrenChanged(this); | 850 document().updateRangesAfterChildrenChanged(this); |
854 invalidateNodeListCachesInAncestors(); | 851 invalidateNodeListCachesInAncestors(); |
855 if (change.type == ChildInserted && !childNeedsStyleRecalc()) { | 852 if (change.isChildInsertion() && !childNeedsStyleRecalc()) { |
856 setChildNeedsStyleRecalc(); | 853 setChildNeedsStyleRecalc(); |
857 markAncestorsWithChildNeedsStyleRecalc(); | 854 markAncestorsWithChildNeedsStyleRecalc(); |
858 } | 855 } |
859 } | 856 } |
860 | 857 |
861 void ContainerNode::cloneChildNodes(ContainerNode *clone) | 858 void ContainerNode::cloneChildNodes(ContainerNode *clone) |
862 { | 859 { |
863 TrackExceptionState exceptionState; | 860 TrackExceptionState exceptionState; |
864 for (Node* n = firstChild(); n && !exceptionState.hadException(); n = n->nex
tSibling()) | 861 for (Node* n = firstChild(); n && !exceptionState.hadException(); n = n->nex
tSibling()) |
865 clone->appendChild(n->cloneNode(true), exceptionState); | 862 clone->appendChild(n->cloneNode(true), exceptionState); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 ASSERT(changeType != FinishedParsingChildren); | 1264 ASSERT(changeType != FinishedParsingChildren); |
1268 // Find our new first child element. | 1265 // Find our new first child element. |
1269 Element* firstChildElement = ElementTraversal::firstChild(*this); | 1266 Element* firstChildElement = ElementTraversal::firstChild(*this); |
1270 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem
ent->renderStyle() : 0; | 1267 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem
ent->renderStyle() : 0; |
1271 | 1268 |
1272 // Find the first element after the change. | 1269 // Find the first element after the change. |
1273 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme
nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange); | 1270 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme
nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange); |
1274 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter
Change->renderStyle() : 0; | 1271 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter
Change->renderStyle() : 0; |
1275 | 1272 |
1276 // This is the element insertion as first child element case. | 1273 // This is the element insertion as first child element case. |
1277 if (firstChildElement != elementAfterChange && elementAfterChangeStyle &
& elementAfterChangeStyle->firstChildState()) | 1274 if (firstChildElement != elementAfterChange && elementAfterChangeStyle &
& elementAfterChangeStyle->firstChildState()) { |
| 1275 ASSERT(changeType == SiblingElementInserted); |
1278 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); | 1276 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1277 } |
1279 | 1278 |
1280 // This is the first child element removal case. | 1279 // This is the first child element removal case. |
1281 if (changeType == SiblingRemoved && firstChildElement == elementAfterCha
nge && firstChildElement && (!firstChildElementStyle || !firstChildElementStyle-
>firstChildState())) | 1280 if (changeType == SiblingElementRemoved && firstChildElement == elementA
fterChange && firstChildElement && (!firstChildElementStyle || !firstChildElemen
tStyle->firstChildState())) |
1282 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange); | 1281 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange); |
1283 } | 1282 } |
1284 | 1283 |
1285 // :last-child. In the parser callback case, we don't have to check anything
, since we were right the first time. | 1284 // :last-child. In the parser callback case, we don't have to check anything
, since we were right the first time. |
1286 // In the DOM case, we only need to do something if |afterChange| is not 0. | 1285 // In the DOM case, we only need to do something if |afterChange| is not 0. |
1287 if (childrenAffectedByLastChildRules() && nodeBeforeChange) { | 1286 if (childrenAffectedByLastChildRules() && nodeBeforeChange) { |
1288 // Find our new last child element. | 1287 // Find our new last child element. |
1289 Element* lastChildElement = ElementTraversal::lastChild(*this); | 1288 Element* lastChildElement = ElementTraversal::lastChild(*this); |
1290 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement
->renderStyle() : 0; | 1289 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement
->renderStyle() : 0; |
1291 | 1290 |
1292 // Find the last element before the change. | 1291 // Find the last element before the change. |
1293 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle
ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange); | 1292 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle
ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange); |
1294 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef
oreChange->renderStyle() : 0; | 1293 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef
oreChange->renderStyle() : 0; |
1295 | 1294 |
1296 // This is the element insertion as last child element case. | 1295 // This is the element insertion as last child element case. |
1297 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle
&& elementBeforeChangeStyle->lastChildState()) | 1296 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle
&& elementBeforeChangeStyle->lastChildState()) { |
| 1297 ASSERT(SiblingElementInserted); |
1298 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange); | 1298 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1299 } |
1299 | 1300 |
1300 // This is the last child element removal case. The parser callback case
is similar to node removal as well in that we need to change the last child | 1301 // This is the last child element removal case. The parser callback case
is similar to node removal as well in that we need to change the last child |
1301 // to match now. | 1302 // to match now. |
1302 if ((changeType == SiblingRemoved || changeType == FinishedParsingChildr
en) && lastChildElement == elementBeforeChange && lastChildElement && (!lastChil
dElementStyle || !lastChildElementStyle->lastChildState())) | 1303 if ((changeType == SiblingElementRemoved || changeType == FinishedParsin
gChildren) && lastChildElement == elementBeforeChange && lastChildElement && (!l
astChildElementStyle || !lastChildElementStyle->lastChildState())) |
1303 lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange); | 1304 lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange); |
1304 } | 1305 } |
1305 | 1306 |
1306 // The + selector. We need to invalidate the first element following the cha
nge. It is the only possible element | 1307 // The + selector. We need to invalidate the first element following the cha
nge. It is the only possible element |
1307 // that could be affected by this DOM change. | 1308 // that could be affected by this DOM change. |
1308 if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) { | 1309 if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) { |
1309 if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toE
lement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange)) | 1310 if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toE
lement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange)) |
1310 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); | 1311 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); |
1311 } | 1312 } |
1312 } | 1313 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 return true; | 1413 return true; |
1413 | 1414 |
1414 if (node->isElementNode() && toElement(node)->shadow()) | 1415 if (node->isElementNode() && toElement(node)->shadow()) |
1415 return true; | 1416 return true; |
1416 | 1417 |
1417 return false; | 1418 return false; |
1418 } | 1419 } |
1419 #endif | 1420 #endif |
1420 | 1421 |
1421 } // namespace blink | 1422 } // namespace blink |
OLD | NEW |