зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1045213 - Make the highlighted menu item vibrant. r=smichaud
This commit is contained in:
Родитель
2f12e52126
Коммит
81d520103d
|
@ -25,7 +25,8 @@ enum class VibrancyType {
|
|||
LIGHT,
|
||||
DARK,
|
||||
TOOLTIP,
|
||||
MENU
|
||||
MENU,
|
||||
HIGHLIGHTED_MENUITEM
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -163,6 +163,7 @@ AppearanceForVibrancyType(VibrancyType aType)
|
|||
case VibrancyType::LIGHT:
|
||||
case VibrancyType::TOOLTIP:
|
||||
case VibrancyType::MENU:
|
||||
case VibrancyType::HIGHLIGHTED_MENUITEM:
|
||||
return [NSAppearanceClass performSelector:@selector(appearanceNamed:)
|
||||
withObject:@"NSAppearanceNameVibrantLight"];
|
||||
case VibrancyType::DARK:
|
||||
|
@ -179,8 +180,29 @@ enum {
|
|||
};
|
||||
#endif
|
||||
|
||||
@interface NSView(NSVisualEffectViewSetState)
|
||||
static NSUInteger
|
||||
VisualEffectStateForVibrancyType(VibrancyType aType)
|
||||
{
|
||||
switch (aType) {
|
||||
case VibrancyType::TOOLTIP:
|
||||
case VibrancyType::MENU:
|
||||
case VibrancyType::HIGHLIGHTED_MENUITEM:
|
||||
// Tooltip and menu windows are never "key", so we need to tell the
|
||||
// vibrancy effect to look active regardless of window state.
|
||||
return NSVisualEffectStateActive;
|
||||
default:
|
||||
return NSVisualEffectStateFollowsWindowActiveState;
|
||||
}
|
||||
}
|
||||
|
||||
enum {
|
||||
NSVisualEffectMaterialMenuItem = 4
|
||||
};
|
||||
|
||||
@interface NSView(NSVisualEffectViewMethods)
|
||||
- (void)setState:(NSUInteger)state;
|
||||
- (void)setMaterial:(NSUInteger)material;
|
||||
- (void)setEmphasized:(BOOL)emphasized;
|
||||
@end
|
||||
|
||||
NSView*
|
||||
|
@ -190,10 +212,13 @@ VibrancyManager::CreateEffectView(VibrancyType aType, NSRect aRect)
|
|||
NSView* effectView = [[EffectViewClass alloc] initWithFrame:aRect];
|
||||
[effectView performSelector:@selector(setAppearance:)
|
||||
withObject:AppearanceForVibrancyType(aType)];
|
||||
if (aType == VibrancyType::TOOLTIP || aType == VibrancyType::MENU) {
|
||||
// Tooltip and menu windows never become active, so we need to tell the
|
||||
// vibrancy effect to look active regardless of window state.
|
||||
[effectView setState:NSVisualEffectStateActive];
|
||||
[effectView setState:VisualEffectStateForVibrancyType(aType)];
|
||||
|
||||
if (aType == VibrancyType::HIGHLIGHTED_MENUITEM) {
|
||||
[effectView setMaterial:NSVisualEffectMaterialMenuItem];
|
||||
if ([effectView respondsToSelector:@selector(setEmphasized:)]) {
|
||||
[effectView setEmphasized:YES];
|
||||
}
|
||||
}
|
||||
return effectView;
|
||||
}
|
||||
|
|
|
@ -2377,18 +2377,25 @@ nsChildView::UpdateVibrancy(const nsTArray<ThemeGeometry>& aThemeGeometries)
|
|||
GatherThemeGeometryRegion(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeMenu);
|
||||
nsIntRegion tooltipRegion =
|
||||
GatherThemeGeometryRegion(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeTooltip);
|
||||
nsIntRegion highlightedMenuItemRegion =
|
||||
GatherThemeGeometryRegion(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeHighlightedMenuItem);
|
||||
|
||||
vibrantDarkRegion.SubOut(vibrantLightRegion);
|
||||
vibrantDarkRegion.SubOut(menuRegion);
|
||||
vibrantDarkRegion.SubOut(tooltipRegion);
|
||||
vibrantDarkRegion.SubOut(highlightedMenuItemRegion);
|
||||
vibrantLightRegion.SubOut(menuRegion);
|
||||
vibrantLightRegion.SubOut(tooltipRegion);
|
||||
vibrantLightRegion.SubOut(highlightedMenuItemRegion);
|
||||
menuRegion.SubOut(tooltipRegion);
|
||||
menuRegion.SubOut(highlightedMenuItemRegion);
|
||||
tooltipRegion.SubOut(highlightedMenuItemRegion);
|
||||
|
||||
auto& vm = EnsureVibrancyManager();
|
||||
vm.UpdateVibrantRegion(VibrancyType::LIGHT, vibrantLightRegion);
|
||||
vm.UpdateVibrantRegion(VibrancyType::TOOLTIP, tooltipRegion);
|
||||
vm.UpdateVibrantRegion(VibrancyType::MENU, menuRegion);
|
||||
vm.UpdateVibrantRegion(VibrancyType::HIGHLIGHTED_MENUITEM, highlightedMenuItemRegion);
|
||||
vm.UpdateVibrantRegion(VibrancyType::DARK, vibrantDarkRegion);
|
||||
}
|
||||
|
||||
|
@ -2412,6 +2419,8 @@ ThemeGeometryTypeToVibrancyType(nsITheme::ThemeGeometryType aThemeGeometryType)
|
|||
return VibrancyType::TOOLTIP;
|
||||
case nsNativeThemeCocoa::eThemeGeometryTypeMenu:
|
||||
return VibrancyType::MENU;
|
||||
case nsNativeThemeCocoa::eThemeGeometryTypeHighlightedMenuItem:
|
||||
return VibrancyType::HIGHLIGHTED_MENUITEM;
|
||||
default:
|
||||
MOZ_CRASH();
|
||||
}
|
||||
|
|
|
@ -2421,11 +2421,12 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
|
|||
|
||||
case NS_THEME_MENUITEM:
|
||||
case NS_THEME_CHECKMENUITEM: {
|
||||
bool isDisabled = IsDisabled(aFrame, eventState);
|
||||
bool isSelected = !isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
|
||||
if (!isSelected && VibrancyManager::SystemSupportsVibrancy()) {
|
||||
DrawVibrancyBackground(cgContext, macRect, aFrame, eThemeGeometryTypeMenu);
|
||||
if (VibrancyManager::SystemSupportsVibrancy()) {
|
||||
ThemeGeometryType type = ThemeGeometryTypeForWidget(aFrame, aWidgetType);
|
||||
DrawVibrancyBackground(cgContext, macRect, aFrame, type);
|
||||
} else {
|
||||
bool isDisabled = IsDisabled(aFrame, eventState);
|
||||
bool isSelected = !isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
|
||||
// maybe use kThemeMenuItemHierBackground or PopUpBackground instead of just Plain?
|
||||
HIThemeMenuItemDrawInfo drawInfo;
|
||||
memset(&drawInfo, 0, sizeof(drawInfo));
|
||||
|
@ -3827,9 +3828,14 @@ nsNativeThemeCocoa::ThemeGeometryTypeForWidget(nsIFrame* aFrame, uint8_t aWidget
|
|||
case NS_THEME_TOOLTIP:
|
||||
return eThemeGeometryTypeTooltip;
|
||||
case NS_THEME_MENUPOPUP:
|
||||
case NS_THEME_MENUITEM:
|
||||
case NS_THEME_CHECKMENUITEM:
|
||||
return eThemeGeometryTypeMenu;
|
||||
case NS_THEME_MENUITEM:
|
||||
case NS_THEME_CHECKMENUITEM: {
|
||||
EventStates eventState = GetContentState(aFrame, aWidgetType);
|
||||
bool isDisabled = IsDisabled(aFrame, eventState);
|
||||
bool isSelected = !isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
|
||||
return isSelected ? eThemeGeometryTypeHighlightedMenuItem : eThemeGeometryTypeMenu;
|
||||
}
|
||||
default:
|
||||
return eThemeGeometryTypeUnknown;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче