Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(991)

Side by Side Diff: Source/core/editing/InsertLineBreakCommand.cpp

Issue 24278008: [oilpan] Handlify Nodes in htmlediting (Closed) Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) { 117 if (isEndOfParagraph(caret) && !lineBreakExistsAtVisiblePosition(caret)) {
118 bool needExtraLineBreak = !pos.deprecatedNode()->hasTagName(hrTag) && !p os.deprecatedNode()->hasTagName(tableTag); 118 bool needExtraLineBreak = !pos.deprecatedNode()->hasTagName(hrTag) && !p os.deprecatedNode()->hasTagName(tableTag);
119 119
120 insertNodeAt(nodeToInsert, pos); 120 insertNodeAt(nodeToInsert, pos);
121 121
122 if (needExtraLineBreak) 122 if (needExtraLineBreak)
123 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); 123 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert);
124 124
125 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert)); 125 VisiblePosition endingPosition(positionBeforeNode(nodeToInsert));
126 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is Directional())); 126 setEndingSelection(VisibleSelection(endingPosition, endingSelection().is Directional()));
127 } else if (pos.deprecatedEditingOffset() <= caretMinOffset(pos.deprecatedNod e().handle().raw())) { 127 } else if (pos.deprecatedEditingOffset() <= caretMinOffset(pos.deprecatedNod e())) {
128 insertNodeAt(nodeToInsert, pos); 128 insertNodeAt(nodeToInsert, pos);
129 129
130 // Insert an extra br or '\n' if the just inserted one collapsed. 130 // Insert an extra br or '\n' if the just inserted one collapsed.
131 if (!isStartOfParagraph(positionBeforeNode(nodeToInsert))) 131 if (!isStartOfParagraph(positionBeforeNode(nodeToInsert)))
132 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert); 132 insertNodeBefore(nodeToInsert->cloneNode(false), nodeToInsert);
133 133
134 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse rt), DOWNSTREAM, endingSelection().isDirectional())); 134 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse rt), DOWNSTREAM, endingSelection().isDirectional()));
135 // If we're inserting after all of the rendered text in a text node, or into a non-text node, 135 // If we're inserting after all of the rendered text in a text node, or into a non-text node,
136 // a simple insertion is sufficient. 136 // a simple insertion is sufficient.
137 } else if (pos.deprecatedEditingOffset() >= caretMaxOffset(pos.deprecatedNod e().handle().raw()) || !pos.deprecatedNode()->isTextNode()) { 137 } else if (pos.deprecatedEditingOffset() >= caretMaxOffset(pos.deprecatedNod e()) || !pos.deprecatedNode()->isTextNode()) {
138 insertNodeAt(nodeToInsert, pos); 138 insertNodeAt(nodeToInsert, pos);
139 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse rt), DOWNSTREAM, endingSelection().isDirectional())); 139 setEndingSelection(VisibleSelection(positionInParentAfterNode(nodeToInse rt), DOWNSTREAM, endingSelection().isDirectional()));
140 } else if (pos.deprecatedNode()->isTextNode()) { 140 } else if (pos.deprecatedNode()->isTextNode()) {
141 // Split a text node 141 // Split a text node
142 Handle<Text> textNode = toText(pos.deprecatedNode()); 142 Handle<Text> textNode = toText(pos.deprecatedNode());
143 splitTextNode(textNode, pos.deprecatedEditingOffset()); 143 splitTextNode(textNode, pos.deprecatedEditingOffset());
144 insertNodeBefore(nodeToInsert, textNode); 144 insertNodeBefore(nodeToInsert, textNode);
145 Position endingPosition = firstPositionInNode(textNode); 145 Position endingPosition = firstPositionInNode(textNode);
146 146
147 // Handle whitespace that occurs after the split 147 // Handle whitespace that occurs after the split
(...skipping 18 matching lines...) Expand all
166 166
167 // Handle the case where there is a typing style. 167 // Handle the case where there is a typing style.
168 168
169 RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingS tyle(); 169 RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingS tyle();
170 170
171 if (typingStyle && !typingStyle->isEmpty()) { 171 if (typingStyle && !typingStyle->isEmpty()) {
172 // Apply the typing style to the inserted line break, so that if the sel ection 172 // Apply the typing style to the inserted line break, so that if the sel ection
173 // leaves and then comes back, new input will have the right style. 173 // leaves and then comes back, new input will have the right style.
174 // FIXME: We shouldn't always apply the typing style to the line break h ere, 174 // FIXME: We shouldn't always apply the typing style to the line break h ere,
175 // see <rdar://problem/5794462>. 175 // see <rdar://problem/5794462>.
176 applyStyle(typingStyle.get(), firstPositionInOrBeforeNode(nodeToInsert.r aw()), lastPositionInOrAfterNode(nodeToInsert.raw())); 176 applyStyle(typingStyle.get(), firstPositionInOrBeforeNode(nodeToInsert), lastPositionInOrAfterNode(nodeToInsert));
177 // Even though this applyStyle operates on a Range, it still sets an end ingSelection(). 177 // Even though this applyStyle operates on a Range, it still sets an end ingSelection().
178 // It tries to set a VisibleSelection around the content it operated on. So, that VisibleSelection 178 // It tries to set a VisibleSelection around the content it operated on. So, that VisibleSelection
179 // will either (a) select the line break we inserted, or it will (b) be a caret just 179 // will either (a) select the line break we inserted, or it will (b) be a caret just
180 // before the line break (if the line break is at the end of a block it isn't selectable). 180 // before the line break (if the line break is at the end of a block it isn't selectable).
181 // So, this next call sets the endingSelection() to a caret just after t he line break 181 // So, this next call sets the endingSelection() to a caret just after t he line break
182 // that we inserted, or just before it if it's at the end of a block. 182 // that we inserted, or just before it if it's at the end of a block.
183 setEndingSelection(endingSelection().visibleEnd()); 183 setEndingSelection(endingSelection().visibleEnd());
184 } 184 }
185 185
186 rebalanceWhitespace(); 186 rebalanceWhitespace();
187 } 187 }
188 188
189 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698