| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005 Apple Computer, 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 Position endPosition = Position(textNode, start.offsetInContainerNode() + te
xt.length()); | 119 Position endPosition = Position(textNode, start.offsetInContainerNode() + te
xt.length()); |
| 120 setEndingSelectionWithoutValidation(start, endPosition); | 120 setEndingSelectionWithoutValidation(start, endPosition); |
| 121 if (!selectInsertedText) | 121 if (!selectInsertedText) |
| 122 setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endi
ngSelection().isDirectional())); | 122 setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endi
ngSelection().isDirectional())); |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void InsertTextCommand::doApply(EditingState* editingState) | 127 void InsertTextCommand::doApply(EditingState* editingState) |
| 128 { | 128 { |
| 129 ASSERT(m_text.find('\n') == kNotFound); | 129 DCHECK_EQ(m_text.find('\n'), kNotFound); |
| 130 | 130 |
| 131 if (!endingSelection().isNonOrphanedCaretOrRange()) | 131 if (!endingSelection().isNonOrphanedCaretOrRange()) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 // Delete the current selection. | 134 // Delete the current selection. |
| 135 // FIXME: This delete operation blows away the typing style. | 135 // FIXME: This delete operation blows away the typing style. |
| 136 if (endingSelection().isRange()) { | 136 if (endingSelection().isRange()) { |
| 137 if (performTrivialReplace(m_text, m_selectInsertedText)) | 137 if (performTrivialReplace(m_text, m_selectInsertedText)) |
| 138 return; | 138 return; |
| 139 bool endOfSelectionWasAtStartOfBlock = isStartOfBlock(endingSelection().
visibleEnd()); | 139 bool endOfSelectionWasAtStartOfBlock = isStartOfBlock(endingSelection().
visibleEnd()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 170 // Don't remove the placeholder yet, otherwise the block we're inserting
into would collapse before | 170 // Don't remove the placeholder yet, otherwise the block we're inserting
into would collapse before |
| 171 // we get a chance to insert into it. We check for a placeholder now, t
hough, because doing so requires | 171 // we get a chance to insert into it. We check for a placeholder now, t
hough, because doing so requires |
| 172 // the creation of a VisiblePosition, and if we did that post-insertion
it would force a layout. | 172 // the creation of a VisiblePosition, and if we did that post-insertion
it would force a layout. |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Insert the character at the leftmost candidate. | 175 // Insert the character at the leftmost candidate. |
| 176 startPosition = mostBackwardCaretPosition(startPosition); | 176 startPosition = mostBackwardCaretPosition(startPosition); |
| 177 | 177 |
| 178 // It is possible for the node that contains startPosition to contain only u
nrendered whitespace, | 178 // It is possible for the node that contains startPosition to contain only u
nrendered whitespace, |
| 179 // and so deleteInsignificantText could remove it. Save the position before
the node in case that happens. | 179 // and so deleteInsignificantText could remove it. Save the position before
the node in case that happens. |
| 180 ASSERT(startPosition.computeContainerNode()); | 180 DCHECK(startPosition.computeContainerNode()) << startPosition; |
| 181 Position positionBeforeStartNode(positionInParentBeforeNode(*startPosition.c
omputeContainerNode())); | 181 Position positionBeforeStartNode(positionInParentBeforeNode(*startPosition.c
omputeContainerNode())); |
| 182 deleteInsignificantText(startPosition, mostForwardCaretPosition(startPositio
n)); | 182 deleteInsignificantText(startPosition, mostForwardCaretPosition(startPositio
n)); |
| 183 if (!startPosition.inShadowIncludingDocument()) | 183 if (!startPosition.inShadowIncludingDocument()) |
| 184 startPosition = positionBeforeStartNode; | 184 startPosition = positionBeforeStartNode; |
| 185 if (!isVisuallyEquivalentCandidate(startPosition)) | 185 if (!isVisuallyEquivalentCandidate(startPosition)) |
| 186 startPosition = mostForwardCaretPosition(startPosition); | 186 startPosition = mostForwardCaretPosition(startPosition); |
| 187 | 187 |
| 188 startPosition = positionAvoidingSpecialElementBoundary(startPosition, editin
gState); | 188 startPosition = positionAvoidingSpecialElementBoundary(startPosition, editin
gState); |
| 189 if (editingState->isAborted()) | 189 if (editingState->isAborted()) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 Position endPosition; | 192 Position endPosition; |
| 193 | 193 |
| 194 if (m_text == "\t" && isRichlyEditablePosition(startPosition)) { | 194 if (m_text == "\t" && isRichlyEditablePosition(startPosition)) { |
| 195 endPosition = insertTab(startPosition, editingState); | 195 endPosition = insertTab(startPosition, editingState); |
| 196 if (editingState->isAborted()) | 196 if (editingState->isAborted()) |
| 197 return; | 197 return; |
| 198 startPosition = previousPositionOf(endPosition, PositionMoveType::Graphe
meCluster); | 198 startPosition = previousPositionOf(endPosition, PositionMoveType::Graphe
meCluster); |
| 199 if (placeholder.isNotNull()) | 199 if (placeholder.isNotNull()) |
| 200 removePlaceholderAt(placeholder); | 200 removePlaceholderAt(placeholder); |
| 201 } else { | 201 } else { |
| 202 // Make sure the document is set up to receive m_text | 202 // Make sure the document is set up to receive m_text |
| 203 startPosition = positionInsideTextNode(startPosition, editingState); | 203 startPosition = positionInsideTextNode(startPosition, editingState); |
| 204 if (editingState->isAborted()) | 204 if (editingState->isAborted()) |
| 205 return; | 205 return; |
| 206 ASSERT(startPosition.isOffsetInAnchor()); | 206 DCHECK(startPosition.isOffsetInAnchor()) << startPosition; |
| 207 ASSERT(startPosition.computeContainerNode()); | 207 DCHECK(startPosition.computeContainerNode()) << startPosition; |
| 208 ASSERT(startPosition.computeContainerNode()->isTextNode()); | 208 DCHECK(startPosition.computeContainerNode()->isTextNode()) << startPosit
ion; |
| 209 if (placeholder.isNotNull()) | 209 if (placeholder.isNotNull()) |
| 210 removePlaceholderAt(placeholder); | 210 removePlaceholderAt(placeholder); |
| 211 Text* textNode = toText(startPosition.computeContainerNode()); | 211 Text* textNode = toText(startPosition.computeContainerNode()); |
| 212 const unsigned offset = startPosition.offsetInContainerNode(); | 212 const unsigned offset = startPosition.offsetInContainerNode(); |
| 213 | 213 |
| 214 insertTextIntoNode(textNode, offset, m_text); | 214 insertTextIntoNode(textNode, offset, m_text); |
| 215 endPosition = Position(textNode, offset + m_text.length()); | 215 endPosition = Position(textNode, offset + m_text.length()); |
| 216 | 216 |
| 217 if (m_rebalanceType == RebalanceLeadingAndTrailingWhitespaces) { | 217 if (m_rebalanceType == RebalanceLeadingAndTrailingWhitespaces) { |
| 218 // The insertion may require adjusting adjacent whitespace, if it is
present. | 218 // The insertion may require adjusting adjacent whitespace, if it is
present. |
| 219 rebalanceWhitespaceAt(endPosition); | 219 rebalanceWhitespaceAt(endPosition); |
| 220 // Rebalancing on both sides isn't necessary if we've inserted only
spaces. | 220 // Rebalancing on both sides isn't necessary if we've inserted only
spaces. |
| 221 if (!shouldRebalanceLeadingWhitespaceFor(m_text)) | 221 if (!shouldRebalanceLeadingWhitespaceFor(m_text)) |
| 222 rebalanceWhitespaceAt(startPosition); | 222 rebalanceWhitespaceAt(startPosition); |
| 223 } else { | 223 } else { |
| 224 ASSERT(m_rebalanceType == RebalanceAllWhitespaces); | 224 DCHECK_EQ(m_rebalanceType, RebalanceAllWhitespaces); |
| 225 if (canRebalance(startPosition) && canRebalance(endPosition)) | 225 if (canRebalance(startPosition) && canRebalance(endPosition)) |
| 226 rebalanceWhitespaceOnTextSubstring(textNode, startPosition.offse
tInContainerNode(), endPosition.offsetInContainerNode()); | 226 rebalanceWhitespaceOnTextSubstring(textNode, startPosition.offse
tInContainerNode(), endPosition.offsetInContainerNode()); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 setEndingSelectionWithoutValidation(startPosition, endPosition); | 230 setEndingSelectionWithoutValidation(startPosition, endPosition); |
| 231 | 231 |
| 232 // Handle the case where there is a typing style. | 232 // Handle the case where there is a typing style. |
| 233 if (EditingStyle* typingStyle = document().frame()->selection().typingStyle(
)) { | 233 if (EditingStyle* typingStyle = document().frame()->selection().typingStyle(
)) { |
| 234 typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWriting
Direction); | 234 typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWriting
Direction); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 if (editingState->isAborted()) | 282 if (editingState->isAborted()) |
| 283 return Position(); | 283 return Position(); |
| 284 | 284 |
| 285 // return the position following the new tab | 285 // return the position following the new tab |
| 286 return lastPositionInNode(spanElement); | 286 return lastPositionInNode(spanElement); |
| 287 } | 287 } |
| 288 | 288 |
| 289 } // namespace blink | 289 } // namespace blink |
| OLD | NEW |