diff --git a/dom/base/nsScreen.cpp b/dom/base/nsScreen.cpp index bb1f0495a59..86d5f390496 100644 --- a/dom/base/nsScreen.cpp +++ b/dom/base/nsScreen.cpp @@ -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 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 target; + aEvent->GetCurrentTarget(getter_AddRefs(target)); + + target->RemoveSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"), + this, true); + + hal::UnlockScreenOrientation(); + + return NS_OK; +} diff --git a/dom/base/nsScreen.h b/dom/base/nsScreen.h index 85934d05fe4..90097d50d8f 100644 --- a/dom/base/nsScreen.h +++ b/dom/base/nsScreen.h @@ -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 mEventListener; + NS_DECL_EVENT_HANDLER(mozorientationchange) };