OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 635 |
636 void ReplaceSelectionCommand::makeInsertedContentRoundTrippableWithHTMLTreeBuild
er(const InsertedNodes& insertedNodes) | 636 void ReplaceSelectionCommand::makeInsertedContentRoundTrippableWithHTMLTreeBuild
er(const InsertedNodes& insertedNodes) |
637 { | 637 { |
638 RefPtrWillBeRawPtr<Node> pastEndNode = insertedNodes.pastLastLeaf(); | 638 RefPtrWillBeRawPtr<Node> pastEndNode = insertedNodes.pastLastLeaf(); |
639 RefPtrWillBeRawPtr<Node> next = nullptr; | 639 RefPtrWillBeRawPtr<Node> next = nullptr; |
640 for (RefPtrWillBeRawPtr<Node> node = insertedNodes.firstNodeInserted(); node
&& node != pastEndNode; node = next) { | 640 for (RefPtrWillBeRawPtr<Node> node = insertedNodes.firstNodeInserted(); node
&& node != pastEndNode; node = next) { |
641 next = NodeTraversal::next(*node); | 641 next = NodeTraversal::next(*node); |
642 | 642 |
643 if (!node->isHTMLElement()) | 643 if (!node->isHTMLElement()) |
644 continue; | 644 continue; |
| 645 // moveElementOutOfAncestor() in a previous iteration might have failed, |
| 646 // and |node| might have been detached from the document tree. |
| 647 if (!node->inDocument()) |
| 648 continue; |
645 | 649 |
646 HTMLElement& element = toHTMLElement(*node); | 650 HTMLElement& element = toHTMLElement(*node); |
647 if (isProhibitedParagraphChild(element.localName())) { | 651 if (isProhibitedParagraphChild(element.localName())) { |
648 if (HTMLElement* paragraphElement = toHTMLElement(enclosingElementWi
thTag(positionInParentBeforeNode(element), pTag))) | 652 if (HTMLElement* paragraphElement = toHTMLElement(enclosingElementWi
thTag(positionInParentBeforeNode(element), pTag))) |
649 moveElementOutOfAncestor(&element, paragraphElement); | 653 moveElementOutOfAncestor(&element, paragraphElement); |
650 } | 654 } |
651 | 655 |
652 if (isHTMLHeaderElement(&element)) { | 656 if (isHTMLHeaderElement(&element)) { |
653 if (HTMLElement* headerElement = toHTMLElement(highestEnclosingNodeO
fType(positionInParentBeforeNode(element), isHTMLHeaderElement))) | 657 if (HTMLElement* headerElement = toHTMLElement(highestEnclosingNodeO
fType(positionInParentBeforeNode(element), isHTMLHeaderElement))) |
654 moveElementOutOfAncestor(&element, headerElement); | 658 moveElementOutOfAncestor(&element, headerElement); |
655 } | 659 } |
656 } | 660 } |
657 } | 661 } |
658 | 662 |
659 void ReplaceSelectionCommand::moveElementOutOfAncestor(PassRefPtrWillBeRawPtr<El
ement> prpElement, PassRefPtrWillBeRawPtr<ContainerNode> prpAncestor) | 663 void ReplaceSelectionCommand::moveElementOutOfAncestor(PassRefPtrWillBeRawPtr<El
ement> prpElement, PassRefPtrWillBeRawPtr<Element> prpAncestor) |
660 { | 664 { |
661 RefPtrWillBeRawPtr<Element> element = prpElement; | 665 RefPtrWillBeRawPtr<Element> element = prpElement; |
662 RefPtrWillBeRawPtr<ContainerNode> ancestor = prpAncestor; | 666 RefPtrWillBeRawPtr<Element> ancestor = prpAncestor; |
663 | 667 |
664 if (!ancestor->parentNode()->hasEditableStyle()) | 668 if (!ancestor->parentNode()->hasEditableStyle()) |
665 return; | 669 return; |
666 | 670 |
667 VisiblePosition positionAtEndOfNode = createVisiblePosition(lastPositionInOr
AfterNode(element.get())); | 671 VisiblePosition positionAtEndOfNode = createVisiblePosition(lastPositionInOr
AfterNode(element.get())); |
668 VisiblePosition lastPositionInParagraph = createVisiblePosition(lastPosition
InNode(ancestor.get())); | 672 VisiblePosition lastPositionInParagraph = createVisiblePosition(lastPosition
InNode(ancestor.get())); |
669 if (positionAtEndOfNode.deepEquivalent() == lastPositionInParagraph.deepEqui
valent()) { | 673 if (positionAtEndOfNode.deepEquivalent() == lastPositionInParagraph.deepEqui
valent()) { |
670 removeNode(element); | 674 removeNode(element); |
671 if (ancestor->nextSibling()) | 675 if (ancestor->nextSibling()) |
672 insertNodeBefore(element, ancestor->nextSibling()); | 676 insertNodeBefore(element, ancestor->nextSibling()); |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 visitor->trace(m_startOfInsertedContent); | 1564 visitor->trace(m_startOfInsertedContent); |
1561 visitor->trace(m_endOfInsertedContent); | 1565 visitor->trace(m_endOfInsertedContent); |
1562 visitor->trace(m_insertionStyle); | 1566 visitor->trace(m_insertionStyle); |
1563 visitor->trace(m_documentFragment); | 1567 visitor->trace(m_documentFragment); |
1564 visitor->trace(m_startOfInsertedRange); | 1568 visitor->trace(m_startOfInsertedRange); |
1565 visitor->trace(m_endOfInsertedRange); | 1569 visitor->trace(m_endOfInsertedRange); |
1566 CompositeEditCommand::trace(visitor); | 1570 CompositeEditCommand::trace(visitor); |
1567 } | 1571 } |
1568 | 1572 |
1569 } // namespace blink | 1573 } // namespace blink |
OLD | NEW |