| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 appendNode(extraNode, nodeToInsert->parentNode(), editingState); | 119 appendNode(extraNode, nodeToInsert->parentNode(), editingState); |
| 120 } else { | 120 } else { |
| 121 extraNode = nodeToInsert->cloneNode(false); | 121 extraNode = nodeToInsert->cloneNode(false); |
| 122 insertNodeAfter(extraNode, nodeToInsert, editingState); | 122 insertNodeAfter(extraNode, nodeToInsert, editingState); |
| 123 } | 123 } |
| 124 if (editingState->isAborted()) | 124 if (editingState->isAborted()) |
| 125 return; | 125 return; |
| 126 nodeToInsert = extraNode; | 126 nodeToInsert = extraNode; |
| 127 } | 127 } |
| 128 | 128 |
| 129 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 129 setEndingSelection(SelectionInDOMTree::Builder() |
| 130 setEndingSelection(createVisibleSelection( | 130 .collapse(Position::beforeNode(nodeToInsert)) |
| 131 SelectionInDOMTree::Builder() | 131 .setIsDirectional(endingSelection().isDirectional()) |
| 132 .collapse(Position::beforeNode(nodeToInsert)) | 132 .build()); |
| 133 .setIsDirectional(endingSelection().isDirectional()) | |
| 134 .build())); | |
| 135 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { | 133 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { |
| 136 insertNodeAt(nodeToInsert, pos, editingState); | 134 insertNodeAt(nodeToInsert, pos, editingState); |
| 137 if (editingState->isAborted()) | 135 if (editingState->isAborted()) |
| 138 return; | 136 return; |
| 139 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 137 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 140 | 138 |
| 141 // Insert an extra br or '\n' if the just inserted one collapsed. | 139 // Insert an extra br or '\n' if the just inserted one collapsed. |
| 142 if (!isStartOfParagraph(VisiblePosition::beforeNode(nodeToInsert))) { | 140 if (!isStartOfParagraph(VisiblePosition::beforeNode(nodeToInsert))) { |
| 143 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert, | 141 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert, |
| 144 editingState); | 142 editingState); |
| 145 if (editingState->isAborted()) | 143 if (editingState->isAborted()) |
| 146 return; | 144 return; |
| 147 document().updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 148 } | 145 } |
| 149 | 146 |
| 150 setEndingSelection(createVisibleSelection( | 147 setEndingSelection(SelectionInDOMTree::Builder() |
| 151 SelectionInDOMTree::Builder() | 148 .collapse(Position::inParentAfterNode(*nodeToInsert)) |
| 152 .collapse(Position::inParentAfterNode(*nodeToInsert)) | 149 .setIsDirectional(endingSelection().isDirectional()) |
| 153 .setIsDirectional(endingSelection().isDirectional()) | 150 .build()); |
| 154 .build())); | |
| 155 // If we're inserting after all of the rendered text in a text node, or into | 151 // If we're inserting after all of the rendered text in a text node, or into |
| 156 // a non-text node, a simple insertion is sufficient. | 152 // a non-text node, a simple insertion is sufficient. |
| 157 } else if (!pos.anchorNode()->isTextNode() || | 153 } else if (!pos.anchorNode()->isTextNode() || |
| 158 pos.computeOffsetInContainerNode() >= | 154 pos.computeOffsetInContainerNode() >= |
| 159 caretMaxOffset(pos.anchorNode())) { | 155 caretMaxOffset(pos.anchorNode())) { |
| 160 insertNodeAt(nodeToInsert, pos, editingState); | 156 insertNodeAt(nodeToInsert, pos, editingState); |
| 161 if (editingState->isAborted()) | 157 if (editingState->isAborted()) |
| 162 return; | 158 return; |
| 163 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 159 setEndingSelection(SelectionInDOMTree::Builder() |
| 164 setEndingSelection(createVisibleSelection( | 160 .collapse(Position::inParentAfterNode(*nodeToInsert)) |
| 165 SelectionInDOMTree::Builder() | 161 .setIsDirectional(endingSelection().isDirectional()) |
| 166 .collapse(Position::inParentAfterNode(*nodeToInsert)) | 162 .build()); |
| 167 .setIsDirectional(endingSelection().isDirectional()) | |
| 168 .build())); | |
| 169 } else if (pos.anchorNode()->isTextNode()) { | 163 } else if (pos.anchorNode()->isTextNode()) { |
| 170 // Split a text node | 164 // Split a text node |
| 171 Text* textNode = toText(pos.anchorNode()); | 165 Text* textNode = toText(pos.anchorNode()); |
| 172 splitTextNode(textNode, pos.computeOffsetInContainerNode()); | 166 splitTextNode(textNode, pos.computeOffsetInContainerNode()); |
| 173 insertNodeBefore(nodeToInsert, textNode, editingState); | 167 insertNodeBefore(nodeToInsert, textNode, editingState); |
| 174 if (editingState->isAborted()) | 168 if (editingState->isAborted()) |
| 175 return; | 169 return; |
| 176 Position endingPosition = Position::firstPositionInNode(textNode); | 170 Position endingPosition = Position::firstPositionInNode(textNode); |
| 177 | 171 |
| 178 // Handle whitespace that occurs after the split | 172 // Handle whitespace that occurs after the split |
| (...skipping 12 matching lines...) Expand all Loading... |
| 191 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); | 185 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); |
| 192 } else { | 186 } else { |
| 193 Text* nbspNode = document().createTextNode(nonBreakingSpaceString()); | 187 Text* nbspNode = document().createTextNode(nonBreakingSpaceString()); |
| 194 insertNodeAt(nbspNode, positionBeforeTextNode, editingState); | 188 insertNodeAt(nbspNode, positionBeforeTextNode, editingState); |
| 195 if (editingState->isAborted()) | 189 if (editingState->isAborted()) |
| 196 return; | 190 return; |
| 197 endingPosition = Position::firstPositionInNode(nbspNode); | 191 endingPosition = Position::firstPositionInNode(nbspNode); |
| 198 } | 192 } |
| 199 } | 193 } |
| 200 | 194 |
| 201 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 195 setEndingSelection(SelectionInDOMTree::Builder() |
| 202 setEndingSelection(createVisibleSelection( | 196 .collapse(endingPosition) |
| 203 SelectionInDOMTree::Builder() | 197 .setIsDirectional(endingSelection().isDirectional()) |
| 204 .collapse(endingPosition) | 198 .build()); |
| 205 .setIsDirectional(endingSelection().isDirectional()) | |
| 206 .build())); | |
| 207 } | 199 } |
| 208 | 200 |
| 209 // Handle the case where there is a typing style. | 201 // Handle the case where there is a typing style. |
| 210 | 202 |
| 211 EditingStyle* typingStyle = document().frame()->selection().typingStyle(); | 203 EditingStyle* typingStyle = document().frame()->selection().typingStyle(); |
| 212 | 204 |
| 213 if (typingStyle && !typingStyle->isEmpty()) { | 205 if (typingStyle && !typingStyle->isEmpty()) { |
| 214 // Apply the typing style to the inserted line break, so that if the | 206 // Apply the typing style to the inserted line break, so that if the |
| 215 // selection leaves and then comes back, new input will have the right | 207 // selection leaves and then comes back, new input will have the right |
| 216 // style. | 208 // style. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 231 // block. | 223 // block. |
| 232 setEndingSelection(SelectionInDOMTree::Builder() | 224 setEndingSelection(SelectionInDOMTree::Builder() |
| 233 .collapse(endingSelection().end()) | 225 .collapse(endingSelection().end()) |
| 234 .build()); | 226 .build()); |
| 235 } | 227 } |
| 236 | 228 |
| 237 rebalanceWhitespace(); | 229 rebalanceWhitespace(); |
| 238 } | 230 } |
| 239 | 231 |
| 240 } // namespace blink | 232 } // namespace blink |
| OLD | NEW |