From ae17d72d9f9935ef740301579285f2049f1e97d3 Mon Sep 17 00:00:00 2001 From: Marian-Vasile Laza Date: Wed, 17 Aug 2022 22:00:06 +0300 Subject: [PATCH] Backed out changeset cf566ee2f54b (bug 1784335) for causing mochitest failures on test_emulateMedium.html. CLOSED TREE --- layout/base/nsPresContext.cpp | 26 +-- layout/base/nsPresContext.h | 2 +- layout/base/tests/test_emulateMedium.html | 254 ++++++++++------------ layout/style/MediaFeatureChange.h | 8 - 4 files changed, 129 insertions(+), 161 deletions(-) diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 1a98eefacb8f..c2d39011ab66 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -876,7 +876,7 @@ void nsPresContext::AttachPresShell(mozilla::PresShell* aPresShell) { } Maybe nsPresContext::GetOverriddenOrEmbedderColorScheme() const { - if (Medium() == nsGkAtoms::print) { + if (IsPrintingOrPrintPreview()) { return Some(ColorScheme::Light); } @@ -900,9 +900,12 @@ void nsPresContext::SetColorSchemeOverride( mOverriddenOrEmbedderColorScheme = aOverride; if (mDocument->PreferredColorScheme() != oldScheme) { - MediaFeatureValuesChanged( - MediaFeatureChange::ForPreferredColorSchemeChange(), - MediaFeatureChangePropagation::JustThisDocument); + // We need to restyle because not only media queries have changed, system + // colors may as well via the prefers-color-scheme meta tag / effective + // color-scheme property value. + MediaFeatureValuesChanged({RestyleHint::RecascadeSubtree(), nsChangeHint(0), + MediaFeatureChangeReason::SystemMetricsChange}, + MediaFeatureChangePropagation::JustThisDocument); } } @@ -1776,22 +1779,13 @@ void nsPresContext::UIResolutionChangedInternal() { void nsPresContext::EmulateMedium(nsAtom* aMediaType) { MOZ_ASSERT(!aMediaType || aMediaType->IsAsciiLowercase()); - RefPtr oldMedium = Medium(); - auto oldScheme = mDocument->PreferredColorScheme(); - mMediaEmulationData.mMedium = aMediaType; - if (Medium() == oldMedium) { - return; + if (Medium() != oldMedium) { + MediaFeatureValuesChanged({MediaFeatureChangeReason::MediumChange}, + MediaFeatureChangePropagation::JustThisDocument); } - - MediaFeatureChange change(MediaFeatureChangeReason::MediumChange); - if (oldScheme != mDocument->PreferredColorScheme()) { - change |= MediaFeatureChange::ForPreferredColorSchemeChange(); - } - MediaFeatureValuesChanged(change, - MediaFeatureChangePropagation::JustThisDocument); } void nsPresContext::ContentLanguageChanged() { diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index a0ea81106fe3..6d42b52ee418 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -345,7 +345,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr { /** * Get medium of presentation */ - const nsAtom* Medium() const { + const nsAtom* Medium() { MOZ_ASSERT(mMedium); return mMediaEmulationData.mMedium ? mMediaEmulationData.mMedium.get() : mMedium; diff --git a/layout/base/tests/test_emulateMedium.html b/layout/base/tests/test_emulateMedium.html index e2a95ee955b6..0126339d2aa8 100644 --- a/layout/base/tests/test_emulateMedium.html +++ b/layout/base/tests/test_emulateMedium.html @@ -3,157 +3,139 @@ - -Test for Bug 819930 - - - - -Mozilla Bug 819930 -

+ @media tv { + body { + background-color: rgb(75, 0, 130); + } + } + + + + Mozilla Bug 819930 +

- + +
+      
+        SpecialPowers.stopEmulatingMedium(window);
+      
+    
+ + diff --git a/layout/style/MediaFeatureChange.h b/layout/style/MediaFeatureChange.h index 70f81f7d1cbd..1e4add412243 100644 --- a/layout/style/MediaFeatureChange.h +++ b/layout/style/MediaFeatureChange.h @@ -79,14 +79,6 @@ struct MediaFeatureChange { mReason |= aOther.mReason; return *this; } - - static MediaFeatureChange ForPreferredColorSchemeChange() { - // We need to restyle because not only media queries have changed, system - // colors may as well via the prefers-color-scheme meta tag / effective - // color-scheme property value. - return {RestyleHint::RecascadeSubtree(), nsChangeHint(0), - MediaFeatureChangeReason::SystemMetricsChange}; - } }; } // namespace mozilla