Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 class ContainerNode; | 37 class ContainerNode; |
| 38 class DOMSelection; | 38 class DOMSelection; |
| 39 class Document; | 39 class Document; |
| 40 class Element; | 40 class Element; |
| 41 class HTMLLabelElement; | 41 class HTMLLabelElement; |
| 42 class HTMLMapElement; | 42 class HTMLMapElement; |
| 43 class HitTestResult; | 43 class HitTestResult; |
| 44 class HitTestRequest; | 44 class HitTestRequest; |
| 45 class IdTargetObserverRegistry; | 45 class IdTargetObserverRegistry; |
| 46 class Node; | |
| 46 class ScopedStyleResolver; | 47 class ScopedStyleResolver; |
| 47 class Node; | 48 class TreeScopeStyleSheetCollection; |
| 48 | 49 |
| 49 // A class which inherits both Node and TreeScope must call clearRareData() in i ts destructor | 50 // A class which inherits both Node and TreeScope must call clearRareData() in i ts destructor |
| 50 // so that the Node destructor no longer does problematic NodeList cache manipul ation in | 51 // so that the Node destructor no longer does problematic NodeList cache manipul ation in |
| 51 // the destructor. | 52 // the destructor. |
| 52 class CORE_EXPORT TreeScope : public WillBeGarbageCollectedMixin { | 53 class CORE_EXPORT TreeScope : public WillBeGarbageCollectedMixin { |
| 53 public: | 54 public: |
| 54 TreeScope* parentTreeScope() const { return m_parentTreeScope; } | 55 TreeScope* parentTreeScope() const { return m_parentTreeScope; } |
| 55 | 56 |
| 56 TreeScope* olderShadowRootOrParentTreeScope() const; | 57 TreeScope* olderShadowRootOrParentTreeScope() const; |
| 57 bool isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(const TreeScope& ) const; | 58 bool isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(const TreeScope& ) const; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 TreeScope* commonAncestorTreeScope(TreeScope& other); | 135 TreeScope* commonAncestorTreeScope(TreeScope& other); |
| 135 | 136 |
| 136 Element* getElementByAccessKey(const String& key) const; | 137 Element* getElementByAccessKey(const String& key) const; |
| 137 | 138 |
| 138 DECLARE_VIRTUAL_TRACE(); | 139 DECLARE_VIRTUAL_TRACE(); |
| 139 | 140 |
| 140 ScopedStyleResolver* scopedStyleResolver() const { return m_scopedStyleResol ver.get(); } | 141 ScopedStyleResolver* scopedStyleResolver() const { return m_scopedStyleResol ver.get(); } |
| 141 ScopedStyleResolver& ensureScopedStyleResolver(); | 142 ScopedStyleResolver& ensureScopedStyleResolver(); |
| 142 void clearScopedStyleResolver(); | 143 void clearScopedStyleResolver(); |
| 143 | 144 |
| 145 TreeScopeStyleSheetCollection* styleSheetCollection(); | |
| 146 | |
| 147 typedef WillBeHeapHashSet<RawPtrWillBeMember<TreeScope>> UnorderedTreeScopeS et; | |
| 148 | |
| 149 // A class which holds document-ordered treescopes which have stylesheets. | |
| 150 // ListHashSet allows only sequential access, not random access. | |
| 151 // So it gets slow when the size of treescopes gets larger when finding | |
| 152 // the best place to insert a treescope into the document-ordered | |
| 153 // treescopes (requires linear search). | |
| 154 // To solve this, use a vector for the document-ordered treescopes and | |
| 155 // use a hashset for quickly checking whether a given treescope is | |
| 156 // in the document-ordered treescopes or not. | |
| 157 class OrderedTreeScopeSet final { | |
| 158 DISALLOW_ALLOCATION(); | |
| 159 WTF_MAKE_NONCOPYABLE(OrderedTreeScopeSet); | |
| 160 public: | |
| 161 OrderedTreeScopeSet() { } | |
| 162 | |
| 163 bool insert(TreeScope*); | |
| 164 bool remove(TreeScope*); | |
| 165 | |
| 166 // When we don't need to consider document-order, use this iterator. | |
| 167 // Otherwise, use [] operator. | |
| 168 UnorderedTreeScopeSet& unordered() { return m_hash; } | |
| 169 | |
| 170 bool isEmpty() const { return m_treeScopes.isEmpty(); } | |
| 171 void clear() | |
| 172 { | |
| 173 m_treeScopes.clear(); | |
| 174 m_hash.clear(); | |
| 175 } | |
| 176 | |
| 177 size_t size() const { return m_treeScopes.size(); } | |
| 178 | |
| 179 TreeScope* operator[](size_t i) { return m_treeScopes[i]; } | |
| 180 const TreeScope* operator[](size_t i) const { return m_treeScopes[i]; } | |
| 181 | |
| 182 typedef WillBeHeapVector<RawPtrWillBeMember<TreeScope>, 16>::iterator it erator; | |
| 183 iterator begin() { return m_treeScopes.begin(); } | |
| 184 iterator end() { return m_treeScopes.end(); } | |
| 185 | |
| 186 DECLARE_TRACE(); | |
| 187 | |
| 188 private: | |
| 189 WillBeHeapVector<RawPtrWillBeMember<TreeScope>, 16> m_treeScopes; | |
| 190 UnorderedTreeScopeSet m_hash; | |
| 191 }; | |
| 192 | |
| 193 class TreeScopesWithActiveStyleSheetsTraversal final { | |
| 194 DISALLOW_ALLOCATION(); | |
| 195 WTF_MAKE_NONCOPYABLE(TreeScopesWithActiveStyleSheetsTraversal); | |
| 196 public: | |
| 197 TreeScopesWithActiveStyleSheetsTraversal(TreeScope&); | |
| 198 TreeScopesWithActiveStyleSheetsTraversal(OrderedTreeScopeSet&); | |
| 199 | |
| 200 class iterator { | |
| 201 public: | |
| 202 iterator(TreeScopesWithActiveStyleSheetsTraversal& traversal) : m_tr aversal(traversal) { } | |
| 203 iterator(const iterator& iterator) : m_traversal(iterator.m_traversa l) { } | |
| 204 | |
| 205 TreeScope* operator*() { return m_traversal.m_current; } | |
| 206 void operator++() { m_traversal.nextWithStyleSheetCollection(); } | |
| 207 bool operator!=(const iterator& other) const { return m_traversal.m_ current; } | |
| 208 | |
| 209 private: | |
| 210 TreeScopesWithActiveStyleSheetsTraversal& m_traversal; | |
| 211 }; | |
| 212 | |
| 213 iterator begin() { return iterator(*this); } | |
| 214 iterator end() { return iterator(*this); } | |
|
kochi
2015/05/26 01:52:34
Why begin() and end() are same?
kojii
2015/05/26 05:21:58
end() is not really used, as operator!=() can dete
| |
| 215 | |
| 216 DECLARE_TRACE(); | |
| 217 | |
| 218 private: | |
| 219 void skipIfNoStyleSheetCollection(); | |
| 220 void nextWithStyleSheetCollection(); | |
| 221 void next(); | |
| 222 | |
| 223 RawPtrWillBeMember<TreeScope> m_current; | |
| 224 OrderedTreeScopeSet::iterator m_iterator; | |
| 225 OrderedTreeScopeSet::iterator m_end; | |
| 226 WillBeHeapVector<std::pair<OrderedTreeScopeSet::iterator, OrderedTreeSco peSet::iterator>, 8> m_stack; | |
| 227 }; | |
| 228 | |
| 229 bool isInActiveStyleSheetsTraversal() const { return m_inActiveStyleSheetsTr aversal; } | |
| 230 OrderedTreeScopeSet& childTreeScopesWithActiveStyleSheets() { return m_child TreeScopesWithActiveStyleSheets; } | |
| 231 bool hasChildTreeScopesWithActiveStyleSheets() const { return !m_childTreeSc opesWithActiveStyleSheets.isEmpty(); } | |
| 232 void insertToActiveStyleSheetsTraversal(); | |
| 233 void removeFromActiveStyleSheetsTraversal(); | |
| 234 | |
| 144 protected: | 235 protected: |
| 145 TreeScope(ContainerNode&, Document&); | 236 TreeScope(ContainerNode&, Document&); |
| 146 TreeScope(Document&); | 237 TreeScope(Document&); |
| 147 virtual ~TreeScope(); | 238 virtual ~TreeScope(); |
| 148 | 239 |
| 149 #if !ENABLE(OILPAN) | 240 #if !ENABLE(OILPAN) |
| 150 void destroyTreeScopeData(); | 241 void destroyTreeScopeData(); |
| 151 #endif | 242 #endif |
| 152 | 243 |
| 153 void setDocument(Document& document) { m_document = &document; } | 244 void setDocument(Document& document) { m_document = &document; } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 184 int m_guardRefCount; | 275 int m_guardRefCount; |
| 185 #endif | 276 #endif |
| 186 | 277 |
| 187 OwnPtrWillBeMember<DocumentOrderedMap> m_elementsById; | 278 OwnPtrWillBeMember<DocumentOrderedMap> m_elementsById; |
| 188 OwnPtrWillBeMember<DocumentOrderedMap> m_imageMapsByName; | 279 OwnPtrWillBeMember<DocumentOrderedMap> m_imageMapsByName; |
| 189 OwnPtrWillBeMember<DocumentOrderedMap> m_labelsByForAttribute; | 280 OwnPtrWillBeMember<DocumentOrderedMap> m_labelsByForAttribute; |
| 190 | 281 |
| 191 OwnPtrWillBeMember<IdTargetObserverRegistry> m_idTargetObserverRegistry; | 282 OwnPtrWillBeMember<IdTargetObserverRegistry> m_idTargetObserverRegistry; |
| 192 | 283 |
| 193 OwnPtrWillBeMember<ScopedStyleResolver> m_scopedStyleResolver; | 284 OwnPtrWillBeMember<ScopedStyleResolver> m_scopedStyleResolver; |
| 285 OrderedTreeScopeSet m_childTreeScopesWithActiveStyleSheets; | |
| 194 | 286 |
| 195 mutable RefPtrWillBeMember<DOMSelection> m_selection; | 287 mutable RefPtrWillBeMember<DOMSelection> m_selection; |
| 288 | |
| 289 bool m_inActiveStyleSheetsTraversal : 1; | |
|
kochi
2015/05/26 01:52:34
Not necessary to be a bitfield for one boolean.
kojii
2015/05/26 05:21:58
Done.
| |
| 196 }; | 290 }; |
| 197 | 291 |
| 198 inline bool TreeScope::hasElementWithId(const AtomicString& id) const | 292 inline bool TreeScope::hasElementWithId(const AtomicString& id) const |
| 199 { | 293 { |
| 200 ASSERT(!id.isNull()); | 294 ASSERT(!id.isNull()); |
| 201 return m_elementsById && m_elementsById->contains(id); | 295 return m_elementsById && m_elementsById->contains(id); |
| 202 } | 296 } |
| 203 | 297 |
| 204 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) co nst | 298 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) co nst |
| 205 { | 299 { |
| 206 return m_elementsById && m_elementsById->containsMultiple(id); | 300 return m_elementsById && m_elementsById->containsMultiple(id); |
| 207 } | 301 } |
| 208 | 302 |
| 209 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(TreeScope) | 303 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(TreeScope) |
| 210 | 304 |
| 211 HitTestResult hitTestInDocument(const Document*, int x, int y); | 305 HitTestResult hitTestInDocument(const Document*, int x, int y); |
| 212 | 306 |
| 213 } // namespace blink | 307 } // namespace blink |
| 214 | 308 |
| 215 #endif // TreeScope_h | 309 #endif // TreeScope_h |
| OLD | NEW |