Bug 1861671 - Remove some dead macOS menu drawing code. r=mac-reviewers,bradwerth

Some of it was already dead like the arrow-button-{up,down} stuff.

Depends on D192082

Differential Revision: https://phabricator.services.mozilla.com/D192083
This commit is contained in:
Emilio Cobos Álvarez 2023-10-31 18:57:12 +00:00
Родитель 2151014a69
Коммит 5e6062194f
8 изменённых файлов: 13 добавлений и 256 удалений

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

@ -1483,11 +1483,6 @@ pub enum Appearance {
/// A dual toolbar button (e.g., a Back button with a dropdown)
#[parse(condition = "ParserContext::chrome_rules_enabled")]
Dualbutton,
/// <menu> and <menuitem> appearances
#[parse(condition = "ParserContext::chrome_rules_enabled")]
Menuitem,
#[parse(condition = "ParserContext::chrome_rules_enabled")]
Checkmenuitem,
/// Menu Popup background.
#[parse(condition = "ParserContext::chrome_rules_enabled")]
Menupopup,

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

@ -1235,18 +1235,6 @@ bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData,
dpiRatio);
break;
}
case StyleAppearance::Menuitem: {
ThemeDrawing::FillRect(aPaintData, devPxRect, [&] {
if (CheckBooleanAttr(aFrame, nsGkAtoms::menuactive)) {
if (elementState.HasState(ElementState::DISABLED)) {
return colors.System(StyleSystemColor::MozMenuhoverdisabled);
}
return colors.System(StyleSystemColor::MozMenuhover);
}
return sTransparent;
}());
break;
}
case StyleAppearance::SpinnerUpbutton:
case StyleAppearance::SpinnerDownbutton:
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
@ -1689,7 +1677,6 @@ bool Theme::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
case StyleAppearance::MozMenulistArrowButton:
case StyleAppearance::SpinnerUpbutton:
case StyleAppearance::SpinnerDownbutton:
case StyleAppearance::Menuitem:
case StyleAppearance::Tooltip:
return !IsWidgetStyled(aPresContext, aFrame, aAppearance);
default:

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

@ -11,7 +11,6 @@ enum MacThemeGeometryType {
eThemeGeometryTypeToolbox,
eThemeGeometryTypeWindowButtons,
eThemeGeometryTypeMenu,
eThemeGeometryTypeHighlightedMenuItem,
eThemeGeometryTypeTooltip,
eThemeGeometryTypeSourceList,
eThemeGeometryTypeSourceListSelection,

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

@ -24,7 +24,6 @@ namespace mozilla {
enum class VibrancyType {
TOOLTIP,
MENU,
HIGHLIGHTED_MENUITEM,
SOURCE_LIST,
SOURCE_LIST_SELECTION,
ACTIVE_SOURCE_LIST_SELECTION
@ -53,8 +52,10 @@ class VibrancyManager {
* @param aContainerView The view that's going to be the superview of the
* NSVisualEffectViews which will be created for vibrant regions.
*/
VibrancyManager(const nsChildView& aCoordinateConverter, NSView* aContainerView)
: mCoordinateConverter(aCoordinateConverter), mContainerView(aContainerView) {}
VibrancyManager(const nsChildView& aCoordinateConverter,
NSView* aContainerView)
: mCoordinateConverter(aCoordinateConverter),
mContainerView(aContainerView) {}
/**
* Update the placement of the NSVisualEffectViews inside the container
@ -64,7 +65,8 @@ class VibrancyManager {
* @param aRegion The vibrant area, in device pixels.
* @return Whether the region changed.
*/
bool UpdateVibrantRegion(VibrancyType aType, const LayoutDeviceIntRegion& aRegion);
bool UpdateVibrantRegion(VibrancyType aType,
const LayoutDeviceIntRegion& aRegion);
bool HasVibrantRegions() { return !mVibrantRegions.IsEmpty(); }

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

@ -27,7 +27,6 @@ static NSVisualEffectState VisualEffectStateForVibrancyType(
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;
@ -47,7 +46,6 @@ static NSVisualEffectMaterial VisualEffectMaterialForVibrancyType(
return NSVisualEffectMaterialSidebar;
case VibrancyType::SOURCE_LIST_SELECTION:
return NSVisualEffectMaterialSelection;
case VibrancyType::HIGHLIGHTED_MENUITEM:
case VibrancyType::ACTIVE_SOURCE_LIST_SELECTION:
*aOutIsEmphasized = YES;
return NSVisualEffectMaterialSelection;

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

@ -1769,8 +1769,6 @@ static Maybe<VibrancyType> ThemeGeometryTypeToVibrancyType(
return Some(VibrancyType::TOOLTIP);
case eThemeGeometryTypeMenu:
return Some(VibrancyType::MENU);
case eThemeGeometryTypeHighlightedMenuItem:
return Some(VibrancyType::HIGHLIGHTED_MENUITEM);
case eThemeGeometryTypeSourceList:
return Some(VibrancyType::SOURCE_LIST);
case eThemeGeometryTypeSourceListSelection:
@ -1822,8 +1820,6 @@ void nsChildView::UpdateVibrancy(
GatherVibrantRegion(aThemeGeometries, VibrancyType::MENU);
LayoutDeviceIntRegion tooltipRegion =
GatherVibrantRegion(aThemeGeometries, VibrancyType::TOOLTIP);
LayoutDeviceIntRegion highlightedMenuItemRegion =
GatherVibrantRegion(aThemeGeometries, VibrancyType::HIGHLIGHTED_MENUITEM);
LayoutDeviceIntRegion sourceListRegion =
GatherVibrantRegion(aThemeGeometries, VibrancyType::SOURCE_LIST);
LayoutDeviceIntRegion sourceListSelectionRegion = GatherVibrantRegion(
@ -1831,16 +1827,14 @@ void nsChildView::UpdateVibrancy(
LayoutDeviceIntRegion activeSourceListSelectionRegion = GatherVibrantRegion(
aThemeGeometries, VibrancyType::ACTIVE_SOURCE_LIST_SELECTION);
MakeRegionsNonOverlapping(
menuRegion, tooltipRegion, highlightedMenuItemRegion, sourceListRegion,
sourceListSelectionRegion, activeSourceListSelectionRegion);
MakeRegionsNonOverlapping(menuRegion, tooltipRegion, sourceListRegion,
sourceListSelectionRegion,
activeSourceListSelectionRegion);
auto& vm = EnsureVibrancyManager();
bool changed = false;
changed |= vm.UpdateVibrantRegion(VibrancyType::MENU, menuRegion);
changed |= vm.UpdateVibrantRegion(VibrancyType::TOOLTIP, tooltipRegion);
changed |= vm.UpdateVibrantRegion(VibrancyType::HIGHLIGHTED_MENUITEM,
highlightedMenuItemRegion);
changed |=
vm.UpdateVibrantRegion(VibrancyType::SOURCE_LIST, sourceListRegion);
changed |= vm.UpdateVibrantRegion(VibrancyType::SOURCE_LIST_SELECTION,

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

@ -32,12 +32,6 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
using ThemeCocoa = mozilla::widget::ThemeCocoa;
public:
enum class MenuIcon : uint8_t {
eCheckmark,
eMenuDownScrollArrow,
eMenuUpScrollArrow
};
enum class CheckboxOrRadioState : uint8_t { eOff, eOn, eIndeterminate };
enum class ButtonType : uint8_t {
@ -73,21 +67,6 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
bool rtl : 1;
};
struct MenuIconParams {
MenuIcon icon = MenuIcon::eCheckmark;
bool disabled = false;
bool insideActiveMenuItem = false;
bool centerHorizontally = false;
bool rtl = false;
};
struct MenuItemParams {
bool checked = false;
bool disabled = false;
bool selected = false;
bool rtl = false;
};
struct CheckboxOrRadioParams {
ControlParams controlParams;
CheckboxOrRadioState state = CheckboxOrRadioState::eOff;
@ -171,8 +150,6 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
enum Widget : uint8_t {
eColorFill, // mozilla::gfx::sRGBColor
eMenuIcon, // MenuIconParams
eMenuItem, // MenuItemParams
eCheckbox, // CheckboxOrRadioParams
eRadio, // CheckboxOrRadioParams
eButton, // ButtonParams
@ -202,12 +179,6 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
static WidgetInfo ColorFill(const mozilla::gfx::sRGBColor& aParams) {
return WidgetInfo(Widget::eColorFill, aParams);
}
static WidgetInfo MenuIcon(const MenuIconParams& aParams) {
return WidgetInfo(Widget::eMenuIcon, aParams);
}
static WidgetInfo MenuItem(const MenuItemParams& aParams) {
return WidgetInfo(Widget::eMenuItem, aParams);
}
static WidgetInfo Checkbox(const CheckboxOrRadioParams& aParams) {
return WidgetInfo(Widget::eCheckbox, aParams);
}
@ -289,11 +260,10 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
WidgetInfo(enum Widget aWidget, const T& aParams)
: mVariant(aParams), mWidget(aWidget) {}
mozilla::Variant<mozilla::gfx::sRGBColor, MenuIconParams, MenuItemParams,
CheckboxOrRadioParams, ButtonParams, DropdownParams,
SpinButtonParams, SegmentParams, TextFieldParams,
ProgressParams, MeterParams, TreeHeaderCellParams,
ScaleParams, bool>
mozilla::Variant<mozilla::gfx::sRGBColor, CheckboxOrRadioParams,
ButtonParams, DropdownParams, SpinButtonParams,
SegmentParams, TextFieldParams, ProgressParams,
MeterParams, TreeHeaderCellParams, ScaleParams, bool>
mVariant;
enum Widget mWidget;
@ -357,12 +327,6 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
nsIFrame* SeparatorResponsibility(nsIFrame* aBefore, nsIFrame* aAfter);
ControlParams ComputeControlParams(nsIFrame* aFrame,
mozilla::dom::ElementState aEventState);
MenuIconParams ComputeMenuIconParams(nsIFrame* aParams,
mozilla::dom::ElementState aEventState,
MenuIcon aIcon);
MenuItemParams ComputeMenuItemParams(nsIFrame* aFrame,
mozilla::dom::ElementState aEventState,
bool aIsChecked);
SegmentParams ComputeSegmentParams(nsIFrame* aFrame,
mozilla::dom::ElementState aEventState,
SegmentType aSegmentType);
@ -405,12 +369,6 @@ class nsNativeThemeCocoa : public mozilla::widget::ThemeCocoa {
void DrawDisclosureButton(CGContextRef cgContext, const HIRect& inBoxRect,
ControlParams aControlParams,
NSControlStateValue aState);
NSString* GetMenuIconName(const MenuIconParams& aParams);
NSSize GetMenuIconSize(MenuIcon aIcon);
void DrawMenuIcon(CGContextRef cgContext, const CGRect& aRect,
const MenuIconParams& aParams);
void DrawMenuItem(CGContextRef cgContext, const CGRect& inBoxRect,
const MenuItemParams& aParams);
void DrawHIThemeButton(CGContextRef cgContext, const HIRect& aRect,
ThemeButtonKind aKind, ThemeButtonValue aValue,
ThemeDrawState aState, ThemeButtonAdornment aAdornment,

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

@ -63,10 +63,6 @@ void CUIDraw(CUIRendererRef r, CGRect rect, CGContextRef ctx,
CFDictionaryRef options, CFDictionaryRef* result);
}
static bool IsDarkAppearance(NSAppearance* appearance) {
return [appearance.name isEqualToString:NSAppearanceNameDarkAqua];
}
// Workaround for NSCell control tint drawing
// Without this workaround, NSCells are always drawn with the clear control tint
// as long as they're not attached to an NSControl which is a subview of an
@ -1107,126 +1103,6 @@ void nsNativeThemeCocoa::DrawSearchField(CGContextRef cgContext,
NS_OBJC_END_TRY_IGNORE_BLOCK;
}
static const NSSize kCheckmarkSize = NSMakeSize(11, 11);
static const NSSize kMenuScrollArrowSize = NSMakeSize(10, 8);
static NSString* kCheckmarkImage = @"MenuOnState";
static NSString* kMenuDownScrollArrowImage = @"MenuScrollDown";
static NSString* kMenuUpScrollArrowImage = @"MenuScrollUp";
static const CGFloat kMenuIconIndent = 6.0f;
NSString* nsNativeThemeCocoa::GetMenuIconName(const MenuIconParams& aParams) {
switch (aParams.icon) {
case MenuIcon::eCheckmark:
return kCheckmarkImage;
case MenuIcon::eMenuDownScrollArrow:
return kMenuDownScrollArrowImage;
case MenuIcon::eMenuUpScrollArrow:
return kMenuUpScrollArrowImage;
}
}
NSSize nsNativeThemeCocoa::GetMenuIconSize(MenuIcon aIcon) {
switch (aIcon) {
case MenuIcon::eCheckmark:
return kCheckmarkSize;
case MenuIcon::eMenuDownScrollArrow:
case MenuIcon::eMenuUpScrollArrow:
return kMenuScrollArrowSize;
}
}
nsNativeThemeCocoa::MenuIconParams nsNativeThemeCocoa::ComputeMenuIconParams(
nsIFrame* aFrame, ElementState aEventState, MenuIcon aIcon) {
bool isDisabled = aEventState.HasState(ElementState::DISABLED);
MenuIconParams params;
params.icon = aIcon;
params.disabled = isDisabled;
params.insideActiveMenuItem =
!isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
params.centerHorizontally = true;
params.rtl = IsFrameRTL(aFrame);
return params;
}
void nsNativeThemeCocoa::DrawMenuIcon(CGContextRef cgContext,
const CGRect& aRect,
const MenuIconParams& aParams) {
NS_OBJC_BEGIN_TRY_IGNORE_BLOCK;
NSSize size = GetMenuIconSize(aParams.icon);
// Adjust size and position of our drawRect.
CGFloat paddingX = std::max(CGFloat(0.0), aRect.size.width - size.width);
CGFloat paddingY = std::max(CGFloat(0.0), aRect.size.height - size.height);
CGFloat paddingStartX = std::min(paddingX, kMenuIconIndent);
CGFloat paddingEndX = std::max(CGFloat(0.0), paddingX - kMenuIconIndent);
CGRect drawRect = CGRectMake(
aRect.origin.x + (aParams.centerHorizontally ? ceil(paddingX / 2)
: aParams.rtl ? paddingEndX
: paddingStartX),
aRect.origin.y + ceil(paddingY / 2), size.width, size.height);
NSString* state;
if (aParams.disabled) {
state = @"disabled";
} else if (aParams.insideActiveMenuItem) {
state = @"pressed";
} else if (IsDarkAppearance(NSAppearance.currentAppearance)) {
// CUIDraw draws the image with a color that's too faint for the dark
// appearance. The "pressed" state happens to use white, which looks better
// and matches the white text color, so use it instead of "normal".
state = @"pressed";
} else {
state = @"normal";
}
NSString* imageName = GetMenuIconName(aParams);
RenderWithCoreUI(
drawRect, cgContext,
[NSDictionary dictionaryWithObjectsAndKeys:@"kCUIBackgroundTypeMenu",
@"backgroundTypeKey",
imageName, @"imageNameKey",
state, @"state", @"image",
@"widget",
[NSNumber numberWithBool:YES],
@"is.flipped", nil]);
#if DRAW_IN_FRAME_DEBUG
CGContextSetRGBFillColor(cgContext, 0.0, 0.0, 0.5, 0.25);
CGContextFillRect(cgContext, drawRect);
#endif
NS_OBJC_END_TRY_IGNORE_BLOCK;
}
nsNativeThemeCocoa::MenuItemParams nsNativeThemeCocoa::ComputeMenuItemParams(
nsIFrame* aFrame, ElementState aEventState, bool aIsChecked) {
bool isDisabled = aEventState.HasState(ElementState::DISABLED);
MenuItemParams params;
params.checked = aIsChecked;
params.disabled = isDisabled;
params.selected =
!isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
params.rtl = IsFrameRTL(aFrame);
return params;
}
void nsNativeThemeCocoa::DrawMenuItem(CGContextRef cgContext,
const CGRect& inBoxRect,
const MenuItemParams& aParams) {
if (aParams.checked) {
MenuIconParams params;
params.disabled = aParams.disabled;
params.insideActiveMenuItem = aParams.selected;
params.rtl = aParams.rtl;
params.icon = MenuIcon::eCheckmark;
DrawMenuIcon(cgContext, inBoxRect, params);
}
}
static bool ShouldUnconditionallyDrawFocusRingIfFocused(nsIFrame* aFrame) {
// Mac always draws focus rings for textboxes and lists.
switch (aFrame->StyleDisplay()->EffectiveAppearance()) {
@ -2347,21 +2223,6 @@ Maybe<nsNativeThemeCocoa::WidgetInfo> nsNativeThemeCocoa::ComputeWidgetInfo(
case StyleAppearance::Menupopup:
return Nothing();
case StyleAppearance::Menuitem:
case StyleAppearance::Checkmenuitem:
return Some(WidgetInfo::MenuItem(ComputeMenuItemParams(
aFrame, elementState,
aAppearance == StyleAppearance::Checkmenuitem)));
case StyleAppearance::ButtonArrowUp:
case StyleAppearance::ButtonArrowDown: {
MenuIcon icon = aAppearance == StyleAppearance::ButtonArrowUp
? MenuIcon::eMenuUpScrollArrow
: MenuIcon::eMenuDownScrollArrow;
return Some(WidgetInfo::MenuIcon(
ComputeMenuIconParams(aFrame, elementState, icon)));
}
case StyleAppearance::Tooltip:
return Nothing();
@ -2737,16 +2598,6 @@ void nsNativeThemeCocoa::RenderWidget(const WidgetInfo& aWidgetInfo,
case Widget::eColorFill:
MOZ_CRASH("already handled in outer switch");
break;
case Widget::eMenuIcon: {
MenuIconParams params = aWidgetInfo.Params<MenuIconParams>();
DrawMenuIcon(cgContext, macRect, params);
break;
}
case Widget::eMenuItem: {
MenuItemParams params = aWidgetInfo.Params<MenuItemParams>();
DrawMenuItem(cgContext, macRect, params);
break;
}
case Widget::eCheckbox: {
CheckboxOrRadioParams params =
aWidgetInfo.Params<CheckboxOrRadioParams>();
@ -2908,10 +2759,6 @@ bool nsNativeThemeCocoa::CreateWebRenderCommandsForWidget(
// - If the case in DrawWidgetBackground draws something complicated for the
// given widget type, return false here.
switch (aAppearance) {
case StyleAppearance::Menuitem:
case StyleAppearance::Checkmenuitem:
case StyleAppearance::ButtonArrowUp:
case StyleAppearance::ButtonArrowDown:
case StyleAppearance::Checkbox:
case StyleAppearance::Radio:
case StyleAppearance::Button:
@ -3173,12 +3020,6 @@ LayoutDeviceIntSize nsNativeThemeCocoa::GetMinimumWidgetSize(
break;
}
case StyleAppearance::ButtonArrowUp:
case StyleAppearance::ButtonArrowDown: {
result.SizeTo(kMenuScrollArrowSize.width, kMenuScrollArrowSize.height);
break;
}
case StyleAppearance::MozMacDisclosureButtonOpen:
case StyleAppearance::MozMacDisclosureButtonClosed: {
result.SizeTo(kDisclosureButtonSize.width, kDisclosureButtonSize.height);
@ -3385,9 +3226,7 @@ bool nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext,
case StyleAppearance::Dialog:
case StyleAppearance::MozWindowButtonBox:
case StyleAppearance::MozWindowTitlebar:
case StyleAppearance::Checkmenuitem:
case StyleAppearance::Menupopup:
case StyleAppearance::Menuitem:
case StyleAppearance::Tooltip:
case StyleAppearance::Checkbox:
@ -3396,8 +3235,6 @@ bool nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext,
case StyleAppearance::MozMacDisclosureButtonOpen:
case StyleAppearance::MozMacDisclosureButtonClosed:
case StyleAppearance::Button:
case StyleAppearance::ButtonArrowUp:
case StyleAppearance::ButtonArrowDown:
case StyleAppearance::Toolbarbutton:
case StyleAppearance::Spinner:
case StyleAppearance::SpinnerUpbutton:
@ -3488,11 +3325,7 @@ bool nsNativeThemeCocoa::WidgetAppearanceDependsOnWindowFocus(
switch (aAppearance) {
case StyleAppearance::Dialog:
case StyleAppearance::Tabpanels:
case StyleAppearance::ButtonArrowUp:
case StyleAppearance::ButtonArrowDown:
case StyleAppearance::Checkmenuitem:
case StyleAppearance::Menupopup:
case StyleAppearance::Menuitem:
case StyleAppearance::Tooltip:
case StyleAppearance::Spinner:
case StyleAppearance::SpinnerUpbutton:
@ -3526,15 +3359,6 @@ nsITheme::ThemeGeometryType nsNativeThemeCocoa::ThemeGeometryTypeForWidget(
return eThemeGeometryTypeTooltip;
case StyleAppearance::Menupopup:
return eThemeGeometryTypeMenu;
case StyleAppearance::Menuitem:
case StyleAppearance::Checkmenuitem: {
ElementState elementState = GetContentState(aFrame, aAppearance);
bool isDisabled = elementState.HasState(ElementState::DISABLED);
bool isSelected =
!isDisabled && CheckBooleanAttr(aFrame, nsGkAtoms::menuactive);
return isSelected ? eThemeGeometryTypeHighlightedMenuItem
: eThemeGeometryTypeMenu;
}
case StyleAppearance::MozMacSourceList:
return eThemeGeometryTypeSourceList;
case StyleAppearance::MozMacSourceListSelection: