Loading layout/base/MediaEmulationData.h 0 → 100644 +26 −0 Original line number Diff line number Diff line /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Common data for media query emulation by DevTools, hanging off nsPresContext */ #ifndef mozilla_MediaEmulationData_h #define mozilla_MediaEmulationData_h #include "nsAtom.h" namespace mozilla { struct MediaEmulationData final { MediaEmulationData() = default; RefPtr<nsAtom> mMedium; float mDPPX = 0.0; }; } // namespace mozilla #endif layout/base/moz.build +1 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ EXPORTS.mozilla += [ 'ArenaObjectID.h', 'GeckoMVMContext.h', 'GeometryUtils.h', 'MediaEmulationData.h', 'MVMContext.h', 'OverflowChangedTracker.h', 'PresShell.h', Loading layout/base/nsPresContext.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -149,7 +149,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType) mTextZoom(1.0), mEffectiveTextZoom(1.0), mFullZoom(1.0), mOverrideDPPX(0.0), mLastFontInflationScreenSize(gfxSize(-1.0, -1.0)), mCurAppUnitsPerDevPixel(0), mAutoQualityMinFontSizePixelsPref(0), Loading Loading @@ -980,11 +979,11 @@ void nsPresContext::SetOverrideDPPX(float aDPPX) { // SetOverrideDPPX is called during navigations, including history // traversals. In that case, it's typically called with our current value, // and we don't need to actually do anything. if (aDPPX == mOverrideDPPX) { if (aDPPX == GetOverrideDPPX()) { return; } mOverrideDPPX = aDPPX; mMediaEmulationData.mDPPX = aDPPX; MediaFeatureValuesChanged({MediaFeatureChangeReason::ResolutionChange}); } Loading Loading @@ -1423,9 +1422,10 @@ void nsPresContext::UIResolutionChangedInternalScale(double aScale) { void nsPresContext::EmulateMedium(nsAtom* aMediaType) { MOZ_ASSERT(!aMediaType || aMediaType->IsAsciiLowercase()); RefPtr<const nsAtom> previousMedium = Medium(); mMediaEmulated = aMediaType; if (mMediaEmulated != previousMedium && mPresShell) { RefPtr<const nsAtom> oldMedium = Medium(); mMediaEmulationData.mMedium = aMediaType; if (Medium() != oldMedium) { MediaFeatureValuesChanged({MediaFeatureChangeReason::MediumChange}); } } Loading layout/base/nsPresContext.h +10 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/TimeStamp.h" #include "mozilla/AppUnits.h" #include "mozilla/MediaEmulationData.h" #include "prclist.h" #include "nsThreadUtils.h" #include "nsIMessageManager.h" Loading Loading @@ -132,6 +133,8 @@ class nsPresContext : public nsISupports, using Encoding = mozilla::Encoding; template <typename T> using NotNull = mozilla::NotNull<T>; using MediaEmulationData = mozilla::MediaEmulationData; typedef mozilla::ScrollStyles ScrollStyles; typedef mozilla::StaticPresData StaticPresData; using TransactionId = mozilla::layers::TransactionId; Loading Loading @@ -305,7 +308,8 @@ class nsPresContext : public nsISupports, */ const nsAtom* Medium() { MOZ_ASSERT(mMedium); return mMediaEmulated ? mMediaEmulated.get() : mMedium; return mMediaEmulationData.mMedium ? mMediaEmulationData.mMedium.get() : mMedium; } /* Loading Loading @@ -484,8 +488,8 @@ class nsPresContext : public nsISupports, float GetDeviceFullZoom(); void SetFullZoom(float aZoom); float GetOverrideDPPX() { return mOverrideDPPX; } void SetOverrideDPPX(float aDPPX); float GetOverrideDPPX() const { return mMediaEmulationData.mDPPX; } void SetOverrideDPPX(float); nscoord GetAutoQualityMinFontSize() { return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref); Loading Loading @@ -1117,8 +1121,10 @@ class nsPresContext : public nsISupports, mozilla::UniquePtr<mozilla::RestyleManager> mRestyleManager; RefPtr<mozilla::CounterStyleManager> mCounterStyleManager; const nsStaticAtom* mMedium; RefPtr<nsAtom> mMediaEmulated; RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup; // TODO(emilio): Maybe lazily create and put under a UniquePtr if this grows a // lot? MediaEmulationData mMediaEmulationData; public: // The following are public member variables so that we can use them Loading @@ -1133,7 +1139,6 @@ class nsPresContext : public nsISupports, float mTextZoom; // Text zoom, defaults to 1.0 float mEffectiveTextZoom; // Text zoom * system font scale float mFullZoom; // Page zoom, defaults to 1.0 float mOverrideDPPX; // DPPX overrided, defaults to 0.0 gfxSize mLastFontInflationScreenSize; int32_t mCurAppUnitsPerDevPixel; Loading servo/components/style/gecko/media_queries.rs +6 −7 Original line number Diff line number Diff line Loading @@ -213,11 +213,11 @@ impl Device { None => return MediaType::screen(), }; // Gecko allows emulating random media with mMediaEmulated. let medium_to_use = if !pc.mMediaEmulated.mRawPtr.is_null() { pc.mMediaEmulated.mRawPtr // Gecko allows emulating random media with mMediaEmulationData.mMedium. let medium_to_use = if !pc.mMediaEmulationData.mMedium.mRawPtr.is_null() { pc.mMediaEmulationData.mMedium.mRawPtr } else { pc.mMedium as *const bindings::nsAtom as *mut _ pc.mMedium as *const structs::nsAtom as *mut _ }; MediaType(CustomIdent(unsafe { Atom::from_raw(medium_to_use) })) Loading Loading @@ -252,9 +252,8 @@ impl Device { None => return Scale::new(1.), }; let override_dppx = pc.mOverrideDPPX; if override_dppx > 0.0 { return Scale::new(override_dppx); if pc.mMediaEmulationData.mDPPX > 0.0 { return Scale::new(pc.mMediaEmulationData.mDPPX); } let au_per_dpx = pc.mCurAppUnitsPerDevPixel as f32; Loading Loading
layout/base/MediaEmulationData.h 0 → 100644 +26 −0 Original line number Diff line number Diff line /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* Common data for media query emulation by DevTools, hanging off nsPresContext */ #ifndef mozilla_MediaEmulationData_h #define mozilla_MediaEmulationData_h #include "nsAtom.h" namespace mozilla { struct MediaEmulationData final { MediaEmulationData() = default; RefPtr<nsAtom> mMedium; float mDPPX = 0.0; }; } // namespace mozilla #endif
layout/base/moz.build +1 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ EXPORTS.mozilla += [ 'ArenaObjectID.h', 'GeckoMVMContext.h', 'GeometryUtils.h', 'MediaEmulationData.h', 'MVMContext.h', 'OverflowChangedTracker.h', 'PresShell.h', Loading
layout/base/nsPresContext.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -149,7 +149,6 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType) mTextZoom(1.0), mEffectiveTextZoom(1.0), mFullZoom(1.0), mOverrideDPPX(0.0), mLastFontInflationScreenSize(gfxSize(-1.0, -1.0)), mCurAppUnitsPerDevPixel(0), mAutoQualityMinFontSizePixelsPref(0), Loading Loading @@ -980,11 +979,11 @@ void nsPresContext::SetOverrideDPPX(float aDPPX) { // SetOverrideDPPX is called during navigations, including history // traversals. In that case, it's typically called with our current value, // and we don't need to actually do anything. if (aDPPX == mOverrideDPPX) { if (aDPPX == GetOverrideDPPX()) { return; } mOverrideDPPX = aDPPX; mMediaEmulationData.mDPPX = aDPPX; MediaFeatureValuesChanged({MediaFeatureChangeReason::ResolutionChange}); } Loading Loading @@ -1423,9 +1422,10 @@ void nsPresContext::UIResolutionChangedInternalScale(double aScale) { void nsPresContext::EmulateMedium(nsAtom* aMediaType) { MOZ_ASSERT(!aMediaType || aMediaType->IsAsciiLowercase()); RefPtr<const nsAtom> previousMedium = Medium(); mMediaEmulated = aMediaType; if (mMediaEmulated != previousMedium && mPresShell) { RefPtr<const nsAtom> oldMedium = Medium(); mMediaEmulationData.mMedium = aMediaType; if (Medium() != oldMedium) { MediaFeatureValuesChanged({MediaFeatureChangeReason::MediumChange}); } } Loading
layout/base/nsPresContext.h +10 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/TimeStamp.h" #include "mozilla/AppUnits.h" #include "mozilla/MediaEmulationData.h" #include "prclist.h" #include "nsThreadUtils.h" #include "nsIMessageManager.h" Loading Loading @@ -132,6 +133,8 @@ class nsPresContext : public nsISupports, using Encoding = mozilla::Encoding; template <typename T> using NotNull = mozilla::NotNull<T>; using MediaEmulationData = mozilla::MediaEmulationData; typedef mozilla::ScrollStyles ScrollStyles; typedef mozilla::StaticPresData StaticPresData; using TransactionId = mozilla::layers::TransactionId; Loading Loading @@ -305,7 +308,8 @@ class nsPresContext : public nsISupports, */ const nsAtom* Medium() { MOZ_ASSERT(mMedium); return mMediaEmulated ? mMediaEmulated.get() : mMedium; return mMediaEmulationData.mMedium ? mMediaEmulationData.mMedium.get() : mMedium; } /* Loading Loading @@ -484,8 +488,8 @@ class nsPresContext : public nsISupports, float GetDeviceFullZoom(); void SetFullZoom(float aZoom); float GetOverrideDPPX() { return mOverrideDPPX; } void SetOverrideDPPX(float aDPPX); float GetOverrideDPPX() const { return mMediaEmulationData.mDPPX; } void SetOverrideDPPX(float); nscoord GetAutoQualityMinFontSize() { return DevPixelsToAppUnits(mAutoQualityMinFontSizePixelsPref); Loading Loading @@ -1117,8 +1121,10 @@ class nsPresContext : public nsISupports, mozilla::UniquePtr<mozilla::RestyleManager> mRestyleManager; RefPtr<mozilla::CounterStyleManager> mCounterStyleManager; const nsStaticAtom* mMedium; RefPtr<nsAtom> mMediaEmulated; RefPtr<gfxFontFeatureValueSet> mFontFeatureValuesLookup; // TODO(emilio): Maybe lazily create and put under a UniquePtr if this grows a // lot? MediaEmulationData mMediaEmulationData; public: // The following are public member variables so that we can use them Loading @@ -1133,7 +1139,6 @@ class nsPresContext : public nsISupports, float mTextZoom; // Text zoom, defaults to 1.0 float mEffectiveTextZoom; // Text zoom * system font scale float mFullZoom; // Page zoom, defaults to 1.0 float mOverrideDPPX; // DPPX overrided, defaults to 0.0 gfxSize mLastFontInflationScreenSize; int32_t mCurAppUnitsPerDevPixel; Loading
servo/components/style/gecko/media_queries.rs +6 −7 Original line number Diff line number Diff line Loading @@ -213,11 +213,11 @@ impl Device { None => return MediaType::screen(), }; // Gecko allows emulating random media with mMediaEmulated. let medium_to_use = if !pc.mMediaEmulated.mRawPtr.is_null() { pc.mMediaEmulated.mRawPtr // Gecko allows emulating random media with mMediaEmulationData.mMedium. let medium_to_use = if !pc.mMediaEmulationData.mMedium.mRawPtr.is_null() { pc.mMediaEmulationData.mMedium.mRawPtr } else { pc.mMedium as *const bindings::nsAtom as *mut _ pc.mMedium as *const structs::nsAtom as *mut _ }; MediaType(CustomIdent(unsafe { Atom::from_raw(medium_to_use) })) Loading Loading @@ -252,9 +252,8 @@ impl Device { None => return Scale::new(1.), }; let override_dppx = pc.mOverrideDPPX; if override_dppx > 0.0 { return Scale::new(override_dppx); if pc.mMediaEmulationData.mDPPX > 0.0 { return Scale::new(pc.mMediaEmulationData.mDPPX); } let au_per_dpx = pc.mCurAppUnitsPerDevPixel as f32; Loading