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 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 bool mergeForward = !(inSameParagraph(startOfInsertedContent, endOfInsertedC
ontent) && !isStartOfParagraph(startOfInsertedContent)); | 814 bool mergeForward = !(inSameParagraph(startOfInsertedContent, endOfInsertedC
ontent) && !isStartOfParagraph(startOfInsertedContent)); |
815 | 815 |
816 VisiblePosition destination = mergeForward ? endOfInsertedContent.next() : e
ndOfInsertedContent; | 816 VisiblePosition destination = mergeForward ? endOfInsertedContent.next() : e
ndOfInsertedContent; |
817 VisiblePosition startOfParagraphToMove = mergeForward ? startOfParagraph(end
OfInsertedContent) : endOfInsertedContent.next(); | 817 VisiblePosition startOfParagraphToMove = mergeForward ? startOfParagraph(end
OfInsertedContent) : endOfInsertedContent.next(); |
818 | 818 |
819 // Merging forward could result in deleting the destination anchor node. | 819 // Merging forward could result in deleting the destination anchor node. |
820 // To avoid this, we add a placeholder node before the start of the paragrap
h. | 820 // To avoid this, we add a placeholder node before the start of the paragrap
h. |
821 if (endOfParagraph(startOfParagraphToMove) == destination) { | 821 if (endOfParagraph(startOfParagraphToMove) == destination) { |
822 RefPtr<Node> placeholder = createBreakElement(document()); | 822 RefPtr<Node> placeholder = createBreakElement(document()); |
823 insertNodeBefore(placeholder, startOfParagraphToMove.deepEquivalent().de
precatedNode()); | 823 insertNodeBefore(placeholder, startOfParagraphToMove.deepEquivalent().de
precatedNode()); |
824 destination = VisiblePosition(positionBeforeNode(*placeholder)); | 824 destination = VisiblePosition(positionBeforeNode(placeholder.get())); |
825 } | 825 } |
826 | 826 |
827 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove)
, destination); | 827 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove)
, destination); |
828 | 828 |
829 // Merging forward will remove m_endOfInsertedContent from the document. | 829 // Merging forward will remove m_endOfInsertedContent from the document. |
830 if (mergeForward) { | 830 if (mergeForward) { |
831 if (m_startOfInsertedContent.isOrphan()) | 831 if (m_startOfInsertedContent.isOrphan()) |
832 m_startOfInsertedContent = endingSelection().visibleStart().deepEqui
valent(); | 832 m_startOfInsertedContent = endingSelection().visibleStart().deepEqui
valent(); |
833 m_endOfInsertedContent = endingSelection().visibleEnd().deepEquivalent(
); | 833 m_endOfInsertedContent = endingSelection().visibleEnd().deepEquivalent(
); |
834 // If we merged text nodes, m_endOfInsertedContent could be null. If thi
s is the case, we use m_startOfInsertedContent. | 834 // If we merged text nodes, m_endOfInsertedContent could be null. If thi
s is the case, we use m_startOfInsertedContent. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 // If the downstream node has been removed there's no point in continuing. | 983 // If the downstream node has been removed there's no point in continuing. |
984 if (!insertionPos.downstream().deprecatedNode()) | 984 if (!insertionPos.downstream().deprecatedNode()) |
985 return; | 985 return; |
986 | 986 |
987 // NOTE: This would be an incorrect usage of downstream() if downstream() we
re changed to mean the last position after | 987 // NOTE: This would be an incorrect usage of downstream() if downstream() we
re changed to mean the last position after |
988 // p that maps to the same visible position as p (since in the case where a
br is at the end of a block and collapsed | 988 // p that maps to the same visible position as p (since in the case where a
br is at the end of a block and collapsed |
989 // away, there are positions after the br which map to the same visible posi
tion as [br, 0]). | 989 // away, there are positions after the br which map to the same visible posi
tion as [br, 0]). |
990 Node* endBR = insertionPos.downstream().deprecatedNode()->hasTagName(brTag)
? insertionPos.downstream().deprecatedNode() : 0; | 990 Node* endBR = insertionPos.downstream().deprecatedNode()->hasTagName(brTag)
? insertionPos.downstream().deprecatedNode() : 0; |
991 VisiblePosition originalVisPosBeforeEndBR; | 991 VisiblePosition originalVisPosBeforeEndBR; |
992 if (endBR) | 992 if (endBR) |
993 originalVisPosBeforeEndBR = VisiblePosition(positionBeforeNode(*endBR),
DOWNSTREAM).previous(); | 993 originalVisPosBeforeEndBR = VisiblePosition(positionBeforeNode(endBR), D
OWNSTREAM).previous(); |
994 | 994 |
995 RefPtr<Node> insertionBlock = enclosingBlock(insertionPos.deprecatedNode()); | 995 RefPtr<Node> insertionBlock = enclosingBlock(insertionPos.deprecatedNode()); |
996 | 996 |
997 // Adjust insertionPos to prevent nesting. | 997 // Adjust insertionPos to prevent nesting. |
998 // If the start was in a Mail blockquote, we will have already handled adjus
ting insertionPos above. | 998 // If the start was in a Mail blockquote, we will have already handled adjus
ting insertionPos above. |
999 if (m_preventNesting && insertionBlock && !isTableCell(insertionBlock.get())
&& !startIsInsideMailBlockquote) { | 999 if (m_preventNesting && insertionBlock && !isTableCell(insertionBlock.get())
&& !startIsInsideMailBlockquote) { |
1000 ASSERT(insertionBlock != currentRoot); | 1000 ASSERT(insertionBlock != currentRoot); |
1001 VisiblePosition visibleInsertionPos(insertionPos); | 1001 VisiblePosition visibleInsertionPos(insertionPos); |
1002 if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInserti
onPos) && fragment.hasInterchangeNewlineAtEnd())) | 1002 if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInserti
onPos) && fragment.hasInterchangeNewlineAtEnd())) |
1003 insertionPos = positionInParentAfterNode(*insertionBlock); | 1003 insertionPos = positionInParentAfterNode(*insertionBlock); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 m_matchStyle = false; | 1226 m_matchStyle = false; |
1227 | 1227 |
1228 completeHTMLReplacement(lastPositionToSelect); | 1228 completeHTMLReplacement(lastPositionToSelect); |
1229 } | 1229 } |
1230 | 1230 |
1231 bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR, const VisiblePositi
on& originalVisPosBeforeEndBR) | 1231 bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR, const VisiblePositi
on& originalVisPosBeforeEndBR) |
1232 { | 1232 { |
1233 if (!endBR || !endBR->inDocument()) | 1233 if (!endBR || !endBR->inDocument()) |
1234 return false; | 1234 return false; |
1235 | 1235 |
1236 VisiblePosition visiblePos(positionBeforeNode(*endBR)); | 1236 VisiblePosition visiblePos(positionBeforeNode(endBR)); |
1237 | 1237 |
1238 // Don't remove the br if nothing was inserted. | 1238 // Don't remove the br if nothing was inserted. |
1239 if (visiblePos.previous() == originalVisPosBeforeEndBR) | 1239 if (visiblePos.previous() == originalVisPosBeforeEndBR) |
1240 return false; | 1240 return false; |
1241 | 1241 |
1242 // Remove the br if it is collapsed away and so is unnecessary. | 1242 // Remove the br if it is collapsed away and so is unnecessary. |
1243 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa
ragraph(visiblePos)) | 1243 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa
ragraph(visiblePos)) |
1244 return true; | 1244 return true; |
1245 | 1245 |
1246 // A br that was originally holding a line open should be displaced by inser
ted content or turned into a line break. | 1246 // A br that was originally holding a line open should be displaced by inser
ted content or turned into a line break. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 RefPtr<Node> nodeAfterInsertionPos = endingSelection().end().downstream().an
chorNode(); | 1483 RefPtr<Node> nodeAfterInsertionPos = endingSelection().end().downstream().an
chorNode(); |
1484 Text* textNode = toText(fragment.firstChild()); | 1484 Text* textNode = toText(fragment.firstChild()); |
1485 // Our fragment creation code handles tabs, spaces, and newlines, so we don'
t have to worry about those here. | 1485 // Our fragment creation code handles tabs, spaces, and newlines, so we don'
t have to worry about those here. |
1486 | 1486 |
1487 Position start = endingSelection().start(); | 1487 Position start = endingSelection().start(); |
1488 Position end = replaceSelectedTextInNode(textNode->data()); | 1488 Position end = replaceSelectedTextInNode(textNode->data()); |
1489 if (end.isNull()) | 1489 if (end.isNull()) |
1490 return false; | 1490 return false; |
1491 | 1491 |
1492 if (nodeAfterInsertionPos && nodeAfterInsertionPos->parentNode() && nodeAfte
rInsertionPos->hasTagName(brTag) | 1492 if (nodeAfterInsertionPos && nodeAfterInsertionPos->parentNode() && nodeAfte
rInsertionPos->hasTagName(brTag) |
1493 && shouldRemoveEndBR(nodeAfterInsertionPos.get(), VisiblePosition(positi
onBeforeNode(*nodeAfterInsertionPos)))) | 1493 && shouldRemoveEndBR(nodeAfterInsertionPos.get(), VisiblePosition(positi
onBeforeNode(nodeAfterInsertionPos.get())))) |
1494 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); | 1494 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); |
1495 | 1495 |
1496 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); | 1496 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); |
1497 | 1497 |
1498 setEndingSelection(selectionAfterReplace); | 1498 setEndingSelection(selectionAfterReplace); |
1499 | 1499 |
1500 return true; | 1500 return true; |
1501 } | 1501 } |
1502 | 1502 |
1503 } // namespace WebCore | 1503 } // namespace WebCore |
OLD | NEW |