OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. |
3 * Copyright (C) 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2012 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "TreeScopeAdopter.h" | 52 #include "TreeScopeAdopter.h" |
53 #include <wtf/Vector.h> | 53 #include <wtf/Vector.h> |
54 #include <wtf/text/AtomicString.h> | 54 #include <wtf/text/AtomicString.h> |
55 #include <wtf/text/CString.h> | 55 #include <wtf/text/CString.h> |
56 | 56 |
57 namespace WebCore { | 57 namespace WebCore { |
58 | 58 |
59 struct SameSizeAsTreeScope { | 59 struct SameSizeAsTreeScope { |
60 virtual ~SameSizeAsTreeScope(); | 60 virtual ~SameSizeAsTreeScope(); |
61 void* pointers[8]; | 61 void* pointers[8]; |
| 62 int ints[1]; |
62 }; | 63 }; |
63 | 64 |
64 COMPILE_ASSERT(sizeof(TreeScope) == sizeof(SameSizeAsTreeScope), treescope_shoul
d_stay_small); | 65 COMPILE_ASSERT(sizeof(TreeScope) == sizeof(SameSizeAsTreeScope), treescope_shoul
d_stay_small); |
65 | 66 |
66 using namespace HTMLNames; | 67 using namespace HTMLNames; |
67 | 68 |
68 TreeScope::TreeScope(ContainerNode* rootNode, Document* document) | 69 TreeScope::TreeScope(ContainerNode* rootNode, Document* document) |
69 : m_rootNode(rootNode) | 70 : m_rootNode(rootNode) |
70 , m_documentScope(document) | 71 , m_documentScope(document) |
71 , m_parentTreeScope(document) | 72 , m_parentTreeScope(document) |
| 73 , m_guardRefCount(0) |
72 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) | 74 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) |
73 { | 75 { |
74 ASSERT(rootNode); | 76 ASSERT(rootNode); |
75 ASSERT(document); | 77 ASSERT(document); |
76 ASSERT(rootNode != document); | 78 ASSERT(rootNode != document); |
| 79 m_parentTreeScope->guardRef(); |
| 80 m_rootNode->setTreeScope(this); |
77 } | 81 } |
78 | 82 |
79 TreeScope::TreeScope(Document* document) | 83 TreeScope::TreeScope(Document* document) |
80 : m_rootNode(document) | 84 : m_rootNode(document) |
81 , m_documentScope(document) | 85 , m_documentScope(document) |
82 , m_parentTreeScope(0) | 86 , m_parentTreeScope(0) |
| 87 , m_guardRefCount(0) |
83 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) | 88 , m_idTargetObserverRegistry(IdTargetObserverRegistry::create()) |
84 { | 89 { |
85 ASSERT(document); | 90 ASSERT(document); |
| 91 m_rootNode->setTreeScope(this); |
86 } | 92 } |
87 | 93 |
88 TreeScope::TreeScope() | 94 TreeScope::TreeScope() |
89 : m_rootNode(0) | 95 : m_rootNode(0) |
90 , m_documentScope(0) | 96 , m_documentScope(0) |
91 , m_parentTreeScope(0) | 97 , m_parentTreeScope(0) |
| 98 , m_guardRefCount(0) |
92 { | 99 { |
93 } | 100 } |
94 | 101 |
95 TreeScope::~TreeScope() | 102 TreeScope::~TreeScope() |
96 { | 103 { |
| 104 ASSERT(!m_guardRefCount); |
| 105 m_rootNode->setTreeScope(noDocumentInstance()); |
| 106 |
97 if (m_selection) { | 107 if (m_selection) { |
98 m_selection->clearTreeScope(); | 108 m_selection->clearTreeScope(); |
99 m_selection = 0; | 109 m_selection = 0; |
100 } | 110 } |
| 111 |
| 112 if (m_parentTreeScope) |
| 113 m_parentTreeScope->guardDeref(); |
101 } | 114 } |
102 | 115 |
103 void TreeScope::destroyTreeScopeData() | 116 void TreeScope::destroyTreeScopeData() |
104 { | 117 { |
105 m_elementsById.clear(); | 118 m_elementsById.clear(); |
106 m_imageMapsByName.clear(); | 119 m_imageMapsByName.clear(); |
107 m_labelsByForAttribute.clear(); | 120 m_labelsByForAttribute.clear(); |
108 } | 121 } |
109 | 122 |
110 void TreeScope::clearDocumentScope() | 123 void TreeScope::clearDocumentScope() |
111 { | 124 { |
112 ASSERT(rootNode()->isDocumentNode()); | 125 ASSERT(rootNode()->isDocumentNode()); |
113 m_documentScope = 0; | 126 m_documentScope = 0; |
114 } | 127 } |
115 | 128 |
116 void TreeScope::setParentTreeScope(TreeScope* newParentScope) | 129 void TreeScope::setParentTreeScope(TreeScope* newParentScope) |
117 { | 130 { |
118 // A document node cannot be re-parented. | 131 // A document node cannot be re-parented. |
119 ASSERT(!rootNode()->isDocumentNode()); | 132 ASSERT(!rootNode()->isDocumentNode()); |
120 // Every scope other than document needs a parent scope. | 133 // Every scope other than document needs a parent scope. |
121 ASSERT(newParentScope); | 134 ASSERT(newParentScope); |
122 | 135 |
| 136 newParentScope->guardRef(); |
| 137 if (m_parentTreeScope) |
| 138 m_parentTreeScope->guardDeref(); |
123 m_parentTreeScope = newParentScope; | 139 m_parentTreeScope = newParentScope; |
124 setDocumentScope(newParentScope->documentScope()); | 140 setDocumentScope(newParentScope->documentScope()); |
125 } | 141 } |
126 | 142 |
127 Element* TreeScope::getElementById(const AtomicString& elementId) const | 143 Element* TreeScope::getElementById(const AtomicString& elementId) const |
128 { | 144 { |
129 if (elementId.isEmpty()) | 145 if (elementId.isEmpty()) |
130 return 0; | 146 return 0; |
131 if (!m_elementsById) | 147 if (!m_elementsById) |
132 return 0; | 148 return 0; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 listTreeScopes(nodeB, treeScopesB); | 424 listTreeScopes(nodeB, treeScopesB); |
409 | 425 |
410 size_t indexA = treeScopesA.size(); | 426 size_t indexA = treeScopesA.size(); |
411 size_t indexB = treeScopesB.size(); | 427 size_t indexB = treeScopesB.size(); |
412 | 428 |
413 for (; indexA > 0 && indexB > 0 && treeScopesA[indexA - 1] == treeScopesB[in
dexB - 1]; --indexA, --indexB) { } | 429 for (; indexA > 0 && indexB > 0 && treeScopesA[indexA - 1] == treeScopesB[in
dexB - 1]; --indexA, --indexB) { } |
414 | 430 |
415 return treeScopesA[indexA] == treeScopesB[indexB] ? treeScopesA[indexA] : 0; | 431 return treeScopesA[indexA] == treeScopesB[indexB] ? treeScopesA[indexA] : 0; |
416 } | 432 } |
417 | 433 |
| 434 #ifndef NDEBUG |
| 435 bool TreeScope::deletionHasBegun() |
| 436 { |
| 437 return rootNode() && rootNode()->m_deletionHasBegun; |
| 438 } |
| 439 |
| 440 void TreeScope::beginDeletion() |
| 441 { |
| 442 ASSERT(this != noDocumentInstance()); |
| 443 rootNode()->m_deletionHasBegun = true; |
| 444 } |
| 445 #endif |
| 446 |
| 447 int TreeScope::refCount() const |
| 448 { |
| 449 if (Node* root = rootNode()) |
| 450 return root->refCount(); |
| 451 return 0; |
| 452 } |
| 453 |
418 } // namespace WebCore | 454 } // namespace WebCore |
OLD | NEW |