| 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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 appendNode(placeholder, container); | 839 appendNode(placeholder, container); |
| 840 return placeholder.release(); | 840 return placeholder.release(); |
| 841 } | 841 } |
| 842 | 842 |
| 843 PassRefPtr<Node> CompositeEditCommand::insertBlockPlaceholder(const Position& po
s) | 843 PassRefPtr<Node> CompositeEditCommand::insertBlockPlaceholder(const Position& po
s) |
| 844 { | 844 { |
| 845 if (pos.isNull()) | 845 if (pos.isNull()) |
| 846 return 0; | 846 return 0; |
| 847 | 847 |
| 848 // Should assert isBlockFlow || isInlineFlow when deletion improves. See 42
44964. | 848 // Should assert isBlockFlow || isInlineFlow when deletion improves. See 42
44964. |
| 849 ASSERT(pos.deprecatedNode()->renderer()); | 849 ASSERT(pos.renderer()); |
| 850 | 850 |
| 851 RefPtr<Node> placeholder = createBlockPlaceholderElement(document()); | 851 RefPtr<Node> placeholder = createBlockPlaceholderElement(document()); |
| 852 insertNodeAt(placeholder, pos); | 852 insertNodeAt(placeholder, pos); |
| 853 return placeholder.release(); | 853 return placeholder.release(); |
| 854 } | 854 } |
| 855 | 855 |
| 856 PassRefPtr<Node> CompositeEditCommand::addBlockPlaceholderIfNeeded(Element* cont
ainer) | 856 PassRefPtr<Node> CompositeEditCommand::addBlockPlaceholderIfNeeded(Element* cont
ainer) |
| 857 { | 857 { |
| 858 if (!container) | 858 if (!container) |
| 859 return 0; | 859 return 0; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 if (comparePositions(pos, upstreamStart) < 0) | 920 if (comparePositions(pos, upstreamStart) < 0) |
| 921 return 0; | 921 return 0; |
| 922 | 922 |
| 923 // Perform some checks to see if we need to perform work in this function. | 923 // Perform some checks to see if we need to perform work in this function. |
| 924 if (isBlock(upstreamStart.deprecatedNode())) { | 924 if (isBlock(upstreamStart.deprecatedNode())) { |
| 925 // If the block is the root editable element, always move content to a n
ew block, | 925 // If the block is the root editable element, always move content to a n
ew block, |
| 926 // since it is illegal to modify attributes on the root editable element
for editing. | 926 // since it is illegal to modify attributes on the root editable element
for editing. |
| 927 if (upstreamStart.deprecatedNode() == editableRootForPosition(upstreamSt
art)) { | 927 if (upstreamStart.deprecatedNode() == editableRootForPosition(upstreamSt
art)) { |
| 928 // If the block is the root editable element and it contains no visi
ble content, create a new | 928 // If the block is the root editable element and it contains no visi
ble content, create a new |
| 929 // block but don't try and move content into it, since there's nothi
ng for moveParagraphs to move. | 929 // block but don't try and move content into it, since there's nothi
ng for moveParagraphs to move. |
| 930 if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(upstream
Start.deprecatedNode()->renderer())) | 930 if (!Position::hasRenderedNonAnonymousDescendantsWithHeight(upstream
Start.renderer())) |
| 931 return insertNewDefaultParagraphElementAt(upstreamStart); | 931 return insertNewDefaultParagraphElementAt(upstreamStart); |
| 932 } else if (isBlock(upstreamEnd.deprecatedNode())) { | 932 } else if (isBlock(upstreamEnd.deprecatedNode())) { |
| 933 if (!upstreamEnd.deprecatedNode()->isDescendantOf(upstreamStart.depr
ecatedNode())) { | 933 if (!upstreamEnd.deprecatedNode()->isDescendantOf(upstreamStart.depr
ecatedNode())) { |
| 934 // If the paragraph end is a descendant of paragraph start, then
we need to run | 934 // If the paragraph end is a descendant of paragraph start, then
we need to run |
| 935 // the rest of this function. If not, we can bail here. | 935 // the rest of this function. If not, we can bail here. |
| 936 return 0; | 936 return 0; |
| 937 } | 937 } |
| 938 } else if (enclosingBlock(upstreamEnd.deprecatedNode()) != upstreamStart
.deprecatedNode()) { | 938 } else if (enclosingBlock(upstreamEnd.deprecatedNode()) != upstreamStart
.deprecatedNode()) { |
| 939 // The visibleEnd. It must be an ancestor of the paragraph start. | 939 // The visibleEnd. It must be an ancestor of the paragraph start. |
| 940 // We can bail as we have a full block to work with. | 940 // We can bail as we have a full block to work with. |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 if (!isStartOfParagraph(atBR)) | 1353 if (!isStartOfParagraph(atBR)) |
| 1354 insertNodeBefore(createBreakElement(document()), br); | 1354 insertNodeBefore(createBreakElement(document()), br); |
| 1355 setEndingSelection(VisibleSelection(atBR, endingSelection().isDirectional())
); | 1355 setEndingSelection(VisibleSelection(atBR, endingSelection().isDirectional())
); |
| 1356 | 1356 |
| 1357 // If this is an empty paragraph there must be a line break here. | 1357 // If this is an empty paragraph there must be a line break here. |
| 1358 if (!lineBreakExistsAtVisiblePosition(caret)) | 1358 if (!lineBreakExistsAtVisiblePosition(caret)) |
| 1359 return false; | 1359 return false; |
| 1360 | 1360 |
| 1361 Position caretPos(caret.deepEquivalent().downstream()); | 1361 Position caretPos(caret.deepEquivalent().downstream()); |
| 1362 // A line break is either a br or a preserved newline. | 1362 // A line break is either a br or a preserved newline. |
| 1363 ASSERT(caretPos.deprecatedNode()->hasTagName(brTag) || (caretPos.deprecatedN
ode()->isTextNode() && caretPos.deprecatedNode()->renderer()->style()->preserveN
ewline())); | 1363 ASSERT(caretPos.deprecatedNode()->hasTagName(brTag) || (caretPos.deprecatedN
ode()->isTextNode() && caretPos.renderer()->style()->preserveNewline())); |
| 1364 | 1364 |
| 1365 if (caretPos.deprecatedNode()->hasTagName(brTag)) | 1365 if (caretPos.deprecatedNode()->hasTagName(brTag)) |
| 1366 removeNodeAndPruneAncestors(caretPos.deprecatedNode()); | 1366 removeNodeAndPruneAncestors(caretPos.deprecatedNode()); |
| 1367 else if (caretPos.deprecatedNode()->isTextNode()) { | 1367 else if (caretPos.deprecatedNode()->isTextNode()) { |
| 1368 ASSERT(caretPos.deprecatedEditingOffset() == 0); | 1368 ASSERT(caretPos.deprecatedEditingOffset() == 0); |
| 1369 Text* textNode = toText(caretPos.deprecatedNode()); | 1369 Text* textNode = toText(caretPos.deprecatedNode()); |
| 1370 ContainerNode* parentNode = textNode->parentNode(); | 1370 ContainerNode* parentNode = textNode->parentNode(); |
| 1371 // The preserved newline must be the first thing in the node, since othe
rwise the previous | 1371 // The preserved newline must be the first thing in the node, since othe
rwise the previous |
| 1372 // paragraph would be quoted, and we verified that it wasn't above. | 1372 // paragraph would be quoted, and we verified that it wasn't above. |
| 1373 deleteTextFromNode(textNode, 0, 1); | 1373 deleteTextFromNode(textNode, 0, 1); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 return node.release(); | 1464 return node.release(); |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 PassRefPtr<Element> createBlockPlaceholderElement(Document* document) | 1467 PassRefPtr<Element> createBlockPlaceholderElement(Document* document) |
| 1468 { | 1468 { |
| 1469 RefPtr<Element> breakNode = document->createElement(brTag, false); | 1469 RefPtr<Element> breakNode = document->createElement(brTag, false); |
| 1470 return breakNode.release(); | 1470 return breakNode.release(); |
| 1471 } | 1471 } |
| 1472 | 1472 |
| 1473 } // namespace WebCore | 1473 } // namespace WebCore |
| OLD | NEW |