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 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 } | 1449 } |
1450 | 1450 |
1451 // Splits the tree parent by parent until we reach the specified ancestor. We us
e VisiblePositions | 1451 // Splits the tree parent by parent until we reach the specified ancestor. We us
e VisiblePositions |
1452 // to determine if the split is necessary. Returns the last split node. | 1452 // to determine if the split is necessary. Returns the last split node. |
1453 PassRefPtr<Node> CompositeEditCommand::splitTreeToNode(Node* start, Node* end, b
ool shouldSplitAncestor) | 1453 PassRefPtr<Node> CompositeEditCommand::splitTreeToNode(Node* start, Node* end, b
ool shouldSplitAncestor) |
1454 { | 1454 { |
1455 ASSERT(start); | 1455 ASSERT(start); |
1456 ASSERT(end); | 1456 ASSERT(end); |
1457 ASSERT(start != end); | 1457 ASSERT(start != end); |
1458 | 1458 |
1459 RefPtr<Node> node; | |
1460 if (shouldSplitAncestor && end->parentNode()) | 1459 if (shouldSplitAncestor && end->parentNode()) |
1461 end = end->parentNode(); | 1460 end = end->parentNode(); |
| 1461 if (!start->isDescendantOf(end)) |
| 1462 return end; |
1462 | 1463 |
1463 RefPtr<Node> endNode = end; | 1464 RefPtr<Node> endNode = end; |
1464 for (node = start; node && node->parentNode() != endNode; node = node->paren
tNode()) { | 1465 RefPtr<Node> node; |
| 1466 for (node = start; node->parentNode() != endNode; node = node->parentNode())
{ |
1465 if (!node->parentNode()->isElementNode()) | 1467 if (!node->parentNode()->isElementNode()) |
1466 break; | 1468 break; |
1467 // Do not split a node when doing so introduces an empty node. | 1469 // Do not split a node when doing so introduces an empty node. |
1468 VisiblePosition positionInParent(firstPositionInNode(node->parentNode())
); | 1470 VisiblePosition positionInParent(firstPositionInNode(node->parentNode())
); |
1469 VisiblePosition positionInNode(firstPositionInOrBeforeNode(node.get())); | 1471 VisiblePosition positionInNode(firstPositionInOrBeforeNode(node.get())); |
1470 if (positionInParent != positionInNode) | 1472 if (positionInParent != positionInNode) |
1471 splitElement(toElement(node->parentNode()), node); | 1473 splitElement(toElement(node->parentNode()), node); |
1472 } | 1474 } |
1473 | 1475 |
1474 return node.release(); | 1476 return node.release(); |
1475 } | 1477 } |
1476 | 1478 |
1477 PassRefPtrWillBeRawPtr<Element> createBlockPlaceholderElement(Document& document
) | 1479 PassRefPtrWillBeRawPtr<Element> createBlockPlaceholderElement(Document& document
) |
1478 { | 1480 { |
1479 return document.createElement(brTag, false); | 1481 return document.createElement(brTag, false); |
1480 } | 1482 } |
1481 | 1483 |
1482 } // namespace WebCore | 1484 } // namespace WebCore |
OLD | NEW |