| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 if (child) | 358 if (child) |
| 359 insertNodeBefore(insertChild, child, editingState); | 359 insertNodeBefore(insertChild, child, editingState); |
| 360 else | 360 else |
| 361 appendNode(insertChild, toContainerNode(refChild), editingState); | 361 appendNode(insertChild, toContainerNode(refChild), editingState); |
| 362 } else if (caretMinOffset(refChild) >= offset) { | 362 } else if (caretMinOffset(refChild) >= offset) { |
| 363 insertNodeBefore(insertChild, refChild, editingState); | 363 insertNodeBefore(insertChild, refChild, editingState); |
| 364 } else if (refChild->isTextNode() && caretMaxOffset(refChild) > offset) { | 364 } else if (refChild->isTextNode() && caretMaxOffset(refChild) > offset) { |
| 365 splitTextNode(toText(refChild), offset); | 365 splitTextNode(toText(refChild), offset); |
| 366 | 366 |
| 367 // Mutation events (bug 22634) from the text node insertion may have rem
oved the refChild | 367 // Mutation events (bug 22634) from the text node insertion may have rem
oved the refChild |
| 368 if (!refChild->inShadowIncludingDocument()) | 368 if (!refChild->isConnected()) |
| 369 return; | 369 return; |
| 370 insertNodeBefore(insertChild, refChild, editingState); | 370 insertNodeBefore(insertChild, refChild, editingState); |
| 371 } else { | 371 } else { |
| 372 insertNodeAfter(insertChild, refChild, editingState); | 372 insertNodeAfter(insertChild, refChild, editingState); |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 | 375 |
| 376 void CompositeEditCommand::appendNode(Node* node, ContainerNode* parent, Editing
State* editingState) | 376 void CompositeEditCommand::appendNode(Node* node, ContainerNode* parent, Editing
State* editingState) |
| 377 { | 377 { |
| 378 // When cloneParagraphUnderNewElement() clones the fallback content | 378 // When cloneParagraphUnderNewElement() clones the fallback content |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 { | 459 { |
| 460 // It would also be possible to implement all of ReplaceNodeWithSpanCommand | 460 // It would also be possible to implement all of ReplaceNodeWithSpanCommand |
| 461 // as a series of existing smaller edit commands. Someone who wanted to | 461 // as a series of existing smaller edit commands. Someone who wanted to |
| 462 // reduce the number of edit commands could do so here. | 462 // reduce the number of edit commands could do so here. |
| 463 ReplaceNodeWithSpanCommand* command = ReplaceNodeWithSpanCommand::create(nod
e); | 463 ReplaceNodeWithSpanCommand* command = ReplaceNodeWithSpanCommand::create(nod
e); |
| 464 // ReplaceNodeWithSpanCommand is never aborted. | 464 // ReplaceNodeWithSpanCommand is never aborted. |
| 465 applyCommandToComposite(command, ASSERT_NO_EDITING_ABORT); | 465 applyCommandToComposite(command, ASSERT_NO_EDITING_ABORT); |
| 466 // Returning a raw pointer here is OK because the command is retained by | 466 // Returning a raw pointer here is OK because the command is retained by |
| 467 // applyCommandToComposite (thus retaining the span), and the span is also | 467 // applyCommandToComposite (thus retaining the span), and the span is also |
| 468 // in the DOM tree, and thus alive whie it has a parent. | 468 // in the DOM tree, and thus alive whie it has a parent. |
| 469 DCHECK(command->spanElement()->inShadowIncludingDocument()) << command->span
Element(); | 469 DCHECK(command->spanElement()->isConnected()) << command->spanElement(); |
| 470 return command->spanElement(); | 470 return command->spanElement(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void CompositeEditCommand::prune(Node* node, EditingState* editingState, Node* e
xcludeNode) | 473 void CompositeEditCommand::prune(Node* node, EditingState* editingState, Node* e
xcludeNode) |
| 474 { | 474 { |
| 475 if (Node* highestNodeToRemove = highestNodeToRemoveInPruning(node, excludeNo
de)) | 475 if (Node* highestNodeToRemove = highestNodeToRemoveInPruning(node, excludeNo
de)) |
| 476 removeNode(highestNodeToRemove, editingState); | 476 removeNode(highestNodeToRemove, editingState); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void CompositeEditCommand::splitTextNode(Text* node, unsigned offset) | 479 void CompositeEditCommand::splitTextNode(Text* node, unsigned offset) |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 if (!anchorNode) | 1041 if (!anchorNode) |
| 1042 return; | 1042 return; |
| 1043 | 1043 |
| 1044 DCHECK(anchorNode->isLink()) << anchorNode; | 1044 DCHECK(anchorNode->isLink()) << anchorNode; |
| 1045 | 1045 |
| 1046 setEndingSelection(VisibleSelection::selectionFromContentsOfNode(anchorNode)
); | 1046 setEndingSelection(VisibleSelection::selectionFromContentsOfNode(anchorNode)
); |
| 1047 applyStyledElement(anchorNode, editingState); | 1047 applyStyledElement(anchorNode, editingState); |
| 1048 if (editingState->isAborted()) | 1048 if (editingState->isAborted()) |
| 1049 return; | 1049 return; |
| 1050 // Clones of anchorNode have been pushed down, now remove it. | 1050 // Clones of anchorNode have been pushed down, now remove it. |
| 1051 if (anchorNode->inShadowIncludingDocument()) | 1051 if (anchorNode->isConnected()) |
| 1052 removeNodePreservingChildren(anchorNode, editingState); | 1052 removeNodePreservingChildren(anchorNode, editingState); |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 // Clone the paragraph between start and end under blockElement, | 1055 // Clone the paragraph between start and end under blockElement, |
| 1056 // preserving the hierarchy up to outerNode. | 1056 // preserving the hierarchy up to outerNode. |
| 1057 | 1057 |
| 1058 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
const Position& end, Node* passedOuterNode, Element* blockElement, EditingState*
editingState) | 1058 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
const Position& end, Node* passedOuterNode, Element* blockElement, EditingState*
editingState) |
| 1059 { | 1059 { |
| 1060 DCHECK_LE(start, end); | 1060 DCHECK_LE(start, end); |
| 1061 DCHECK(passedOuterNode); | 1061 DCHECK(passedOuterNode); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1091 Node* child = item->cloneNode(isDisplayInsideTable(item)); | 1091 Node* child = item->cloneNode(isDisplayInsideTable(item)); |
| 1092 appendNode(child, toElement(lastNode), editingState); | 1092 appendNode(child, toElement(lastNode), editingState); |
| 1093 if (editingState->isAborted()) | 1093 if (editingState->isAborted()) |
| 1094 return; | 1094 return; |
| 1095 lastNode = child; | 1095 lastNode = child; |
| 1096 } | 1096 } |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 // Scripts specified in javascript protocol may remove |outerNode| | 1099 // Scripts specified in javascript protocol may remove |outerNode| |
| 1100 // during insertion, e.g. <iframe src="javascript:..."> | 1100 // during insertion, e.g. <iframe src="javascript:..."> |
| 1101 if (!outerNode->inShadowIncludingDocument()) | 1101 if (!outerNode->isConnected()) |
| 1102 return; | 1102 return; |
| 1103 | 1103 |
| 1104 // Handle the case of paragraphs with more than one node, | 1104 // Handle the case of paragraphs with more than one node, |
| 1105 // cloning all the siblings until end.anchorNode() is reached. | 1105 // cloning all the siblings until end.anchorNode() is reached. |
| 1106 | 1106 |
| 1107 if (start.anchorNode() != end.anchorNode() && !start.anchorNode()->isDescend
antOf(end.anchorNode())) { | 1107 if (start.anchorNode() != end.anchorNode() && !start.anchorNode()->isDescend
antOf(end.anchorNode())) { |
| 1108 // If end is not a descendant of outerNode we need to | 1108 // If end is not a descendant of outerNode we need to |
| 1109 // find the first common ancestor to increase the scope | 1109 // find the first common ancestor to increase the scope |
| 1110 // of our nextSibling traversal. | 1110 // of our nextSibling traversal. |
| 1111 while (outerNode && !end.anchorNode()->isDescendantOf(outerNode)) { | 1111 while (outerNode && !end.anchorNode()->isDescendantOf(outerNode)) { |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo
ved" and call shouldInsertFragment here. | 1310 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo
ved" and call shouldInsertFragment here. |
| 1311 | 1311 |
| 1312 setEndingSelection(VisibleSelection(start, end)); | 1312 setEndingSelection(VisibleSelection(start, end)); |
| 1313 document().frame()->spellChecker().clearMisspellingsAndBadGrammar(endingSele
ction()); | 1313 document().frame()->spellChecker().clearMisspellingsAndBadGrammar(endingSele
ction()); |
| 1314 deleteSelection(editingState, false, false, false); | 1314 deleteSelection(editingState, false, false, false); |
| 1315 if (editingState->isAborted()) | 1315 if (editingState->isAborted()) |
| 1316 return; | 1316 return; |
| 1317 | 1317 |
| 1318 DCHECK(destination.deepEquivalent().inShadowIncludingDocument()) << destinat
ion; | 1318 DCHECK(destination.deepEquivalent().isConnected()) << destination; |
| 1319 cleanupAfterDeletion(editingState, destination); | 1319 cleanupAfterDeletion(editingState, destination); |
| 1320 if (editingState->isAborted()) | 1320 if (editingState->isAborted()) |
| 1321 return; | 1321 return; |
| 1322 DCHECK(destination.deepEquivalent().inShadowIncludingDocument()) << destinat
ion; | 1322 DCHECK(destination.deepEquivalent().isConnected()) << destination; |
| 1323 | 1323 |
| 1324 // Add a br if pruning an empty block level element caused a collapse. For e
xample: | 1324 // Add a br if pruning an empty block level element caused a collapse. For e
xample: |
| 1325 // foo^ | 1325 // foo^ |
| 1326 // <div>bar</div> | 1326 // <div>bar</div> |
| 1327 // baz | 1327 // baz |
| 1328 // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That
would | 1328 // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That
would |
| 1329 // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br
. | 1329 // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br
. |
| 1330 // Must recononicalize these two VisiblePositions after the pruning above. | 1330 // Must recononicalize these two VisiblePositions after the pruning above. |
| 1331 VisiblePosition beforeParagraph = createVisiblePosition(beforeParagraphPosit
ion.position()); | 1331 VisiblePosition beforeParagraph = createVisiblePosition(beforeParagraphPosit
ion.position()); |
| 1332 VisiblePosition afterParagraph = createVisiblePosition(afterParagraphPositio
n.position()); | 1332 VisiblePosition afterParagraph = createVisiblePosition(afterParagraphPositio
n.position()); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1623 } | 1623 } |
| 1624 | 1624 |
| 1625 DEFINE_TRACE(CompositeEditCommand) | 1625 DEFINE_TRACE(CompositeEditCommand) |
| 1626 { | 1626 { |
| 1627 visitor->trace(m_commands); | 1627 visitor->trace(m_commands); |
| 1628 visitor->trace(m_composition); | 1628 visitor->trace(m_composition); |
| 1629 EditCommand::trace(visitor); | 1629 EditCommand::trace(visitor); |
| 1630 } | 1630 } |
| 1631 | 1631 |
| 1632 } // namespace blink | 1632 } // namespace blink |
| OLD | NEW |