Bug 740188 - Screen Orientation API locking (3/3): revert orientation when fullscreen is left. r=smaug

This commit is contained in:
Mounir Lamouri 2012-03-29 09:31:11 -07:00
Родитель 818512952b
Коммит 5018a9ca0b
2 изменённых файлов: 48 добавлений и 0 удалений

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

@ -112,6 +112,7 @@ nsScreen::Create(nsPIDOMWindow* aWindow)
}
nsScreen::nsScreen()
: mEventListener(nsnull)
{
}
@ -471,6 +472,19 @@ nsScreen::MozLockOrientation(const nsAString& aOrientation, bool* aReturn)
*aReturn = false;
return NS_OK;
}
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(GetOwner());
if (!target) {
*aReturn = false;
return NS_OK;
}
if (!mEventListener) {
mEventListener = new FullScreenEventListener();
}
target->AddSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
mEventListener, true);
}
*aReturn = hal::LockScreenOrientation(orientation);
@ -483,3 +497,26 @@ nsScreen::MozUnlockOrientation()
hal::UnlockScreenOrientation();
return NS_OK;
}
NS_IMPL_ISUPPORTS1(nsScreen::FullScreenEventListener, nsIDOMEventListener)
NS_IMETHODIMP
nsScreen::FullScreenEventListener::HandleEvent(nsIDOMEvent* aEvent)
{
#ifdef DEBUG
nsAutoString eventType;
aEvent->GetType(eventType);
MOZ_ASSERT(eventType.EqualsLiteral("mozfullscreenchange"));
#endif
nsCOMPtr<nsIDOMEventTarget> target;
aEvent->GetCurrentTarget(getter_AddRefs(target));
target->RemoveSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
this, true);
hal::UnlockScreenOrientation();
return NS_OK;
}

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

@ -79,6 +79,15 @@ protected:
mozilla::dom::ScreenOrientation mOrientation;
private:
class FullScreenEventListener : public nsIDOMEventListener
{
public:
FullScreenEventListener() {};
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTLISTENER
};
nsScreen();
virtual ~nsScreen();
@ -90,6 +99,8 @@ private:
bool IsWhiteListed();
nsRefPtr<FullScreenEventListener> mEventListener;
NS_DECL_EVENT_HANDLER(mozorientationchange)
};