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/DeleteSelectionCommand.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) 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 30 matching lines...) Expand all
41 #include "core/html/HTMLTableRowElement.h" 41 #include "core/html/HTMLTableRowElement.h"
42 #include "core/layout/LayoutTableCell.h" 42 #include "core/layout/LayoutTableCell.h"
43 #include "core/layout/LayoutText.h" 43 #include "core/layout/LayoutText.h"
44 44
45 namespace blink { 45 namespace blink {
46 46
47 using namespace HTMLNames; 47 using namespace HTMLNames;
48 48
49 static bool isTableCellEmpty(Node* cell) 49 static bool isTableCellEmpty(Node* cell)
50 { 50 {
51 ASSERT(isTableCell(cell)); 51 DCHECK(isTableCell(cell)) << cell;
52 return createVisiblePosition(firstPositionInNode(cell)).deepEquivalent() == createVisiblePosition(lastPositionInNode(cell)).deepEquivalent(); 52 return createVisiblePosition(firstPositionInNode(cell)).deepEquivalent() == createVisiblePosition(lastPositionInNode(cell)).deepEquivalent();
53 } 53 }
54 54
55 static bool isTableRowEmpty(Node* row) 55 static bool isTableRowEmpty(Node* row)
56 { 56 {
57 if (!isHTMLTableRowElement(row)) 57 if (!isHTMLTableRowElement(row))
58 return false; 58 return false;
59 59
60 for (Node* child = row->firstChild(); child; child = child->nextSibling()) { 60 for (Node* child = row->firstChild(); child; child = child->nextSibling()) {
61 if (isTableCell(child) && !isTableCellEmpty(child)) 61 if (isTableCell(child) && !isTableCellEmpty(child))
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 bool isBaseFirst = startingSelection().isBaseFirst(); 159 bool isBaseFirst = startingSelection().isBaseFirst();
160 VisiblePosition newBase = createVisiblePosition(isBaseFirst ? start : end); 160 VisiblePosition newBase = createVisiblePosition(isBaseFirst ? start : end);
161 VisiblePosition newExtent = createVisiblePosition(isBaseFirst ? end : start) ; 161 VisiblePosition newExtent = createVisiblePosition(isBaseFirst ? end : start) ;
162 setStartingSelection(VisibleSelection(newBase, newExtent, startingSelection( ).isDirectional())); 162 setStartingSelection(VisibleSelection(newBase, newExtent, startingSelection( ).isDirectional()));
163 } 163 }
164 164
165 void DeleteSelectionCommand::initializePositionData(EditingState* editingState) 165 void DeleteSelectionCommand::initializePositionData(EditingState* editingState)
166 { 166 {
167 Position start, end; 167 Position start, end;
168 initializeStartEnd(start, end); 168 initializeStartEnd(start, end);
169 ASSERT(start.isNotNull()); 169 DCHECK(start.isNotNull());
170 ASSERT(end.isNotNull()); 170 DCHECK(end.isNotNull());
171 if (!isEditablePosition(start, ContentIsEditable, DoNotUpdateStyle)) { 171 if (!isEditablePosition(start, ContentIsEditable, DoNotUpdateStyle)) {
172 editingState->abort(); 172 editingState->abort();
173 return; 173 return;
174 } 174 }
175 if (!isEditablePosition(end, ContentIsEditable, DoNotUpdateStyle)) { 175 if (!isEditablePosition(end, ContentIsEditable, DoNotUpdateStyle)) {
176 Node* highestRoot = highestEditableRoot(start); 176 Node* highestRoot = highestEditableRoot(start);
177 ASSERT(highestRoot); 177 DCHECK(highestRoot);
178 end = lastEditablePositionBeforePositionInRoot(end, *highestRoot); 178 end = lastEditablePositionBeforePositionInRoot(end, *highestRoot);
179 } 179 }
180 180
181 m_upstreamStart = mostBackwardCaretPosition(start); 181 m_upstreamStart = mostBackwardCaretPosition(start);
182 m_downstreamStart = mostForwardCaretPosition(start); 182 m_downstreamStart = mostForwardCaretPosition(start);
183 m_upstreamEnd = mostBackwardCaretPosition(end); 183 m_upstreamEnd = mostBackwardCaretPosition(end);
184 m_downstreamEnd = mostForwardCaretPosition(end); 184 m_downstreamEnd = mostForwardCaretPosition(end);
185 185
186 m_startRoot = rootEditableElementOf(start); 186 m_startRoot = rootEditableElementOf(start);
187 m_endRoot = rootEditableElementOf(end); 187 m_endRoot = rootEditableElementOf(end);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 if (upstreamStartIsBR && downstreamStartIsBR && !(isStartOfBlock(createVisib lePosition(positionBeforeNode(nodeAfterUpstreamStart))) && isEndOfBlock(createVi siblePosition(positionAfterNode(nodeAfterUpstreamStart))))) { 327 if (upstreamStartIsBR && downstreamStartIsBR && !(isStartOfBlock(createVisib lePosition(positionBeforeNode(nodeAfterUpstreamStart))) && isEndOfBlock(createVi siblePosition(positionAfterNode(nodeAfterUpstreamStart))))) {
328 m_startsAtEmptyLine = true; 328 m_startsAtEmptyLine = true;
329 m_endingPosition = m_downstreamEnd; 329 m_endingPosition = m_downstreamEnd;
330 } 330 }
331 331
332 return false; 332 return false;
333 } 333 }
334 334
335 static Position firstEditablePositionInNode(Node* node) 335 static Position firstEditablePositionInNode(Node* node)
336 { 336 {
337 ASSERT(node); 337 DCHECK(node);
338 Node* next = node; 338 Node* next = node;
339 while (next && !next->hasEditableStyle()) 339 while (next && !next->hasEditableStyle())
340 next = NodeTraversal::next(*next, node); 340 next = NodeTraversal::next(*next, node);
341 return next ? firstPositionInOrBeforeNode(next) : Position(); 341 return next ? firstPositionInOrBeforeNode(next) : Position();
342 } 342 }
343 343
344 void DeleteSelectionCommand::removeNode(Node* node, EditingState* editingState, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable) 344 void DeleteSelectionCommand::removeNode(Node* node, EditingState* editingState, ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable)
345 { 345 {
346 if (!node) 346 if (!node)
347 return; 347 return;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 456 }
457 } 457 }
458 458
459 void DeleteSelectionCommand::handleGeneralDelete(EditingState* editingState) 459 void DeleteSelectionCommand::handleGeneralDelete(EditingState* editingState)
460 { 460 {
461 if (m_upstreamStart.isNull()) 461 if (m_upstreamStart.isNull())
462 return; 462 return;
463 463
464 int startOffset = m_upstreamStart.computeEditingOffset(); 464 int startOffset = m_upstreamStart.computeEditingOffset();
465 Node* startNode = m_upstreamStart.anchorNode(); 465 Node* startNode = m_upstreamStart.anchorNode();
466 ASSERT(startNode); 466 DCHECK(startNode);
467 467
468 makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss(editingSta te); 468 makeStylingElementsDirectChildrenOfEditableRootToPreventStyleLoss(editingSta te);
469 if (editingState->isAborted()) 469 if (editingState->isAborted())
470 return; 470 return;
471 471
472 // Never remove the start block unless it's a table, in which case we won't merge content in. 472 // Never remove the start block unless it's a table, in which case we won't merge content in.
473 if (startNode == m_startBlock.get() && !startOffset && canHaveChildrenForEdi ting(startNode) && !isHTMLTableElement(*startNode)) { 473 if (startNode == m_startBlock.get() && !startOffset && canHaveChildrenForEdi ting(startNode) && !isHTMLTableElement(*startNode)) {
474 startOffset = 0; 474 startOffset = 0;
475 startNode = NodeTraversal::next(*startNode); 475 startNode = NodeTraversal::next(*startNode);
476 if (!startNode) 476 if (!startNode)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } 595 }
596 596
597 void DeleteSelectionCommand::fixupWhitespace() 597 void DeleteSelectionCommand::fixupWhitespace()
598 { 598 {
599 document().updateLayoutIgnorePendingStylesheets(); 599 document().updateLayoutIgnorePendingStylesheets();
600 // TODO(yosin) |isRenderedCharacter()| should be removed, and we should use 600 // TODO(yosin) |isRenderedCharacter()| should be removed, and we should use
601 // |VisiblePosition::characterAfter()| and 601 // |VisiblePosition::characterAfter()| and
602 // |VisiblePosition::characterBefore()| 602 // |VisiblePosition::characterBefore()|
603 if (m_leadingWhitespace.isNotNull() && !isRenderedCharacter(m_leadingWhitesp ace) && m_leadingWhitespace.anchorNode()->isTextNode()) { 603 if (m_leadingWhitespace.isNotNull() && !isRenderedCharacter(m_leadingWhitesp ace) && m_leadingWhitespace.anchorNode()->isTextNode()) {
604 Text* textNode = toText(m_leadingWhitespace.anchorNode()); 604 Text* textNode = toText(m_leadingWhitespace.anchorNode());
605 ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style()->c ollapseWhiteSpace()); 605 DCHECK(!textNode->layoutObject() || textNode->layoutObject()->style()->c ollapseWhiteSpace()) << textNode;
606 replaceTextInNodePreservingMarkers(textNode, m_leadingWhitespace.compute OffsetInContainerNode(), 1, nonBreakingSpaceString()); 606 replaceTextInNodePreservingMarkers(textNode, m_leadingWhitespace.compute OffsetInContainerNode(), 1, nonBreakingSpaceString());
607 } 607 }
608 if (m_trailingWhitespace.isNotNull() && !isRenderedCharacter(m_trailingWhite space) && m_trailingWhitespace.anchorNode()->isTextNode()) { 608 if (m_trailingWhitespace.isNotNull() && !isRenderedCharacter(m_trailingWhite space) && m_trailingWhitespace.anchorNode()->isTextNode()) {
609 Text* textNode = toText(m_trailingWhitespace.anchorNode()); 609 Text* textNode = toText(m_trailingWhitespace.anchorNode());
610 ASSERT(!textNode->layoutObject() || textNode->layoutObject()->style()->c ollapseWhiteSpace()); 610 DCHECK(!textNode->layoutObject() || textNode->layoutObject()->style()->c ollapseWhiteSpace()) << textNode;
611 replaceTextInNodePreservingMarkers(textNode, m_trailingWhitespace.comput eOffsetInContainerNode(), 1, nonBreakingSpaceString()); 611 replaceTextInNodePreservingMarkers(textNode, m_trailingWhitespace.comput eOffsetInContainerNode(), 1, nonBreakingSpaceString());
612 } 612 }
613 } 613 }
614 614
615 // If a selection starts in one block and ends in another, we have to merge to b ring content before the 615 // If a selection starts in one block and ends in another, we have to merge to b ring content before the
616 // start together with content after the end. 616 // start together with content after the end.
617 void DeleteSelectionCommand::mergeParagraphs(EditingState* editingState) 617 void DeleteSelectionCommand::mergeParagraphs(EditingState* editingState)
618 { 618 {
619 if (!m_mergeBlocksAfterDelete) { 619 if (!m_mergeBlocksAfterDelete) {
620 if (m_pruneStartBlockIfNecessary) { 620 if (m_pruneStartBlockIfNecessary) {
621 // We aren't going to merge into the start block, so remove it if it 's empty. 621 // We aren't going to merge into the start block, so remove it if it 's empty.
622 prune(m_startBlock, editingState); 622 prune(m_startBlock, editingState);
623 if (editingState->isAborted()) 623 if (editingState->isAborted())
624 return; 624 return;
625 // Removing the start block during a deletion is usually an indicati on that we need 625 // Removing the start block during a deletion is usually an indicati on that we need
626 // a placeholder, but not in this case. 626 // a placeholder, but not in this case.
627 m_needPlaceholder = false; 627 m_needPlaceholder = false;
628 } 628 }
629 return; 629 return;
630 } 630 }
631 631
632 // It shouldn't have been asked to both try and merge content into the start block and prune it. 632 // It shouldn't have been asked to both try and merge content into the start block and prune it.
633 ASSERT(!m_pruneStartBlockIfNecessary); 633 DCHECK(!m_pruneStartBlockIfNecessary);
634 634
635 // FIXME: Deletion should adjust selection endpoints as it removes nodes so that we never get into this state (4099839). 635 // FIXME: Deletion should adjust selection endpoints as it removes nodes so that we never get into this state (4099839).
636 if (!m_downstreamEnd.inShadowIncludingDocument() || !m_upstreamStart.inShado wIncludingDocument()) 636 if (!m_downstreamEnd.inShadowIncludingDocument() || !m_upstreamStart.inShado wIncludingDocument())
637 return; 637 return;
638 638
639 // FIXME: The deletion algorithm shouldn't let this happen. 639 // FIXME: The deletion algorithm shouldn't let this happen.
640 if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0) 640 if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0)
641 return; 641 return;
642 642
643 // There's nothing to merge. 643 // There's nothing to merge.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 visitor->trace(m_deleteIntoBlockquoteStyle); 963 visitor->trace(m_deleteIntoBlockquoteStyle);
964 visitor->trace(m_startRoot); 964 visitor->trace(m_startRoot);
965 visitor->trace(m_endRoot); 965 visitor->trace(m_endRoot);
966 visitor->trace(m_startTableRow); 966 visitor->trace(m_startTableRow);
967 visitor->trace(m_endTableRow); 967 visitor->trace(m_endTableRow);
968 visitor->trace(m_temporaryPlaceholder); 968 visitor->trace(m_temporaryPlaceholder);
969 CompositeEditCommand::trace(visitor); 969 CompositeEditCommand::trace(visitor);
970 } 970 }
971 971
972 } // namespace blink 972 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698