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

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

Issue 1878473002: ASSERT -> DCHECK in core/editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Output info for some DCHECKs, add TODOs. Created 4 years, 8 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraph(visibleEnd)) { 76 if (visibleEnd.deepEquivalent() != visibleStart.deepEquivalent() && isStartO fParagraph(visibleEnd)) {
77 VisibleSelection newSelection(visibleStart, previousPositionOf(visibleEn d, CannotCrossEditingBoundary), endingSelection().isDirectional()); 77 VisibleSelection newSelection(visibleStart, previousPositionOf(visibleEn d, CannotCrossEditingBoundary), endingSelection().isDirectional());
78 if (newSelection.isNone()) 78 if (newSelection.isNone())
79 return; 79 return;
80 setEndingSelection(newSelection); 80 setEndingSelection(newSelection);
81 } 81 }
82 82
83 VisibleSelection selection = selectionForParagraphIteration(endingSelection( )); 83 VisibleSelection selection = selectionForParagraphIteration(endingSelection( ));
84 VisiblePosition startOfSelection = selection.visibleStart(); 84 VisiblePosition startOfSelection = selection.visibleStart();
85 VisiblePosition endOfSelection = selection.visibleEnd(); 85 VisiblePosition endOfSelection = selection.visibleEnd();
86 ASSERT(!startOfSelection.isNull()); 86 DCHECK(!startOfSelection.isNull());
87 ASSERT(!endOfSelection.isNull()); 87 DCHECK(!endOfSelection.isNull());
88 ContainerNode* startScope = nullptr; 88 ContainerNode* startScope = nullptr;
89 int startIndex = indexForVisiblePosition(startOfSelection, startScope); 89 int startIndex = indexForVisiblePosition(startOfSelection, startScope);
90 ContainerNode* endScope = nullptr; 90 ContainerNode* endScope = nullptr;
91 int endIndex = indexForVisiblePosition(endOfSelection, endScope); 91 int endIndex = indexForVisiblePosition(endOfSelection, endScope);
92 92
93 formatSelection(startOfSelection, endOfSelection, editingState); 93 formatSelection(startOfSelection, endOfSelection, editingState);
94 if (editingState->isAborted()) 94 if (editingState->isAborted())
95 return; 95 return;
96 96
97 document().updateLayoutIgnorePendingStylesheets(); 97 document().updateLayoutIgnorePendingStylesheets();
98 98
99 ASSERT(startScope == endScope); 99 DCHECK_EQ(startScope, endScope);
100 ASSERT(startIndex >= 0); 100 DCHECK_GE(startIndex, 0);
101 ASSERT(startIndex <= endIndex); 101 DCHECK_LE(startIndex, endIndex);
102 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { 102 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) {
103 VisiblePosition start(visiblePositionForIndex(startIndex, startScope)); 103 VisiblePosition start(visiblePositionForIndex(startIndex, startScope));
104 VisiblePosition end(visiblePositionForIndex(endIndex, endScope)); 104 VisiblePosition end(visiblePositionForIndex(endIndex, endScope));
105 if (start.isNotNull() && end.isNotNull()) 105 if (start.isNotNull() && end.isNotNull())
106 setEndingSelection(VisibleSelection(start, end, endingSelection().is Directional())); 106 setEndingSelection(VisibleSelection(start, end, endingSelection().is Directional()));
107 } 107 }
108 } 108 }
109 109
110 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel ection, const VisiblePosition& endOfSelection, EditingState* editingState) 110 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel ection, const VisiblePosition& endOfSelection, EditingState* editingState)
111 { 111 {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(previousPositionOf(start, PositionMoveType::CodeUnit)) && start. offsetInContainerNode() > 0) 205 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(previousPositionOf(start, PositionMoveType::CodeUnit)) && start. offsetInContainerNode() > 0)
206 start = startOfParagraph(createVisiblePosition(previousPositionOf(en d, PositionMoveType::CodeUnit))).deepEquivalent(); 206 start = startOfParagraph(createVisiblePosition(previousPositionOf(en d, PositionMoveType::CodeUnit))).deepEquivalent();
207 207
208 // If start is in the middle of a text node, split. 208 // If start is in the middle of a text node, split.
209 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) { 209 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) {
210 int startOffset = start.offsetInContainerNode(); 210 int startOffset = start.offsetInContainerNode();
211 Text* startText = toText(start.computeContainerNode()); 211 Text* startText = toText(start.computeContainerNode());
212 splitTextNode(startText, startOffset); 212 splitTextNode(startText, startOffset);
213 start = firstPositionInNode(startText); 213 start = firstPositionInNode(startText);
214 if (isStartAndEndOnSameNode) { 214 if (isStartAndEndOnSameNode) {
215 ASSERT(end.offsetInContainerNode() >= startOffset); 215 DCHECK_GE(end.offsetInContainerNode(), startOffset);
216 end = Position(startText, end.offsetInContainerNode() - startOff set); 216 end = Position(startText, end.offsetInContainerNode() - startOff set);
217 } 217 }
218 if (isStartAndEndOfLastParagraphOnSameNode) { 218 if (isStartAndEndOfLastParagraphOnSameNode) {
219 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffs et); 219 DCHECK_GE(m_endOfLastParagraph.offsetInContainerNode(), startOff set);
220 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph. offsetInContainerNode() - startOffset); 220 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph. offsetInContainerNode() - startOffset);
221 } 221 }
222 } 222 }
223 } 223 }
224 224
225 document().updateLayoutTree(); 225 document().updateLayoutTree();
226 226
227 if (const ComputedStyle* endStyle = computedStyleOfEnclosingTextNode(end)) { 227 if (const ComputedStyle* endStyle = computedStyleOfEnclosingTextNode(end)) {
228 bool isEndAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingText Node(m_endOfLastParagraph) && end.anchorNode() == m_endOfLastParagraph.anchorNod e(); 228 bool isEndAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingText Node(m_endOfLastParagraph) && end.anchorNode() == m_endOfLastParagraph.anchorNod e();
229 // Include \n at the end of line if we're at an empty paragraph 229 // Include \n at the end of line if we're at an empty paragraph
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 Text* text = toText(position.computeContainerNode()); 265 Text* text = toText(position.computeContainerNode());
266 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(firstPositionInNode(text))) 266 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(firstPositionInNode(text)))
267 return endOfNextParagraph; 267 return endOfNextParagraph;
268 268
269 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones. 269 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones.
270 // If endOfNextParagraph was pointing at this same text node, endOfNextParag raph will be shifted by one paragraph. 270 // If endOfNextParagraph was pointing at this same text node, endOfNextParag raph will be shifted by one paragraph.
271 // Avoid this by splitting "\n" 271 // Avoid this by splitting "\n"
272 splitTextNode(text, 1); 272 splitTextNode(text, 1);
273 273
274 if (text == start.computeContainerNode() && text->previousSibling() && text- >previousSibling()->isTextNode()) { 274 if (text == start.computeContainerNode() && text->previousSibling() && text- >previousSibling()->isTextNode()) {
275 ASSERT(start.offsetInContainerNode() < position.offsetInContainerNode()) ; 275 DCHECK_LT(start.offsetInContainerNode(), position.offsetInContainerNode( ));
276 start = Position(toText(text->previousSibling()), start.offsetInContaine rNode()); 276 start = Position(toText(text->previousSibling()), start.offsetInContaine rNode());
277 } 277 }
278 if (text == end.computeContainerNode() && text->previousSibling() && text->p reviousSibling()->isTextNode()) { 278 if (text == end.computeContainerNode() && text->previousSibling() && text->p reviousSibling()->isTextNode()) {
279 ASSERT(end.offsetInContainerNode() < position.offsetInContainerNode()); 279 DCHECK_LT(end.offsetInContainerNode(), position.offsetInContainerNode()) ;
280 end = Position(toText(text->previousSibling()), end.offsetInContainerNod e()); 280 end = Position(toText(text->previousSibling()), end.offsetInContainerNod e());
281 } 281 }
282 if (text == m_endOfLastParagraph.computeContainerNode()) { 282 if (text == m_endOfLastParagraph.computeContainerNode()) {
283 if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInCont ainerNode()) { 283 if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInCont ainerNode()) {
284 // We can only fix endOfLastParagraph if the previous node was still text and hasn't been modified by script. 284 // We can only fix endOfLastParagraph if the previous node was still text and hasn't been modified by script.
285 if (text->previousSibling()->isTextNode() 285 if (text->previousSibling()->isTextNode()
286 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN ode()) <= toText(text->previousSibling())->length()) 286 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN ode()) <= toText(text->previousSibling())->length())
287 m_endOfLastParagraph = Position(toText(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode()); 287 m_endOfLastParagraph = Position(toText(text->previousSibling()), m_endOfLastParagraph.offsetInContainerNode());
288 } else { 288 } else {
289 m_endOfLastParagraph = Position(text, m_endOfLastParagraph.offsetInC ontainerNode() - 1); 289 m_endOfLastParagraph = Position(text, m_endOfLastParagraph.offsetInC ontainerNode() - 1);
(...skipping 11 matching lines...) Expand all
301 return element; 301 return element;
302 } 302 }
303 303
304 DEFINE_TRACE(ApplyBlockElementCommand) 304 DEFINE_TRACE(ApplyBlockElementCommand)
305 { 305 {
306 visitor->trace(m_endOfLastParagraph); 306 visitor->trace(m_endOfLastParagraph);
307 CompositeEditCommand::trace(visitor); 307 CompositeEditCommand::trace(visitor);
308 } 308 }
309 309
310 } // namespace blink 310 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698