From b0bc11783bff87a941b2556345964a511d52148d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 24 Dec 2018 12:33:22 +0000 Subject: [PATCH] Bug 1513658 - Implement DocumentOrShadowRoot.node(s)FromPoint. r=smaug ChromeOnly for now, needs tests that I'll make sure to land with. Differential Revision: https://phabricator.services.mozilla.com/D14360 --HG-- extra : moz-landing-system : lando --- dom/base/DocumentOrShadowRoot.cpp | 12 ++ dom/base/DocumentOrShadowRoot.h | 12 +- dom/tests/mochitest/chrome/chrome.ini | 1 + .../mochitest/chrome/test_nodesFromPoint.html | 119 ++++++++++++++++++ dom/webidl/DocumentOrShadowRoot.webidl | 12 +- 5 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 dom/tests/mochitest/chrome/test_nodesFromPoint.html diff --git a/dom/base/DocumentOrShadowRoot.cpp b/dom/base/DocumentOrShadowRoot.cpp index 2196205f10fe..21f9874b82ad 100644 --- a/dom/base/DocumentOrShadowRoot.cpp +++ b/dom/base/DocumentOrShadowRoot.cpp @@ -330,6 +330,18 @@ void DocumentOrShadowRoot::ElementsFromPoint( aElements); } +void DocumentOrShadowRoot::NodesFromPoint(float aX, float aY, + nsTArray>& aNodes) { + QueryNodesFromPoint(*this, aX, aY, {}, FlushLayout::Yes, Multiple::Yes, + aNodes); +} + +nsINode* DocumentOrShadowRoot::NodeFromPoint(float aX, float aY) { + AutoTArray, 1> nodes; + QueryNodesFromPoint(*this, aX, aY, {}, FlushLayout::Yes, Multiple::No, nodes); + return nodes.SafeElementAt(0); +} + Element* DocumentOrShadowRoot::ElementFromPointHelper( float aX, float aY, bool aIgnoreRootScrollFrame, bool aFlushLayout) { EnumSet options; diff --git a/dom/base/DocumentOrShadowRoot.h b/dom/base/DocumentOrShadowRoot.h index 6b47041b0ec9..f916ce87e929 100644 --- a/dom/base/DocumentOrShadowRoot.h +++ b/dom/base/DocumentOrShadowRoot.h @@ -48,7 +48,7 @@ class DocumentOrShadowRoot { public: explicit DocumentOrShadowRoot(nsIDocument&); - explicit DocumentOrShadowRoot(mozilla::dom::ShadowRoot&); + explicit DocumentOrShadowRoot(ShadowRoot&); // Unusual argument naming is because of cycle collection macros. static void Traverse(DocumentOrShadowRoot* tmp, @@ -103,8 +103,10 @@ class DocumentOrShadowRoot { Element* GetFullscreenElement(); Element* ElementFromPoint(float aX, float aY); - void ElementsFromPoint(float aX, float aY, - nsTArray>& aElements); + nsINode* NodeFromPoint(float aX, float aY); + + void ElementsFromPoint(float aX, float aY, nsTArray>&); + void NodesFromPoint(float aX, float aY, nsTArray>&); /** * Helper for elementFromPoint implementation that allows @@ -214,8 +216,8 @@ class DocumentOrShadowRoot { */ Element* GetRetargetedFocusedElement(); - nsTArray> mStyleSheets; - RefPtr mDOMStyleSheets; + nsTArray> mStyleSheets; + RefPtr mDOMStyleSheets; /* * mIdentifierMap works as follows for IDs: diff --git a/dom/tests/mochitest/chrome/chrome.ini b/dom/tests/mochitest/chrome/chrome.ini index 7a85a584a536..32f897743ce6 100644 --- a/dom/tests/mochitest/chrome/chrome.ini +++ b/dom/tests/mochitest/chrome/chrome.ini @@ -75,6 +75,7 @@ skip-if = os == 'linux' tags = fullscreen # disabled on OS X for intermittent failures--bug-798848 skip-if = toolkit == 'cocoa' +[test_nodesFromPoint.html] [test_nodesFromRect.html] [test_parsingMode.html] [test_popup_blocker_chrome.xul] diff --git a/dom/tests/mochitest/chrome/test_nodesFromPoint.html b/dom/tests/mochitest/chrome/test_nodesFromPoint.html new file mode 100644 index 000000000000..30675a41dd2e --- /dev/null +++ b/dom/tests/mochitest/chrome/test_nodesFromPoint.html @@ -0,0 +1,119 @@ + + + + +
+ diff --git a/dom/webidl/DocumentOrShadowRoot.webidl b/dom/webidl/DocumentOrShadowRoot.webidl index 8a288f6151cc..99d2aa996f60 100644 --- a/dom/webidl/DocumentOrShadowRoot.webidl +++ b/dom/webidl/DocumentOrShadowRoot.webidl @@ -12,8 +12,16 @@ interface DocumentOrShadowRoot { // Not implemented yet: bug 1430308. // Selection? getSelection(); - Element? elementFromPoint (float x, float y); - sequence elementsFromPoint (float x, float y); + Element? elementFromPoint(float x, float y); + sequence elementsFromPoint(float x, float y); + + // TODO: Avoid making these ChromeOnly, see: + // https://github.com/w3c/csswg-drafts/issues/556 + [ChromeOnly] + Node? nodeFromPoint(float x, float y); + [ChromeOnly] + sequence nodesFromPoint(float x, float y); + // Not implemented yet: bug 1430307. // CaretPosition? caretPositionFromPoint (float x, float y);