Bug 1403690 Part 6: UIKit change nsLookAndFeel::NativeGetColor to use cached colors. r=ted
☠☠ backed out by 6ca4d18dede7 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Tue, 10 Oct 2017 13:50:58 -0700
changeset 387759 29e6612a4083dce3e7838e95f887bf77c61d2c2a
parent 387758 6a5e056b7fb9ce08fd29387060705571d605bf64
child 387760 671e63202d443d65d482e2807e839b31f84e7e35
push id96497
push userarchaeopteryx@coole-files.de
push dateTue, 24 Oct 2017 09:57:53 +0000
treeherdermozilla-inbound@7de3cc48b5b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
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 6: UIKit change nsLookAndFeel::NativeGetColor to use cached colors. r=ted MozReview-Commit-ID: Jai4OLrNe6Y
widget/uikit/nsLookAndFeel.h
widget/uikit/nsLookAndFeel.mm
--- a/widget/uikit/nsLookAndFeel.h
+++ b/widget/uikit/nsLookAndFeel.h
@@ -9,28 +9,37 @@
 #include "nsXPLookAndFeel.h"
 
 class nsLookAndFeel final : public nsXPLookAndFeel
 {
 public:
     nsLookAndFeel();
     virtual ~nsLookAndFeel();
 
+    virtual void NativeInit() final;
+    virtual void RefreshImpl();
     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.
         return 0x2022;
     }
 
     static bool UseOverlayScrollbars()
     {
         return true;
     }
+
+private:
+    nscolor mColorTextSelectForeground;
+    nscolor mColorDarkText;
+
+    bool mInitialized;
+
+    void EnsureInit();
 };
 
 #endif
--- a/widget/uikit/nsLookAndFeel.mm
+++ b/widget/uikit/nsLookAndFeel.mm
@@ -8,16 +8,17 @@
 
 #include "nsLookAndFeel.h"
 #include "nsStyleConsts.h"
 #include "gfxFont.h"
 #include "gfxFontConstants.h"
 
 nsLookAndFeel::nsLookAndFeel()
     : nsXPLookAndFeel()
+    , mInitialized(false)
 {
 }
 
 nsLookAndFeel::~nsLookAndFeel()
 {
 }
 
 static nscolor GetColorFromUIColor(UIColor* aColor)
@@ -34,19 +35,35 @@ static nscolor GetColorFromUIColor(UICol
         unsigned int val = (unsigned int)(components[0] * 255.0);
         return NS_RGBA(val, val, val,
                        (unsigned int)(components[1] * 255.0));
     }
     NS_NOTREACHED("Unhandled color space!");
     return 0;
 }
 
+void
+nsLookAndFeel::NativeInit()
+{
+  EnsureInit();
+}
+
+void
+nsLookAndFeel::RefreshImpl()
+{
+  nsXPLookAndFeel::RefreshImpl();
+
+  mInitialized = false;
+}
+
 nsresult
 nsLookAndFeel::NativeGetColor(const ColorID aID, nscolor &aResult)
 {
+  EnsureInit();
+
   nsresult res = NS_OK;
 
   switch (aID) {
     case eColorID_WindowBackground:
       aResult = NS_RGB(0xff,0xff,0xff);
       break;
     case eColorID_WindowForeground:
       aResult = NS_RGB(0x00,0x00,0x00);
@@ -80,21 +97,17 @@ nsLookAndFeel::NativeGetColor(const Colo
       aResult = NS_RGB(0xaa,0xaa,0xaa);
       break;
     case eColorID__moz_menuhover:
       aResult = NS_RGB(0xee,0xee,0xee);
       break;
     case eColorID_TextSelectForeground:
     case eColorID_highlighttext:  // CSS2 color
     case eColorID__moz_menuhovertext:
-      GetColor(eColorID_TextSelectBackground, aResult);
-      if (aResult == 0x000000)
-        aResult = NS_RGB(0xff,0xff,0xff);
-      else
-        aResult = NS_DONT_CHANGE_COLOR;
+      aResult = mColorTextSelectForeground;
       break;
     case eColorID_IMESelectedRawTextBackground:
     case eColorID_IMESelectedConvertedTextBackground:
     case eColorID_IMERawInputBackground:
     case eColorID_IMEConvertedTextBackground:
       aResult = NS_TRANSPARENT;
       break;
     case eColorID_IMESelectedRawTextForeground:
@@ -120,17 +133,17 @@ nsLookAndFeel::NativeGetColor(const Colo
     //
     case eColorID_buttontext:
     case eColorID__moz_buttonhovertext:
     case eColorID_captiontext:
     case eColorID_menutext:
     case eColorID_infotext:
     case eColorID__moz_menubartext:
     case eColorID_windowtext:
-      aResult = GetColorFromUIColor([UIColor darkTextColor]);
+      aResult = mColorDarkText;
       break;
     case eColorID_activecaption:
       aResult = NS_RGB(0xff,0xff,0xff);
       break;
     case eColorID_activeborder:
       aResult = NS_RGB(0x00,0x00,0x00);
       break;
      case eColorID_appworkspace:
@@ -190,25 +203,25 @@ nsLookAndFeel::NativeGetColor(const Colo
       break;
     case eColorID_window:
     case eColorID__moz_field:
     case eColorID__moz_combobox:
       aResult = NS_RGB(0xff,0xff,0xff);
       break;
     case eColorID__moz_fieldtext:
     case eColorID__moz_comboboxtext:
-      aResult = GetColorFromUIColor([UIColor darkTextColor]);
+      aResult = mColorDarkText;
       break;
     case eColorID__moz_dialog:
       aResult = NS_RGB(0xaa,0xaa,0xaa);
       break;
     case eColorID__moz_dialogtext:
     case eColorID__moz_cellhighlighttext:
     case eColorID__moz_html_cellhighlighttext:
-      aResult = GetColorFromUIColor([UIColor darkTextColor]);
+      aResult = mColorDarkText;
       break;
     case eColorID__moz_dragtargetzone:
     case eColorID__moz_mac_chrome_active:
     case eColorID__moz_mac_chrome_inactive:
       aResult = NS_RGB(0xaa,0xaa,0xaa);
       break;
     case eColorID__moz_mac_focusring:
       aResult = NS_RGB(0x3F,0x98,0xDD);
@@ -394,8 +407,27 @@ nsLookAndFeel::GetFontImpl(FontID aID, n
 
         aFontName.AssignLiteral("sans-serif");
         return true;
     }
 
     //TODO: implement more here?
     return false;
 }
+
+void
+nsLookAndFeel::EnsureInit()
+{
+  if (mInitialized) {
+    return;
+  }
+  mInitialized = true;
+
+  nscolor color;
+  GetColor(eColorID_TextSelectBackground, color);
+  if (color == 0x000000) {
+    mColorTextSelectForeground = NS_RGB(0xff,0xff,0xff);
+  } else {
+    mColorTextSelectForeground = NS_DONT_CHANGE_COLOR;
+  }
+
+  mColorDarkText = GetColorFromUIColor([UIColor darkTextColor]);
+}