| 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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 { | 670 { |
| 671 Node* pastEndNode = insertedNodes.pastLastLeaf(); | 671 Node* pastEndNode = insertedNodes.pastLastLeaf(); |
| 672 Node* next = nullptr; | 672 Node* next = nullptr; |
| 673 for (Node* node = insertedNodes.firstNodeInserted(); node && node != pastEnd
Node; node = next) { | 673 for (Node* node = insertedNodes.firstNodeInserted(); node && node != pastEnd
Node; node = next) { |
| 674 next = NodeTraversal::next(*node); | 674 next = NodeTraversal::next(*node); |
| 675 | 675 |
| 676 if (!node->isHTMLElement()) | 676 if (!node->isHTMLElement()) |
| 677 continue; | 677 continue; |
| 678 // moveElementOutOfAncestor() in a previous iteration might have failed, | 678 // moveElementOutOfAncestor() in a previous iteration might have failed, |
| 679 // and |node| might have been detached from the document tree. | 679 // and |node| might have been detached from the document tree. |
| 680 if (!node->inShadowIncludingDocument()) | 680 if (!node->isConnected()) |
| 681 continue; | 681 continue; |
| 682 | 682 |
| 683 HTMLElement& element = toHTMLElement(*node); | 683 HTMLElement& element = toHTMLElement(*node); |
| 684 if (isProhibitedParagraphChild(element.localName())) { | 684 if (isProhibitedParagraphChild(element.localName())) { |
| 685 if (HTMLElement* paragraphElement = toHTMLElement(enclosingElementWi
thTag(Position::inParentBeforeNode(element), pTag))) { | 685 if (HTMLElement* paragraphElement = toHTMLElement(enclosingElementWi
thTag(Position::inParentBeforeNode(element), pTag))) { |
| 686 moveElementOutOfAncestor(&element, paragraphElement, editingStat
e); | 686 moveElementOutOfAncestor(&element, paragraphElement, editingStat
e); |
| 687 if (editingState->isAborted()) | 687 if (editingState->isAborted()) |
| 688 return; | 688 return; |
| 689 } | 689 } |
| 690 } | 690 } |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 if (editingState->isAborted()) | 1232 if (editingState->isAborted()) |
| 1233 return; | 1233 return; |
| 1234 } else { | 1234 } else { |
| 1235 insertNodeAt(refNode, insertionPos, editingState); | 1235 insertNodeAt(refNode, insertionPos, editingState); |
| 1236 if (editingState->isAborted()) | 1236 if (editingState->isAborted()) |
| 1237 return; | 1237 return; |
| 1238 insertedNodes.respondToNodeInsertion(*refNode); | 1238 insertedNodes.respondToNodeInsertion(*refNode); |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 // Mutation events (bug 22634) may have already removed the inserted content | 1241 // Mutation events (bug 22634) may have already removed the inserted content |
| 1242 if (!refNode->inShadowIncludingDocument()) | 1242 if (!refNode->isConnected()) |
| 1243 return; | 1243 return; |
| 1244 | 1244 |
| 1245 bool plainTextFragment = isPlainTextMarkup(refNode); | 1245 bool plainTextFragment = isPlainTextMarkup(refNode); |
| 1246 | 1246 |
| 1247 while (node) { | 1247 while (node) { |
| 1248 Node* next = node->nextSibling(); | 1248 Node* next = node->nextSibling(); |
| 1249 fragment.removeNode(node); | 1249 fragment.removeNode(node); |
| 1250 insertNodeAfter(node, refNode, editingState); | 1250 insertNodeAfter(node, refNode, editingState); |
| 1251 if (editingState->isAborted()) | 1251 if (editingState->isAborted()) |
| 1252 return; | 1252 return; |
| 1253 insertedNodes.respondToNodeInsertion(*node); | 1253 insertedNodes.respondToNodeInsertion(*node); |
| 1254 | 1254 |
| 1255 // Mutation events (bug 22634) may have already removed the inserted con
tent | 1255 // Mutation events (bug 22634) may have already removed the inserted con
tent |
| 1256 if (!node->inShadowIncludingDocument()) | 1256 if (!node->isConnected()) |
| 1257 return; | 1257 return; |
| 1258 | 1258 |
| 1259 refNode = node; | 1259 refNode = node; |
| 1260 if (node && plainTextFragment) | 1260 if (node && plainTextFragment) |
| 1261 plainTextFragment = isPlainTextMarkup(node); | 1261 plainTextFragment = isPlainTextMarkup(node); |
| 1262 node = next; | 1262 node = next; |
| 1263 } | 1263 } |
| 1264 | 1264 |
| 1265 if (isRichlyEditablePosition(insertionPos)) | 1265 if (isRichlyEditablePosition(insertionPos)) |
| 1266 removeUnrenderedTextNodesAtEnds(insertedNodes); | 1266 removeUnrenderedTextNodesAtEnds(insertedNodes); |
| 1267 | 1267 |
| 1268 if (!handledStyleSpans) { | 1268 if (!handledStyleSpans) { |
| 1269 handleStyleSpans(insertedNodes, editingState); | 1269 handleStyleSpans(insertedNodes, editingState); |
| 1270 if (editingState->isAborted()) | 1270 if (editingState->isAborted()) |
| 1271 return; | 1271 return; |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 // Mutation events (bug 20161) may have already removed the inserted content | 1274 // Mutation events (bug 20161) may have already removed the inserted content |
| 1275 if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted()
->inShadowIncludingDocument()) | 1275 if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted()
->isConnected()) |
| 1276 return; | 1276 return; |
| 1277 | 1277 |
| 1278 // Scripts specified in javascript protocol may remove |enclosingBlockOfInse
rtionPos| | 1278 // Scripts specified in javascript protocol may remove |enclosingBlockOfInse
rtionPos| |
| 1279 // during insertion, e.g. <iframe src="javascript:..."> | 1279 // during insertion, e.g. <iframe src="javascript:..."> |
| 1280 if (enclosingBlockOfInsertionPos && !enclosingBlockOfInsertionPos->inShadowI
ncludingDocument()) | 1280 if (enclosingBlockOfInsertionPos && !enclosingBlockOfInsertionPos->isConnect
ed()) |
| 1281 enclosingBlockOfInsertionPos = nullptr; | 1281 enclosingBlockOfInsertionPos = nullptr; |
| 1282 | 1282 |
| 1283 VisiblePosition startOfInsertedContent = createVisiblePosition(firstPosition
InOrBeforeNode(insertedNodes.firstNodeInserted())); | 1283 VisiblePosition startOfInsertedContent = createVisiblePosition(firstPosition
InOrBeforeNode(insertedNodes.firstNodeInserted())); |
| 1284 | 1284 |
| 1285 // We inserted before the enclosingBlockOfInsertionPos to prevent nesting, a
nd the content before the enclosingBlockOfInsertionPos wasn't in its own block a
nd | 1285 // We inserted before the enclosingBlockOfInsertionPos to prevent nesting, a
nd the content before the enclosingBlockOfInsertionPos wasn't in its own block a
nd |
| 1286 // didn't have a br after it, so the inserted content ended up in the same p
aragraph. | 1286 // didn't have a br after it, so the inserted content ended up in the same p
aragraph. |
| 1287 if (!startOfInsertedContent.isNull() && enclosingBlockOfInsertionPos && inse
rtionPos.anchorNode() == enclosingBlockOfInsertionPos->parentNode() && (unsigned
)insertionPos.computeEditingOffset() < enclosingBlockOfInsertionPos->nodeIndex()
&& !isStartOfParagraph(startOfInsertedContent)) { | 1287 if (!startOfInsertedContent.isNull() && enclosingBlockOfInsertionPos && inse
rtionPos.anchorNode() == enclosingBlockOfInsertionPos->parentNode() && (unsigned
)insertionPos.computeEditingOffset() < enclosingBlockOfInsertionPos->nodeIndex()
&& !isStartOfParagraph(startOfInsertedContent)) { |
| 1288 insertNodeAt(HTMLBRElement::create(document()), startOfInsertedContent.d
eepEquivalent(), editingState); | 1288 insertNodeAt(HTMLBRElement::create(document()), startOfInsertedContent.d
eepEquivalent(), editingState); |
| 1289 if (editingState->isAborted()) | 1289 if (editingState->isAborted()) |
| 1290 return; | 1290 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 // and it was not wrapped in a block, the selection that was pasted into
ended | 1345 // and it was not wrapped in a block, the selection that was pasted into
ended |
| 1346 // at the end of a block and the next paragraph didn't start at the star
t of a block. | 1346 // at the end of a block and the next paragraph didn't start at the star
t of a block. |
| 1347 // Insert a line break just after the inserted content to separate it fr
om what | 1347 // Insert a line break just after the inserted content to separate it fr
om what |
| 1348 // comes after and prevent that from happening. | 1348 // comes after and prevent that from happening. |
| 1349 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); | 1349 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); |
| 1350 if (startOfParagraph(endOfInsertedContent).deepEquivalent() == startOfPa
ragraphToMove.deepEquivalent()) { | 1350 if (startOfParagraph(endOfInsertedContent).deepEquivalent() == startOfPa
ragraphToMove.deepEquivalent()) { |
| 1351 insertNodeAt(HTMLBRElement::create(document()), endOfInsertedContent
.deepEquivalent(), editingState); | 1351 insertNodeAt(HTMLBRElement::create(document()), endOfInsertedContent
.deepEquivalent(), editingState); |
| 1352 if (editingState->isAborted()) | 1352 if (editingState->isAborted()) |
| 1353 return; | 1353 return; |
| 1354 // Mutation events (bug 22634) triggered by inserting the <br> might
have removed the content we're about to move | 1354 // Mutation events (bug 22634) triggered by inserting the <br> might
have removed the content we're about to move |
| 1355 if (!startOfParagraphToMove.deepEquivalent().inShadowIncludingDocume
nt()) | 1355 if (!startOfParagraphToMove.deepEquivalent().isConnected()) |
| 1356 return; | 1356 return; |
| 1357 } | 1357 } |
| 1358 | 1358 |
| 1359 // FIXME: Maintain positions for the start and end of inserted content i
nstead of keeping nodes. The nodes are | 1359 // FIXME: Maintain positions for the start and end of inserted content i
nstead of keeping nodes. The nodes are |
| 1360 // only ever used to create positions where inserted content starts/ends
. | 1360 // only ever used to create positions where inserted content starts/ends
. |
| 1361 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToM
ove), destination, editingState); | 1361 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToM
ove), destination, editingState); |
| 1362 if (editingState->isAborted()) | 1362 if (editingState->isAborted()) |
| 1363 return; | 1363 return; |
| 1364 m_startOfInsertedContent = mostForwardCaretPosition(endingSelection().vi
sibleStart().deepEquivalent()); | 1364 m_startOfInsertedContent = mostForwardCaretPosition(endingSelection().vi
sibleStart().deepEquivalent()); |
| 1365 if (m_endOfInsertedContent.isOrphan()) | 1365 if (m_endOfInsertedContent.isOrphan()) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 // If we are dealing with a fragment created from plain text | 1425 // If we are dealing with a fragment created from plain text |
| 1426 // no style matching is necessary. | 1426 // no style matching is necessary. |
| 1427 if (plainTextFragment) | 1427 if (plainTextFragment) |
| 1428 m_matchStyle = false; | 1428 m_matchStyle = false; |
| 1429 | 1429 |
| 1430 completeHTMLReplacement(lastPositionToSelect, editingState); | 1430 completeHTMLReplacement(lastPositionToSelect, editingState); |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 bool ReplaceSelectionCommand::shouldRemoveEndBR(HTMLBRElement* endBR, const Visi
blePosition& originalVisPosBeforeEndBR) | 1433 bool ReplaceSelectionCommand::shouldRemoveEndBR(HTMLBRElement* endBR, const Visi
blePosition& originalVisPosBeforeEndBR) |
| 1434 { | 1434 { |
| 1435 if (!endBR || !endBR->inShadowIncludingDocument()) | 1435 if (!endBR || !endBR->isConnected()) |
| 1436 return false; | 1436 return false; |
| 1437 | 1437 |
| 1438 VisiblePosition visiblePos = VisiblePosition::beforeNode(endBR); | 1438 VisiblePosition visiblePos = VisiblePosition::beforeNode(endBR); |
| 1439 | 1439 |
| 1440 // Don't remove the br if nothing was inserted. | 1440 // Don't remove the br if nothing was inserted. |
| 1441 if (previousPositionOf(visiblePos).deepEquivalent() == originalVisPosBeforeE
ndBR.deepEquivalent()) | 1441 if (previousPositionOf(visiblePos).deepEquivalent() == originalVisPosBeforeE
ndBR.deepEquivalent()) |
| 1442 return false; | 1442 return false; |
| 1443 | 1443 |
| 1444 // Remove the br if it is collapsed away and so is unnecessary. | 1444 // Remove the br if it is collapsed away and so is unnecessary. |
| 1445 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa
ragraph(visiblePos)) | 1445 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa
ragraph(visiblePos)) |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1755 visitor->trace(m_startOfInsertedContent); | 1755 visitor->trace(m_startOfInsertedContent); |
| 1756 visitor->trace(m_endOfInsertedContent); | 1756 visitor->trace(m_endOfInsertedContent); |
| 1757 visitor->trace(m_insertionStyle); | 1757 visitor->trace(m_insertionStyle); |
| 1758 visitor->trace(m_documentFragment); | 1758 visitor->trace(m_documentFragment); |
| 1759 visitor->trace(m_startOfInsertedRange); | 1759 visitor->trace(m_startOfInsertedRange); |
| 1760 visitor->trace(m_endOfInsertedRange); | 1760 visitor->trace(m_endOfInsertedRange); |
| 1761 CompositeEditCommand::trace(visitor); | 1761 CompositeEditCommand::trace(visitor); |
| 1762 } | 1762 } |
| 1763 | 1763 |
| 1764 } // namespace blink | 1764 } // namespace blink |
| OLD | NEW |