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

Side by Side Diff: Source/core/editing/ReplaceSelectionCommand.cpp

Issue 149213006: Replace ASSERT by null-check in InsertedNodes::lastLeafInserted() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add layout test Created 6 years, 10 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
« no previous file with comments | « Source/core/editing/ReplaceSelectionCommand.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010, 2011 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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 658
659 static inline bool nodeHasVisibleRenderText(Text& text) 659 static inline bool nodeHasVisibleRenderText(Text& text)
660 { 660 {
661 return text.renderer() && toRenderText(text.renderer())->renderedTextLength( ) > 0; 661 return text.renderer() && toRenderText(text.renderer())->renderedTextLength( ) > 0;
662 } 662 }
663 663
664 void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& ins ertedNodes) 664 void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& ins ertedNodes)
665 { 665 {
666 document().updateLayoutIgnorePendingStylesheets(); 666 document().updateLayoutIgnorePendingStylesheets();
667 667
668 Node& lastLeafInserted = insertedNodes.lastLeafInserted(); 668 Node* lastLeafInserted = insertedNodes.lastLeafInserted();
669 if (lastLeafInserted.isTextNode() && !nodeHasVisibleRenderText(toText(lastLe afInserted)) 669 if (lastLeafInserted && lastLeafInserted->isTextNode() && !nodeHasVisibleRen derText(toText(*lastLeafInserted))
670 && !enclosingNodeWithTag(firstPositionInOrBeforeNode(&lastLeafInserted), selectTag) 670 && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), selectTag)
671 && !enclosingNodeWithTag(firstPositionInOrBeforeNode(&lastLeafInserted), scriptTag)) { 671 && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), scriptTag)) {
672 insertedNodes.willRemoveNode(lastLeafInserted); 672 insertedNodes.willRemoveNode(*lastLeafInserted);
673 removeNode(&lastLeafInserted); 673 removeNode(lastLeafInserted);
674 } 674 }
675 675
676 // We don't have to make sure that firstNodeInserted isn't inside a select o r script element, because 676 // We don't have to make sure that firstNodeInserted isn't inside a select o r script element, because
677 // it is a top level node in the fragment and the user can't insert into tho se elements. 677 // it is a top level node in the fragment and the user can't insert into tho se elements.
678 Node* firstNodeInserted = insertedNodes.firstNodeInserted(); 678 Node* firstNodeInserted = insertedNodes.firstNodeInserted();
679 if (firstNodeInserted && firstNodeInserted->isTextNode() && !nodeHasVisibleR enderText(toText(*firstNodeInserted))) { 679 if (firstNodeInserted && firstNodeInserted->isTextNode() && !nodeHasVisibleR enderText(toText(*firstNodeInserted))) {
680 insertedNodes.willRemoveNode(*firstNodeInserted); 680 insertedNodes.willRemoveNode(*firstNodeInserted);
681 removeNode(firstNodeInserted); 681 removeNode(firstNodeInserted);
682 } 682 }
683 } 683 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 1136
1137 makeInsertedContentRoundTrippableWithHTMLTreeBuilder(insertedNodes); 1137 makeInsertedContentRoundTrippableWithHTMLTreeBuilder(insertedNodes);
1138 1138
1139 removeRedundantStylesAndKeepStyleSpanInline(insertedNodes); 1139 removeRedundantStylesAndKeepStyleSpanInline(insertedNodes);
1140 1140
1141 if (m_sanitizeFragment) 1141 if (m_sanitizeFragment)
1142 applyCommandToComposite(SimplifyMarkupCommand::create(document(), insert edNodes.firstNodeInserted(), insertedNodes.pastLastLeaf())); 1142 applyCommandToComposite(SimplifyMarkupCommand::create(document(), insert edNodes.firstNodeInserted(), insertedNodes.pastLastLeaf()));
1143 1143
1144 // Setup m_startOfInsertedContent and m_endOfInsertedContent. This should be the last two lines of code that access insertedNodes. 1144 // Setup m_startOfInsertedContent and m_endOfInsertedContent. This should be the last two lines of code that access insertedNodes.
1145 m_startOfInsertedContent = firstPositionInOrBeforeNode(insertedNodes.firstNo deInserted()); 1145 m_startOfInsertedContent = firstPositionInOrBeforeNode(insertedNodes.firstNo deInserted());
1146 m_endOfInsertedContent = lastPositionInOrAfterNode(&insertedNodes.lastLeafIn serted()); 1146 m_endOfInsertedContent = lastPositionInOrAfterNode(insertedNodes.lastLeafIns erted());
1147 1147
1148 // Determine whether or not we should merge the end of inserted content with what's after it before we do 1148 // Determine whether or not we should merge the end of inserted content with what's after it before we do
1149 // the start merge so that the start merge doesn't effect our decision. 1149 // the start merge so that the start merge doesn't effect our decision.
1150 m_shouldMergeEnd = shouldMergeEnd(selectionEndWasEndOfParagraph); 1150 m_shouldMergeEnd = shouldMergeEnd(selectionEndWasEndOfParagraph);
1151 1151
1152 if (shouldMergeStart(selectionStartWasStartOfParagraph, fragment.hasIntercha ngeNewlineAtStart(), startIsInsideMailBlockquote)) { 1152 if (shouldMergeStart(selectionStartWasStartOfParagraph, fragment.hasIntercha ngeNewlineAtStart(), startIsInsideMailBlockquote)) {
1153 VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedConten t(); 1153 VisiblePosition startOfParagraphToMove = positionAtStartOfInsertedConten t();
1154 VisiblePosition destination = startOfParagraphToMove.previous(); 1154 VisiblePosition destination = startOfParagraphToMove.previous();
1155 // We need to handle the case where we need to merge the end 1155 // We need to handle the case where we need to merge the end
1156 // but our destination node is inside an inline that is the last in the block. 1156 // but our destination node is inside an inline that is the last in the block.
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get()); 1493 removeNodeAndPruneAncestors(nodeAfterInsertionPos.get());
1494 1494
1495 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en d); 1495 VisibleSelection selectionAfterReplace(m_selectReplacement ? start : end, en d);
1496 1496
1497 setEndingSelection(selectionAfterReplace); 1497 setEndingSelection(selectionAfterReplace);
1498 1498
1499 return true; 1499 return true;
1500 } 1500 }
1501 1501
1502 } // namespace WebCore 1502 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/ReplaceSelectionCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698