Bug 1403690 Part 6: UIKit change nsLookAndFeel::NativeGetColor to use cached colors.
MozReview-Commit-ID: Jai4OLrNe6Y
--- 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]);
+}