Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp

Issue 1858163002: Rename inDocument() to inShadowIncludingDocument() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
670 { 670 {
671 RawPtr<Node> pastEndNode = insertedNodes.pastLastLeaf(); 671 RawPtr<Node> pastEndNode = insertedNodes.pastLastLeaf();
672 RawPtr<Node> next = nullptr; 672 RawPtr<Node> next = nullptr;
673 for (RawPtr<Node> node = insertedNodes.firstNodeInserted(); node && node != pastEndNode; node = next) { 673 for (RawPtr<Node> node = insertedNodes.firstNodeInserted(); node && node != pastEndNode; 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->inDocument()) 680 if (!node->inShadowIncludingDocument())
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(positionInParentBeforeNode(element), pTag))) { 685 if (HTMLElement* paragraphElement = toHTMLElement(enclosingElementWi thTag(positionInParentBeforeNode(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 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 if (editingState->isAborted()) 1189 if (editingState->isAborted())
1190 return; 1190 return;
1191 } else { 1191 } else {
1192 insertNodeAt(refNode, insertionPos, editingState); 1192 insertNodeAt(refNode, insertionPos, editingState);
1193 if (editingState->isAborted()) 1193 if (editingState->isAborted())
1194 return; 1194 return;
1195 insertedNodes.respondToNodeInsertion(*refNode); 1195 insertedNodes.respondToNodeInsertion(*refNode);
1196 } 1196 }
1197 1197
1198 // Mutation events (bug 22634) may have already removed the inserted content 1198 // Mutation events (bug 22634) may have already removed the inserted content
1199 if (!refNode->inDocument()) 1199 if (!refNode->inShadowIncludingDocument())
1200 return; 1200 return;
1201 1201
1202 bool plainTextFragment = isPlainTextMarkup(refNode.get()); 1202 bool plainTextFragment = isPlainTextMarkup(refNode.get());
1203 1203
1204 while (node) { 1204 while (node) {
1205 RawPtr<Node> next = node->nextSibling(); 1205 RawPtr<Node> next = node->nextSibling();
1206 fragment.removeNode(node.get()); 1206 fragment.removeNode(node.get());
1207 insertNodeAfter(node, refNode, editingState); 1207 insertNodeAfter(node, refNode, editingState);
1208 if (editingState->isAborted()) 1208 if (editingState->isAborted())
1209 return; 1209 return;
1210 insertedNodes.respondToNodeInsertion(*node); 1210 insertedNodes.respondToNodeInsertion(*node);
1211 1211
1212 // Mutation events (bug 22634) may have already removed the inserted con tent 1212 // Mutation events (bug 22634) may have already removed the inserted con tent
1213 if (!node->inDocument()) 1213 if (!node->inShadowIncludingDocument())
1214 return; 1214 return;
1215 1215
1216 refNode = node; 1216 refNode = node;
1217 if (node && plainTextFragment) 1217 if (node && plainTextFragment)
1218 plainTextFragment = isPlainTextMarkup(node.get()); 1218 plainTextFragment = isPlainTextMarkup(node.get());
1219 node = next; 1219 node = next;
1220 } 1220 }
1221 1221
1222 if (isRichlyEditablePosition(insertionPos)) 1222 if (isRichlyEditablePosition(insertionPos))
1223 removeUnrenderedTextNodesAtEnds(insertedNodes); 1223 removeUnrenderedTextNodesAtEnds(insertedNodes);
1224 1224
1225 if (!handledStyleSpans) { 1225 if (!handledStyleSpans) {
1226 handleStyleSpans(insertedNodes, editingState); 1226 handleStyleSpans(insertedNodes, editingState);
1227 if (editingState->isAborted()) 1227 if (editingState->isAborted())
1228 return; 1228 return;
1229 } 1229 }
1230 1230
1231 // Mutation events (bug 20161) may have already removed the inserted content 1231 // Mutation events (bug 20161) may have already removed the inserted content
1232 if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted() ->inDocument()) 1232 if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted() ->inShadowIncludingDocument())
1233 return; 1233 return;
1234 1234
1235 // Scripts specified in javascript protocol may remove |enclosingBlockOfInse rtionPos| 1235 // Scripts specified in javascript protocol may remove |enclosingBlockOfInse rtionPos|
1236 // during insertion, e.g. <iframe src="javascript:..."> 1236 // during insertion, e.g. <iframe src="javascript:...">
1237 if (enclosingBlockOfInsertionPos && !enclosingBlockOfInsertionPos->inDocumen t()) 1237 if (enclosingBlockOfInsertionPos && !enclosingBlockOfInsertionPos->inShadowI ncludingDocument())
1238 enclosingBlockOfInsertionPos = nullptr; 1238 enclosingBlockOfInsertionPos = nullptr;
1239 1239
1240 VisiblePosition startOfInsertedContent = createVisiblePosition(firstPosition InOrBeforeNode(insertedNodes.firstNodeInserted())); 1240 VisiblePosition startOfInsertedContent = createVisiblePosition(firstPosition InOrBeforeNode(insertedNodes.firstNodeInserted()));
1241 1241
1242 // We inserted before the enclosingBlockOfInsertionPos to prevent nesting, a nd the content before the enclosingBlockOfInsertionPos wasn't in its own block a nd 1242 // We inserted before the enclosingBlockOfInsertionPos to prevent nesting, a nd the content before the enclosingBlockOfInsertionPos wasn't in its own block a nd
1243 // didn't have a br after it, so the inserted content ended up in the same p aragraph. 1243 // didn't have a br after it, so the inserted content ended up in the same p aragraph.
1244 if (!startOfInsertedContent.isNull() && enclosingBlockOfInsertionPos && inse rtionPos.anchorNode() == enclosingBlockOfInsertionPos->parentNode() && (unsigned )insertionPos.computeEditingOffset() < enclosingBlockOfInsertionPos->nodeIndex() && !isStartOfParagraph(startOfInsertedContent)) { 1244 if (!startOfInsertedContent.isNull() && enclosingBlockOfInsertionPos && inse rtionPos.anchorNode() == enclosingBlockOfInsertionPos->parentNode() && (unsigned )insertionPos.computeEditingOffset() < enclosingBlockOfInsertionPos->nodeIndex() && !isStartOfParagraph(startOfInsertedContent)) {
1245 insertNodeAt(HTMLBRElement::create(document()).get(), startOfInsertedCon tent.deepEquivalent(), editingState); 1245 insertNodeAt(HTMLBRElement::create(document()).get(), startOfInsertedCon tent.deepEquivalent(), editingState);
1246 if (editingState->isAborted()) 1246 if (editingState->isAborted())
1247 return; 1247 return;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 // and it was not wrapped in a block, the selection that was pasted into ended 1302 // and it was not wrapped in a block, the selection that was pasted into ended
1303 // at the end of a block and the next paragraph didn't start at the star t of a block. 1303 // at the end of a block and the next paragraph didn't start at the star t of a block.
1304 // Insert a line break just after the inserted content to separate it fr om what 1304 // Insert a line break just after the inserted content to separate it fr om what
1305 // comes after and prevent that from happening. 1305 // comes after and prevent that from happening.
1306 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent(); 1306 VisiblePosition endOfInsertedContent = positionAtEndOfInsertedContent();
1307 if (startOfParagraph(endOfInsertedContent).deepEquivalent() == startOfPa ragraphToMove.deepEquivalent()) { 1307 if (startOfParagraph(endOfInsertedContent).deepEquivalent() == startOfPa ragraphToMove.deepEquivalent()) {
1308 insertNodeAt(HTMLBRElement::create(document()).get(), endOfInsertedC ontent.deepEquivalent(), editingState); 1308 insertNodeAt(HTMLBRElement::create(document()).get(), endOfInsertedC ontent.deepEquivalent(), editingState);
1309 if (editingState->isAborted()) 1309 if (editingState->isAborted())
1310 return; 1310 return;
1311 // Mutation events (bug 22634) triggered by inserting the <br> might have removed the content we're about to move 1311 // Mutation events (bug 22634) triggered by inserting the <br> might have removed the content we're about to move
1312 if (!startOfParagraphToMove.deepEquivalent().inDocument()) 1312 if (!startOfParagraphToMove.deepEquivalent().inShadowIncludingDocume nt())
1313 return; 1313 return;
1314 } 1314 }
1315 1315
1316 // FIXME: Maintain positions for the start and end of inserted content i nstead of keeping nodes. The nodes are 1316 // FIXME: Maintain positions for the start and end of inserted content i nstead of keeping nodes. The nodes are
1317 // only ever used to create positions where inserted content starts/ends . 1317 // only ever used to create positions where inserted content starts/ends .
1318 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToM ove), destination, editingState); 1318 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToM ove), destination, editingState);
1319 if (editingState->isAborted()) 1319 if (editingState->isAborted())
1320 return; 1320 return;
1321 m_startOfInsertedContent = mostForwardCaretPosition(endingSelection().vi sibleStart().deepEquivalent()); 1321 m_startOfInsertedContent = mostForwardCaretPosition(endingSelection().vi sibleStart().deepEquivalent());
1322 if (m_endOfInsertedContent.isOrphan()) 1322 if (m_endOfInsertedContent.isOrphan())
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 // If we are dealing with a fragment created from plain text 1382 // If we are dealing with a fragment created from plain text
1383 // no style matching is necessary. 1383 // no style matching is necessary.
1384 if (plainTextFragment) 1384 if (plainTextFragment)
1385 m_matchStyle = false; 1385 m_matchStyle = false;
1386 1386
1387 completeHTMLReplacement(lastPositionToSelect, editingState); 1387 completeHTMLReplacement(lastPositionToSelect, editingState);
1388 } 1388 }
1389 1389
1390 bool ReplaceSelectionCommand::shouldRemoveEndBR(HTMLBRElement* endBR, const Visi blePosition& originalVisPosBeforeEndBR) 1390 bool ReplaceSelectionCommand::shouldRemoveEndBR(HTMLBRElement* endBR, const Visi blePosition& originalVisPosBeforeEndBR)
1391 { 1391 {
1392 if (!endBR || !endBR->inDocument()) 1392 if (!endBR || !endBR->inShadowIncludingDocument())
1393 return false; 1393 return false;
1394 1394
1395 VisiblePosition visiblePos = createVisiblePosition(positionBeforeNode(endBR) ); 1395 VisiblePosition visiblePos = createVisiblePosition(positionBeforeNode(endBR) );
1396 1396
1397 // Don't remove the br if nothing was inserted. 1397 // Don't remove the br if nothing was inserted.
1398 if (previousPositionOf(visiblePos).deepEquivalent() == originalVisPosBeforeE ndBR.deepEquivalent()) 1398 if (previousPositionOf(visiblePos).deepEquivalent() == originalVisPosBeforeE ndBR.deepEquivalent())
1399 return false; 1399 return false;
1400 1400
1401 // Remove the br if it is collapsed away and so is unnecessary. 1401 // Remove the br if it is collapsed away and so is unnecessary.
1402 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa ragraph(visiblePos)) 1402 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa ragraph(visiblePos))
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 visitor->trace(m_startOfInsertedContent); 1714 visitor->trace(m_startOfInsertedContent);
1715 visitor->trace(m_endOfInsertedContent); 1715 visitor->trace(m_endOfInsertedContent);
1716 visitor->trace(m_insertionStyle); 1716 visitor->trace(m_insertionStyle);
1717 visitor->trace(m_documentFragment); 1717 visitor->trace(m_documentFragment);
1718 visitor->trace(m_startOfInsertedRange); 1718 visitor->trace(m_startOfInsertedRange);
1719 visitor->trace(m_endOfInsertedRange); 1719 visitor->trace(m_endOfInsertedRange);
1720 CompositeEditCommand::trace(visitor); 1720 CompositeEditCommand::trace(visitor);
1721 } 1721 }
1722 1722
1723 } // namespace blink 1723 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698