| 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 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 return; | 983 return; |
| 984 | 984 |
| 985 // NOTE: This would be an incorrect usage of downstream() if downstream() we
re changed to mean the last position after | 985 // NOTE: This would be an incorrect usage of downstream() if downstream() we
re changed to mean the last position after |
| 986 // 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 | 986 // 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 |
| 987 // away, there are positions after the br which map to the same visible posi
tion as [br, 0]). | 987 // away, there are positions after the br which map to the same visible posi
tion as [br, 0]). |
| 988 Node* endBR = insertionPos.downstream().deprecatedNode()->hasTagName(brTag)
? insertionPos.downstream().deprecatedNode() : 0; | 988 Node* endBR = insertionPos.downstream().deprecatedNode()->hasTagName(brTag)
? insertionPos.downstream().deprecatedNode() : 0; |
| 989 VisiblePosition originalVisPosBeforeEndBR; | 989 VisiblePosition originalVisPosBeforeEndBR; |
| 990 if (endBR) | 990 if (endBR) |
| 991 originalVisPosBeforeEndBR = VisiblePosition(positionBeforeNode(endBR), D
OWNSTREAM).previous(); | 991 originalVisPosBeforeEndBR = VisiblePosition(positionBeforeNode(endBR), D
OWNSTREAM).previous(); |
| 992 | 992 |
| 993 startBlock = enclosingBlock(insertionPos.deprecatedNode()); | 993 RefPtr<Node> insertionBlock = enclosingBlock(insertionPos.deprecatedNode()); |
| 994 | 994 |
| 995 // Adjust insertionPos to prevent nesting. | 995 // Adjust insertionPos to prevent nesting. |
| 996 // If the start was in a Mail blockquote, we will have already handled adjus
ting insertionPos above. | 996 // If the start was in a Mail blockquote, we will have already handled adjus
ting insertionPos above. |
| 997 if (m_preventNesting && startBlock && !isTableCell(startBlock) && !startIsIn
sideMailBlockquote) { | 997 if (m_preventNesting && insertionBlock && !isTableCell(insertionBlock.get())
&& !startIsInsideMailBlockquote) { |
| 998 ASSERT(startBlock != currentRoot); | 998 ASSERT(insertionBlock != currentRoot); |
| 999 VisiblePosition visibleInsertionPos(insertionPos); | 999 VisiblePosition visibleInsertionPos(insertionPos); |
| 1000 if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInserti
onPos) && fragment.hasInterchangeNewlineAtEnd())) | 1000 if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInserti
onPos) && fragment.hasInterchangeNewlineAtEnd())) |
| 1001 insertionPos = positionInParentAfterNode(startBlock); | 1001 insertionPos = positionInParentAfterNode(insertionBlock.get()); |
| 1002 else if (isStartOfBlock(visibleInsertionPos)) | 1002 else if (isStartOfBlock(visibleInsertionPos)) |
| 1003 insertionPos = positionInParentBeforeNode(startBlock); | 1003 insertionPos = positionInParentBeforeNode(insertionBlock.get()); |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 // Paste at start or end of link goes outside of link. | 1006 // Paste at start or end of link goes outside of link. |
| 1007 insertionPos = positionAvoidingSpecialElementBoundary(insertionPos); | 1007 insertionPos = positionAvoidingSpecialElementBoundary(insertionPos); |
| 1008 | 1008 |
| 1009 // FIXME: Can this wait until after the operation has been performed? There
doesn't seem to be | 1009 // FIXME: Can this wait until after the operation has been performed? There
doesn't seem to be |
| 1010 // any work performed after this that queries or uses the typing style. | 1010 // any work performed after this that queries or uses the typing style. |
| 1011 if (Frame* frame = document().frame()) | 1011 if (Frame* frame = document().frame()) |
| 1012 frame->selection().clearTypingStyle(); | 1012 frame->selection().clearTypingStyle(); |
| 1013 | 1013 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 | 1103 |
| 1104 removeUnrenderedTextNodesAtEnds(insertedNodes); | 1104 removeUnrenderedTextNodesAtEnds(insertedNodes); |
| 1105 | 1105 |
| 1106 if (!handledStyleSpans) | 1106 if (!handledStyleSpans) |
| 1107 handleStyleSpans(insertedNodes); | 1107 handleStyleSpans(insertedNodes); |
| 1108 | 1108 |
| 1109 // Mutation events (bug 20161) may have already removed the inserted content | 1109 // Mutation events (bug 20161) may have already removed the inserted content |
| 1110 if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted()
->inDocument()) | 1110 if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted()
->inDocument()) |
| 1111 return; | 1111 return; |
| 1112 | 1112 |
| 1113 // Scripts specified in javascript protocol may remove |insertionBlock| |
| 1114 // during insertion, e.g. <iframe src="javascript:..."> |
| 1115 if (insertionBlock && !insertionBlock->inDocument()) |
| 1116 insertionBlock = 0; |
| 1117 |
| 1113 VisiblePosition startOfInsertedContent = firstPositionInOrBeforeNode(inserte
dNodes.firstNodeInserted()); | 1118 VisiblePosition startOfInsertedContent = firstPositionInOrBeforeNode(inserte
dNodes.firstNodeInserted()); |
| 1114 | 1119 |
| 1115 // We inserted before the startBlock to prevent nesting, and the content bef
ore the startBlock wasn't in its own block and | 1120 // We inserted before the insertionBlock to prevent nesting, and the content
before the insertionBlock wasn't in its own block and |
| 1116 // didn't have a br after it, so the inserted content ended up in the same p
aragraph. | 1121 // didn't have a br after it, so the inserted content ended up in the same p
aragraph. |
| 1117 if (startBlock && insertionPos.deprecatedNode() == startBlock->parentNode()
&& (unsigned)insertionPos.deprecatedEditingOffset() < startBlock->nodeIndex() &&
!isStartOfParagraph(startOfInsertedContent)) | 1122 if (insertionBlock && insertionPos.deprecatedNode() == insertionBlock->paren
tNode() && (unsigned)insertionPos.deprecatedEditingOffset() < insertionBlock->no
deIndex() && !isStartOfParagraph(startOfInsertedContent)) |
| 1118 insertNodeAt(createBreakElement(document()).get(), startOfInsertedConten
t.deepEquivalent()); | 1123 insertNodeAt(createBreakElement(document()).get(), startOfInsertedConten
t.deepEquivalent()); |
| 1119 | 1124 |
| 1120 if (endBR && (plainTextFragment || shouldRemoveEndBR(endBR, originalVisPosBe
foreEndBR))) { | 1125 if (endBR && (plainTextFragment || shouldRemoveEndBR(endBR, originalVisPosBe
foreEndBR))) { |
| 1121 RefPtr<Node> parent = endBR->parentNode(); | 1126 RefPtr<Node> parent = endBR->parentNode(); |
| 1122 insertedNodes.willRemoveNode(*endBR); | 1127 insertedNodes.willRemoveNode(*endBR); |
| 1123 removeNode(endBR); | 1128 removeNode(endBR); |
| 1124 if (Node* nodeToRemove = highestNodeToRemoveInPruning(parent.get())) { | 1129 if (Node* nodeToRemove = highestNodeToRemoveInPruning(parent.get())) { |
| 1125 insertedNodes.willRemoveNode(*nodeToRemove); | 1130 insertedNodes.willRemoveNode(*nodeToRemove); |
| 1126 removeNode(nodeToRemove); | 1131 removeNode(nodeToRemove); |
| 1127 } | 1132 } |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); | 1491 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); |
| 1487 | 1492 |
| 1488 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); | 1493 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); |
| 1489 | 1494 |
| 1490 setEndingSelection(selectionAfterReplace); | 1495 setEndingSelection(selectionAfterReplace); |
| 1491 | 1496 |
| 1492 return true; | 1497 return true; |
| 1493 } | 1498 } |
| 1494 | 1499 |
| 1495 } // namespace WebCore | 1500 } // namespace WebCore |
| OLD | NEW |