Chromium Code Reviews| 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 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 957 if (anchorNode->inDocument()) | 957 if (anchorNode->inDocument()) |
| 958 removeNodePreservingChildren(anchorNode); | 958 removeNodePreservingChildren(anchorNode); |
| 959 } | 959 } |
| 960 | 960 |
| 961 // Clone the paragraph between start and end under blockElement, | 961 // Clone the paragraph between start and end under blockElement, |
| 962 // preserving the hierarchy up to outerNode. | 962 // preserving the hierarchy up to outerNode. |
| 963 | 963 |
| 964 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start, const Position& end, Node* passedOuterNode, Element* blockElement) | 964 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start, const Position& end, Node* passedOuterNode, Element* blockElement) |
| 965 { | 965 { |
| 966 ASSERT(comparePositions(start, end) <= 0); | 966 ASSERT(comparePositions(start, end) <= 0); |
| 967 ASSERT(passedOuterNode); | |
| 968 ASSERT(blockElement); | |
| 967 | 969 |
| 968 // First we clone the outerNode | 970 // First we clone the outerNode |
| 969 RefPtr<Node> lastNode; | 971 RefPtr<Node> lastNode; |
| 970 RefPtr<Node> outerNode = passedOuterNode; | 972 RefPtr<Node> outerNode = passedOuterNode; |
| 971 | 973 |
| 972 if (outerNode->isRootEditableElement()) { | 974 if (outerNode->isRootEditableElement()) { |
| 973 lastNode = blockElement; | 975 lastNode = blockElement; |
| 974 } else { | 976 } else { |
| 975 lastNode = outerNode->cloneNode(isRenderedTableElement(outerNode.get())) ; | 977 lastNode = outerNode->cloneNode(isRenderedTableElement(outerNode.get())) ; |
| 976 appendNode(lastNode, blockElement); | 978 appendNode(lastNode, blockElement); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 998 if (!outerNode->inDocument()) | 1000 if (!outerNode->inDocument()) |
| 999 return; | 1001 return; |
| 1000 | 1002 |
| 1001 // Handle the case of paragraphs with more than one node, | 1003 // Handle the case of paragraphs with more than one node, |
| 1002 // cloning all the siblings until end.deprecatedNode() is reached. | 1004 // cloning all the siblings until end.deprecatedNode() is reached. |
| 1003 | 1005 |
| 1004 if (start.deprecatedNode() != end.deprecatedNode() && !start.deprecatedNode( )->isDescendantOf(end.deprecatedNode())) { | 1006 if (start.deprecatedNode() != end.deprecatedNode() && !start.deprecatedNode( )->isDescendantOf(end.deprecatedNode())) { |
| 1005 // If end is not a descendant of outerNode we need to | 1007 // If end is not a descendant of outerNode we need to |
| 1006 // find the first common ancestor to increase the scope | 1008 // find the first common ancestor to increase the scope |
| 1007 // of our nextSibling traversal. | 1009 // of our nextSibling traversal. |
| 1008 while (!end.deprecatedNode()->isDescendantOf(outerNode.get())) { | 1010 while (outerNode && !end.deprecatedNode()->isDescendantOf(outerNode.get( ))) { |
| 1009 outerNode = outerNode->parentNode(); | 1011 outerNode = outerNode->parentNode(); |
| 1010 } | 1012 } |
| 1011 | 1013 |
| 1014 if (!outerNode) | |
|
Yuta Kitamura
2014/04/28 02:56:42
In what situation this could happen? (I really cou
yoichio
2014/04/30 07:45:17
It takes place when |passedOuterNode| and |end| ar
| |
| 1015 return; | |
| 1016 | |
| 1012 RefPtr<Node> startNode = start.deprecatedNode(); | 1017 RefPtr<Node> startNode = start.deprecatedNode(); |
| 1013 for (RefPtr<Node> node = NodeTraversal::nextSkippingChildren(*startNode, outerNode.get()); node; node = NodeTraversal::nextSkippingChildren(*node, outer Node.get())) { | 1018 for (RefPtr<Node> node = NodeTraversal::nextSkippingChildren(*startNode, outerNode.get()); node; node = NodeTraversal::nextSkippingChildren(*node, outer Node.get())) { |
| 1014 // Move lastNode up in the tree as much as node was moved up in the | 1019 // Move lastNode up in the tree as much as node was moved up in the |
| 1015 // tree by NodeTraversal::nextSkippingChildren, so that the relative depth between | 1020 // tree by NodeTraversal::nextSkippingChildren, so that the relative depth between |
| 1016 // node and the original start node is maintained in the clone. | 1021 // node and the original start node is maintained in the clone. |
| 1017 while (startNode->parentNode() != node->parentNode()) { | 1022 while (startNode && lastNode && startNode->parentNode() != node->par entNode()) { |
| 1018 startNode = startNode->parentNode(); | 1023 startNode = startNode->parentNode(); |
| 1019 lastNode = lastNode->parentNode(); | 1024 lastNode = lastNode->parentNode(); |
| 1020 } | 1025 } |
| 1021 | 1026 |
| 1027 if (!lastNode || !lastNode->parentNode()) | |
|
Yuta Kitamura
2014/04/28 02:56:42
What's the point of checking the non-nullness of
l
yoichio
2014/04/30 07:45:17
It is for L1031:insertNodeAfter(clonedNode, lastNo
| |
| 1028 return; | |
| 1029 | |
| 1022 RefPtr<Node> clonedNode = node->cloneNode(true); | 1030 RefPtr<Node> clonedNode = node->cloneNode(true); |
| 1023 insertNodeAfter(clonedNode, lastNode); | 1031 insertNodeAfter(clonedNode, lastNode); |
| 1024 lastNode = clonedNode.release(); | 1032 lastNode = clonedNode.release(); |
| 1025 if (node == end.deprecatedNode() || end.deprecatedNode()->isDescenda ntOf(node.get())) | 1033 if (node == end.deprecatedNode() || end.deprecatedNode()->isDescenda ntOf(node.get())) |
| 1026 break; | 1034 break; |
| 1027 } | 1035 } |
| 1028 } | 1036 } |
| 1029 } | 1037 } |
| 1030 | 1038 |
| 1031 | 1039 |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 return node.release(); | 1468 return node.release(); |
| 1461 } | 1469 } |
| 1462 | 1470 |
| 1463 PassRefPtr<Element> createBlockPlaceholderElement(Document& document) | 1471 PassRefPtr<Element> createBlockPlaceholderElement(Document& document) |
| 1464 { | 1472 { |
| 1465 RefPtr<Element> breakNode = document.createElement(brTag, false); | 1473 RefPtr<Element> breakNode = document.createElement(brTag, false); |
| 1466 return breakNode.release(); | 1474 return breakNode.release(); |
| 1467 } | 1475 } |
| 1468 | 1476 |
| 1469 } // namespace WebCore | 1477 } // namespace WebCore |
| OLD | NEW |