Bug 1403690 Part 5: Android change pref and color caching to match approach used in gtk, macOS, and Windows. r=snorp
☠☠ backed out by 888af9141ff8 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Tue, 10 Oct 2017 13:12:28 -0700
changeset 438436 6a5e056b7fb9ce08fd29387060705571d605bf64
parent 438435 349f51081127674758ef0f272a2cc3b2de355c5c
child 438437 29e6612a4083dce3e7838e95f887bf77c61d2c2a
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1403690
milestone58.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 1403690 Part 5: Android change pref and color caching to match approach used in gtk, macOS, and Windows. r=snorp MozReview-Commit-ID: DoffjB9QMmH
widget/android/nsLookAndFeel.cpp
widget/android/nsLookAndFeel.h
--- a/widget/android/nsLookAndFeel.cpp
+++ b/widget/android/nsLookAndFeel.cpp
@@ -37,26 +37,21 @@ nsLookAndFeel::~nsLookAndFeel()
 #define DARK_GRAY_COLOR        NS_RGB(0x40,0x40,0x40)
 #define GRAY_COLOR             NS_RGB(0x80,0x80,0x80)
 #define LIGHT_GRAY_COLOR       NS_RGB(0xa0,0xa0,0xa0)
 #define RED_COLOR              NS_RGB(0xff,0x00,0x00)
 
 nsresult
 nsLookAndFeel::GetSystemColors()
 {
-    if (mInitializedSystemColors)
-        return NS_OK;
-
     if (!AndroidBridge::Bridge())
         return NS_ERROR_FAILURE;
 
     AndroidBridge::Bridge()->GetSystemColors(&mSystemColors);
 
-    mInitializedSystemColors = true;
-
     return NS_OK;
 }
 
 nsresult
 nsLookAndFeel::CallRemoteGetSystemColors()
 {
     // An array has to be used to get data from remote process
     InfallibleTArray<uint32_t> colors;
@@ -71,32 +66,45 @@ nsLookAndFeel::CallRemoteGetSystemColors
 
     if (colors.Length() < colorsCount)
         colorsCount = colors.Length();
 
     // Array elements correspond to the members of mSystemColors structure,
     // so just copy the memory block
     memcpy(&mSystemColors, colors.Elements(), sizeof(nscolor) * colorsCount);
 
-    mInitializedSystemColors = true;
+    return NS_OK;
+}
+
+void
+nsLookAndFeel::NativeInit()
+{
+    EnsureInit();
+}
 
-    return NS_OK;
+/* virtual */
+void
+nsLookAndFeel::RefreshImpl()
+{
+    nsXPLookAndFeel::RefreshImpl();
+
+    mInitializedSystemColors = false;
+    mInitializedShowPassword = false;
 }
 
 nsresult
 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
 {
     nsresult rv = NS_OK;
 
+    EnsureInit();
     if (!mInitializedSystemColors) {
-        if (XRE_IsParentProcess())
-            rv = GetSystemColors();
-        else
-            rv = CallRemoteGetSystemColors();
-        NS_ENSURE_SUCCESS(rv, rv);
+        // Failure to initialize colors is an error condition. Return black.
+        aColor = 0;
+        return NS_ERROR_FAILURE;
     }
 
     // XXX we'll want to use context.obtainStyledAttributes on the java side to
     // get all of these; see TextView.java for a good exmaple.
 
     switch (aID) {
         // These colors don't seem to be used for anything anymore in Mozilla
         // (except here at least TextSelectBackground and TextSelectForeground)
@@ -338,17 +346,16 @@ nsLookAndFeel::NativeGetColor(ColorID aI
         aColor = 0;
         rv = NS_ERROR_FAILURE;
         break;
     }
 
     return rv;
 }
 
-
 nsresult
 nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
 {
     nsresult rv = nsXPLookAndFeel::GetIntImpl(aID, aResult);
     if (NS_SUCCEEDED(rv))
         return rv;
 
     rv = NS_OK;
@@ -464,24 +471,17 @@ nsLookAndFeel::GetFontImpl(FontID aID, n
     aFontStyle.systemFont = true;
     return true;
 }
 
 /*virtual*/
 bool
 nsLookAndFeel::GetEchoPasswordImpl()
 {
-    if (!mInitializedShowPassword) {
-        if (XRE_IsParentProcess()) {
-            mShowPassword = java::GeckoAppShell::GetShowPasswordSetting();
-        } else {
-            ContentChild::GetSingleton()->SendGetShowPasswordSetting(&mShowPassword);
-        }
-        mInitializedShowPassword = true;
-    }
+    EnsureInit();
     return mShowPassword;
 }
 
 uint32_t
 nsLookAndFeel::GetPasswordMaskDelayImpl()
 {
   // This value is hard-coded in Android OS's PasswordTransformationMethod.java
   return 1500;
@@ -489,8 +489,31 @@ nsLookAndFeel::GetPasswordMaskDelayImpl(
 
 /* virtual */
 char16_t
 nsLookAndFeel::GetPasswordCharacterImpl()
 {
   // This value is hard-coded in Android OS's PasswordTransformationMethod.java
   return UNICODE_BULLET;
 }
+
+void
+nsLookAndFeel::EnsureInit()
+{
+    if (!mInitializedSystemColors) {
+        nsresult rv;
+        if (XRE_IsParentProcess()) {
+            rv = GetSystemColors();
+        } else {
+            rv = CallRemoteGetSystemColors();
+        }
+        mInitializedSystemColors = NS_SUCCESS(rv);
+    }
+
+    if (!mInitializedShowPassword) {
+        if (XRE_IsParentProcess()) {
+            mShowPassword = java::GeckoAppShell::GetShowPasswordSetting();
+        } else {
+            ContentChild::GetSingleton()->SendGetShowPasswordSetting(&mShowPassword);
+        }
+        mInitializedShowPassword = true;
+    }
+}
--- a/widget/android/nsLookAndFeel.h
+++ b/widget/android/nsLookAndFeel.h
@@ -9,29 +9,32 @@
 #include "AndroidBridge.h"
 
 class nsLookAndFeel final : public nsXPLookAndFeel
 {
 public:
     nsLookAndFeel();
     virtual ~nsLookAndFeel();
 
+    virtual void NativeInit() final;
+    virtual void RefreshImpl();
     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();
 
 protected:
     static bool mInitializedSystemColors;
     static mozilla::AndroidSystemColors mSystemColors;
     static bool mInitializedShowPassword;
     static bool mShowPassword;
 
     nsresult GetSystemColors();
     nsresult CallRemoteGetSystemColors();
+
+    void EnsureInit();
 };
 
 #endif