Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / dom / TreeScope.h
blob08c246254c1b8fcbb01e1cd69c2a047ad7508171
1 /*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 * Copyright (C) 2012 Apple Inc. All Rights Reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef TreeScope_h
28 #define TreeScope_h
30 #include "core/CoreExport.h"
31 #include "core/dom/DocumentOrderedMap.h"
32 #include "core/layout/HitTestRequest.h"
33 #include "platform/heap/Handle.h"
34 #include "wtf/text/AtomicString.h"
36 namespace blink {
38 class ContainerNode;
39 class DOMSelection;
40 class Document;
41 class Element;
42 class HTMLLabelElement;
43 class HTMLMapElement;
44 class HitTestResult;
45 class IdTargetObserverRegistry;
46 class ScopedStyleResolver;
47 class Node;
49 // A class which inherits both Node and TreeScope must call clearRareData() in its destructor
50 // so that the Node destructor no longer does problematic NodeList cache manipulation in
51 // the destructor.
52 class CORE_EXPORT TreeScope : public WillBeGarbageCollectedMixin {
53 public:
54 TreeScope* parentTreeScope() const { return m_parentTreeScope; }
56 TreeScope* olderShadowRootOrParentTreeScope() const;
57 bool isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(const TreeScope&) const;
59 Element* adjustedFocusedElement() const;
60 Element* getElementById(const AtomicString&) const;
61 const WillBeHeapVector<RawPtrWillBeMember<Element>>& getAllElementsById(const AtomicString&) const;
62 bool hasElementWithId(const AtomicString& id) const;
63 bool containsMultipleElementsWithId(const AtomicString& id) const;
64 void addElementById(const AtomicString& elementId, Element*);
65 void removeElementById(const AtomicString& elementId, Element*);
67 Document& document() const
69 ASSERT(m_document);
70 return *m_document;
73 Node* ancestorInThisScope(Node*) const;
75 void addImageMap(HTMLMapElement*);
76 void removeImageMap(HTMLMapElement*);
77 HTMLMapElement* getImageMap(const String& url) const;
79 Element* elementFromPoint(int x, int y) const;
80 Element* hitTestPoint(int x, int y, const HitTestRequest&) const;
81 Vector<Element*> elementsFromPoint(int x, int y) const;
83 // For accessibility.
84 bool shouldCacheLabelsByForAttribute() const { return m_labelsByForAttribute; }
85 void addLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
86 void removeLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
87 HTMLLabelElement* labelElementForId(const AtomicString& forAttributeValue);
89 DOMSelection* getSelection() const;
91 // Find first anchor with the given name.
92 // First searches for an element with the given ID, but if that fails, then looks
93 // for an anchor with the given name. ID matching is always case sensitive, but
94 // Anchor name matching is case sensitive in strict mode and not case sensitive in
95 // quirks mode for historical compatibility reasons.
96 Element* findAnchor(const String& name);
98 // Used by the basic DOM mutation methods (e.g., appendChild()).
99 void adoptIfNeeded(Node&);
101 ContainerNode& rootNode() const { return *m_rootNode; }
103 IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTargetObserverRegistry.get(); }
105 #if !ENABLE(OILPAN)
106 // Nodes belonging to this scope hold guard references -
107 // these are enough to keep the scope from being destroyed, but
108 // not enough to keep it from removing its children. This allows a
109 // node that outlives its scope to still have a valid document
110 // pointer without introducing reference cycles.
111 void guardRef()
113 ASSERT(!deletionHasBegun());
114 ++m_guardRefCount;
117 void guardDeref()
119 ASSERT(m_guardRefCount > 0);
120 ASSERT(!deletionHasBegun());
121 --m_guardRefCount;
122 if (!m_guardRefCount && !refCount() && !rootNodeHasTreeSharedParent()) {
123 beginDeletion();
124 delete this;
127 #endif
129 void removedLastRefToScope();
131 bool isInclusiveAncestorOf(const TreeScope&) const;
132 unsigned short comparePosition(const TreeScope&) const;
134 const TreeScope* commonAncestorTreeScope(const TreeScope& other) const;
135 TreeScope* commonAncestorTreeScope(TreeScope& other);
137 Element* getElementByAccessKey(const String& key) const;
139 DECLARE_VIRTUAL_TRACE();
141 ScopedStyleResolver* scopedStyleResolver() const { return m_scopedStyleResolver.get(); }
142 ScopedStyleResolver& ensureScopedStyleResolver();
143 void clearScopedStyleResolver();
145 protected:
146 TreeScope(ContainerNode&, Document&);
147 TreeScope(Document&);
148 virtual ~TreeScope();
150 #if !ENABLE(OILPAN)
151 void destroyTreeScopeData();
152 #endif
154 void setDocument(Document& document) { m_document = &document; }
155 void setParentTreeScope(TreeScope&);
157 #if !ENABLE(OILPAN)
158 bool hasGuardRefCount() const { return m_guardRefCount; }
159 #endif
161 void setNeedsStyleRecalcForViewportUnits();
163 private:
164 #if !ENABLE(OILPAN)
165 virtual void dispose() { }
167 int refCount() const;
169 #if ENABLE(SECURITY_ASSERT)
170 bool deletionHasBegun();
171 void beginDeletion();
172 #else
173 bool deletionHasBegun() { return false; }
174 void beginDeletion() { }
175 #endif
176 #endif
178 bool rootNodeHasTreeSharedParent() const;
180 RawPtrWillBeMember<ContainerNode> m_rootNode;
181 RawPtrWillBeMember<Document> m_document;
182 RawPtrWillBeMember<TreeScope> m_parentTreeScope;
184 #if !ENABLE(OILPAN)
185 int m_guardRefCount;
186 #endif
188 OwnPtrWillBeMember<DocumentOrderedMap> m_elementsById;
189 OwnPtrWillBeMember<DocumentOrderedMap> m_imageMapsByName;
190 OwnPtrWillBeMember<DocumentOrderedMap> m_labelsByForAttribute;
192 OwnPtrWillBeMember<IdTargetObserverRegistry> m_idTargetObserverRegistry;
194 OwnPtrWillBeMember<ScopedStyleResolver> m_scopedStyleResolver;
196 mutable RefPtrWillBeMember<DOMSelection> m_selection;
199 inline bool TreeScope::hasElementWithId(const AtomicString& id) const
201 ASSERT(!id.isNull());
202 return m_elementsById && m_elementsById->contains(id);
205 inline bool TreeScope::containsMultipleElementsWithId(const AtomicString& id) const
207 return m_elementsById && m_elementsById->containsMultiple(id);
210 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(TreeScope)
212 HitTestResult hitTestInDocument(const Document*, int x, int y, const HitTestRequest& = HitTestRequest::ReadOnly | HitTestRequest::Active);
214 } // namespace blink
216 #endif // TreeScope_h