| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 HeapVector<Member<ContainerNode>> nodesToRemove; | 44 HeapVector<Member<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())) |
| 52 continue; | 52 continue; |
| 53 | 53 |
| 54 ContainerNode* startingNode = node->parentNode(); | 54 ContainerNode* const startingNode = node->parentNode(); |
| 55 if (!startingNode) | 55 if (!startingNode) |
| 56 continue; | 56 continue; |
| 57 const ComputedStyle* startingStyle = startingNode->computedStyle(); | 57 const ComputedStyle* startingStyle = startingNode->computedStyle(); |
| 58 if (!startingStyle) | 58 if (!startingStyle) |
| 59 continue; | 59 continue; |
| 60 ContainerNode* currentNode = startingNode; | 60 ContainerNode* currentNode = startingNode; |
| 61 ContainerNode* topNodeWithStartingStyle = nullptr; | 61 ContainerNode* topNodeWithStartingStyle = nullptr; |
| 62 while (currentNode != rootNode) { | 62 while (currentNode != rootNode) { |
| 63 if (currentNode->parentNode() != rootNode && isRemovableBlock(curren
tNode)) | 63 if (currentNode->parentNode() != rootNode && isRemovableBlock(curren
tNode)) |
| 64 nodesToRemove.append(currentNode); | 64 nodesToRemove.append(currentNode); |
| 65 | 65 |
| 66 currentNode = currentNode->parentNode(); | 66 currentNode = currentNode->parentNode(); |
| 67 if (!currentNode) | 67 if (!currentNode) |
| 68 break; | 68 break; |
| 69 | 69 |
| 70 if (!currentNode->layoutObject() || !currentNode->layoutObject()->is
LayoutInline() || toLayoutInline(currentNode->layoutObject())->alwaysCreateLineB
oxes()) | 70 if (!currentNode->layoutObject() || !currentNode->layoutObject()->is
LayoutInline() || toLayoutInline(currentNode->layoutObject())->alwaysCreateLineB
oxes()) |
| 71 continue; | 71 continue; |
| 72 | 72 |
| 73 if (currentNode->firstChild() != currentNode->lastChild()) { | 73 if (currentNode->firstChild() != currentNode->lastChild()) { |
| 74 topNodeWithStartingStyle = 0; | 74 topNodeWithStartingStyle = 0; |
| 75 break; | 75 break; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (!currentNode->computedStyle()->visualInvalidationDiff(*startingS
tyle).hasDifference()) | 78 if (!currentNode->computedStyle()->visualInvalidationDiff(*startingS
tyle).hasDifference()) |
| 79 topNodeWithStartingStyle = currentNode; | 79 topNodeWithStartingStyle = currentNode; |
| 80 | 80 |
| 81 } | 81 } |
| 82 if (topNodeWithStartingStyle) { | 82 if (topNodeWithStartingStyle) { |
| 83 for (ContainerNode* node = startingNode; node != topNodeWithStarting
Style; node = node->parentNode()) | 83 for (Node& node : NodeTraversal::inclusiveAncestorsOf(*startingNode)
) { |
| 84 nodesToRemove.append(node); | 84 if (node == topNodeWithStartingStyle) |
| 85 break; |
| 86 nodesToRemove.append(static_cast<ContainerNode*>(&node)); |
| 87 } |
| 85 } | 88 } |
| 86 } | 89 } |
| 87 | 90 |
| 88 // we perform all the DOM mutations at once. | 91 // we perform all the DOM mutations at once. |
| 89 for (size_t i = 0; i < nodesToRemove.size(); ++i) { | 92 for (size_t i = 0; i < nodesToRemove.size(); ++i) { |
| 90 // FIXME: We can do better by directly moving children from nodesToRemov
e[i]. | 93 // FIXME: We can do better by directly moving children from nodesToRemov
e[i]. |
| 91 int numPrunedAncestors = pruneSubsequentAncestorsToRemove(nodesToRemove,
i, editingState); | 94 int numPrunedAncestors = pruneSubsequentAncestorsToRemove(nodesToRemove,
i, editingState); |
| 92 if (editingState->isAborted()) | 95 if (editingState->isAborted()) |
| 93 return; | 96 return; |
| 94 if (numPrunedAncestors < 0) | 97 if (numPrunedAncestors < 0) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 134 } |
| 132 | 135 |
| 133 DEFINE_TRACE(SimplifyMarkupCommand) | 136 DEFINE_TRACE(SimplifyMarkupCommand) |
| 134 { | 137 { |
| 135 visitor->trace(m_firstNode); | 138 visitor->trace(m_firstNode); |
| 136 visitor->trace(m_nodeAfterLast); | 139 visitor->trace(m_nodeAfterLast); |
| 137 CompositeEditCommand::trace(visitor); | 140 CompositeEditCommand::trace(visitor); |
| 138 } | 141 } |
| 139 | 142 |
| 140 } // namespace blink | 143 } // namespace blink |
| OLD | NEW |