| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 if (child) | 357 if (child) |
| 358 insertNodeBefore(insertChild, child, editingState); | 358 insertNodeBefore(insertChild, child, editingState); |
| 359 else | 359 else |
| 360 appendNode(insertChild, toContainerNode(refChild), editingState); | 360 appendNode(insertChild, toContainerNode(refChild), editingState); |
| 361 } else if (caretMinOffset(refChild) >= offset) { | 361 } else if (caretMinOffset(refChild) >= offset) { |
| 362 insertNodeBefore(insertChild, refChild, editingState); | 362 insertNodeBefore(insertChild, refChild, editingState); |
| 363 } else if (refChild->isTextNode() && caretMaxOffset(refChild) > offset) { | 363 } else if (refChild->isTextNode() && caretMaxOffset(refChild) > offset) { |
| 364 splitTextNode(toText(refChild), offset); | 364 splitTextNode(toText(refChild), offset); |
| 365 | 365 |
| 366 // Mutation events (bug 22634) from the text node insertion may have rem
oved the refChild | 366 // Mutation events (bug 22634) from the text node insertion may have rem
oved the refChild |
| 367 if (!refChild->inDocument()) | 367 if (!refChild->inShadowIncludingDocument()) |
| 368 return; | 368 return; |
| 369 insertNodeBefore(insertChild, refChild, editingState); | 369 insertNodeBefore(insertChild, refChild, editingState); |
| 370 } else { | 370 } else { |
| 371 insertNodeAfter(insertChild, refChild, editingState); | 371 insertNodeAfter(insertChild, refChild, editingState); |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 | 374 |
| 375 void CompositeEditCommand::appendNode(RawPtr<Node> node, RawPtr<ContainerNode> p
arent, EditingState* editingState) | 375 void CompositeEditCommand::appendNode(RawPtr<Node> node, RawPtr<ContainerNode> p
arent, EditingState* editingState) |
| 376 { | 376 { |
| 377 // When cloneParagraphUnderNewElement() clones the fallback content | 377 // When cloneParagraphUnderNewElement() clones the fallback content |
| (...skipping 81 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 RawPtr<ReplaceNodeWithSpanCommand> command = ReplaceNodeWithSpanCommand::cre
ate(node); | 463 RawPtr<ReplaceNodeWithSpanCommand> command = ReplaceNodeWithSpanCommand::cre
ate(node); |
| 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 ASSERT(command->spanElement()->inDocument()); | 469 ASSERT(command->spanElement()->inShadowIncludingDocument()); |
| 470 return command->spanElement(); | 470 return command->spanElement(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void CompositeEditCommand::prune(RawPtr<Node> node, EditingState* editingState,
Node* excludeNode) | 473 void CompositeEditCommand::prune(RawPtr<Node> node, EditingState* editingState,
Node* excludeNode) |
| 474 { | 474 { |
| 475 if (RawPtr<Node> highestNodeToRemove = highestNodeToRemoveInPruning(node.get
(), excludeNode)) | 475 if (RawPtr<Node> highestNodeToRemove = highestNodeToRemoveInPruning(node.get
(), excludeNode)) |
| 476 removeNode(highestNodeToRemove.release(), editingState); | 476 removeNode(highestNodeToRemove.release(), editingState); |
| 477 } | 477 } |
| 478 | 478 |
| 479 void CompositeEditCommand::splitTextNode(RawPtr<Text> node, unsigned offset) | 479 void CompositeEditCommand::splitTextNode(RawPtr<Text> node, unsigned offset) |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 if (!anchorNode) | 1046 if (!anchorNode) |
| 1047 return; | 1047 return; |
| 1048 | 1048 |
| 1049 ASSERT(anchorNode->isLink()); | 1049 ASSERT(anchorNode->isLink()); |
| 1050 | 1050 |
| 1051 setEndingSelection(VisibleSelection::selectionFromContentsOfNode(anchorNode)
); | 1051 setEndingSelection(VisibleSelection::selectionFromContentsOfNode(anchorNode)
); |
| 1052 applyStyledElement(anchorNode, editingState); | 1052 applyStyledElement(anchorNode, editingState); |
| 1053 if (editingState->isAborted()) | 1053 if (editingState->isAborted()) |
| 1054 return; | 1054 return; |
| 1055 // Clones of anchorNode have been pushed down, now remove it. | 1055 // Clones of anchorNode have been pushed down, now remove it. |
| 1056 if (anchorNode->inDocument()) | 1056 if (anchorNode->inShadowIncludingDocument()) |
| 1057 removeNodePreservingChildren(anchorNode, editingState); | 1057 removeNodePreservingChildren(anchorNode, editingState); |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 // Clone the paragraph between start and end under blockElement, | 1060 // Clone the paragraph between start and end under blockElement, |
| 1061 // preserving the hierarchy up to outerNode. | 1061 // preserving the hierarchy up to outerNode. |
| 1062 | 1062 |
| 1063 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
const Position& end, Node* passedOuterNode, Element* blockElement, EditingState*
editingState) | 1063 void CompositeEditCommand::cloneParagraphUnderNewElement(const Position& start,
const Position& end, Node* passedOuterNode, Element* blockElement, EditingState*
editingState) |
| 1064 { | 1064 { |
| 1065 ASSERT(comparePositions(start, end) <= 0); | 1065 ASSERT(comparePositions(start, end) <= 0); |
| 1066 ASSERT(passedOuterNode); | 1066 ASSERT(passedOuterNode); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1093 RawPtr<Node> child = item->cloneNode(isDisplayInsideTable(item)); | 1093 RawPtr<Node> child = item->cloneNode(isDisplayInsideTable(item)); |
| 1094 appendNode(child, toElement(lastNode), editingState); | 1094 appendNode(child, toElement(lastNode), editingState); |
| 1095 if (editingState->isAborted()) | 1095 if (editingState->isAborted()) |
| 1096 return; | 1096 return; |
| 1097 lastNode = child.release(); | 1097 lastNode = child.release(); |
| 1098 } | 1098 } |
| 1099 } | 1099 } |
| 1100 | 1100 |
| 1101 // Scripts specified in javascript protocol may remove |outerNode| | 1101 // Scripts specified in javascript protocol may remove |outerNode| |
| 1102 // during insertion, e.g. <iframe src="javascript:..."> | 1102 // during insertion, e.g. <iframe src="javascript:..."> |
| 1103 if (!outerNode->inDocument()) | 1103 if (!outerNode->inShadowIncludingDocument()) |
| 1104 return; | 1104 return; |
| 1105 | 1105 |
| 1106 // Handle the case of paragraphs with more than one node, | 1106 // Handle the case of paragraphs with more than one node, |
| 1107 // cloning all the siblings until end.anchorNode() is reached. | 1107 // cloning all the siblings until end.anchorNode() is reached. |
| 1108 | 1108 |
| 1109 if (start.anchorNode() != end.anchorNode() && !start.anchorNode()->isDescend
antOf(end.anchorNode())) { | 1109 if (start.anchorNode() != end.anchorNode() && !start.anchorNode()->isDescend
antOf(end.anchorNode())) { |
| 1110 // If end is not a descendant of outerNode we need to | 1110 // If end is not a descendant of outerNode we need to |
| 1111 // find the first common ancestor to increase the scope | 1111 // find the first common ancestor to increase the scope |
| 1112 // of our nextSibling traversal. | 1112 // of our nextSibling traversal. |
| 1113 while (outerNode && !end.anchorNode()->isDescendantOf(outerNode.get()))
{ | 1113 while (outerNode && !end.anchorNode()->isDescendantOf(outerNode.get()))
{ |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 } | 1304 } |
| 1305 | 1305 |
| 1306 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo
ved" and call shouldInsertFragment here. | 1306 // FIXME (5098931): We should add a new insert action "WebViewInsertActionMo
ved" and call shouldInsertFragment here. |
| 1307 | 1307 |
| 1308 setEndingSelection(VisibleSelection(start, end)); | 1308 setEndingSelection(VisibleSelection(start, end)); |
| 1309 document().frame()->spellChecker().clearMisspellingsAndBadGrammar(endingSele
ction()); | 1309 document().frame()->spellChecker().clearMisspellingsAndBadGrammar(endingSele
ction()); |
| 1310 deleteSelection(editingState, false, false, false); | 1310 deleteSelection(editingState, false, false, false); |
| 1311 if (editingState->isAborted()) | 1311 if (editingState->isAborted()) |
| 1312 return; | 1312 return; |
| 1313 | 1313 |
| 1314 ASSERT(destination.deepEquivalent().inDocument()); | 1314 ASSERT(destination.deepEquivalent().inShadowIncludingDocument()); |
| 1315 cleanupAfterDeletion(editingState, destination); | 1315 cleanupAfterDeletion(editingState, destination); |
| 1316 if (editingState->isAborted()) | 1316 if (editingState->isAborted()) |
| 1317 return; | 1317 return; |
| 1318 ASSERT(destination.deepEquivalent().inDocument()); | 1318 ASSERT(destination.deepEquivalent().inShadowIncludingDocument()); |
| 1319 | 1319 |
| 1320 // Add a br if pruning an empty block level element caused a collapse. For e
xample: | 1320 // Add a br if pruning an empty block level element caused a collapse. For e
xample: |
| 1321 // foo^ | 1321 // foo^ |
| 1322 // <div>bar</div> | 1322 // <div>bar</div> |
| 1323 // baz | 1323 // baz |
| 1324 // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That
would | 1324 // Imagine moving 'bar' to ^. 'bar' will be deleted and its div pruned. That
would |
| 1325 // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br
. | 1325 // cause 'baz' to collapse onto the line with 'foobar' unless we insert a br
. |
| 1326 // Must recononicalize these two VisiblePositions after the pruning above. | 1326 // Must recononicalize these two VisiblePositions after the pruning above. |
| 1327 beforeParagraph = createVisiblePosition(beforeParagraph.deepEquivalent()); | 1327 beforeParagraph = createVisiblePosition(beforeParagraph.deepEquivalent()); |
| 1328 afterParagraph = createVisiblePosition(afterParagraph.deepEquivalent()); | 1328 afterParagraph = createVisiblePosition(afterParagraph.deepEquivalent()); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 } | 1615 } |
| 1616 | 1616 |
| 1617 DEFINE_TRACE(CompositeEditCommand) | 1617 DEFINE_TRACE(CompositeEditCommand) |
| 1618 { | 1618 { |
| 1619 visitor->trace(m_commands); | 1619 visitor->trace(m_commands); |
| 1620 visitor->trace(m_composition); | 1620 visitor->trace(m_composition); |
| 1621 EditCommand::trace(visitor); | 1621 EditCommand::trace(visitor); |
| 1622 } | 1622 } |
| 1623 | 1623 |
| 1624 } // namespace blink | 1624 } // namespace blink |
| OLD | NEW |