diff --git a/dom/base/DocumentOrShadowRoot.cpp b/dom/base/DocumentOrShadowRoot.cpp index f20b9dc4f74e..f992da00f5b7 100644 --- a/dom/base/DocumentOrShadowRoot.cpp +++ b/dom/base/DocumentOrShadowRoot.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "DocumentOrShadowRoot.h" +#include "mozilla/EventStateManager.h" #include "mozilla/dom/StyleSheetList.h" #include "nsDocument.h" #include "nsFocusManager.h" @@ -130,5 +131,20 @@ DocumentOrShadowRoot::GetRetargetedFocusedElement() return nullptr; } +Element* +DocumentOrShadowRoot::GetPointerLockElement() +{ + nsCOMPtr pointerLockedElement = + do_QueryReferent(EventStateManager::sPointerLockedElement); + if (!pointerLockedElement) { + return nullptr; + } + + nsIContent* retargetedPointerLockedElement = Retarget(pointerLockedElement); + return + retargetedPointerLockedElement && retargetedPointerLockedElement->IsElement() ? + retargetedPointerLockedElement->AsElement() : nullptr; +} + } } diff --git a/dom/base/DocumentOrShadowRoot.h b/dom/base/DocumentOrShadowRoot.h index f5fd7d0eb4de..f6c783085b44 100644 --- a/dom/base/DocumentOrShadowRoot.h +++ b/dom/base/DocumentOrShadowRoot.h @@ -113,6 +113,7 @@ public: ~DocumentOrShadowRoot() = default; + Element* GetPointerLockElement(); protected: nsIContent* Retarget(nsIContent* aContent) const; diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 18e0a096c1e5..131fc69d0b79 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -11640,7 +11640,7 @@ GetPointerLockError(Element* aElement, Element* aCurrentLock, return "PointerLockDeniedInUse"; } - if (!aElement->IsInUncomposedDoc()) { + if (!aElement->IsInComposedDoc()) { return "PointerLockDeniedNotInDocument"; } @@ -11691,11 +11691,11 @@ ChangePointerLockedElement(Element* aElement, nsIDocument* aDocument, MOZ_ASSERT(aDocument); MOZ_ASSERT(aElement != aPointerLockedElement); if (aPointerLockedElement) { - MOZ_ASSERT(aPointerLockedElement->GetUncomposedDoc() == aDocument); + MOZ_ASSERT(aPointerLockedElement->GetComposedDoc() == aDocument); aPointerLockedElement->ClearPointerLock(); } if (aElement) { - MOZ_ASSERT(aElement->GetUncomposedDoc() == aDocument); + MOZ_ASSERT(aElement->GetComposedDoc() == aDocument); aElement->SetPointerLock(); EventStateManager::sPointerLockedElement = do_GetWeakReference(aElement); EventStateManager::sPointerLockedDoc = do_GetWeakReference(aDocument); @@ -11719,9 +11719,9 @@ PointerLockRequest::Run() nsCOMPtr doc = do_QueryReferent(mDocument); nsDocument* d = static_cast(doc.get()); const char* error = nullptr; - if (!e || !d || !e->GetUncomposedDoc()) { + if (!e || !d || !e->GetComposedDoc()) { error = "PointerLockDeniedNotInDocument"; - } else if (e->GetUncomposedDoc() != d) { + } else if (e->GetComposedDoc() != d) { error = "PointerLockDeniedMovedDocument"; } if (!error) { @@ -11872,25 +11872,6 @@ nsIDocument::UnlockPointer(nsIDocument* aDoc) nsDocument::UnlockPointer(aDoc); } -Element* -nsIDocument::GetPointerLockElement() -{ - nsCOMPtr pointerLockedElement = - do_QueryReferent(EventStateManager::sPointerLockedElement); - if (!pointerLockedElement) { - return nullptr; - } - - // Make sure pointer locked element is in the same document. - nsCOMPtr pointerLockedDoc = - do_QueryReferent(EventStateManager::sPointerLockedDoc); - if (pointerLockedDoc != this) { - return nullptr; - } - - return pointerLockedElement; -} - void nsDocument::UpdateVisibilityState() { diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 034de076b63c..66ec6974a1ff 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -2932,7 +2932,6 @@ public: return !!GetFullscreenElement(); } void ExitFullscreen(); - Element* GetPointerLockElement(); void ExitPointerLock() { UnlockPointer(this); diff --git a/dom/tests/mochitest/pointerlock/file_pointerlock-api-with-shadow.html b/dom/tests/mochitest/pointerlock/file_pointerlock-api-with-shadow.html new file mode 100644 index 000000000000..b80a61ed112b --- /dev/null +++ b/dom/tests/mochitest/pointerlock/file_pointerlock-api-with-shadow.html @@ -0,0 +1,110 @@ + + + + + Bug 633602 + + + + + + + + Mozilla Bug 633602 + +
+
+    
+  
+ + diff --git a/dom/tests/mochitest/pointerlock/mochitest.ini b/dom/tests/mochitest/pointerlock/mochitest.ini index f332e4928d82..b5116dc1dae5 100644 --- a/dom/tests/mochitest/pointerlock/mochitest.ini +++ b/dom/tests/mochitest/pointerlock/mochitest.ini @@ -9,6 +9,7 @@ tags = fullscreen support-files = pointerlock_utils.js file_pointerlock-api.html + file_pointerlock-api-with-shadow.html file_pointerlockerror.html file_escapeKey.html file_withoutDOM.html diff --git a/dom/tests/mochitest/pointerlock/test_pointerlock-api.html b/dom/tests/mochitest/pointerlock/test_pointerlock-api.html index 3094c565e711..f7eceab6a27f 100644 --- a/dom/tests/mochitest/pointerlock/test_pointerlock-api.html +++ b/dom/tests/mochitest/pointerlock/test_pointerlock-api.html @@ -33,7 +33,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602 ["full-screen-api.unprefix.enabled", true], ["full-screen-api.allow-trusted-requests-only", false], ["full-screen-api.transition-duration.enter", "0 0"], - ["full-screen-api.transition-duration.leave", "0 0"] + ["full-screen-api.transition-duration.leave", "0 0"], + ["dom.webcomponents.shadowdom.enabled", true] ]}, nextTest); // Run the tests which go full-screen in new window, as Mochitests @@ -49,6 +50,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=633602 "file_movementXY.html", "file_nestedFullScreen.html", "file_pointerlock-api.html", + "file_pointerlock-api-with-shadow.html", "file_pointerlockerror.html", "file_pointerLockPref.html", "file_removedFromDOM.html", diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index bb9e0022b1b1..d743404a7e08 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -262,7 +262,6 @@ partial interface Document { // https://w3c.github.io/pointerlock/#extensions-to-the-document-interface // https://w3c.github.io/pointerlock/#extensions-to-the-documentorshadowroot-mixin partial interface Document { - readonly attribute Element? pointerLockElement; void exitPointerLock(); // Event handlers diff --git a/dom/webidl/DocumentOrShadowRoot.webidl b/dom/webidl/DocumentOrShadowRoot.webidl index 16388d1264f8..267f16f23b65 100644 --- a/dom/webidl/DocumentOrShadowRoot.webidl +++ b/dom/webidl/DocumentOrShadowRoot.webidl @@ -22,8 +22,7 @@ interface DocumentOrShadowRoot { readonly attribute Element? activeElement; readonly attribute StyleSheetList styleSheets; - // Not implemented yet: bug 1430303. - // readonly attribute Element? pointerLockElement; + readonly attribute Element? pointerLockElement; // Not implemented yet: bug 1430305. // readonly attribute Element? fullscreenElement; };