Bug 1284785 part 1 - Make ShouldLockPointer have internal linkage rather than being a method of nsDocument. r=smaug

MozReview-Commit-ID: 9dYVmUnTEgR

--HG--
extra : rebase_source : b8431cfbadf88657510e3d567c1de8b2768cce83
extra : source : 33a7da7c10be659ee5e804bd260e9eb884066567
This commit is contained in:
Xidorn Quan 2016-07-13 10:28:28 +10:00
Родитель 2f4c9bbf67
Коммит 5056efcb42
2 изменённых файлов: 60 добавлений и 62 удалений

Просмотреть файл

@ -12314,6 +12314,65 @@ private:
bool mUserInputOrChromeCaller;
};
static bool
ShouldLockPointer(Element* aElement, Element* aCurrentLock,
bool aNoFocusCheck = false)
{
// Check if pointer lock pref is enabled
if (!Preferences::GetBool("full-screen-api.pointer-lock.enabled")) {
NS_WARNING("ShouldLockPointer(): Pointer Lock pref not enabled");
return false;
}
nsCOMPtr<nsIDocument> ownerDoc = aElement->OwnerDoc();
if (aCurrentLock && aCurrentLock->OwnerDoc() != ownerDoc) {
NS_WARNING("ShouldLockPointer(): Existing pointer lock element in a different document");
return false;
}
if (!aElement->IsInUncomposedDoc()) {
NS_WARNING("ShouldLockPointer(): Element without Document");
return false;
}
if (ownerDoc->GetSandboxFlags() & SANDBOXED_POINTER_LOCK) {
NS_WARNING("ShouldLockPointer(): Document is sandboxed and doesn't allow pointer-lock");
return false;
}
// Check if the element is in a document with a docshell.
if (!ownerDoc->GetContainer()) {
return false;
}
nsCOMPtr<nsPIDOMWindowOuter> ownerWindow = ownerDoc->GetWindow();
if (!ownerWindow) {
return false;
}
nsCOMPtr<nsPIDOMWindowInner> ownerInnerWindow = ownerDoc->GetInnerWindow();
if (!ownerInnerWindow) {
return false;
}
if (ownerWindow->GetCurrentInnerWindow() != ownerInnerWindow) {
return false;
}
nsCOMPtr<nsPIDOMWindowOuter> top = ownerWindow->GetScriptableTop();
if (!top || !top->GetExtantDoc() || top->GetExtantDoc()->Hidden()) {
NS_WARNING("ShouldLockPointer(): Top document isn't visible.");
return false;
}
if (!aNoFocusCheck) {
mozilla::ErrorResult rv;
if (!top->GetExtantDoc()->HasFocus(rv)) {
NS_WARNING("ShouldLockPointer(): Top document isn't focused.");
return false;
}
}
return true;
}
NS_IMETHODIMP
PointerLockRequest::Run()
{
@ -12333,7 +12392,7 @@ PointerLockRequest::Run()
}
// Note, we must bypass focus change, so pass true as the last parameter!
if (!d->ShouldLockPointer(e, pointerLockedElement, true)) {
if (!ShouldLockPointer(e, pointerLockedElement, true)) {
DispatchPointerLockError(d);
return NS_OK;
}
@ -12389,65 +12448,6 @@ nsDocument::RequestPointerLock(Element* aElement)
userInputOrChromeCaller));
}
bool
nsDocument::ShouldLockPointer(Element* aElement, Element* aCurrentLock,
bool aNoFocusCheck)
{
// Check if pointer lock pref is enabled
if (!Preferences::GetBool("full-screen-api.pointer-lock.enabled")) {
NS_WARNING("ShouldLockPointer(): Pointer Lock pref not enabled");
return false;
}
if (aCurrentLock && aCurrentLock->OwnerDoc() != aElement->OwnerDoc()) {
NS_WARNING("ShouldLockPointer(): Existing pointer lock element in a different document");
return false;
}
if (!aElement->IsInUncomposedDoc()) {
NS_WARNING("ShouldLockPointer(): Element without Document");
return false;
}
if (mSandboxFlags & SANDBOXED_POINTER_LOCK) {
NS_WARNING("ShouldLockPointer(): Document is sandboxed and doesn't allow pointer-lock");
return false;
}
// Check if the element is in a document with a docshell.
nsCOMPtr<nsIDocument> ownerDoc = aElement->OwnerDoc();
if (!ownerDoc->GetContainer()) {
return false;
}
nsCOMPtr<nsPIDOMWindowOuter> ownerWindow = ownerDoc->GetWindow();
if (!ownerWindow) {
return false;
}
nsCOMPtr<nsPIDOMWindowInner> ownerInnerWindow = ownerDoc->GetInnerWindow();
if (!ownerInnerWindow) {
return false;
}
if (ownerWindow->GetCurrentInnerWindow() != ownerInnerWindow) {
return false;
}
nsCOMPtr<nsPIDOMWindowOuter> top = ownerWindow->GetScriptableTop();
if (!top || !top->GetExtantDoc() || top->GetExtantDoc()->Hidden()) {
NS_WARNING("ShouldLockPointer(): Top document isn't visible.");
return false;
}
if (!aNoFocusCheck) {
mozilla::ErrorResult rv;
if (!top->GetExtantDoc()->HasFocus(rv)) {
NS_WARNING("ShouldLockPointer(): Top document isn't focused.");
return false;
}
}
return true;
}
bool
nsDocument::SetPointerLock(Element* aElement, int aCursorStyle)
{

Просмотреть файл

@ -1268,8 +1268,6 @@ public:
Element* GetFullscreenElement() override;
void RequestPointerLock(Element* aElement) override;
bool ShouldLockPointer(Element* aElement, Element* aCurrentLock,
bool aNoFocusCheck = false);
bool SetPointerLock(Element* aElement, int aCursorStyle);
static void UnlockPointer(nsIDocument* aDoc = nullptr);