OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 if (anchorNode->inDocument()) | 958 if (anchorNode->inDocument()) |
959 removeNodePreservingChildren(anchorNode); | 959 removeNodePreservingChildren(anchorNode); |
960 } | 960 } |
961 | 961 |
962 // Clone the paragraph between start and end under blockElement, | 962 // Clone the paragraph between start and end under blockElement, |
963 // preserving the hierarchy up to outerNode. | 963 // preserving the hierarchy up to outerNode. |
964 | 964 |
965 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
const Position& end, Node* passedOuterNode, Element* blockElement) | 965 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
const Position& end, Node* passedOuterNode, Element* blockElement) |
966 { | 966 { |
967 ASSERT(comparePositions(start, end) <= 0); | 967 ASSERT(comparePositions(start, end) <= 0); |
| 968 ASSERT(passedOuterNode); |
| 969 ASSERT(blockElement); |
968 | 970 |
969 // First we clone the outerNode | 971 // First we clone the outerNode |
970 RefPtr<Node> lastNode; | 972 RefPtr<Node> lastNode; |
971 RefPtr<Node> outerNode = passedOuterNode; | 973 RefPtr<Node> outerNode = passedOuterNode; |
972 | 974 |
973 if (outerNode->isRootEditableElement()) { | 975 if (outerNode->isRootEditableElement()) { |
974 lastNode = blockElement; | 976 lastNode = blockElement; |
975 } else { | 977 } else { |
976 lastNode = outerNode->cloneNode(isRenderedTableElement(outerNode.get()))
; | 978 lastNode = outerNode->cloneNode(isRenderedTableElement(outerNode.get()))
; |
977 appendNode(lastNode, blockElement); | 979 appendNode(lastNode, blockElement); |
(...skipping 21 matching lines...) Expand all Loading... |
999 if (!outerNode->inDocument()) | 1001 if (!outerNode->inDocument()) |
1000 return; | 1002 return; |
1001 | 1003 |
1002 // Handle the case of paragraphs with more than one node, | 1004 // Handle the case of paragraphs with more than one node, |
1003 // cloning all the siblings until end.deprecatedNode() is reached. | 1005 // cloning all the siblings until end.deprecatedNode() is reached. |
1004 | 1006 |
1005 if (start.deprecatedNode() != end.deprecatedNode() && !start.deprecatedNode(
)->isDescendantOf(end.deprecatedNode())) { | 1007 if (start.deprecatedNode() != end.deprecatedNode() && !start.deprecatedNode(
)->isDescendantOf(end.deprecatedNode())) { |
1006 // If end is not a descendant of outerNode we need to | 1008 // If end is not a descendant of outerNode we need to |
1007 // find the first common ancestor to increase the scope | 1009 // find the first common ancestor to increase the scope |
1008 // of our nextSibling traversal. | 1010 // of our nextSibling traversal. |
1009 while (!end.deprecatedNode()->isDescendantOf(outerNode.get())) { | 1011 while (outerNode && !end.deprecatedNode()->isDescendantOf(outerNode.get(
))) { |
1010 outerNode = outerNode->parentNode(); | 1012 outerNode = outerNode->parentNode(); |
1011 } | 1013 } |
1012 | 1014 |
| 1015 if (!outerNode) |
| 1016 return; |
| 1017 |
1013 RefPtr<Node> startNode = start.deprecatedNode(); | 1018 RefPtr<Node> startNode = start.deprecatedNode(); |
1014 for (RefPtr<Node> node = NodeTraversal::nextSkippingChildren(*startNode,
outerNode.get()); node; node = NodeTraversal::nextSkippingChildren(*node, outer
Node.get())) { | 1019 for (RefPtr<Node> node = NodeTraversal::nextSkippingChildren(*startNode,
outerNode.get()); node; node = NodeTraversal::nextSkippingChildren(*node, outer
Node.get())) { |
1015 // Move lastNode up in the tree as much as node was moved up in the | 1020 // Move lastNode up in the tree as much as node was moved up in the |
1016 // tree by NodeTraversal::nextSkippingChildren, so that the relative
depth between | 1021 // tree by NodeTraversal::nextSkippingChildren, so that the relative
depth between |
1017 // node and the original start node is maintained in the clone. | 1022 // node and the original start node is maintained in the clone. |
1018 while (startNode->parentNode() != node->parentNode()) { | 1023 while (startNode && lastNode && startNode->parentNode() != node->par
entNode()) { |
1019 startNode = startNode->parentNode(); | 1024 startNode = startNode->parentNode(); |
1020 lastNode = lastNode->parentNode(); | 1025 lastNode = lastNode->parentNode(); |
1021 } | 1026 } |
1022 | 1027 |
| 1028 if (!lastNode || !lastNode->parentNode()) |
| 1029 return; |
| 1030 |
1023 RefPtr<Node> clonedNode = node->cloneNode(true); | 1031 RefPtr<Node> clonedNode = node->cloneNode(true); |
1024 insertNodeAfter(clonedNode, lastNode); | 1032 insertNodeAfter(clonedNode, lastNode); |
1025 lastNode = clonedNode.release(); | 1033 lastNode = clonedNode.release(); |
1026 if (node == end.deprecatedNode() || end.deprecatedNode()->isDescenda
ntOf(node.get())) | 1034 if (node == end.deprecatedNode() || end.deprecatedNode()->isDescenda
ntOf(node.get())) |
1027 break; | 1035 break; |
1028 } | 1036 } |
1029 } | 1037 } |
1030 } | 1038 } |
1031 | 1039 |
1032 | 1040 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 return node.release(); | 1469 return node.release(); |
1462 } | 1470 } |
1463 | 1471 |
1464 PassRefPtr<Element> createBlockPlaceholderElement(Document& document) | 1472 PassRefPtr<Element> createBlockPlaceholderElement(Document& document) |
1465 { | 1473 { |
1466 RefPtr<Element> breakNode = document.createElement(brTag, false); | 1474 RefPtr<Element> breakNode = document.createElement(brTag, false); |
1467 return breakNode.release(); | 1475 return breakNode.release(); |
1468 } | 1476 } |
1469 | 1477 |
1470 } // namespace WebCore | 1478 } // namespace WebCore |
OLD | NEW |