const AtomicString& ScreenOrientation::orientation(Screen* screen) { ScreenOrientation* screenOrientation = ScreenOrientation::from(screen); ScreenOrientationController* controller = ScreenOrientationController::from(screenOrientation->document()); ASSERT(controller); return orientationToString(controller->orientation()); }
NS_IMETHODIMP ScreenOrientation::VisibleEventListener::HandleEvent(nsIDOMEvent* aEvent) { // Document may have become visible, if the page is visible, run the steps // following the "now visible algorithm" as specified. nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetCurrentTarget(); MOZ_ASSERT(target); nsCOMPtr<nsIDocument> doc = do_QueryInterface(target); if (!doc || doc->Hidden()) { return NS_OK; } auto* win = nsGlobalWindow::Cast(doc->GetInnerWindow()); if (!win) { return NS_OK; } ErrorResult rv; nsScreen* screen = win->GetScreen(rv); if (NS_WARN_IF(rv.Failed())) { return rv.StealNSResult(); } MOZ_ASSERT(screen); ScreenOrientation* orientation = screen->Orientation(); MOZ_ASSERT(orientation); rv = target->RemoveSystemEventListener(NS_LITERAL_STRING("visibilitychange"), this, true); if (NS_WARN_IF(rv.Failed())) { return rv.StealNSResult(); } if (doc->CurrentOrientationType() != orientation->DeviceType(CallerType::System)) { doc->SetCurrentOrientation(orientation->DeviceType(CallerType::System), orientation->DeviceAngle(CallerType::System)); Promise* pendingPromise = doc->GetOrientationPendingPromise(); if (pendingPromise) { pendingPromise->MaybeResolveWithUndefined(); doc->SetOrientationPendingPromise(nullptr); } nsCOMPtr<nsIRunnable> runnable = NewRunnableMethod(orientation, &ScreenOrientation::DispatchChangeEvent); rv = NS_DispatchToMainThread(runnable); if (NS_WARN_IF(rv.Failed())) { return rv.StealNSResult(); } } return NS_OK; }
// static ScreenOrientation* ScreenOrientation::create(LocalFrame* frame) { ASSERT(frame); ScreenOrientation* orientation = adoptRefCountedGarbageCollectedWillBeNoop(new ScreenOrientation(frame)); ASSERT(orientation->controller()); // FIXME: ideally, we would like to provide the ScreenOrientationController // the case where it is not defined but for the moment, it is eagerly // created when the LocalFrame is created so we shouldn't be in that // situtaion. // In order to create the ScreenOrientationController lazily, we would need // to be able to access WebFrameClient from modules/. orientation->controller()->setOrientation(orientation); return orientation; }
// static ScreenOrientation* ScreenOrientation::create(LocalFrame* frame) { ASSERT(frame); // Check if the ScreenOrientationController is supported for the // frame. It will not be for all LocalFrames, or the frame may // have been detached. if (!ScreenOrientationController::from(*frame)) return nullptr; ScreenOrientation* orientation = new ScreenOrientation(frame); ASSERT(orientation->controller()); // FIXME: ideally, we would like to provide the ScreenOrientationController // the case where it is not defined but for the moment, it is eagerly // created when the LocalFrame is created so we shouldn't be in that // situation. // In order to create the ScreenOrientationController lazily, we would need // to be able to access WebFrameClient from modules/. orientation->controller()->setOrientation(orientation); return orientation; }