| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 { | 158 { |
| 159 m_scopedStyleResolver.clear(); | 159 m_scopedStyleResolver.clear(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 Element* TreeScope::getElementById(const AtomicString& elementId) const | 162 Element* TreeScope::getElementById(const AtomicString& elementId) const |
| 163 { | 163 { |
| 164 if (elementId.isEmpty()) | 164 if (elementId.isEmpty()) |
| 165 return 0; | 165 return 0; |
| 166 if (!m_elementsById) | 166 if (!m_elementsById) |
| 167 return 0; | 167 return 0; |
| 168 return m_elementsById->getElementById(elementId.impl(), this); | 168 return m_elementsById->getElementById(elementId, this); |
| 169 } | 169 } |
| 170 | 170 |
| 171 const WillBeHeapVector<RawPtrWillBeMember<Element> >& TreeScope::getAllElementsB
yId(const AtomicString& elementId) const | 171 const WillBeHeapVector<RawPtrWillBeMember<Element> >& TreeScope::getAllElementsB
yId(const AtomicString& elementId) const |
| 172 { | 172 { |
| 173 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WillBeHeapVector<RawPtrWillBeMemb
er<Element> > >, emptyVector, (adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWil
lBeMember<Element> >()))); | 173 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WillBeHeapVector<RawPtrWillBeMemb
er<Element> > >, emptyVector, (adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWil
lBeMember<Element> >()))); |
| 174 if (elementId.isEmpty()) | 174 if (elementId.isEmpty()) |
| 175 return *emptyVector; | 175 return *emptyVector; |
| 176 if (!m_elementsById) | 176 if (!m_elementsById) |
| 177 return *emptyVector; | 177 return *emptyVector; |
| 178 return m_elementsById->getAllElementsById(elementId.impl(), this); | 178 return m_elementsById->getAllElementsById(elementId, this); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void TreeScope::addElementById(const AtomicString& elementId, Element* element) | 181 void TreeScope::addElementById(const AtomicString& elementId, Element* element) |
| 182 { | 182 { |
| 183 if (!m_elementsById) | 183 if (!m_elementsById) |
| 184 m_elementsById = DocumentOrderedMap::create(); | 184 m_elementsById = DocumentOrderedMap::create(); |
| 185 m_elementsById->add(elementId.impl(), element); | 185 m_elementsById->add(elementId, element); |
| 186 m_idTargetObserverRegistry->notifyObservers(elementId); | 186 m_idTargetObserverRegistry->notifyObservers(elementId); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void TreeScope::removeElementById(const AtomicString& elementId, Element* elemen
t) | 189 void TreeScope::removeElementById(const AtomicString& elementId, Element* elemen
t) |
| 190 { | 190 { |
| 191 if (!m_elementsById) | 191 if (!m_elementsById) |
| 192 return; | 192 return; |
| 193 m_elementsById->remove(elementId.impl(), element); | 193 m_elementsById->remove(elementId, element); |
| 194 m_idTargetObserverRegistry->notifyObservers(elementId); | 194 m_idTargetObserverRegistry->notifyObservers(elementId); |
| 195 } | 195 } |
| 196 | 196 |
| 197 Node* TreeScope::ancestorInThisScope(Node* node) const | 197 Node* TreeScope::ancestorInThisScope(Node* node) const |
| 198 { | 198 { |
| 199 while (node) { | 199 while (node) { |
| 200 if (node->treeScope() == this) | 200 if (node->treeScope() == this) |
| 201 return node; | 201 return node; |
| 202 if (!node->isInShadowTree()) | 202 if (!node->isInShadowTree()) |
| 203 return 0; | 203 return 0; |
| 204 | 204 |
| 205 node = node->shadowHost(); | 205 node = node->shadowHost(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 return 0; | 208 return 0; |
| 209 } | 209 } |
| 210 | 210 |
| 211 void TreeScope::addImageMap(HTMLMapElement* imageMap) | 211 void TreeScope::addImageMap(HTMLMapElement* imageMap) |
| 212 { | 212 { |
| 213 StringImpl* name = imageMap->getName().impl(); | 213 const AtomicString& name = imageMap->getName(); |
| 214 if (!name) | 214 if (!name) |
| 215 return; | 215 return; |
| 216 if (!m_imageMapsByName) | 216 if (!m_imageMapsByName) |
| 217 m_imageMapsByName = DocumentOrderedMap::create(); | 217 m_imageMapsByName = DocumentOrderedMap::create(); |
| 218 m_imageMapsByName->add(name, imageMap); | 218 m_imageMapsByName->add(name, imageMap); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void TreeScope::removeImageMap(HTMLMapElement* imageMap) | 221 void TreeScope::removeImageMap(HTMLMapElement* imageMap) |
| 222 { | 222 { |
| 223 if (!m_imageMapsByName) | 223 if (!m_imageMapsByName) |
| 224 return; | 224 return; |
| 225 StringImpl* name = imageMap->getName().impl(); | 225 const AtomicString& name = imageMap->getName(); |
| 226 if (!name) | 226 if (!name) |
| 227 return; | 227 return; |
| 228 m_imageMapsByName->remove(name, imageMap); | 228 m_imageMapsByName->remove(name, imageMap); |
| 229 } | 229 } |
| 230 | 230 |
| 231 HTMLMapElement* TreeScope::getImageMap(const String& url) const | 231 HTMLMapElement* TreeScope::getImageMap(const String& url) const |
| 232 { | 232 { |
| 233 if (url.isNull()) | 233 if (url.isNull()) |
| 234 return 0; | 234 return 0; |
| 235 if (!m_imageMapsByName) | 235 if (!m_imageMapsByName) |
| 236 return 0; | 236 return 0; |
| 237 size_t hashPos = url.find('#'); | 237 size_t hashPos = url.find('#'); |
| 238 String name = (hashPos == kNotFound ? url : url.substring(hashPos + 1)).impl
(); | 238 String name = hashPos == kNotFound ? url : url.substring(hashPos + 1); |
| 239 if (rootNode().document().isHTMLDocument()) | 239 if (rootNode().document().isHTMLDocument()) |
| 240 return toHTMLMapElement(m_imageMapsByName->getElementByLowercasedMapName
(AtomicString(name.lower()).impl(), this)); | 240 return toHTMLMapElement(m_imageMapsByName->getElementByLowercasedMapName
(AtomicString(name.lower()), this)); |
| 241 return toHTMLMapElement(m_imageMapsByName->getElementByMapName(AtomicString(
name).impl(), this)); | 241 return toHTMLMapElement(m_imageMapsByName->getElementByMapName(AtomicString(
name), this)); |
| 242 } | 242 } |
| 243 | 243 |
| 244 HitTestResult hitTestInDocument(const Document* document, int x, int y) | 244 HitTestResult hitTestInDocument(const Document* document, int x, int y) |
| 245 { | 245 { |
| 246 LocalFrame* frame = document->frame(); | 246 LocalFrame* frame = document->frame(); |
| 247 | 247 |
| 248 if (!frame) | 248 if (!frame) |
| 249 return HitTestResult(); | 249 return HitTestResult(); |
| 250 FrameView* frameView = frame->view(); | 250 FrameView* frameView = frame->view(); |
| 251 if (!frameView) | 251 if (!frameView) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 274 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); | 274 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); |
| 275 node = ancestorInThisScope(node); | 275 node = ancestorInThisScope(node); |
| 276 if (!node || !node->isElementNode()) | 276 if (!node || !node->isElementNode()) |
| 277 return 0; | 277 return 0; |
| 278 return toElement(node); | 278 return toElement(node); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement
* element) | 281 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement
* element) |
| 282 { | 282 { |
| 283 ASSERT(m_labelsByForAttribute); | 283 ASSERT(m_labelsByForAttribute); |
| 284 m_labelsByForAttribute->add(forAttributeValue.impl(), element); | 284 m_labelsByForAttribute->add(forAttributeValue, element); |
| 285 } | 285 } |
| 286 | 286 |
| 287 void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElem
ent* element) | 287 void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElem
ent* element) |
| 288 { | 288 { |
| 289 ASSERT(m_labelsByForAttribute); | 289 ASSERT(m_labelsByForAttribute); |
| 290 m_labelsByForAttribute->remove(forAttributeValue.impl(), element); | 290 m_labelsByForAttribute->remove(forAttributeValue, element); |
| 291 } | 291 } |
| 292 | 292 |
| 293 HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeV
alue) | 293 HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeV
alue) |
| 294 { | 294 { |
| 295 if (forAttributeValue.isEmpty()) | 295 if (forAttributeValue.isEmpty()) |
| 296 return 0; | 296 return 0; |
| 297 | 297 |
| 298 if (!m_labelsByForAttribute) { | 298 if (!m_labelsByForAttribute) { |
| 299 // Populate the map on first access. | 299 // Populate the map on first access. |
| 300 m_labelsByForAttribute = DocumentOrderedMap::create(); | 300 m_labelsByForAttribute = DocumentOrderedMap::create(); |
| 301 for (HTMLLabelElement* label = Traversal<HTMLLabelElement>::firstWithin(
rootNode()); label; label = Traversal<HTMLLabelElement>::next(*label)) { | 301 for (HTMLLabelElement* label = Traversal<HTMLLabelElement>::firstWithin(
rootNode()); label; label = Traversal<HTMLLabelElement>::next(*label)) { |
| 302 const AtomicString& forValue = label->fastGetAttribute(forAttr); | 302 const AtomicString& forValue = label->fastGetAttribute(forAttr); |
| 303 if (!forValue.isEmpty()) | 303 if (!forValue.isEmpty()) |
| 304 addLabel(forValue, label); | 304 addLabel(forValue, label); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 return toHTMLLabelElement(m_labelsByForAttribute->getElementByLabelForAttrib
ute(forAttributeValue.impl(), this)); | 308 return toHTMLLabelElement(m_labelsByForAttribute->getElementByLabelForAttrib
ute(forAttributeValue, this)); |
| 309 } | 309 } |
| 310 | 310 |
| 311 DOMSelection* TreeScope::getSelection() const | 311 DOMSelection* TreeScope::getSelection() const |
| 312 { | 312 { |
| 313 if (!rootNode().document().frame()) | 313 if (!rootNode().document().frame()) |
| 314 return 0; | 314 return 0; |
| 315 | 315 |
| 316 if (m_selection) | 316 if (m_selection) |
| 317 return m_selection.get(); | 317 return m_selection.get(); |
| 318 | 318 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 visitor->trace(m_parentTreeScope); | 558 visitor->trace(m_parentTreeScope); |
| 559 visitor->trace(m_idTargetObserverRegistry); | 559 visitor->trace(m_idTargetObserverRegistry); |
| 560 visitor->trace(m_selection); | 560 visitor->trace(m_selection); |
| 561 visitor->trace(m_elementsById); | 561 visitor->trace(m_elementsById); |
| 562 visitor->trace(m_imageMapsByName); | 562 visitor->trace(m_imageMapsByName); |
| 563 visitor->trace(m_labelsByForAttribute); | 563 visitor->trace(m_labelsByForAttribute); |
| 564 visitor->trace(m_scopedStyleResolver); | 564 visitor->trace(m_scopedStyleResolver); |
| 565 } | 565 } |
| 566 | 566 |
| 567 } // namespace blink | 567 } // namespace blink |
| OLD | NEW |