Merge branch 'more-a11y-tweaks' into 'main'

A11y improvements

See merge request GNOME/gtk!6116
This commit is contained in:
Emmanuele Bassi 2023-06-19 12:53:10 +00:00
commit 76efe45552
14 changed files with 141 additions and 13 deletions

View File

@ -4,6 +4,9 @@
<object class="GtkWindow" id="window">
<property name="resizable">1</property>
<property name="title">Clipboard</property>
<accessibility>
<relation name="described-by">label</relation>
</accessibility>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
@ -13,7 +16,7 @@
<property name="margin-bottom">12</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="label">
<property name="label">“Copy” will copy the selected data the clipboard, “Paste” will show the current clipboard contents. You can also drag the data to the bottom.</property>
<property name="wrap">1</property>
<property name="max-width-chars">40</property>

View File

@ -387,6 +387,8 @@ demo3_widget_class_init (Demo3WidgetClass *class)
gtk_widget_class_set_template_from_resource (widget_class, "/menu/demo3widget.ui");
gtk_widget_class_bind_template_child (widget_class, Demo3Widget, menu);
gtk_widget_class_bind_template_callback (widget_class, pressed_cb);
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_IMG);
}
GtkWidget *

View File

@ -19,8 +19,14 @@
</item>
</menu>
<template class="Demo3Widget">
<accessibility>
<property name="label">Demo image</property>
</accessibility>
<child>
<object class="GtkPopoverMenu" id="menu">
<accessibility>
<property name="label">Context menu</property>
</accessibility>
<property name="has-arrow">0</property>
<property name="menu-model">model</property>
</object>

View File

@ -334,11 +334,17 @@ do_drawingarea (GtkWidget *do_widget)
gtk_widget_set_vexpand (frame, TRUE);
gtk_box_append (GTK_BOX (vbox), frame);
da = gtk_drawing_area_new ();
da = g_object_new (GTK_TYPE_DRAWING_AREA,
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
gtk_accessible_update_relation (GTK_ACCESSIBLE (da),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), groups_draw, NULL, NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
/*
* Create the scribble area
@ -352,11 +358,17 @@ do_drawingarea (GtkWidget *do_widget)
gtk_widget_set_vexpand (frame, TRUE);
gtk_box_append (GTK_BOX (vbox), frame);
da = gtk_drawing_area_new ();
da = g_object_new (GTK_TYPE_DRAWING_AREA,
"accessible-role", GTK_ACCESSIBLE_ROLE_IMG,
NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
gtk_accessible_update_relation (GTK_ACCESSIBLE (da),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (da), 100);
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (da), scribble_draw, NULL, NULL);
gtk_frame_set_child (GTK_FRAME (frame), da);
g_signal_connect (da, "resize",
G_CALLBACK (scribble_resize), NULL);
@ -372,7 +384,7 @@ do_drawingarea (GtkWidget *do_widget)
}
if (!gtk_widget_get_visible (window))
gtk_widget_set_visible (window, TRUE);
gtk_window_present (GTK_WINDOW (window));
else
gtk_window_destroy (GTK_WINDOW (window));

View File

@ -18,6 +18,7 @@ do_headerbar (GtkWidget *do_widget)
GtkWidget *header;
GtkWidget *button;
GtkWidget *box;
GtkWidget *content;
if (!window)
{
@ -37,16 +38,26 @@ do_headerbar (GtkWidget *do_widget)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_add_css_class (box, "linked");
button = gtk_button_new_from_icon_name ("go-previous-symbolic");
gtk_widget_set_tooltip_text (button, "Back");
gtk_box_append (GTK_BOX (box), button);
button = gtk_button_new_from_icon_name ("go-next-symbolic");
gtk_widget_set_tooltip_text (button, "Forward");
gtk_box_append (GTK_BOX (box), button);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), box);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), gtk_switch_new ());
button = gtk_switch_new ();
gtk_accessible_update_property (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Change something",
-1);
gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);
gtk_window_set_titlebar (GTK_WINDOW (window), header);
gtk_window_set_child (GTK_WINDOW (window), gtk_text_view_new ());
content = gtk_text_view_new ();
gtk_accessible_update_property (GTK_ACCESSIBLE (content),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Content",
-1);
gtk_window_set_child (GTK_WINDOW (window), content);
}
if (!gtk_widget_get_visible (window))

View File

@ -164,12 +164,18 @@ do_image_scaling (GtkWidget *do_widget)
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, -10., 10., 0.1);
gtk_scale_add_mark (GTK_SCALE (scale), 0., GTK_POS_TOP, NULL);
gtk_widget_set_tooltip_text (scale, "Zoom");
gtk_accessible_update_property (GTK_ACCESSIBLE (scale),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Zoom",
-1);
gtk_range_set_value (GTK_RANGE (scale), 0.);
gtk_widget_set_hexpand (scale, TRUE);
gtk_box_append (GTK_BOX (box2), scale);
dropdown = gtk_drop_down_new (G_LIST_MODEL (gtk_string_list_new ((const char *[]){ "Linear", "Nearest", "Trilinear", NULL })), NULL);
gtk_widget_set_tooltip_text (dropdown, "Filter");
gtk_accessible_update_property (GTK_ACCESSIBLE (dropdown),
GTK_ACCESSIBLE_PROPERTY_LABEL, "Filter",
-1);
gtk_box_append (GTK_BOX (box2), dropdown);
g_object_bind_property (dropdown, "selected", widget, "filter", G_BINDING_DEFAULT);

View File

@ -37,6 +37,7 @@
#include "gtkbox.h"
#include "gtklabel.h"
#include "gtkbutton.h"
#include "gtkimage.h"
#include "gtkenums.h"
#include "deprecated/gtkdialog.h"
#include "gtkrevealer.h"
@ -46,6 +47,8 @@
#include "gtkbinlayout.h"
#include "gtkgestureclick.h"
#include <glib/gi18n-lib.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
/**
@ -456,6 +459,7 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
GtkWidget *widget = GTK_WIDGET (info_bar);
GtkWidget *main_box;
GtkGesture *gesture;
GtkWidget *image;
/* message-type is a CONSTRUCT property, so we init to a value
* different from its default to trigger its property setter
@ -478,11 +482,23 @@ gtk_info_bar_init (GtkInfoBar *info_bar)
gtk_widget_set_valign (info_bar->action_area, GTK_ALIGN_CENTER);
gtk_box_append (GTK_BOX (main_box), info_bar->action_area);
info_bar->close_button = gtk_button_new_from_icon_name ("window-close-symbolic");
info_bar->close_button = gtk_button_new ();
/* The icon is not relevant for accessibility purposes */
image = g_object_new (GTK_TYPE_IMAGE,
"accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION,
"icon-name", "window-close-symbolic",
"use-fallback", TRUE,
NULL);
gtk_button_set_child (GTK_BUTTON (info_bar->close_button), image);
gtk_widget_hide (info_bar->close_button);
gtk_widget_set_valign (info_bar->close_button, GTK_ALIGN_CENTER);
gtk_widget_add_css_class (info_bar->close_button, "close");
gtk_box_append (GTK_BOX (main_box), info_bar->close_button);
gtk_accessible_update_property (GTK_ACCESSIBLE (info_bar->close_button),
GTK_ACCESSIBLE_PROPERTY_LABEL, _("Close"),
GTK_ACCESSIBLE_PROPERTY_DESCRIPTION, _("Close the infobar"),
-1);
g_signal_connect (info_bar->close_button, "clicked",
G_CALLBACK (close_button_clicked_cb), info_bar);

View File

@ -171,6 +171,10 @@ button_toggled (GtkWidget *widget,
gtk_popover_popup (GTK_POPOVER (self->popup));
else
gtk_popover_popdown (GTK_POPOVER (self->popup));
gtk_accessible_update_state (GTK_ACCESSIBLE (self),
GTK_ACCESSIBLE_STATE_EXPANDED, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)),
-1);
}
static void
@ -695,7 +699,10 @@ setup_item (GtkSignalListItemFactory *factory,
label = gtk_label_new (NULL);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_box_append (GTK_BOX (box), label);
icon = gtk_image_new_from_icon_name ("object-select-symbolic");
icon = g_object_new (GTK_TYPE_IMAGE,
"icon-name", "object-select-symbolic",
"accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION,
NULL);
gtk_box_append (GTK_BOX (box), icon);
gtk_list_item_set_child (list_item, box);
}

View File

@ -1286,9 +1286,11 @@ typedef enum {
* @GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO: A radio item in a menu.
* @GTK_ACCESSIBLE_ROLE_NAVIGATION: Unused
* @GTK_ACCESSIBLE_ROLE_NONE: An element that is not represented to accessibility technologies.
* This role is synonymous to @GTK_ACCESSIBLE_ROLE_PRESENTATION.
* @GTK_ACCESSIBLE_ROLE_NOTE: Unused
* @GTK_ACCESSIBLE_ROLE_OPTION: Unused
* @GTK_ACCESSIBLE_ROLE_PRESENTATION: An element that is not represented to accessibility technologies.
* This role is synonymous to @GTK_ACCESSIBLE_ROLE_NONE.
* @GTK_ACCESSIBLE_ROLE_PROGRESS_BAR: An element that displays the progress
* status for tasks that take a long time.
* @GTK_ACCESSIBLE_ROLE_RADIO: A checkable input in a group of radio roles,

View File

@ -587,6 +587,17 @@ update_accessible_properties (GtkModelButton *button)
gtk_accessible_update_relation (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, button->label, NULL,
-1);
if (button->accel_label)
{
const char *text = gtk_label_get_label (GTK_LABEL (button->accel_label));
gtk_accessible_update_property (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_PROPERTY_KEY_SHORTCUTS, text,
-1);
}
else
gtk_accessible_reset_property (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_PROPERTY_KEY_SHORTCUTS);
}
static void
@ -831,6 +842,7 @@ update_accel (GtkModelButton *self,
if (!self->accel_label)
{
self->accel_label = g_object_new (GTK_TYPE_LABEL,
"accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION,
"css-name", "accelerator",
NULL);
gtk_widget_insert_before (self->accel_label, GTK_WIDGET (self), NULL);
@ -880,6 +892,8 @@ update_accel (GtkModelButton *self,
self->controller = NULL;
}
}
update_accessible_properties (self);
}
static void
@ -1481,7 +1495,7 @@ gtk_model_button_init (GtkModelButton *self)
gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
self->role = GTK_BUTTON_ROLE_NORMAL;
self->label = gtk_label_new ("");
self->label = g_object_new (GTK_TYPE_LABEL, "accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION, NULL);
gtk_widget_set_halign (self->label, GTK_ALIGN_START);
gtk_widget_set_parent (self->label, GTK_WIDGET (self));

View File

@ -4043,6 +4043,9 @@ gtk_notebook_insert_notebook_page (GtkNotebook *notebook,
if (page->tab_label)
{
gtk_widget_set_parent (page->tab_label, page->tab_widget);
gtk_accessible_update_relation (GTK_ACCESSIBLE (page->tab_widget),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, page->tab_label, NULL,
-1);
g_object_set_data (G_OBJECT (page->tab_label), "notebook", notebook);
}

View File

@ -346,9 +346,9 @@ update_window_buttons (GtkWindowControls *self)
image = g_object_new (GTK_TYPE_IMAGE,
"accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION,
"icon-name", "window-close-symbolic",
"use-fallback", TRUE,
NULL);
gtk_widget_add_css_class (button, "close");
g_object_set (image, "use-fallback", TRUE, NULL);
gtk_button_set_child (GTK_BUTTON (button), image);
gtk_widget_set_can_focus (button, FALSE);
gtk_actionable_set_action_name (GTK_ACTIONABLE (button),

View File

@ -201,11 +201,16 @@
</child>
<child>
<object class="GtkGrid" id="range_table">
<accessibility>
<relation name="labelled-by">label_widget1</relation>
</accessibility>
<property name="accessible-role">radio-group</property>
<property name="margin-start">12</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkCheckButton" id="all_pages_radio">
<property name="accessible-role">radio</property>
<property name="label" translatable="yes">_All Pages</property>
<property name="use-underline">1</property>
<property name="active">1</property>
@ -218,6 +223,7 @@
</child>
<child>
<object class="GtkCheckButton" id="current_page_radio">
<property name="accessible-role">radio</property>
<property name="label" translatable="yes">C_urrent Page</property>
<property name="sensitive">0</property>
<property name="use-underline">1</property>
@ -231,6 +237,7 @@
</child>
<child>
<object class="GtkCheckButton" id="selection_radio">
<property name="accessible-role">radio</property>
<property name="label" translatable="yes">Se_lection</property>
<property name="sensitive">0</property>
<property name="use-underline">1</property>
@ -244,7 +251,12 @@
</child>
<child>
<object class="GtkCheckButton" id="page_range_radio">
<property name="label" translatable="yes">Pag_es:</property>
<property name="child">
<object class="GtkLabel" id="page_range_label">
<property name="label" translatable="yes">Pag_es:</property>
<property name="use-underline">1</property>
</object>
</property>
<property name="tooltip-text" translatable="yes">Specify one or more page ranges,
e.g. 13, 7, 11</property>
<property name="use-underline">1</property>
@ -266,6 +278,9 @@
<property name="column">1</property>
<property name="row">3</property>
</layout>
<accessibility>
<relation name="labelled-by">page_range_label</relation>
</accessibility>
</object>
</child>
</object>
@ -289,6 +304,9 @@
</child>
<child>
<object class="GtkGrid" id="grid1">
<accessibility>
<relation name="labelled-by">label_widget2</relation>
</accessibility>
<property name="margin-start">12</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
@ -341,6 +359,11 @@
</child>
<child>
<object class="GtkFixed" id="page_collate_preview">
<property name="accessible-role">img</property>
<accessibility>
<property name="label" translatable="1">Page ordering preview</property>
<property name="description" translatable="1">A visualization of the effect of the collate and reverse options on the page ordering</property>
</accessibility>
<child>
<object class="GtkPageThumbnail" id="page_a1">
<property name="page-num">1</property>
@ -433,6 +456,10 @@
</child>
<child>
<object class="GtkGrid" id="grid2">
<property name="accessible-role">group</property>
<accessibility>
<relation name="labelled-by">label_widget3</relation>
</accessibility>
<property name="margin-start">12</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
@ -556,6 +583,9 @@
<property name="valign">4</property>
<child>
<object class="GtkSpinButton" id="scale_spin">
<accessibility>
<property name="label" translatable="1">Scale in percent</property>
</accessibility>
<property name="valign">4</property>
<property name="adjustment">scale_spin_adjustment</property>
<property name="digits">1</property>
@ -594,6 +624,10 @@
</child>
<child>
<object class="GtkGrid" id="grid3">
<property name="accessible-role">group</property>
<accessibility>
<relation name="labelled-by">label_widget4</relation>
</accessibility>
<property name="margin-start">12</property>
<property name="row-spacing">6</property>
<property name="column-spacing">12</property>
@ -730,6 +764,10 @@
<object class="GtkBox" id="box6">
<child>
<object class="GtkDrawingArea" id="page_layout_preview">
<property name="accessible-role">img</property>
<accessibility>
<property name="label" translatable="1">Page layout preview</property>
</accessibility>
<property name="content-width">320</property>
<property name="content-height">160</property>
<property name="hexpand">1</property>

View File

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk40">
<template class="GtkDropDown" parent="GtkWidget">
<accessibility>
<property name="has-popup">1</property>
<relation name="labelled-by">button_item</relation>
<state name="expanded">0</state>
</accessibility>
<child>
<object class="GtkToggleButton" id="button">
<signal name="toggled" handler="button_toggled"/>
@ -9,6 +14,7 @@
<property name="can-focus">0</property>
<child>
<object class="GtkStack" id="button_stack">
<property name="accessible-role">generic</property>
<property name="hexpand">1</property>
<property name="hhomogeneous">0</property>
<child>
@ -34,6 +40,7 @@
</child>
<child>
<object class="GtkBuiltinIcon" id="arrow">
<property name="accessible-role">presentation</property>
<property name="css-name">arrow</property>
</object>
</child>
@ -43,6 +50,7 @@
</child>
<child>
<object class="GtkPopover" id="popup">
<property name="accessible-role">list-box</property>
<signal name="closed" handler="popover_closed"/>
<property name="halign">1</property>
<property name="has-arrow">0</property>