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

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

Issue 1703903002: Editing: Remove unreasonable ASSERT_NO_EDITING_ABORT instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « third_party/WebKit/Source/core/editing/commands/SimplifyMarkupCommand.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) 2012 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2012 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 20 matching lines...) Expand all
31 #include "core/layout/LayoutObject.h" 31 #include "core/layout/LayoutObject.h"
32 #include "core/style/ComputedStyle.h" 32 #include "core/style/ComputedStyle.h"
33 33
34 namespace blink { 34 namespace blink {
35 35
36 SimplifyMarkupCommand::SimplifyMarkupCommand(Document& document, Node* firstNode , Node* nodeAfterLast) 36 SimplifyMarkupCommand::SimplifyMarkupCommand(Document& document, Node* firstNode , Node* nodeAfterLast)
37 : CompositeEditCommand(document), m_firstNode(firstNode), m_nodeAfterLast(no deAfterLast) 37 : CompositeEditCommand(document), m_firstNode(firstNode), m_nodeAfterLast(no deAfterLast)
38 { 38 {
39 } 39 }
40 40
41 void SimplifyMarkupCommand::doApply(EditingState*) 41 void SimplifyMarkupCommand::doApply(EditingState* editingState)
42 { 42 {
43 ContainerNode* rootNode = m_firstNode->parentNode(); 43 ContainerNode* rootNode = m_firstNode->parentNode();
44 WillBeHeapVector<RefPtrWillBeMember<ContainerNode>> nodesToRemove; 44 WillBeHeapVector<RefPtrWillBeMember<ContainerNode>> nodesToRemove;
45 45
46 // Walk through the inserted nodes, to see if there are elements that could be removed 46 // Walk through the inserted nodes, to see if there are elements that could be removed
47 // without affecting the style. The goal is to produce leaner markup even wh en starting 47 // without affecting the style. The goal is to produce leaner markup even wh en starting
48 // from a verbose fragment. 48 // from a verbose fragment.
49 // We look at inline elements as well as non top level divs that don't have attributes. 49 // We look at inline elements as well as non top level divs that don't have attributes.
50 for (Node* node = m_firstNode.get(); node && node != m_nodeAfterLast; node = NodeTraversal::next(*node)) { 50 for (Node* node = m_firstNode.get(); node && node != m_nodeAfterLast; node = NodeTraversal::next(*node)) {
51 if (node->hasChildren() || (node->isTextNode() && node->nextSibling())) 51 if (node->hasChildren() || (node->isTextNode() && node->nextSibling()))
(...skipping 29 matching lines...) Expand all
81 } 81 }
82 if (topNodeWithStartingStyle) { 82 if (topNodeWithStartingStyle) {
83 for (ContainerNode* node = startingNode; node != topNodeWithStarting Style; node = node->parentNode()) 83 for (ContainerNode* node = startingNode; node != topNodeWithStarting Style; node = node->parentNode())
84 nodesToRemove.append(node); 84 nodesToRemove.append(node);
85 } 85 }
86 } 86 }
87 87
88 // we perform all the DOM mutations at once. 88 // we perform all the DOM mutations at once.
89 for (size_t i = 0; i < nodesToRemove.size(); ++i) { 89 for (size_t i = 0; i < nodesToRemove.size(); ++i) {
90 // FIXME: We can do better by directly moving children from nodesToRemov e[i]. 90 // FIXME: We can do better by directly moving children from nodesToRemov e[i].
91 int numPrunedAncestors = pruneSubsequentAncestorsToRemove(nodesToRemove, i); 91 int numPrunedAncestors = pruneSubsequentAncestorsToRemove(nodesToRemove, i, editingState);
92 if (editingState->isAborted())
93 return;
92 if (numPrunedAncestors < 0) 94 if (numPrunedAncestors < 0)
93 continue; 95 continue;
94 removeNodePreservingChildren(nodesToRemove[i], ASSERT_NO_EDITING_ABORT, AssumeContentIsAlwaysEditable); 96 removeNodePreservingChildren(nodesToRemove[i], editingState, AssumeConte ntIsAlwaysEditable);
97 if (editingState->isAborted())
98 return;
95 i += numPrunedAncestors; 99 i += numPrunedAncestors;
96 } 100 }
97 } 101 }
98 102
99 int SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove(WillBeHeapVector<Ref PtrWillBeMember<ContainerNode>>& nodesToRemove, size_t startNodeIndex) 103 int SimplifyMarkupCommand::pruneSubsequentAncestorsToRemove(WillBeHeapVector<Ref PtrWillBeMember<ContainerNode>>& nodesToRemove, size_t startNodeIndex, EditingSt ate* editingState)
100 { 104 {
101 size_t pastLastNodeToRemove = startNodeIndex + 1; 105 size_t pastLastNodeToRemove = startNodeIndex + 1;
102 for (; pastLastNodeToRemove < nodesToRemove.size(); ++pastLastNodeToRemove) { 106 for (; pastLastNodeToRemove < nodesToRemove.size(); ++pastLastNodeToRemove) {
103 if (nodesToRemove[pastLastNodeToRemove - 1]->parentNode() != nodesToRemo ve[pastLastNodeToRemove]) 107 if (nodesToRemove[pastLastNodeToRemove - 1]->parentNode() != nodesToRemo ve[pastLastNodeToRemove])
104 break; 108 break;
105 ASSERT(nodesToRemove[pastLastNodeToRemove]->firstChild() == nodesToRemov e[pastLastNodeToRemove]->lastChild()); 109 ASSERT(nodesToRemove[pastLastNodeToRemove]->firstChild() == nodesToRemov e[pastLastNodeToRemove]->lastChild());
106 } 110 }
107 111
108 ContainerNode* highestAncestorToRemove = nodesToRemove[pastLastNodeToRemove - 1].get(); 112 ContainerNode* highestAncestorToRemove = nodesToRemove[pastLastNodeToRemove - 1].get();
109 RefPtrWillBeRawPtr<ContainerNode> parent = highestAncestorToRemove->parentNo de(); 113 RefPtrWillBeRawPtr<ContainerNode> parent = highestAncestorToRemove->parentNo de();
110 if (!parent) // Parent has already been removed. 114 if (!parent) // Parent has already been removed.
111 return -1; 115 return -1;
112 116
113 if (pastLastNodeToRemove == startNodeIndex + 1) 117 if (pastLastNodeToRemove == startNodeIndex + 1)
114 return 0; 118 return 0;
115 119
116 removeNode(nodesToRemove[startNodeIndex], ASSERT_NO_EDITING_ABORT, AssumeCon tentIsAlwaysEditable); 120 removeNode(nodesToRemove[startNodeIndex], editingState, AssumeContentIsAlway sEditable);
117 insertNodeBefore(nodesToRemove[startNodeIndex], highestAncestorToRemove, ASS ERT_NO_EDITING_ABORT, AssumeContentIsAlwaysEditable); 121 if (editingState->isAborted())
118 removeNode(highestAncestorToRemove, ASSERT_NO_EDITING_ABORT, AssumeContentIs AlwaysEditable); 122 return -1;
123 insertNodeBefore(nodesToRemove[startNodeIndex], highestAncestorToRemove, edi tingState, AssumeContentIsAlwaysEditable);
124 if (editingState->isAborted())
125 return -1;
126 removeNode(highestAncestorToRemove, editingState, AssumeContentIsAlwaysEdita ble);
127 if (editingState->isAborted())
128 return -1;
119 129
120 return pastLastNodeToRemove - startNodeIndex - 1; 130 return pastLastNodeToRemove - startNodeIndex - 1;
121 } 131 }
122 132
123 DEFINE_TRACE(SimplifyMarkupCommand) 133 DEFINE_TRACE(SimplifyMarkupCommand)
124 { 134 {
125 visitor->trace(m_firstNode); 135 visitor->trace(m_firstNode);
126 visitor->trace(m_nodeAfterLast); 136 visitor->trace(m_nodeAfterLast);
127 CompositeEditCommand::trace(visitor); 137 CompositeEditCommand::trace(visitor);
128 } 138 }
129 139
130 } // namespace blink 140 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/SimplifyMarkupCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698