1 | /* |
2 | * Copyright (C) 2007, 2015 Apple Inc. All rights reserved. |
3 | * (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | * |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include "ContainerNode.h" |
25 | #include <wtf/Assertions.h> |
26 | |
27 | namespace WebCore { |
28 | |
29 | // FIXME: Delete this class after fixing FormAssociatedElement to avoid calling getElementById during a tree removal. |
30 | #if !ASSERT_DISABLED |
31 | class ContainerChildRemovalScope { |
32 | public: |
33 | ContainerChildRemovalScope(ContainerNode& parentOfRemovedTree, Node& child) |
34 | : m_parentOfRemovedTree(parentOfRemovedTree) |
35 | , m_removedChild(child) |
36 | , m_previousScope(s_scope) |
37 | { |
38 | s_scope = this; |
39 | } |
40 | |
41 | ~ContainerChildRemovalScope() |
42 | { |
43 | s_scope = m_previousScope; |
44 | } |
45 | |
46 | ContainerNode& parentOfRemovedTree() { return m_parentOfRemovedTree; } |
47 | Node& removedChild() { return m_removedChild; } |
48 | |
49 | static ContainerChildRemovalScope* currentScope() { return s_scope; } |
50 | |
51 | private: |
52 | ContainerNode& m_parentOfRemovedTree; |
53 | Node& m_removedChild; |
54 | ContainerChildRemovalScope* m_previousScope; |
55 | static ContainerChildRemovalScope* s_scope; |
56 | }; |
57 | #else |
58 | class ContainerChildRemovalScope { |
59 | public: |
60 | ContainerChildRemovalScope(ContainerNode&, Node&) { } |
61 | }; |
62 | #endif |
63 | |
64 | NodeVector notifyChildNodeInserted(ContainerNode& parentOfInsertedTree, Node&); |
65 | void notifyChildNodeRemoved(ContainerNode& oldParentOfRemovedTree, Node&); |
66 | void removeDetachedChildrenInContainer(ContainerNode&); |
67 | |
68 | enum SubframeDisconnectPolicy { |
69 | RootAndDescendants, |
70 | DescendantsOnly |
71 | }; |
72 | void disconnectSubframes(ContainerNode& root, SubframeDisconnectPolicy); |
73 | |
74 | inline void disconnectSubframesIfNeeded(ContainerNode& root, SubframeDisconnectPolicy policy) |
75 | { |
76 | if (!root.connectedSubframeCount()) |
77 | return; |
78 | disconnectSubframes(root, policy); |
79 | } |
80 | |
81 | } // namespace WebCore |
82 | |