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

Unified Diff: WebCore/editing/ReplaceSelectionCommand.cpp

Issue 6180005: Merge 74979 - Merge 73801 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/597/
Patch Set: Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/editing/execCommand/insertHTML-mutation-crash-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: WebCore/editing/ReplaceSelectionCommand.cpp
===================================================================
--- WebCore/editing/ReplaceSelectionCommand.cpp (revision 75428)
+++ WebCore/editing/ReplaceSelectionCommand.cpp (working copy)
@@ -50,9 +50,12 @@
#include "markup.h"
#include "visible_units.h"
#include <wtf/StdLibExtras.h>
+#include <wtf/Vector.h>
namespace WebCore {
+typedef Vector<RefPtr<Node> > NodeVector;
+
using namespace HTMLNames;
enum EFragmentType { EmptyFragment, SingleTextNodeFragment, TreeFragment };
@@ -682,7 +685,12 @@
void ReplaceSelectionCommand::copyStyleToChildren(Node* parentNode, const CSSMutableStyleDeclaration* parentStyle)
{
ASSERT(parentNode->hasTagName(spanTag));
- for (Node* childNode = parentNode->firstChild(); childNode; childNode = childNode->nextSibling()) {
+ NodeVector childNodes;
+ for (RefPtr<Node> childNode = parentNode->firstChild(); childNode; childNode = childNode->nextSibling())
+ childNodes.append(childNode);
+
+ for (NodeVector::const_iterator it = childNodes.begin(); it != childNodes.end(); it++) {
+ Node* childNode = it->get();
if (childNode->isTextNode() || !isBlock(childNode) || childNode->hasTagName(preTag)) {
// In this case, put a span tag around the child node.
RefPtr<Node> newNode = parentNode->cloneNode(false);
@@ -864,6 +872,10 @@
// Inserting content could cause whitespace to collapse, e.g. inserting <div>foo</div> into hello^ world.
prepareWhitespaceAtPositionForSplit(insertionPos);
+
+ // If the downstream node has been removed there's no point in continuing.
+ if (!insertionPos.downstream().node())
+ return;
// NOTE: This would be an incorrect usage of downstream() if downstream() were changed to mean the last position after
// p that maps to the same visible position as p (since in the case where a br is at the end of a block and collapsed
@@ -942,8 +954,8 @@
bool plainTextFragment = isPlainTextMarkup(refNode.get());
while (node) {
- Node* next = node->nextSibling();
- fragment.removeNode(node);
+ RefPtr<Node> next = node->nextSibling();
+ fragment.removeNode(node.get());
insertNodeAfterAndUpdateNodesInserted(node, refNode.get());
// Mutation events (bug 22634) may have already removed the inserted content
« no previous file with comments | « LayoutTests/editing/execCommand/insertHTML-mutation-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698