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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/BreakBlockquoteCommand.cpp

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 HTMLBRElement* breakElement = HTMLBRElement::create(document()); 106 HTMLBRElement* breakElement = HTMLBRElement::create(document());
107 107
108 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu ote); 108 bool isLastVisPosInNode = isLastVisiblePositionInNode(visiblePos, topBlockqu ote);
109 109
110 // If the position is at the beginning of the top quoted content, we don't n eed to break the quote. 110 // If the position is at the beginning of the top quoted content, we don't n eed to break the quote.
111 // Instead, insert the break before the blockquote, unless the position is a s the end of the the quoted content. 111 // Instead, insert the break before the blockquote, unless the position is a s the end of the the quoted content.
112 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPos InNode) { 112 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && !isLastVisPos InNode) {
113 insertNodeBefore(breakElement, topBlockquote, editingState); 113 insertNodeBefore(breakElement, topBlockquote, editingState);
114 if (editingState->isAborted()) 114 if (editingState->isAborted())
115 return; 115 return;
116 setEndingSelection(VisibleSelection(Position::beforeNode(breakElement), TextAffinity::Downstream, endingSelection().isDirectional())); 116 setEndingSelection(createVisibleSelectionDeprecated(Position::beforeNode (breakElement), TextAffinity::Downstream, endingSelection().isDirectional()));
117 rebalanceWhitespace(); 117 rebalanceWhitespace();
118 return; 118 return;
119 } 119 }
120 120
121 // Insert a break after the top blockquote. 121 // Insert a break after the top blockquote.
122 insertNodeAfter(breakElement, topBlockquote, editingState); 122 insertNodeAfter(breakElement, topBlockquote, editingState);
123 if (editingState->isAborted()) 123 if (editingState->isAborted())
124 return; 124 return;
125 125
126 // If we're inserting the break at the end of the quoted content, we don't n eed to break the quote. 126 // If we're inserting the break at the end of the quoted content, we don't n eed to break the quote.
127 if (isLastVisPosInNode) { 127 if (isLastVisPosInNode) {
128 setEndingSelection(VisibleSelection(Position::beforeNode(breakElement), TextAffinity::Downstream, endingSelection().isDirectional())); 128 setEndingSelection(createVisibleSelectionDeprecated(Position::beforeNode (breakElement), TextAffinity::Downstream, endingSelection().isDirectional()));
129 rebalanceWhitespace(); 129 rebalanceWhitespace();
130 return; 130 return;
131 } 131 }
132 132
133 // Don't move a line break just after the caret. Doing so would create an e xtra, empty paragraph 133 // Don't move a line break just after the caret. Doing so would create an e xtra, empty paragraph
134 // in the new blockquote. 134 // in the new blockquote.
135 if (lineBreakExistsAtVisiblePosition(visiblePos)) { 135 if (lineBreakExistsAtVisiblePosition(visiblePos)) {
136 pos = nextPositionOf(pos, PositionMoveType::GraphemeCluster); 136 pos = nextPositionOf(pos, PositionMoveType::GraphemeCluster);
137 } 137 }
138 138
(...skipping 17 matching lines...) Expand all
156 splitTextNode(textNode, textOffset); 156 splitTextNode(textNode, textOffset);
157 } 157 }
158 } else if (pos.computeEditingOffset() > 0) { 158 } else if (pos.computeEditingOffset() > 0) {
159 Node* childAtOffset = NodeTraversal::childAt(*startNode, pos.computeEdit ingOffset()); 159 Node* childAtOffset = NodeTraversal::childAt(*startNode, pos.computeEdit ingOffset());
160 startNode = childAtOffset ? childAtOffset : NodeTraversal::next(*startNo de); 160 startNode = childAtOffset ? childAtOffset : NodeTraversal::next(*startNo de);
161 DCHECK(startNode); 161 DCHECK(startNode);
162 } 162 }
163 163
164 // If there's nothing inside topBlockquote to move, we're finished. 164 // If there's nothing inside topBlockquote to move, we're finished.
165 if (!startNode->isDescendantOf(topBlockquote)) { 165 if (!startNode->isDescendantOf(topBlockquote)) {
166 setEndingSelection(VisibleSelection(createVisiblePositionDeprecated(firs tPositionInOrBeforeNode(startNode)), endingSelection().isDirectional())); 166 setEndingSelection(createVisibleSelectionDeprecated(createVisiblePositio nDeprecated(firstPositionInOrBeforeNode(startNode)), endingSelection().isDirecti onal()));
167 return; 167 return;
168 } 168 }
169 169
170 // Build up list of ancestors in between the start node and the top blockquo te. 170 // Build up list of ancestors in between the start node and the top blockquo te.
171 HeapVector<Member<Element>> ancestors; 171 HeapVector<Member<Element>> ancestors;
172 for (Element* node = startNode->parentElement(); node && node != topBlockquo te; node = node->parentElement()) 172 for (Element* node = startNode->parentElement(); node && node != topBlockquo te; node = node->parentElement())
173 ancestors.append(node); 173 ancestors.append(node);
174 174
175 // Insert a clone of the top blockquote after the break. 175 // Insert a clone of the top blockquote after the break.
176 Element* clonedBlockquote = topBlockquote->cloneElementWithoutChildren(); 176 Element* clonedBlockquote = topBlockquote->cloneElementWithoutChildren();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return; 229 return;
230 } 230 }
231 } 231 }
232 232
233 // Make sure the cloned block quote renders. 233 // Make sure the cloned block quote renders.
234 addBlockPlaceholderIfNeeded(clonedBlockquote, editingState); 234 addBlockPlaceholderIfNeeded(clonedBlockquote, editingState);
235 if (editingState->isAborted()) 235 if (editingState->isAborted())
236 return; 236 return;
237 237
238 // Put the selection right before the break. 238 // Put the selection right before the break.
239 setEndingSelection(VisibleSelection(Position::beforeNode(breakElement), Text Affinity::Downstream, endingSelection().isDirectional())); 239 setEndingSelection(createVisibleSelectionDeprecated(Position::beforeNode(bre akElement), TextAffinity::Downstream, endingSelection().isDirectional()));
240 rebalanceWhitespace(); 240 rebalanceWhitespace();
241 } 241 }
242 242
243 } // namespace blink 243 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698