From b74c4d0f6994290b5053417076f7cd973d830617 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 3 Aug 2017 13:16:31 -0700 Subject: [PATCH] Bug 1386915 - Add nsLookAndFeel::NativeInit() virtual call for initializing native-side state; r=jfkthame MozReview-Commit-ID: 8XKSC1AOI0N --- layout/style/ServoStyleSet.cpp | 3 +++ widget/LookAndFeel.h | 10 ++++++++++ widget/android/nsLookAndFeel.h | 1 + widget/cocoa/nsLookAndFeel.h | 1 + widget/gtk/nsLookAndFeel.cpp | 6 ++++++ widget/gtk/nsLookAndFeel.h | 1 + widget/headless/HeadlessLookAndFeel.h | 1 + widget/nsXPLookAndFeel.cpp | 7 +++++++ widget/nsXPLookAndFeel.h | 2 ++ widget/uikit/nsLookAndFeel.h | 1 + widget/windows/nsLookAndFeel.h | 1 + 11 files changed, 34 insertions(+) diff --git a/layout/style/ServoStyleSet.cpp b/layout/style/ServoStyleSet.cpp index a18ab190a6b4..adb3cba922d2 100644 --- a/layout/style/ServoStyleSet.cpp +++ b/layout/style/ServoStyleSet.cpp @@ -9,6 +9,7 @@ #include "gfxPlatformFontList.h" #include "mozilla/AutoRestyleTimelineMarker.h" #include "mozilla/DocumentStyleRootIterator.h" +#include "mozilla/LookAndFeel.h" #include "mozilla/ServoBindings.h" #include "mozilla/ServoRestyleManager.h" #include "mozilla/ServoStyleRuleMap.h" @@ -260,6 +261,8 @@ ServoStyleSet::PreTraverseSync() nsCSSRuleProcessor::InitSystemMetrics(); + LookAndFeel::NativeInit(); + // This is lazily computed and pseudo matching needs to access // it so force computation early. mPresContext->Document()->GetDocumentState(); diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h index c79e14fcf668..7c4d1006bcb8 100644 --- a/widget/LookAndFeel.h +++ b/widget/LookAndFeel.h @@ -618,6 +618,16 @@ public: */ static void Refresh(); + /** + * GTK's initialization code can't be run off main thread, call this + * if you plan on using LookAndFeel off main thread later. + * + * This initialized state may get reset due to theme changes, so it + * must be called prior to each potential off-main-thread LookAndFeel + * call, not just once. + */ + static void NativeInit(); + /** * If the implementation is caching values, these accessors allow the * cache to be exported and imported. diff --git a/widget/android/nsLookAndFeel.h b/widget/android/nsLookAndFeel.h index 4984f4013e6e..faad951b0ea1 100644 --- a/widget/android/nsLookAndFeel.h +++ b/widget/android/nsLookAndFeel.h @@ -15,6 +15,7 @@ public: virtual ~nsLookAndFeel(); virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult); + virtual void NativeInit() final {}; virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); virtual nsresult GetFloatImpl(FloatID aID, float &aResult); virtual bool GetFontImpl(FontID aID, nsString& aName, gfxFontStyle& aStyle, diff --git a/widget/cocoa/nsLookAndFeel.h b/widget/cocoa/nsLookAndFeel.h index 567e72e11f46..87edc6db0829 100644 --- a/widget/cocoa/nsLookAndFeel.h +++ b/widget/cocoa/nsLookAndFeel.h @@ -14,6 +14,7 @@ public: virtual ~nsLookAndFeel(); virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult); + virtual void NativeInit() final {}; virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); virtual nsresult GetFloatImpl(FloatID aID, float &aResult); virtual bool GetFontImpl(FontID aID, nsString& aFontName, diff --git a/widget/gtk/nsLookAndFeel.cpp b/widget/gtk/nsLookAndFeel.cpp index cd8a23eb4f34..7cd8e8dcc163 100644 --- a/widget/gtk/nsLookAndFeel.cpp +++ b/widget/gtk/nsLookAndFeel.cpp @@ -54,6 +54,12 @@ nsLookAndFeel::nsLookAndFeel() { } +void +nsLookAndFeel::NativeInit() +{ + EnsureInit(); +} + nsLookAndFeel::~nsLookAndFeel() { #if (MOZ_WIDGET_GTK == 2) diff --git a/widget/gtk/nsLookAndFeel.h b/widget/gtk/nsLookAndFeel.h index 7833aef32afe..9a4015e95415 100644 --- a/widget/gtk/nsLookAndFeel.h +++ b/widget/gtk/nsLookAndFeel.h @@ -21,6 +21,7 @@ public: virtual ~nsLookAndFeel(); virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult); + virtual void NativeInit() final; virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); virtual nsresult GetFloatImpl(FloatID aID, float &aResult); virtual bool GetFontImpl(FontID aID, nsString& aFontName, diff --git a/widget/headless/HeadlessLookAndFeel.h b/widget/headless/HeadlessLookAndFeel.h index b537e68c62a2..68a6704f9c87 100644 --- a/widget/headless/HeadlessLookAndFeel.h +++ b/widget/headless/HeadlessLookAndFeel.h @@ -24,6 +24,7 @@ public: virtual ~HeadlessLookAndFeel(); virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult); + virtual void NativeInit() final {}; virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); virtual nsresult GetFloatImpl(FloatID aID, float &aResult); virtual bool GetFontImpl(FontID aID, diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index e5fab2d505bf..a3ce20531a1f 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -990,6 +990,13 @@ LookAndFeel::Refresh() nsLookAndFeel::GetInstance()->RefreshImpl(); } +// static +void +LookAndFeel::NativeInit() +{ + nsLookAndFeel::GetInstance()->NativeInit(); +} + // static nsTArray LookAndFeel::GetIntCache() diff --git a/widget/nsXPLookAndFeel.h b/widget/nsXPLookAndFeel.h index 9808a6b10cad..a21d88050bbf 100644 --- a/widget/nsXPLookAndFeel.h +++ b/widget/nsXPLookAndFeel.h @@ -84,6 +84,8 @@ public: virtual nsTArray GetIntCacheImpl(); virtual void SetIntCacheImpl(const nsTArray& aLookAndFeelIntCache) {} + virtual void NativeInit() = 0; + protected: nsXPLookAndFeel(); diff --git a/widget/uikit/nsLookAndFeel.h b/widget/uikit/nsLookAndFeel.h index 6d5b355bc5b7..036f89ab150e 100644 --- a/widget/uikit/nsLookAndFeel.h +++ b/widget/uikit/nsLookAndFeel.h @@ -15,6 +15,7 @@ public: virtual ~nsLookAndFeel(); virtual nsresult NativeGetColor(const ColorID aID, nscolor &aResult); + virtual void NativeInit() final {}; virtual nsresult GetIntImpl(IntID aID, int32_t &aResult); virtual nsresult GetFloatImpl(FloatID aID, float &aResult); virtual bool GetFontImpl(FontID aID, nsString& aFontName, diff --git a/widget/windows/nsLookAndFeel.h b/widget/windows/nsLookAndFeel.h index 117ff7b7755a..5f32f4510db8 100644 --- a/widget/windows/nsLookAndFeel.h +++ b/widget/windows/nsLookAndFeel.h @@ -43,6 +43,7 @@ public: virtual ~nsLookAndFeel(); nsresult NativeGetColor(ColorID aID, nscolor &aResult) override; + void NativeInit() final {}; nsresult GetIntImpl(IntID aID, int32_t &aResult) override; nsresult GetFloatImpl(FloatID aID, float &aResult) override; bool GetFontImpl(FontID aID, nsString& aFontName,