Bug 1386915 - Add nsLookAndFeel::NativeInit() virtual call for initializing native-side state; r=jfkthame
authorManish Goregaokar <manishearth@gmail.com>
Thu, 03 Aug 2017 13:16:31 -0700
changeset 373147 813810854eeaae9f2c5cb8f6879f91ac45e5038a
parent 373146 f2a82baba93a5e644ae6ed84666db85f5838043c
child 373148 bb8de16ce00cb57b587a14c210ecc7505f366328
push id93450
push userryanvm@gmail.com
push dateMon, 07 Aug 2017 01:21:31 +0000
treeherdermozilla-inbound@bb8de16ce00c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1386915
milestone57.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 1386915 - Add nsLookAndFeel::NativeInit() virtual call for initializing native-side state; r=jfkthame MozReview-Commit-ID: 8XKSC1AOI0N
layout/style/ServoStyleSet.cpp
widget/LookAndFeel.h
widget/android/nsLookAndFeel.h
widget/cocoa/nsLookAndFeel.h
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsLookAndFeel.h
widget/headless/HeadlessLookAndFeel.h
widget/nsXPLookAndFeel.cpp
widget/nsXPLookAndFeel.h
widget/uikit/nsLookAndFeel.h
widget/windows/nsLookAndFeel.h
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ServoStyleSet.h"
 
 #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"
 #include "mozilla/css/Loader.h"
 #include "mozilla/dom/AnonymousContent.h"
 #include "mozilla/dom/ChildIterator.h"
 #include "mozilla/dom/FontFaceSet.h"
 #include "mozilla/dom/Element.h"
@@ -255,16 +256,18 @@ ServoStyleSet::ResolveMappedAttrDeclarat
 
 void
 ServoStyleSet::PreTraverseSync()
 {
   ResolveMappedAttrDeclarationBlocks();
 
   nsCSSRuleProcessor::InitSystemMetrics();
 
+  LookAndFeel::NativeInit();
+
   // This is lazily computed and pseudo matching needs to access
   // it so force computation early.
   mPresContext->Document()->GetDocumentState();
 
   if (gfxUserFontSet* userFontSet = mPresContext->Document()->GetUserFontSet()) {
     // Ensure that the @font-face data is not stale
     uint64_t generation = userFontSet->GetGeneration();
     if (generation != mUserFontSetUpdateGeneration) {
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -614,16 +614,26 @@ public:
 
   /**
    * When system look and feel is changed, Refresh() must be called.  Then,
    * cached data would be released.
    */
   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.
    */
   static nsTArray<LookAndFeelInt> GetIntCache();
   static void SetIntCache(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache);
 };
 
 } // namespace mozilla
--- a/widget/android/nsLookAndFeel.h
+++ b/widget/android/nsLookAndFeel.h
@@ -10,16 +10,17 @@
 
 class nsLookAndFeel final : public nsXPLookAndFeel
 {
 public:
     nsLookAndFeel();
     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,
                              float aDevPixPerCSSPixel);
     virtual bool GetEchoPasswordImpl();
     virtual uint32_t GetPasswordMaskDelayImpl();
     virtual char16_t GetPasswordCharacterImpl();
 
--- a/widget/cocoa/nsLookAndFeel.h
+++ b/widget/cocoa/nsLookAndFeel.h
@@ -9,16 +9,17 @@
 
 class nsLookAndFeel final : public nsXPLookAndFeel
 {
 public:
   nsLookAndFeel();
   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,
                            gfxFontStyle& aFontStyle,
                            float aDevPixPerCSSPixel);
   virtual char16_t GetPasswordCharacterImpl()
   {
     // unicode value for the bullet character, used for password textfields.
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -49,16 +49,22 @@ nsLookAndFeel::nsLookAndFeel()
       mStyle(nullptr),
 #endif
       mDefaultFontCached(false), mButtonFontCached(false),
       mFieldFontCached(false), mMenuFontCached(false),
       mInitialized(false)
 {
 }
 
+void
+nsLookAndFeel::NativeInit()
+{
+    EnsureInit();
+}
+
 nsLookAndFeel::~nsLookAndFeel()
 {
 #if (MOZ_WIDGET_GTK == 2)
     g_object_unref(mStyle);
 #endif
 }
 
 #if MOZ_WIDGET_GTK != 2
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -16,16 +16,17 @@ struct _GtkStyle;
 
 class nsLookAndFeel final : public nsXPLookAndFeel
 {
 public:
     nsLookAndFeel();
     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,
                              gfxFontStyle& aFontStyle,
                              float aDevPixPerCSSPixel);
 
     virtual void RefreshImpl();
     virtual char16_t GetPasswordCharacterImpl();
--- a/widget/headless/HeadlessLookAndFeel.h
+++ b/widget/headless/HeadlessLookAndFeel.h
@@ -19,16 +19,17 @@ namespace widget {
 // mode, so we use an implementation with hardcoded values.
 
 class HeadlessLookAndFeel: public nsXPLookAndFeel {
 public:
   HeadlessLookAndFeel();
   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,
                            nsString& aFontName,
                            gfxFontStyle& aFontStyle,
                            float aDevPixPerCSSPixel);
 
   virtual void RefreshImpl();
--- a/widget/nsXPLookAndFeel.cpp
+++ b/widget/nsXPLookAndFeel.cpp
@@ -986,16 +986,23 @@ LookAndFeel::GetPasswordMaskDelay()
 // static
 void
 LookAndFeel::Refresh()
 {
   nsLookAndFeel::GetInstance()->RefreshImpl();
 }
 
 // static
+void
+LookAndFeel::NativeInit()
+{
+  nsLookAndFeel::GetInstance()->NativeInit();
+}
+
+// static
 nsTArray<LookAndFeelInt>
 LookAndFeel::GetIntCache()
 {
   return nsLookAndFeel::GetInstance()->GetIntCacheImpl();
 }
 
 // static
 void
--- a/widget/nsXPLookAndFeel.h
+++ b/widget/nsXPLookAndFeel.h
@@ -79,16 +79,18 @@ public:
   virtual uint32_t GetPasswordMaskDelayImpl()
   {
     return 600;
   }
 
   virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
   virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache) {}
 
+  virtual void NativeInit() = 0;
+
 protected:
   nsXPLookAndFeel();
 
   static void IntPrefChanged(nsLookAndFeelIntPref *data);
   static void FloatPrefChanged(nsLookAndFeelFloatPref *data);
   static void ColorPrefChanged(unsigned int index, const char *prefName);
   void InitFromPref(nsLookAndFeelIntPref* aPref);
   void InitFromPref(nsLookAndFeelFloatPref* aPref);
--- a/widget/uikit/nsLookAndFeel.h
+++ b/widget/uikit/nsLookAndFeel.h
@@ -10,16 +10,17 @@
 
 class nsLookAndFeel final : public nsXPLookAndFeel
 {
 public:
     nsLookAndFeel();
     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,
                              gfxFontStyle& aFontStyle,
                              float aDevPixPerCSSPixel);
     virtual char16_t GetPasswordCharacterImpl()
     {
         // unicode value for the bullet character, used for password textfields.
--- a/widget/windows/nsLookAndFeel.h
+++ b/widget/windows/nsLookAndFeel.h
@@ -38,16 +38,17 @@
 class nsLookAndFeel final : public nsXPLookAndFeel
 {
   static OperatingSystemVersion GetOperatingSystemVersion();
 public:
   nsLookAndFeel();
   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,
                    gfxFontStyle& aFontStyle,
                    float aDevPixPerCSSPixel) override;
   void RefreshImpl() override;
   char16_t GetPasswordCharacterImpl() override;