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

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

Issue 2366693005: Mark paragraph-related functions deprecated in VisibleUnits (Closed)
Patch Set: Add output for DCHECK 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) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return; 65 return;
66 66
67 // When a selection ends at the start of a paragraph, we rarely paint 67 // When a selection ends at the start of a paragraph, we rarely paint
68 // the selection gap before that paragraph, because there often is no gap. 68 // the selection gap before that paragraph, because there often is no gap.
69 // In a case like this, it's not obvious to the user that the selection 69 // In a case like this, it's not obvious to the user that the selection
70 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent 70 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent
71 // operated on that paragraph. 71 // operated on that paragraph.
72 // FIXME: We paint the gap before some paragraphs that are indented with lef t 72 // FIXME: We paint the gap before some paragraphs that are indented with lef t
73 // margin/padding, but not others. We should make the gap painting more 73 // margin/padding, but not others. We should make the gap painting more
74 // consistent and then use a left margin/padding rule here. 74 // consistent and then use a left margin/padding rule here.
75 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraph(visibleEnd)) { 75 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraphDeprecated(visibleEnd)) {
76 VisibleSelection newSelection(visibleStart, previousPositionOf(visibleEn d, CannotCrossEditingBoundary), endingSelection().isDirectional()); 76 VisibleSelection newSelection(visibleStart, previousPositionOf(visibleEn d, CannotCrossEditingBoundary), endingSelection().isDirectional());
77 if (newSelection.isNone()) 77 if (newSelection.isNone())
78 return; 78 return;
79 setEndingSelection(newSelection); 79 setEndingSelection(newSelection);
80 } 80 }
81 81
82 VisibleSelection selection = selectionForParagraphIteration(endingSelection( )); 82 VisibleSelection selection = selectionForParagraphIteration(endingSelection( ));
83 VisiblePosition startOfSelection = selection.visibleStart(); 83 VisiblePosition startOfSelection = selection.visibleStart();
84 VisiblePosition endOfSelection = selection.visibleEnd(); 84 VisiblePosition endOfSelection = selection.visibleEnd();
85 DCHECK(!startOfSelection.isNull()); 85 DCHECK(!startOfSelection.isNull());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return; 124 return;
125 HTMLBRElement* placeholder = HTMLBRElement::create(document()); 125 HTMLBRElement* placeholder = HTMLBRElement::create(document());
126 appendNode(placeholder, blockquote, editingState); 126 appendNode(placeholder, blockquote, editingState);
127 if (editingState->isAborted()) 127 if (editingState->isAborted())
128 return; 128 return;
129 setEndingSelection(VisibleSelection(Position::beforeNode(placeholder), T extAffinity::Downstream, endingSelection().isDirectional())); 129 setEndingSelection(VisibleSelection(Position::beforeNode(placeholder), T extAffinity::Downstream, endingSelection().isDirectional()));
130 return; 130 return;
131 } 131 }
132 132
133 HTMLElement* blockquoteForNextIndent = nullptr; 133 HTMLElement* blockquoteForNextIndent = nullptr;
134 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); 134 VisiblePosition endOfCurrentParagraph = endOfParagraphDeprecated(startOfSele ction);
135 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); 135 VisiblePosition endOfLastParagraph = endOfParagraphDeprecated(endOfSelection );
136 VisiblePosition endAfterSelection = endOfParagraph(nextPositionOf(endOfLastP aragraph)); 136 VisiblePosition endAfterSelection = endOfParagraphDeprecated(nextPositionOf( endOfLastParagraph));
137 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent(); 137 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent();
138 138
139 bool atEnd = false; 139 bool atEnd = false;
140 Position end; 140 Position end;
141 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv alent() && !atEnd) { 141 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv alent() && !atEnd) {
142 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph) 142 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph)
143 atEnd = true; 143 atEnd = true;
144 144
145 rangeForParagraphSplittingTextNodesIfNeeded(endOfCurrentParagraph, start , end); 145 rangeForParagraphSplittingTextNodesIfNeeded(endOfCurrentParagraph, start , end);
146 endOfCurrentParagraph = createVisiblePositionDeprecated(end); 146 endOfCurrentParagraph = createVisiblePositionDeprecated(end);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 187
188 static const ComputedStyle* computedStyleOfEnclosingTextNode(const Position& pos ition) 188 static const ComputedStyle* computedStyleOfEnclosingTextNode(const Position& pos ition)
189 { 189 {
190 if (!position.isOffsetInAnchor() || !position.computeContainerNode() || !pos ition.computeContainerNode()->isTextNode()) 190 if (!position.isOffsetInAnchor() || !position.computeContainerNode() || !pos ition.computeContainerNode()->isTextNode())
191 return 0; 191 return 0;
192 return position.computeContainerNode()->computedStyle(); 192 return position.computeContainerNode()->computedStyle();
193 } 193 }
194 194
195 void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const VisiblePosition& endOfCurrentParagraph, Position& start, Position& end) 195 void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const VisiblePosition& endOfCurrentParagraph, Position& start, Position& end)
196 { 196 {
197 start = startOfParagraph(endOfCurrentParagraph).deepEquivalent(); 197 start = startOfParagraphDeprecated(endOfCurrentParagraph).deepEquivalent();
198 end = endOfCurrentParagraph.deepEquivalent(); 198 end = endOfCurrentParagraph.deepEquivalent();
199 199
200 document().updateStyleAndLayoutTree(); 200 document().updateStyleAndLayoutTree();
201 201
202 bool isStartAndEndOnSameNode = false; 202 bool isStartAndEndOnSameNode = false;
203 if (const ComputedStyle* startStyle = computedStyleOfEnclosingTextNode(start )) { 203 if (const ComputedStyle* startStyle = computedStyleOfEnclosingTextNode(start )) {
204 isStartAndEndOnSameNode = computedStyleOfEnclosingTextNode(end) && start .computeContainerNode() == end.computeContainerNode(); 204 isStartAndEndOnSameNode = computedStyleOfEnclosingTextNode(end) && start .computeContainerNode() == end.computeContainerNode();
205 bool isStartAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingTe xtNode(m_endOfLastParagraph) && start.computeContainerNode() == m_endOfLastParag raph.computeContainerNode(); 205 bool isStartAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingTe xtNode(m_endOfLastParagraph) && start.computeContainerNode() == m_endOfLastParag raph.computeContainerNode();
206 206
207 // Avoid obtanining the start of next paragraph for start 207 // Avoid obtanining the start of next paragraph for start
208 // TODO(yosin) We should use |PositionMoveType::CodePoint| for 208 // TODO(yosin) We should use |PositionMoveType::CodePoint| for
209 // |previousPositionOf()|. 209 // |previousPositionOf()|.
210 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(previousPositionOf(start, PositionMoveType::CodeUnit)) && start. offsetInContainerNode() > 0) 210 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(previousPositionOf(start, PositionMoveType::CodeUnit)) && start. offsetInContainerNode() > 0)
211 start = startOfParagraph(createVisiblePositionDeprecated(previousPos itionOf(end, PositionMoveType::CodeUnit))).deepEquivalent(); 211 start = startOfParagraphDeprecated(createVisiblePositionDeprecated(p reviousPositionOf(end, PositionMoveType::CodeUnit))).deepEquivalent();
212 212
213 // If start is in the middle of a text node, split. 213 // If start is in the middle of a text node, split.
214 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) { 214 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) {
215 int startOffset = start.offsetInContainerNode(); 215 int startOffset = start.offsetInContainerNode();
216 Text* startText = toText(start.computeContainerNode()); 216 Text* startText = toText(start.computeContainerNode());
217 splitTextNode(startText, startOffset); 217 splitTextNode(startText, startOffset);
218 start = Position::firstPositionInNode(startText); 218 start = Position::firstPositionInNode(startText);
219 if (isStartAndEndOnSameNode) { 219 if (isStartAndEndOnSameNode) {
220 DCHECK_GE(end.offsetInContainerNode(), startOffset); 220 DCHECK_GE(end.offsetInContainerNode(), startOffset);
221 end = Position(startText, end.offsetInContainerNode() - startOff set); 221 end = Position(startText, end.offsetInContainerNode() - startOff set);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 else 254 else
255 m_endOfLastParagraph = Position(endContainer, m_endOfLastPar agraph.offsetInContainerNode() - end.offsetInContainerNode()); 255 m_endOfLastParagraph = Position(endContainer, m_endOfLastPar agraph.offsetInContainerNode() - end.offsetInContainerNode());
256 } 256 }
257 end = Position::lastPositionInNode(endContainer->previousSibling()); 257 end = Position::lastPositionInNode(endContainer->previousSibling());
258 } 258 }
259 } 259 }
260 } 260 }
261 261
262 VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN eeded(VisiblePosition& endOfCurrentParagraph, Position& start, Position& end) 262 VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN eeded(VisiblePosition& endOfCurrentParagraph, Position& start, Position& end)
263 { 263 {
264 VisiblePosition endOfNextParagraph = endOfParagraph(nextPositionOf(endOfCurr entParagraph)); 264 VisiblePosition endOfNextParagraph = endOfParagraphDeprecated(nextPositionOf (endOfCurrentParagraph));
265 Position position = endOfNextParagraph.deepEquivalent(); 265 Position position = endOfNextParagraph.deepEquivalent();
266 const ComputedStyle* style = computedStyleOfEnclosingTextNode(position); 266 const ComputedStyle* style = computedStyleOfEnclosingTextNode(position);
267 if (!style) 267 if (!style)
268 return endOfNextParagraph; 268 return endOfNextParagraph;
269 269
270 Text* text = toText(position.computeContainerNode()); 270 Text* text = toText(position.computeContainerNode());
271 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(Position::firstPositionInNode(text))) 271 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(Position::firstPositionInNode(text)))
272 return endOfNextParagraph; 272 return endOfNextParagraph;
273 273
274 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones. 274 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return element; 306 return element;
307 } 307 }
308 308
309 DEFINE_TRACE(ApplyBlockElementCommand) 309 DEFINE_TRACE(ApplyBlockElementCommand)
310 { 310 {
311 visitor->trace(m_endOfLastParagraph); 311 visitor->trace(m_endOfLastParagraph);
312 CompositeEditCommand::trace(visitor); 312 CompositeEditCommand::trace(visitor);
313 } 313 }
314 314
315 } // namespace blink 315 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698