| OLD | NEW |
| 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 26 matching lines...) Expand all Loading... |
| 37 Node* firstNode, | 37 Node* firstNode, |
| 38 Node* nodeAfterLast) | 38 Node* nodeAfterLast) |
| 39 : CompositeEditCommand(document), | 39 : CompositeEditCommand(document), |
| 40 m_firstNode(firstNode), | 40 m_firstNode(firstNode), |
| 41 m_nodeAfterLast(nodeAfterLast) {} | 41 m_nodeAfterLast(nodeAfterLast) {} |
| 42 | 42 |
| 43 void SimplifyMarkupCommand::doApply(EditingState* editingState) { | 43 void SimplifyMarkupCommand::doApply(EditingState* editingState) { |
| 44 ContainerNode* rootNode = m_firstNode->parentNode(); | 44 ContainerNode* rootNode = m_firstNode->parentNode(); |
| 45 HeapVector<Member<ContainerNode>> nodesToRemove; | 45 HeapVector<Member<ContainerNode>> nodesToRemove; |
| 46 | 46 |
| 47 // Walk through the inserted nodes, to see if there are elements that could be
removed | 47 // Walk through the inserted nodes, to see if there are elements that could be |
| 48 // without affecting the style. The goal is to produce leaner markup even when
starting | 48 // removed without affecting the style. The goal is to produce leaner markup |
| 49 // from a verbose fragment. | 49 // even when starting from a verbose fragment. |
| 50 // We look at inline elements as well as non top level divs that don't have at
tributes. | 50 // We look at inline elements as well as non top level divs that don't have |
| 51 // attributes. |
| 51 for (Node* node = m_firstNode.get(); node && node != m_nodeAfterLast; | 52 for (Node* node = m_firstNode.get(); node && node != m_nodeAfterLast; |
| 52 node = NodeTraversal::next(*node)) { | 53 node = NodeTraversal::next(*node)) { |
| 53 if (node->hasChildren() || (node->isTextNode() && node->nextSibling())) | 54 if (node->hasChildren() || (node->isTextNode() && node->nextSibling())) |
| 54 continue; | 55 continue; |
| 55 | 56 |
| 56 ContainerNode* const startingNode = node->parentNode(); | 57 ContainerNode* const startingNode = node->parentNode(); |
| 57 if (!startingNode) | 58 if (!startingNode) |
| 58 continue; | 59 continue; |
| 59 const ComputedStyle* startingStyle = startingNode->computedStyle(); | 60 const ComputedStyle* startingStyle = startingNode->computedStyle(); |
| 60 if (!startingStyle) | 61 if (!startingStyle) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 89 for (Node& node : NodeTraversal::inclusiveAncestorsOf(*startingNode)) { | 90 for (Node& node : NodeTraversal::inclusiveAncestorsOf(*startingNode)) { |
| 90 if (node == topNodeWithStartingStyle) | 91 if (node == topNodeWithStartingStyle) |
| 91 break; | 92 break; |
| 92 nodesToRemove.append(static_cast<ContainerNode*>(&node)); | 93 nodesToRemove.append(static_cast<ContainerNode*>(&node)); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 // we perform all the DOM mutations at once. | 98 // we perform all the DOM mutations at once. |
| 98 for (size_t i = 0; i < nodesToRemove.size(); ++i) { | 99 for (size_t i = 0; i < nodesToRemove.size(); ++i) { |
| 99 // FIXME: We can do better by directly moving children from nodesToRemove[i]
. | 100 // FIXME: We can do better by directly moving children from |
| 101 // nodesToRemove[i]. |
| 100 int numPrunedAncestors = | 102 int numPrunedAncestors = |
| 101 pruneSubsequentAncestorsToRemove(nodesToRemove, i, editingState); | 103 pruneSubsequentAncestorsToRemove(nodesToRemove, i, editingState); |
| 102 if (editingState->isAborted()) | 104 if (editingState->isAborted()) |
| 103 return; | 105 return; |
| 104 if (numPrunedAncestors < 0) | 106 if (numPrunedAncestors < 0) |
| 105 continue; | 107 continue; |
| 106 removeNodePreservingChildren(nodesToRemove[i], editingState, | 108 removeNodePreservingChildren(nodesToRemove[i], editingState, |
| 107 AssumeContentIsAlwaysEditable); | 109 AssumeContentIsAlwaysEditable); |
| 108 if (editingState->isAborted()) | 110 if (editingState->isAborted()) |
| 109 return; | 111 return; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return pastLastNodeToRemove - startNodeIndex - 1; | 151 return pastLastNodeToRemove - startNodeIndex - 1; |
| 150 } | 152 } |
| 151 | 153 |
| 152 DEFINE_TRACE(SimplifyMarkupCommand) { | 154 DEFINE_TRACE(SimplifyMarkupCommand) { |
| 153 visitor->trace(m_firstNode); | 155 visitor->trace(m_firstNode); |
| 154 visitor->trace(m_nodeAfterLast); | 156 visitor->trace(m_nodeAfterLast); |
| 155 CompositeEditCommand::trace(visitor); | 157 CompositeEditCommand::trace(visitor); |
| 156 } | 158 } |
| 157 | 159 |
| 158 } // namespace blink | 160 } // namespace blink |
| OLD | NEW |