Bug 1812868 - Tweak RDM and theme setup. r=mstange

This is in order to make nsPresContext::UseOverlayScrollbars() thread-safe for
stylo usage.

Document::GetBrowsingContext() does ref-counting of main-thread-only
objects, and we don't want that.

Similarly nsPresContext::Theme() mutates the pres context which is not
something we can do from multiple threads.

Reviewed in: https://phabricator.services.mozilla.com/D168148
This commit is contained in:
Emilio Cobos Álvarez 2023-02-17 21:15:06 +00:00
Родитель f58704f4b9
Коммит e22c322da5
3 изменённых файлов: 39 добавлений и 40 удалений

Просмотреть файл

@ -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>,

Просмотреть файл

@ -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();
}
@ -1626,11 +1639,15 @@ void nsPresContext::RecordInteractionTime(InteractionType aType,
}
}
nsITheme* nsPresContext::EnsureTheme() {
nsITheme* nsPresContext::Theme() const {
MOZ_ASSERT(mTheme);
return mTheme;
}
void 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();
@ -1639,7 +1656,6 @@ nsITheme* nsPresContext::EnsureTheme() {
mTheme = do_GetNativeThemeDoNotUseDirectly();
}
MOZ_RELEASE_ASSERT(mTheme);
return mTheme;
}
void nsPresContext::RecomputeTheme() {
@ -1651,17 +1667,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) {

Просмотреть файл

@ -573,6 +573,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 +825,7 @@ 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)) {
return mTheme;
}
return EnsureTheme();
}
nsITheme* Theme() const MOZ_NONNULL_RETURN;
void RecomputeTheme();
@ -1352,6 +1342,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?
@ -1383,7 +1376,7 @@ class nsPresContext : public nsISupports, public mozilla::SupportsWeakPtr {
void LastRelease();
nsITheme* EnsureTheme();
void EnsureTheme();
#ifdef DEBUG
private: