diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index ce0398fb3bc..4b4cd5034f8 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -13676,6 +13676,14 @@ nsGlobalWindow::BeginWindowMove(Event& aMouseDownEvent, Element* aPanel, aError = widget->BeginMoveDrag(mouseEvent); } +already_AddRefed +nsGlobalWindow::GetWindowRoot(mozilla::ErrorResult& aError) +{ + FORWARD_TO_OUTER_OR_THROW(GetWindowRoot, (aError), aError, nullptr); + nsCOMPtr root = GetTopWindowRoot(); + return root.forget().downcast(); +} + //Note: This call will lock the cursor, it will not change as it moves. //To unlock, the cursor must be set back to CURSOR_AUTO. NS_IMETHODIMP diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index d2667de6f3b..58485263d28 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -1098,6 +1098,8 @@ public: JS::MutableHandle aRetval, mozilla::ErrorResult& aError); + already_AddRefed GetWindowRoot(mozilla::ErrorResult& aError); + protected: // Web IDL helpers diff --git a/dom/base/test/chrome/chrome.ini b/dom/base/test/chrome/chrome.ini index ddc21944202..df4d5985f40 100644 --- a/dom/base/test/chrome/chrome.ini +++ b/dom/base/test/chrome/chrome.ini @@ -70,3 +70,4 @@ skip-if = buildapp == 'mulet' [test_fileconstructor_tempfile.xul] [test_nsITextInputProcessor.xul] [test_title.xul] +[test_windowroot.xul] diff --git a/dom/base/test/chrome/test_windowroot.xul b/dom/base/test/chrome/test_windowroot.xul new file mode 100644 index 00000000000..c9ff7f0b50b --- /dev/null +++ b/dom/base/test/chrome/test_windowroot.xul @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index 7ef06ad92e0..e3350bcf0ed 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -401,6 +401,12 @@ partial interface Window { [ChromeOnly, Throws] readonly attribute object? __content; [Throws, ChromeOnly] any getInterface(IID iid); + + /** + * Same as nsIDOMWindow.windowRoot, useful for event listener targeting. + */ + [ChromeOnly, Throws] + readonly attribute WindowRoot? windowRoot; }; Window implements TouchEventHandlers;