Commit d93f6419 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1570721 - Move the overrides to a separate struct in nsPresContext. r=heycam

Just so that we can keep track of these together.

Differential Revision: https://phabricator.services.mozilla.com/D40247
parent e288006e
Loading
Loading
Loading
Loading
+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
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ EXPORTS.mozilla += [
    'ArenaObjectID.h',
    'GeckoMVMContext.h',
    'GeometryUtils.h',
    'MediaEmulationData.h',
    'MVMContext.h',
    'OverflowChangedTracker.h',
    'PresShell.h',
+6 −6
Original line number Diff line number Diff line
@@ -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),
@@ -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});
}

@@ -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});
  }
}
+10 −5
Original line number Diff line number Diff line
@@ -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"
@@ -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;
@@ -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;
  }

  /*
@@ -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);
@@ -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
@@ -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;
+6 −7
Original line number Diff line number Diff line
@@ -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) }))
@@ -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;