Bug 1403690 Part 3: macOS change nsLookAndFeel::NativeGetColor to use cached colors. r=mstange

MozReview-Commit-ID: FHm6d2Vz2sJ

--HG--
extra : rebase_source : 9a92e8567b19aaa283cfc7d80f04ba7c3546742b
This commit is contained in:
Brad Werth 2017-10-02 17:13:48 -07:00
Родитель fc748892e5
Коммит beec09dd81
2 изменённых файлов: 188 добавлений и 67 удалений

Просмотреть файл

@ -13,8 +13,9 @@ public:
nsLookAndFeel();
virtual ~nsLookAndFeel();
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
virtual void NativeInit() final;
virtual void RefreshImpl();
virtual nsresult NativeGetColor(ColorID aID, nscolor &aResult);
virtual nsresult GetIntImpl(IntID aID, int32_t &aResult);
virtual nsresult GetFloatImpl(FloatID aID, float &aResult);
virtual bool GetFontImpl(FontID aID, nsString& aFontName,
@ -31,8 +32,6 @@ public:
virtual nsTArray<LookAndFeelInt> GetIntCacheImpl();
virtual void SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache);
virtual void RefreshImpl();
protected:
static bool SystemWantsOverlayScrollbars();
static bool AllowOverlayScrollbarsOverlap();
@ -43,6 +42,45 @@ private:
int32_t mAllowOverlayScrollbarsOverlap;
bool mAllowOverlayScrollbarsOverlapCached;
nscolor mColorTextSelectBackground;
nscolor mColorTextSelectBackgroundDisabled;
nscolor mColorHighlight;
nscolor mColorMenuHover;
nscolor mColorTextSelectForeground;
nscolor mColorMenuHoverText;
nscolor mColorButtonText;
bool mHasColorButtonText;
nscolor mColorButtonHoverText;
nscolor mColorText;
nscolor mColorWindowText;
nscolor mColorActiveCaption;
nscolor mColorActiveBorder;
nscolor mColorGrayText;
nscolor mColorInactiveBorder;
nscolor mColorInactiveCaption;
nscolor mColorScrollbar;
nscolor mColorThreeDHighlight;
nscolor mColorMenu;
nscolor mColorWindowFrame;
nscolor mColorFieldText;
nscolor mColorDialog;
nscolor mColorDialogText;
nscolor mColorDragTargetZone;
nscolor mColorChromeActive;
nscolor mColorChromeInactive;
nscolor mColorFocusRing;
nscolor mColorTextSelect;
nscolor mColorDisabledToolbarText;
nscolor mColorMenuSelect;
nscolor mColorCellHighlight;
nscolor mColorEvenTreeRow;
nscolor mColorOddTreeRow;
nscolor mColorActiveSourceListSelection;
bool mInitialized;
void EnsureInit();
};
#endif // nsLookAndFeel_h_

Просмотреть файл

@ -37,6 +37,8 @@ nsLookAndFeel::nsLookAndFeel()
, mUseOverlayScrollbarsCached(false)
, mAllowOverlayScrollbarsOverlap(-1)
, mAllowOverlayScrollbarsOverlapCached(false)
, mHasColorButtonText(false)
, mInitialized(false)
{
}
@ -61,25 +63,48 @@ static nscolor GetColorFromNSColorWithAlpha(NSColor* aColor, float alpha)
(unsigned int)(alpha * 255.0));
}
void
nsLookAndFeel::NativeInit()
{
EnsureInit();
}
void
nsLookAndFeel::RefreshImpl()
{
nsXPLookAndFeel::RefreshImpl();
// We should only clear the cache if we're in the main browser process.
// Otherwise, we should wait for the parent to inform us of new values
// to cache via LookAndFeel::SetIntCache.
if (XRE_IsParentProcess()) {
mUseOverlayScrollbarsCached = false;
mAllowOverlayScrollbarsOverlapCached = false;
}
// Fetch colors next time they are requested.
mInitialized = false;
}
nsresult
nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
EnsureInit();
nsresult res = NS_OK;
switch (aID) {
case eColorID_WindowBackground:
aColor = NS_RGB(0xff,0xff,0xff);
break;
case eColorID_WindowForeground:
aColor = NS_RGB(0x00,0x00,0x00);
aColor = NS_RGB(0x00,0x00,0x00);
break;
case eColorID_WidgetBackground:
aColor = NS_RGB(0xdd,0xdd,0xdd);
break;
case eColorID_WidgetForeground:
aColor = NS_RGB(0x00,0x00,0x00);
aColor = NS_RGB(0x00,0x00,0x00);
break;
case eColorID_WidgetSelectBackground:
aColor = NS_RGB(0x80,0x80,0x80);
@ -100,29 +125,25 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
aColor = NS_RGB(0x00,0x00,0x00);
break;
case eColorID_TextSelectBackground:
aColor = GetColorFromNSColor([NSColor selectedTextBackgroundColor]);
aColor = mColorTextSelectBackground;
break;
// This is used to gray out the selection when it's not focused. Used with
// nsISelectionController::SELECTION_DISABLED.
case eColorID_TextSelectBackgroundDisabled:
aColor = GetColorFromNSColor([NSColor secondarySelectedControlColor]);
aColor = mColorTextSelectBackgroundDisabled;
break;
case eColorID_highlight: // CSS2 color
aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
aColor = mColorHighlight;
break;
case eColorID__moz_menuhover:
aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
break;
aColor = mColorMenuHover;
break;
case eColorID_TextSelectForeground:
GetColor(eColorID_TextSelectBackground, aColor);
if (aColor == 0x000000)
aColor = NS_RGB(0xff,0xff,0xff);
else
aColor = NS_DONT_CHANGE_COLOR;
aColor = mColorTextSelectForeground;
break;
case eColorID_highlighttext: // CSS2 color
case eColorID__moz_menuhovertext:
aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]);
aColor = mColorMenuHoverText;
break;
case eColorID_IMESelectedRawTextBackground:
case eColorID_IMESelectedConvertedTextBackground:
@ -152,39 +173,39 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
// css2 system colors http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
//
// It's really hard to effectively map these to the Appearance Manager properly,
// since they are modeled word for word after the win32 system colors and don't have any
// real counterparts in the Mac world. I'm sure we'll be tweaking these for
// years to come.
// since they are modeled word for word after the win32 system colors and don't have any
// real counterparts in the Mac world. I'm sure we'll be tweaking these for
// years to come.
//
// Thanks to mpt26@student.canterbury.ac.nz for the hardcoded values that form the defaults
// if querying the Appearance Manager fails ;)
//
case eColorID__moz_mac_buttonactivetext:
case eColorID__moz_mac_defaultbuttontext:
if (nsCocoaFeatures::OnYosemiteOrLater()) {
aColor = NS_RGB(0xFF,0xFF,0xFF);
if (mHasColorButtonText) {
aColor = mColorButtonText;
break;
}
// Otherwise fall through and return the regular button text:
MOZ_FALLTHROUGH;
case eColorID_buttontext:
case eColorID__moz_buttonhovertext:
aColor = GetColorFromNSColor([NSColor controlTextColor]);
aColor = mColorButtonHoverText;
break;
case eColorID_captiontext:
case eColorID_menutext:
case eColorID_infotext:
case eColorID__moz_menubartext:
aColor = GetColorFromNSColor([NSColor textColor]);
aColor = mColorText;
break;
case eColorID_windowtext:
aColor = GetColorFromNSColor([NSColor windowFrameTextColor]);
aColor = mColorWindowText;
break;
case eColorID_activecaption:
aColor = GetColorFromNSColor([NSColor gridColor]);
aColor = mColorActiveCaption;
break;
case eColorID_activeborder:
aColor = GetColorFromNSColor([NSColor keyboardFocusIndicatorColor]);
aColor = mColorActiveBorder;
break;
case eColorID_appworkspace:
aColor = NS_RGB(0xFF,0xFF,0xFF);
@ -203,19 +224,19 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
aColor = NS_RGB(0xDC,0xDC,0xDC);
break;
case eColorID_graytext:
aColor = GetColorFromNSColor([NSColor disabledControlTextColor]);
aColor = mColorGrayText;
break;
case eColorID_inactiveborder:
aColor = GetColorFromNSColor([NSColor controlBackgroundColor]);
aColor = mColorInactiveBorder;
break;
case eColorID_inactivecaption:
aColor = GetColorFromNSColor([NSColor controlBackgroundColor]);
aColor = mColorInactiveCaption;
break;
case eColorID_inactivecaptiontext:
aColor = NS_RGB(0x45,0x45,0x45);
break;
case eColorID_scrollbar:
aColor = GetColorFromNSColor([NSColor scrollBarColor]);
aColor = mColorScrollbar;
break;
case eColorID_threeddarkshadow:
aColor = NS_RGB(0xDC,0xDC,0xDC);
@ -227,19 +248,19 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
aColor = NS_RGB(0xF0,0xF0,0xF0);
break;
case eColorID_threedhighlight:
aColor = GetColorFromNSColor([NSColor highlightColor]);
aColor = mColorThreeDHighlight;
break;
case eColorID_threedlightshadow:
aColor = NS_RGB(0xDA,0xDA,0xDA);
break;
case eColorID_menu:
aColor = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]);
aColor = mColorMenu;
break;
case eColorID_infobackground:
aColor = NS_RGB(0xFF,0xFF,0xC7);
break;
case eColorID_windowframe:
aColor = GetColorFromNSColor([NSColor gridColor]);
aColor = mColorWindowFrame;
break;
case eColorID_window:
case eColorID__moz_field:
@ -248,42 +269,42 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
break;
case eColorID__moz_fieldtext:
case eColorID__moz_comboboxtext:
aColor = GetColorFromNSColor([NSColor controlTextColor]);
aColor = mColorFieldText;
break;
case eColorID__moz_dialog:
aColor = GetColorFromNSColor([NSColor controlHighlightColor]);
aColor = mColorDialog;
break;
case eColorID__moz_dialogtext:
case eColorID__moz_cellhighlighttext:
case eColorID__moz_html_cellhighlighttext:
aColor = GetColorFromNSColor([NSColor controlTextColor]);
aColor = mColorDialogText;
break;
case eColorID__moz_dragtargetzone:
aColor = GetColorFromNSColor([NSColor selectedControlColor]);
aColor = mColorDragTargetZone;
break;
case eColorID__moz_mac_chrome_active:
case eColorID__moz_mac_chrome_inactive: {
int grey = NativeGreyColorAsInt(toolbarFillGrey, (aID == eColorID__moz_mac_chrome_active));
aColor = NS_RGB(grey, grey, grey);
}
aColor = mColorChromeActive;
break;
case eColorID__moz_mac_chrome_inactive:
aColor = mColorChromeInactive;
break;
case eColorID__moz_mac_focusring:
aColor = GetColorFromNSColorWithAlpha([NSColor keyboardFocusIndicatorColor], 0.48);
aColor = mColorFocusRing;
break;
case eColorID__moz_mac_menushadow:
aColor = NS_RGB(0xA3,0xA3,0xA3);
break;
break;
case eColorID__moz_mac_menutextdisable:
aColor = NS_RGB(0x98,0x98,0x98);
break;
break;
case eColorID__moz_mac_menutextselect:
aColor = GetColorFromNSColor([NSColor selectedMenuItemTextColor]);
break;
aColor = mColorTextSelect;
break;
case eColorID__moz_mac_disabledtoolbartext:
aColor = GetColorFromNSColor([NSColor disabledControlTextColor]);
aColor = mColorDisabledToolbarText;
break;
case eColorID__moz_mac_menuselect:
aColor = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
aColor = mColorMenuSelect;
break;
case eColorID__moz_buttondefault:
aColor = NS_RGB(0xDC,0xDC,0xDC);
@ -292,15 +313,15 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
case eColorID__moz_html_cellhighlight:
case eColorID__moz_mac_secondaryhighlight:
// For inactive list selection
aColor = GetColorFromNSColor([NSColor secondarySelectedControlColor]);
aColor = mColorCellHighlight;
break;
case eColorID__moz_eventreerow:
// Background color of even list rows.
aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:0]);
aColor = mColorEvenTreeRow;
break;
case eColorID__moz_oddtreerow:
// Background color of odd list rows.
aColor = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors] objectAtIndex:1]);
aColor = mColorOddTreeRow;
break;
case eColorID__moz_nativehyperlinktext:
// There appears to be no available system defined color. HARDCODING to the appropriate color.
@ -331,8 +352,7 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
break;
case eColorID__moz_mac_active_menuitem:
case eColorID__moz_mac_active_source_list_selection:
aColor = [NSColor currentControlTint] == NSGraphiteControlTint
? NS_RGB(0xa0,0xa0,0xa0) : NS_RGB(0x0a,0x64,0xdc);
aColor = mColorActiveSourceListSelection;
break;
default:
NS_WARNING("Someone asked nsILookAndFeel for a color I don't know about");
@ -342,8 +362,6 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
}
return res;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
nsresult
@ -355,7 +373,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eIntID_CaretBlinkTime:
aResult = 567;
@ -503,7 +521,7 @@ nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eFloatID_IMEUnderlineRelativeSize:
aResult = 2.0f;
@ -599,13 +617,78 @@ nsLookAndFeel::SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCa
}
void
nsLookAndFeel::RefreshImpl()
nsLookAndFeel::EnsureInit()
{
// We should only clear the cache if we're in the main browser process.
// Otherwise, we should wait for the parent to inform us of new values
// to cache via LookAndFeel::SetIntCache.
if (XRE_IsParentProcess()) {
mUseOverlayScrollbarsCached = false;
mAllowOverlayScrollbarsOverlapCached = false;
if (mInitialized) {
return;
}
mInitialized = true;
NS_OBJC_BEGIN_TRY_ABORT_BLOCK
nscolor color;
mColorTextSelectBackground = GetColorFromNSColor(
[NSColor selectedTextBackgroundColor]);
mColorTextSelectBackgroundDisabled = GetColorFromNSColor(
[NSColor secondarySelectedControlColor]);
mColorHighlight = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
mColorMenuHover = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
GetColor(eColorID_TextSelectBackground, color);
if (color == 0x000000) {
mColorTextSelectForeground = NS_RGB(0xff,0xff,0xff);
} else {
mColorTextSelectForeground = NS_DONT_CHANGE_COLOR;
}
mColorMenuHoverText = GetColorFromNSColor(
[NSColor alternateSelectedControlTextColor]);
if (nsCocoaFeatures::OnYosemiteOrLater()) {
mColorButtonText = NS_RGB(0xFF,0xFF,0xFF);
mHasColorButtonText = true;
}
mColorButtonHoverText = GetColorFromNSColor([NSColor controlTextColor]);
mColorText = GetColorFromNSColor([NSColor textColor]);
mColorWindowText = GetColorFromNSColor([NSColor windowFrameTextColor]);
mColorActiveCaption = GetColorFromNSColor([NSColor gridColor]);
mColorActiveBorder = GetColorFromNSColor([NSColor keyboardFocusIndicatorColor]);
mColorGrayText = GetColorFromNSColor([NSColor disabledControlTextColor]);
mColorInactiveBorder = GetColorFromNSColor([NSColor controlBackgroundColor]);
mColorInactiveCaption = GetColorFromNSColor([NSColor controlBackgroundColor]);
mColorScrollbar = GetColorFromNSColor([NSColor scrollBarColor]);
mColorThreeDHighlight = GetColorFromNSColor([NSColor highlightColor]);
mColorMenu = GetColorFromNSColor([NSColor alternateSelectedControlTextColor]);
mColorWindowFrame = GetColorFromNSColor([NSColor gridColor]);
mColorFieldText = GetColorFromNSColor([NSColor controlTextColor]);
mColorDialog = GetColorFromNSColor([NSColor controlHighlightColor]);
mColorDialogText = GetColorFromNSColor([NSColor controlTextColor]);
mColorDragTargetZone = GetColorFromNSColor([NSColor selectedControlColor]);
int grey = NativeGreyColorAsInt(toolbarFillGrey, true);
mColorChromeActive = NS_RGB(grey, grey, grey);
grey = NativeGreyColorAsInt(toolbarFillGrey, false);
mColorChromeInactive = NS_RGB(grey, grey, grey);
mColorFocusRing = GetColorFromNSColorWithAlpha([NSColor keyboardFocusIndicatorColor],
0.48);
mColorTextSelect = GetColorFromNSColor([NSColor selectedMenuItemTextColor]);
mColorDisabledToolbarText = GetColorFromNSColor([NSColor disabledControlTextColor]);
mColorMenuSelect = GetColorFromNSColor([NSColor alternateSelectedControlColor]);
mColorCellHighlight = GetColorFromNSColor([NSColor secondarySelectedControlColor]);
mColorEvenTreeRow = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors]
objectAtIndex:0]);
mColorOddTreeRow = GetColorFromNSColor([[NSColor controlAlternatingRowBackgroundColors]
objectAtIndex:1]);
color = [NSColor currentControlTint];
mColorActiveSourceListSelection = (color == NSGraphiteControlTint) ?
NS_RGB(0xa0,0xa0,0xa0) :
NS_RGB(0x0a,0x64,0xdc);
NS_OBJC_END_TRY_ABORT_BLOCK
}