| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 Element* TreeScope::getElementById(const AtomicString& elementId) const | 161 Element* TreeScope::getElementById(const AtomicString& elementId) const |
| 162 { | 162 { |
| 163 if (elementId.isEmpty()) | 163 if (elementId.isEmpty()) |
| 164 return 0; | 164 return 0; |
| 165 if (!m_elementsById) | 165 if (!m_elementsById) |
| 166 return 0; | 166 return 0; |
| 167 return m_elementsById->getElementById(elementId, this); | 167 return m_elementsById->getElementById(elementId, this); |
| 168 } | 168 } |
| 169 | 169 |
| 170 const WillBeHeapVector<RawPtrWillBeMember<Element>>& TreeScope::getAllElementsBy
Id(const AtomicString& elementId) const | 170 const HeapVector<Member<Element>>& TreeScope::getAllElementsById(const AtomicStr
ing& elementId) const |
| 171 { | 171 { |
| 172 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<WillBeHeapVector<RawPtrWillBeMemb
er<Element>>>, emptyVector, (adoptPtrWillBeNoop(new WillBeHeapVector<RawPtrWillB
eMember<Element>>()))); | 172 DEFINE_STATIC_LOCAL(Persistent<HeapVector<Member<Element>>>, emptyVector, ((
new HeapVector<Member<Element>>()))); |
| 173 if (elementId.isEmpty()) | 173 if (elementId.isEmpty()) |
| 174 return *emptyVector; | 174 return *emptyVector; |
| 175 if (!m_elementsById) | 175 if (!m_elementsById) |
| 176 return *emptyVector; | 176 return *emptyVector; |
| 177 return m_elementsById->getAllElementsById(elementId, this); | 177 return m_elementsById->getAllElementsById(elementId, this); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void TreeScope::addElementById(const AtomicString& elementId, Element* element) | 180 void TreeScope::addElementById(const AtomicString& elementId, Element* element) |
| 181 { | 181 { |
| 182 if (!m_elementsById) | 182 if (!m_elementsById) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 return 0; | 286 return 0; |
| 287 if (node->isPseudoElement() || node->isTextNode()) | 287 if (node->isPseudoElement() || node->isTextNode()) |
| 288 node = node->parentOrShadowHostNode(); | 288 node = node->parentOrShadowHostNode(); |
| 289 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); | 289 ASSERT(!node || node->isElementNode() || node->isShadowRoot()); |
| 290 node = ancestorInThisScope(node); | 290 node = ancestorInThisScope(node); |
| 291 if (!node || !node->isElementNode()) | 291 if (!node || !node->isElementNode()) |
| 292 return 0; | 292 return 0; |
| 293 return toElement(node); | 293 return toElement(node); |
| 294 } | 294 } |
| 295 | 295 |
| 296 WillBeHeapVector<RawPtrWillBeMember<Element>> TreeScope::elementsFromHitTestResu
lt(HitTestResult& result) const | 296 HeapVector<Member<Element>> TreeScope::elementsFromHitTestResult(HitTestResult&
result) const |
| 297 { | 297 { |
| 298 WillBeHeapVector<RawPtrWillBeMember<Element>> elements; | 298 HeapVector<Member<Element>> elements; |
| 299 | 299 |
| 300 Node* lastNode = nullptr; | 300 Node* lastNode = nullptr; |
| 301 for (const auto rectBasedNode : result.listBasedTestResult()) { | 301 for (const auto rectBasedNode : result.listBasedTestResult()) { |
| 302 Node* node = rectBasedNode.get(); | 302 Node* node = rectBasedNode.get(); |
| 303 if (!node || !node->isElementNode() || node->isDocumentNode()) | 303 if (!node || !node->isElementNode() || node->isDocumentNode()) |
| 304 continue; | 304 continue; |
| 305 | 305 |
| 306 if (node->isPseudoElement() || node->isTextNode()) | 306 if (node->isPseudoElement() || node->isTextNode()) |
| 307 node = node->parentOrShadowHostNode(); | 307 node = node->parentOrShadowHostNode(); |
| 308 node = ancestorInThisScope(node); | 308 node = ancestorInThisScope(node); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 321 if (rootNode().isDocumentNode()) { | 321 if (rootNode().isDocumentNode()) { |
| 322 if (Element* rootElement = toDocument(rootNode()).documentElement()) { | 322 if (Element* rootElement = toDocument(rootNode()).documentElement()) { |
| 323 if (elements.isEmpty() || elements.last() != rootElement) | 323 if (elements.isEmpty() || elements.last() != rootElement) |
| 324 elements.append(rootElement); | 324 elements.append(rootElement); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 return elements; | 328 return elements; |
| 329 } | 329 } |
| 330 | 330 |
| 331 WillBeHeapVector<RawPtrWillBeMember<Element>> TreeScope::elementsFromPoint(int x
, int y) const | 331 HeapVector<Member<Element>> TreeScope::elementsFromPoint(int x, int y) const |
| 332 { | 332 { |
| 333 Document& document = rootNode().document(); | 333 Document& document = rootNode().document(); |
| 334 IntPoint hitPoint(x, y); | 334 IntPoint hitPoint(x, y); |
| 335 if (!pointWithScrollAndZoomIfPossible(document, hitPoint)) | 335 if (!pointWithScrollAndZoomIfPossible(document, hitPoint)) |
| 336 return WillBeHeapVector<RawPtrWillBeMember<Element>>(); | 336 return HeapVector<Member<Element>>(); |
| 337 | 337 |
| 338 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H
itTestRequest::ListBased | HitTestRequest::PenetratingList); | 338 HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | H
itTestRequest::ListBased | HitTestRequest::PenetratingList); |
| 339 HitTestResult result(request, hitPoint); | 339 HitTestResult result(request, hitPoint); |
| 340 document.layoutView()->hitTest(result); | 340 document.layoutView()->hitTest(result); |
| 341 | 341 |
| 342 return elementsFromHitTestResult(result); | 342 return elementsFromHitTestResult(result); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement
* element) | 345 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement
* element) |
| 346 { | 346 { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 421 |
| 422 Element* TreeScope::adjustedFocusedElement() const | 422 Element* TreeScope::adjustedFocusedElement() const |
| 423 { | 423 { |
| 424 Document& document = rootNode().document(); | 424 Document& document = rootNode().document(); |
| 425 Element* element = document.focusedElement(); | 425 Element* element = document.focusedElement(); |
| 426 if (!element && document.page()) | 426 if (!element && document.page()) |
| 427 element = document.page()->focusController().focusedFrameOwnerElement(*d
ocument.frame()); | 427 element = document.page()->focusController().focusedFrameOwnerElement(*d
ocument.frame()); |
| 428 if (!element) | 428 if (!element) |
| 429 return 0; | 429 return 0; |
| 430 | 430 |
| 431 OwnPtrWillBeRawPtr<EventPath> eventPath = adoptPtrWillBeNoop(new EventPath(*
element)); | 431 RawPtr<EventPath> eventPath = (new EventPath(*element)); |
| 432 for (size_t i = 0; i < eventPath->size(); ++i) { | 432 for (size_t i = 0; i < eventPath->size(); ++i) { |
| 433 if (eventPath->at(i).node() == rootNode()) { | 433 if (eventPath->at(i).node() == rootNode()) { |
| 434 // eventPath->at(i).target() is one of the followings: | 434 // eventPath->at(i).target() is one of the followings: |
| 435 // - InsertionPoint | 435 // - InsertionPoint |
| 436 // - shadow host | 436 // - shadow host |
| 437 // - Document::focusedElement() | 437 // - Document::focusedElement() |
| 438 // So, it's safe to do toElement(). | 438 // So, it's safe to do toElement(). |
| 439 return toElement(eventPath->at(i).target()->toNode()); | 439 return toElement(eventPath->at(i).target()->toNode()); |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 return 0; | 442 return 0; |
| 443 } | 443 } |
| 444 | 444 |
| 445 unsigned short TreeScope::comparePosition(const TreeScope& otherScope) const | 445 unsigned short TreeScope::comparePosition(const TreeScope& otherScope) const |
| 446 { | 446 { |
| 447 if (otherScope == this) | 447 if (otherScope == this) |
| 448 return Node::DOCUMENT_POSITION_EQUIVALENT; | 448 return Node::DOCUMENT_POSITION_EQUIVALENT; |
| 449 | 449 |
| 450 WillBeHeapVector<RawPtrWillBeMember<const TreeScope>, 16> chain1; | 450 HeapVector<Member<const TreeScope>, 16> chain1; |
| 451 WillBeHeapVector<RawPtrWillBeMember<const TreeScope>, 16> chain2; | 451 HeapVector<Member<const TreeScope>, 16> chain2; |
| 452 const TreeScope* current; | 452 const TreeScope* current; |
| 453 for (current = this; current; current = current->parentTreeScope()) | 453 for (current = this; current; current = current->parentTreeScope()) |
| 454 chain1.append(current); | 454 chain1.append(current); |
| 455 for (current = &otherScope; current; current = current->parentTreeScope()) | 455 for (current = &otherScope; current; current = current->parentTreeScope()) |
| 456 chain2.append(current); | 456 chain2.append(current); |
| 457 | 457 |
| 458 unsigned index1 = chain1.size(); | 458 unsigned index1 = chain1.size(); |
| 459 unsigned index2 = chain2.size(); | 459 unsigned index2 = chain2.size(); |
| 460 if (chain1[index1 - 1] != chain2[index2 - 1]) | 460 if (chain1[index1 - 1] != chain2[index2 - 1]) |
| 461 return Node::DOCUMENT_POSITION_DISCONNECTED | Node::DOCUMENT_POSITION_IM
PLEMENTATION_SPECIFIC; | 461 return Node::DOCUMENT_POSITION_DISCONNECTED | Node::DOCUMENT_POSITION_IM
PLEMENTATION_SPECIFIC; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 480 | 480 |
| 481 // There was no difference between the two parent chains, i.e., one was a su
bset of the other. The shorter | 481 // There was no difference between the two parent chains, i.e., one was a su
bset of the other. The shorter |
| 482 // chain is the ancestor. | 482 // chain is the ancestor. |
| 483 return index1 < index2 ? | 483 return index1 < index2 ? |
| 484 Node::DOCUMENT_POSITION_FOLLOWING | Node::DOCUMENT_POSITION_CONTAINED_BY
: | 484 Node::DOCUMENT_POSITION_FOLLOWING | Node::DOCUMENT_POSITION_CONTAINED_BY
: |
| 485 Node::DOCUMENT_POSITION_PRECEDING | Node::DOCUMENT_POSITION_CONTAINS; | 485 Node::DOCUMENT_POSITION_PRECEDING | Node::DOCUMENT_POSITION_CONTAINS; |
| 486 } | 486 } |
| 487 | 487 |
| 488 const TreeScope* TreeScope::commonAncestorTreeScope(const TreeScope& other) cons
t | 488 const TreeScope* TreeScope::commonAncestorTreeScope(const TreeScope& other) cons
t |
| 489 { | 489 { |
| 490 WillBeHeapVector<RawPtrWillBeMember<const TreeScope>, 16> thisChain; | 490 HeapVector<Member<const TreeScope>, 16> thisChain; |
| 491 for (const TreeScope* tree = this; tree; tree = tree->parentTreeScope()) | 491 for (const TreeScope* tree = this; tree; tree = tree->parentTreeScope()) |
| 492 thisChain.append(tree); | 492 thisChain.append(tree); |
| 493 | 493 |
| 494 WillBeHeapVector<RawPtrWillBeMember<const TreeScope>, 16> otherChain; | 494 HeapVector<Member<const TreeScope>, 16> otherChain; |
| 495 for (const TreeScope* tree = &other; tree; tree = tree->parentTreeScope()) | 495 for (const TreeScope* tree = &other; tree; tree = tree->parentTreeScope()) |
| 496 otherChain.append(tree); | 496 otherChain.append(tree); |
| 497 | 497 |
| 498 // Keep popping out the last elements of these chains until a mismatched pai
r is found. If |this| and |other| | 498 // Keep popping out the last elements of these chains until a mismatched pai
r is found. If |this| and |other| |
| 499 // belong to different documents, null will be returned. | 499 // belong to different documents, null will be returned. |
| 500 const TreeScope* lastAncestor = nullptr; | 500 const TreeScope* lastAncestor = nullptr; |
| 501 while (!thisChain.isEmpty() && !otherChain.isEmpty() && thisChain.last() ==
otherChain.last()) { | 501 while (!thisChain.isEmpty() && !otherChain.isEmpty() && thisChain.last() ==
otherChain.last()) { |
| 502 lastAncestor = thisChain.last(); | 502 lastAncestor = thisChain.last(); |
| 503 thisChain.removeLast(); | 503 thisChain.removeLast(); |
| 504 otherChain.removeLast(); | 504 otherChain.removeLast(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 visitor->trace(m_parentTreeScope); | 574 visitor->trace(m_parentTreeScope); |
| 575 visitor->trace(m_idTargetObserverRegistry); | 575 visitor->trace(m_idTargetObserverRegistry); |
| 576 visitor->trace(m_selection); | 576 visitor->trace(m_selection); |
| 577 visitor->trace(m_elementsById); | 577 visitor->trace(m_elementsById); |
| 578 visitor->trace(m_imageMapsByName); | 578 visitor->trace(m_imageMapsByName); |
| 579 visitor->trace(m_labelsByForAttribute); | 579 visitor->trace(m_labelsByForAttribute); |
| 580 visitor->trace(m_scopedStyleResolver); | 580 visitor->trace(m_scopedStyleResolver); |
| 581 } | 581 } |
| 582 | 582 |
| 583 } // namespace blink | 583 } // namespace blink |
| OLD | NEW |