| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } else { | 113 } else { |
| 114 extraNode = nodeToInsert->cloneNode(false); | 114 extraNode = nodeToInsert->cloneNode(false); |
| 115 insertNodeAfter(extraNode, nodeToInsert, editingState); | 115 insertNodeAfter(extraNode, nodeToInsert, editingState); |
| 116 } | 116 } |
| 117 if (editingState->isAborted()) | 117 if (editingState->isAborted()) |
| 118 return; | 118 return; |
| 119 nodeToInsert = extraNode; | 119 nodeToInsert = extraNode; |
| 120 } | 120 } |
| 121 | 121 |
| 122 VisiblePosition endingPosition = VisiblePosition::beforeNode(nodeToInser
t); | 122 VisiblePosition endingPosition = VisiblePosition::beforeNode(nodeToInser
t); |
| 123 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); | 123 setEndingSelection(createVisibleSelectionDeprecated(endingPosition, endi
ngSelection().isDirectional())); |
| 124 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { | 124 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { |
| 125 insertNodeAt(nodeToInsert, pos, editingState); | 125 insertNodeAt(nodeToInsert, pos, editingState); |
| 126 if (editingState->isAborted()) | 126 if (editingState->isAborted()) |
| 127 return; | 127 return; |
| 128 | 128 |
| 129 // Insert an extra br or '\n' if the just inserted one collapsed. | 129 // Insert an extra br or '\n' if the just inserted one collapsed. |
| 130 if (!isStartOfParagraphDeprecated(VisiblePosition::beforeNode(nodeToInse
rt))) { | 130 if (!isStartOfParagraphDeprecated(VisiblePosition::beforeNode(nodeToInse
rt))) { |
| 131 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert, editi
ngState); | 131 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert, editi
ngState); |
| 132 if (editingState->isAborted()) | 132 if (editingState->isAborted()) |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 setEndingSelection(VisibleSelection(Position::inParentAfterNode(*nodeToI
nsert), TextAffinity::Downstream, endingSelection().isDirectional())); | 136 setEndingSelection(createVisibleSelectionDeprecated(Position::inParentAf
terNode(*nodeToInsert), TextAffinity::Downstream, endingSelection().isDirectiona
l())); |
| 137 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, | 137 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, |
| 138 // a simple insertion is sufficient. | 138 // a simple insertion is sufficient. |
| 139 } else if (!pos.anchorNode()->isTextNode() || pos.computeOffsetInContainerNo
de() >= caretMaxOffset(pos.anchorNode())) { | 139 } else if (!pos.anchorNode()->isTextNode() || pos.computeOffsetInContainerNo
de() >= caretMaxOffset(pos.anchorNode())) { |
| 140 insertNodeAt(nodeToInsert, pos, editingState); | 140 insertNodeAt(nodeToInsert, pos, editingState); |
| 141 if (editingState->isAborted()) | 141 if (editingState->isAborted()) |
| 142 return; | 142 return; |
| 143 setEndingSelection(VisibleSelection(Position::inParentAfterNode(*nodeToI
nsert), TextAffinity::Downstream, endingSelection().isDirectional())); | 143 setEndingSelection(createVisibleSelectionDeprecated(Position::inParentAf
terNode(*nodeToInsert), TextAffinity::Downstream, endingSelection().isDirectiona
l())); |
| 144 } else if (pos.anchorNode()->isTextNode()) { | 144 } else if (pos.anchorNode()->isTextNode()) { |
| 145 // Split a text node | 145 // Split a text node |
| 146 Text* textNode = toText(pos.anchorNode()); | 146 Text* textNode = toText(pos.anchorNode()); |
| 147 splitTextNode(textNode, pos.computeOffsetInContainerNode()); | 147 splitTextNode(textNode, pos.computeOffsetInContainerNode()); |
| 148 insertNodeBefore(nodeToInsert, textNode, editingState); | 148 insertNodeBefore(nodeToInsert, textNode, editingState); |
| 149 if (editingState->isAborted()) | 149 if (editingState->isAborted()) |
| 150 return; | 150 return; |
| 151 Position endingPosition = Position::firstPositionInNode(textNode); | 151 Position endingPosition = Position::firstPositionInNode(textNode); |
| 152 | 152 |
| 153 // Handle whitespace that occurs after the split | 153 // Handle whitespace that occurs after the split |
| (...skipping 10 matching lines...) Expand all Loading... |
| 164 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); | 164 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); |
| 165 } else { | 165 } else { |
| 166 Text* nbspNode = document().createTextNode(nonBreakingSpaceStrin
g()); | 166 Text* nbspNode = document().createTextNode(nonBreakingSpaceStrin
g()); |
| 167 insertNodeAt(nbspNode, positionBeforeTextNode, editingState); | 167 insertNodeAt(nbspNode, positionBeforeTextNode, editingState); |
| 168 if (editingState->isAborted()) | 168 if (editingState->isAborted()) |
| 169 return; | 169 return; |
| 170 endingPosition = Position::firstPositionInNode(nbspNode); | 170 endingPosition = Position::firstPositionInNode(nbspNode); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 setEndingSelection(VisibleSelection(endingPosition, TextAffinity::Downst
ream, endingSelection().isDirectional())); | 174 setEndingSelection(createVisibleSelectionDeprecated(endingPosition, Text
Affinity::Downstream, endingSelection().isDirectional())); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Handle the case where there is a typing style. | 177 // Handle the case where there is a typing style. |
| 178 | 178 |
| 179 EditingStyle* typingStyle = document().frame()->selection().typingStyle(); | 179 EditingStyle* typingStyle = document().frame()->selection().typingStyle(); |
| 180 | 180 |
| 181 if (typingStyle && !typingStyle->isEmpty()) { | 181 if (typingStyle && !typingStyle->isEmpty()) { |
| 182 // Apply the typing style to the inserted line break, so that if the sel
ection | 182 // Apply the typing style to the inserted line break, so that if the sel
ection |
| 183 // leaves and then comes back, new input will have the right style. | 183 // leaves and then comes back, new input will have the right style. |
| 184 // FIXME: We shouldn't always apply the typing style to the line break h
ere, | 184 // FIXME: We shouldn't always apply the typing style to the line break h
ere, |
| 185 // see <rdar://problem/5794462>. | 185 // see <rdar://problem/5794462>. |
| 186 applyStyle(typingStyle, firstPositionInOrBeforeNode(nodeToInsert), lastP
ositionInOrAfterNode(nodeToInsert), editingState); | 186 applyStyle(typingStyle, firstPositionInOrBeforeNode(nodeToInsert), lastP
ositionInOrAfterNode(nodeToInsert), editingState); |
| 187 if (editingState->isAborted()) | 187 if (editingState->isAborted()) |
| 188 return; | 188 return; |
| 189 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). | 189 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). |
| 190 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection | 190 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection |
| 191 // will either (a) select the line break we inserted, or it will (b) be
a caret just | 191 // will either (a) select the line break we inserted, or it will (b) be
a caret just |
| 192 // before the line break (if the line break is at the end of a block it
isn't selectable). | 192 // before the line break (if the line break is at the end of a block it
isn't selectable). |
| 193 // So, this next call sets the endingSelection() to a caret just after t
he line break | 193 // So, this next call sets the endingSelection() to a caret just after t
he line break |
| 194 // that we inserted, or just before it if it's at the end of a block. | 194 // that we inserted, or just before it if it's at the end of a block. |
| 195 setEndingSelection(endingSelection().visibleEndDeprecated()); | 195 setEndingSelection(endingSelection().visibleEndDeprecated()); |
| 196 } | 196 } |
| 197 | 197 |
| 198 rebalanceWhitespace(); | 198 rebalanceWhitespace(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace blink | 201 } // namespace blink |
| OLD | NEW |