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 25 matching lines...) Expand all Loading... |
36 , m_element1(first) | 36 , m_element1(first) |
37 , m_element2(second) | 37 , m_element2(second) |
38 { | 38 { |
39 DCHECK(m_element1); | 39 DCHECK(m_element1); |
40 DCHECK(m_element2); | 40 DCHECK(m_element2); |
41 DCHECK_EQ(m_element1->nextSibling(), m_element2); | 41 DCHECK_EQ(m_element1->nextSibling(), m_element2); |
42 } | 42 } |
43 | 43 |
44 void MergeIdenticalElementsCommand::doApply(EditingState*) | 44 void MergeIdenticalElementsCommand::doApply(EditingState*) |
45 { | 45 { |
46 if (m_element1->nextSibling() != m_element2 || !m_element1->hasEditableStyle
() || !m_element2->hasEditableStyle()) | 46 if (m_element1->nextSibling() != m_element2 || !hasEditableStyle(*m_element1
) || !hasEditableStyle(*m_element2)) |
47 return; | 47 return; |
48 | 48 |
49 m_atChild = m_element2->firstChild(); | 49 m_atChild = m_element2->firstChild(); |
50 | 50 |
51 NodeVector children; | 51 NodeVector children; |
52 getChildNodes(*m_element1, children); | 52 getChildNodes(*m_element1, children); |
53 | 53 |
54 for (auto& child : children) | 54 for (auto& child : children) |
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 DCHECK(m_element1); | 62 DCHECK(m_element1); |
63 DCHECK(m_element2); | 63 DCHECK(m_element2); |
64 | 64 |
65 Node* atChild = m_atChild.release(); | 65 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 || !hasEditableStyle(*parent)) |
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 HeapVector<Member<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 |