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

Bug 18307460 - Rework -x-text-zoom to allow disabling text zoom and...

Bug 18307460 - Rework -x-text-zoom to allow disabling text zoom and min-font-size separately. r=jfkthame,layout-reviewers

And use it instead of explicit document checks. This centralizes where
we check for it.

IsChromeDoc is relatively cheap, but this bug wants to also check for
PDF.js which is a bit more expensive.

No behavior change.

Differential Revision: https://phabricator.services.mozilla.com/D176940
parent ca23ed1b
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -1374,18 +1374,19 @@ void Gecko_nsStyleFont_CopyLangFrom(nsStyleFont* aFont,

Length Gecko_nsStyleFont_ComputeMinSize(const nsStyleFont* aFont,
                                        const Document* aDocument) {
  // Don't change font-size:0, since that would un-hide hidden text,
  // or SVG text, or chrome docs, we assume those know what they do.
  if (aFont->mSize.IsZero() || !aFont->mAllowZoomAndMinSize ||
      nsContentUtils::IsChromeDoc(aDocument)) {
  // Don't change font-size:0, since that would un-hide hidden text.
  if (aFont->mSize.IsZero()) {
    return {0};
  }
  // Don't change it for docs where we don't enable the min-font-size.
  if (!aFont->MinFontSizeEnabled()) {
    return {0};
  }

  Length minFontSize;
  bool needsCache = false;

  auto MinFontSize = [&](bool* aNeedsToCache) {
    auto* prefs =
    const auto* prefs =
        aDocument->GetFontPrefsForLang(aFont->mLanguage, aNeedsToCache);
    return prefs ? prefs->mMinimumFontSize : Length{0};
  };
+1 −0
Original line number Diff line number Diff line
@@ -647,6 +647,7 @@ cbindgen-types = [
    { gecko = "StyleFontSynthesis", servo = "crate::values::computed::font::FontSynthesis" },
    { gecko = "StyleBoolInteger", servo = "crate::values::computed::BoolInteger" },
    { gecko = "StyleTime", servo = "crate::values::computed::Time" },
    { gecko = "StyleXTextScale", servo = "crate::values::computed::XTextScale" },
]

mapped-generic-types = [
+13 −9
Original line number Diff line number Diff line
@@ -214,7 +214,7 @@ nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
      mMathStyle(aSrc.mMathStyle),
      mMinFontSizeRatio(aSrc.mMinFontSizeRatio),
      mExplicitLanguage(aSrc.mExplicitLanguage),
      mAllowZoomAndMinSize(aSrc.mAllowZoomAndMinSize),
      mXTextScale(aSrc.mXTextScale),
      mScriptUnconstrainedSize(aSrc.mScriptUnconstrainedSize),
      mScriptMinSize(aSrc.mScriptMinSize),
      mScriptSizeMultiplier(aSrc.mScriptSizeMultiplier),
@@ -222,6 +222,13 @@ nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
  MOZ_COUNT_CTOR(nsStyleFont);
}

static StyleXTextScale InitialTextScale(const Document& aDoc) {
  if (nsContentUtils::IsChromeDoc(&aDoc)) {
    return StyleXTextScale::ZoomOnly;
  }
  return StyleXTextScale::All;
}

nsStyleFont::nsStyleFont(const Document& aDocument)
    : mFont(*aDocument.GetFontPrefsForLang(nullptr)->GetDefaultFont(
          StyleGenericFontFamily::None)),
@@ -233,9 +240,7 @@ nsStyleFont::nsStyleFont(const Document& aDocument)
      mMathDepth(0),
      mMathVariant(StyleMathVariant::None),
      mMathStyle(StyleMathStyle::Normal),
      mMinFontSizeRatio(100),  // 100%
      mExplicitLanguage(false),
      mAllowZoomAndMinSize(true),
      mXTextScale(InitialTextScale(aDocument)),
      mScriptUnconstrainedSize(mSize),
      mScriptMinSize(Length::FromPixels(
          CSSPixel::FromPoints(kMathMLDefaultScriptMinSizePt))),
@@ -245,8 +250,8 @@ nsStyleFont::nsStyleFont(const Document& aDocument)
  MOZ_ASSERT(NS_IsMainThread());
  mFont.family.is_initial = true;
  mFont.size = mSize;
  if (!nsContentUtils::IsChromeDoc(&aDocument)) {
    Length minimumFontSize =
  if (MinFontSizeEnabled()) {
    const Length minimumFontSize =
        aDocument.GetFontPrefsForLang(mLanguage)->mMinimumFontSize;
    mFont.size = Length::FromPixels(
        std::max(mSize.ToCSSPixels(), minimumFontSize.ToCSSPixels()));
@@ -254,9 +259,8 @@ nsStyleFont::nsStyleFont(const Document& aDocument)
}

nsChangeHint nsStyleFont::CalcDifference(const nsStyleFont& aNewData) const {
  MOZ_ASSERT(
      mAllowZoomAndMinSize == aNewData.mAllowZoomAndMinSize,
      "expected mAllowZoomAndMinSize to be the same on both nsStyleFonts");
  MOZ_ASSERT(mXTextScale == aNewData.mXTextScale,
             "expected -x-text-scale to be the same on both nsStyleFonts");
  if (mSize != aNewData.mSize || mLanguage != aNewData.mLanguage ||
      mExplicitLanguage != aNewData.mExplicitLanguage ||
      mMathVariant != aNewData.mMathVariant ||
+9 −8
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ struct ContainSizeAxes {
}  // namespace mozilla

struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
  nsStyleFont(const nsStyleFont& aStyleFont);
  nsStyleFont(const nsStyleFont&);
  explicit nsStyleFont(const mozilla::dom::Document&);
  MOZ_COUNTED_DTOR(nsStyleFont)
  static constexpr bool kHasTriggerImageLoads = false;
@@ -144,15 +144,16 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
  mozilla::StyleMathStyle mMathStyle;

  // allow different min font-size for certain cases
  uint8_t mMinFontSizeRatio;  // percent * 100
  uint8_t mMinFontSizeRatio = 100;  // percent * 100

  // was mLanguage set based on a lang attribute in the document?
  bool mExplicitLanguage;
  // Was mLanguage set based on a lang attribute in the document?
  bool mExplicitLanguage = false;

  // should calls to ZoomText() and UnZoomText() be made to the font
  // size on this nsStyleFont? Also used to prevent SVG text from being
  // affected by minimum font size pref.
  bool mAllowZoomAndMinSize;
  mozilla::StyleXTextScale mXTextScale;

  bool MinFontSizeEnabled() const {
    return mXTextScale == mozilla::StyleXTextScale::All;
  }

  // The value mSize would have had if scriptminsize had never been applied
  mozilla::NonNegativeLength mScriptUnconstrainedSize;
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ const char* gInaccessibleProperties[] = {
    "-x-cols",
    "-x-lang",
    "-x-span",
    "-x-text-zoom",
    "-x-text-scale",
    "-moz-default-appearance",
    "-moz-inert",
    "-moz-script-level",  // parsed by UA sheets only
Loading