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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get())); | 102 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert.get())); |
103 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); | 103 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is
Directional())); |
104 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { | 104 } else if (pos.computeEditingOffset() <= caretMinOffset(pos.anchorNode())) { |
105 insertNodeAt(nodeToInsert.get(), pos); | 105 insertNodeAt(nodeToInsert.get(), pos); |
106 | 106 |
107 // Insert an extra br or '\n' if the just inserted one collapsed. | 107 // Insert an extra br or '\n' if the just inserted one collapsed. |
108 if (!isStartOfParagraph(VisiblePosition(positionBeforeNode(nodeToInsert.
get())))) | 108 if (!isStartOfParagraph(VisiblePosition(positionBeforeNode(nodeToInsert.
get())))) |
109 insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.
get()); | 109 insertNodeBefore(nodeToInsert->cloneNode(false).get(), nodeToInsert.
get()); |
110 | 110 |
111 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), DOWNSTREAM, endingSelection().isDirectional())); | 111 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), TextAffinity::Downstream, endingSelection().isDirectional())); |
112 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, | 112 // If we're inserting after all of the rendered text in a text node, or into
a non-text node, |
113 // a simple insertion is sufficient. | 113 // a simple insertion is sufficient. |
114 } else if (!pos.anchorNode()->isTextNode() || pos.computeOffsetInContainerNo
de() >= caretMaxOffset(pos.anchorNode())) { | 114 } else if (!pos.anchorNode()->isTextNode() || pos.computeOffsetInContainerNo
de() >= caretMaxOffset(pos.anchorNode())) { |
115 insertNodeAt(nodeToInsert.get(), pos); | 115 insertNodeAt(nodeToInsert.get(), pos); |
116 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), DOWNSTREAM, endingSelection().isDirectional())); | 116 setEndingSelection(VisibleSelection(positionInParentAfterNode(*nodeToIns
ert), TextAffinity::Downstream, endingSelection().isDirectional())); |
117 } else if (pos.anchorNode()->isTextNode()) { | 117 } else if (pos.anchorNode()->isTextNode()) { |
118 // Split a text node | 118 // Split a text node |
119 Text* textNode = toText(pos.anchorNode()); | 119 Text* textNode = toText(pos.anchorNode()); |
120 splitTextNode(textNode, pos.computeOffsetInContainerNode()); | 120 splitTextNode(textNode, pos.computeOffsetInContainerNode()); |
121 insertNodeBefore(nodeToInsert, textNode); | 121 insertNodeBefore(nodeToInsert, textNode); |
122 Position endingPosition = firstPositionInNode(textNode); | 122 Position endingPosition = firstPositionInNode(textNode); |
123 | 123 |
124 // Handle whitespace that occurs after the split | 124 // Handle whitespace that occurs after the split |
125 document().updateLayoutIgnorePendingStylesheets(); | 125 document().updateLayoutIgnorePendingStylesheets(); |
126 // TODO(yosin) |isRenderedCharacter()| should be removed, and we should | 126 // TODO(yosin) |isRenderedCharacter()| should be removed, and we should |
127 // use |VisiblePosition::characterAfter()|. | 127 // use |VisiblePosition::characterAfter()|. |
128 if (!isRenderedCharacter(endingPosition)) { | 128 if (!isRenderedCharacter(endingPosition)) { |
129 Position positionBeforeTextNode(positionInParentBeforeNode(*textNode
)); | 129 Position positionBeforeTextNode(positionInParentBeforeNode(*textNode
)); |
130 // Clear out all whitespace and insert one non-breaking space | 130 // Clear out all whitespace and insert one non-breaking space |
131 deleteInsignificantTextDownstream(endingPosition); | 131 deleteInsignificantTextDownstream(endingPosition); |
132 ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style(
)->collapseWhiteSpace()); | 132 ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style(
)->collapseWhiteSpace()); |
133 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. | 133 // Deleting insignificant whitespace will remove textNode if it cont
ains nothing but insignificant whitespace. |
134 if (textNode->inDocument()) { | 134 if (textNode->inDocument()) { |
135 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); | 135 insertTextIntoNode(textNode, 0, nonBreakingSpaceString()); |
136 } else { | 136 } else { |
137 RefPtrWillBeRawPtr<Text> nbspNode = document().createTextNode(no
nBreakingSpaceString()); | 137 RefPtrWillBeRawPtr<Text> nbspNode = document().createTextNode(no
nBreakingSpaceString()); |
138 insertNodeAt(nbspNode.get(), positionBeforeTextNode); | 138 insertNodeAt(nbspNode.get(), positionBeforeTextNode); |
139 endingPosition = firstPositionInNode(nbspNode.get()); | 139 endingPosition = firstPositionInNode(nbspNode.get()); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 setEndingSelection(VisibleSelection(endingPosition, DOWNSTREAM, endingSe
lection().isDirectional())); | 143 setEndingSelection(VisibleSelection(endingPosition, TextAffinity::Downst
ream, endingSelection().isDirectional())); |
144 } | 144 } |
145 | 145 |
146 // Handle the case where there is a typing style. | 146 // Handle the case where there is a typing style. |
147 | 147 |
148 RefPtrWillBeRawPtr<EditingStyle> typingStyle = document().frame()->selection
().typingStyle(); | 148 RefPtrWillBeRawPtr<EditingStyle> typingStyle = document().frame()->selection
().typingStyle(); |
149 | 149 |
150 if (typingStyle && !typingStyle->isEmpty()) { | 150 if (typingStyle && !typingStyle->isEmpty()) { |
151 // Apply the typing style to the inserted line break, so that if the sel
ection | 151 // Apply the typing style to the inserted line break, so that if the sel
ection |
152 // leaves and then comes back, new input will have the right style. | 152 // leaves and then comes back, new input will have the right style. |
153 // FIXME: We shouldn't always apply the typing style to the line break h
ere, | 153 // FIXME: We shouldn't always apply the typing style to the line break h
ere, |
154 // see <rdar://problem/5794462>. | 154 // see <rdar://problem/5794462>. |
155 applyStyle(typingStyle.get(), firstPositionInOrBeforeNode(nodeToInsert.g
et()), lastPositionInOrAfterNode(nodeToInsert.get())); | 155 applyStyle(typingStyle.get(), firstPositionInOrBeforeNode(nodeToInsert.g
et()), lastPositionInOrAfterNode(nodeToInsert.get())); |
156 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). | 156 // Even though this applyStyle operates on a Range, it still sets an end
ingSelection(). |
157 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection | 157 // It tries to set a VisibleSelection around the content it operated on.
So, that VisibleSelection |
158 // will either (a) select the line break we inserted, or it will (b) be
a caret just | 158 // will either (a) select the line break we inserted, or it will (b) be
a caret just |
159 // before the line break (if the line break is at the end of a block it
isn't selectable). | 159 // before the line break (if the line break is at the end of a block it
isn't selectable). |
160 // So, this next call sets the endingSelection() to a caret just after t
he line break | 160 // So, this next call sets the endingSelection() to a caret just after t
he line break |
161 // that we inserted, or just before it if it's at the end of a block. | 161 // that we inserted, or just before it if it's at the end of a block. |
162 setEndingSelection(endingSelection().visibleEnd()); | 162 setEndingSelection(endingSelection().visibleEnd()); |
163 } | 163 } |
164 | 164 |
165 rebalanceWhitespace(); | 165 rebalanceWhitespace(); |
166 } | 166 } |
167 | 167 |
168 } | 168 } |
OLD | NEW |