| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2008 Apple 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 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "core/editing/commands/MergeIdenticalElementsCommand.h" | 26 #include "core/editing/commands/MergeIdenticalElementsCommand.h" |
| 27 | 27 |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 MergeIdenticalElementsCommand::MergeIdenticalElementsCommand(PassRefPtrWillBeRaw
Ptr<Element> first, PassRefPtrWillBeRawPtr<Element> second) | 34 MergeIdenticalElementsCommand::MergeIdenticalElementsCommand(RawPtr<Element> fir
st, RawPtr<Element> second) |
| 35 : SimpleEditCommand(first->document()) | 35 : SimpleEditCommand(first->document()) |
| 36 , m_element1(first) | 36 , m_element1(first) |
| 37 , m_element2(second) | 37 , m_element2(second) |
| 38 { | 38 { |
| 39 ASSERT(m_element1); | 39 ASSERT(m_element1); |
| 40 ASSERT(m_element2); | 40 ASSERT(m_element2); |
| 41 ASSERT(m_element1->nextSibling() == m_element2); | 41 ASSERT(m_element1->nextSibling() == m_element2); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void MergeIdenticalElementsCommand::doApply(EditingState*) | 44 void MergeIdenticalElementsCommand::doApply(EditingState*) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 m_element2->insertBefore(child.release(), m_atChild.get(), IGNORE_EXCEPT
ION); | 55 m_element2->insertBefore(child.release(), m_atChild.get(), IGNORE_EXCEPT
ION); |
| 56 | 56 |
| 57 m_element1->remove(IGNORE_EXCEPTION); | 57 m_element1->remove(IGNORE_EXCEPTION); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void MergeIdenticalElementsCommand::doUnapply() | 60 void MergeIdenticalElementsCommand::doUnapply() |
| 61 { | 61 { |
| 62 ASSERT(m_element1); | 62 ASSERT(m_element1); |
| 63 ASSERT(m_element2); | 63 ASSERT(m_element2); |
| 64 | 64 |
| 65 RefPtrWillBeRawPtr<Node> atChild = m_atChild.release(); | 65 RawPtr<Node> atChild = m_atChild.release(); |
| 66 | 66 |
| 67 ContainerNode* parent = m_element2->parentNode(); | 67 ContainerNode* parent = m_element2->parentNode(); |
| 68 if (!parent || !parent->hasEditableStyle()) | 68 if (!parent || !parent->hasEditableStyle()) |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 TrackExceptionState exceptionState; | 71 TrackExceptionState exceptionState; |
| 72 | 72 |
| 73 parent->insertBefore(m_element1.get(), m_element2.get(), exceptionState); | 73 parent->insertBefore(m_element1.get(), m_element2.get(), exceptionState); |
| 74 if (exceptionState.hadException()) | 74 if (exceptionState.hadException()) |
| 75 return; | 75 return; |
| 76 | 76 |
| 77 WillBeHeapVector<RefPtrWillBeMember<Node>> children; | 77 HeapVector<Member<Node>> children; |
| 78 for (Node* child = m_element2->firstChild(); child && child != atChild; chil
d = child->nextSibling()) | 78 for (Node* child = m_element2->firstChild(); child && child != atChild; chil
d = child->nextSibling()) |
| 79 children.append(child); | 79 children.append(child); |
| 80 | 80 |
| 81 for (auto& child : children) | 81 for (auto& child : children) |
| 82 m_element1->appendChild(child.release(), exceptionState); | 82 m_element1->appendChild(child.release(), exceptionState); |
| 83 } | 83 } |
| 84 | 84 |
| 85 DEFINE_TRACE(MergeIdenticalElementsCommand) | 85 DEFINE_TRACE(MergeIdenticalElementsCommand) |
| 86 { | 86 { |
| 87 visitor->trace(m_element1); | 87 visitor->trace(m_element1); |
| 88 visitor->trace(m_element2); | 88 visitor->trace(m_element2); |
| 89 visitor->trace(m_atChild); | 89 visitor->trace(m_atChild); |
| 90 SimpleEditCommand::trace(visitor); | 90 SimpleEditCommand::trace(visitor); |
| 91 } | 91 } |
| 92 | 92 |
| 93 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |