| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2009 Google Inc. All rights reserved. | 2 * Copyright (c) 2009 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 HTMLElement& elementToReplace) { | 51 HTMLElement& elementToReplace) { |
| 52 DCHECK(elementToReplace.isConnected()) << elementToReplace; | 52 DCHECK(elementToReplace.isConnected()) << elementToReplace; |
| 53 ContainerNode* parentNode = elementToReplace.parentNode(); | 53 ContainerNode* parentNode = elementToReplace.parentNode(); |
| 54 parentNode->insertBefore(newElement, &elementToReplace); | 54 parentNode->insertBefore(newElement, &elementToReplace); |
| 55 | 55 |
| 56 NodeVector children; | 56 NodeVector children; |
| 57 getChildNodes(elementToReplace, children); | 57 getChildNodes(elementToReplace, children); |
| 58 for (const auto& child : children) | 58 for (const auto& child : children) |
| 59 newElement->appendChild(child); | 59 newElement->appendChild(child); |
| 60 | 60 |
| 61 // FIXME: Fix this to send the proper MutationRecords when MutationObservers a
re present. | 61 // FIXME: Fix this to send the proper MutationRecords when MutationObservers |
| 62 // are present. |
| 62 newElement->cloneDataFromElement(elementToReplace); | 63 newElement->cloneDataFromElement(elementToReplace); |
| 63 | 64 |
| 64 parentNode->removeChild(&elementToReplace, ASSERT_NO_EXCEPTION); | 65 parentNode->removeChild(&elementToReplace, ASSERT_NO_EXCEPTION); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void ReplaceNodeWithSpanCommand::doApply(EditingState*) { | 68 void ReplaceNodeWithSpanCommand::doApply(EditingState*) { |
| 68 if (!m_elementToReplace->isConnected()) | 69 if (!m_elementToReplace->isConnected()) |
| 69 return; | 70 return; |
| 70 if (!m_spanElement) | 71 if (!m_spanElement) |
| 71 m_spanElement = HTMLSpanElement::create(m_elementToReplace->document()); | 72 m_spanElement = HTMLSpanElement::create(m_elementToReplace->document()); |
| 72 swapInNodePreservingAttributesAndChildren(m_spanElement.get(), | 73 swapInNodePreservingAttributesAndChildren(m_spanElement.get(), |
| 73 *m_elementToReplace); | 74 *m_elementToReplace); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void ReplaceNodeWithSpanCommand::doUnapply() { | 77 void ReplaceNodeWithSpanCommand::doUnapply() { |
| 77 if (!m_spanElement->isConnected()) | 78 if (!m_spanElement->isConnected()) |
| 78 return; | 79 return; |
| 79 swapInNodePreservingAttributesAndChildren(m_elementToReplace.get(), | 80 swapInNodePreservingAttributesAndChildren(m_elementToReplace.get(), |
| 80 *m_spanElement); | 81 *m_spanElement); |
| 81 } | 82 } |
| 82 | 83 |
| 83 DEFINE_TRACE(ReplaceNodeWithSpanCommand) { | 84 DEFINE_TRACE(ReplaceNodeWithSpanCommand) { |
| 84 visitor->trace(m_elementToReplace); | 85 visitor->trace(m_elementToReplace); |
| 85 visitor->trace(m_spanElement); | 86 visitor->trace(m_spanElement); |
| 86 SimpleEditCommand::trace(visitor); | 87 SimpleEditCommand::trace(visitor); |
| 87 } | 88 } |
| 88 | 89 |
| 89 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |