Bug 1846859 - Remove appearance: {checkbox,radio}-{label,container}. r=desktop-theme-reviewers,dao

I didn't find a single GTK theme that drew something useful for this:

 * The container appearance isn't needed. It is a hack needed to get the
   right styles for the native checkbox, but that's it, we don't need to
   expose it to CSS.

 * The label appearance was meant to draw the focus outline but since it
   didn't work reliably we've been doing it manually since seven years
   ago (see bug 582951 and bug 1312169).

Other platforms also don't use these so this simplifies the code a bit.

Depends on D185279

Differential Revision: https://phabricator.services.mozilla.com/D185286
This commit is contained in:
Emilio Cobos Álvarez 2023-08-03 16:36:39 +00:00
parent 5777ff0911
commit bdce6101d4
9 changed files with 11 additions and 136 deletions

View File

@ -226,8 +226,6 @@ exports.CSS_PROPERTIES = {
"button-arrow-previous",
"button-arrow-up",
"checkbox",
"checkbox-container",
"checkbox-label",
"checkmenuitem",
"dialog",
"dualbutton",
@ -246,8 +244,6 @@ exports.CSS_PROPERTIES = {
"progress-bar",
"progresschunk",
"radio",
"radio-container",
"radio-label",
"range",
"range-thumb",
"revert",
@ -1481,8 +1477,6 @@ exports.CSS_PROPERTIES = {
"button-arrow-previous",
"button-arrow-up",
"checkbox",
"checkbox-container",
"checkbox-label",
"checkmenuitem",
"dialog",
"dualbutton",
@ -1501,8 +1495,6 @@ exports.CSS_PROPERTIES = {
"progress-bar",
"progresschunk",
"radio",
"radio-container",
"radio-label",
"range",
"range-thumb",
"revert",
@ -3519,8 +3511,6 @@ exports.CSS_PROPERTIES = {
"button-arrow-previous",
"button-arrow-up",
"checkbox",
"checkbox-container",
"checkbox-label",
"checkmenuitem",
"dialog",
"dualbutton",
@ -3539,8 +3529,6 @@ exports.CSS_PROPERTIES = {
"progress-bar",
"progresschunk",
"radio",
"radio-container",
"radio-label",
"range",
"range-thumb",
"revert",

View File

@ -1508,18 +1508,6 @@ pub enum Appearance {
/// The progress bar's progress indicator
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Progresschunk,
/// A generic container that always repaints on state changes. This is a
/// hack to make XUL checkboxes and radio buttons work.
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
CheckboxContainer,
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
RadioContainer,
/// The label part of a checkbox or radio button, used for painting a focus
/// outline.
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
CheckboxLabel,
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
RadioLabel,
/// nsRangeFrame and its subparts
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Range,

View File

@ -126,8 +126,6 @@ checkbox[native][disabled="true"] {
@media (-moz-platform: windows) or (-moz-platform: linux) {
checkbox[native]:focus-visible > .checkbox-label-box {
/* On Linux, native theming should take care of this but it appears to be
* broken with some Gtk themes. Bug 1312169. */
outline: var(--focus-outline);
}
}
@ -152,14 +150,6 @@ checkbox[native][disabled="true"] {
@media (-moz-platform: linux) {
checkbox:where([native]) {
appearance: auto;
-moz-default-appearance: checkbox-container;
margin: 2px 4px;
}
.checkbox-label-box[native] {
/* FIXME: Is this needed given the focus rules above? */
appearance: auto;
-moz-default-appearance: checkbox-label;
}
}

View File

@ -53,8 +53,6 @@ radio {
}
@media (-moz-platform: windows) or (-moz-platform: linux) {
/* On Linux, native theming should take care of this but it appears to be
* broken with some Gtk themes. Bug 1312169. */
radiogroup:focus-visible > radio[focused="true"] > .radio-label-box {
outline: var(--focus-outline);
}
@ -72,14 +70,6 @@ radio {
}
}
@media (-moz-platform: linux) {
/* FIXME: Is this needed given the focused styles above? */
.radio-label-box {
appearance: auto;
-moz-default-appearance: radio-label;
}
}
@media (-moz-platform: macos) {
.radio-label,
radiogroup {

View File

@ -3207,7 +3207,6 @@ bool nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFra
case StyleAppearance::Tooltip:
case StyleAppearance::Checkbox:
case StyleAppearance::CheckboxContainer:
case StyleAppearance::Radio:
case StyleAppearance::RadioContainer:
case StyleAppearance::MozMacHelpButton:

View File

@ -1211,35 +1211,6 @@ static gint moz_gtk_combo_box_entry_button_paint(cairo_t* cr,
return MOZ_GTK_SUCCESS;
}
static gint moz_gtk_container_paint(cairo_t* cr, GdkRectangle* rect,
GtkWidgetState* state,
WidgetNodeType widget_type,
GtkTextDirection direction) {
GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
GtkStyleContext* style =
GetStyleContext(widget_type, state->image_scale, direction, state_flags);
/* this is for drawing a prelight box */
if (state_flags & GTK_STATE_FLAG_PRELIGHT) {
gtk_render_background(style, cr, rect->x, rect->y, rect->width,
rect->height);
}
return MOZ_GTK_SUCCESS;
}
static gint moz_gtk_toggle_label_paint(cairo_t* cr, GdkRectangle* rect,
GtkWidgetState* state, gboolean isradio,
GtkTextDirection direction) {
if (!state->focused) return MOZ_GTK_SUCCESS;
GtkStyleContext* style = GetStyleContext(
isradio ? MOZ_GTK_RADIOBUTTON_CONTAINER : MOZ_GTK_CHECKBUTTON_CONTAINER,
state->image_scale, direction, GetStateFlagsFromGtkWidgetState(state));
gtk_render_focus(style, cr, rect->x, rect->y, rect->width, rect->height);
return MOZ_GTK_SUCCESS;
}
static gint moz_gtk_toolbar_paint(cairo_t* cr, GdkRectangle* rect,
GtkWidgetState* state,
GtkTextDirection direction) {
@ -1884,18 +1855,6 @@ gint moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top,
case MOZ_GTK_FRAME:
w = GetWidget(MOZ_GTK_FRAME);
break;
case MOZ_GTK_CHECKBUTTON_CONTAINER:
case MOZ_GTK_RADIOBUTTON_CONTAINER: {
w = GetWidget(widget);
if (w) {
style = gtk_widget_get_style_context(w);
*left = *top = *right = *bottom =
gtk_container_get_border_width(GTK_CONTAINER(w));
moz_gtk_add_border_padding(style, left, top, right, bottom);
}
return MOZ_GTK_SUCCESS;
}
case MOZ_GTK_TOOLTIP: {
// In GTK 3 there are 6 pixels of additional margin around the box.
// See details there:
@ -1930,8 +1889,6 @@ gint moz_gtk_get_widget_border(WidgetNodeType widget, gint* left, gint* top,
return MOZ_GTK_SUCCESS;
}
/* These widgets have no borders, since they are not containers. */
case MOZ_GTK_CHECKBUTTON_LABEL:
case MOZ_GTK_RADIOBUTTON_LABEL:
case MOZ_GTK_SPLITTER_HORIZONTAL:
case MOZ_GTK_SPLITTER_VERTICAL:
case MOZ_GTK_CHECKBUTTON:
@ -2391,13 +2348,6 @@ gint moz_gtk_widget_paint(WidgetNodeType widget, cairo_t* cr,
case MOZ_GTK_DROPDOWN_ARROW:
return moz_gtk_combo_box_entry_button_paint(cr, rect, state, flags,
direction);
case MOZ_GTK_CHECKBUTTON_CONTAINER:
case MOZ_GTK_RADIOBUTTON_CONTAINER:
return moz_gtk_container_paint(cr, rect, state, widget, direction);
case MOZ_GTK_CHECKBUTTON_LABEL:
case MOZ_GTK_RADIOBUTTON_LABEL:
return moz_gtk_toggle_label_paint(
cr, rect, state, (widget == MOZ_GTK_RADIOBUTTON_LABEL), direction);
case MOZ_GTK_TOOLBAR:
return moz_gtk_toolbar_paint(cr, rect, state, direction);
case MOZ_GTK_TOOLBAR_SEPARATOR:

View File

@ -130,15 +130,11 @@ enum WidgetNodeType : int {
MOZ_GTK_CHECKBUTTON_CONTAINER,
/* Paints a GtkCheckButton. flags is a boolean, 1=checked, 0=not checked. */
MOZ_GTK_CHECKBUTTON,
/* Paints the label of a GtkCheckButton (focus outline) */
MOZ_GTK_CHECKBUTTON_LABEL,
/* Paints the container part of a GtkRadioButton. */
MOZ_GTK_RADIOBUTTON_CONTAINER,
/* Paints a GtkRadioButton. flags is a boolean, 1=checked, 0=not checked. */
MOZ_GTK_RADIOBUTTON,
/* Paints the label of a GtkRadioButton (focus outline) */
MOZ_GTK_RADIOBUTTON_LABEL,
/* Vertical GtkScrollbar counterparts */
MOZ_GTK_SCROLLBAR_VERTICAL,
MOZ_GTK_SCROLLBAR_CONTENTS_VERTICAL,

View File

@ -272,10 +272,10 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance,
aGtkWidgetType = MOZ_GTK_TOOLBAR_BUTTON;
break;
case StyleAppearance::Checkbox:
aGtkWidgetType = MOZ_GTK_CHECKBUTTON;
break;
case StyleAppearance::Radio:
aGtkWidgetType = (aAppearance == StyleAppearance::Radio)
? MOZ_GTK_RADIOBUTTON
: MOZ_GTK_CHECKBUTTON;
aGtkWidgetType = MOZ_GTK_RADIOBUTTON;
break;
case StyleAppearance::Spinner:
aGtkWidgetType = MOZ_GTK_SPINBUTTON;
@ -392,18 +392,6 @@ bool nsNativeThemeGTK::GetGtkWidgetAndState(StyleAppearance aAppearance,
*aWidgetFlags = GTK_ARROW_LEFT;
}
break;
case StyleAppearance::CheckboxContainer:
aGtkWidgetType = MOZ_GTK_CHECKBUTTON_CONTAINER;
break;
case StyleAppearance::RadioContainer:
aGtkWidgetType = MOZ_GTK_RADIOBUTTON_CONTAINER;
break;
case StyleAppearance::CheckboxLabel:
aGtkWidgetType = MOZ_GTK_CHECKBUTTON_LABEL;
break;
case StyleAppearance::RadioLabel:
aGtkWidgetType = MOZ_GTK_RADIOBUTTON_LABEL;
break;
case StyleAppearance::Toolbar:
aGtkWidgetType = MOZ_GTK_TOOLBAR;
break;
@ -1164,10 +1152,6 @@ LayoutDeviceIntSize nsNativeThemeGTK::GetMinimumWidgetSize(
result.height = metrics->minSizeWithBorderMargin.height;
break;
}
case StyleAppearance::CheckboxContainer:
case StyleAppearance::RadioContainer:
case StyleAppearance::CheckboxLabel:
case StyleAppearance::RadioLabel:
case StyleAppearance::Button:
case StyleAppearance::Menulist:
case StyleAppearance::MenulistButton:
@ -1375,10 +1359,6 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext,
case StyleAppearance::Textarea:
case StyleAppearance::Range:
case StyleAppearance::RangeThumb:
case StyleAppearance::CheckboxContainer:
case StyleAppearance::RadioContainer:
case StyleAppearance::CheckboxLabel:
case StyleAppearance::RadioLabel:
case StyleAppearance::Menuarrow:
case StyleAppearance::Splitter:
case StyleAppearance::MozWindowButtonBox:

View File

@ -51,18 +51,14 @@ NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed)
const bool isXULElement = frameContent->IsXULElement();
if (isXULElement) {
if (aAppearance == StyleAppearance::CheckboxLabel ||
aAppearance == StyleAppearance::RadioLabel) {
aFrame = aFrame->GetParent()->GetParent();
frameContent = aFrame->GetContent();
} else if (aAppearance == StyleAppearance::Checkbox ||
aAppearance == StyleAppearance::Radio ||
aAppearance == StyleAppearance::ToolbarbuttonDropdown ||
aAppearance == StyleAppearance::Treeheadersortarrow ||
aAppearance == StyleAppearance::ButtonArrowPrevious ||
aAppearance == StyleAppearance::ButtonArrowNext ||
aAppearance == StyleAppearance::ButtonArrowUp ||
aAppearance == StyleAppearance::ButtonArrowDown) {
if (aAppearance == StyleAppearance::Checkbox ||
aAppearance == StyleAppearance::Radio ||
aAppearance == StyleAppearance::ToolbarbuttonDropdown ||
aAppearance == StyleAppearance::Treeheadersortarrow ||
aAppearance == StyleAppearance::ButtonArrowPrevious ||
aAppearance == StyleAppearance::ButtonArrowNext ||
aAppearance == StyleAppearance::ButtonArrowUp ||
aAppearance == StyleAppearance::ButtonArrowDown) {
aFrame = aFrame->GetParent();
frameContent = aFrame->GetContent();
}
@ -87,7 +83,6 @@ NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed)
}
switch (aAppearance) {
case StyleAppearance::RadioLabel:
case StyleAppearance::Radio: {
if (CheckBooleanAttr(aFrame, nsGkAtoms::focused)) {
flags |= ElementState::FOCUS;
@ -103,7 +98,6 @@ NS_IMPL_ISUPPORTS(nsNativeTheme, nsITimerCallback, nsINamed)
}
break;
}
case StyleAppearance::CheckboxLabel:
case StyleAppearance::Checkbox: {
if (CheckBooleanAttr(aFrame, nsGkAtoms::checked)) {
flags |= ElementState::CHECKED;