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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get())); | 100 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get())); |
101 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); | 101 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); |
102 } else if (pos.deprecatedEditingOffset() <= caretMinOffset(pos.deprecatedNod
e())) { | 102 } else if (pos.deprecatedEditingOffset() <= caretMinOffset(pos.deprecatedNod
e())) { |
103 insertNodeAt(nodeToInsert.get(), pos); | 103 insertNodeAt(nodeToInsert.get(), pos); |
104 | 104 |
105 // Insert an extra br or '\n' if the just inserted one collapsed. | 105 // Insert an extra br or '\n' if the just inserted one collapsed. |
106 if (!isStartOfParagraph(VisiblePosition(positionBeforeNode(nodeToInsert.
get())))) | 106 if (!isStartOfParagraph(VisiblePosition(positionBeforeNode(nodeToInsert.
get())))) |
107 insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.
get()); | 107 insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.
get()); |
108 | 108 |
109 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse
rt.get()), DOWNSTREAM, endingSelection().isDirectional())); | 109 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), DOWNSTREAM, endingSelection().isDirectional())); |
110 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, | 110 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, |
111 // a simple insertion is sufficient. | 111 // a simple insertion is sufficient. |
112 } else if (pos.deprecatedEditingOffset() >= caretMaxOffset(pos.deprecatedNod
e()) || !pos.deprecatedNode()->isTextNode()) { | 112 } else if (pos.deprecatedEditingOffset() >= caretMaxOffset(pos.deprecatedNod
e()) || !pos.deprecatedNode()->isTextNode()) { |
113 insertNodeAt(nodeToInsert.get(), pos); | 113 insertNodeAt(nodeToInsert.get(), pos); |
114 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse
rt.get()), DOWNSTREAM, endingSelection().isDirectional())); | 114 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), DOWNSTREAM, endingSelection().isDirectional())); |
115 } else if (pos.deprecatedNode()->isTextNode()) { | 115 } else if (pos.deprecatedNode()->isTextNode()) { |
116 // Split a text node | 116 // Split a text node |
117 Text* textNode = toText(pos.deprecatedNode()); | 117 Text* textNode = toText(pos.deprecatedNode()); |
118 splitTextNode(textNode, pos.deprecatedEditingOffset()); | 118 splitTextNode(textNode, pos.deprecatedEditingOffset()); |
119 insertNodeBefore(nodeToInsert, textNode); | 119 insertNodeBefore(nodeToInsert, textNode); |
120 Position endingPosition = firstPositionInNode(textNode); | 120 Position endingPosition = firstPositionInNode(textNode); |
121 | 121 |
122 // Handle whitespace that occurs after the split | 122 // Handle whitespace that occurs after the split |
123 document().updateLayoutIgnorePendingStylesheets(); | 123 document().updateLayoutIgnorePendingStylesheets(); |
124 if (!endingPosition.isRenderedCharacter()) { | 124 if (!endingPosition.isRenderedCharacter()) { |
125 Position positionBeforeTextNode(positionInParentBeforeNode(textNode)
); | 125 Position positionBeforeTextNode(positionInParentBeforeNode(*textNode
)); |
126 // Clear out all whitespace and insert one non-breaking space | 126 // Clear out all whitespace and insert one non-breaking space |
127 deleteInsignificantTextDownstream(endingPosition); | 127 deleteInsignificantTextDownstream(endingPosition); |
128 ASSERT(!textNode->renderer() || textNode->renderer()->style()->colla
pseWhiteSpace()); | 128 ASSERT(!textNode->renderer() || textNode->renderer()->style()->colla
pseWhiteSpace()); |
129 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. | 129 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. |
130 if (textNode->inDocument()) | 130 if (textNode->inDocument()) |
131 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); | 131 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); |
132 else { | 132 else { |
133 RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpa
ceString()); | 133 RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpa
ceString()); |
134 insertNodeAt(nbspNode.get(), positionBeforeTextNode); | 134 insertNodeAt(nbspNode.get(), positionBeforeTextNode); |
135 endingPosition = firstPositionInNode(nbspNode.get()); | 135 endingPosition = firstPositionInNode(nbspNode.get()); |
(...skipping 19 matching lines...) Expand all Loading... |
155 // before the line break (if the line break is at the end of a block it
isn't selectable). | 155 // before the line break (if the line break is at the end of a block it
isn't selectable). |
156 // So, this next call sets the endingSelection() to a caret just after t
he line break | 156 // So, this next call sets the endingSelection() to a caret just after t
he line break |
157 // that we inserted, or just before it if it's at the end of a block. | 157 // that we inserted, or just before it if it's at the end of a block. |
158 setEndingSelection(endingSelection().visibleEnd()); | 158 setEndingSelection(endingSelection().visibleEnd()); |
159 } | 159 } |
160 | 160 |
161 rebalanceWhitespace(); | 161 rebalanceWhitespace(); |
162 } | 162 } |
163 | 163 |
164 } | 164 } |
OLD | NEW |