Bug 1158076 - postpone nsLookAndFeel module initialization, r?karlt
MozReview-Commit-ID: LISvLuAqCIP
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -44,19 +44,19 @@ using mozilla::LookAndFeel;
(int)((c).blue*255), (int)((c).alpha*255)))
nsLookAndFeel::nsLookAndFeel()
: nsXPLookAndFeel(),
#if (MOZ_WIDGET_GTK == 2)
mStyle(nullptr),
#endif
mDefaultFontCached(false), mButtonFontCached(false),
- mFieldFontCached(false), mMenuFontCached(false)
+ mFieldFontCached(false), mMenuFontCached(false),
+ mInitialized(false)
{
- Init();
}
nsLookAndFeel::~nsLookAndFeel()
{
#if (MOZ_WIDGET_GTK == 2)
g_object_unref(mStyle);
#endif
}
@@ -218,16 +218,18 @@ GetBorderColors(GtkStyleContext* aContex
*aDarkColor = GDK_RGBA_TO_NS_RGBA(darkColor);
return ret;
}
#endif
nsresult
nsLookAndFeel::NativeGetColor(ColorID aID, nscolor& aColor)
{
+ EnsureInit();
+
#if (MOZ_WIDGET_GTK == 3)
GdkRGBA gdk_color;
#endif
nsresult res = NS_OK;
switch (aID) {
// These colors don't seem to be used for anything anymore in Mozilla
// (except here at least TextSelectBackground and TextSelectForeground)
@@ -669,16 +671,18 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
break;
}
res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
+ // We use delayed initialization by EnsureInit() here
+ // to ensure mozilla::Preferences is available (see Bug 1158076).
switch (aID) {
case eIntID_CaretBlinkTime:
{
GtkSettings *settings;
gint blink_time;
gboolean blink;
settings = gtk_settings_get_default ();
@@ -831,16 +835,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
case eIntID_IMESelectedRawTextUnderlineStyle:
case eIntID_IMESelectedConvertedTextUnderline:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
break;
case eIntID_SpellCheckerUnderlineStyle:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
break;
case eIntID_MenuBarDrag:
+ EnsureInit();
aResult = sMenuSupportsDrag;
break;
case eIntID_ScrollbarButtonAutoRepeatBehavior:
aResult = 1;
break;
case eIntID_SwipeAnimationEnabled:
aResult = 0;
break;
@@ -871,16 +876,17 @@ nsLookAndFeel::GetFloatImpl(FloatID aID,
switch (aID) {
case eFloatID_IMEUnderlineRelativeSize:
aResult = 1.0f;
break;
case eFloatID_SpellCheckerUnderlineRelativeSize:
aResult = 1.0f;
break;
case eFloatID_CaretAspectRatio:
+ EnsureInit();
aResult = sCaretRatio;
break;
default:
aResult = -1.0;
res = NS_ERROR_FAILURE;
}
return res;
}
@@ -1051,21 +1057,25 @@ nsLookAndFeel::GetFontImpl(FontID aID, n
}
aFontName = *cachedFontName;
aFontStyle = *cachedFontStyle;
return true;
}
void
-nsLookAndFeel::Init()
+nsLookAndFeel::EnsureInit()
{
GdkColor colorValue;
GdkColor *colorValuePtr;
+ if (mInitialized)
+ return;
+ mInitialized = true;
+
#if (MOZ_WIDGET_GTK == 2)
NS_ASSERTION(!mStyle, "already initialized");
// GtkInvisibles come with a refcount that is not floating
// (since their initialization code calls g_object_ref_sink) and
// their destroy code releases that reference (which means they
// have to be explicitly destroyed, since calling unref enough
// to cause destruction would lead to *another* unref).
// However, this combination means that it's actually still ok
@@ -1433,16 +1443,17 @@ nsLookAndFeel::Init()
gtk_widget_destroy(window);
}
// virtual
char16_t
nsLookAndFeel::GetPasswordCharacterImpl()
{
+ EnsureInit();
return sInvisibleCharacter;
}
void
nsLookAndFeel::RefreshImpl()
{
nsXPLookAndFeel::RefreshImpl();
@@ -1451,15 +1462,15 @@ nsLookAndFeel::RefreshImpl()
mFieldFontCached = false;
mMenuFontCached = false;
#if (MOZ_WIDGET_GTK == 2)
g_object_unref(mStyle);
mStyle = nullptr;
#endif
- Init();
+ mInitialized = false;
}
bool
nsLookAndFeel::GetEchoPasswordImpl() {
return false;
}
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -76,13 +76,14 @@ protected:
nscolor sTextSelectedBackground;
nscolor sMozScrollbar;
#if (MOZ_WIDGET_GTK == 3)
nscolor sInfoBarText;
#endif
char16_t sInvisibleCharacter;
float sCaretRatio;
bool sMenuSupportsDrag;
+ bool mInitialized;
- void Init();
+ void EnsureInit();
};
#endif