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, 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 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 return nullptr; | 561 return nullptr; |
| 562 } | 562 } |
| 563 | 563 |
| 564 { | 564 { |
| 565 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; | 565 HTMLFrameOwnerElement::UpdateSuspendScope suspendWidgetHierarchyUpdates; |
| 566 | 566 |
| 567 Node* prev = child->previousSibling(); | 567 Node* prev = child->previousSibling(); |
| 568 Node* next = child->nextSibling(); | 568 Node* next = child->nextSibling(); |
| 569 removeBetween(prev, next, *child); | 569 removeBetween(prev, next, *child); |
| 570 notifyNodeRemoved(*child); | 570 notifyNodeRemoved(*child); |
| 571 ChildrenChange change = {ChildRemoved, prev, next, ChildrenChangeSourceA PI}; | 571 childrenChanged(ChildrenChange::forRemoval(*child, prev, next, ChildrenC hangeSourceAPI)); |
| 572 childrenChanged(change); | |
| 573 } | 572 } |
| 574 dispatchSubtreeModifiedEvent(); | 573 dispatchSubtreeModifiedEvent(); |
| 575 return child; | 574 return child; |
| 576 } | 575 } |
| 577 | 576 |
| 578 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol dChild) | 577 void ContainerNode::removeBetween(Node* previousChild, Node* nextChild, Node& ol dChild) |
| 579 { | 578 { |
| 580 NoEventDispatchAssertion assertNoEventDispatch; | 579 NoEventDispatchAssertion assertNoEventDispatch; |
| 581 | 580 |
| 582 ASSERT(oldChild.parentNode() == this); | 581 ASSERT(oldChild.parentNode() == this); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 608 Node* prev = oldChild.previousSibling(); | 607 Node* prev = oldChild.previousSibling(); |
| 609 Node* next = oldChild.nextSibling(); | 608 Node* next = oldChild.nextSibling(); |
| 610 | 609 |
| 611 oldChild.updateAncestorConnectedSubframeCountForRemoval(); | 610 oldChild.updateAncestorConnectedSubframeCountForRemoval(); |
| 612 | 611 |
| 613 ChildListMutationScope(*this).willRemoveChild(oldChild); | 612 ChildListMutationScope(*this).willRemoveChild(oldChild); |
| 614 oldChild.notifyMutationObserversNodeWillDetach(); | 613 oldChild.notifyMutationObserversNodeWillDetach(); |
| 615 | 614 |
| 616 removeBetween(prev, next, oldChild); | 615 removeBetween(prev, next, oldChild); |
| 617 | 616 |
| 618 ChildrenChange change = {ChildRemoved, prev, next, ChildrenChangeSourceParse r}; | |
| 619 notifyNodeRemoved(oldChild); | 617 notifyNodeRemoved(oldChild); |
| 620 childrenChanged(change); | 618 childrenChanged(ChildrenChange::forRemoval(oldChild, prev, next, ChildrenCha ngeSourceParser)); |
| 621 } | 619 } |
| 622 | 620 |
| 623 // this differs from other remove functions because it forcibly removes all the children, | 621 // this differs from other remove functions because it forcibly removes all the children, |
| 624 // regardless of read-only status or event exceptions, e.g. | 622 // regardless of read-only status or event exceptions, e.g. |
| 625 void ContainerNode::removeChildren() | 623 void ContainerNode::removeChildren() |
| 626 { | 624 { |
| 627 if (!m_firstChild) | 625 if (!m_firstChild) |
| 628 return; | 626 return; |
| 629 | 627 |
| 630 // The container node can be removed from event handlers. | 628 // The container node can be removed from event handlers. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 761 { | 759 { |
| 762 NoEventDispatchAssertion assertNoEventDispatch; | 760 NoEventDispatchAssertion assertNoEventDispatch; |
| 763 ScriptForbiddenScope forbidScript; | 761 ScriptForbiddenScope forbidScript; |
| 764 | 762 |
| 765 treeScope().adoptIfNeeded(*newChild); | 763 treeScope().adoptIfNeeded(*newChild); |
| 766 appendChildCommon(*newChild); | 764 appendChildCommon(*newChild); |
| 767 newChild->updateAncestorConnectedSubframeCountForInsertion(); | 765 newChild->updateAncestorConnectedSubframeCountForInsertion(); |
| 768 ChildListMutationScope(*this).childAdded(*newChild); | 766 ChildListMutationScope(*this).childAdded(*newChild); |
| 769 } | 767 } |
| 770 | 768 |
| 769 | |
|
esprehn
2014/08/01 14:12:26
why extra nl?
Inactive
2014/08/01 15:40:07
Done.
| |
| 771 notifyNodeInserted(*newChild, ChildrenChangeSourceParser); | 770 notifyNodeInserted(*newChild, ChildrenChangeSourceParser); |
| 772 } | 771 } |
| 773 | 772 |
| 774 void ContainerNode::notifyNodeInserted(Node& root, ChildrenChangeSource source) | 773 void ContainerNode::notifyNodeInserted(Node& root, ChildrenChangeSource source) |
| 775 { | 774 { |
| 776 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); | 775 ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden()); |
| 777 | 776 |
| 778 InspectorInstrumentation::didInsertDOMNode(&root); | 777 InspectorInstrumentation::didInsertDOMNode(&root); |
| 779 | 778 |
| 780 RefPtrWillBeRawPtr<Node> protect(this); | 779 RefPtrWillBeRawPtr<Node> protect(this); |
| 781 RefPtrWillBeRawPtr<Node> protectNode(root); | 780 RefPtrWillBeRawPtr<Node> protectNode(root); |
| 782 | 781 |
| 783 NodeVector postInsertionNotificationTargets; | 782 NodeVector postInsertionNotificationTargets; |
| 784 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); | 783 notifyNodeInsertedInternal(root, postInsertionNotificationTargets); |
| 785 | 784 |
| 786 // ShadowRoots are not real children, we don't need to tell host that it's | 785 // ShadowRoots are not real children, we don't need to tell host that it's |
| 787 // children changed when one is added. | 786 // children changed when one is added. |
| 788 // FIXME: We should have a separate code path for ShadowRoot since it only | 787 // FIXME: We should have a separate code path for ShadowRoot since it only |
| 789 // needs to call insertedInto and the rest of this logic is not needed. | 788 // needs to call insertedInto and the rest of this logic is not needed. |
| 790 if (!root.isShadowRoot()) { | 789 if (!root.isShadowRoot()) |
| 791 ChildrenChange change = {ChildInserted, root.previousSibling(), root.nex tSibling(), source}; | 790 childrenChanged(ChildrenChange::forInsertion(root, source)); |
|
esprehn
2014/08/01 14:12:26
This code needs to be rebased again.
Inactive
2014/08/01 15:40:07
Done.
| |
| 792 childrenChanged(change); | |
| 793 } | |
| 794 | 791 |
| 795 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { | 792 for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) { |
| 796 Node* targetNode = postInsertionNotificationTargets[i].get(); | 793 Node* targetNode = postInsertionNotificationTargets[i].get(); |
| 797 if (targetNode->inDocument()) | 794 if (targetNode->inDocument()) |
| 798 targetNode->didNotifySubtreeInsertionsToDocument(); | 795 targetNode->didNotifySubtreeInsertionsToDocument(); |
| 799 } | 796 } |
| 800 } | 797 } |
| 801 | 798 |
| 802 void ContainerNode::notifyNodeInsertedInternal(Node& root, NodeVector& postInser tionNotificationTargets) | 799 void ContainerNode::notifyNodeInsertedInternal(Node& root, NodeVector& postInser tionNotificationTargets) |
| 803 { | 800 { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 clearChildNeedsStyleRecalc(); | 846 clearChildNeedsStyleRecalc(); |
| 850 Node::detach(context); | 847 Node::detach(context); |
| 851 } | 848 } |
| 852 | 849 |
| 853 void ContainerNode::childrenChanged(const ChildrenChange& change) | 850 void ContainerNode::childrenChanged(const ChildrenChange& change) |
| 854 { | 851 { |
| 855 document().incDOMTreeVersion(); | 852 document().incDOMTreeVersion(); |
| 856 if (!change.byParser && change.type != TextChanged) | 853 if (!change.byParser && change.type != TextChanged) |
| 857 document().updateRangesAfterChildrenChanged(this); | 854 document().updateRangesAfterChildrenChanged(this); |
| 858 invalidateNodeListCachesInAncestors(); | 855 invalidateNodeListCachesInAncestors(); |
| 859 if (change.type == ChildInserted && !childNeedsStyleRecalc()) { | 856 if (change.isChildInsertion() && !childNeedsStyleRecalc()) { |
| 860 setChildNeedsStyleRecalc(); | 857 setChildNeedsStyleRecalc(); |
| 861 markAncestorsWithChildNeedsStyleRecalc(); | 858 markAncestorsWithChildNeedsStyleRecalc(); |
| 862 } | 859 } |
| 863 } | 860 } |
| 864 | 861 |
| 865 void ContainerNode::cloneChildNodes(ContainerNode *clone) | 862 void ContainerNode::cloneChildNodes(ContainerNode *clone) |
| 866 { | 863 { |
| 867 TrackExceptionState exceptionState; | 864 TrackExceptionState exceptionState; |
| 868 for (Node* n = firstChild(); n && !exceptionState.hadException(); n = n->nex tSibling()) | 865 for (Node* n = firstChild(); n && !exceptionState.hadException(); n = n->nex tSibling()) |
| 869 clone->appendChild(n->cloneNode(true), exceptionState); | 866 clone->appendChild(n->cloneNode(true), exceptionState); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1280 ASSERT(changeType != FinishedParsingChildren); | 1277 ASSERT(changeType != FinishedParsingChildren); |
| 1281 // Find our new first child element. | 1278 // Find our new first child element. |
| 1282 Element* firstChildElement = ElementTraversal::firstChild(*this); | 1279 Element* firstChildElement = ElementTraversal::firstChild(*this); |
| 1283 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem ent->renderStyle() : 0; | 1280 RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElem ent->renderStyle() : 0; |
| 1284 | 1281 |
| 1285 // Find the first element after the change. | 1282 // Find the first element after the change. |
| 1286 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange); | 1283 Element* elementAfterChange = nodeAfterChange->isElementNode() ? toEleme nt(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange); |
| 1287 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter Change->renderStyle() : 0; | 1284 RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfter Change->renderStyle() : 0; |
| 1288 | 1285 |
| 1289 // This is the element insertion as first child element case. | 1286 // This is the element insertion as first child element case. |
| 1290 if (firstChildElement != elementAfterChange && elementAfterChangeStyle & & elementAfterChangeStyle->firstChildState()) | 1287 if (firstChildElement != elementAfterChange && elementAfterChangeStyle & & elementAfterChangeStyle->firstChildState()) { |
| 1288 ASSERT(changeType == SiblingElementInserted); | |
| 1291 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); | 1289 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1290 } | |
| 1292 | 1291 |
| 1293 // This is the first child element removal case. | 1292 // This is the first child element removal case. |
| 1294 if (changeType == SiblingRemoved && firstChildElement == elementAfterCha nge && firstChildElement && (!firstChildElementStyle || !firstChildElementStyle- >firstChildState())) | 1293 if (changeType == SiblingElementRemoved && firstChildElement == elementA fterChange && firstChildElement && (!firstChildElementStyle || !firstChildElemen tStyle->firstChildState())) |
| 1295 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange); | 1294 firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1296 } | 1295 } |
| 1297 | 1296 |
| 1298 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time. | 1297 // :last-child. In the parser callback case, we don't have to check anything , since we were right the first time. |
| 1299 // In the DOM case, we only need to do something if |afterChange| is not 0. | 1298 // In the DOM case, we only need to do something if |afterChange| is not 0. |
| 1300 if (childrenAffectedByLastChildRules() && nodeBeforeChange) { | 1299 if (childrenAffectedByLastChildRules() && nodeBeforeChange) { |
| 1301 // Find our new last child element. | 1300 // Find our new last child element. |
| 1302 Element* lastChildElement = ElementTraversal::lastChild(*this); | 1301 Element* lastChildElement = ElementTraversal::lastChild(*this); |
| 1303 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement ->renderStyle() : 0; | 1302 RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement ->renderStyle() : 0; |
| 1304 | 1303 |
| 1305 // Find the last element before the change. | 1304 // Find the last element before the change. |
| 1306 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange); | 1305 Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toEle ment(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange); |
| 1307 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef oreChange->renderStyle() : 0; | 1306 RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBef oreChange->renderStyle() : 0; |
| 1308 | 1307 |
| 1309 // This is the element insertion as last child element case. | 1308 // This is the element insertion as last child element case. |
| 1310 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle && elementBeforeChangeStyle->lastChildState()) | 1309 if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle && elementBeforeChangeStyle->lastChildState()) { |
| 1310 ASSERT(SiblingElementInserted); | |
| 1311 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange); | 1311 elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1312 } | |
| 1312 | 1313 |
| 1313 // 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 | 1314 // 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 |
| 1314 // to match now. | 1315 // to match now. |
| 1315 if ((changeType == SiblingRemoved || changeType == FinishedParsingChildr en) && lastChildElement == elementBeforeChange && lastChildElement && (!lastChil dElementStyle || !lastChildElementStyle->lastChildState())) | 1316 if ((changeType == SiblingElementRemoved || changeType == FinishedParsin gChildren) && lastChildElement == elementBeforeChange && lastChildElement && (!l astChildElementStyle || !lastChildElementStyle->lastChildState())) |
| 1316 lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange); | 1317 lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1317 } | 1318 } |
| 1318 | 1319 |
| 1319 // The + selector. We need to invalidate the first element following the cha nge. It is the only possible element | 1320 // The + selector. We need to invalidate the first element following the cha nge. It is the only possible element |
| 1320 // that could be affected by this DOM change. | 1321 // that could be affected by this DOM change. |
| 1321 if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) { | 1322 if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) { |
| 1322 if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toE lement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange)) | 1323 if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toE lement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange)) |
| 1323 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); | 1324 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); |
| 1324 } | 1325 } |
| 1325 } | 1326 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1420 return true; | 1421 return true; |
| 1421 | 1422 |
| 1422 if (node->isElementNode() && toElement(node)->shadow()) | 1423 if (node->isElementNode() && toElement(node)->shadow()) |
| 1423 return true; | 1424 return true; |
| 1424 | 1425 |
| 1425 return false; | 1426 return false; |
| 1426 } | 1427 } |
| 1427 #endif | 1428 #endif |
| 1428 | 1429 |
| 1429 } // namespace blink | 1430 } // namespace blink |
| OLD | NEW |