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

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

Issue 2397963002: Reflow comments in //third_party/WebKit/Source/core/editing/commands (Closed)
Patch Set: . 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // This is a scenario that should never happen, but we want to 88 // This is a scenario that should never happen, but we want to
89 // make sure we don't dereference a null pointer below. 89 // make sure we don't dereference a null pointer below.
90 90
91 DCHECK(!endingSelection().isNone()); 91 DCHECK(!endingSelection().isNone());
92 92
93 if (endingSelection().isNone()) 93 if (endingSelection().isNone())
94 return; 94 return;
95 95
96 VisiblePosition visiblePos = endingSelection().visibleStartDeprecated(); 96 VisiblePosition visiblePos = endingSelection().visibleStartDeprecated();
97 97
98 // pos is a position equivalent to the caret. We use downstream() so that pos will 98 // pos is a position equivalent to the caret. We use downstream() so that pos
99 // be in the first node that we need to move (there are a few exceptions to th is, see below). 99 // will be in the first node that we need to move (there are a few exceptions
100 // to this, see below).
100 Position pos = mostForwardCaretPosition(endingSelection().start()); 101 Position pos = mostForwardCaretPosition(endingSelection().start());
101 102
102 // Find the top-most blockquote from the start. 103 // Find the top-most blockquote from the start.
103 HTMLQuoteElement* topBlockquote = toHTMLQuoteElement( 104 HTMLQuoteElement* topBlockquote = toHTMLQuoteElement(
104 highestEnclosingNodeOfType(pos, isMailHTMLBlockquoteElement)); 105 highestEnclosingNodeOfType(pos, isMailHTMLBlockquoteElement));
105 if (!topBlockquote || !topBlockquote->parentNode()) 106 if (!topBlockquote || !topBlockquote->parentNode())
106 return; 107 return;
107 108
108 HTMLBRElement* breakElement = HTMLBRElement::create(document()); 109 HTMLBRElement* breakElement = HTMLBRElement::create(document());
109 110
110 bool isLastVisPosInNode = 111 bool isLastVisPosInNode =
111 isLastVisiblePositionInNode(visiblePos, topBlockquote); 112 isLastVisiblePositionInNode(visiblePos, topBlockquote);
112 113
113 // If the position is at the beginning of the top quoted content, we don't nee d to break the quote. 114 // If the position is at the beginning of the top quoted content, we don't
114 // Instead, insert the break before the blockquote, unless the position is as the end of the the quoted content. 115 // need to break the quote. Instead, insert the break before the blockquote,
116 // unless the position is as the end of the the quoted content.
115 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) && 117 if (isFirstVisiblePositionInNode(visiblePos, topBlockquote) &&
116 !isLastVisPosInNode) { 118 !isLastVisPosInNode) {
117 insertNodeBefore(breakElement, topBlockquote, editingState); 119 insertNodeBefore(breakElement, topBlockquote, editingState);
118 if (editingState->isAborted()) 120 if (editingState->isAborted())
119 return; 121 return;
120 setEndingSelection(createVisibleSelectionDeprecated( 122 setEndingSelection(createVisibleSelectionDeprecated(
121 Position::beforeNode(breakElement), TextAffinity::Downstream, 123 Position::beforeNode(breakElement), TextAffinity::Downstream,
122 endingSelection().isDirectional())); 124 endingSelection().isDirectional()));
123 rebalanceWhitespace(); 125 rebalanceWhitespace();
124 return; 126 return;
125 } 127 }
126 128
127 // Insert a break after the top blockquote. 129 // Insert a break after the top blockquote.
128 insertNodeAfter(breakElement, topBlockquote, editingState); 130 insertNodeAfter(breakElement, topBlockquote, editingState);
129 if (editingState->isAborted()) 131 if (editingState->isAborted())
130 return; 132 return;
131 133
132 // If we're inserting the break at the end of the quoted content, we don't nee d to break the quote. 134 // If we're inserting the break at the end of the quoted content, we don't
135 // need to break the quote.
133 if (isLastVisPosInNode) { 136 if (isLastVisPosInNode) {
134 setEndingSelection(createVisibleSelectionDeprecated( 137 setEndingSelection(createVisibleSelectionDeprecated(
135 Position::beforeNode(breakElement), TextAffinity::Downstream, 138 Position::beforeNode(breakElement), TextAffinity::Downstream,
136 endingSelection().isDirectional())); 139 endingSelection().isDirectional()));
137 rebalanceWhitespace(); 140 rebalanceWhitespace();
138 return; 141 return;
139 } 142 }
140 143
141 // Don't move a line break just after the caret. Doing so would create an ext ra, empty paragraph 144 // Don't move a line break just after the caret. Doing so would create an
142 // in the new blockquote. 145 // extra, empty paragraph in the new blockquote.
143 if (lineBreakExistsAtVisiblePosition(visiblePos)) { 146 if (lineBreakExistsAtVisiblePosition(visiblePos)) {
144 pos = nextPositionOf(pos, PositionMoveType::GraphemeCluster); 147 pos = nextPositionOf(pos, PositionMoveType::GraphemeCluster);
145 } 148 }
146 149
147 // Adjust the position so we don't split at the beginning of a quote. 150 // Adjust the position so we don't split at the beginning of a quote.
148 while (isFirstVisiblePositionInNode(createVisiblePositionDeprecated(pos), 151 while (isFirstVisiblePositionInNode(createVisiblePositionDeprecated(pos),
149 toHTMLQuoteElement(enclosingNodeOfType( 152 toHTMLQuoteElement(enclosingNodeOfType(
150 pos, isMailHTMLBlockquoteElement)))) { 153 pos, isMailHTMLBlockquoteElement)))) {
151 pos = previousPositionOf(pos, PositionMoveType::GraphemeCluster); 154 pos = previousPositionOf(pos, PositionMoveType::GraphemeCluster);
152 } 155 }
(...skipping 20 matching lines...) Expand all
173 } 176 }
174 177
175 // If there's nothing inside topBlockquote to move, we're finished. 178 // If there's nothing inside topBlockquote to move, we're finished.
176 if (!startNode->isDescendantOf(topBlockquote)) { 179 if (!startNode->isDescendantOf(topBlockquote)) {
177 setEndingSelection(createVisibleSelectionDeprecated( 180 setEndingSelection(createVisibleSelectionDeprecated(
178 createVisiblePositionDeprecated(firstPositionInOrBeforeNode(startNode)), 181 createVisiblePositionDeprecated(firstPositionInOrBeforeNode(startNode)),
179 endingSelection().isDirectional())); 182 endingSelection().isDirectional()));
180 return; 183 return;
181 } 184 }
182 185
183 // Build up list of ancestors in between the start node and the top blockquote . 186 // Build up list of ancestors in between the start node and the top
187 // blockquote.
184 HeapVector<Member<Element>> ancestors; 188 HeapVector<Member<Element>> ancestors;
185 for (Element* node = startNode->parentElement(); 189 for (Element* node = startNode->parentElement();
186 node && node != topBlockquote; node = node->parentElement()) 190 node && node != topBlockquote; node = node->parentElement())
187 ancestors.append(node); 191 ancestors.append(node);
188 192
189 // Insert a clone of the top blockquote after the break. 193 // Insert a clone of the top blockquote after the break.
190 Element* clonedBlockquote = topBlockquote->cloneElementWithoutChildren(); 194 Element* clonedBlockquote = topBlockquote->cloneElementWithoutChildren();
191 insertNodeAfter(clonedBlockquote, breakElement, editingState); 195 insertNodeAfter(clonedBlockquote, breakElement, editingState);
192 if (editingState->isAborted()) 196 if (editingState->isAborted())
193 return; 197 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 return; 260 return;
257 261
258 // Put the selection right before the break. 262 // Put the selection right before the break.
259 setEndingSelection(createVisibleSelectionDeprecated( 263 setEndingSelection(createVisibleSelectionDeprecated(
260 Position::beforeNode(breakElement), TextAffinity::Downstream, 264 Position::beforeNode(breakElement), TextAffinity::Downstream,
261 endingSelection().isDirectional())); 265 endingSelection().isDirectional()));
262 rebalanceWhitespace(); 266 rebalanceWhitespace();
263 } 267 }
264 268
265 } // namespace blink 269 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698