| 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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 VisiblePosition destination = mergeForward ? nextPositionOf(endOfInsertedCon
tent) : endOfInsertedContent; | 902 VisiblePosition destination = mergeForward ? nextPositionOf(endOfInsertedCon
tent) : endOfInsertedContent; |
| 903 VisiblePosition startOfParagraphToMove = mergeForward ? startOfParagraph(end
OfInsertedContent) : nextPositionOf(endOfInsertedContent); | 903 VisiblePosition startOfParagraphToMove = mergeForward ? startOfParagraph(end
OfInsertedContent) : nextPositionOf(endOfInsertedContent); |
| 904 | 904 |
| 905 // Merging forward could result in deleting the destination anchor node. | 905 // Merging forward could result in deleting the destination anchor node. |
| 906 // To avoid this, we add a placeholder node before the start of the paragrap
h. | 906 // To avoid this, we add a placeholder node before the start of the paragrap
h. |
| 907 if (endOfParagraph(startOfParagraphToMove).deepEquivalent() == destination.d
eepEquivalent()) { | 907 if (endOfParagraph(startOfParagraphToMove).deepEquivalent() == destination.d
eepEquivalent()) { |
| 908 HTMLBRElement* placeholder = HTMLBRElement::create(document()); | 908 HTMLBRElement* placeholder = HTMLBRElement::create(document()); |
| 909 insertNodeBefore(placeholder, startOfParagraphToMove.deepEquivalent().an
chorNode(), editingState); | 909 insertNodeBefore(placeholder, startOfParagraphToMove.deepEquivalent().an
chorNode(), editingState); |
| 910 if (editingState->isAborted()) | 910 if (editingState->isAborted()) |
| 911 return; | 911 return; |
| 912 destination = createVisiblePosition(positionBeforeNode(placeholder)); | 912 destination = createVisiblePosition(Position::beforeNode(placeholder)); |
| 913 } | 913 } |
| 914 | 914 |
| 915 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove)
, destination, editingState); | 915 moveParagraph(startOfParagraphToMove, endOfParagraph(startOfParagraphToMove)
, destination, editingState); |
| 916 if (editingState->isAborted()) | 916 if (editingState->isAborted()) |
| 917 return; | 917 return; |
| 918 | 918 |
| 919 // Merging forward will remove m_endOfInsertedContent from the document. | 919 // Merging forward will remove m_endOfInsertedContent from the document. |
| 920 if (mergeForward) { | 920 if (mergeForward) { |
| 921 if (m_startOfInsertedContent.isOrphan()) | 921 if (m_startOfInsertedContent.isOrphan()) |
| 922 m_startOfInsertedContent = endingSelection().visibleStart().deepEqui
valent(); | 922 m_startOfInsertedContent = endingSelection().visibleStart().deepEqui
valent(); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 // If the downstream node has been removed there's no point in continuing. | 1096 // If the downstream node has been removed there's no point in continuing. |
| 1097 if (!mostForwardCaretPosition(insertionPos).anchorNode()) | 1097 if (!mostForwardCaretPosition(insertionPos).anchorNode()) |
| 1098 return; | 1098 return; |
| 1099 | 1099 |
| 1100 // NOTE: This would be an incorrect usage of downstream() if downstream() we
re changed to mean the last position after | 1100 // NOTE: This would be an incorrect usage of downstream() if downstream() we
re changed to mean the last position after |
| 1101 // 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 | 1101 // 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 |
| 1102 // away, there are positions after the br which map to the same visible posi
tion as [br, 0]). | 1102 // away, there are positions after the br which map to the same visible posi
tion as [br, 0]). |
| 1103 HTMLBRElement* endBR = isHTMLBRElement(*mostForwardCaretPosition(insertionPo
s).anchorNode()) ? toHTMLBRElement(mostForwardCaretPosition(insertionPos).anchor
Node()) : 0; | 1103 HTMLBRElement* endBR = isHTMLBRElement(*mostForwardCaretPosition(insertionPo
s).anchorNode()) ? toHTMLBRElement(mostForwardCaretPosition(insertionPos).anchor
Node()) : 0; |
| 1104 VisiblePosition originalVisPosBeforeEndBR; | 1104 VisiblePosition originalVisPosBeforeEndBR; |
| 1105 if (endBR) | 1105 if (endBR) |
| 1106 originalVisPosBeforeEndBR = previousPositionOf(createVisiblePosition(pos
itionBeforeNode(endBR))); | 1106 originalVisPosBeforeEndBR = previousPositionOf(createVisiblePosition(Pos
ition::beforeNode(endBR))); |
| 1107 | 1107 |
| 1108 Element* enclosingBlockOfInsertionPos = enclosingBlock(insertionPos.anchorNo
de()); | 1108 Element* enclosingBlockOfInsertionPos = enclosingBlock(insertionPos.anchorNo
de()); |
| 1109 | 1109 |
| 1110 // Adjust insertionPos to prevent nesting. | 1110 // Adjust insertionPos to prevent nesting. |
| 1111 // If the start was in a Mail blockquote, we will have already handled adjus
ting insertionPos above. | 1111 // If the start was in a Mail blockquote, we will have already handled adjus
ting insertionPos above. |
| 1112 if (m_preventNesting && enclosingBlockOfInsertionPos && !isTableCell(enclosi
ngBlockOfInsertionPos) && !startIsInsideMailBlockquote) { | 1112 if (m_preventNesting && enclosingBlockOfInsertionPos && !isTableCell(enclosi
ngBlockOfInsertionPos) && !startIsInsideMailBlockquote) { |
| 1113 DCHECK_NE(enclosingBlockOfInsertionPos, currentRoot); | 1113 DCHECK_NE(enclosingBlockOfInsertionPos, currentRoot); |
| 1114 VisiblePosition visibleInsertionPos = createVisiblePosition(insertionPos
); | 1114 VisiblePosition visibleInsertionPos = createVisiblePosition(insertionPos
); |
| 1115 if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInserti
onPos) && fragment.hasInterchangeNewlineAtEnd())) | 1115 if (isEndOfBlock(visibleInsertionPos) && !(isStartOfBlock(visibleInserti
onPos) && fragment.hasInterchangeNewlineAtEnd())) |
| 1116 insertionPos = Position::inParentAfterNode(*enclosingBlockOfInsertio
nPos); | 1116 insertionPos = Position::inParentAfterNode(*enclosingBlockOfInsertio
nPos); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1390 m_matchStyle = false; | 1390 m_matchStyle = false; |
| 1391 | 1391 |
| 1392 completeHTMLReplacement(lastPositionToSelect, editingState); | 1392 completeHTMLReplacement(lastPositionToSelect, editingState); |
| 1393 } | 1393 } |
| 1394 | 1394 |
| 1395 bool ReplaceSelectionCommand::shouldRemoveEndBR(HTMLBRElement* endBR, const Visi
blePosition& originalVisPosBeforeEndBR) | 1395 bool ReplaceSelectionCommand::shouldRemoveEndBR(HTMLBRElement* endBR, const Visi
blePosition& originalVisPosBeforeEndBR) |
| 1396 { | 1396 { |
| 1397 if (!endBR || !endBR->inShadowIncludingDocument()) | 1397 if (!endBR || !endBR->inShadowIncludingDocument()) |
| 1398 return false; | 1398 return false; |
| 1399 | 1399 |
| 1400 VisiblePosition visiblePos = createVisiblePosition(positionBeforeNode(endBR)
); | 1400 VisiblePosition visiblePos = createVisiblePosition(Position::beforeNode(endB
R)); |
| 1401 | 1401 |
| 1402 // Don't remove the br if nothing was inserted. | 1402 // Don't remove the br if nothing was inserted. |
| 1403 if (previousPositionOf(visiblePos).deepEquivalent() == originalVisPosBeforeE
ndBR.deepEquivalent()) | 1403 if (previousPositionOf(visiblePos).deepEquivalent() == originalVisPosBeforeE
ndBR.deepEquivalent()) |
| 1404 return false; | 1404 return false; |
| 1405 | 1405 |
| 1406 // Remove the br if it is collapsed away and so is unnecessary. | 1406 // Remove the br if it is collapsed away and so is unnecessary. |
| 1407 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa
ragraph(visiblePos)) | 1407 if (!document().inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfPa
ragraph(visiblePos)) |
| 1408 return true; | 1408 return true; |
| 1409 | 1409 |
| 1410 // A br that was originally holding a line open should be displaced by inser
ted content or turned into a line break. | 1410 // A br that was originally holding a line open should be displaced by inser
ted content or turned into a line break. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1679 Node* nodeAfterInsertionPos = mostForwardCaretPosition(endingSelection().end
()).anchorNode(); | 1679 Node* nodeAfterInsertionPos = mostForwardCaretPosition(endingSelection().end
()).anchorNode(); |
| 1680 Text* textNode = toText(fragment.firstChild()); | 1680 Text* textNode = toText(fragment.firstChild()); |
| 1681 // Our fragment creation code handles tabs, spaces, and newlines, so we don'
t have to worry about those here. | 1681 // Our fragment creation code handles tabs, spaces, and newlines, so we don'
t have to worry about those here. |
| 1682 | 1682 |
| 1683 Position start = endingSelection().start(); | 1683 Position start = endingSelection().start(); |
| 1684 Position end = replaceSelectedTextInNode(textNode->data()); | 1684 Position end = replaceSelectedTextInNode(textNode->data()); |
| 1685 if (end.isNull()) | 1685 if (end.isNull()) |
| 1686 return false; | 1686 return false; |
| 1687 | 1687 |
| 1688 if (nodeAfterInsertionPos && nodeAfterInsertionPos->parentNode() && isHTMLBR
Element(*nodeAfterInsertionPos) | 1688 if (nodeAfterInsertionPos && nodeAfterInsertionPos->parentNode() && isHTMLBR
Element(*nodeAfterInsertionPos) |
| 1689 && shouldRemoveEndBR(toHTMLBRElement(nodeAfterInsertionPos), createVisib
lePosition(positionBeforeNode(nodeAfterInsertionPos)))) { | 1689 && shouldRemoveEndBR(toHTMLBRElement(nodeAfterInsertionPos), createVisib
lePosition(Position::beforeNode(nodeAfterInsertionPos)))) { |
| 1690 removeNodeAndPruneAncestors(nodeAfterInsertionPos, editingState); | 1690 removeNodeAndPruneAncestors(nodeAfterInsertionPos, editingState); |
| 1691 if (editingState->isAborted()) | 1691 if (editingState->isAborted()) |
| 1692 return false; | 1692 return false; |
| 1693 } | 1693 } |
| 1694 | 1694 |
| 1695 m_startOfInsertedRange = start; | 1695 m_startOfInsertedRange = start; |
| 1696 m_endOfInsertedRange = end; | 1696 m_endOfInsertedRange = end; |
| 1697 | 1697 |
| 1698 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); | 1698 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en
d); |
| 1699 | 1699 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1717 visitor->trace(m_startOfInsertedContent); | 1717 visitor->trace(m_startOfInsertedContent); |
| 1718 visitor->trace(m_endOfInsertedContent); | 1718 visitor->trace(m_endOfInsertedContent); |
| 1719 visitor->trace(m_insertionStyle); | 1719 visitor->trace(m_insertionStyle); |
| 1720 visitor->trace(m_documentFragment); | 1720 visitor->trace(m_documentFragment); |
| 1721 visitor->trace(m_startOfInsertedRange); | 1721 visitor->trace(m_startOfInsertedRange); |
| 1722 visitor->trace(m_endOfInsertedRange); | 1722 visitor->trace(m_endOfInsertedRange); |
| 1723 CompositeEditCommand::trace(visitor); | 1723 CompositeEditCommand::trace(visitor); |
| 1724 } | 1724 } |
| 1725 | 1725 |
| 1726 } // namespace blink | 1726 } // namespace blink |
| OLD | NEW |