From bfed43b17884fa7b17ffb36dd4fa182c18350a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 16 Mar 2019 15:17:49 +0000 Subject: [PATCH] Bug 1535790 - Initialize members in nsLookAndFeel, and bail out when there's no screen settings. r=stransky A patch of mine starts calling nsLookAndFeel from xpcshell tests, which makes gtk crash eventually. Differential Revision: https://phabricator.services.mozilla.com/D23759 --HG-- extra : moz-landing-system : lando --- widget/gtk/nsLookAndFeel.cpp | 13 +++-- widget/gtk/nsLookAndFeel.h | 95 +++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index f2f5baecc6b5..996a64e34980 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -48,13 +48,7 @@ using mozilla::LookAndFeel; # define GTK_STATE_FLAG_LINK (static_cast(1 << 9)) #endif -nsLookAndFeel::nsLookAndFeel() - : nsXPLookAndFeel(), - mDefaultFontCached(false), - mButtonFontCached(false), - mFieldFontCached(false), - mMenuFontCached(false), - mInitialized(false) {} +nsLookAndFeel::nsLookAndFeel() = default; nsLookAndFeel::~nsLookAndFeel() {} @@ -866,6 +860,11 @@ void nsLookAndFeel::EnsureInit() { // with wrong color theme, see Bug 972382 GtkSettings* settings = gtk_settings_get_for_screen(gdk_screen_get_default()); + if (MOZ_UNLIKELY(!settings)) { + NS_WARNING("EnsureInit: No settings"); + return; + } + // Dark themes interacts poorly with widget styling (see bug 1216658). // We disable dark themes by default for all processes (chrome, web content) // but allow user to overide it by prefs. diff --git a/widget/gtk/nsLookAndFeel.h b/widget/gtk/nsLookAndFeel.h index e0bb71dd8972..5f8b9aee1e76 100644 --- a/widget/gtk/nsLookAndFeel.h +++ b/widget/gtk/nsLookAndFeel.h @@ -33,12 +33,15 @@ class nsLookAndFeel final : public nsXPLookAndFeel { bool IsCSDAvailable() const { return mCSDAvailable; } + static const nscolor kBlack = NS_RGB(0, 0, 0); + static const nscolor kWhite = NS_RGB(255, 255, 255); + protected: // Cached fonts - bool mDefaultFontCached; - bool mButtonFontCached; - bool mFieldFontCached; - bool mMenuFontCached; + bool mDefaultFontCached = false; + bool mButtonFontCached = false; + bool mFieldFontCached = false; + bool mMenuFontCached = false; nsString mDefaultFontName; nsString mButtonFontName; nsString mFieldFontName; @@ -49,48 +52,48 @@ class nsLookAndFeel final : public nsXPLookAndFeel { gfxFontStyle mMenuFontStyle; // Cached colors - nscolor mInfoBackground; - nscolor mInfoText; - nscolor mMenuBackground; - nscolor mMenuBarText; - nscolor mMenuBarHoverText; - nscolor mMenuText; - nscolor mMenuTextInactive; - nscolor mMenuHover; - nscolor mMenuHoverText; - nscolor mButtonDefault; - nscolor mButtonText; - nscolor mButtonHoverText; - nscolor mButtonHoverFace; - nscolor mFrameOuterLightBorder; - nscolor mFrameInnerDarkBorder; - nscolor mOddCellBackground; - nscolor mNativeHyperLinkText; - nscolor mComboBoxText; - nscolor mComboBoxBackground; - nscolor mMozFieldText; - nscolor mMozFieldBackground; - nscolor mMozWindowText; - nscolor mMozWindowBackground; - nscolor mMozWindowActiveBorder; - nscolor mMozWindowInactiveBorder; - nscolor mMozWindowInactiveCaption; - nscolor mMozCellHighlightBackground; - nscolor mMozCellHighlightText; - nscolor mTextSelectedText; - nscolor mTextSelectedBackground; - nscolor mMozScrollbar; - nscolor mInfoBarText; - char16_t mInvisibleCharacter; - float mCaretRatio; - bool mMenuSupportsDrag; - bool mCSDAvailable; - bool mCSDHideTitlebarByDefault; - bool mCSDMaximizeButton; - bool mCSDMinimizeButton; - bool mCSDCloseButton; - bool mCSDReversedPlacement; - bool mInitialized; + nscolor mInfoBackground = kWhite; + nscolor mInfoText = kBlack; + nscolor mMenuBackground = kWhite; + nscolor mMenuBarText = kBlack; + nscolor mMenuBarHoverText = kBlack; + nscolor mMenuText = kBlack; + nscolor mMenuTextInactive = kWhite; + nscolor mMenuHover = kWhite; + nscolor mMenuHoverText = kBlack; + nscolor mButtonDefault = kWhite; + nscolor mButtonText = kBlack; + nscolor mButtonHoverText = kBlack; + nscolor mButtonHoverFace = kWhite; + nscolor mFrameOuterLightBorder = kBlack; + nscolor mFrameInnerDarkBorder = kBlack; + nscolor mOddCellBackground = kWhite; + nscolor mNativeHyperLinkText = kBlack; + nscolor mComboBoxText = kBlack; + nscolor mComboBoxBackground = kWhite; + nscolor mMozFieldText = kBlack; + nscolor mMozFieldBackground = kWhite; + nscolor mMozWindowText = kBlack; + nscolor mMozWindowBackground = kWhite; + nscolor mMozWindowActiveBorder = kBlack; + nscolor mMozWindowInactiveBorder = kBlack; + nscolor mMozWindowInactiveCaption = kWhite; + nscolor mMozCellHighlightBackground = kWhite; + nscolor mMozCellHighlightText = kBlack; + nscolor mTextSelectedText = kBlack; + nscolor mTextSelectedBackground = kWhite; + nscolor mMozScrollbar = kWhite; + nscolor mInfoBarText = kBlack; + char16_t mInvisibleCharacter = 0; + float mCaretRatio = 0.0f; + bool mMenuSupportsDrag = false; + bool mCSDAvailable = false; + bool mCSDHideTitlebarByDefault = false; + bool mCSDMaximizeButton = false; + bool mCSDMinimizeButton = false; + bool mCSDCloseButton = false; + bool mCSDReversedPlacement = false; + bool mInitialized = false; void EnsureInit();