| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (caret.isNull()) | 63 if (caret.isNull()) |
| 64 return; | 64 return; |
| 65 | 65 |
| 66 Position pos(caret.deepEquivalent()); | 66 Position pos(caret.deepEquivalent()); |
| 67 | 67 |
| 68 pos = positionAvoidingSpecialElementBoundary(pos); | 68 pos = positionAvoidingSpecialElementBoundary(pos); |
| 69 | 69 |
| 70 pos = positionOutsideTabSpan(pos); | 70 pos = positionOutsideTabSpan(pos); |
| 71 | 71 |
| 72 RefPtr<Node> nodeToInsert = nullptr; | 72 RefPtr<Node> nodeToInsert = nullptr; |
| 73 nodeToInsert = document().createTextNode("\n"); | 73 nodeToInsert = Text::create(document(), "\n"); |
| 74 | 74 |
| 75 // FIXME: Need to merge text nodes when inserting just after or before text. | 75 // FIXME: Need to merge text nodes when inserting just after or before text. |
| 76 | 76 |
| 77 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { | 77 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { |
| 78 insertNodeAt(nodeToInsert.get(), pos); | 78 insertNodeAt(nodeToInsert.get(), pos); |
| 79 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); | 79 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); |
| 80 | 80 |
| 81 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get())); | 81 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get())); |
| 82 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); | 82 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); |
| 83 } else if (pos.deprecatedEditingOffset() <= caretMinOffset(pos.deprecatedNod
e())) { | 83 } else if (pos.deprecatedEditingOffset() <= caretMinOffset(pos.deprecatedNod
e())) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 104 document().updateLayout(); | 104 document().updateLayout(); |
| 105 if (!endingPosition.isRenderedCharacter()) { | 105 if (!endingPosition.isRenderedCharacter()) { |
| 106 Position positionBeforeTextNode(positionInParentBeforeNode(*textNode
)); | 106 Position positionBeforeTextNode(positionInParentBeforeNode(*textNode
)); |
| 107 // Clear out all whitespace and insert one non-breaking space | 107 // Clear out all whitespace and insert one non-breaking space |
| 108 deleteInsignificantTextDownstream(endingPosition); | 108 deleteInsignificantTextDownstream(endingPosition); |
| 109 ASSERT(!textNode->renderer() || textNode->renderer()->style()->colla
pseWhiteSpace()); | 109 ASSERT(!textNode->renderer() || textNode->renderer()->style()->colla
pseWhiteSpace()); |
| 110 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. | 110 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. |
| 111 if (textNode->inDocument()) | 111 if (textNode->inDocument()) |
| 112 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); | 112 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); |
| 113 else { | 113 else { |
| 114 RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpa
ceString()); | 114 RefPtr<Text> nbspNode = Text::create(document(), nonBreakingSpac
eString()); |
| 115 insertNodeAt(nbspNode.get(), positionBeforeTextNode); | 115 insertNodeAt(nbspNode.get(), positionBeforeTextNode); |
| 116 endingPosition = firstPositionInNode(nbspNode.get()); | 116 endingPosition = firstPositionInNode(nbspNode.get()); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 setEndingSelection(VisibleSelection(endingPosition, DOWNSTREAM, endingSe
lection().isDirectional())); | 120 setEndingSelection(VisibleSelection(endingPosition, DOWNSTREAM, endingSe
lection().isDirectional())); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Handle the case where there is a typing style. | 123 // Handle the case where there is a typing style. |
| 124 | 124 |
| 125 RefPtr<EditingStyle> typingStyle = document().frame()->selection().typingSty
le(); | 125 RefPtr<EditingStyle> typingStyle = document().frame()->selection().typingSty
le(); |
| 126 | 126 |
| 127 if (typingStyle && !typingStyle->isEmpty()) { | 127 if (typingStyle && !typingStyle->isEmpty()) { |
| 128 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). | 128 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). |
| 129 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection | 129 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection |
| 130 // will either (a) select the line break we inserted, or it will (b) be
a caret just | 130 // will either (a) select the line break we inserted, or it will (b) be
a caret just |
| 131 // before the line break (if the line break is at the end of a block it
isn't selectable). | 131 // before the line break (if the line break is at the end of a block it
isn't selectable). |
| 132 // So, this next call sets the endingSelection() to a caret just after t
he line break | 132 // So, this next call sets the endingSelection() to a caret just after t
he line break |
| 133 // that we inserted, or just before it if it's at the end of a block. | 133 // that we inserted, or just before it if it's at the end of a block. |
| 134 setEndingSelection(endingSelection().visibleEnd()); | 134 setEndingSelection(endingSelection().visibleEnd()); |
| 135 } | 135 } |
| 136 | 136 |
| 137 rebalanceWhitespace(); | 137 rebalanceWhitespace(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 } | 140 } |
| OLD | NEW |