Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit ddacb6c

Browse files
authored
Merge pull request #9387 from mono/fix1021556-nuget-accessible-tabs
[NuGet][1021556] Make tab labels behave like real tabs with VO
2 parents a9a857c + d391c51 commit ddacb6c

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.UI.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ internal partial class ManagePackagesDialog : ExtendedTitleBarDialog
6969
Label installedLabel;
7070
Label updatesLabel;
7171
Label consolidateLabel;
72+
HBox tabGroup;
7273
VBox projectsListViewVBox;
7374
Label projectsListViewLabel;
7475
ListView projectsListView;
@@ -110,40 +111,39 @@ void Build ()
110111
packageSourceComboBox.Accessible.LabelWidget = packageSourceLabel;
111112
topHBox.PackStart (packageSourceComboBox);
112113

114+
tabGroup = new HBox ();
115+
113116
int tabLabelMinWidth = 60;
114117
browseLabel = new Label ();
115118
browseLabel.Text = GettextCatalog.GetString ("Browse");
116119
browseLabel.Tag = browseLabel.Text;
117120
browseLabel.MinWidth = tabLabelMinWidth;
118121
browseLabel.MarginLeft = 10;
119122
browseLabel.CanGetFocus = true;
120-
browseLabel.Accessible.Role = Xwt.Accessibility.Role.Button;
121-
122-
topHBox.PackStart (browseLabel);
123+
tabGroup.PackStart (browseLabel);
123124

124125
installedLabel = new Label ();
125126
installedLabel.Text = GettextCatalog.GetString ("Installed");
126127
installedLabel.Tag = installedLabel.Text;
127128
installedLabel.MinWidth = tabLabelMinWidth;
128129
installedLabel.CanGetFocus = true;
129-
installedLabel.Accessible.Role = Xwt.Accessibility.Role.Button;
130-
topHBox.PackStart (installedLabel);
130+
tabGroup.PackStart (installedLabel);
131131

132132
updatesLabel = new Label ();
133133
updatesLabel.Text = GettextCatalog.GetString ("Updates");
134134
updatesLabel.Tag = updatesLabel.Text;
135135
updatesLabel.MinWidth = tabLabelMinWidth;
136136
updatesLabel.CanGetFocus = true;
137-
updatesLabel.Accessible.Role = Xwt.Accessibility.Role.Button;
138-
topHBox.PackStart (updatesLabel);
137+
tabGroup.PackStart (updatesLabel);
139138

140139
consolidateLabel = new Label ();
141140
consolidateLabel.Text = GettextCatalog.GetString ("Consolidate");
142141
consolidateLabel.Tag = consolidateLabel.Text;
143142
consolidateLabel.MinWidth = tabLabelMinWidth;
144143
consolidateLabel.CanGetFocus = true;
145-
consolidateLabel.Accessible.Role = Xwt.Accessibility.Role.Button;
146-
topHBox.PackStart (consolidateLabel);
144+
tabGroup.PackStart (consolidateLabel);
145+
146+
topHBox.PackStart (tabGroup);
147147

148148
packageSearchEntry = new SearchTextEntry ();
149149
packageSearchEntry.Name = "managePackagesDialogSearchEntry";

main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Gui/ManagePackagesDialog.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public ManagePackagesDialog (
9191
consolidateLabel.Visible = viewModel.IsManagingSolution;
9292
UpdateDialogTitle ();
9393
UpdatePackageSearchEntryWithInitialText (initialSearch);
94-
UpdatePackageResultsPageLabels ();
9594

9695
InitializeListView ();
9796
UpdateAddPackagesButton ();
@@ -114,6 +113,33 @@ public ManagePackagesDialog (
114113
updatesLabel.KeyPressed += UpdatesLabelKeyPressed;
115114
consolidateLabel.ButtonPressed += ConsolidateLabelButtonPressed;
116115
consolidateLabel.KeyPressed += ConsolidateLabelKeyPressed;
116+
UpdateTabAccessibility ();
117+
UpdatePackageResultsPageLabels ();
118+
}
119+
120+
void UpdateTabAccessibility ()
121+
{
122+
if (tabGroup.Surface.ToolkitEngine.Type == ToolkitType.Gtk) {
123+
if (consolidateLabel.Parent.Surface.NativeWidget is Gtk.Container a11yGroup) {
124+
a11yGroup.Accessible.SetRole (AtkCocoa.Roles.AXTabGroup);
125+
var children = a11yGroup.Children;
126+
var tabs = new List<Atk.Object> (children.Length);
127+
foreach (var child in children) {
128+
if (!child.Visible)
129+
continue;
130+
if (child is Gtk.EventBox box && box.Child is Gtk.Label) {
131+
box.Accessible.SetTitleUIElement (box.Child.Accessible);
132+
box.Child.Accessible.SetShouldIgnore (true);
133+
}
134+
var tab = child.Accessible;
135+
tab.SetRole (AtkCocoa.Roles.AXRadioButton);
136+
tab.SetSubRole (AtkCocoa.SubRoles.AXTabButton);
137+
tab.SetValue (false);
138+
tabs.Add (tab);
139+
}
140+
a11yGroup.Accessible.SetTabs (tabs.ToArray ());
141+
}
142+
}
117143
}
118144

119145
public bool ShowPreferencesForPackageSources { get; private set; }
@@ -1131,12 +1157,26 @@ void UpdatePackageResultsLabel (ManagePackagesPage page, Label label)
11311157
{
11321158
string text = (string)label.Tag;
11331159
if (page == viewModel.PageSelected) {
1160+
UpdatePackageResultsLabelA11y (label, true);
11341161
label.Markup = string.Format ("<b><u>{0}</u></b>", text);
11351162
} else {
1163+
UpdatePackageResultsLabelA11y (label, false);
11361164
label.Markup = text;
11371165
}
11381166
}
11391167

1168+
static void UpdatePackageResultsLabelA11y (Label label, bool active)
1169+
{
1170+
if (label.Surface.ToolkitEngine.Type == ToolkitType.Gtk) {
1171+
var widget = label.Surface.NativeWidget as Gtk.Widget;
1172+
if (widget != null) {
1173+
widget.Accessible.SetValue (active);
1174+
// FIXME: Accessible.SetValue has no effect, so set the role description instead
1175+
widget.Accessible.SetRole (AtkCocoa.Roles.AXRadioButton, active ? "selected tab" : "tab");
1176+
}
1177+
}
1178+
}
1179+
11401180
void UpdatePackageResultsLabel (ManagePackagesPage page, Button label)
11411181
{
11421182
string text = (string)label.Tag;

main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AtkCocoaHelper/AtkCocoaHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public enum Roles
154154
public enum SubRoles
155155
{
156156
AXCloseButton,
157+
AXTabButton,
157158
};
158159

159160
public struct Range

main/src/core/MonoDevelop.Ide/MonoDevelop.Components.AtkCocoaHelper/AtkCocoaHelperMac.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,23 @@ public static void SetMainWindow (this Atk.Object o, Atk.Object mainWindow)
213213
}
214214

215215
public static void SetValue (this Atk.Object o, string stringValue)
216+
{
217+
SetValue (o, (NSObject) new NSString (stringValue));
218+
}
219+
220+
public static void SetValue (this Atk.Object o, object value)
221+
{
222+
SetValue (o, NSObject.FromObject (value));
223+
}
224+
225+
static void SetValue (this Atk.Object o, NSObject value)
216226
{
217227
var nsa = GetNSAccessibilityElement (o);
218228
if (nsa == null) {
219229
return;
220230
}
221231

222-
nsa.AccessibilityValue = new NSString (stringValue);
232+
nsa.AccessibilityValue = value;
223233
}
224234

225235
public static void SetUrl (this Atk.Object o, string url)
@@ -261,6 +271,11 @@ public static void SetSubRole (this Atk.Object o, string subrole)
261271
nsa.AccessibilitySubrole = subrole;
262272
}
263273

274+
public static void SetSubRole (this Atk.Object o, AtkCocoa.SubRoles subrole)
275+
{
276+
o.SetSubRole (subrole.ToString ());
277+
}
278+
264279
public static void SetTitleUIElement (this Atk.Object o, Atk.Object title)
265280
{
266281
var nsa = GetNSAccessibilityElement (o);

0 commit comments

Comments
 (0)