Bug 1493976 - Reset the resolution to 1 when entering fullscreen mode. r=kats,xidorn
The previous resolution is restored when exiting fullscreen mode.
Depends on D9442
Differential Revision:
https://phabricator.services.mozilla.com/D9443
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1505,17 +1505,18 @@ nsIDocument::nsIDocument()
mBoxObjectTable(nullptr),
mCurrentOrientationAngle(0),
mCurrentOrientationType(OrientationType::Portrait_primary),
mServoRestyleRootDirtyBits(0),
mThrowOnDynamicMarkupInsertionCounter(0),
mIgnoreOpensDuringUnloadCounter(0),
mNumTrackersFound(0),
mNumTrackersBlocked(0),
- mDocLWTheme(Doc_Theme_Uninitialized)
+ mDocLWTheme(Doc_Theme_Uninitialized),
+ mSavedResolution(1.0f)
{
SetIsInDocument();
SetIsConnected(true);
if (StaticPrefs::layout_css_use_counters_enabled()) {
mStyleUseCounters.reset(Servo_UseCounters_Create());
}
}
@@ -11181,16 +11182,26 @@ nsIDocument::CleanupFullscreenState()
// after bug 1195213.
for (nsWeakPtr& weakPtr : Reversed(mFullscreenStack)) {
if (nsCOMPtr<Element> element = do_QueryReferent(weakPtr)) {
ClearFullscreenStateOnElement(element);
}
}
mFullscreenStack.Clear();
mFullscreenRoot = nullptr;
+
+ // Restore the zoom level that was in place prior to entering fullscreen.
+ if (nsIPresShell* shell = GetShell()) {
+ if (nsPresContext* context = shell->GetPresContext()) {
+ if (context->IsRootContentDocument()) {
+ shell->SetResolutionAndScaleTo(mSavedResolution);
+ }
+ }
+ }
+
UpdateViewportScrollbarOverrideForFullscreen(this);
}
bool
nsIDocument::FullscreenStackPush(Element* aElement)
{
NS_ASSERTION(aElement, "Must pass non-null to FullscreenStackPush()");
Element* top = FullscreenStackTop();
@@ -11584,16 +11595,33 @@ nsIDocument::ApplyFullscreen(UniquePtr<F
// Propagate up the document hierarchy, setting the fullscreen element as
// the element's container in ancestor documents. This also sets the
// appropriate css styles as well. Note we don't propagate down the
// document hierarchy, the fullscreen element (or its container) is not
// visible there. Stop when we reach the root document.
nsIDocument* child = this;
while (true) {
child->SetFullscreenRoot(fullScreenRootDoc);
+
+ // When entering fullscreen, reset the RCD's zoom level to 1,
+ // otherwise the fullscreen content could be sized larger than the
+ // screen (since fullscreen is implemented using position:fixed and
+ // fixed elements are sized to the layout viewport).
+ // This also ensures that things like video controls aren't zoomed in
+ // when in fullscreen mode.
+ if (nsIPresShell* shell = child->GetShell()) {
+ if (nsPresContext* context = shell->GetPresContext()) {
+ if (context->IsRootContentDocument()) {
+ // Save the previous resolution so it can be restored.
+ child->mSavedResolution = shell->GetResolution();
+ shell->SetResolutionAndScaleTo(1.0f);
+ }
+ }
+ }
+
NS_ASSERTION(child->GetFullscreenRoot() == fullScreenRootDoc,
"Fullscreen root should be set!");
if (child == fullScreenRootDoc) {
break;
}
nsIDocument* parent = child->GetParentDocument();
Element* element = parent->FindContentForSubDocument(child);
if (static_cast<nsDocument*>(parent)->FullscreenStackPush(element)) {
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -4766,16 +4766,19 @@ protected:
uint32_t mNumTrackersBlocked;
mozilla::EnumSet<mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED>
mTrackerBlockedReasons;
// document lightweight theme for use with :-moz-lwtheme, :-moz-lwtheme-brighttext
// and :-moz-lwtheme-darktext
DocumentTheme mDocLWTheme;
+
+ // Pres shell resolution saved before entering fullscreen mode.
+ float mSavedResolution;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID)
/**
* mozAutoSubtreeModified batches DOM mutations so that a DOMSubtreeModified
* event is dispatched, if necessary, when the outermost mozAutoSubtreeModified
* object is deleted.