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

Bug 1812868 - Expose scrollbar-inline-size as a CSS variable to chrome code. r=mstange

For that we need to:

 * Make GetDPIRatioForScrollbarPart thread-safe: This was using the
   widget for bug 1727289, but just looking at the print preview scale
   is enough to fix that.

 * Make nsPresContext::UseOverlayScrollbars() thread-safe: We store the
   RDM pane stuff in the pres context.

The rest is pretty straight-forward.

Differential Revision: https://phabricator.services.mozilla.com/D168148
parent 42ef1bc6
Loading
Loading
Loading
Loading
+1 −15
Original line number Diff line number Diff line
@@ -2757,21 +2757,7 @@ void BrowsingContext::DidSet(FieldIndex<IDX_InRDMPane>, bool aOldValue) {
  if (GetInRDMPane() == aOldValue) {
    return;
  }

  PreOrderWalk([&](BrowsingContext* aContext) {
    if (nsIDocShell* shell = aContext->GetDocShell()) {
      if (nsPresContext* pc = shell->GetPresContext()) {
        pc->RecomputeTheme();

        // This is a bit of a lie, but this affects the overlay-scrollbars
        // media query and it's the code-path that gets taken for regular system
        // metrics changes via ThemeChanged().
        pc->MediaFeatureValuesChanged(
            {MediaFeatureChangeReason::SystemMetricsChange},
            MediaFeatureChangePropagation::JustThisDocument);
      }
    }
  });
  PresContextAffectingFieldChanged();
}

bool BrowsingContext::CanSet(FieldIndex<IDX_PageAwakeRequestCount>,
+26 −10
Original line number Diff line number Diff line
@@ -278,6 +278,7 @@ nsPresContext::nsPresContext(dom::Document* aDocument, nsPresContextType aType)
      mFontFeatureValuesDirty(true),
      mFontPaletteValuesDirty(true),
      mIsVisual(false),
      mInRDMPane(false),
      mHasWarnedAboutTooLargeDashedOrDottedRadius(false),
      mQuirkSheetAdded(false),
      mHadNonBlankPaint(false),
@@ -858,6 +859,8 @@ void nsPresContext::AttachPresShell(mozilla::PresShell* aPresShell) {
  // have a presshell, and hence a document.
  GetUserPreferences();

  EnsureTheme();

  nsIURI* docURI = doc->GetDocumentURI();

  if (IsDynamic() && docURI) {
@@ -933,6 +936,8 @@ void nsPresContext::RecomputeBrowsingContextDependentData() {
    return browsingContext->GetEmbedderColorSchemes().mPreferred;
  }());

  SetInRDMPane(top->GetInRDMPane());

  if (doc == mDocument) {
    // Medium doesn't apply to resource documents, etc.
    RefPtr<nsAtom> mediumToEmulate;
@@ -1286,6 +1291,14 @@ void nsPresContext::UpdateEffectiveTextZoom() {
      MediaFeatureChangePropagation::JustThisDocument);
}

void nsPresContext::SetInRDMPane(bool aInRDMPane) {
  if (mInRDMPane == aInRDMPane) {
    return;
  }
  mInRDMPane = aInRDMPane;
  RecomputeTheme();
}

float nsPresContext::GetDeviceFullZoom() {
  return mDeviceContext->GetFullZoom();
}
@@ -1629,8 +1642,7 @@ void nsPresContext::RecordInteractionTime(InteractionType aType,
nsITheme* nsPresContext::EnsureTheme() {
  MOZ_ASSERT(!mTheme);
  if (Document()->ShouldAvoidNativeTheme()) {
    BrowsingContext* bc = Document()->GetBrowsingContext();
    if (bc && bc->Top()->InRDMPane()) {
    if (mInRDMPane) {
      mTheme = do_GetRDMThemeDoNotUseDirectly();
    } else {
      mTheme = do_GetBasicNativeThemeDoNotUseDirectly();
@@ -1651,17 +1663,21 @@ void nsPresContext::RecomputeTheme() {
  if (oldTheme == mTheme) {
    return;
  }
  // Theme only affects layout information, not style, so we just need to
  // reframe (as it affects whether we create scrollbar buttons for example).
  RebuildAllStyleData(nsChangeHint_ReconstructFrame, RestyleHint{0});
  // Theme affects layout information (as it affects whether we create
  // scrollbar buttons for example) and also style (affects the
  // scrollbar-inline-size env var).
  RebuildAllStyleData(nsChangeHint_ReconstructFrame,
                      RestyleHint::RecascadeSubtree());
  // This is a bit of a lie, but this affects the overlay-scrollbars
  // media query and it's the code-path that gets taken for regular system
  // metrics changes via ThemeChanged().
  MediaFeatureValuesChanged({MediaFeatureChangeReason::SystemMetricsChange},
                            MediaFeatureChangePropagation::JustThisDocument);
}

bool nsPresContext::UseOverlayScrollbars() const {
  if (LookAndFeel::GetInt(LookAndFeel::IntID::UseOverlayScrollbars)) {
    return true;
  }
  BrowsingContext* bc = Document()->GetBrowsingContext();
  return bc && bc->Top()->InRDMPane();
  return LookAndFeel::GetInt(LookAndFeel::IntID::UseOverlayScrollbars) ||
         mInRDMPane;
}

void nsPresContext::ThemeChanged(widget::ThemeChangeKind aKind) {
+12 −12
Original line number Diff line number Diff line
@@ -502,7 +502,9 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
   *
   * XXX Temporary: see http://wiki.mozilla.org/Gecko:PrintPreview
   */
  float GetPrintPreviewScaleForSequenceFrame() { return mPPScale; }
  float GetPrintPreviewScaleForSequenceFrameOrScrollbars() const {
    return mPPScale;
  }
  void SetPrintPreviewScale(float aScale) { mPPScale = aScale; }

  nsDeviceContext* DeviceContext() const { return mDeviceContext; }
@@ -573,6 +575,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
  }
  void SetFullZoom(float aZoom);
  void SetOverrideDPPX(float);
  void SetInRDMPane(bool aInRDMPane);

 public:
  float GetFullZoom() { return mFullZoom; }
@@ -824,18 +827,10 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
   */
  uint32_t GetBidi() const;

  /*
   * Obtain a native theme for rendering our widgets (both form controls and
   * html)
   *
   * Guaranteed to return non-null.
   */
  nsITheme* Theme() MOZ_NONNULL_RETURN {
    if (MOZ_LIKELY(mTheme)) {
  nsITheme* Theme() const MOZ_NONNULL_RETURN {
    MOZ_ASSERT(mTheme);
    return mTheme;
  }
    return EnsureTheme();
  }

  void RecomputeTheme();

@@ -907,6 +902,8 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
    return mType == eContext_Print || mType == eContext_PrintPreview;
  }

  bool IsPrintPreview() const { return mType == eContext_PrintPreview; }

  // Is this presentation in a chrome docshell?
  bool IsChrome() const;

@@ -1352,6 +1349,9 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {

  unsigned mIsVisual : 1;

  // Are we in the RDM pane?
  unsigned mInRDMPane : 1;

  unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;

  // Have we added quirk.css to the style set?
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)

float nsPageSequenceFrame::GetPrintPreviewScale() const {
  nsPresContext* pc = PresContext();
  float scale = pc->GetPrintPreviewScaleForSequenceFrame();
  float scale = pc->GetPrintPreviewScaleForSequenceFrameOrScrollbars();

  WritingMode wm = GetWritingMode();
  if (pc->IsScreen() && MOZ_LIKELY(mScrollportSize.ISize(wm) > 0 &&
+10 −0
Original line number Diff line number Diff line
@@ -305,6 +305,16 @@ bool Gecko_AnimationNameMayBeReferencedFromStyle(
  return aPresContext->AnimationManager()->AnimationMayBeReferenced(aName);
}

float Gecko_GetScrollbarInlineSize(const nsPresContext* aPc) {
  MOZ_ASSERT(aPc);
  AutoWriteLock guard(*sServoFFILock);  // We read some look&feel values.
  auto overlay = aPc->UseOverlayScrollbars() ? nsITheme::Overlay::Yes
                                             : nsITheme::Overlay::No;
  LayoutDeviceIntCoord size =
      aPc->Theme()->GetScrollbarSize(aPc, StyleScrollbarWidth::Auto, overlay);
  return aPc->DevPixelsToFloatCSSPixels(size);
}

PseudoStyleType Gecko_GetImplementedPseudo(const Element* aElement) {
  return aElement->GetPseudoElementType();
}
Loading