Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Unified Diff: Source/core/dom/TreeScope.cpp

Issue 869813003: Implement elementsFromPoint (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix typeo Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/TreeScope.cpp
diff --git a/Source/core/dom/TreeScope.cpp b/Source/core/dom/TreeScope.cpp
index 671a79cacbad3324f215f926c720e2f53d04b6a4..5c99b5954ed6e3c4df0e78627dc051afd6d85cd7 100644
--- a/Source/core/dom/TreeScope.cpp
+++ b/Source/core/dom/TreeScope.cpp
@@ -241,7 +241,7 @@ HTMLMapElement* TreeScope::getImageMap(const String& url) const
return toHTMLMapElement(m_imageMapsByName->getElementByMapName(AtomicString(name), this));
}
-HitTestResult hitTestInDocument(const Document* document, int x, int y)
+HitTestResult hitTestInDocument(const Document* document, int x, int y, HitTestRequest request)
{
LocalFrame* frame = document->frame();
@@ -257,7 +257,6 @@ HitTestResult hitTestInDocument(const Document* document, int x, int y)
if (!frameView->visibleContentRect().contains(point))
return HitTestResult();
- HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
HitTestResult result(point);
document->renderView()->hitTest(request, result);
return result;
@@ -265,7 +264,8 @@ HitTestResult hitTestInDocument(const Document* document, int x, int y)
Element* TreeScope::elementFromPoint(int x, int y) const
{
- HitTestResult result = hitTestInDocument(&rootNode().document(), x, y);
+ HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
+ HitTestResult result = hitTestInDocument(&rootNode().document(), x, y, request);
Node* node = result.innerNode();
if (!node || node->isDocumentNode())
return 0;
@@ -278,6 +278,36 @@ Element* TreeScope::elementFromPoint(int x, int y) const
return toElement(node);
}
+Vector<Element*> TreeScope::elementsFromPoint(int x, int y) const
+{
+ Vector<Element*> elements;
+
+ HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ListBased | HitTestRequest::Penetrating);
+ HitTestResult result = hitTestInDocument(&rootNode().document(), x, y, request);
+
+ Node* lastNode = nullptr;
+ for (const auto rectBasedNode : result.listBasedTestResult()) {
+ Node* node = rectBasedNode.get();
+ if (!node || !node->isElementNode() || node->isDocumentNode())
+ continue;
+
+ if (node->isPseudoElement() || node->isTextNode())
+ node = node->parentOrShadowHostNode();
+ node = ancestorInThisScope(node);
+
+ // Prune duplicate entries. A pseduo ::before content above its parent
+ // node should only result in a single entry.
Rick Byers 2015/02/04 10:34:03 are duplicate notes guaranteed to be adjacent, or
pdr. 2015/02/17 04:10:13 This is a good question. Because result.listBasedT
+ if (node == lastNode)
+ continue;
+
+ if (node && node->isElementNode()) {
+ elements.append(toElement(node));
+ lastNode = node;
+ }
+ }
+ return elements;
+}
+
void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
{
ASSERT(m_labelsByForAttribute);

Powered by Google App Engine
This is Rietveld 408576698