Bug 1535790 - Initialize members in nsLookAndFeel, and bail out when there's no screen settings. r=stransky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 16 Mar 2019 15:17:49 +0000
changeset 464486 786be6f1f8e0ede952a00e55132648950a30b44b
parent 464485 b12dda048dd5b1d0bed3d3e0cb7387c4cb6b66cf
child 464487 55935c0cdcb403767b529b865be953b7bc529157
push id35716
push useraciure@mozilla.com
push dateSun, 17 Mar 2019 09:42:17 +0000
treeherdermozilla-central@8ee97c045359 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstransky
bugs1535790
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsLookAndFeel.h
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -43,23 +43,17 @@ using mozilla::LookAndFeel;
 #define GDK_RGBA_TO_NS_RGBA(c)                                    \
   ((nscolor)NS_RGBA((int)((c).red * 255), (int)((c).green * 255), \
                     (int)((c).blue * 255), (int)((c).alpha * 255)))
 
 #if !GTK_CHECK_VERSION(3, 12, 0)
 #  define GTK_STATE_FLAG_LINK (static_cast<GtkStateFlags>(1 << 9))
 #endif
 
-nsLookAndFeel::nsLookAndFeel()
-    : nsXPLookAndFeel(),
-      mDefaultFontCached(false),
-      mButtonFontCached(false),
-      mFieldFontCached(false),
-      mMenuFontCached(false),
-      mInitialized(false) {}
+nsLookAndFeel::nsLookAndFeel() = default;
 
 nsLookAndFeel::~nsLookAndFeel() {}
 
 // Modifies color |*aDest| as if a pattern of color |aSource| was painted with
 // CAIRO_OPERATOR_OVER to a surface with color |*aDest|.
 static void ApplyColorOver(const GdkRGBA& aSource, GdkRGBA* aDest) {
   gdouble sourceCoef = aSource.alpha;
   gdouble destCoef = aDest->alpha * (1.0 - sourceCoef);
@@ -861,16 +855,21 @@ void nsLookAndFeel::EnsureInit() {
   GdkRGBA color;
   GtkStyleContext* style;
 
   // Gtk manages a screen's CSS in the settings object so we
   // ask Gtk to create it explicitly. Otherwise we may end up
   // 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.
   const gchar* dark_setting = "gtk-application-prefer-dark-theme";
   gboolean darkThemeDefault;
   g_object_get(settings, dark_setting, &darkThemeDefault, nullptr);
 
   // To avoid triggering reload of theme settings unnecessarily, only set the
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -28,74 +28,77 @@ class nsLookAndFeel final : public nsXPL
   virtual bool GetFontImpl(FontID aID, nsString &aFontName,
                            gfxFontStyle &aFontStyle) override;
 
   virtual char16_t GetPasswordCharacterImpl() override;
   virtual bool GetEchoPasswordImpl() override;
 
   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;
   nsString mMenuFontName;
   gfxFontStyle mDefaultFontStyle;
   gfxFontStyle mButtonFontStyle;
   gfxFontStyle mFieldFontStyle;
   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();
 
  private:
   nsresult InitCellHighlightColors();
 };
 
 #endif