Index: Source/WebCore/dom/ContainerNodeAlgorithms.h |
=================================================================== |
--- Source/WebCore/dom/ContainerNodeAlgorithms.h (revision 128789) |
+++ Source/WebCore/dom/ContainerNodeAlgorithms.h (working copy) |
@@ -281,13 +281,37 @@ |
class ChildFrameDisconnector { |
public: |
- explicit ChildFrameDisconnector(Node* root); |
+ enum ShouldIncludeRoot { |
+ DoNotIncludeRoot, |
+ IncludeRoot |
+ }; |
+ |
+ explicit ChildFrameDisconnector(Node* root, ShouldIncludeRoot shouldIncludeRoot = IncludeRoot) |
+ : m_root(root) |
+ { |
+ collectDescendant(m_root, shouldIncludeRoot); |
+ rootNodes().add(m_root); |
+ } |
+ |
+ ~ChildFrameDisconnector() |
+ { |
+ rootNodes().remove(m_root); |
+ } |
+ |
void disconnect(); |
+ static bool nodeHasDisconnector(Node*); |
+ |
private: |
- void collectDescendant(Node* root); |
+ void collectDescendant(Node* root, ShouldIncludeRoot); |
void collectDescendant(ElementShadow*); |
+ static HashSet<Node*>& rootNodes() |
+ { |
+ DEFINE_STATIC_LOCAL(HashSet<Node*>, nodes, ()); |
+ return nodes; |
+ } |
+ |
class Target { |
public: |
Target(HTMLFrameOwnerElement* element) |
@@ -305,16 +329,13 @@ |
}; |
Vector<Target, 10> m_list; |
+ Node* m_root; |
}; |
-inline ChildFrameDisconnector::ChildFrameDisconnector(Node* root) |
+inline void ChildFrameDisconnector::collectDescendant(Node* root, ShouldIncludeRoot shouldIncludeRoot) |
{ |
- collectDescendant(root); |
-} |
- |
-inline void ChildFrameDisconnector::collectDescendant(Node* root) |
-{ |
- for (Node* node = root; node; node = node->traverseNextNode(root)) { |
+ for (Node* node = shouldIncludeRoot == IncludeRoot ? root : root->firstChild(); node; |
+ node = node->traverseNextNode(root)) { |
if (!node->isElementNode()) |
continue; |
Element* element = toElement(node); |
@@ -335,6 +356,20 @@ |
} |
} |
+inline bool ChildFrameDisconnector::nodeHasDisconnector(Node* node) |
+{ |
+ HashSet<Node*>& nodes = rootNodes(); |
+ |
+ if (nodes.isEmpty()) |
+ return false; |
+ |
+ for (; node; node = node->parentNode()) |
+ if (nodes.contains(node)) |
+ return true; |
+ |
+ return false; |
+} |
+ |
} // namespace WebCore |
#endif // ContainerNodeAlgorithms_h |